Commit b4cc1de2 authored by Thoren Paulson's avatar Thoren Paulson Committed by Commit Bot

[Chromecast] Don't run stop if we didn't start.

When an app starts in background mode and then stops without being
displayed, the service-based path crashed due to calling unbindService
without calling bindService. This change prevents stop logic from being
called if start was never called.

BUG=internal 63015237
TEST=cast_shell_junit_tests

Change-Id: I8a89580927972b13d6b0842972805853b8c5bbb7
Reviewed-on: https://chromium-review.googlesource.com/576196Reviewed-by: default avatarLuke Halliwell <halliwell@chromium.org>
Commit-Queue: Thoren Paulson <thoren@chromium.org>
Cr-Commit-Position: refs/heads/master@{#487641}
parent 2ec63638
...@@ -137,6 +137,7 @@ public class CastWebContentsComponent { ...@@ -137,6 +137,7 @@ public class CastWebContentsComponent {
private OnKeyDownHandler mKeyDownHandler; private OnKeyDownHandler mKeyDownHandler;
private Receiver mReceiver; private Receiver mReceiver;
private String mInstanceId; private String mInstanceId;
private boolean mStarted = false;
public CastWebContentsComponent(String instanceId, public CastWebContentsComponent(String instanceId,
OnComponentClosedHandler onComponentClosedHandler, OnKeyDownHandler onKeyDownHandler) { OnComponentClosedHandler onComponentClosedHandler, OnKeyDownHandler onKeyDownHandler) {
...@@ -164,13 +165,17 @@ public class CastWebContentsComponent { ...@@ -164,13 +165,17 @@ public class CastWebContentsComponent {
LocalBroadcastManager.getInstance(context).registerReceiver(mReceiver, filter); LocalBroadcastManager.getInstance(context).registerReceiver(mReceiver, filter);
mDelegate.start(context, webContents); mDelegate.start(context, webContents);
mStarted = true;
} }
public void stop(Context context) { public void stop(Context context) {
if (DEBUG) Log.d(TAG, "stop"); if (DEBUG) Log.d(TAG, "stop");
if (mStarted) {
LocalBroadcastManager.getInstance(context).unregisterReceiver(mReceiver); LocalBroadcastManager.getInstance(context).unregisterReceiver(mReceiver);
mDelegate.stop(context); mDelegate.stop(context);
mStarted = false;
}
} }
public static void onComponentClosed(Context context, String instanceId) { public static void onComponentClosed(Context context, String instanceId) {
......
...@@ -6,6 +6,7 @@ package org.chromium.chromecast.shell; ...@@ -6,6 +6,7 @@ package org.chromium.chromecast.shell;
import static org.mockito.Mockito.any; import static org.mockito.Mockito.any;
import static org.mockito.Mockito.eq; import static org.mockito.Mockito.eq;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
import android.app.Activity; import android.app.Activity;
...@@ -141,4 +142,13 @@ public class CastWebContentsComponentTest { ...@@ -141,4 +142,13 @@ public class CastWebContentsComponentTest {
verify(callback).onKeyDown(42); verify(callback).onKeyDown(42);
} }
@Test
public void testStopDoesNotUnbindServiceIfStartWasNotCalled() {
CastWebContentsComponent component = new CastWebContentsComponent(INSTANCE_ID, null, null);
component.stop(mActivity);
verify(mActivity, never()).unbindService(any(ServiceConnection.class));
}
} }
\ No newline at end of file
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