Fix stopForegroundTask crash.

This commit is contained in:
Clark 2023-06-14 10:54:21 -04:00 committed by GitHub
parent 332c4ca26e
commit ad196bf03c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 3 deletions

View file

@ -187,13 +187,13 @@ public final class GenericForegroundService extends Service {
return new NotificationController(context, id); return new NotificationController(context, id);
} }
public static void stopForegroundTask(@NonNull Context context, int id) { public static void stopForegroundTask(@NonNull Context context, int id) throws UnableToStartException, IllegalStateException {
Intent intent = new Intent(context, GenericForegroundService.class); Intent intent = new Intent(context, GenericForegroundService.class);
intent.setAction(ACTION_STOP); intent.setAction(ACTION_STOP);
intent.putExtra(EXTRA_ID, id); intent.putExtra(EXTRA_ID, id);
Log.i(TAG, String.format(Locale.US, "Stopping foreground service id=%d", id)); Log.i(TAG, String.format(Locale.US, "Stopping foreground service id=%d", id));
ForegroundServiceUtil.startWhenCapableOrThrow(context, intent); ForegroundServiceUtil.startWhenCapable(context, intent);
} }
synchronized void replaceTitle(int id, @NonNull String title) { synchronized void replaceTitle(int id, @NonNull String title) {

View file

@ -9,6 +9,7 @@ import android.os.IBinder;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import org.signal.core.util.logging.Log; import org.signal.core.util.logging.Log;
import org.thoughtcrime.securesms.jobs.UnableToStartException;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
@ -54,7 +55,7 @@ public final class NotificationController implements AutoCloseable,
} }
GenericForegroundService.stopForegroundTask(context, id); GenericForegroundService.stopForegroundTask(context, id);
} catch (IllegalArgumentException e) { } catch (IllegalStateException | UnableToStartException e) {
Log.w(TAG, "Failed to unbind service...", e); Log.w(TAG, "Failed to unbind service...", e);
} }
} }