From 137a26c3bf1e8ae074410b2fbd823df6627f8dca Mon Sep 17 00:00:00 2001 From: ThomasSession Date: Thu, 1 Aug 2024 11:25:35 +1000 Subject: [PATCH 1/7] KeepAliveService doesn't seem to be used anywhere --- app/src/main/AndroidManifest.xml | 4 +--- .../jobmanager/KeepAliveService.java | 24 ------------------- app/src/main/res/values-v26/values.xml | 1 - app/src/main/res/values/values.xml | 1 - libsession/src/main/res/values/values.xml | 1 - 5 files changed, 1 insertion(+), 30 deletions(-) delete mode 100644 app/src/main/java/org/thoughtcrime/securesms/jobmanager/KeepAliveService.java diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 7e04ad44ca..2d06893ca0 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -440,9 +440,7 @@ - + diff --git a/app/src/main/java/org/thoughtcrime/securesms/jobmanager/KeepAliveService.java b/app/src/main/java/org/thoughtcrime/securesms/jobmanager/KeepAliveService.java deleted file mode 100644 index 121686671c..0000000000 --- a/app/src/main/java/org/thoughtcrime/securesms/jobmanager/KeepAliveService.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.thoughtcrime.securesms.jobmanager; - -import android.app.Service; -import android.content.Intent; -import android.os.IBinder; -import androidx.annotation.Nullable; - -/** - * Service that keeps the application in memory while the app is closed. - * - * Important: Should only be used on API < 26. - */ -public class KeepAliveService extends Service { - - @Override - public @Nullable IBinder onBind(Intent intent) { - return null; - } - - @Override - public int onStartCommand(Intent intent, int flags, int startId) { - return START_STICKY; - } -} diff --git a/app/src/main/res/values-v26/values.xml b/app/src/main/res/values-v26/values.xml index dc6b4b7941..c9cf9e837c 100644 --- a/app/src/main/res/values-v26/values.xml +++ b/app/src/main/res/values-v26/values.xml @@ -1,5 +1,4 @@ - false true diff --git a/app/src/main/res/values/values.xml b/app/src/main/res/values/values.xml index c87ba9badd..384c8df05b 100644 --- a/app/src/main/res/values/values.xml +++ b/app/src/main/res/values/values.xml @@ -1,6 +1,5 @@ - true false diff --git a/libsession/src/main/res/values/values.xml b/libsession/src/main/res/values/values.xml index f493249a83..899d189687 100644 --- a/libsession/src/main/res/values/values.xml +++ b/libsession/src/main/res/values/values.xml @@ -1,6 +1,5 @@ - true false true From 33f23e5fa1b3f4ac5b74082334dbef39222431fe Mon Sep 17 00:00:00 2001 From: ThomasSession Date: Thu, 1 Aug 2024 11:27:43 +1000 Subject: [PATCH 2/7] Another unused or referenced service --- app/src/main/AndroidManifest.xml | 1 - .../service/GenericForegroundService.java | 128 ------------------ 2 files changed, 129 deletions(-) delete mode 100644 app/src/main/java/org/thoughtcrime/securesms/service/GenericForegroundService.java diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 2d06893ca0..e1a2e79694 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -328,7 +328,6 @@ - Date: Thu, 1 Aug 2024 16:50:20 +1000 Subject: [PATCH 3/7] Cleaning up foreground service calls --- .../securesms/service/KeyCachingService.java | 18 +++++++++++++----- .../securesms/service/WebRtcCallService.kt | 13 +++++++++++-- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/service/KeyCachingService.java b/app/src/main/java/org/thoughtcrime/securesms/service/KeyCachingService.java index f919af7ad6..47b5c52f16 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/service/KeyCachingService.java +++ b/app/src/main/java/org/thoughtcrime/securesms/service/KeyCachingService.java @@ -35,6 +35,7 @@ import android.os.SystemClock; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.core.app.NotificationCompat; +import androidx.core.app.ServiceCompat; import org.session.libsession.utilities.ServiceUtil; import org.session.libsession.utilities.TextSecurePreferences; @@ -122,7 +123,7 @@ public class KeyCachingService extends Service { KeyCachingService.masterSecret = masterSecret; foregroundService(); - + new AsyncTask() { @Override protected Void doInBackground(Void... params) { @@ -252,11 +253,18 @@ public class KeyCachingService extends Service { builder.setContentIntent(buildLaunchIntent()); stopForeground(true); - if (Build.VERSION.SDK_INT >= 34) { - startForeground(SERVICE_RUNNING_ID, builder.build(), ServiceInfo.FOREGROUND_SERVICE_TYPE_SPECIAL_USE); - } else { - startForeground(SERVICE_RUNNING_ID, builder.build()); + + int type = 0; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) { + type = ServiceInfo.FOREGROUND_SERVICE_TYPE_SPECIAL_USE; } + + ServiceCompat.startForeground( + this, + SERVICE_RUNNING_ID, + builder.build(), + type + ); } private PendingIntent buildLockIntent() { diff --git a/app/src/main/java/org/thoughtcrime/securesms/service/WebRtcCallService.kt b/app/src/main/java/org/thoughtcrime/securesms/service/WebRtcCallService.kt index f40a075d8d..6ee33721e8 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/service/WebRtcCallService.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/service/WebRtcCallService.kt @@ -7,9 +7,12 @@ import android.content.Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT import android.content.Intent.FLAG_ACTIVITY_NEW_TASK import android.content.IntentFilter import android.content.pm.PackageManager +import android.content.pm.ServiceInfo import android.media.AudioManager +import android.os.Build import android.os.ResultReceiver import android.telephony.TelephonyManager +import androidx.core.app.ServiceCompat import androidx.core.content.ContextCompat import androidx.core.os.bundleOf import androidx.lifecycle.LifecycleService @@ -723,9 +726,15 @@ class WebRtcCallService : LifecycleService(), CallManager.WebRtcListener { private fun setCallInProgressNotification(type: Int, recipient: Recipient?) { try { - startForeground( + ServiceCompat.startForeground( + this, CallNotificationBuilder.WEBRTC_NOTIFICATION, - CallNotificationBuilder.getCallInProgressNotification(this, type, recipient) + CallNotificationBuilder.getCallInProgressNotification(this, type, recipient), + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { + ServiceInfo.FOREGROUND_SERVICE_TYPE_MICROPHONE + } else { + 0 + } ) } catch (e: IllegalStateException) { Log.e(TAG, "Failed to setCallInProgressNotification as a foreground service for type: ${type}, trying to update instead", e) From d8bcb83de5115d065ce7de78370ab962884f7942 Mon Sep 17 00:00:00 2001 From: bemusementpark Date: Sat, 27 Jul 2024 16:12:03 +0930 Subject: [PATCH 4/7] Fix app exit after Lock Screen --- app/src/main/AndroidManifest.xml | 2 +- .../main/java/org/thoughtcrime/securesms/home/HomeActivity.kt | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index e1a2e79694..91d9572f90 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -125,7 +125,7 @@ Date: Fri, 2 Aug 2024 08:43:48 +1000 Subject: [PATCH 5/7] Update app/src/main/java/org/thoughtcrime/securesms/service/KeyCachingService.java Co-authored-by: Andrew --- .../org/thoughtcrime/securesms/service/KeyCachingService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/service/KeyCachingService.java b/app/src/main/java/org/thoughtcrime/securesms/service/KeyCachingService.java index 47b5c52f16..14b2c43af4 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/service/KeyCachingService.java +++ b/app/src/main/java/org/thoughtcrime/securesms/service/KeyCachingService.java @@ -255,7 +255,7 @@ public class KeyCachingService extends Service { stopForeground(true); int type = 0; - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) { + if (Build.VERSION.SDK_INT >= 34) { type = ServiceInfo.FOREGROUND_SERVICE_TYPE_SPECIAL_USE; } From 7dcfba49324b18fe7635548343b6b65611b1f087 Mon Sep 17 00:00:00 2001 From: ThomasSession Date: Fri, 2 Aug 2024 08:44:30 +1000 Subject: [PATCH 6/7] Update app/src/main/java/org/thoughtcrime/securesms/service/KeyCachingService.java Co-authored-by: Andrew --- .../securesms/service/KeyCachingService.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/service/KeyCachingService.java b/app/src/main/java/org/thoughtcrime/securesms/service/KeyCachingService.java index 14b2c43af4..cf250665ef 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/service/KeyCachingService.java +++ b/app/src/main/java/org/thoughtcrime/securesms/service/KeyCachingService.java @@ -260,11 +260,11 @@ public class KeyCachingService extends Service { } ServiceCompat.startForeground( - this, - SERVICE_RUNNING_ID, - builder.build(), - type - ); + this, + SERVICE_RUNNING_ID, + builder.build(), + type + ); } private PendingIntent buildLockIntent() { From e71f650dc0c9dd67d7b05278704bfcaae8b6a397 Mon Sep 17 00:00:00 2001 From: ThomasSession Date: Fri, 2 Aug 2024 08:44:39 +1000 Subject: [PATCH 7/7] Update app/src/main/java/org/thoughtcrime/securesms/service/WebRtcCallService.kt Co-authored-by: Andrew --- .../org/thoughtcrime/securesms/service/WebRtcCallService.kt | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/service/WebRtcCallService.kt b/app/src/main/java/org/thoughtcrime/securesms/service/WebRtcCallService.kt index 6ee33721e8..78f1a55470 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/service/WebRtcCallService.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/service/WebRtcCallService.kt @@ -730,11 +730,7 @@ class WebRtcCallService : LifecycleService(), CallManager.WebRtcListener { this, CallNotificationBuilder.WEBRTC_NOTIFICATION, CallNotificationBuilder.getCallInProgressNotification(this, type, recipient), - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { - ServiceInfo.FOREGROUND_SERVICE_TYPE_MICROPHONE - } else { - 0 - } + if (Build.VERSION.SDK_INT >= 30) ServiceInfo.FOREGROUND_SERVICE_TYPE_MICROPHONE else 0 ) } catch (e: IllegalStateException) { Log.e(TAG, "Failed to setCallInProgressNotification as a foreground service for type: ${type}, trying to update instead", e)