Merge "cts: Re-launch the desired activity after screen-on on TVs." am: 422c7dd460

Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1900117

Change-Id: I9f1b99857989fc0e938259ae8ed3d30cd36dfade
This commit is contained in:
Ross Yeh 2022-03-10 01:39:36 +00:00 • committed by Automerger Merge Worker
commit 821cd25be2
2 changed files with 13 additions and 2 deletions

View file

@ -881,6 +881,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);

View file

@ -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.