diff --git a/.github/workflows/android.yml b/.github/workflows/android.yml index edff8661f..067daf43a 100644 --- a/.github/workflows/android.yml +++ b/.github/workflows/android.yml @@ -50,4 +50,22 @@ jobs: with: name: PR-${{ github.event.number }}-googleplay path: ${{ steps.google-play-apk-path-id.outputs.google-play-apk-path }} - retention-days: 2 \ No newline at end of file + retention-days: 2 + + - name: upload apk + uses: wei/curl@v1 + with: + args: --upload-file ${{ steps.apk-path-id.outputs.apk-path }} https://transfer.sh/PR-${{ github.event.number }}.apk -o apkpath.txt + + + - name: upload apk + id: upload-apk-path-id + run: | + echo "::set-output name=apk-path::$(cat apkpath.txt)" + shell: bash + + - name: commit + uses: mshick/add-pr-comment@v2 + with: + message: | + **Download apk from path: ${{ steps.upload-apk-path-id.outputs.apk-path }}** \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index 595096b49..d4846ea52 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -5,14 +5,14 @@ apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' android { - compileSdkVersion 30 + compileSdkVersion 33 defaultConfig { applicationId "com.parishod.watomatic" minSdkVersion 21 - targetSdkVersion 30 + targetSdkVersion 33 versionCode 26 - versionName "1.21" + versionName "1.22" javaCompileOptions { annotationProcessorOptions { @@ -75,6 +75,7 @@ dependencies { implementation 'com.google.android.material:material:1.5.0-alpha02' implementation 'androidx.constraintlayout:constraintlayout:2.1.1' implementation 'androidx.room:room-runtime:2.3.0' + implementation "androidx.work:work-runtime:2.7.1" testImplementation 'junit:junit:4.13.2' androidTestImplementation 'androidx.test.ext:junit:1.1.3' androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 7242233a0..68d35e01a 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -23,7 +23,8 @@ android:supportsRtl="true" android:theme="@style/Theme.WaReply"> - + @@ -34,7 +35,8 @@ + android:parentActivityName="com.parishod.watomatic.activity.main.MainActivity" + android:exported="true"> @@ -49,6 +51,7 @@ android:name="com.parishod.watomatic.activity.about.AboutActivity" android:label="@string/about" android:parentActivityName="com.parishod.watomatic.activity.main.MainActivity" + android:exported="false" > @@ -56,6 +59,7 @@ android:name="com.parishod.watomatic.activity.settings.SettingsActivity" android:label="@string/settings" android:parentActivityName="com.parishod.watomatic.activity.main.MainActivity" + android:exported="false" > @@ -63,6 +67,7 @@ android:name="com.parishod.watomatic.activity.advancedsettings.AdvancedSettingsActivity" android:label="@string/advanced_settings" android:parentActivityName="com.parishod.watomatic.activity.settings.SettingsActivity" + android:exported="false" > @@ -70,40 +75,46 @@ android:name=".activity.contactselector.ContactSelectorActivity" android:label="@string/contact_selector" android:parentActivityName=".activity.advancedsettings.AdvancedSettingsActivity" + android:exported="false" > + android:parentActivityName=".activity.main.MainActivity" + android:exported="false"/> + android:parentActivityName=".activity.main.MainActivity" + android:exported="false"/> + android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE" + android:exported="true"> + android:stopWithTask="false" + android:exported="true"/> + android:exported="true"> diff --git a/app/src/main/java/com/parishod/watomatic/fragment/MainFragment.java b/app/src/main/java/com/parishod/watomatic/fragment/MainFragment.java index 72580138b..a529ed7e5 100644 --- a/app/src/main/java/com/parishod/watomatic/fragment/MainFragment.java +++ b/app/src/main/java/com/parishod/watomatic/fragment/MainFragment.java @@ -484,7 +484,7 @@ private void enableService(boolean enable) { } private void startNotificationService() { - if (preferencesManager.isForegroundServiceNotificationEnabled()) { + if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.S || preferencesManager.isForegroundServiceNotificationEnabled()) { ServieUtils.getInstance(mActivity).startNotificationService(); } } diff --git a/app/src/main/java/com/parishod/watomatic/fragment/SettingsFragment.java b/app/src/main/java/com/parishod/watomatic/fragment/SettingsFragment.java index 2ce9b5f2b..ce4ce6315 100644 --- a/app/src/main/java/com/parishod/watomatic/fragment/SettingsFragment.java +++ b/app/src/main/java/com/parishod/watomatic/fragment/SettingsFragment.java @@ -1,5 +1,6 @@ package com.parishod.watomatic.fragment; +import android.os.Build; import android.os.Bundle; import androidx.preference.Preference; @@ -31,6 +32,9 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { SwitchPreference foregroundServiceNotifPref = findPreference(getString(R.string.pref_show_foreground_service_notification)); if (foregroundServiceNotifPref != null) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { + foregroundServiceNotifPref.setVisible(false); + } foregroundServiceNotifPref.setOnPreferenceChangeListener((preference, newValue) -> { if (newValue.equals(true)) { ServieUtils.getInstance(getActivity()).startNotificationService(); diff --git a/app/src/main/java/com/parishod/watomatic/model/utils/NotificationHelper.java b/app/src/main/java/com/parishod/watomatic/model/utils/NotificationHelper.java index b7fb7559e..d47dc8690 100644 --- a/app/src/main/java/com/parishod/watomatic/model/utils/NotificationHelper.java +++ b/app/src/main/java/com/parishod/watomatic/model/utils/NotificationHelper.java @@ -65,7 +65,7 @@ public void sendNotification(String title, String message, String packageName) { Intent intent = new Intent(appContext, NotificationIntentActivity.class); intent.putExtra("package", packageName); intent.setAction(Long.toString(System.currentTimeMillis()));//This is needed to generate unique pending intents, else when we create multiple pending intents they will be overwritten by last one - PendingIntent pIntent = PendingIntent.getActivity(appContext, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); + PendingIntent pIntent = PendingIntent.getActivity(appContext, 0, intent, PendingIntent.FLAG_IMMUTABLE | PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(appContext, Constants.NOTIFICATION_CHANNEL_ID) .setGroup("watomatic-" + packageName) @@ -141,7 +141,7 @@ public NotificationCompat.Builder getForegroundServiceNotification(Service servi Intent intent = new Intent(appContext, NotificationIntentActivity.class); intent.setAction(Long.toString(System.currentTimeMillis()));//This is needed to generate unique pending intents, else when we create multiple pending intents they will be overwritten by last one - PendingIntent pIntent = PendingIntent.getActivity(appContext, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT); + PendingIntent pIntent = PendingIntent.getActivity(appContext, 0, intent, PendingIntent.FLAG_IMMUTABLE | PendingIntent.FLAG_CANCEL_CURRENT); NotificationCompat.Builder notificationBuilder; if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) { diff --git a/app/src/main/java/com/parishod/watomatic/receivers/NotificationServiceRestartReceiver.kt b/app/src/main/java/com/parishod/watomatic/receivers/NotificationServiceRestartReceiver.kt index 7d74fb95f..b6c3ac38f 100644 --- a/app/src/main/java/com/parishod/watomatic/receivers/NotificationServiceRestartReceiver.kt +++ b/app/src/main/java/com/parishod/watomatic/receivers/NotificationServiceRestartReceiver.kt @@ -5,6 +5,7 @@ import android.content.ComponentName import android.content.Context import android.content.Intent import android.content.pm.PackageManager +import android.os.Build import android.util.Log import com.parishod.watomatic.NotificationService import com.parishod.watomatic.model.preferences.PreferencesManager @@ -21,15 +22,19 @@ class NotificationServiceRestartReceiver : BroadcastReceiver() { private fun restartService(context: Context) { val preferencesManager = PreferencesManager.getPreferencesInstance(context) - if (preferencesManager.isForegroundServiceNotificationEnabled) { + if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.S || preferencesManager.isForegroundServiceNotificationEnabled) { val serviceIntent = Intent(context, KeepAliveService::class.java) // ToDo: Should probably start using foreground service to prevent IllegalState exception below try { - context.startService(serviceIntent) + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + context.startForegroundService(serviceIntent) + } else { + context.startService(serviceIntent) + } } catch (e: IllegalStateException) { Log.e("NotifServiceRestart", "Unable to restart notification service") } - } else { + }else{ enableService(context) } } diff --git a/app/src/main/java/com/parishod/watomatic/service/KeepAliveService.java b/app/src/main/java/com/parishod/watomatic/service/KeepAliveService.java index 501e5cdf3..8ffc29d9e 100644 --- a/app/src/main/java/com/parishod/watomatic/service/KeepAliveService.java +++ b/app/src/main/java/com/parishod/watomatic/service/KeepAliveService.java @@ -4,6 +4,7 @@ import android.app.Service; import android.content.Context; import android.content.Intent; +import android.os.Build; import android.os.IBinder; import android.util.Log; @@ -63,7 +64,7 @@ public void onTaskRemoved(Intent rootIntent) { public void tryReconnectService() { if (PreferencesManager.getPreferencesInstance(getApplicationContext()).isServiceEnabled() - && PreferencesManager.getPreferencesInstance(getApplicationContext()).isForegroundServiceNotificationEnabled()) { + && (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S || PreferencesManager.getPreferencesInstance(getApplicationContext()).isForegroundServiceNotificationEnabled())) { Log.d("DEBUG", "KeepAliveService tryReconnectService"); //Send broadcast to restart service Intent broadcastIntent = new Intent(getApplicationContext(), NotificationServiceRestartReceiver.class); @@ -94,7 +95,9 @@ private boolean isMyServiceRunning() { private void startForeground(Service service) { Log.e("DEBUG", "startForeground"); - NotificationCompat.Builder notificationBuilder = NotificationHelper.getInstance(getApplicationContext()).getForegroundServiceNotification(service); - service.startForeground(FOREGROUND_NOTIFICATION_ID, notificationBuilder.build()); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + NotificationCompat.Builder notificationBuilder = NotificationHelper.getInstance(getApplicationContext()).getForegroundServiceNotification(service); + service.startForeground(FOREGROUND_NOTIFICATION_ID, notificationBuilder.build()); + } } } diff --git a/app/src/main/java/com/parishod/watomatic/viewmodel/SwipeToKillAppDetectViewModel.java b/app/src/main/java/com/parishod/watomatic/viewmodel/SwipeToKillAppDetectViewModel.java index 459d47ecd..1a9783185 100644 --- a/app/src/main/java/com/parishod/watomatic/viewmodel/SwipeToKillAppDetectViewModel.java +++ b/app/src/main/java/com/parishod/watomatic/viewmodel/SwipeToKillAppDetectViewModel.java @@ -3,6 +3,7 @@ import android.app.Application; import android.content.Context; import android.content.Intent; +import android.os.Build; import android.util.Log; import androidx.annotation.NonNull; @@ -32,7 +33,7 @@ protected void onCleared() { public void tryReconnectService() { if (PreferencesManager.getPreferencesInstance(context).isServiceEnabled() - && PreferencesManager.getPreferencesInstance(context).isForegroundServiceNotificationEnabled()) { + && (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S || PreferencesManager.getPreferencesInstance(context).isForegroundServiceNotificationEnabled())) { Log.d("DEBUG", "viewmodel tryReconnectService"); //Send broadcast to restart service Intent broadcastIntent = new Intent(context, NotificationServiceRestartReceiver.class);