From ccb8daa808b4cb69fc4274393e5dc16d105090ad Mon Sep 17 00:00:00 2001 From: Benjamin Cooley Date: Mon, 22 Nov 2021 23:23:19 -0800 Subject: [PATCH] cts: Re-launch the desired activity after screen-on on TVs. Some TV's do not resume the previous activity coming back from sleep. Add a case to restart activity. Derived from https://android-review.googlesource.com/c/platform/cts/+/1358002 (Bug: 148812676) Test: Verified existing passing tests continue to pass on TCL Beyond TV (Pie) Change-Id: I86fe80c5326065ac349585d1ab95736132ddfb5a --- .../AbstractRestrictBackgroundNetworkTestCase.java | 5 +++++ .../android/cts/net/hostside/DataSaverModeTest.java | 10 ++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/tests/cts/hostside/app/src/com/android/cts/net/hostside/AbstractRestrictBackgroundNetworkTestCase.java b/tests/cts/hostside/app/src/com/android/cts/net/hostside/AbstractRestrictBackgroundNetworkTestCase.java index 1b52ec4896..56d25b609a 100644 --- a/tests/cts/hostside/app/src/com/android/cts/net/hostside/AbstractRestrictBackgroundNetworkTestCase.java +++ b/tests/cts/hostside/app/src/com/android/cts/net/hostside/AbstractRestrictBackgroundNetworkTestCase.java @@ -878,6 +878,11 @@ public abstract class AbstractRestrictBackgroundNetworkTestCase { } } + protected void startActivity() throws Exception { + final Intent launchIntent = getIntentForComponent(TYPE_COMPONENT_ACTIVTIY); + mContext.startActivity(launchIntent); + } + private void startForegroundService() throws Exception { final Intent launchIntent = getIntentForComponent(TYPE_COMPONENT_FOREGROUND_SERVICE); mContext.startForegroundService(launchIntent); diff --git a/tests/cts/hostside/app/src/com/android/cts/net/hostside/DataSaverModeTest.java b/tests/cts/hostside/app/src/com/android/cts/net/hostside/DataSaverModeTest.java index 604a0b62c6..2f30536922 100644 --- a/tests/cts/hostside/app/src/com/android/cts/net/hostside/DataSaverModeTest.java +++ b/tests/cts/hostside/app/src/com/android/cts/net/hostside/DataSaverModeTest.java @@ -20,6 +20,7 @@ import static android.net.ConnectivityManager.RESTRICT_BACKGROUND_STATUS_DISABLE import static android.net.ConnectivityManager.RESTRICT_BACKGROUND_STATUS_ENABLED; import static android.net.ConnectivityManager.RESTRICT_BACKGROUND_STATUS_WHITELISTED; +import static com.android.compatibility.common.util.FeatureUtil.isTV; import static com.android.cts.net.hostside.NetworkPolicyTestUtils.setRestrictBackground; import static com.android.cts.net.hostside.Property.DATA_SAVER_MODE; import static com.android.cts.net.hostside.Property.METERED_NETWORK; @@ -27,14 +28,14 @@ import static com.android.cts.net.hostside.Property.NO_DATA_SAVER_MODE; import static org.junit.Assert.fail; +import androidx.test.filters.LargeTest; + import com.android.compatibility.common.util.CddTest; import org.junit.After; import org.junit.Before; import org.junit.Test; -import androidx.test.filters.LargeTest; - @RequiredProperties({DATA_SAVER_MODE, METERED_NETWORK}) @LargeTest public class DataSaverModeTest extends AbstractRestrictBackgroundNetworkTestCase { @@ -113,6 +114,11 @@ public class DataSaverModeTest extends AbstractRestrictBackgroundNetworkTestCase turnScreenOff(); assertBackgroundNetworkAccess(false); turnScreenOn(); + // On some TVs, it is possible that the activity on top may change after the screen is + // turned off and on again, so relaunch the activity in the test app again. + if (isTV()) { + startActivity(); + } assertForegroundNetworkAccess(); // Goes back to background state.