Commit c0b4e54e authored by Min Qin's avatar Min Qin Committed by Commit Bot

Fix a crash that startForeground is not called after startForegroundService() call

BUG=826998

Change-Id: Ifcd496ae29831730b1a960478ad42eea8246c2ef
Reviewed-on: https://chromium-review.googlesource.com/1128564
Commit-Queue: Min Qin <qinmin@chromium.org>
Reviewed-by: default avatarMounir Lamouri <mlamouri@chromium.org>
Cr-Commit-Position: refs/heads/master@{#574215}
parent 2e3a96d3
......@@ -341,7 +341,13 @@ public class MediaNotificationManager {
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Log.i(TAG, "onStartCommand, intent: " + intent);
if (!processIntent(intent)) stopListenerService();
if (!processIntent(intent)) {
// The service has been started with startForegroundService() but the
// notification hasn't been shown. On O it will lead to the app crash.
// So show an empty notification before stopping the service.
finishStartingForegroundService(this);
stopListenerService();
}
return START_NOT_STICKY;
}
......@@ -366,16 +372,9 @@ public class MediaNotificationManager {
if (intent == null) return false;
MediaNotificationManager manager = getManager();
if (manager == null || manager.mMediaNotificationInfo == null) {
if (intent.getAction() == null) {
// The service has been started with startForegroundService() but the
// notification hasn't been shown. On O it will lead to the app crash.
// So show an empty notification before stopping the service.
finishStartingForegroundService(this);
}
return false;
}
if (manager == null || manager.mMediaNotificationInfo == null) return false;
Log.i(TAG, "process intent, intent Action:" + intent.getAction());
if (intent.getAction() == null) {
// The intent comes from {@link AppHooks#startForegroundService}.
manager.onServiceStarted(this);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment