Fix crash around unbinding GenericForegroundService.

fork-5.53.8
Greyson Parrelli 2022-04-27 10:34:04 -04:00
rodzic ebf2ef65e2
commit 08ac99b4c1
1 zmienionych plików z 16 dodań i 5 usunięć

Wyświetl plik

@ -24,6 +24,7 @@ public final class NotificationController implements AutoCloseable,
private int progressMax;
private boolean indeterminate;
private long percent = -1;
private boolean isBound;
private final AtomicReference<GenericForegroundService> service = new AtomicReference<>();
@ -31,11 +32,11 @@ public final class NotificationController implements AutoCloseable,
this.context = context;
this.id = id;
bindToService();
isBound = bindToService();
}
private void bindToService() {
context.bindService(new Intent(context, GenericForegroundService.class), this, Context.BIND_AUTO_CREATE);
private boolean bindToService() {
return context.bindService(new Intent(context, GenericForegroundService.class), this, Context.BIND_AUTO_CREATE);
}
public int getId() {
@ -44,8 +45,18 @@ public final class NotificationController implements AutoCloseable,
@Override
public void close() {
context.unbindService(this);
GenericForegroundService.stopForegroundTask(context, id);
try {
if (isBound) {
context.unbindService(this);
isBound = false;
} else {
Log.w(TAG, "Service was not bound at the time of close()...");
}
GenericForegroundService.stopForegroundTask(context, id);
} catch (IllegalArgumentException e) {
Log.w(TAG, "Failed to unbind service...", e);
}
}
public void setIndeterminateProgress() {