Commit 6809fabe authored by Thoren Paulson's avatar Thoren Paulson Committed by Commit Bot

[Chromecast] Use turn_on_screen param.

In some situations we should not turn on the screen, such as launching
an app that supports audio-only devices on a device that can play audio
without the screen on.

Bug: internal b/110169298
Test: test on Sony TV
Change-Id: I3615f2fa7ac696b4d6843a4f560572b27ab39d8f
Reviewed-on: https://chromium-review.googlesource.com/1180363Reviewed-by: default avatarSimeon Anfinrud <sanfin@chromium.org>
Reviewed-by: default avatarLuke Halliwell <halliwell@chromium.org>
Commit-Queue: Thoren Paulson <thoren@chromium.org>
Cr-Commit-Position: refs/heads/master@{#584782}
parent 7acbe2e5
......@@ -37,20 +37,22 @@ public class CastContentWindowAndroid implements CastWebContentsComponent.OnComp
@SuppressWarnings("unused")
@CalledByNative
private static CastContentWindowAndroid create(long nativeCastContentWindowAndroid,
boolean isHeadless, boolean enableTouchInput, boolean isRemoteControlMode) {
boolean isHeadless, boolean enableTouchInput, boolean isRemoteControlMode,
boolean turnOnScreen) {
return new CastContentWindowAndroid(nativeCastContentWindowAndroid,
ContextUtils.getApplicationContext(), isHeadless, enableTouchInput,
isRemoteControlMode);
isRemoteControlMode, turnOnScreen);
}
private CastContentWindowAndroid(long nativeCastContentWindowAndroid, final Context context,
boolean isHeadless, boolean enableTouchInput, boolean isRemoteControlMode) {
boolean isHeadless, boolean enableTouchInput, boolean isRemoteControlMode,
boolean turnOnScreen) {
mNativeCastContentWindowAndroid = nativeCastContentWindowAndroid;
mContext = context;
mInstanceId = Integer.toString(sInstanceId++);
// TODO call nativeGetId() to set ID to CastWebContentsComponent.
mComponent = new CastWebContentsComponent(
mInstanceId, this, this, this, isHeadless, enableTouchInput, isRemoteControlMode);
mComponent = new CastWebContentsComponent(mInstanceId, this, this, this, isHeadless,
enableTouchInput, isRemoteControlMode, turnOnScreen);
}
@SuppressWarnings("unused")
......
......@@ -14,6 +14,7 @@ import android.os.Bundle;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.FrameLayout;
import android.widget.Toast;
......@@ -77,12 +78,6 @@ public class CastWebContentsActivity extends Activity {
mIsFinishingState.set("Failed to initialize browser");
}
// Set flags to both exit sleep mode when this activity starts and
// avoid entering sleep mode while playing media. We cannot distinguish
// between video and audio so this applies to both.
getWindow().addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
setContentView(R.layout.cast_web_contents_activity);
mSurfaceHelper = new CastWebContentsSurfaceHelper(this, /* hostActivity */
......@@ -93,6 +88,17 @@ public class CastWebContentsActivity extends Activity {
(Uri uri) -> mIsFinishingState.set("Delayed teardown for URI: " + uri));
}));
mCreatedState.map(x -> getWindow())
.and(mGotIntentState)
.watch(Observers.onEnter(Both.adapt((Window window, Intent intent) -> {
// Set flags to both exit sleep mode when this activity starts and
// avoid entering sleep mode while playing media. If an app that shouldn't turn
// on the screen is launching, we don't add TURN_SCREEN_ON.
if (CastWebContentsIntentUtils.shouldTurnOnScreen(intent))
window.addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
})));
// Initialize the audio manager in onCreate() if tests haven't already.
mCreatedState.and(Observable.not(mAudioManagerState)).watch(Observers.onEnter(() -> {
mAudioManagerState.set(CastAudioManager.getAudioManager(this));
......
......@@ -73,15 +73,11 @@ public class CastWebContentsComponent {
private static final String TAG = "cr_CastWebContent_AD";
private boolean mStarted = false;
public ActivityDelegate(boolean enableTouchInput) {
mEnableTouchInput = enableTouchInput;
}
@Override
public void start(StartParams params) {
if (mStarted) return; // No-op if already started.
if (DEBUG) Log.d(TAG, "start: SHOW_WEB_CONTENT in activity");
startCastActivity(params.context, params.webContents, mEnableTouchInput);
startCastActivity(params.context, params.webContents, mEnableTouchInput, mTurnOnScreen);
mStarted = true;
}
......@@ -95,17 +91,14 @@ public class CastWebContentsComponent {
private class FragmentDelegate implements Delegate {
private static final String TAG = "cr_CastWebContent_FD";
public FragmentDelegate(boolean enableTouchInput) {
mEnableTouchInput = enableTouchInput;
}
@Override
public void start(StartParams params) {
if (!sendIntent(CastWebContentsIntentUtils.requestStartCastFragment(params.webContents,
params.appId, params.visibilityPriority, mEnableTouchInput, mInstanceId,
mIsRemoteControlMode))) {
mIsRemoteControlMode, mTurnOnScreen))) {
// No intent receiver to handle SHOW_WEB_CONTENT in fragment
startCastActivity(params.context, params.webContents, mEnableTouchInput);
startCastActivity(
params.context, params.webContents, mEnableTouchInput, mTurnOnScreen);
}
}
......@@ -115,9 +108,10 @@ public class CastWebContentsComponent {
}
}
private void startCastActivity(Context context, WebContents webContents, boolean enableTouch) {
private void startCastActivity(
Context context, WebContents webContents, boolean enableTouch, boolean turnOnScreen) {
Intent intent = CastWebContentsIntentUtils.requestStartCastActivity(
context, webContents, enableTouch, mInstanceId);
context, webContents, enableTouch, turnOnScreen, mInstanceId);
if (DEBUG) Log.d(TAG, "start activity by intent: " + intent);
context.startActivity(intent);
}
......@@ -170,32 +164,36 @@ public class CastWebContentsComponent {
private boolean mStarted;
private boolean mEnableTouchInput;
private final boolean mIsRemoteControlMode;
private final boolean mTurnOnScreen;
public CastWebContentsComponent(String instanceId,
OnComponentClosedHandler onComponentClosedHandler, OnKeyDownHandler onKeyDownHandler,
SurfaceEventHandler surfaceEventHandler, boolean isHeadless, boolean enableTouchInput,
boolean isRemoteControlMode) {
boolean isRemoteControlMode, boolean turnOnScreen) {
if (DEBUG) {
Log.d(TAG,
"New CastWebContentsComponent. Instance ID: " + instanceId + "; isHeadless: "
+ isHeadless + "; enableTouchInput:" + enableTouchInput
+ "; isRemoteControlMode:" + isRemoteControlMode);
}
mComponentClosedHandler = onComponentClosedHandler;
mEnableTouchInput = enableTouchInput;
mKeyDownHandler = onKeyDownHandler;
mInstanceId = instanceId;
mSurfaceEventHandler = surfaceEventHandler;
mIsRemoteControlMode = isRemoteControlMode;
mTurnOnScreen = turnOnScreen;
if (BuildConfig.DISPLAY_WEB_CONTENTS_IN_SERVICE || isHeadless) {
if (DEBUG) Log.d(TAG, "Creating service delegate...");
mDelegate = new ServiceDelegate();
} else if (BuildConfig.ENABLE_CAST_FRAGMENT) {
if (DEBUG) Log.d(TAG, "Creating fragment delegate...");
mDelegate = new FragmentDelegate(enableTouchInput);
mDelegate = new FragmentDelegate();
} else {
if (DEBUG) Log.d(TAG, "Creating activity delegate...");
mDelegate = new ActivityDelegate(enableTouchInput);
mDelegate = new ActivityDelegate();
}
mHasWebContentsState.watch(x -> {
......
......@@ -101,6 +101,11 @@ public class CastWebContentsIntentUtils {
static final String INTENT_EXTRA_REMOTE_CONTROL_MODE =
"com.google.android.apps.castshell.intent.extra.REMOTE_CONTROL_MODE";
/** Key for extra value for intent to start web contents. true if the app should turn on the
* display. */
static final String INTENT_EXTRA_TURN_ON_SCREEN =
"com.google.android.apps.castshell.intent.extra.TURN_ON_SCREEN";
/**
* Key of extra value of the intent ACTION_REQUEST_VISIBILITY, value is visibility priority
* (int).
......@@ -278,13 +283,14 @@ public class CastWebContentsIntentUtils {
}
// CastWebContentsComponent.Receiver -> CastWebContentsActivity
public static Intent requestStartCastActivity(
Context context, WebContents webContents, boolean enableTouch, String instanceId) {
public static Intent requestStartCastActivity(Context context, WebContents webContents,
boolean enableTouch, boolean turnOnScreen, String instanceId) {
Intent intent =
new Intent(Intent.ACTION_VIEW, null, context, CastWebContentsActivity.class);
intent.putExtra(INTENT_EXTRA_URI, getInstanceUri(instanceId).toString());
intent.putExtra(INTENT_EXTRA_WEB_CONTENTS, webContents);
intent.putExtra(INTENT_EXTRA_TOUCH_INPUT_ENABLED, enableTouch);
intent.putExtra(INTENT_EXTRA_TURN_ON_SCREEN, turnOnScreen);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP
| Intent.FLAG_ACTIVITY_NO_ANIMATION);
return intent;
......@@ -293,13 +299,14 @@ public class CastWebContentsIntentUtils {
// CastWebContentsComponent.Receiver -> Host activity of CastWebContentsFragment
public static Intent requestStartCastFragment(WebContents webContents, String appId,
int visibilityPriority, boolean enableTouch, String instanceId,
boolean isRemoteControlMode) {
boolean isRemoteControlMode, boolean turnOnScreen) {
Intent intent = new Intent();
intent.setAction(CastIntents.ACTION_SHOW_WEB_CONTENT);
intent.putExtra(INTENT_EXTRA_URI, getInstanceUri(instanceId).toString());
intent.putExtra(INTENT_EXTRA_APP_ID, appId);
intent.putExtra(INTENT_EXTRA_VISIBILITY_PRIORITY, visibilityPriority);
intent.putExtra(INTENT_EXTRA_TOUCH_INPUT_ENABLED, enableTouch);
intent.putExtra(INTENT_EXTRA_TURN_ON_SCREEN, turnOnScreen);
intent.putExtra(INTENT_EXTRA_WEB_CONTENTS, webContents);
intent.putExtra(INTENT_EXTRA_REMOTE_CONTROL_MODE, isRemoteControlMode);
return intent;
......@@ -371,6 +378,11 @@ public class CastWebContentsIntentUtils {
return isRemoteControlMode(in.getExtras());
}
// Used by ACTION_VIEW and ACTION_SHOW_WEB_CONTENT
public static boolean shouldTurnOnScreen(Intent intent) {
return intent.getBooleanExtra(INTENT_EXTRA_TURN_ON_SCREEN, true);
}
// CastWebContentsComponent -> CastWebContentsSurfaceHelper and host activity of
// CastWebContentsFragment
public static Intent enableTouchInput(String instanceId, boolean enabled) {
......
......@@ -27,11 +27,12 @@ base::android::ScopedJavaLocalRef<jobject> CreateJavaWindow(
jlong native_window,
bool is_headless,
bool enable_touch_input,
bool is_remote_control_mode) {
bool is_remote_control_mode,
bool turn_on_screen) {
JNIEnv* env = base::android::AttachCurrentThread();
return Java_CastContentWindowAndroid_create(env, native_window, is_headless,
enable_touch_input,
is_remote_control_mode);
return Java_CastContentWindowAndroid_create(
env, native_window, is_headless, enable_touch_input,
is_remote_control_mode, turn_on_screen);
}
} // namespace
......@@ -48,7 +49,8 @@ CastContentWindowAndroid::CastContentWindowAndroid(
java_window_(CreateJavaWindow(reinterpret_cast<jlong>(this),
params.is_headless,
params.enable_touch_input,
params.is_remote_control_mode)) {
params.is_remote_control_mode,
params.turn_on_screen)) {
DCHECK(delegate_);
}
......
......@@ -14,7 +14,9 @@ import static org.mockito.Mockito.verify;
import android.content.Intent;
import android.media.AudioManager;
import android.view.WindowManager;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
......@@ -45,7 +47,7 @@ public class CastWebContentsActivityTest {
private static Intent defaultIntentForCastWebContentsActivity(WebContents webContents) {
return CastWebContentsIntentUtils.requestStartCastActivity(
RuntimeEnvironment.application, webContents, true, "0");
RuntimeEnvironment.application, webContents, true, true, "0");
}
@Before
......@@ -91,7 +93,7 @@ public class CastWebContentsActivityTest {
CastWebContentsSurfaceHelper surfaceHelper = mock(CastWebContentsSurfaceHelper.class);
WebContents newWebContents = mock(WebContents.class);
Intent intent = CastWebContentsIntentUtils.requestStartCastActivity(
RuntimeEnvironment.application, newWebContents, true, null);
RuntimeEnvironment.application, newWebContents, true, true, null);
intent.removeExtra(CastWebContentsIntentUtils.INTENT_EXTRA_URI);
mActivity.setSurfaceHelperForTesting(surfaceHelper);
mActivityLifecycle.create();
......@@ -104,7 +106,7 @@ public class CastWebContentsActivityTest {
public void testDropsIntentWithoutWebContents() {
CastWebContentsSurfaceHelper surfaceHelper = mock(CastWebContentsSurfaceHelper.class);
Intent intent = CastWebContentsIntentUtils.requestStartCastActivity(
RuntimeEnvironment.application, null, true, "1");
RuntimeEnvironment.application, null, true, true, "1");
mActivity.setSurfaceHelperForTesting(surfaceHelper);
mActivityLifecycle.create();
reset(surfaceHelper);
......@@ -117,7 +119,7 @@ public class CastWebContentsActivityTest {
CastWebContentsSurfaceHelper surfaceHelper = mock(CastWebContentsSurfaceHelper.class);
WebContents newWebContents = mock(WebContents.class);
Intent intent = CastWebContentsIntentUtils.requestStartCastActivity(
RuntimeEnvironment.application, newWebContents, true, "2");
RuntimeEnvironment.application, newWebContents, true, true, "2");
mActivity.setSurfaceHelperForTesting(surfaceHelper);
mActivityLifecycle.create();
reset(surfaceHelper);
......@@ -138,4 +140,39 @@ public class CastWebContentsActivityTest {
mActivityLifecycle.newIntent(intent);
verify(surfaceHelper, never()).onNewStartParams(anyObject());
}
@Test
public void testTurnsScreenOnIfTurnOnScreen() {
mActivityLifecycle = Robolectric.buildActivity(CastWebContentsActivity.class,
CastWebContentsIntentUtils.requestStartCastActivity(
RuntimeEnvironment.application, mWebContents, true, true, "0"));
mActivity = mActivityLifecycle.get();
mActivity.testingModeForTesting();
mShadowActivity = Shadows.shadowOf(mActivity);
mActivityLifecycle.create();
Assert.assertTrue(Shadows.shadowOf(mShadowActivity.getWindow())
.getFlag(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON));
}
@Test
public void testDoesNotTurnScreenOnIfNotTurnOnScreen() {
mActivityLifecycle = Robolectric.buildActivity(CastWebContentsActivity.class,
CastWebContentsIntentUtils.requestStartCastActivity(
RuntimeEnvironment.application, mWebContents, true, false, "0"));
mActivity = mActivityLifecycle.get();
mActivity.testingModeForTesting();
mShadowActivity = Shadows.shadowOf(mActivity);
mActivityLifecycle.create();
Assert.assertFalse(Shadows.shadowOf(mShadowActivity.getWindow())
.getFlag(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON));
}
@Test
public void testSetsKeepScreenOnFlag() {
mActivityLifecycle.create();
Assert.assertTrue(Shadows.shadowOf(mShadowActivity.getWindow())
.getFlag(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON));
}
}
......@@ -67,8 +67,8 @@ public class CastWebContentsComponentTest {
public void testStartStartsWebContentsActivity() {
Assume.assumeFalse(BuildConfig.DISPLAY_WEB_CONTENTS_IN_SERVICE);
CastWebContentsComponent component =
new CastWebContentsComponent(INSTANCE_ID, null, null, null, false, false, false);
CastWebContentsComponent component = new CastWebContentsComponent(
INSTANCE_ID, null, null, null, false, false, false, true);
component.start(mStartParams);
Intent intent = mShadowActivity.getNextStartedActivity();
Assert.assertEquals(
......@@ -86,8 +86,8 @@ public class CastWebContentsComponentTest {
LocalBroadcastManager.getInstance(ContextUtils.getApplicationContext())
.registerReceiver(receiver, intentFilter);
CastWebContentsComponent component =
new CastWebContentsComponent(INSTANCE_ID, null, null, null, false, false, false);
CastWebContentsComponent component = new CastWebContentsComponent(
INSTANCE_ID, null, null, null, false, false, false, true);
component.start(mStartParams);
component.stop(ContextUtils.getApplicationContext());
......@@ -101,8 +101,8 @@ public class CastWebContentsComponentTest {
public void testStartBindsWebContentsService() {
Assume.assumeTrue(BuildConfig.DISPLAY_WEB_CONTENTS_IN_SERVICE);
CastWebContentsComponent component =
new CastWebContentsComponent(INSTANCE_ID, null, null, null, false, false, false);
CastWebContentsComponent component = new CastWebContentsComponent(
INSTANCE_ID, null, null, null, false, false, false, true);
component.start(mStartParams);
component.stop(mActivity);
......@@ -117,8 +117,8 @@ public class CastWebContentsComponentTest {
public void testStopUnbindsWebContentsService() {
Assume.assumeTrue(BuildConfig.DISPLAY_WEB_CONTENTS_IN_SERVICE);
CastWebContentsComponent component =
new CastWebContentsComponent(INSTANCE_ID, null, null, null, false, false, false);
CastWebContentsComponent component = new CastWebContentsComponent(
INSTANCE_ID, null, null, null, false, false, false, true);
component.start(mStartParams);
component.stop(mActivity);
......@@ -135,8 +135,8 @@ public class CastWebContentsComponentTest {
LocalBroadcastManager.getInstance(ContextUtils.getApplicationContext())
.registerReceiver(receiver, intentFilter);
CastWebContentsComponent component =
new CastWebContentsComponent(INSTANCE_ID, null, null, null, false, false, false);
CastWebContentsComponent component = new CastWebContentsComponent(
INSTANCE_ID, null, null, null, false, false, false, true);
component.enableTouchInput(true);
LocalBroadcastManager.getInstance(ContextUtils.getApplicationContext())
......@@ -150,8 +150,8 @@ public class CastWebContentsComponentTest {
Assume.assumeFalse(BuildConfig.DISPLAY_WEB_CONTENTS_IN_SERVICE);
Assume.assumeFalse(BuildConfig.ENABLE_CAST_FRAGMENT);
CastWebContentsComponent component =
new CastWebContentsComponent(INSTANCE_ID, null, null, null, false, false, false);
CastWebContentsComponent component = new CastWebContentsComponent(
INSTANCE_ID, null, null, null, false, false, false, true);
component.enableTouchInput(true);
component.start(mStartParams);
......@@ -166,8 +166,8 @@ public class CastWebContentsComponentTest {
Assume.assumeFalse(BuildConfig.DISPLAY_WEB_CONTENTS_IN_SERVICE);
Assume.assumeFalse(BuildConfig.ENABLE_CAST_FRAGMENT);
CastWebContentsComponent component =
new CastWebContentsComponent(INSTANCE_ID, null, null, null, false, false, false);
CastWebContentsComponent component = new CastWebContentsComponent(
INSTANCE_ID, null, null, null, false, false, false, true);
component.enableTouchInput(false);
component.start(mStartParams);
......@@ -183,7 +183,7 @@ public class CastWebContentsComponentTest {
Mockito.mock(CastWebContentsComponent.OnComponentClosedHandler.class);
CastWebContentsComponent component = new CastWebContentsComponent(
INSTANCE_ID, callback, null, null, false, false, false);
INSTANCE_ID, callback, null, null, false, false, false, true);
component.start(mStartParams);
CastWebContentsComponent.onComponentClosed(INSTANCE_ID);
verify(callback).onComponentClosed();
......@@ -197,7 +197,7 @@ public class CastWebContentsComponentTest {
Mockito.mock(CastWebContentsComponent.OnKeyDownHandler.class);
CastWebContentsComponent component = new CastWebContentsComponent(
INSTANCE_ID, null, callback, null, false, false, false);
INSTANCE_ID, null, callback, null, false, false, false, true);
component.start(mStartParams);
CastWebContentsComponent.onKeyDown(INSTANCE_ID, 42);
component.stop(mActivity);
......@@ -207,8 +207,8 @@ public class CastWebContentsComponentTest {
@Test
public void testStopDoesNotUnbindServiceIfStartWasNotCalled() {
CastWebContentsComponent component =
new CastWebContentsComponent(INSTANCE_ID, null, null, null, false, false, false);
CastWebContentsComponent component = new CastWebContentsComponent(
INSTANCE_ID, null, null, null, false, false, false, true);
component.stop(mActivity);
......@@ -221,7 +221,7 @@ public class CastWebContentsComponentTest {
Mockito.mock(CastWebContentsComponent.SurfaceEventHandler.class);
CastWebContentsComponent component = new CastWebContentsComponent(
INSTANCE_ID, null, null, callback, false, false, false);
INSTANCE_ID, null, null, callback, false, false, false, true);
component.start(mStartParams);
CastWebContentsComponent.onVisibilityChange(INSTANCE_ID, 2);
component.stop(mActivity);
......@@ -235,7 +235,7 @@ public class CastWebContentsComponentTest {
Mockito.mock(CastWebContentsComponent.SurfaceEventHandler.class);
CastWebContentsComponent component = new CastWebContentsComponent(
INSTANCE_ID, null, null, callback, false, false, false);
INSTANCE_ID, null, null, callback, false, false, false, true);
component.start(mStartParams);
CastWebContentsComponent.onGesture(INSTANCE_ID, 1);
component.stop(mActivity);
......@@ -245,8 +245,8 @@ public class CastWebContentsComponentTest {
@Test
public void testStartWebContentsComponentMultipleTimes() {
CastWebContentsComponent component =
new CastWebContentsComponent(INSTANCE_ID, null, null, null, false, false, false);
CastWebContentsComponent component = new CastWebContentsComponent(
INSTANCE_ID, null, null, null, false, false, false, true);
CastWebContentsComponent.Delegate delegate = mock(CastWebContentsComponent.Delegate.class);
component.setDelegate(delegate);
component.start(mStartParams);
......@@ -267,9 +267,9 @@ public class CastWebContentsComponentTest {
// Sending focus events to a started Activity is unnecessary because the Activity is always
// in focus, and issues with onNewIntent() and duplicate detection can cause unintended
// side effects.
CastWebContentsComponent component =
new CastWebContentsComponent(INSTANCE_ID, null, null, null, false, false, false);
component.setDelegate(component.new ActivityDelegate(false));
CastWebContentsComponent component = new CastWebContentsComponent(
INSTANCE_ID, null, null, null, false, false, false, true);
component.setDelegate(component.new ActivityDelegate());
component.start(mStartParams);
Assert.assertEquals(mShadowActivity.getNextStartedActivity().getComponent().getClassName(),
CastWebContentsActivity.class.getName());
......
......@@ -147,7 +147,7 @@ public class CastWebContentsIntentUtilsTest {
@Test
public void testRequestStartCastActivity() {
Intent in = CastWebContentsIntentUtils.requestStartCastActivity(
mActivity, mWebContents, true, INSTANCE_ID);
mActivity, mWebContents, true, true, INSTANCE_ID);
Assert.assertNull(in.getData());
String uri = CastWebContentsIntentUtils.getUriString(in);
Assert.assertNotNull(uri);
......@@ -161,7 +161,7 @@ public class CastWebContentsIntentUtilsTest {
@Test
public void testRequestStartCastFragment() {
Intent in = CastWebContentsIntentUtils.requestStartCastFragment(
mWebContents, APP_ID, 3, true, INSTANCE_ID, true);
mWebContents, APP_ID, 3, true, INSTANCE_ID, true, true);
Assert.assertNull(in.getData());
String uri = CastWebContentsIntentUtils.getUriString(in);
Assert.assertNotNull(uri);
......@@ -215,6 +215,34 @@ public class CastWebContentsIntentUtilsTest {
Assert.assertFalse(CastWebContentsIntentUtils.isTouchable(in));
}
@Test
public void testShouldTurnOnScreenActivityTrue() {
Intent intent = CastWebContentsIntentUtils.requestStartCastActivity(
mActivity, mWebContents, true, true, INSTANCE_ID);
Assert.assertTrue(CastWebContentsIntentUtils.shouldTurnOnScreen(intent));
}
@Test
public void testShouldTurnOnScreenActivityFalse() {
Intent intent = CastWebContentsIntentUtils.requestStartCastActivity(
mActivity, mWebContents, true, false, INSTANCE_ID);
Assert.assertFalse(CastWebContentsIntentUtils.shouldTurnOnScreen(intent));
}
@Test
public void testShouldTurnOnScreenFragmentTrue() {
Intent intent = CastWebContentsIntentUtils.requestStartCastFragment(
mWebContents, APP_ID, 3, true, INSTANCE_ID, true, true);
Assert.assertTrue(CastWebContentsIntentUtils.shouldTurnOnScreen(intent));
}
@Test
public void testShouldTurnOnScreenFragmentFalse() {
Intent intent = CastWebContentsIntentUtils.requestStartCastFragment(
mWebContents, APP_ID, 3, true, INSTANCE_ID, true, false);
Assert.assertFalse(CastWebContentsIntentUtils.shouldTurnOnScreen(intent));
}
@Test
public void testOnWebContentStopped() {
Intent in = CastWebContentsIntentUtils.onWebContentStopped(Uri.parse(EXPECTED_URI));
......@@ -226,14 +254,14 @@ public class CastWebContentsIntentUtilsTest {
@Test
public void testIsRemoteControlModeTrue() {
Intent in = CastWebContentsIntentUtils.requestStartCastFragment(
mWebContents, APP_ID, 3, true, INSTANCE_ID, true);
mWebContents, APP_ID, 3, true, INSTANCE_ID, true, true);
Assert.assertTrue(CastWebContentsIntentUtils.isRemoteControlMode(in));
}
@Test
public void testIsRemoteControlModeFalse() {
Intent in = CastWebContentsIntentUtils.requestStartCastFragment(
mWebContents, APP_ID, 3, false, INSTANCE_ID, false);
mWebContents, APP_ID, 3, false, INSTANCE_ID, false, true);
Assert.assertFalse(CastWebContentsIntentUtils.isRemoteControlMode(in));
}
}
......@@ -126,6 +126,9 @@ class CastContentWindow {
// True if this CastContentWindow is for running a remote control app.
bool is_remote_control_mode = false;
// True if this app should turn on the screen.
bool turn_on_screen = true;
CreateParams();
};
......
......@@ -104,6 +104,9 @@ class CastWebView {
// Whether this CastWebView should be managed by web ui window manager.
bool managed = true;
// True if this app should turn on the screen.
bool turn_on_screen = true;
CreateParams();
};
......
......@@ -58,6 +58,7 @@ shell::CastContentWindow::CreateParams CreateWindowParams(
window_params.enable_touch_input = params.enable_touch_input;
window_params.is_headless = params.is_headless;
window_params.is_remote_control_mode = params.is_remote_control_mode;
window_params.turn_on_screen = params.turn_on_screen;
return window_params;
}
......
......@@ -24,6 +24,7 @@ shell::CastContentWindow::CreateParams CreateWindowParams(
window_params.enable_touch_input = params.enable_touch_input;
window_params.is_headless = params.is_headless;
window_params.is_remote_control_mode = params.is_remote_control_mode;
window_params.turn_on_screen = params.turn_on_screen;
return window_params;
}
......
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