catch rare instances of foreground service not allowed to start
This commit is contained in:
parent
205472bcc7
commit
2adff4a92c
|
@ -1367,12 +1367,12 @@ public class XmppConnectionService extends Service {
|
||||||
if (ongoing != null) {
|
if (ongoing != null) {
|
||||||
notification = this.mNotificationService.getOngoingCallNotification(ongoing);
|
notification = this.mNotificationService.getOngoingCallNotification(ongoing);
|
||||||
id = NotificationService.ONGOING_CALL_NOTIFICATION_ID;
|
id = NotificationService.ONGOING_CALL_NOTIFICATION_ID;
|
||||||
startForeground(id, notification);
|
startForegroundOrCatch(id, notification);
|
||||||
mNotificationService.cancel(NotificationService.FOREGROUND_NOTIFICATION_ID);
|
mNotificationService.cancel(NotificationService.FOREGROUND_NOTIFICATION_ID);
|
||||||
} else {
|
} else {
|
||||||
notification = this.mNotificationService.createForegroundNotification();
|
notification = this.mNotificationService.createForegroundNotification();
|
||||||
id = NotificationService.FOREGROUND_NOTIFICATION_ID;
|
id = NotificationService.FOREGROUND_NOTIFICATION_ID;
|
||||||
startForeground(id, notification);
|
startForegroundOrCatch(id, notification);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!mForceForegroundService.get()) {
|
if (!mForceForegroundService.get()) {
|
||||||
|
@ -1392,6 +1392,14 @@ public class XmppConnectionService extends Service {
|
||||||
Log.d(Config.LOGTAG, "ForegroundService: " + (status ? "on" : "off"));
|
Log.d(Config.LOGTAG, "ForegroundService: " + (status ? "on" : "off"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void startForegroundOrCatch(final int id, final Notification notification) {
|
||||||
|
try {
|
||||||
|
startForeground(id, notification);
|
||||||
|
} catch (final IllegalStateException e) {
|
||||||
|
Log.e(Config.LOGTAG,"Could not start foreground service", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public boolean foregroundNotificationNeedsUpdatingWhenErrorStateChanges() {
|
public boolean foregroundNotificationNeedsUpdatingWhenErrorStateChanges() {
|
||||||
return !mForceForegroundService.get() && ongoingCall.get() == null && Compatibility.keepForegroundService(this) && hasEnabledAccounts();
|
return !mForceForegroundService.get() && ongoingCall.get() == null && Compatibility.keepForegroundService(this) && hasEnabledAccounts();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue