Commit 52da2312 authored by Evan Stade's avatar Evan Stade Committed by Commit Bot

Abort rather than crashing when MediaSessionService is started w/o WL.

When an intent attempts to start MediaSessionService but WebLayer has
not been loaded, the service will no-op instead of throwing an
exception.

Bug: b/167388918
Change-Id: I0f191d0f620016c8ee072e0953d10ad1c257fa15
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2388404Reviewed-by: default avatarScott Violet <sky@chromium.org>
Reviewed-by: default avatarClark DuVall <cduvall@chromium.org>
Commit-Queue: Evan Stade <estade@chromium.org>
Cr-Commit-Position: refs/heads/master@{#803594}
parent 072cf1bf
...@@ -25,12 +25,6 @@ public class MediaSessionService extends Service { ...@@ -25,12 +25,6 @@ public class MediaSessionService extends Service {
// A helper to automatically pause the media session when a user removes headphones. // A helper to automatically pause the media session when a user removes headphones.
private BroadcastReceiver mAudioBecomingNoisyReceiver; private BroadcastReceiver mAudioBecomingNoisyReceiver;
public MediaSessionService() {
if (WebLayer.getSupportedMajorVersionInternal() < 85) {
throw new UnsupportedOperationException();
}
}
@Override @Override
public IBinder onBind(Intent intent) { public IBinder onBind(Intent intent) {
return null; return null;
...@@ -40,6 +34,11 @@ public class MediaSessionService extends Service { ...@@ -40,6 +34,11 @@ public class MediaSessionService extends Service {
public void onCreate() { public void onCreate() {
super.onCreate(); super.onCreate();
if (!WebLayer.hasWebLayerInitializationStarted()) {
stopSelf();
return;
}
mAudioBecomingNoisyReceiver = new BroadcastReceiver() { mAudioBecomingNoisyReceiver = new BroadcastReceiver() {
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
...@@ -61,6 +60,8 @@ public class MediaSessionService extends Service { ...@@ -61,6 +60,8 @@ public class MediaSessionService extends Service {
public void onDestroy() { public void onDestroy() {
super.onDestroy(); super.onDestroy();
if (mAudioBecomingNoisyReceiver == null) return;
try { try {
getWebLayer().getImpl().onMediaSessionServiceDestroyed(); getWebLayer().getImpl().onMediaSessionServiceDestroyed();
} catch (RemoteException e) { } catch (RemoteException e) {
...@@ -73,7 +74,10 @@ public class MediaSessionService extends Service { ...@@ -73,7 +74,10 @@ public class MediaSessionService extends Service {
@Override @Override
public int onStartCommand(Intent intent, int flags, int startId) { public int onStartCommand(Intent intent, int flags, int startId) {
try { try {
getWebLayer().getImpl().onMediaSessionServiceStarted(ObjectWrapper.wrap(this), intent); if (WebLayer.hasWebLayerInitializationStarted()) {
getWebLayer().getImpl().onMediaSessionServiceStarted(
ObjectWrapper.wrap(this), intent);
}
} catch (RemoteException e) { } catch (RemoteException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
......
...@@ -157,6 +157,11 @@ public class WebLayer { ...@@ -157,6 +157,11 @@ public class WebLayer {
return sLoader; return sLoader;
} }
/** Returns whether WebLayer loading has at least started. */
static boolean hasWebLayerInitializationStarted() {
return sLoader != null;
}
IWebLayer getImpl() { IWebLayer getImpl() {
return mImpl; return mImpl;
} }
......
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