diff options
author | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2022-02-17 01:00:40 +0000 |
---|---|---|
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2022-02-17 01:00:40 +0000 |
commit | 5fb71a6da6cd9b1c651e51af54d7b58e9e05161a (patch) | |
tree | 9ef441d3bcc5cfb351553c1a000f96ec87d7b1b1 | |
parent | a25c5e92c28c094dcc02afdf867b64abbf0b1fc9 (diff) | |
parent | b532f352f9e58f1436a3246601a8614a6cf62ea8 (diff) | |
download | cts-android12-mainline-cellbroadcast-release.tar.gz |
Snap for 8192308 from b532f352f9e58f1436a3246601a8614a6cf62ea8 to mainline-cellbroadcast-releaseandroid-mainline-12.0.0_r86android12-mainline-cellbroadcast-release
Change-Id: I8a651d982e4bea93468b216ce82c678728bfb071
41 files changed, 894 insertions, 121 deletions
diff --git a/hostsidetests/appcloning/Android.bp b/hostsidetests/appcloning/Android.bp new file mode 100644 index 00000000000..f1ecc4be33b --- /dev/null +++ b/hostsidetests/appcloning/Android.bp @@ -0,0 +1,38 @@ +// Copyright (C) 2022 The Android Open Source Project +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package { + default_applicable_licenses: ["Android-Apache-2.0"], +} + +java_test_host { + name: "CtsAppCloningHostTest", + srcs: [ + "hostside/src/**/AppCloningHostTest.java", + "hostside/src/**/BaseHostTestCase.java", + ], + libs: [ + "cts-tradefed", + "tradefed", + "testng", + ], + // tag the module as cts a test artifact + test_suites: [ + "general-tests", + "mts-mediaprovider", + "cts", + ], + test_config: "AndroidTestAppCloning.xml", + data: [":CtsAppCloningTestApp"], +} diff --git a/hostsidetests/scopedstorage/AndroidTestAppCloning.xml b/hostsidetests/appcloning/AndroidTestAppCloning.xml index 03802f23886..8c882eb773a 100644 --- a/hostsidetests/scopedstorage/AndroidTestAppCloning.xml +++ b/hostsidetests/appcloning/AndroidTestAppCloning.xml @@ -1,29 +1,29 @@ <?xml version="1.0" encoding="utf-8"?> -<!-- Copyright (C) 2021 The Android Open Source Project - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. ---> +<!-- + ~ Copyright (C) 2022 The Android Open Source Project + ~ + ~ Licensed under the Apache License, Version 2.0 (the "License"); + ~ you may not use this file except in compliance with the License. + ~ You may obtain a copy of the License at + ~ + ~ http://www.apache.org/licenses/LICENSE-2.0 + ~ + ~ Unless required by applicable law or agreed to in writing, software + ~ distributed under the License is distributed on an "AS IS" BASIS, + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + ~ See the License for the specific language governing permissions and + ~ limitations under the License. + --> <configuration description="Test for App cloning support with clone user profiles"> <option name="test-suite-tag" value="cts" /> <option name="config-descriptor:metadata" key="component" value="framework" /> <option name="config-descriptor:metadata" key="parameter" value="instant_app" /> <option name="config-descriptor:metadata" key="parameter" value="not_multi_abi" /> - <!-- TODO(b/169101565): change to secondary_user when fixed --> <!-- Clone user profile is meant to exist only alongside a real system user. It does not exist for a headless system user, or a secondary user --> <option name="config-descriptor:metadata" key="parameter" value="not_secondary_user" /> <test class="com.android.tradefed.testtype.HostTest" > - <option name="class" value="android.scopedstorage.cts.host.AppCloningHostTest" /> + <option name="class" value="com.android.cts.appcloning.AppCloningHostTest" /> </test> <object type="module_controller" class="com.android.tradefed.testtype.suite.module.MainlineTestModuleController"> diff --git a/hostsidetests/appcloning/OWNERS b/hostsidetests/appcloning/OWNERS new file mode 100644 index 00000000000..7cc93143726 --- /dev/null +++ b/hostsidetests/appcloning/OWNERS @@ -0,0 +1,6 @@ +# Bug component: 1029024 +saumyap@google.com +maco@google.com +dagarhimanshu@google.com +sarup@google.com +sailendrabathi@google.com
\ No newline at end of file diff --git a/hostsidetests/appcloning/TEST_MAPPING b/hostsidetests/appcloning/TEST_MAPPING new file mode 100644 index 00000000000..f512df95a6c --- /dev/null +++ b/hostsidetests/appcloning/TEST_MAPPING @@ -0,0 +1,7 @@ +{ + "presubmit": [ + { + "name": "CtsAppCloningHostTest" + } + ] +}
\ No newline at end of file diff --git a/hostsidetests/scopedstorage/host/src/android/scopedstorage/cts/host/AppCloningHostTest.java b/hostsidetests/appcloning/hostside/src/com/android/cts/appcloning/AppCloningHostTest.java index 9522731fe5d..ce7356c5966 100644 --- a/hostsidetests/scopedstorage/host/src/android/scopedstorage/cts/host/AppCloningHostTest.java +++ b/hostsidetests/appcloning/hostside/src/com/android/cts/appcloning/AppCloningHostTest.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package android.scopedstorage.cts.host; +package com.android.cts.appcloning; import static com.google.common.truth.Truth.assertThat; @@ -34,36 +34,39 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; -import java.util.ArrayList; -import java.util.List; - /** * Runs the AppCloning tests. */ @RunWith(DeviceJUnit4ClassRunner.class) @AppModeFull public class AppCloningHostTest extends BaseHostTestCase { - private static final String APP_A = "CtsScopedStorageTestAppA.apk"; - private static final String APP_A_PACKAGE = "android.scopedstorage.cts.testapp.A.withres"; + + private static final String APP_A = "CtsAppCloningTestApp.apk"; + private static final String APP_A_PACKAGE = "com.android.cts.appcloningtestapp"; + private static final String CONTENT_PROVIDER_URL = "content://android.tradefed.contentprovider"; private static final int CLONE_PROFILE_DIRECTORY_CREATION_TIMEOUT_MS = 20000; + private String mCloneUserId; private ContentProviderHandler mContentProviderHandler; - @Before public void setup() throws Exception { assumeFalse("Device is in headless system user mode", isHeadlessSystemUserMode()); assumeTrue(isAtLeastS()); assumeFalse("Device uses sdcardfs", usesSdcardFs()); + // create clone user String output = executeShellCommand( "pm create-user --profileOf 0 --user-type android.os.usertype.profile.CLONE " + "testUser"); - mCloneUserId = output.substring(output.lastIndexOf(' ') + 1).replaceAll("[^0-9]", ""); + mCloneUserId = output.substring(output.lastIndexOf(' ') + 1).replaceAll("[^0-9]", + ""); assertThat(mCloneUserId).isNotEmpty(); + CommandResult out = executeShellV2Command("am start-user -w %s", mCloneUserId); assertThat(out.getStderr()).isEmpty(); + mContentProviderHandler = new ContentProviderHandler(getDevice()); mContentProviderHandler.setUp(); } @@ -74,6 +77,8 @@ public class AppCloningHostTest extends BaseHostTestCase { if (mContentProviderHandler != null) { mContentProviderHandler.tearDown(); } + + // remove the clone user executeShellCommand("pm remove-user %s", mCloneUserId); } @@ -92,7 +97,8 @@ public class AppCloningHostTest extends BaseHostTestCase { eventually(() -> { // Wait for finish. assertThat(isSuccessful( - runContentProviderCommand("query", mCloneUserId, "/sdcard", ""))).isTrue(); + runContentProviderCommand("query", mCloneUserId, + "/sdcard", ""))).isTrue(); }, CLONE_PROFILE_DIRECTORY_CREATION_TIMEOUT_MS); // Create a file on the clone user storage @@ -101,16 +107,19 @@ public class AppCloningHostTest extends BaseHostTestCase { eventually(() -> { // Wait for finish. assertThat(isSuccessful( - runContentProviderCommand("write", mCloneUserId, "/sdcard/testFile.txt", + runContentProviderCommand("write", mCloneUserId, + "/sdcard/testFile.txt", "< /sdcard/testFile.txt"))).isTrue(); }, CLONE_PROFILE_DIRECTORY_CREATION_TIMEOUT_MS); // Check that the above created file exists on the clone user storage - out = runContentProviderCommand("query", mCloneUserId, "/sdcard/testFile.txt", ""); + out = runContentProviderCommand("query", mCloneUserId, + "/sdcard/testFile.txt", ""); assertThat(isSuccessful(out)).isTrue(); // Cleanup the created file - out = runContentProviderCommand("delete", mCloneUserId, "/sdcard/testFile.txt", ""); + out = runContentProviderCommand("delete", mCloneUserId, + "/sdcard/testFile.txt", ""); assertThat(isSuccessful(out)).isTrue(); } @@ -136,7 +145,6 @@ public class AppCloningHostTest extends BaseHostTestCase { } private boolean usesSdcardFs() throws Exception { - List<String> mounts = new ArrayList<>(); CommandResult out = executeShellV2Command("cat /proc/mounts"); assertThat(isSuccessful(out)).isTrue(); for (String line : out.getStdout().split("\n")) { @@ -147,6 +155,4 @@ public class AppCloningHostTest extends BaseHostTestCase { } return false; } - - } diff --git a/hostsidetests/appcloning/hostside/src/com/android/cts/appcloning/BaseHostTestCase.java b/hostsidetests/appcloning/hostside/src/com/android/cts/appcloning/BaseHostTestCase.java new file mode 100644 index 00000000000..3d301f1b7ca --- /dev/null +++ b/hostsidetests/appcloning/hostside/src/com/android/cts/appcloning/BaseHostTestCase.java @@ -0,0 +1,108 @@ +/* + * Copyright (C) 2022 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.cts.appcloning; + +import com.android.tradefed.device.DeviceNotAvailableException; +import com.android.tradefed.device.ITestDevice; +import com.android.tradefed.device.NativeDevice; +import com.android.tradefed.log.LogUtil.CLog; +import com.android.tradefed.testtype.junit4.BaseHostJUnit4Test; +import com.android.tradefed.util.CommandResult; +import com.android.tradefed.util.CommandStatus; + + +abstract class BaseHostTestCase extends BaseHostJUnit4Test { + private int mCurrentUserId = NativeDevice.INVALID_USER_ID; + private static final String ERROR_MESSAGE_TAG = "[ERROR]"; + + protected String executeShellCommand(String cmd, Object... args) throws Exception { + return getDevice().executeShellCommand(String.format(cmd, args)); + } + + protected CommandResult executeShellV2Command(String cmd, Object... args) throws Exception { + return getDevice().executeShellV2Command(String.format(cmd, args)); + } + + protected boolean isPackageInstalled(String packageName, String userId) throws Exception { + return getDevice().isPackageInstalled(packageName, userId); + } + + // TODO (b/174775905) remove after exposing the check from ITestDevice. + protected boolean isHeadlessSystemUserMode() throws DeviceNotAvailableException { + String result = getDevice() + .executeShellCommand("getprop ro.fw.mu.headless_system_user").trim(); + return "true".equalsIgnoreCase(result); + } + + protected boolean isAtLeastS() throws DeviceNotAvailableException { + return getDevice().getApiLevel() >= 31 /* BUILD.VERSION_CODES.S */; + } + + protected static void eventually(ThrowingRunnable r, long timeoutMillis) { + long start = System.currentTimeMillis(); + + while (true) { + try { + r.run(); + return; + } catch (Throwable e) { + if (System.currentTimeMillis() - start < timeoutMillis) { + try { + Thread.sleep(100); + } catch (InterruptedException ignored) { + throw new RuntimeException(e); + } + } else { + throw new RuntimeException(e); + } + } + } + } + + protected int getCurrentUserId() throws Exception { + setCurrentUserId(); + + return mCurrentUserId; + } + + protected boolean isSuccessful(CommandResult result) { + if (!CommandStatus.SUCCESS.equals(result.getStatus())) { + return false; + } + String stdout = result.getStdout(); + if (stdout.contains(ERROR_MESSAGE_TAG)) { + return false; + } + String stderr = result.getStderr(); + return (stderr == null || stderr.trim().isEmpty()); + } + + private void setCurrentUserId() throws Exception { + if (mCurrentUserId != NativeDevice.INVALID_USER_ID) return; + + ITestDevice device = getDevice(); + mCurrentUserId = device.getCurrentUser(); + CLog.i("Current user: %d"); + } + + protected interface ThrowingRunnable { + /** + * Similar to {@link Runnable#run} but has {@code throws Exception}. + */ + void run() throws Exception; + } +} diff --git a/hostsidetests/appcloning/test-apps/AppCloningTestApp/Android.bp b/hostsidetests/appcloning/test-apps/AppCloningTestApp/Android.bp new file mode 100644 index 00000000000..b3edfec5112 --- /dev/null +++ b/hostsidetests/appcloning/test-apps/AppCloningTestApp/Android.bp @@ -0,0 +1,31 @@ +// Copyright (C) 2022 The Android Open Source Project +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package { + default_applicable_licenses: ["Android-Apache-2.0"], +} + +android_test_helper_app { + name: "CtsAppCloningTestApp", + defaults: ["cts_defaults"], + static_libs: [ + "androidx.test.rules", + "truth-prebuilt", + "cts-install-lib", + ], + srcs: ["src/**/*.java"], + sdk_version: "test_current", + target_sdk_version: "current", + min_sdk_version: "30", +} diff --git a/hostsidetests/appcloning/test-apps/AppCloningTestApp/AndroidManifest.xml b/hostsidetests/appcloning/test-apps/AppCloningTestApp/AndroidManifest.xml new file mode 100644 index 00000000000..07d78a0ead2 --- /dev/null +++ b/hostsidetests/appcloning/test-apps/AppCloningTestApp/AndroidManifest.xml @@ -0,0 +1,32 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + ~ Copyright (C) 2022 The Android Open Source Project + ~ + ~ Licensed under the Apache License, Version 2.0 (the "License"); + ~ you may not use this file except in compliance with the License. + ~ You may obtain a copy of the License at + ~ + ~ http://www.apache.org/licenses/LICENSE-2.0 + ~ + ~ Unless required by applicable law or agreed to in writing, software + ~ distributed under the License is distributed on an "AS IS" BASIS, + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + ~ See the License for the specific language governing permissions and + ~ limitations under the License. + --> + +<manifest xmlns:android="http://schemas.android.com/apk/res/android" + package="com.android.cts.appcloningtestapp" + android:versionCode="1" + android:versionName="1.0" > + + <uses-sdk android:minSdkVersion="30" /> + + <application> + <uses-library android:name="android.test.runner" /> + </application> + + <instrumentation android:name="androidx.test.runner.AndroidJUnitRunner" + android:targetPackage="com.android.cts.appcloningtestapp" /> + +</manifest>
\ No newline at end of file diff --git a/hostsidetests/appcloning/test-apps/AppCloningTestApp/src/com/android/cts/appcloningtestapp/AppCloningDeviceTest.java b/hostsidetests/appcloning/test-apps/AppCloningTestApp/src/com/android/cts/appcloningtestapp/AppCloningDeviceTest.java new file mode 100644 index 00000000000..46480f7cd78 --- /dev/null +++ b/hostsidetests/appcloning/test-apps/AppCloningTestApp/src/com/android/cts/appcloningtestapp/AppCloningDeviceTest.java @@ -0,0 +1,25 @@ +/* + * Copyright (C) 2022 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.cts.appcloningtestapp; + +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +@RunWith(JUnit4.class) +public class AppCloningDeviceTest { + private static final String TAG = "AppCloningDeviceTest"; +} diff --git a/hostsidetests/scopedstorage/Android.bp b/hostsidetests/scopedstorage/Android.bp index 689141f98e1..808a00d2c2a 100644 --- a/hostsidetests/scopedstorage/Android.bp +++ b/hostsidetests/scopedstorage/Android.bp @@ -25,8 +25,13 @@ android_test_helper_app { min_sdk_version: "30", srcs: ["ScopedStorageTestHelper/src/**/*.java"], // Tag as a CTS artifact - test_suites: ["general-tests", "mts-mediaprovider", "cts"], + test_suites: [ + "general-tests", + "mts-mediaprovider", + "cts", + ], } + android_test_helper_app { name: "CtsScopedStorageTestAppB", manifest: "ScopedStorageTestHelper/TestAppB.xml", @@ -36,8 +41,13 @@ android_test_helper_app { min_sdk_version: "30", srcs: ["ScopedStorageTestHelper/src/**/*.java"], // Tag as a CTS artifact - test_suites: ["general-tests", "mts-mediaprovider", "cts"], + test_suites: [ + "general-tests", + "mts-mediaprovider", + "cts", + ], } + android_test_helper_app { name: "CtsScopedStorageTestAppC", manifest: "ScopedStorageTestHelper/TestAppC.xml", @@ -47,8 +57,13 @@ android_test_helper_app { min_sdk_version: "30", srcs: ["ScopedStorageTestHelper/src/**/*.java"], // Tag as a CTS artifact - test_suites: ["general-tests", "mts-mediaprovider", "cts"], + test_suites: [ + "general-tests", + "mts-mediaprovider", + "cts", + ], } + android_test_helper_app { name: "CtsScopedStorageTestAppC30", manifest: "ScopedStorageTestHelper/TestAppC30.xml", @@ -58,8 +73,13 @@ android_test_helper_app { min_sdk_version: "30", srcs: ["ScopedStorageTestHelper/src/**/*.java"], // Tag as a CTS artifact - test_suites: ["general-tests", "mts", "cts"], + test_suites: [ + "general-tests", + "mts", + "cts", + ], } + android_test_helper_app { name: "CtsScopedStorageTestAppCLegacy", manifest: "ScopedStorageTestHelper/TestAppCLegacy.xml", @@ -69,8 +89,13 @@ android_test_helper_app { min_sdk_version: "28", srcs: ["ScopedStorageTestHelper/src/**/*.java"], // Tag as a CTS artifact - test_suites: ["general-tests", "mts-mediaprovider", "cts"], + test_suites: [ + "general-tests", + "mts-mediaprovider", + "cts", + ], } + android_test_helper_app { name: "CtsScopedStorageTestAppDLegacy", manifest: "ScopedStorageTestHelper/TestAppDLegacy.xml", @@ -80,7 +105,11 @@ android_test_helper_app { min_sdk_version: "28", srcs: ["ScopedStorageTestHelper/src/**/*.java"], // Tag as a CTS artifact - test_suites: ["general-tests", "mts-mediaprovider", "cts"], + test_suites: [ + "general-tests", + "mts-mediaprovider", + "cts", + ], } android_test_helper_app { @@ -92,8 +121,13 @@ android_test_helper_app { min_sdk_version: "30", srcs: ["ScopedStorageTestHelper/src/**/*.java"], // Tag as a CTS artifact - test_suites: ["general-tests", "mts-mediaprovider", "cts"], + test_suites: [ + "general-tests", + "mts-mediaprovider", + "cts", + ], } + android_test_helper_app { name: "CtsScopedStorageTestAppFileManagerBypassDB", manifest: "ScopedStorageTestHelper/TestAppFileManagerBypassDB.xml", @@ -103,8 +137,13 @@ android_test_helper_app { min_sdk_version: "30", srcs: ["ScopedStorageTestHelper/src/**/*.java"], // Tag as a CTS artifact - test_suites: ["general-tests", "mts", "cts"], + test_suites: [ + "general-tests", + "mts", + "cts", + ], } + android_test_helper_app { name: "CtsScopedStorageTestAppSystemGalleryBypassDB", manifest: "ScopedStorageTestHelper/TestAppSystemGalleryBypassDB.xml", @@ -114,8 +153,13 @@ android_test_helper_app { min_sdk_version: "30", srcs: ["ScopedStorageTestHelper/src/**/*.java"], // Tag as a CTS artifact - test_suites: ["general-tests", "mts", "cts"], + test_suites: [ + "general-tests", + "mts", + "cts", + ], } + android_test_helper_app { name: "CtsScopedStorageTestAppSystemGallery30BypassDB", manifest: "ScopedStorageTestHelper/TestAppSystemGallery30BypassDB.xml", @@ -125,7 +169,11 @@ android_test_helper_app { min_sdk_version: "30", srcs: ["ScopedStorageTestHelper/src/**/*.java"], // Tag as a CTS artifact - test_suites: ["general-tests", "mts", "cts"], + test_suites: [ + "general-tests", + "mts", + "cts", + ], } android_test_helper_app { @@ -150,9 +198,16 @@ android_test { name: "ScopedStorageTest", manifest: "AndroidManifest.xml", srcs: ["src/**/*.java"], - static_libs: ["truth-prebuilt", "cts-scopedstorage-lib"], + static_libs: [ + "truth-prebuilt", + "cts-scopedstorage-lib", + ], compile_multilib: "both", - test_suites: ["general-tests", "mts-mediaprovider", "cts"], + test_suites: [ + "general-tests", + "mts-mediaprovider", + "cts", + ], sdk_version: "test_current", target_sdk_version: "31", min_sdk_version: "30", @@ -161,40 +216,67 @@ android_test { ":CtsScopedStorageTestAppB", ":CtsScopedStorageTestAppC", ":CtsScopedStorageTestAppCLegacy", - ] + ], } android_test { name: "LegacyStorageTest", manifest: "legacy/AndroidManifest.xml", srcs: ["legacy/src/**/*.java"], - static_libs: ["truth-prebuilt", "cts-scopedstorage-lib"], + static_libs: [ + "truth-prebuilt", + "cts-scopedstorage-lib", + ], compile_multilib: "both", - test_suites: ["general-tests", "mts-mediaprovider", "cts"], + test_suites: [ + "general-tests", + "mts-mediaprovider", + "cts", + ], sdk_version: "test_current", target_sdk_version: "29", min_sdk_version: "30", java_resources: [ ":CtsScopedStorageTestAppA", - ] + ], } java_test_host { name: "CtsScopedStorageCoreHostTest", - srcs: [ + srcs: [ "host/src/android/scopedstorage/cts/host/ScopedStorageCoreHostTest.java", - "host/src/android/scopedstorage/cts/host/BaseHostTestCase.java" + "host/src/android/scopedstorage/cts/host/BaseHostTestCase.java", + ], + libs: [ + "cts-tradefed", + "tradefed", + "testng", + ], + test_suites: [ + "general-tests", + "mts-mediaprovider", + "cts", ], - libs: ["cts-tradefed", "tradefed", "testng"], - test_suites: ["general-tests", "mts-mediaprovider", "cts"], test_config: "CoreTest.xml", } java_test_host { name: "CtsScopedStorageHostTest", srcs: ["host/src/**/*.java"], - libs: ["cts-tradefed", "tradefed", "testng"], - test_suites: ["general-tests", "mts-mediaprovider", "cts"], + libs: [ + "cts-tradefed", + "tradefed", + "testng", + ], + static_libs: [ + "modules-utils-build-testing", + "compatibility-host-util", + ], + test_suites: [ + "general-tests", + "mts-mediaprovider", + "cts", + ], test_config: "AndroidTest.xml", data: [ ":CtsLegacyStorageTestAppRequestLegacy", @@ -205,20 +287,20 @@ java_test_host { java_test_host { name: "CtsScopedStoragePublicVolumeHostTest", srcs: ["host/src/**/*.java"], - libs: ["cts-tradefed", "tradefed", "testng"], - test_suites: ["general-tests", "mts-mediaprovider"], - test_config: "PublicVolumeTest.xml", -} - -java_test_host { - name: "CtsAppCloningHostTest", - srcs: [ - "host/src/android/scopedstorage/cts/host/AppCloningHostTest.java", - "host/src/android/scopedstorage/cts/host/BaseHostTestCase.java" + libs: [ + "cts-tradefed", + "tradefed", + "testng", + ], + static_libs: [ + "modules-utils-build-testing", + "compatibility-host-util", + ], + test_suites: [ + "general-tests", + "mts-mediaprovider", ], - libs: ["cts-tradefed", "tradefed", "testng"], - test_suites: ["general-tests", "mts-mediaprovider", "cts"], - test_config: "AndroidTestAppCloning.xml", + test_config: "PublicVolumeTest.xml", } android_test { @@ -226,13 +308,24 @@ android_test { manifest: "device/AndroidManifest.xml", test_config: "device/AndroidTest.xml", srcs: ["device/**/*.java"], - static_libs: ["truth-prebuilt", "cts-scopedstorage-lib",], + static_libs: [ + "truth-prebuilt", + "cts-scopedstorage-lib", + ], compile_multilib: "both", - test_suites: ["general-tests", "mts-mediaprovider", "cts"], + test_suites: [ + "general-tests", + "mts-mediaprovider", + "cts", + ], sdk_version: "test_current", target_sdk_version: "31", min_sdk_version: "30", - libs: ["android.test.base", "android.test.mock", "android.test.runner",], + libs: [ + "android.test.base", + "android.test.mock", + "android.test.runner", + ], java_resources: [ ":CtsScopedStorageTestAppA", ":CtsScopedStorageTestAppB", @@ -244,5 +337,5 @@ android_test { ":CtsScopedStorageTestAppFileManagerBypassDB", ":CtsScopedStorageTestAppSystemGalleryBypassDB", ":CtsScopedStorageTestAppSystemGallery30BypassDB", - ] + ], } diff --git a/hostsidetests/securitybulletin/securityPatch/CVE-2019-2017/Android.bp b/hostsidetests/securitybulletin/securityPatch/CVE-2019-2017/Android.bp new file mode 100644 index 00000000000..5dac7f7abc3 --- /dev/null +++ b/hostsidetests/securitybulletin/securityPatch/CVE-2019-2017/Android.bp @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2022 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package { + default_applicable_licenses: ["Android-Apache-2.0"], +} + +cc_test { + name: "CVE-2019-2017", + defaults: ["cts_hostsidetests_securitybulletin_defaults"], + srcs: [ + "poc.cpp", + ], + compile_multilib: "64", + shared_libs: [ + "libnfc-nci", + ], + include_dirs: [ + "system/nfc/src/nfc/include", + "system/nfc/src/gki/common", + "system/nfc/src/gki/ulinux", + "system/nfc/src/include", + ], +} diff --git a/hostsidetests/securitybulletin/securityPatch/CVE-2019-2017/poc.cpp b/hostsidetests/securitybulletin/securityPatch/CVE-2019-2017/poc.cpp new file mode 100644 index 00000000000..9ecc457f143 --- /dev/null +++ b/hostsidetests/securitybulletin/securityPatch/CVE-2019-2017/poc.cpp @@ -0,0 +1,73 @@ +/* + * Copyright (C) 2022 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <rw_int.h> +#include <stdlib.h> +#include "../includes/common.h" + +bool testInProgress = false; +struct sigaction new_action, old_action; +void sigabrt_handler(int signum, siginfo_t *info, void *context) { + if (testInProgress && info->si_signo == SIGABRT) { + (*old_action.sa_sigaction)(signum, info, context); + return; + } + exit(EXIT_FAILURE); +} + +uint8_t *p_data = nullptr; +extern tRW_CB rw_cb; + +extern void rw_t2t_handle_rsp(uint8_t *p_data); + +void poc_cback(uint8_t, tRW_DATA *) {} + +void exit_handler(void) { + if (p_data) { + free(p_data); + p_data = nullptr; + } +} + +int main() { + atexit(exit_handler); + sigemptyset(&new_action.sa_mask); + new_action.sa_flags = SA_SIGINFO; + new_action.sa_sigaction = sigabrt_handler; + sigaction(SIGABRT, &new_action, &old_action); + + tNFC_ACTIVATE_DEVT p_activate_params = {}; + p_activate_params.protocol = NFC_PROTOCOL_ISO_DEP; + p_activate_params.rf_tech_param.mode = NFC_DISCOVERY_TYPE_POLL_A; + FAIL_CHECK(RW_SetActivatedTagType(&p_activate_params, &poc_cback) == NFC_STATUS_OK); + FAIL_CHECK(rw_cb.p_cback == &poc_cback); + tRW_T2T_CB *p_t2t = &rw_cb.tcb.t2t; + p_t2t->state = RW_T2T_STATE_DETECT_TLV; + p_t2t->tlv_detect = TAG_LOCK_CTRL_TLV; + p_t2t->substate = RW_T2T_SUBSTATE_WAIT_READ_TLV_VALUE; + p_t2t->found_tlv = TAG_LOCK_CTRL_TLV; + p_t2t->bytes_count = 0; + p_t2t->p_cur_cmd_buf = (NFC_HDR *)GKI_getpoolbuf(NFC_RW_POOL_ID); + rw_cb.p_cback = &poc_cback; + p_data = (uint8_t *)malloc(sizeof(uint8_t)); + FAIL_CHECK(p_data); + + testInProgress = true; + rw_t2t_handle_rsp(p_data); + testInProgress = false; + + return EXIT_SUCCESS; +} diff --git a/hostsidetests/securitybulletin/securityPatch/CVE-2019-2020/Android.bp b/hostsidetests/securitybulletin/securityPatch/CVE-2019-2020/Android.bp new file mode 100644 index 00000000000..5fdbfdba161 --- /dev/null +++ b/hostsidetests/securitybulletin/securityPatch/CVE-2019-2020/Android.bp @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2022 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package { + default_applicable_licenses: ["Android-Apache-2.0"], +} + +cc_test { + name: "CVE-2019-2020", + defaults: ["cts_hostsidetests_securitybulletin_defaults"], + srcs: [ + "poc.cpp", + ], + compile_multilib: "64", + shared_libs: [ + "libnfc-nci", + ], + include_dirs: [ + "system/nfc/src/nfc/include", + "system/nfc/src/gki/common", + "system/nfc/src/gki/ulinux", + "system/nfc/src/include", + ], +} diff --git a/hostsidetests/securitybulletin/securityPatch/CVE-2019-2020/poc.cpp b/hostsidetests/securitybulletin/securityPatch/CVE-2019-2020/poc.cpp new file mode 100644 index 00000000000..ba4d950474e --- /dev/null +++ b/hostsidetests/securitybulletin/securityPatch/CVE-2019-2020/poc.cpp @@ -0,0 +1,80 @@ +/* + * Copyright (C) 2022 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <stdlib.h> +#include "../includes/common.h" + +#include <nfc_api.h> +#include <nfc_int.h> +#include <rw_int.h> +#include <tags_defs.h> +#include <llcp_int.h> + +#define DEFAULT_SAP 1 +#define LENGTH 0 + +bool testInProgress = false; + +struct sigaction new_action, old_action; + +void sigsegv_handler(int signum, siginfo_t *info, void *context) { + if (testInProgress && info->si_signo == SIGSEGV) { + (*old_action.sa_sigaction)(signum, info, context); + return; + } + exit(EXIT_FAILURE); +} + +extern tLLCP_CB llcp_cb; +extern tRW_CB rw_cb; +extern tNFC_CB nfc_cb; + +void GKI_freebuf(void* x) { (void)x; } +void GKI_start_timer(uint8_t, int32_t, bool) {} +void GKI_stop_timer(uint8_t) {} + +void poc_cback(tRW_EVENT event, tRW_DATA* p_rw_data) { + (void)event; + (void)p_rw_data; +} + +int32_t main() { + sigemptyset(&new_action.sa_mask); + new_action.sa_flags = SA_SIGINFO; + new_action.sa_sigaction = sigsegv_handler; + sigaction(SIGSEGV, &new_action, &old_action); + + tNFC_ACTIVATE_DEVT p_activate_params = {}; + p_activate_params.protocol = NFC_PROTOCOL_ISO_DEP; + p_activate_params.rf_tech_param.mode = NFC_DISCOVERY_TYPE_POLL_A; + RW_SetActivatedTagType(&p_activate_params, &poc_cback); + FAIL_CHECK(rw_cb.p_cback == &poc_cback); + + GKI_init(); + llcp_init(); + for (int32_t n = 0; n < LLCP_MAX_DATA_LINK; ++n) { + llcp_cb.dlcb[n].state = LLCP_DLC_STATE_CONNECTED; + llcp_cb.dlcb[n].local_sap = DEFAULT_SAP; + llcp_cb.dlcb[n].remote_sap = DEFAULT_SAP; + } + + testInProgress = true; + llcp_dlc_proc_rx_pdu(DEFAULT_SAP, LLCP_PDU_RNR_TYPE, DEFAULT_SAP, LENGTH, + nullptr); + testInProgress = false; + + return EXIT_SUCCESS; +} diff --git a/hostsidetests/securitybulletin/src/android/security/cts/Bug_183613671.java b/hostsidetests/securitybulletin/src/android/security/cts/Bug_183613671.java index 63a5370188f..75bbd0ac298 100644 --- a/hostsidetests/securitybulletin/src/android/security/cts/Bug_183613671.java +++ b/hostsidetests/securitybulletin/src/android/security/cts/Bug_183613671.java @@ -23,10 +23,10 @@ import org.junit.Test; import org.junit.Before; import org.junit.runner.RunWith; import com.android.tradefed.testtype.DeviceJUnit4ClassRunner; -import com.android.tradefed.testtype.junit4.BaseHostJUnit4Test; +import com.android.sts.common.tradefed.testtype.StsExtraBusinessLogicHostTestBase; @RunWith(DeviceJUnit4ClassRunner.class) -public final class Bug_183613671 extends BaseHostJUnit4Test { +public final class Bug_183613671 extends StsExtraBusinessLogicHostTestBase { private static final String TEST_PKG = "android.security.cts.BUG_183613671"; private static final String TEST_CLASS = TEST_PKG + "." + "DeviceTest"; private static final String TEST_APP = "BUG-183613671.apk"; diff --git a/hostsidetests/securitybulletin/src/android/security/cts/Bug_183963253.java b/hostsidetests/securitybulletin/src/android/security/cts/Bug_183963253.java index e31cb479c0e..adf6103043a 100644 --- a/hostsidetests/securitybulletin/src/android/security/cts/Bug_183963253.java +++ b/hostsidetests/securitybulletin/src/android/security/cts/Bug_183963253.java @@ -25,10 +25,10 @@ import org.junit.Before; import org.junit.runner.RunWith; import com.android.tradefed.testtype.DeviceJUnit4ClassRunner; -import com.android.tradefed.testtype.junit4.BaseHostJUnit4Test; +import com.android.sts.common.tradefed.testtype.StsExtraBusinessLogicHostTestBase; @RunWith(DeviceJUnit4ClassRunner.class) -public final class Bug_183963253 extends BaseHostJUnit4Test { +public final class Bug_183963253 extends StsExtraBusinessLogicHostTestBase { private static final String TEST_PKG = "android.security.cts.BUG_183963253"; private static final String TEST_CLASS = TEST_PKG + "." + "DeviceTest"; private static final String TEST_APP = "BUG-183963253.apk"; diff --git a/hostsidetests/securitybulletin/src/android/security/cts/CVE_2019_2017.java b/hostsidetests/securitybulletin/src/android/security/cts/CVE_2019_2017.java new file mode 100644 index 00000000000..b7c2ea8fab3 --- /dev/null +++ b/hostsidetests/securitybulletin/src/android/security/cts/CVE_2019_2017.java @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2022 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.security.cts; + +import android.platform.test.annotations.AsbSecurityTest; + +import com.android.compatibility.common.util.CrashUtils; +import com.android.compatibility.common.util.CrashUtils.Config.BacktraceFilterPattern; +import com.android.tradefed.testtype.DeviceJUnit4ClassRunner; + +import java.util.regex.Pattern; + +import org.junit.runner.RunWith; +import org.junit.Test; + +@RunWith(DeviceJUnit4ClassRunner.class) +public class CVE_2019_2017 extends SecurityTestCase { + + /** + * b/121035711 + * Vulnerability Behaviour: SIGABRT in self + * Vulnerable Library: libnfc-nci (As per AOSP code) + * Vulnerable Function: rw_t2t_handle_tlv_detect_rsp (As per AOSP code) + */ + @AsbSecurityTest(cveBugId = 121035711) + @Test + public void testPocCVE_2019_2017() throws Exception { + AdbUtils.assumeHasNfc(getDevice()); + assumeIsSupportedNfcDevice(getDevice()); + pocPusher.only64(); + String signals[] = {CrashUtils.SIGABRT}; + String binaryName = "CVE-2019-2017"; + AdbUtils.pocConfig testConfig = new AdbUtils.pocConfig(binaryName, getDevice()); + testConfig.config = new CrashUtils.Config().setProcessPatterns(Pattern.compile(binaryName)) + .setBacktraceIncludes(new BacktraceFilterPattern("libnfc-nci", + "rw_t2t_handle_tlv_detect_rsp")); + testConfig.config + .setBacktraceExcludes(new BacktraceFilterPattern("libdl", "__cfi_slowpath")); + testConfig.config.setSignals(signals); + AdbUtils.runPocAssertNoCrashesNotVulnerable(testConfig); + } +} diff --git a/hostsidetests/securitybulletin/src/android/security/cts/CVE_2019_2020.java b/hostsidetests/securitybulletin/src/android/security/cts/CVE_2019_2020.java new file mode 100644 index 00000000000..b65faeef587 --- /dev/null +++ b/hostsidetests/securitybulletin/src/android/security/cts/CVE_2019_2020.java @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2022 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.security.cts; + +import android.platform.test.annotations.AsbSecurityTest; + +import com.android.compatibility.common.util.CrashUtils; +import com.android.compatibility.common.util.CrashUtils.Config.BacktraceFilterPattern; +import com.android.tradefed.testtype.DeviceJUnit4ClassRunner; + +import java.util.regex.Pattern; + +import org.junit.runner.RunWith; +import org.junit.Test; + +@RunWith(DeviceJUnit4ClassRunner.class) +public class CVE_2019_2020 extends SecurityTestCase { + + /** + * b/116788646 + * Vulnerability Behaviour: SIGSEGV in self + * Vulnerable Library: libnfc-nci (As per AOSP code) + * Vulnerable Function: llcp_dlc_proc_rx_pdu (As per AOSP code) + */ + @AsbSecurityTest(cveBugId = 116788646) + @Test + public void testPocCVE_2019_2020() throws Exception { + AdbUtils.assumeHasNfc(getDevice()); + assumeIsSupportedNfcDevice(getDevice()); + pocPusher.only64(); + String signals[] = {CrashUtils.SIGSEGV}; + String binaryName = "CVE-2019-2020"; + AdbUtils.pocConfig testConfig = new AdbUtils.pocConfig(binaryName, getDevice()); + testConfig.config = new CrashUtils.Config().setProcessPatterns(Pattern.compile(binaryName)) + .setBacktraceIncludes(new BacktraceFilterPattern("libnfc-nci", + "llcp_dlc_proc_rx_pdu")); + testConfig.config + .setBacktraceExcludes(new BacktraceFilterPattern("libdl", "__cfi_slowpath")); + testConfig.config.checkMinAddress(false); + testConfig.config.setSignals(signals); + AdbUtils.runPocAssertNoCrashesNotVulnerable(testConfig); + } +} diff --git a/hostsidetests/securitybulletin/src/android/security/cts/CVE_2021_0305.java b/hostsidetests/securitybulletin/src/android/security/cts/CVE_2021_0305.java index a6ae4f823fa..4b1bc22e33f 100644 --- a/hostsidetests/securitybulletin/src/android/security/cts/CVE_2021_0305.java +++ b/hostsidetests/securitybulletin/src/android/security/cts/CVE_2021_0305.java @@ -22,7 +22,7 @@ import android.util.Log; import android.platform.test.annotations.AsbSecurityTest; import com.android.tradefed.testtype.DeviceJUnit4ClassRunner; -import com.android.tradefed.testtype.junit4.BaseHostJUnit4Test; +import com.android.sts.common.tradefed.testtype.StsExtraBusinessLogicHostTestBase; import org.junit.After; import org.junit.Assert; @@ -38,7 +38,7 @@ import org.junit.runner.RunWith; * collected from the hostside and reported accordingly. */ @RunWith(DeviceJUnit4ClassRunner.class) -public class CVE_2021_0305 extends BaseHostJUnit4Test { +public class CVE_2021_0305 extends StsExtraBusinessLogicHostTestBase { private static final String TEST_PKG = "android.security.cts.CVE_2021_0305"; private static final String TEST_CLASS = TEST_PKG + "." + "DeviceTest"; private static final String TEST_APP = "CVE-2021-0305.apk"; diff --git a/hostsidetests/securitybulletin/src/android/security/cts/CVE_2021_0481.java b/hostsidetests/securitybulletin/src/android/security/cts/CVE_2021_0481.java index 5f0c200d1f4..2ae3f0f0d9c 100644 --- a/hostsidetests/securitybulletin/src/android/security/cts/CVE_2021_0481.java +++ b/hostsidetests/securitybulletin/src/android/security/cts/CVE_2021_0481.java @@ -22,7 +22,7 @@ import android.util.Log; import android.platform.test.annotations.AsbSecurityTest; import com.android.tradefed.testtype.DeviceJUnit4ClassRunner; -import com.android.tradefed.testtype.junit4.BaseHostJUnit4Test; +import com.android.sts.common.tradefed.testtype.StsExtraBusinessLogicHostTestBase; import com.android.tradefed.log.LogUtil.CLog; import org.junit.After; @@ -42,7 +42,7 @@ import static org.hamcrest.CoreMatchers.*; * collected from the hostside and reported accordingly. */ @RunWith(DeviceJUnit4ClassRunner.class) -public class CVE_2021_0481 extends BaseHostJUnit4Test { +public class CVE_2021_0481 extends StsExtraBusinessLogicHostTestBase { private static final String TEST_PKG = "android.security.cts.CVE_2021_0481"; private static final String TEST_CLASS = TEST_PKG + "." + "DeviceTest"; private static final String TEST_APP = "CVE-2021-0481.apk"; diff --git a/hostsidetests/securitybulletin/src/android/security/cts/CVE_2021_0523.java b/hostsidetests/securitybulletin/src/android/security/cts/CVE_2021_0523.java index 77c9188d6b5..3e6928853de 100644 --- a/hostsidetests/securitybulletin/src/android/security/cts/CVE_2021_0523.java +++ b/hostsidetests/securitybulletin/src/android/security/cts/CVE_2021_0523.java @@ -20,14 +20,15 @@ import android.platform.test.annotations.AppModeFull; import android.platform.test.annotations.AsbSecurityTest; import com.android.tradefed.device.ITestDevice; import com.android.tradefed.testtype.DeviceJUnit4ClassRunner; -import com.android.tradefed.testtype.junit4.BaseHostJUnit4Test; +import com.android.sts.common.tradefed.testtype.StsExtraBusinessLogicHostTestBase; + import org.junit.Assert; import org.junit.Before; import org.junit.runner.RunWith; import org.junit.Test; @RunWith(DeviceJUnit4ClassRunner.class) -public class CVE_2021_0523 extends BaseHostJUnit4Test { +public class CVE_2021_0523 extends StsExtraBusinessLogicHostTestBase { private static final String TEST_PKG = "android.security.cts.cve_2021_0523"; private static final String TEST_CLASS = TEST_PKG + "." + "DeviceTest"; private static final String TEST_APP = "CVE-2021-0523.apk"; diff --git a/hostsidetests/securitybulletin/src/android/security/cts/CVE_2021_0586.java b/hostsidetests/securitybulletin/src/android/security/cts/CVE_2021_0586.java index 34e2ca1ec31..5a7ec8d1c24 100644 --- a/hostsidetests/securitybulletin/src/android/security/cts/CVE_2021_0586.java +++ b/hostsidetests/securitybulletin/src/android/security/cts/CVE_2021_0586.java @@ -20,14 +20,14 @@ import android.platform.test.annotations.AppModeFull; import android.platform.test.annotations.AsbSecurityTest; import com.android.tradefed.device.ITestDevice; import com.android.tradefed.testtype.DeviceJUnit4ClassRunner; -import com.android.tradefed.testtype.junit4.BaseHostJUnit4Test; +import com.android.sts.common.tradefed.testtype.StsExtraBusinessLogicHostTestBase; import org.junit.Assert; import org.junit.Before; import org.junit.runner.RunWith; import org.junit.Test; @RunWith(DeviceJUnit4ClassRunner.class) -public class CVE_2021_0586 extends BaseHostJUnit4Test { +public class CVE_2021_0586 extends StsExtraBusinessLogicHostTestBase { private static final String TEST_PKG = "android.security.cts.cve_2021_0586"; private static final String TEST_CLASS = TEST_PKG + "." + "DeviceTest"; private static final String TEST_APP = "CVE-2021-0586.apk"; diff --git a/hostsidetests/securitybulletin/src/android/security/cts/CVE_2021_0591.java b/hostsidetests/securitybulletin/src/android/security/cts/CVE_2021_0591.java index 0c8f0a9fd1b..eb74b201862 100644 --- a/hostsidetests/securitybulletin/src/android/security/cts/CVE_2021_0591.java +++ b/hostsidetests/securitybulletin/src/android/security/cts/CVE_2021_0591.java @@ -21,7 +21,7 @@ import android.platform.test.annotations.AsbSecurityTest; import android.platform.test.annotations.RequiresDevice; import com.android.tradefed.device.ITestDevice; import com.android.tradefed.testtype.DeviceJUnit4ClassRunner; -import com.android.tradefed.testtype.junit4.BaseHostJUnit4Test; +import com.android.sts.common.tradefed.testtype.StsExtraBusinessLogicHostTestBase; import java.util.regex.Pattern; import org.junit.Assert; import org.junit.Before; @@ -33,7 +33,7 @@ import static org.junit.Assert.assertThat; import static org.junit.Assume.assumeTrue; @RunWith(DeviceJUnit4ClassRunner.class) -public class CVE_2021_0591 extends BaseHostJUnit4Test { +public class CVE_2021_0591 extends StsExtraBusinessLogicHostTestBase { private static final String TEST_PKG = "android.security.cts.CVE_2021_0591"; private static final String TEST_CLASS = TEST_PKG + "." + "DeviceTest"; diff --git a/hostsidetests/securitybulletin/src/android/security/cts/CVE_2021_0691.java b/hostsidetests/securitybulletin/src/android/security/cts/CVE_2021_0691.java index 9b592bdcbbd..bf261fd0eab 100644 --- a/hostsidetests/securitybulletin/src/android/security/cts/CVE_2021_0691.java +++ b/hostsidetests/securitybulletin/src/android/security/cts/CVE_2021_0691.java @@ -22,7 +22,7 @@ import android.util.Log; import android.platform.test.annotations.AsbSecurityTest; import com.android.tradefed.testtype.DeviceJUnit4ClassRunner; -import com.android.tradefed.testtype.junit4.BaseHostJUnit4Test; +import com.android.sts.common.tradefed.testtype.StsExtraBusinessLogicHostTestBase; import com.android.tradefed.log.LogUtil.CLog; import org.junit.After; @@ -38,7 +38,7 @@ import static org.hamcrest.CoreMatchers.*; * Test installs sample app and then tries to overwrite *.apk file */ @RunWith(DeviceJUnit4ClassRunner.class) -public class CVE_2021_0691 extends BaseHostJUnit4Test { +public class CVE_2021_0691 extends StsExtraBusinessLogicHostTestBase { private static final String TEST_PKG = "android.security.cts.CVE_2021_0691"; private static final String TEST_APP = "CVE-2021-0691.apk"; private static final String DEVICE_TMP_DIR = "/data/local/tmp/"; diff --git a/hostsidetests/securitybulletin/src/android/security/cts/CVE_2021_0706.java b/hostsidetests/securitybulletin/src/android/security/cts/CVE_2021_0706.java index c46bedeb2f7..fabaf89437a 100644 --- a/hostsidetests/securitybulletin/src/android/security/cts/CVE_2021_0706.java +++ b/hostsidetests/securitybulletin/src/android/security/cts/CVE_2021_0706.java @@ -20,13 +20,13 @@ import android.platform.test.annotations.AppModeFull; import android.platform.test.annotations.AsbSecurityTest; import com.android.tradefed.device.ITestDevice; import com.android.tradefed.testtype.DeviceJUnit4ClassRunner; -import com.android.tradefed.testtype.junit4.BaseHostJUnit4Test; +import com.android.sts.common.tradefed.testtype.StsExtraBusinessLogicHostTestBase; import org.junit.Before; import org.junit.runner.RunWith; import org.junit.Test; @RunWith(DeviceJUnit4ClassRunner.class) -public class CVE_2021_0706 extends BaseHostJUnit4Test { +public class CVE_2021_0706 extends StsExtraBusinessLogicHostTestBase { private static final String TEST_PKG = "android.security.cts.CVE_2021_0706"; private static final String TEST_CLASS = TEST_PKG + "." + "DeviceTest"; diff --git a/hostsidetests/securitybulletin/src/android/security/cts/CVE_2021_0921.java b/hostsidetests/securitybulletin/src/android/security/cts/CVE_2021_0921.java index 27900e19fcb..760c265fe09 100644 --- a/hostsidetests/securitybulletin/src/android/security/cts/CVE_2021_0921.java +++ b/hostsidetests/securitybulletin/src/android/security/cts/CVE_2021_0921.java @@ -20,7 +20,7 @@ import android.platform.test.annotations.AppModeFull; import android.util.Log; import android.platform.test.annotations.AsbSecurityTest; import com.android.tradefed.testtype.DeviceJUnit4ClassRunner; -import com.android.tradefed.testtype.junit4.BaseHostJUnit4Test; +import com.android.sts.common.tradefed.testtype.StsExtraBusinessLogicHostTestBase; import com.android.tradefed.log.LogUtil.CLog; import org.junit.After; import org.junit.Assert; @@ -30,7 +30,7 @@ import org.junit.runner.RunWith; import static org.junit.Assert.*; @RunWith(DeviceJUnit4ClassRunner.class) -public class CVE_2021_0921 extends BaseHostJUnit4Test { +public class CVE_2021_0921 extends StsExtraBusinessLogicHostTestBase { private static final String TEST_PKG = "android.security.cts.CVE_2021_0921"; private static final String TEST_CLASS = TEST_PKG + "." + "DeviceTest"; private static final String TEST_APP = "CVE-2021-0921.apk"; diff --git a/hostsidetests/securitybulletin/src/android/security/cts/CVE_2021_0953.java b/hostsidetests/securitybulletin/src/android/security/cts/CVE_2021_0953.java index 6d320f562d8..ecb6bdd3cd4 100644 --- a/hostsidetests/securitybulletin/src/android/security/cts/CVE_2021_0953.java +++ b/hostsidetests/securitybulletin/src/android/security/cts/CVE_2021_0953.java @@ -19,13 +19,13 @@ package android.security.cts; import android.platform.test.annotations.AsbSecurityTest; import com.android.tradefed.device.ITestDevice; import com.android.tradefed.testtype.DeviceJUnit4ClassRunner; -import com.android.tradefed.testtype.junit4.BaseHostJUnit4Test; +import com.android.sts.common.tradefed.testtype.StsExtraBusinessLogicHostTestBase; import org.junit.Test; import org.junit.runner.RunWith; @RunWith(DeviceJUnit4ClassRunner.class) -public class CVE_2021_0953 extends BaseHostJUnit4Test { +public class CVE_2021_0953 extends StsExtraBusinessLogicHostTestBase { @AsbSecurityTest(cveBugId = 184046278) @Test diff --git a/hostsidetests/securitybulletin/src/android/security/cts/CVE_2021_0965.java b/hostsidetests/securitybulletin/src/android/security/cts/CVE_2021_0965.java index 4deab6614e8..65934f2741f 100644 --- a/hostsidetests/securitybulletin/src/android/security/cts/CVE_2021_0965.java +++ b/hostsidetests/securitybulletin/src/android/security/cts/CVE_2021_0965.java @@ -21,7 +21,7 @@ import android.platform.test.annotations.AppModeFull; import android.platform.test.annotations.AsbSecurityTest; import com.android.tradefed.testtype.DeviceJUnit4ClassRunner; -import com.android.tradefed.testtype.junit4.BaseHostJUnit4Test; +import com.android.sts.common.tradefed.testtype.StsExtraBusinessLogicHostTestBase; import org.junit.Assert; import org.junit.Before; @@ -29,7 +29,7 @@ import org.junit.Test; import org.junit.runner.RunWith; @RunWith(DeviceJUnit4ClassRunner.class) -public class CVE_2021_0965 extends BaseHostJUnit4Test { +public class CVE_2021_0965 extends StsExtraBusinessLogicHostTestBase { private static final String TEST_PKG = "android.security.cts.CVE_2021_0965"; private static final String TEST_CLASS = TEST_PKG + "." + "DeviceTest"; private static final String TEST_APP = "CVE-2021-0965.apk"; diff --git a/hostsidetests/securitybulletin/src/android/security/cts/CVE_2021_39700.java b/hostsidetests/securitybulletin/src/android/security/cts/CVE_2021_39700.java new file mode 100644 index 00000000000..363e522a406 --- /dev/null +++ b/hostsidetests/securitybulletin/src/android/security/cts/CVE_2021_39700.java @@ -0,0 +1,51 @@ +/** + * Copyright (C) 2022 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.security.cts; + +import static org.junit.Assert.assertTrue; +import static org.junit.Assume.assumeTrue; + +import android.platform.test.annotations.AsbSecurityTest; + +import com.android.tradefed.device.ITestDevice; +import com.android.tradefed.testtype.DeviceJUnit4ClassRunner; +import com.android.tradefed.testtype.junit4.BaseHostJUnit4Test; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import java.io.File; + +@RunWith(DeviceJUnit4ClassRunner.class) +public class CVE_2021_39700 extends BaseHostJUnit4Test { + + /** + * b/201645790 + * This test is related to + * "hostsidetests/appsecurity/src/android/appsecurity/cts/ListeningPortsTest.java" + */ + @AsbSecurityTest(cveBugId = 201645790) + @Test + public void testPocCVE_2021_39700() throws Exception { + ITestDevice device = getDevice(); + assumeTrue("Failed to unroot the device", device.disableAdbRoot()); + String procUdp6File = "/proc/net/udp6"; + File tempFile = File.createTempFile("CVE_2021_39700", "temp"); + assertTrue("Vulnerable to b/201645790 !!", device.pullFile(procUdp6File, tempFile)); + tempFile.deleteOnExit(); + } +} diff --git a/hostsidetests/securitybulletin/test-apps/CVE-2021-0523/src/android/security/cts/CVE_2021_0523/PocActivity.java b/hostsidetests/securitybulletin/test-apps/CVE-2021-0523/src/android/security/cts/CVE_2021_0523/PocActivity.java index a28b337a327..3e35266716d 100644 --- a/hostsidetests/securitybulletin/test-apps/CVE-2021-0523/src/android/security/cts/CVE_2021_0523/PocActivity.java +++ b/hostsidetests/securitybulletin/test-apps/CVE-2021-0523/src/android/security/cts/CVE_2021_0523/PocActivity.java @@ -17,6 +17,7 @@ package android.security.cts.cve_2021_0523; import android.app.Activity; +import android.content.ActivityNotFoundException; import android.content.Intent; import android.net.wifi.WifiManager; import android.os.Bundle; @@ -28,6 +29,10 @@ public class PocActivity extends Activity { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Intent intent = new Intent(WifiManager.ACTION_REQUEST_SCAN_ALWAYS_AVAILABLE); - startActivity(intent); + try { + startActivity(intent); + } catch (ActivityNotFoundException e) { + // do nothing + } } } diff --git a/hostsidetests/securitybulletin/test-apps/CVE-2021-0953/src/android/security/cts/CVE_2021_0953/PocActivity.java b/hostsidetests/securitybulletin/test-apps/CVE-2021-0953/src/android/security/cts/CVE_2021_0953/PocActivity.java index 3684cbe97cc..c28bd75d1b9 100644 --- a/hostsidetests/securitybulletin/test-apps/CVE-2021-0953/src/android/security/cts/CVE_2021_0953/PocActivity.java +++ b/hostsidetests/securitybulletin/test-apps/CVE-2021-0953/src/android/security/cts/CVE_2021_0953/PocActivity.java @@ -21,6 +21,7 @@ import android.app.PendingIntent; import android.appwidget.AppWidgetHost; import android.appwidget.AppWidgetManager; import android.content.ComponentName; +import android.content.ActivityNotFoundException; import android.content.Intent; import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; @@ -70,7 +71,13 @@ public class PocActivity extends Activity { intent.putExtra("appWidgetId", APPWIDGET_ID); intent.putExtra("appWidgetProvider", new ComponentName("com.android.quicksearchbox", "com.android.quicksearchbox.SearchWidgetProvider")); - PocActivity.this.startActivityForResult(intent, REQUEST_BIND_APPWIDGET); + try { + PocActivity.this.startActivityForResult(intent, REQUEST_BIND_APPWIDGET); + } catch (ActivityNotFoundException e) { + sendTestResult(getResources().getInteger(R.integer.assumption_failure), + "Could not start activity"); + return; + } String settingsPkgName = ""; PackageManager pm = getPackageManager(); List<ResolveInfo> ris = pm.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); diff --git a/tests/MediaProviderTranscode/AndroidTest.xml b/tests/MediaProviderTranscode/AndroidTest.xml index 7dc78ebcd2f..6b9c8e902fe 100644 --- a/tests/MediaProviderTranscode/AndroidTest.xml +++ b/tests/MediaProviderTranscode/AndroidTest.xml @@ -37,4 +37,8 @@ <option name="runner" value="androidx.test.runner.AndroidJUnitRunner" /> <option name="hidden-api-checks" value="false"/> </test> + + <object type="module_controller" class="com.android.tradefed.testtype.suite.module.MainlineTestModuleController"> + <option name="mainline-module-package-name" value="com.google.android.mediaprovider" /> + </object> </configuration> diff --git a/tests/providerui/src/android/providerui/cts/MediaStoreUiTest.java b/tests/providerui/src/android/providerui/cts/MediaStoreUiTest.java index 47fe16104d4..542b3aa9db6 100644 --- a/tests/providerui/src/android/providerui/cts/MediaStoreUiTest.java +++ b/tests/providerui/src/android/providerui/cts/MediaStoreUiTest.java @@ -16,6 +16,8 @@ package android.providerui.cts; +import static android.provider.cts.ProviderTestUtils.resolveVolumeName; + import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; @@ -122,6 +124,7 @@ public class MediaStoreUiTest { mActivity = (GetResultActivity) mInstrumentation.startActivitySync(intent); mInstrumentation.waitForIdleSync(); mActivity.clearResult(); + mDevice.wakeUp(); } @After @@ -147,6 +150,7 @@ public class MediaStoreUiTest { if (!supportsHardware()) return; prepareFile(); + clearDocumentsUi(); final Uri treeUri = acquireAccess(mFile, Environment.DIRECTORY_DOCUMENTS); assertNotNull(treeUri); @@ -175,6 +179,7 @@ public class MediaStoreUiTest { if (!supportsHardware()) return; prepareFile(); + clearDocumentsUi(); try { MediaStore.getDocumentUri(mActivity, mMediaStoreUri); @@ -189,6 +194,7 @@ public class MediaStoreUiTest { if (!supportsHardware()) return; prepareFile(); + clearDocumentsUi(); final Uri treeUri = acquireAccess(mFile, Environment.DIRECTORY_DOCUMENTS); Log.v(TAG, "Tree " + treeUri); @@ -408,7 +414,7 @@ public class MediaStoreUiTest { } private void prepareFile() throws Exception { - final File dir = new File(getVolumePath(mVolumeName), + final File dir = new File(getVolumePath(resolveVolumeName(mVolumeName)), Environment.DIRECTORY_DOCUMENTS); final File file = new File(dir, "cts" + System.nanoTime() + ".txt"); @@ -419,7 +425,7 @@ public class MediaStoreUiTest { } private void prepareFile(String rawText) throws Exception { - final File dir = new File(getVolumePath(mVolumeName), + final File dir = new File(getVolumePath(resolveVolumeName(mVolumeName)), Environment.DIRECTORY_DOCUMENTS); final File file = new File(dir, "cts" + System.nanoTime() + ".txt"); @@ -430,7 +436,8 @@ public class MediaStoreUiTest { } private Pair<Uri, File> prepareFileAndFetchDetails(String rawText) throws Exception { - final File dir = new File(getVolumePath(mVolumeName), Environment.DIRECTORY_DOCUMENTS); + final File dir = new File(getVolumePath(resolveVolumeName(mVolumeName)), + Environment.DIRECTORY_DOCUMENTS); final File file = new File(dir, "cts" + System.nanoTime() + ".txt"); File stagedFile = stageFileWithRawText(rawText, file); diff --git a/tests/tests/security/src/android/security/cts/AllocatePixelRefIntOverflowTest.java b/tests/tests/security/src/android/security/cts/AllocatePixelRefIntOverflowTest.java index 5d297c6a9b2..b2e55864d49 100644 --- a/tests/tests/security/src/android/security/cts/AllocatePixelRefIntOverflowTest.java +++ b/tests/tests/security/src/android/security/cts/AllocatePixelRefIntOverflowTest.java @@ -19,13 +19,15 @@ package android.security.cts; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.platform.test.annotations.AsbSecurityTest; -import android.test.AndroidTestCase; +import com.android.sts.common.util.StsExtraBusinessLogicTestCase; + +import static org.junit.Assert.*; import java.io.InputStream; import android.security.cts.R; -public class AllocatePixelRefIntOverflowTest extends AndroidTestCase { +public class AllocatePixelRefIntOverflowTest extends StsExtraBusinessLogicTestCase { /** * Verifies that the device is not vulnerable to ANDROID-19270126: Android @@ -33,7 +35,7 @@ public class AllocatePixelRefIntOverflowTest extends AndroidTestCase { */ @AsbSecurityTest(cveBugId = 19394591) public void testAllocateJavaPixelRefIntOverflow() { - InputStream exploitImage = mContext.getResources().openRawResource( + InputStream exploitImage = getInstrumentation().getContext().getResources().openRawResource( R.raw.cve_2015_1531_b_19270126); /** * The decodeStream method results in SIGSEGV (Segmentation fault) on unpatched devices diff --git a/tests/tests/security/src/android/security/cts/BitmapFactoryDecodeStreamTest.java b/tests/tests/security/src/android/security/cts/BitmapFactoryDecodeStreamTest.java index 444b110b629..6a5003bb773 100644 --- a/tests/tests/security/src/android/security/cts/BitmapFactoryDecodeStreamTest.java +++ b/tests/tests/security/src/android/security/cts/BitmapFactoryDecodeStreamTest.java @@ -18,14 +18,14 @@ package android.security.cts; import android.graphics.BitmapFactory; import android.platform.test.annotations.AsbSecurityTest; -import android.test.AndroidTestCase; - +import com.android.sts.common.util.StsExtraBusinessLogicTestCase; +import static org.junit.Assert.*; import android.security.cts.R; import java.io.BufferedInputStream; import java.io.InputStream; -public class BitmapFactoryDecodeStreamTest extends AndroidTestCase { +public class BitmapFactoryDecodeStreamTest extends StsExtraBusinessLogicTestCase { /* * This test case reproduces the bug in CVE-2015-1532. * It verifies that the BitmapFactory:decodeStream method is not vulnerable @@ -34,7 +34,7 @@ public class BitmapFactoryDecodeStreamTest extends AndroidTestCase { */ @AsbSecurityTest(cveBugId = 19151999) public void testNinePatchHeapOverflow() throws Exception { - InputStream inStream = new BufferedInputStream(mContext.getResources().openRawResource( + InputStream inStream = new BufferedInputStream(getInstrumentation().getContext().getResources().openRawResource( R.raw.cve_2015_1532)); BitmapFactory.decodeStream(inStream); @@ -42,14 +42,14 @@ public class BitmapFactoryDecodeStreamTest extends AndroidTestCase { @AsbSecurityTest(cveBugId = 36724453) public void testPocCVE_2017_0691() throws Exception { - InputStream exploitImage = new BufferedInputStream(mContext.getResources().openRawResource( + InputStream exploitImage = new BufferedInputStream(getInstrumentation().getContext().getResources().openRawResource( R.raw.cve_2017_0691)); BitmapFactory.decodeStream(exploitImage); } @AsbSecurityTest(cveBugId = 65290323) public void test_b65290323() throws Exception { - InputStream exploitImage = new BufferedInputStream(mContext.getResources().openRawResource( + InputStream exploitImage = new BufferedInputStream(getInstrumentation().getContext().getResources().openRawResource( R.raw.b65290323)); BitmapFactory.decodeStream(exploitImage); } diff --git a/tests/tests/security/src/android/security/cts/NativeCodeTest.java b/tests/tests/security/src/android/security/cts/NativeCodeTest.java index c5a9bac2504..a46a2319584 100644 --- a/tests/tests/security/src/android/security/cts/NativeCodeTest.java +++ b/tests/tests/security/src/android/security/cts/NativeCodeTest.java @@ -18,9 +18,11 @@ package android.security.cts; import android.platform.test.annotations.AsbSecurityTest; -import junit.framework.TestCase; +import com.android.sts.common.util.StsExtraBusinessLogicTestCase; -public class NativeCodeTest extends TestCase { +import static org.junit.Assert.*; + +public class NativeCodeTest extends StsExtraBusinessLogicTestCase { static { System.loadLibrary("ctssecurity_jni"); diff --git a/tests/tests/security/src/android/security/cts/NetdTest.java b/tests/tests/security/src/android/security/cts/NetdTest.java index 14623fd4085..c32fbcf58aa 100644 --- a/tests/tests/security/src/android/security/cts/NetdTest.java +++ b/tests/tests/security/src/android/security/cts/NetdTest.java @@ -20,13 +20,13 @@ import android.os.Binder; import android.os.IBinder; import android.platform.test.annotations.AsbSecurityTest; -import junit.framework.TestCase; +import com.android.sts.common.util.StsExtraBusinessLogicTestCase; import java.lang.Class; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; -public class NetdTest extends TestCase { +public class NetdTest extends StsExtraBusinessLogicTestCase { /** * Detect if netd has unsanitized system call in Throttle API. diff --git a/tests/tests/security/src/android/security/cts/RunningAppProcessInfoTest.java b/tests/tests/security/src/android/security/cts/RunningAppProcessInfoTest.java index 8405acc0265..a091282b3f7 100644 --- a/tests/tests/security/src/android/security/cts/RunningAppProcessInfoTest.java +++ b/tests/tests/security/src/android/security/cts/RunningAppProcessInfoTest.java @@ -19,11 +19,13 @@ package android.security.cts; import android.app.ActivityManager; import android.content.Context; import android.platform.test.annotations.AsbSecurityTest; -import android.test.AndroidTestCase; +import com.android.sts.common.util.StsExtraBusinessLogicTestCase; + +import static org.junit.Assert.*; import java.util.List; -public class RunningAppProcessInfoTest extends AndroidTestCase { +public class RunningAppProcessInfoTest extends StsExtraBusinessLogicTestCase { /* * This test verifies severity vulnerability: apps can bypass the L restrictions in * getRunningTasks()is fixed. The test tries to get current RunningAppProcessInfo and passes @@ -33,7 +35,7 @@ public class RunningAppProcessInfoTest extends AndroidTestCase { @AsbSecurityTest(cveBugId = 20034603) public void testRunningAppProcessInfo() { ActivityManager amActivityManager = - (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE); + (ActivityManager) getInstrumentation().getContext().getSystemService(Context.ACTIVITY_SERVICE); List<ActivityManager.RunningAppProcessInfo> appList = amActivityManager.getRunningAppProcesses(); // The test will pass if it is able to get only its process info diff --git a/tests/tests/security/src/android/security/cts/SkiaICORecursiveDecodingTest.java b/tests/tests/security/src/android/security/cts/SkiaICORecursiveDecodingTest.java index 4a9802fc307..77aca65e765 100644 --- a/tests/tests/security/src/android/security/cts/SkiaICORecursiveDecodingTest.java +++ b/tests/tests/security/src/android/security/cts/SkiaICORecursiveDecodingTest.java @@ -19,14 +19,14 @@ package android.security.cts; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.platform.test.annotations.AsbSecurityTest; -import android.test.AndroidTestCase; +import com.android.sts.common.util.StsExtraBusinessLogicTestCase; import java.io.InputStream; import android.security.cts.R; import android.platform.test.annotations.AsbSecurityTest; -public class SkiaICORecursiveDecodingTest extends AndroidTestCase { +public class SkiaICORecursiveDecodingTest extends StsExtraBusinessLogicTestCase { @AsbSecurityTest(cveBugId = 73782357) public void testAndroid_cve_2017_13318() { @@ -47,7 +47,7 @@ public class SkiaICORecursiveDecodingTest extends AndroidTestCase { * Verifies that the device prevents recursive decoding of malformed ICO files */ public void doSkiaIcoRecursiveDecodingTest(int resId) { - InputStream exploitImage = mContext.getResources().openRawResource(resId); + InputStream exploitImage = getInstrumentation().getContext().getResources().openRawResource(resId); /** * The decodeStream method results in SIGSEGV (Segmentation fault) on unpatched devices * while decoding the exploit image which will lead to process crash diff --git a/tests/tests/wifi/src/android/net/wifi/cts/MultiStaConcurrencyWifiNetworkSpecifierTest.java b/tests/tests/wifi/src/android/net/wifi/cts/MultiStaConcurrencyWifiNetworkSpecifierTest.java index 71300513612..88457caaa9b 100644 --- a/tests/tests/wifi/src/android/net/wifi/cts/MultiStaConcurrencyWifiNetworkSpecifierTest.java +++ b/tests/tests/wifi/src/android/net/wifi/cts/MultiStaConcurrencyWifiNetworkSpecifierTest.java @@ -259,7 +259,9 @@ public class MultiStaConcurrencyWifiNetworkSpecifierTest extends WifiJUnit4TestB * Tests the concurrent connection flow. * 1. Connect to a network using peer to peer API. * 2. Connect to a network using internet connectivity API. - * 3. Verify that both connections are active. + * 3. Verify that both connections are active only the network for peer-to-peer and network + * for internet have different SSIDs. If they have the same SSID, verify there's exactly one + * connection. */ @Test public void testConnectToInternetNetworkWhenConnectedToPeerPeerNetwork() throws Exception { @@ -275,7 +277,9 @@ public class MultiStaConcurrencyWifiNetworkSpecifierTest extends WifiJUnit4TestB mTestNetworkForInternetConnection); // Ensure that there are 2 wifi connections available for apps. - assertThat(mTestHelper.getNumWifiConnections()).isEqualTo(2); + assertThat(mTestHelper.getNumWifiConnections()).isEqualTo( + mTestNetworkForPeerToPeer.SSID.equals(mTestNetworkForInternetConnection.SSID) + ? 1 : 2); } /** diff --git a/tests/tests/wifi/src/android/net/wifi/cts/TestHelper.java b/tests/tests/wifi/src/android/net/wifi/cts/TestHelper.java index 98ab11db9fb..c845138b0aa 100644 --- a/tests/tests/wifi/src/android/net/wifi/cts/TestHelper.java +++ b/tests/tests/wifi/src/android/net/wifi/cts/TestHelper.java @@ -146,7 +146,7 @@ public class TestHelper { wifiManager.unregisterScanResultsCallback(scanResultsCallback); } List<ScanResult> scanResults = wifiManager.getScanResults(); - if (scanResults == null || scanResults.isEmpty()) fail("No scan results available"); + if (scanResults == null || scanResults.isEmpty()) continue; for (ScanResult scanResult : scanResults) { WifiConfiguration matchingNetwork = savedNetworks.stream() .filter(network -> TextUtils.equals( |