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 {
// A helper to automatically pause the media session when a user removes headphones.
private BroadcastReceiver mAudioBecomingNoisyReceiver;
public MediaSessionService() {
if (WebLayer.getSupportedMajorVersionInternal() < 85) {
throw new UnsupportedOperationException();
}
}
@Override
public IBinder onBind(Intent intent) {
return null;
......@@ -40,6 +34,11 @@ public class MediaSessionService extends Service {
public void onCreate() {
super.onCreate();
if (!WebLayer.hasWebLayerInitializationStarted()) {
stopSelf();
return;
}
mAudioBecomingNoisyReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
......@@ -61,6 +60,8 @@ public class MediaSessionService extends Service {
public void onDestroy() {
super.onDestroy();
if (mAudioBecomingNoisyReceiver == null) return;
try {
getWebLayer().getImpl().onMediaSessionServiceDestroyed();
} catch (RemoteException e) {
......@@ -73,7 +74,10 @@ public class MediaSessionService extends Service {
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
try {
getWebLayer().getImpl().onMediaSessionServiceStarted(ObjectWrapper.wrap(this), intent);
if (WebLayer.hasWebLayerInitializationStarted()) {
getWebLayer().getImpl().onMediaSessionServiceStarted(
ObjectWrapper.wrap(this), intent);
}
} catch (RemoteException e) {
throw new RuntimeException(e);
}
......
......@@ -157,6 +157,11 @@ public class WebLayer {
return sLoader;
}
/** Returns whether WebLayer loading has at least started. */
static boolean hasWebLayerInitializationStarted() {
return sLoader != null;
}
IWebLayer getImpl() {
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