diff options
author | Will Burr <wgb@google.com> | 2024-01-26 15:09:56 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2024-01-26 15:09:56 +0000 |
commit | d7cc9290336eb89818343d05bb81cc21b0e05caf (patch) | |
tree | 2faba0e1fa73757d9206cf7305c606c91a35d88a | |
parent | 8a7909ed7b8e4b57e387be0881ebce4598164c37 (diff) | |
parent | f2a3e48214f65ee0a80e1fc1298269e195e373e2 (diff) | |
download | AdServices-d7cc9290336eb89818343d05bb81cc21b0e05caf.tar.gz |
Merge "DO NOT MERGE: Skip CTS tests on SDK sandbox for Go devices" into android14-tests-dev
11 files changed, 98 insertions, 9 deletions
diff --git a/sdksandbox/tests/cts/endtoendtests/src/com/android/tests/sdksandbox/endtoend/CustomizedSdkContextTest.java b/sdksandbox/tests/cts/endtoendtests/src/com/android/tests/sdksandbox/endtoend/CustomizedSdkContextTest.java index 8911da98bd..43d4ba6415 100644 --- a/sdksandbox/tests/cts/endtoendtests/src/com/android/tests/sdksandbox/endtoend/CustomizedSdkContextTest.java +++ b/sdksandbox/tests/cts/endtoendtests/src/com/android/tests/sdksandbox/endtoend/CustomizedSdkContextTest.java @@ -23,6 +23,7 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assume.assumeTrue; import android.app.sdksandbox.SdkSandboxManager; +import android.app.sdksandbox.testutils.DeviceSupportUtils; import android.app.sdksandbox.testutils.FakeLoadSdkCallback; import android.content.Context; import android.content.pm.PackageInfo; @@ -68,6 +69,7 @@ public class CustomizedSdkContextTest { @Before public void setup() { final Context context = InstrumentationRegistry.getInstrumentation().getContext(); + assumeTrue("Device supports SdkSandbox", DeviceSupportUtils.isSdkSandboxSupported(context)); mSdkSandboxManager = context.getSystemService(SdkSandboxManager.class); mRule.getScenario(); } diff --git a/sdksandbox/tests/cts/endtoendtests/src/com/android/tests/sdksandbox/endtoend/SandboxedSdkProviderTest.java b/sdksandbox/tests/cts/endtoendtests/src/com/android/tests/sdksandbox/endtoend/SandboxedSdkProviderTest.java index d051877b89..57eb6bbc7c 100644 --- a/sdksandbox/tests/cts/endtoendtests/src/com/android/tests/sdksandbox/endtoend/SandboxedSdkProviderTest.java +++ b/sdksandbox/tests/cts/endtoendtests/src/com/android/tests/sdksandbox/endtoend/SandboxedSdkProviderTest.java @@ -19,9 +19,11 @@ package com.android.tests.sdksandbox.endtoend; import static com.google.common.truth.Truth.assertThat; import static org.junit.Assert.assertThrows; +import static org.junit.Assume.assumeTrue; import android.app.sdksandbox.SandboxedSdk; import android.app.sdksandbox.SandboxedSdkProvider; +import android.app.sdksandbox.testutils.DeviceSupportUtils; import android.content.Context; import android.os.Bundle; import android.view.View; @@ -41,6 +43,8 @@ public class SandboxedSdkProviderTest { @Before public void setup() { + final Context context = InstrumentationRegistry.getInstrumentation().getContext(); + assumeTrue("Device supports SdkSandbox", DeviceSupportUtils.isSdkSandboxSupported(context)); mSdk = new TestSandboxedSdkProvider(); } diff --git a/sdksandbox/tests/cts/endtoendtests/src/com/android/tests/sdksandbox/endtoend/SdkSandboxManagerTest.java b/sdksandbox/tests/cts/endtoendtests/src/com/android/tests/sdksandbox/endtoend/SdkSandboxManagerTest.java index 0b22d6225d..14cc2f4c45 100644 --- a/sdksandbox/tests/cts/endtoendtests/src/com/android/tests/sdksandbox/endtoend/SdkSandboxManagerTest.java +++ b/sdksandbox/tests/cts/endtoendtests/src/com/android/tests/sdksandbox/endtoend/SdkSandboxManagerTest.java @@ -34,6 +34,7 @@ import android.app.ActivityManager; import android.app.sdksandbox.LoadSdkException; import android.app.sdksandbox.SandboxedSdk; import android.app.sdksandbox.SdkSandboxManager; +import android.app.sdksandbox.testutils.DeviceSupportUtils; import android.app.sdksandbox.testutils.FakeLoadSdkCallback; import android.app.sdksandbox.testutils.FakeRequestSurfacePackageCallback; import android.app.sdksandbox.testutils.FakeSdkSandboxProcessDeathCallback; @@ -88,10 +89,10 @@ public class SdkSandboxManagerTest { private ActivityScenario<TestActivity> mScenario; private SdkSandboxManager mSdkSandboxManager; - @Before public void setup() { final Context context = InstrumentationRegistry.getInstrumentation().getContext(); + assumeTrue("Device supports SdkSandbox", DeviceSupportUtils.isSdkSandboxSupported(context)); mSdkSandboxManager = context.getSystemService(SdkSandboxManager.class); unloadAllSdks(); mScenario = mRule.getScenario(); diff --git a/sdksandbox/tests/cts/hostside/src/com/android/sdksandbox/cts/host/CtsSdkSandboxStorageHostTest.java b/sdksandbox/tests/cts/hostside/src/com/android/sdksandbox/cts/host/CtsSdkSandboxStorageHostTest.java index a4034fa323..b5e0b020d5 100644 --- a/sdksandbox/tests/cts/hostside/src/com/android/sdksandbox/cts/host/CtsSdkSandboxStorageHostTest.java +++ b/sdksandbox/tests/cts/hostside/src/com/android/sdksandbox/cts/host/CtsSdkSandboxStorageHostTest.java @@ -18,6 +18,10 @@ package com.android.sdksandbox.cts.host; import static com.google.common.truth.Truth.assertThat; +import static org.junit.Assume.assumeTrue; + +import android.app.sdksandbox.hosttestutils.DeviceSupportHostUtils; + import com.android.tradefed.testtype.DeviceJUnit4ClassRunner; import com.android.tradefed.testtype.junit4.BaseHostJUnit4Test; @@ -32,6 +36,8 @@ public final class CtsSdkSandboxStorageHostTest extends BaseHostJUnit4Test { private static final String TEST_APP_PACKAGE_NAME = "com.android.sdksandbox.cts.app"; private static final String TEST_APP_APK_NAME = "CtsSdkSandboxHostTestApp.apk"; + private final DeviceSupportHostUtils mDeviceSupportUtils = new DeviceSupportHostUtils(this); + /** * Runs the given phase of a test by calling into the device. Throws an exception if the test * phase fails. @@ -49,6 +55,7 @@ public final class CtsSdkSandboxStorageHostTest extends BaseHostJUnit4Test { @Before public void setUp() throws Exception { + assumeTrue("Device supports SdkSandbox", mDeviceSupportUtils.isSdkSandboxSupported()); uninstallPackage(TEST_APP_PACKAGE_NAME); } diff --git a/sdksandbox/tests/cts/hostside/src/com/android/sdksandbox/cts/host/SdkSandboxDataIsolationHostTest.java b/sdksandbox/tests/cts/hostside/src/com/android/sdksandbox/cts/host/SdkSandboxDataIsolationHostTest.java index f2d39bfaaa..4bb34ec69b 100644 --- a/sdksandbox/tests/cts/hostside/src/com/android/sdksandbox/cts/host/SdkSandboxDataIsolationHostTest.java +++ b/sdksandbox/tests/cts/hostside/src/com/android/sdksandbox/cts/host/SdkSandboxDataIsolationHostTest.java @@ -21,6 +21,7 @@ import static com.google.common.truth.Truth.assertThat; import static org.junit.Assume.assumeTrue; import android.app.sdksandbox.hosttestutils.AdoptableStorageUtils; +import android.app.sdksandbox.hosttestutils.DeviceSupportHostUtils; import android.app.sdksandbox.hosttestutils.SecondaryUserUtils; import com.android.modules.utils.build.testing.DeviceSdkLevel; @@ -45,6 +46,7 @@ public class SdkSandboxDataIsolationHostTest extends BaseHostJUnit4Test { private final SecondaryUserUtils mUserUtils = new SecondaryUserUtils(this); private final AdoptableStorageUtils mAdoptableUtils = new AdoptableStorageUtils(this); + private final DeviceSupportHostUtils mDeviceSupportUtils = new DeviceSupportHostUtils(this); private DeviceSdkLevel mDeviceSdkLevel; @@ -71,6 +73,7 @@ public class SdkSandboxDataIsolationHostTest extends BaseHostJUnit4Test { @Before public void setUp() throws Exception { + assumeTrue("Device supports SdkSandbox", mDeviceSupportUtils.isSdkSandboxSupported()); mDeviceSdkLevel = new DeviceSdkLevel(getDevice()); // These tests run on system user uninstallPackage(APP_PACKAGE); diff --git a/sdksandbox/tests/cts/hostside/src/com/android/sdksandbox/cts/host/SdkSandboxMediationHostTest.java b/sdksandbox/tests/cts/hostside/src/com/android/sdksandbox/cts/host/SdkSandboxMediationHostTest.java index 65bef44ae7..5d0d20acf3 100644 --- a/sdksandbox/tests/cts/hostside/src/com/android/sdksandbox/cts/host/SdkSandboxMediationHostTest.java +++ b/sdksandbox/tests/cts/hostside/src/com/android/sdksandbox/cts/host/SdkSandboxMediationHostTest.java @@ -18,6 +18,10 @@ package com.android.sdksandbox.cts.host; import static com.google.common.truth.Truth.assertThat; +import static org.junit.Assume.assumeTrue; + +import android.app.sdksandbox.hosttestutils.DeviceSupportHostUtils; + import com.android.tradefed.testtype.DeviceJUnit4ClassRunner; import com.android.tradefed.testtype.junit4.BaseHostJUnit4Test; @@ -32,6 +36,8 @@ public final class SdkSandboxMediationHostTest extends BaseHostJUnit4Test { private static final String TEST_APP_PACKAGE_NAME = "com.android.sdksandbox.cts.app"; private static final String TEST_APP_APK_NAME = "CtsSdkSandboxHostTestApp.apk"; + private final DeviceSupportHostUtils mDeviceSupportUtils = new DeviceSupportHostUtils(this); + /** * Runs the given phase of a test by calling into the device. Throws an exception if the test * phase fails. @@ -39,6 +45,7 @@ public final class SdkSandboxMediationHostTest extends BaseHostJUnit4Test { * <p>For example, <code>runPhase("testExample");</code> */ private void runPhase(String phase) throws Exception { + assumeTrue("Device supports SdkSandbox", mDeviceSupportUtils.isSdkSandboxSupported()); assertThat( runDeviceTests( TEST_APP_PACKAGE_NAME, diff --git a/sdksandbox/tests/cts/inprocess/src/com/android/sdksandbox/tests/cts/inprocess/SdkSandboxConfigurationTest.java b/sdksandbox/tests/cts/inprocess/src/com/android/sdksandbox/tests/cts/inprocess/SdkSandboxConfigurationTest.java index 4a356ca0d1..57af5be38c 100644 --- a/sdksandbox/tests/cts/inprocess/src/com/android/sdksandbox/tests/cts/inprocess/SdkSandboxConfigurationTest.java +++ b/sdksandbox/tests/cts/inprocess/src/com/android/sdksandbox/tests/cts/inprocess/SdkSandboxConfigurationTest.java @@ -72,6 +72,7 @@ public class SdkSandboxConfigurationTest { @Before public void setUp() { assumeTrue( + "Device supports SdkSandbox", DeviceSupportUtils.isSdkSandboxSupported( InstrumentationRegistry.getInstrumentation().getContext())); } diff --git a/sdksandbox/tests/cts/inprocess/src/com/android/sdksandbox/tests/cts/inprocess/SdkSandboxRestrictionsTest.java b/sdksandbox/tests/cts/inprocess/src/com/android/sdksandbox/tests/cts/inprocess/SdkSandboxRestrictionsTest.java index 5de84236b4..418df49681 100644 --- a/sdksandbox/tests/cts/inprocess/src/com/android/sdksandbox/tests/cts/inprocess/SdkSandboxRestrictionsTest.java +++ b/sdksandbox/tests/cts/inprocess/src/com/android/sdksandbox/tests/cts/inprocess/SdkSandboxRestrictionsTest.java @@ -67,6 +67,7 @@ public class SdkSandboxRestrictionsTest { @Before public void setUp() { assumeTrue( + "Device supports SdkSandbox", DeviceSupportUtils.isSdkSandboxSupported( InstrumentationRegistry.getInstrumentation().getContext())); } diff --git a/sdksandbox/tests/testutils/Android.bp b/sdksandbox/tests/testutils/Android.bp index e626647253..b3ff108e0d 100644 --- a/sdksandbox/tests/testutils/Android.bp +++ b/sdksandbox/tests/testutils/Android.bp @@ -26,6 +26,7 @@ java_library { ], static_libs: [ "service-sdksandbox.impl", + "compatibility-device-util-axt", "truth-prebuilt", "androidx.test.ext.junit", "SdkSandbox-java-lib", @@ -42,5 +43,6 @@ java_library_host { srcs: [ "src/**/hosttestutils/*.java", ], + static_libs: ["compatibility-host-util"], libs: ["tradefed"], }
\ No newline at end of file diff --git a/sdksandbox/tests/testutils/src/android/app/sdksandbox/hosttestutils/DeviceSupportHostUtils.java b/sdksandbox/tests/testutils/src/android/app/sdksandbox/hosttestutils/DeviceSupportHostUtils.java index 66d8ee3d3d..8063308a43 100644 --- a/sdksandbox/tests/testutils/src/android/app/sdksandbox/hosttestutils/DeviceSupportHostUtils.java +++ b/sdksandbox/tests/testutils/src/android/app/sdksandbox/hosttestutils/DeviceSupportHostUtils.java @@ -16,23 +16,53 @@ package android.app.sdksandbox.hosttestutils; +import com.android.compatibility.common.util.FeatureUtil; +import com.android.compatibility.common.util.PackageUtil; import com.android.tradefed.device.DeviceNotAvailableException; import com.android.tradefed.device.ITestDevice; import com.android.tradefed.testtype.junit4.BaseHostJUnit4Test; public class DeviceSupportHostUtils { private final BaseHostJUnit4Test mTest; - private static final String FEATURE_WATCH = "android.hardware.type.watch"; + + private static final String GMS_CORE_PACKAGE = "com.google.android.gms"; + private static final String PLAY_STORE_PACKAGE = "com.android.vending"; public DeviceSupportHostUtils(BaseHostJUnit4Test test) { mTest = test; } public boolean isSdkSandboxSupported() throws DeviceNotAvailableException { - return !isWatch(mTest.getDevice()); + return !isWatch() && !isTv() && !isAutomotive() && !isGoDevice(); + } + + private boolean isWatch() throws DeviceNotAvailableException { + return FeatureUtil.isWatch(mTest.getDevice()); + } + + private boolean isTv() throws DeviceNotAvailableException { + return FeatureUtil.isTV(mTest.getDevice()); + } + + private boolean isAutomotive() throws DeviceNotAvailableException { + return FeatureUtil.isAutomotive(mTest.getDevice()); + } + + private boolean hasGmsCore() throws DeviceNotAvailableException { + return PackageUtil.exists(mTest.getDevice(), GMS_CORE_PACKAGE); + } + + private boolean hasPlayStore() throws DeviceNotAvailableException { + return PackageUtil.exists(mTest.getDevice(), PLAY_STORE_PACKAGE); } - private boolean isWatch(ITestDevice device) throws DeviceNotAvailableException { - return device.hasFeature(FEATURE_WATCH); + // Taken from vendor/xts/common/host-side/util/src/com/android/xts/common/util/GmsUtil.java + private boolean isGoDevice() throws DeviceNotAvailableException { + ITestDevice device = mTest.getDevice(); + return FeatureUtil.isLowRam(device) + && hasGmsCore() + && hasPlayStore() + && !isWatch() + && !isTv(); } } diff --git a/sdksandbox/tests/testutils/src/android/app/sdksandbox/testutils/DeviceSupportUtils.java b/sdksandbox/tests/testutils/src/android/app/sdksandbox/testutils/DeviceSupportUtils.java index 14d67f24c7..290253ee98 100644 --- a/sdksandbox/tests/testutils/src/android/app/sdksandbox/testutils/DeviceSupportUtils.java +++ b/sdksandbox/tests/testutils/src/android/app/sdksandbox/testutils/DeviceSupportUtils.java @@ -17,16 +17,47 @@ package android.app.sdksandbox.testutils; import android.content.Context; -import android.content.pm.PackageManager; + +import com.android.compatibility.common.util.FeatureUtil; +import com.android.compatibility.common.util.PackageUtil; +import com.android.compatibility.common.util.PropertyUtil; /** Utility class to control which devices SDK sandbox tests run on. */ public class DeviceSupportUtils { + private static final String GMS_CORE_PACKAGE = "com.google.android.gms"; + private static final String PLAY_STORE_PACKAGE = "com.android.vending"; + private static final String PLAY_STORE_USER_CERT = + "F0:FD:6C:5B:41:0F:25:CB:25:C3:B5:33:46:C8:97:2F:" + + "AE:30:F8:EE:74:11:DF:91:04:80:AD:6B:2D:60:DB:83"; + public static boolean isSdkSandboxSupported(Context context) { - return !isWatch(context); + return !FeatureUtil.isWatch() + && !FeatureUtil.isTV() + && !FeatureUtil.isAutomotive() + && !isGoDevice(); + } + + // Taken from vendor/xts/common/device-side/util/src/com/android/xts/common/util/GmsUtil.java + private static boolean isGoDevice() { + return FeatureUtil.isLowRam() + && hasGmsCore() + && hasPlayStore() + && !FeatureUtil.isWatch() + && !FeatureUtil.isTV() + && !FeatureUtil.isAutomotive() + && !FeatureUtil.isVrHeadset() + && !FeatureUtil.isArc(); + } + + /** Returns whether GMS Core is installed for this build */ + private static boolean hasGmsCore() { + return PackageUtil.exists(GMS_CORE_PACKAGE); } - private static boolean isWatch(Context context) { - return context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_WATCH); + private static boolean hasPlayStore() { + return (PropertyUtil.isUserBuild()) + ? PackageUtil.exists(PLAY_STORE_PACKAGE, PLAY_STORE_USER_CERT) + : PackageUtil.exists(PLAY_STORE_PACKAGE); } } |