diff options
author | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2022-12-05 03:38:50 +0000 |
---|---|---|
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2022-12-05 03:38:50 +0000 |
commit | 3a8082949aa7f396d863b60d5107b448c10d67ef (patch) | |
tree | 94a15036f0e3383f1474922e8b594b7c9c86d7c9 | |
parent | 21e92d1db5479fd4162cd54e9f710a2a3861c462 (diff) | |
parent | f95c6d4c1bffea3d03ee516eba01741ac56624a2 (diff) | |
download | cts-android13-mainline-extservices-release.tar.gz |
Snap for 9367776 from f95c6d4c1bffea3d03ee516eba01741ac56624a2 to mainline-extservices-releaseaml_ext_331814220aml_ext_331412000android13-mainline-extservices-release
Change-Id: Iedc8f841866e027baeba334bc7cadc56385fd21f
23 files changed, 318 insertions, 58 deletions
diff --git a/tests/PhotoPicker/src/android/photopicker/cts/PhotoPickerSettingsTest.java b/tests/PhotoPicker/src/android/photopicker/cts/PhotoPickerSettingsTest.java index 3c7ff091a2b..d0715e3f699 100644 --- a/tests/PhotoPicker/src/android/photopicker/cts/PhotoPickerSettingsTest.java +++ b/tests/PhotoPicker/src/android/photopicker/cts/PhotoPickerSettingsTest.java @@ -16,7 +16,6 @@ package android.photopicker.cts; -import static android.os.SystemProperties.getBoolean; import static android.photopicker.cts.util.PhotoPickerUiUtils.isPhotoPickerVisible; import static android.photopicker.cts.util.PhotoPickerUiUtils.verifyActionBarExists; import static android.photopicker.cts.util.PhotoPickerUiUtils.verifySettingsActivityIsVisible; @@ -47,8 +46,6 @@ public class PhotoPickerSettingsTest extends PhotoPickerBaseTest { private static final String NAMESPACE_STORAGE_NATIVE_BOOT = "storage_native_boot"; private static final String ALLOWED_CLOUD_PROVIDERS_KEY = "allowed_cloud_providers"; - private static final String SETTINGS_SYS_PROP = - "debug.photopicker.enable_settings_screen"; private static String sPreviouslyAllowedCloudProviders; @@ -62,8 +59,6 @@ public class PhotoPickerSettingsTest extends PhotoPickerBaseTest { String.format("device_config put %s %s not_empty", NAMESPACE_STORAGE_NATIVE_BOOT, ALLOWED_CLOUD_PROVIDERS_KEY)); Assume.assumeTrue(!getAllowedProvidersDeviceConfig().isBlank()); - sDevice.executeShellCommand(String.format("setprop %s true", SETTINGS_SYS_PROP)); - Assume.assumeTrue(getBoolean(SETTINGS_SYS_PROP, false)); } @AfterClass @@ -80,9 +75,6 @@ public class PhotoPickerSettingsTest extends PhotoPickerBaseTest { String.format("device_config put %s %s %s", NAMESPACE_STORAGE_NATIVE_BOOT, ALLOWED_CLOUD_PROVIDERS_KEY, sPreviouslyAllowedCloudProviders)); } - - // Disable Settings menu item in PhotoPickerActivity's overflow menu. - sDevice.executeShellCommand(String.format("setprop %s false", SETTINGS_SYS_PROP)); } @Test diff --git a/tests/tests/hibernation/Android.bp b/tests/tests/hibernation/Android.bp new file mode 100644 index 00000000000..3bb187f5d60 --- /dev/null +++ b/tests/tests/hibernation/Android.bp @@ -0,0 +1,65 @@ +// 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 { + name: "CtsHibernationTestCases", + defaults: [ + "cts_defaults", + "mts-target-sdk-version-current", + ], + compile_multilib: "both", + static_libs: [ + "androidx.test.core", + "androidx.test.ext.junit", + "androidx.test.rules", + "androidx.test.uiautomator_uiautomator", + "compatibility-device-util-axt", + "ctstestrunner-axt", + "testng", + "truth-prebuilt", + "guava", + "junit", + "hamcrest-library", + "modules-utils-build_system", + "safety-center-internal-data", + ], + srcs: [ + "src/**/*.kt", + ], + test_config: "AndroidTest.xml", + // Tag this module as a cts test artifact + test_suites: [ + "cts", + "general-tests", + "mts-permission", + ], + sdk_version: "test_current", + libs: [ + "android.test.runner", + "android.test.base", + ], + // Do not compress minijail policy files. + aaptflags: ["-0 .policy"], + min_sdk_version: "29", + data: [ + ":CtsAutoRevokeQApp", + ":CtsAutoRevokeSApp", + ":CtsAutoRevokeRApp", + ], + per_testcase_directory: true, +} diff --git a/tests/tests/hibernation/AndroidManifest.xml b/tests/tests/hibernation/AndroidManifest.xml new file mode 100644 index 00000000000..80ccd376851 --- /dev/null +++ b/tests/tests/hibernation/AndroidManifest.xml @@ -0,0 +1,30 @@ +<?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="android.hibernation.cts"> + + <uses-permission android:name="android.permission.QUERY_ALL_PACKAGES" /> + + <instrumentation android:name="androidx.test.runner.AndroidJUnitRunner" + android:targetPackage="android.hibernation.cts" + android:label="CTS tests of android.hibernation"> + <meta-data android:name="listener" + android:value="com.android.cts.runner.CtsTestRunListener"/> + </instrumentation> + +</manifest> diff --git a/tests/tests/hibernation/AndroidTest.xml b/tests/tests/hibernation/AndroidTest.xml new file mode 100644 index 00000000000..b5b82d27c14 --- /dev/null +++ b/tests/tests/hibernation/AndroidTest.xml @@ -0,0 +1,47 @@ +<?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. +--> +<configuration description="Configuration for Hibernation Tests"> + <option name="test-suite-tag" value="cts" /> + <option name="config-descriptor:metadata" key="component" value="framework" /> + <option name="config-descriptor:metadata" key="parameter" value="not_instant_app" /> + <option name="config-descriptor:metadata" key="parameter" value="not_multi_abi" /> + <option name="config-descriptor:metadata" key="parameter" value="secondary_user" /> + <option name="config-descriptor:metadata" key="parameter" value="multiuser" /> + <option name="config-descriptor:metadata" key="mainline-param" value="com.google.android.permission.apex" /> + <object type="module_controller" class="com.android.tradefed.testtype.suite.module.Sdk30ModuleController" /> + <target_preparer class="com.android.tradefed.targetprep.suite.SuiteApkInstaller"> + <option name="cleanup-apks" value="true" /> + <option name="test-file-name" value="CtsHibernationTestCases.apk" /> + </target_preparer> + <test class="com.android.tradefed.testtype.AndroidJUnitTest" > + <option name="package" value="android.hibernation.cts" /> + <option name="runtime-hint" value="3m15s" /> + <option name="runner" value="androidx.test.runner.AndroidJUnitRunner" /> + </test> + + <!-- Create Place to store apks --> + <target_preparer class="com.android.tradefed.targetprep.RunCommandTargetPreparer"> + <option name="run-command" value="mkdir -p /data/local/tmp/cts/hibernation" /> + <option name="run-command" value="am wait-for-broadcast-idle" /> + <option name="teardown-command" value="rm -rf /data/local/tmp/cts/hibernation" /> + </target_preparer> + <!-- Load additional APKs onto device --> + <target_preparer class="com.android.compatibility.common.tradefed.targetprep.FilePusher"> + <option name="push" value="CtsAutoRevokeSApp.apk->/data/local/tmp/cts/hibernation/CtsAutoRevokeSApp.apk" /> + <option name="push" value="CtsAutoRevokeRApp.apk->/data/local/tmp/cts/hibernation/CtsAutoRevokeRApp.apk" /> + <option name="push" value="CtsAutoRevokeQApp.apk->/data/local/tmp/cts/hibernation/CtsAutoRevokeQApp.apk" /> + </target_preparer> +</configuration> diff --git a/tests/tests/os/AutoRevokeQApp/Android.bp b/tests/tests/hibernation/AutoRevokeQApp/Android.bp index 5c7d4b926d4..a4a57fa5b89 100644 --- a/tests/tests/os/AutoRevokeQApp/Android.bp +++ b/tests/tests/hibernation/AutoRevokeQApp/Android.bp @@ -33,5 +33,8 @@ android_test_helper_app { "general-tests", "sts", ], - srcs: ["src/**/*.java", "src/**/*.kt"], + srcs: [ + "src/**/*.java", + "src/**/*.kt", + ], } diff --git a/tests/tests/os/AutoRevokeQApp/AndroidManifest.xml b/tests/tests/hibernation/AutoRevokeQApp/AndroidManifest.xml index c6355eb693a..c307b8476a6 100644 --- a/tests/tests/os/AutoRevokeQApp/AndroidManifest.xml +++ b/tests/tests/hibernation/AutoRevokeQApp/AndroidManifest.xml @@ -16,12 +16,12 @@ --> <manifest xmlns:android="http://schemas.android.com/apk/res/android" - package="android.os.cts.autorevokeqapp"> + package="android.hibernation.cts.autorevokeqapp"> <uses-permission android:name="android.permission.READ_CALENDAR" /> <application> - <activity android:name="android.os.cts.autorevokeqapp.MainActivity" + <activity android:name="android.hibernation.cts.autorevokeqapp.MainActivity" android:exported="true" android:visibleToInstantApps="true" > <intent-filter> diff --git a/tests/tests/os/AutoRevokeQApp/src/android/os/cts/autorevokeqapp/MainActivity.kt b/tests/tests/hibernation/AutoRevokeQApp/src/android/hibernation/cts/autorevokeqapp/MainActivity.kt index 101f2008d64..22feb544188 100644 --- a/tests/tests/os/AutoRevokeQApp/src/android/os/cts/autorevokeqapp/MainActivity.kt +++ b/tests/tests/hibernation/AutoRevokeQApp/src/android/hibernation/cts/autorevokeqapp/MainActivity.kt @@ -14,7 +14,7 @@ * limitations under the License. */ -package android.os.cts.autorevokeqapp +package android.hibernation.cts.autorevokeqapp import android.app.Activity import android.os.Bundle diff --git a/tests/tests/os/AutoRevokeRApp/Android.bp b/tests/tests/hibernation/AutoRevokeRApp/Android.bp index 8e013887a1e..f1d92ca038a 100644 --- a/tests/tests/os/AutoRevokeRApp/Android.bp +++ b/tests/tests/hibernation/AutoRevokeRApp/Android.bp @@ -32,5 +32,8 @@ android_test_helper_app { "general-tests", "sts", ], - srcs: ["src/**/*.java", "src/**/*.kt"], + srcs: [ + "src/**/*.java", + "src/**/*.kt", + ], } diff --git a/tests/tests/os/AutoRevokeRApp/AndroidManifest.xml b/tests/tests/hibernation/AutoRevokeRApp/AndroidManifest.xml index 91777a0d262..1c2cbb0ab20 100644 --- a/tests/tests/os/AutoRevokeRApp/AndroidManifest.xml +++ b/tests/tests/hibernation/AutoRevokeRApp/AndroidManifest.xml @@ -16,14 +16,14 @@ --> <manifest xmlns:android="http://schemas.android.com/apk/res/android" - package="android.os.cts.autorevokerapp"> + package="android.hibernation.cts.autorevokerapp"> <uses-permission android:name="android.permission.READ_CALENDAR" /> <uses-permission android:name="android.permission.BLUETOOTH" /> <uses-permission android:name="android.permission.QUERY_ALL_PACKAGES" /> <application> - <activity android:name="android.os.cts.autorevokerapp.MainActivity" + <activity android:name="android.hibernation.cts.autorevokerapp.MainActivity" android:exported="true" android:visibleToInstantApps="true" > <intent-filter> diff --git a/tests/tests/os/AutoRevokeRApp/src/android/os/cts/autorevokerapp/MainActivity.kt b/tests/tests/hibernation/AutoRevokeRApp/src/android/hibernation/cts/autorevokerapp/MainActivity.kt index c97f88369a7..5f3d0ae4f53 100644 --- a/tests/tests/os/AutoRevokeRApp/src/android/os/cts/autorevokerapp/MainActivity.kt +++ b/tests/tests/hibernation/AutoRevokeRApp/src/android/hibernation/cts/autorevokerapp/MainActivity.kt @@ -14,7 +14,7 @@ * limitations under the License. */ -package android.os.cts.autorevokerapp +package android.hibernation.cts.autorevokerapp import android.app.Activity import android.content.Intent diff --git a/tests/tests/os/AutoRevokeSApp/Android.bp b/tests/tests/hibernation/AutoRevokeSApp/Android.bp index 60ca80fabb2..11255920315 100644 --- a/tests/tests/os/AutoRevokeSApp/Android.bp +++ b/tests/tests/hibernation/AutoRevokeSApp/Android.bp @@ -32,5 +32,8 @@ android_test_helper_app { "general-tests", "sts", ], - srcs: ["src/**/*.java", "src/**/*.kt"], + srcs: [ + "src/**/*.java", + "src/**/*.kt", + ], } diff --git a/tests/tests/os/AutoRevokeSApp/AndroidManifest.xml b/tests/tests/hibernation/AutoRevokeSApp/AndroidManifest.xml index 08478e80bd8..b33a5461793 100644 --- a/tests/tests/os/AutoRevokeSApp/AndroidManifest.xml +++ b/tests/tests/hibernation/AutoRevokeSApp/AndroidManifest.xml @@ -16,13 +16,13 @@ --> <manifest xmlns:android="http://schemas.android.com/apk/res/android" - package="android.os.cts.autorevokesapp"> + package="android.hibernation.cts.autorevokesapp"> <uses-permission android:name="android.permission.READ_CALENDAR" /> <uses-permission android:name="android.permission.BLUETOOTH" /> <application> - <activity android:name="android.os.cts.autorevokesapp.MainActivity" + <activity android:name="android.hibernation.cts.autorevokesapp.MainActivity" android:exported="true" android:visibleToInstantApps="true" > <intent-filter> diff --git a/tests/tests/os/AutoRevokeSApp/src/android/os/cts/autorevokesapp/MainActivity.kt b/tests/tests/hibernation/AutoRevokeSApp/src/android/hibernation/cts/autorevokesapp/MainActivity.kt index c04efb23cad..e1f5842d404 100644 --- a/tests/tests/os/AutoRevokeSApp/src/android/os/cts/autorevokesapp/MainActivity.kt +++ b/tests/tests/hibernation/AutoRevokeSApp/src/android/hibernation/cts/autorevokesapp/MainActivity.kt @@ -14,7 +14,7 @@ * limitations under the License. */ -package android.os.cts.autorevokesapp +package android.hibernation.cts.autorevokesapp import android.app.Activity import android.content.Intent diff --git a/tests/tests/hibernation/OWNERS b/tests/tests/hibernation/OWNERS new file mode 100644 index 00000000000..002ca5d8681 --- /dev/null +++ b/tests/tests/hibernation/OWNERS @@ -0,0 +1,5 @@ +# Bug component: 1051079 +include platform/frameworks/base:/core/java/android/apphibernation/OWNERS +include platform/frameworks/base:/core/java/android/permission/OWNERS + +per-file *AppHibernationIntegration* = file:platform/frameworks/base:/core/java/android/apphibernation/OWNERS
\ No newline at end of file diff --git a/tests/tests/hibernation/TEST_MAPPING b/tests/tests/hibernation/TEST_MAPPING new file mode 100644 index 00000000000..742357e1051 --- /dev/null +++ b/tests/tests/hibernation/TEST_MAPPING @@ -0,0 +1,7 @@ +{ + "presubmit": [ + { + "name": "CtsHibernationTestCases" + } + ] +} diff --git a/tests/tests/os/src/android/os/cts/AppHibernationIntegrationTest.kt b/tests/tests/hibernation/src/android/hibernation/cts/AppHibernationIntegrationTest.kt index 26473eda4b7..e5b93282b47 100644 --- a/tests/tests/os/src/android/os/cts/AppHibernationIntegrationTest.kt +++ b/tests/tests/hibernation/src/android/hibernation/cts/AppHibernationIntegrationTest.kt @@ -14,7 +14,7 @@ * limitations under the License. */ -package android.os.cts +package android.hibernation.cts import android.app.ActivityManager import android.app.ActivityManager.RunningAppProcessInfo.IMPORTANCE_GONE @@ -46,11 +46,13 @@ import androidx.test.runner.AndroidJUnit4 import com.android.compatibility.common.util.DisableAnimationRule import com.android.compatibility.common.util.FreezeRotationRule import com.android.compatibility.common.util.SystemUtil +import com.android.compatibility.common.util.SystemUtil.callWithShellPermissionIdentity import com.android.compatibility.common.util.SystemUtil.eventually import com.android.compatibility.common.util.SystemUtil.runShellCommandOrThrow import com.android.compatibility.common.util.SystemUtil.runWithShellPermissionIdentity -import com.android.compatibility.common.util.SystemUtil.callWithShellPermissionIdentity import com.android.compatibility.common.util.UiAutomatorUtils +import java.util.concurrent.CountDownLatch +import java.util.concurrent.TimeUnit import org.hamcrest.CoreMatchers import org.hamcrest.Matchers import org.junit.After @@ -62,11 +64,10 @@ import org.junit.Assert.assertTrue import org.junit.Assume.assumeFalse import org.junit.Before import org.junit.BeforeClass +import org.junit.Ignore import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith -import java.util.concurrent.CountDownLatch -import java.util.concurrent.TimeUnit /** * Integration test for app hibernation. diff --git a/tests/tests/os/src/android/os/cts/AppHibernationUtils.kt b/tests/tests/hibernation/src/android/hibernation/cts/AppHibernationUtils.kt index f49e06548d6..485a4efe431 100644 --- a/tests/tests/os/src/android/os/cts/AppHibernationUtils.kt +++ b/tests/tests/hibernation/src/android/hibernation/cts/AppHibernationUtils.kt @@ -14,7 +14,7 @@ * limitations under the License. */ -package android.os.cts +package android.hibernation.cts import android.app.Activity import android.app.ActivityManager @@ -78,12 +78,12 @@ const val VIEW_WAIT_TIMEOUT = 3000L const val CMD_EXPAND_NOTIFICATIONS = "cmd statusbar expand-notifications" const val CMD_COLLAPSE = "cmd statusbar collapse" -const val APK_PATH_S_APP = "/data/local/tmp/cts/os/CtsAutoRevokeSApp.apk" -const val APK_PACKAGE_NAME_S_APP = "android.os.cts.autorevokesapp" -const val APK_PATH_R_APP = "/data/local/tmp/cts/os/CtsAutoRevokeRApp.apk" -const val APK_PACKAGE_NAME_R_APP = "android.os.cts.autorevokerapp" -const val APK_PATH_Q_APP = "/data/local/tmp/cts/os/CtsAutoRevokeQApp.apk" -const val APK_PACKAGE_NAME_Q_APP = "android.os.cts.autorevokeqapp" +const val APK_PATH_S_APP = "/data/local/tmp/cts/hibernation/CtsAutoRevokeSApp.apk" +const val APK_PACKAGE_NAME_S_APP = "android.hibernation.cts.autorevokesapp" +const val APK_PATH_R_APP = "/data/local/tmp/cts/hibernation/CtsAutoRevokeRApp.apk" +const val APK_PACKAGE_NAME_R_APP = "android.hibernation.cts.autorevokerapp" +const val APK_PATH_Q_APP = "/data/local/tmp/cts/hibernation/CtsAutoRevokeQApp.apk" +const val APK_PACKAGE_NAME_Q_APP = "android.hibernation.cts.autorevokeqapp" fun runBootCompleteReceiver(context: Context, testTag: String) { val pkgManager = context.packageManager diff --git a/tests/tests/os/src/android/os/cts/AutoRevokeTest.kt b/tests/tests/hibernation/src/android/hibernation/cts/AutoRevokeTest.kt index fdfda50bda9..543c0cb94f0 100644 --- a/tests/tests/os/src/android/os/cts/AutoRevokeTest.kt +++ b/tests/tests/hibernation/src/android/hibernation/cts/AutoRevokeTest.kt @@ -14,7 +14,7 @@ * limitations under the License. */ -package android.os.cts +package android.hibernation.cts import android.app.ActivityManager.RunningAppProcessInfo.IMPORTANCE_TOP_SLEEPING import android.app.Instrumentation diff --git a/tests/tests/os/Android.bp b/tests/tests/os/Android.bp index c50c6a70dd7..7645ce7747b 100644 --- a/tests/tests/os/Android.bp +++ b/tests/tests/os/Android.bp @@ -18,10 +18,7 @@ package { android_test { name: "CtsOsTestCases", - defaults: [ - "cts_defaults", - "mts-target-sdk-version-current", - ], + defaults: ["cts_defaults"], compile_multilib: "both", static_libs: [ "android.hidl.manager-V1.0-java", @@ -40,7 +37,6 @@ android_test { "hamcrest-library", "modules-utils-build_system", "platformprotosnano", - "safety-center-internal-data", ], jni_uses_platform_apis: true, jni_libs: [ @@ -64,7 +60,6 @@ android_test { test_suites: [ "cts", "general-tests", - "mts-permission", "sts", ], sdk_version: "test_current", @@ -76,9 +71,6 @@ android_test { aaptflags: ["-0 .policy"], min_sdk_version: "29", data: [ - ":CtsAutoRevokeQApp", - ":CtsAutoRevokeSApp", - ":CtsAutoRevokeRApp", ":CtsCompanionTestApp", ], per_testcase_directory: true, diff --git a/tests/tests/os/CtsOsTestCases.xml b/tests/tests/os/CtsOsTestCases.xml index 631b627f693..e0a13b1a31a 100644 --- a/tests/tests/os/CtsOsTestCases.xml +++ b/tests/tests/os/CtsOsTestCases.xml @@ -48,9 +48,6 @@ </target_preparer> <!-- Load additional APKs onto device --> <target_preparer class="com.android.compatibility.common.tradefed.targetprep.FilePusher"> - <option name="push" value="CtsAutoRevokeSApp.apk->/data/local/tmp/cts/os/CtsAutoRevokeSApp.apk" /> - <option name="push" value="CtsAutoRevokeRApp.apk->/data/local/tmp/cts/os/CtsAutoRevokeRApp.apk" /> - <option name="push" value="CtsAutoRevokeQApp.apk->/data/local/tmp/cts/os/CtsAutoRevokeQApp.apk" /> <option name="push" value="CtsCompanionTestApp.apk->/data/local/tmp/cts/os/CtsCompanionTestApp.apk" /> </target_preparer> </configuration> diff --git a/tests/tests/os/OWNERS b/tests/tests/os/OWNERS index 5c286aace47..8ab70d2ac5e 100644 --- a/tests/tests/os/OWNERS +++ b/tests/tests/os/OWNERS @@ -1,5 +1,3 @@ -per-file *AutoRevoke* = file:platform/frameworks/base:/core/java/android/permission/OWNERS -per-file *AppHibernation* = file:platform/frameworks/base:/core/java/android/permission/OWNERS per-file *Companion* = file:platform/frameworks/base:/core/java/android/permission/OWNERS per-file *Vibrat* = file:platform/frameworks/base:/services/core/java/com/android/server/vibrator/OWNERS per-file *AndroidManifest.xml = file:platform/frameworks/base:/core/java/android/permission/OWNERS diff --git a/tests/tests/os/src/android/os/cts/CompanionDeviceManagerTest.kt b/tests/tests/os/src/android/os/cts/CompanionDeviceManagerTest.kt index b398affc3df..bcdecdb2845 100644 --- a/tests/tests/os/src/android/os/cts/CompanionDeviceManagerTest.kt +++ b/tests/tests/os/src/android/os/cts/CompanionDeviceManagerTest.kt @@ -16,8 +16,12 @@ package android.os.cts +import android.app.ActivityManager +import android.app.ActivityManager.RunningAppProcessInfo.IMPORTANCE_TOP_SLEEPING import android.app.Instrumentation +import android.app.UiAutomation import android.companion.CompanionDeviceManager +import android.content.Context import android.content.pm.PackageManager import android.content.pm.PackageManager.FEATURE_AUTOMOTIVE import android.content.pm.PackageManager.FEATURE_COMPANION_DEVICE_SETUP @@ -31,22 +35,30 @@ import android.platform.test.annotations.AppModeFull import android.util.Size import android.util.SizeF import android.util.SparseArray +import android.view.accessibility.AccessibilityNodeInfo import androidx.test.InstrumentationRegistry import androidx.test.runner.AndroidJUnit4 -import androidx.test.uiautomator.By -import androidx.test.uiautomator.BySelector -import androidx.test.uiautomator.UiDevice -import androidx.test.uiautomator.UiObject2 -import androidx.test.uiautomator.Until +import android.support.test.uiautomator.By +import android.support.test.uiautomator.BySelector +import android.support.test.uiautomator.UiDevice +import android.support.test.uiautomator.UiObject2 +import android.support.test.uiautomator.Until import com.android.compatibility.common.util.MatcherUtils.hasIdThat +import com.android.compatibility.common.util.SystemUtil import com.android.compatibility.common.util.SystemUtil.getEventually import com.android.compatibility.common.util.SystemUtil.runShellCommand import com.android.compatibility.common.util.SystemUtil.runShellCommandOrThrow import com.android.compatibility.common.util.SystemUtil.runWithShellPermissionIdentity import com.android.compatibility.common.util.ThrowingSupplier -import com.android.compatibility.common.util.UiAutomatorUtils.waitFindObject +import com.android.compatibility.common.util.UI_ROOT +import com.android.compatibility.common.util.UiAutomatorUtils import com.android.compatibility.common.util.click +import com.android.compatibility.common.util.depthFirstSearch +import com.android.compatibility.common.util.textAsString +import com.android.compatibility.common.util.uiDump import org.hamcrest.CoreMatchers.containsString +import org.hamcrest.Matcher +import org.hamcrest.Matchers import org.junit.After import org.junit.Assert.assertFalse import org.junit.Assert.assertThat @@ -58,6 +70,8 @@ import org.junit.Ignore import org.junit.Test import org.junit.runner.RunWith import java.io.Serializable +import java.util.concurrent.atomic.AtomicReference +import java.util.regex.Pattern /** * Test for [CompanionDeviceManager] @@ -226,14 +240,112 @@ class CompanionDeviceManagerTest { MacAddress.fromString(macAddress), context.user) }, *permissions) } -} -private fun UiDevice.waitAndFind(selector: BySelector): UiObject2 = - wait(Until.findObject(selector), 1000) + private fun UiDevice.waitAndFind(selector: BySelector): UiObject2 = + wait(Until.findObject(selector), 1000) -private fun click(label: String) { - waitFindObject(byTextIgnoreCase(label)).click() - waitForIdle() + private fun click(label: String) { + waitFindObject(byTextIgnoreCase(label)).click() + waitForIdle() + } + + private fun uninstallAppWithoutAssertion(packageName: String) { + runShellCommandOrThrow("pm uninstall $packageName") + } + + private fun installApk(apk: String) { + assertThat(runShellCommandOrThrow("pm install -r $apk"), containsString("Success")) + } + + /** + * For some reason waitFindObject sometimes fails to find UI that is present in the view hierarchy + */ + private fun waitFindNode( + matcher: Matcher<AccessibilityNodeInfo>, + failMsg: String? = null, + timeoutMs: Long = 10_000 + ): AccessibilityNodeInfo { + return getEventually({ + val ui = UI_ROOT + ui.depthFirstSearch { node -> + matcher.matches(node) + }.assertNotNull { + buildString { + if (failMsg != null) { + appendLine(failMsg) + } + appendLine("No view found matching $matcher:\n\n${uiDump(ui)}") + } + } + }, timeoutMs) + } + + private fun waitFindObject(selector: BySelector): UiObject2 { + return waitFindObject(instrumentation.uiAutomation, selector) + } + + private fun waitFindObject(uiAutomation: UiAutomation, selector: BySelector): UiObject2 { + try { + return UiAutomatorUtils.waitFindObject(selector) + } catch (e: RuntimeException) { + val ui = uiAutomation.rootInActiveWindow + + val title = ui.depthFirstSearch { node -> + node.viewIdResourceName?.contains("alertTitle") == true + } + val okButton = ui.depthFirstSearch { node -> + node.textAsString?.equals("OK", ignoreCase = true) ?: false + } + + if (title?.text?.toString() == "Android System" && okButton != null) { + // Auto dismiss occasional system dialogs to prevent interfering with the test + okButton.click() + return UiAutomatorUtils.waitFindObject(selector) + } else { + throw e + } + } + } + + private fun byTextIgnoreCase(txt: String): BySelector { + return By.text(Pattern.compile(txt, Pattern.CASE_INSENSITIVE)) + } + + private fun waitForIdle() { + InstrumentationRegistry.getInstrumentation().uiAutomation.waitForIdle(1000, 10000) + } + + private inline fun <T> eventually(crossinline action: () -> T): T { + val res = AtomicReference<T>() + SystemUtil.eventually { + res.set(action()) + } + return res.get() + } + + private fun awaitAppState(pkg: String, stateMatcher: Matcher<Int>) { + val context: Context = InstrumentationRegistry.getTargetContext() + eventually { + runWithShellPermissionIdentity { + val packageImportance = context + .getSystemService(ActivityManager::class.java)!! + .getPackageImportance(pkg) + assertThat(packageImportance, stateMatcher) + } + } + } + + private fun startApp(packageName: String) { + val context = InstrumentationRegistry.getTargetContext() + val intent = context.packageManager.getLaunchIntentForPackage(packageName) + context.startActivity(intent) + awaitAppState(packageName, Matchers.lessThanOrEqualTo(IMPORTANCE_TOP_SLEEPING)) + waitForIdle() + } + + private inline fun <T> T?.assertNotNull(errorMsg: () -> String): T { + return if (this == null) throw AssertionError(errorMsg()) else this + } } operator fun Bundle.set(key: String, value: Any?) { diff --git a/tests/tests/security/src/android/security/cts/SplitPermissionAutoGrantTest.kt b/tests/tests/security/src/android/security/cts/SplitPermissionAutoGrantTest.kt index 28d004f53cd..3b20d458354 100644 --- a/tests/tests/security/src/android/security/cts/SplitPermissionAutoGrantTest.kt +++ b/tests/tests/security/src/android/security/cts/SplitPermissionAutoGrantTest.kt @@ -18,7 +18,10 @@ package android.security.cts import android.platform.test.annotations.AsbSecurityTest import androidx.test.ext.junit.runners.AndroidJUnit4 +import com.android.compatibility.common.util.mainline.MainlineModule +import com.android.compatibility.common.util.mainline.ModuleDetector import org.junit.After +import org.junit.Assume.assumeFalse import org.junit.Before import org.junit.Test import org.junit.runner.RunWith @@ -35,6 +38,8 @@ class SplitPermissionAutoGrantTest : BasePermissionUiTest() { @Test @AsbSecurityTest(cveBugId = [223907044]) fun testAutoGrant() { + assumeFalse(ModuleDetector.moduleIsPlayManaged( + mContext.getPackageManager(), MainlineModule.PERMISSION_CONTROLLER)) installPackage(SPLIT_PERMISSION_APK_PATH) assertAppHasPermission(android.Manifest.permission.BLUETOOTH, true) assertAppHasPermission(android.Manifest.permission.BLUETOOTH_CONNECT, true) |