Prevent calls crashing due to background restrictions.
This commit is contained in:
parent
a63fd5a584
commit
919648b94b
3 changed files with 15 additions and 1 deletions
|
@ -35,6 +35,7 @@ import org.thoughtcrime.securesms.permissions.Permissions
|
|||
import org.thoughtcrime.securesms.recipients.Recipient
|
||||
import org.thoughtcrime.securesms.recipients.RecipientId
|
||||
import org.thoughtcrime.securesms.service.SafeForegroundService
|
||||
import org.thoughtcrime.securesms.util.DeviceProperties
|
||||
import org.thoughtcrime.securesms.util.TelephonyUtil
|
||||
import org.thoughtcrime.securesms.webrtc.CallNotificationBuilder
|
||||
import org.thoughtcrime.securesms.webrtc.UncaughtExceptionHandlerManager
|
||||
|
@ -147,6 +148,8 @@ class ActiveCallManager(
|
|||
private var previousNotificationDisposable = Disposable.disposed()
|
||||
|
||||
init {
|
||||
Log.i(TAG, "init(bkgRestricted: ${DeviceProperties.isBackgroundRestricted()})")
|
||||
|
||||
registerUncaughtExceptionHandler()
|
||||
registerNetworkReceiver()
|
||||
|
||||
|
@ -266,6 +269,8 @@ class ActiveCallManager(
|
|||
/** Foreground service started only after a call is established */
|
||||
class ActiveCallForegroundService : SafeForegroundService() {
|
||||
companion object {
|
||||
private const val TAG = "ActiveCallService"
|
||||
|
||||
private const val EXTRA_RECIPIENT_ID = "RECIPIENT_ID"
|
||||
private const val EXTRA_IS_VIDEO_CALL = "IS_VIDEO_CALL"
|
||||
private const val EXTRA_TYPE = "TYPE"
|
||||
|
|
|
@ -10,6 +10,7 @@ import androidx.annotation.NonNull;
|
|||
import androidx.annotation.RequiresApi;
|
||||
|
||||
import org.signal.core.util.logging.Log;
|
||||
import org.thoughtcrime.securesms.dependencies.AppDependencies;
|
||||
|
||||
/**
|
||||
* Easy access to various properties of the device, typically to make performance-related decisions.
|
||||
|
@ -65,6 +66,13 @@ public final class DeviceProperties {
|
|||
return info;
|
||||
}
|
||||
|
||||
public static boolean isBackgroundRestricted() {
|
||||
if (Build.VERSION.SDK_INT >= 28) {
|
||||
return isBackgroundRestricted(AppDependencies.getApplication());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@RequiresApi(28)
|
||||
public static boolean isBackgroundRestricted(@NonNull Context context) {
|
||||
ActivityManager activityManager = ServiceUtil.getActivityManager(context);
|
||||
|
|
|
@ -20,6 +20,7 @@ import org.thoughtcrime.securesms.notifications.NotificationChannels;
|
|||
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||
import org.thoughtcrime.securesms.service.webrtc.ActiveCallManager;
|
||||
import org.thoughtcrime.securesms.util.ConversationUtil;
|
||||
import org.thoughtcrime.securesms.util.DeviceProperties;
|
||||
|
||||
/**
|
||||
* Manages the state of the WebRtc items in the Android notification bar.
|
||||
|
@ -232,6 +233,6 @@ public class CallNotificationBuilder {
|
|||
}
|
||||
|
||||
private static boolean deviceVersionSupportsIncomingCallStyle() {
|
||||
return Build.VERSION.SDK_INT >= API_LEVEL_CALL_STYLE;
|
||||
return Build.VERSION.SDK_INT >= API_LEVEL_CALL_STYLE && !DeviceProperties.isBackgroundRestricted();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue