diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 7e04ad44ca..91d9572f90 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -125,7 +125,7 @@
-
-
+
diff --git a/app/src/main/java/org/thoughtcrime/securesms/home/HomeActivity.kt b/app/src/main/java/org/thoughtcrime/securesms/home/HomeActivity.kt
index a971a5a1a6..74ce5638da 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/home/HomeActivity.kt
+++ b/app/src/main/java/org/thoughtcrime/securesms/home/HomeActivity.kt
@@ -143,8 +143,6 @@ class HomeActivity : PassphraseRequiredActionBarActivity(),
override fun onCreate(savedInstanceState: Bundle?, isReady: Boolean) {
super.onCreate(savedInstanceState, isReady)
- if (!isTaskRoot) { finish(); return }
-
// Set content view
binding = ActivityHomeBinding.inflate(layoutInflater)
setContentView(binding.root)
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/java/org/thoughtcrime/securesms/service/GenericForegroundService.java b/app/src/main/java/org/thoughtcrime/securesms/service/GenericForegroundService.java
deleted file mode 100644
index 52a259d5be..0000000000
--- a/app/src/main/java/org/thoughtcrime/securesms/service/GenericForegroundService.java
+++ /dev/null
@@ -1,128 +0,0 @@
-package org.thoughtcrime.securesms.service;
-
-
-import android.app.PendingIntent;
-import android.app.Service;
-import android.content.Context;
-import android.content.Intent;
-import android.os.IBinder;
-
-import androidx.annotation.DrawableRes;
-import androidx.annotation.NonNull;
-import androidx.annotation.Nullable;
-import androidx.core.app.NotificationCompat;
-import androidx.core.content.ContextCompat;
-
-import org.session.libsignal.utilities.Log;
-import org.session.libsignal.utilities.guava.Preconditions;
-import org.thoughtcrime.securesms.home.HomeActivity;
-import org.thoughtcrime.securesms.notifications.NotificationChannels;
-
-import network.loki.messenger.R;
-
-public class GenericForegroundService extends Service {
-
- private static final String TAG = GenericForegroundService.class.getSimpleName();
-
- private static final int NOTIFICATION_ID = 827353982;
- private static final String EXTRA_TITLE = "extra_title";
- private static final String EXTRA_CHANNEL_ID = "extra_channel_id";
- private static final String EXTRA_ICON_RES = "extra_icon_res";
-
- private static final String ACTION_START = "start";
- private static final String ACTION_STOP = "stop";
-
- private int foregroundCount;
- private String activeTitle;
- private String activeChannelId;
- private int activeIconRes;
-
- @Override
- public void onCreate() {
-
- }
-
- @Override
- public int onStartCommand(Intent intent, int flags, int startId) {
- synchronized (GenericForegroundService.class) {
- if (intent != null && ACTION_START.equals(intent.getAction())) handleStart(intent);
- else if (intent != null && ACTION_STOP.equals(intent.getAction())) handleStop();
- else throw new IllegalStateException("Action needs to be START or STOP.");
-
- return START_NOT_STICKY;
- }
- }
-
-
- private void handleStart(@NonNull Intent intent) {
- String title = Preconditions.checkNotNull(intent.getStringExtra(EXTRA_TITLE));
- String channelId = Preconditions.checkNotNull(intent.getStringExtra(EXTRA_CHANNEL_ID));
- int iconRes = intent.getIntExtra(EXTRA_ICON_RES, R.drawable.ic_notification);
-
- Log.i(TAG, "handleStart() Title: " + title + " ChannelId: " + channelId);
-
- foregroundCount++;
-
- if (foregroundCount == 1) {
- Log.d(TAG, "First request. Title: " + title + " ChannelId: " + channelId);
- activeTitle = title;
- activeChannelId = channelId;
- activeIconRes = iconRes;
- }
-
- postObligatoryForegroundNotification(activeTitle, activeChannelId, activeIconRes);
- }
-
- private void handleStop() {
- Log.i(TAG, "handleStop()");
-
- postObligatoryForegroundNotification(activeTitle, activeChannelId, activeIconRes);
-
- foregroundCount--;
-
- if (foregroundCount == 0) {
- Log.d(TAG, "Last request. Ending foreground service.");
- stopForeground(true);
- stopSelf();
- }
- }
-
- private void postObligatoryForegroundNotification(String title, String channelId, @DrawableRes int iconRes) {
- startForeground(NOTIFICATION_ID, new NotificationCompat.Builder(this, channelId)
- .setSmallIcon(iconRes)
- .setContentTitle(title)
- .setContentIntent(PendingIntent.getActivity(this, 0, new Intent(this, HomeActivity.class), PendingIntent.FLAG_IMMUTABLE))
- .build());
- }
-
- @Nullable
- @Override
- public IBinder onBind(Intent intent) {
- return null;
- }
-
- public static void startForegroundTask(@NonNull Context context, @NonNull String task) {
- startForegroundTask(context, task, NotificationChannels.OTHER);
- }
-
- public static void startForegroundTask(@NonNull Context context, @NonNull String task, @NonNull String channelId) {
- startForegroundTask(context, task, channelId, R.drawable.ic_notification);
- }
-
- public static void startForegroundTask(@NonNull Context context, @NonNull String task, @NonNull String channelId, @DrawableRes int iconRes) {
- Intent intent = new Intent(context, GenericForegroundService.class);
- intent.setAction(ACTION_START);
- intent.putExtra(EXTRA_TITLE, task);
- intent.putExtra(EXTRA_CHANNEL_ID, channelId);
- intent.putExtra(EXTRA_ICON_RES, iconRes);
-
- ContextCompat.startForegroundService(context, intent);
- }
-
- public static void stopForegroundTask(@NonNull Context context) {
- Intent intent = new Intent(context, GenericForegroundService.class);
- intent.setAction(ACTION_STOP);
-
- ContextCompat.startForegroundService(context, intent);
- }
-}
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..cf250665ef 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);
+
+ int type = 0;
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());
+ 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..78f1a55470 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,11 @@ 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 >= 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)
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