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