Fix stopForegroundTask crash.
This commit is contained in:
parent
332c4ca26e
commit
ad196bf03c
2 changed files with 4 additions and 3 deletions
|
@ -187,13 +187,13 @@ public final class GenericForegroundService extends Service {
|
|||
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.setAction(ACTION_STOP);
|
||||
intent.putExtra(EXTRA_ID, 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) {
|
||||
|
|
|
@ -9,6 +9,7 @@ import android.os.IBinder;
|
|||
import androidx.annotation.NonNull;
|
||||
|
||||
import org.signal.core.util.logging.Log;
|
||||
import org.thoughtcrime.securesms.jobs.UnableToStartException;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
|
@ -54,7 +55,7 @@ public final class NotificationController implements AutoCloseable,
|
|||
}
|
||||
|
||||
GenericForegroundService.stopForegroundTask(context, id);
|
||||
} catch (IllegalArgumentException e) {
|
||||
} catch (IllegalStateException | UnableToStartException e) {
|
||||
Log.w(TAG, "Failed to unbind service...", e);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue