Prevent calling service crash loop when system restarts us in background.

This commit is contained in:
Cody Henthorne
2024-01-17 15:48:36 -05:00
committed by Greyson Parrelli
parent ae884d79a1
commit bc5d27ed90

View File

@@ -178,7 +178,7 @@ public final class WebRtcCallService extends Service implements SignalAudioManag
@Override @Override
public int onStartCommand(Intent intent, int flags, int startId) { public int onStartCommand(Intent intent, int flags, int startId) {
if (intent == null || intent.getAction() == null) { if (intent == null || intent.getAction() == null) {
setCallNotification(true); Log.w(TAG, "Service running with null intent/action likely from system restart, stopping");
stop(); stop();
return START_NOT_STICKY; return START_NOT_STICKY;
} }
@@ -234,9 +234,11 @@ public final class WebRtcCallService extends Service implements SignalAudioManag
if (!stopping && lastNotificationId != INVALID_NOTIFICATION_ID) { if (!stopping && lastNotificationId != INVALID_NOTIFICATION_ID) {
startForegroundCompat(lastNotificationId, lastNotification); startForegroundCompat(lastNotificationId, lastNotification);
} else { } else {
Log.w(TAG, "Service running without having called start first, show temp notification and terminate service."); if (!stopping) {
startForegroundCompat(CallNotificationBuilder.getStartingStoppingNotificationId(), CallNotificationBuilder.getStoppingNotification(this)); Log.i(TAG, "Service was started without calling UPDATE first, using temporary notification.");
stop(); }
startForegroundCompat(CallNotificationBuilder.getStartingStoppingNotificationId(), stopping ? CallNotificationBuilder.getStoppingNotification(this)
: CallNotificationBuilder.getStartingNotification(this));
} }
} }