Potentially resolve bad service starts on BOOT_COMPLETED.

This commit is contained in:
Greyson Parrelli
2026-07-17 09:20:20 -04:00
parent 7ad05dd53c
commit 28d2dee617
2 changed files with 41 additions and 6 deletions
@@ -18,12 +18,14 @@ package org.thoughtcrime.securesms.service;
import android.annotation.SuppressLint;
import android.app.AlarmManager;
import android.app.ForegroundServiceStartNotAllowedException;
import android.app.Notification;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.os.Binder;
import android.os.Build;
import android.os.IBinder;
import android.os.SystemClock;
@@ -285,7 +287,16 @@ public class KeyCachingService extends Service {
builder.setContentIntent(buildLaunchIntent());
stopForeground(true);
startForeground(SERVICE_RUNNING_ID, builder.build());
try {
startForeground(SERVICE_RUNNING_ID, builder.build());
} catch (Exception e) {
if (Build.VERSION.SDK_INT >= 31 && e instanceof ForegroundServiceStartNotAllowedException) {
Log.w(TAG, "Not allowed to start foreground service.", e);
} else {
throw e;
}
}
}
private void broadcastNewSecret() {