diff options
Diffstat (limited to 'tests')
15 files changed, 222 insertions, 95 deletions
diff --git a/tests/cts/permissionpolicy/res/raw/android_manifest.xml b/tests/cts/permissionpolicy/res/raw/android_manifest.xml index cd80fe78e..ceefe3dfd 100644 --- a/tests/cts/permissionpolicy/res/raw/android_manifest.xml +++ b/tests/cts/permissionpolicy/res/raw/android_manifest.xml @@ -7759,7 +7759,17 @@ @FlaggedApi("com.android.server.telecom.flags.telecom_resolve_hidden_dependencies") @hide --> <permission android:name="android.permission.READ_BLOCKED_NUMBERS" - android:protectionLevel="signature" /> + android:protectionLevel="signature" + android:featureFlag="!android.permission.flags.grant_read_blocked_numbers_to_system_ui_intelligence" /> + + <!-- Allows the holder to read blocked numbers. See + {@link android.provider.BlockedNumberContract}. + @SystemApi + @FlaggedApi("com.android.server.telecom.flags.telecom_resolve_hidden_dependencies") + @hide --> + <permission android:name="android.permission.READ_BLOCKED_NUMBERS" + android:protectionLevel="signature|role" + android:featureFlag="android.permission.flags.grant_read_blocked_numbers_to_system_ui_intelligence" /> <!-- Allows the holder to write blocked numbers. See {@link android.provider.BlockedNumberContract}. diff --git a/tests/cts/permissionui/src/android/permissionui/cts/BaseUsePermissionTest.kt b/tests/cts/permissionui/src/android/permissionui/cts/BaseUsePermissionTest.kt index ccc5a0a5e..f52e32344 100644 --- a/tests/cts/permissionui/src/android/permissionui/cts/BaseUsePermissionTest.kt +++ b/tests/cts/permissionui/src/android/permissionui/cts/BaseUsePermissionTest.kt @@ -38,6 +38,7 @@ import android.provider.DeviceConfig import android.provider.Settings import android.text.Spanned import android.text.style.ClickableSpan +import android.util.Log import android.view.View import android.view.accessibility.AccessibilityNodeInfo import androidx.test.uiautomator.By @@ -51,6 +52,7 @@ 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.runWithShellPermissionIdentity +import com.android.compatibility.common.util.UiDumpUtils import com.android.modules.utils.build.SdkLevel import java.util.concurrent.CompletableFuture import java.util.concurrent.TimeUnit @@ -64,6 +66,7 @@ import org.junit.Before abstract class BaseUsePermissionTest : BasePermissionTest() { companion object { + const val LOG_TAG = "BaseUsePermissionTest" const val APP_APK_NAME_31 = "CtsUsePermissionApp31.apk" const val APP_APK_NAME_31_WITH_ASL = "CtsUsePermissionApp31WithAsl.apk" const val APP_APK_NAME_LATEST = "CtsUsePermissionAppLatest.apk" @@ -791,6 +794,9 @@ abstract class BaseUsePermissionTest : BasePermissionTest() { ) if (timeoutOccurred) { + val uiDump = StringBuilder() + UiDumpUtils.dumpNodes(uiDump) + Log.w(LOG_TAG, "Timed out waiting for window transition, UI dump: $uiDump") throw RuntimeException("Timed out waiting for window transition.") } } diff --git a/tests/cts/permissionui/src/android/permissionui/cts/LocationAccuracyTest.kt b/tests/cts/permissionui/src/android/permissionui/cts/LocationAccuracyTest.kt index be4b82932..4781fb895 100644 --- a/tests/cts/permissionui/src/android/permissionui/cts/LocationAccuracyTest.kt +++ b/tests/cts/permissionui/src/android/permissionui/cts/LocationAccuracyTest.kt @@ -72,6 +72,8 @@ class LocationAccuracyTest : BaseUsePermissionTest() { } @Test + @Ignore("b/396478581") + // Ignore this test until the cause of flakiness is identified. fun testPrecisePermissionIsGranted() { installPackage(APP_APK_PATH_31) diff --git a/tests/cts/permissionui/src/android/permissionui/cts/PermissionDecisionsTest.kt b/tests/cts/permissionui/src/android/permissionui/cts/PermissionDecisionsTest.kt index ae6e33b2a..e4ee52186 100644 --- a/tests/cts/permissionui/src/android/permissionui/cts/PermissionDecisionsTest.kt +++ b/tests/cts/permissionui/src/android/permissionui/cts/PermissionDecisionsTest.kt @@ -53,7 +53,8 @@ class PermissionDecisionsTest : BaseUsePermissionTest() { openPermissionDecisions() waitFindObject( By.hasChild( - By.text("You gave $APP_PACKAGE_NAME access to location").displayId(displayId)) + By.text("You gave $APP_PACKAGE_NAME access to location").displayId(displayId) + ) .hasChild(By.text("Today").displayId(displayId)) .displayId(displayId) ) @@ -69,7 +70,8 @@ class PermissionDecisionsTest : BaseUsePermissionTest() { openPermissionDecisions() waitFindObject( By.hasChild( - By.text("You denied $APP_PACKAGE_NAME access to location").displayId(displayId)) + By.text("You denied $APP_PACKAGE_NAME access to location").displayId(displayId) + ) .hasChild(By.text("Today").displayId(displayId)) .displayId(displayId) ) @@ -86,11 +88,13 @@ class PermissionDecisionsTest : BaseUsePermissionTest() { openPermissionDecisions() assertNull( waitFindObjectOrNull( - By.hasChild(By.text("You denied $APP_PACKAGE_NAME access to location") - .displayId(displayId)) + By.hasChild( + By.text("You denied $APP_PACKAGE_NAME access to location") + .displayId(displayId) + ) .hasChild(By.text("Today").displayId(displayId)) .displayId(displayId), - ASSERT_ABSENT_SELECTOR_TIMEOUT_MS + ASSERT_ABSENT_SELECTOR_TIMEOUT_MS, ) ) } @@ -105,8 +109,10 @@ class PermissionDecisionsTest : BaseUsePermissionTest() { openPermissionDecisions() waitFindObject( - By.hasChild(By.text("You gave $APP_PACKAGE_NAME access to location") - .displayId(displayId)) + By.hasChild( + By.text("You gave $APP_PACKAGE_NAME access to location") + .displayId(displayId) + ) .hasChild(By.text("Today").displayId(displayId)) .displayId(displayId) ) @@ -121,7 +127,8 @@ class PermissionDecisionsTest : BaseUsePermissionTest() { pressBack() waitFindObject( By.hasChild( - By.text("You denied $APP_PACKAGE_NAME access to location").displayId(displayId)) + By.text("You denied $APP_PACKAGE_NAME access to location").displayId(displayId) + ) .hasChild(By.text("Today").displayId(displayId)) .displayId(displayId) ) @@ -132,7 +139,7 @@ class PermissionDecisionsTest : BaseUsePermissionTest() { SystemUtil.runWithShellPermissionIdentity { context.startActivity( Intent(PermissionManager.ACTION_REVIEW_PERMISSION_DECISIONS).apply { - addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) + addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK) } ) } diff --git a/tests/cts/permissionui/src/android/permissionui/cts/PermissionRationalePermissionGrantDialogTest.kt b/tests/cts/permissionui/src/android/permissionui/cts/PermissionRationalePermissionGrantDialogTest.kt index 751c56b3c..9a12765c0 100644 --- a/tests/cts/permissionui/src/android/permissionui/cts/PermissionRationalePermissionGrantDialogTest.kt +++ b/tests/cts/permissionui/src/android/permissionui/cts/PermissionRationalePermissionGrantDialogTest.kt @@ -41,8 +41,7 @@ import org.junit.Test @FlakyTest class PermissionRationalePermissionGrantDialogTest : BaseUsePermissionTest() { - @get:Rule - val checkFlagsRule = DeviceFlagsValueProvider.createCheckFlagsRule() + @get:Rule val checkFlagsRule = DeviceFlagsValueProvider.createCheckFlagsRule() @get:Rule val deviceConfigPermissionRationaleEnabled = @@ -50,7 +49,7 @@ class PermissionRationalePermissionGrantDialogTest : BaseUsePermissionTest() { context, DeviceConfig.NAMESPACE_PRIVACY, PERMISSION_RATIONALE_ENABLED, - true.toString() + true.toString(), ) @Before @@ -248,8 +247,10 @@ class PermissionRationalePermissionGrantDialogTest : BaseUsePermissionTest() { } } - @SdkSuppress(minSdkVersion = Build.VERSION_CODES.VANILLA_ICE_CREAM, codeName = - "VanillaIceCream") + @SdkSuppress( + minSdkVersion = Build.VERSION_CODES.VANILLA_ICE_CREAM, + codeName = "VanillaIceCream", + ) @RequiresFlagsEnabled(android.content.pm.Flags.FLAG_ASL_IN_APK_APP_METADATA_SOURCE) @Test fun requestCoarseLocationPerm_hasAslInApk_packageSourceUnspecified() { @@ -262,8 +263,10 @@ class PermissionRationalePermissionGrantDialogTest : BaseUsePermissionTest() { } } - @SdkSuppress(minSdkVersion = Build.VERSION_CODES.VANILLA_ICE_CREAM, codeName = - "VanillaIceCream") + @SdkSuppress( + minSdkVersion = Build.VERSION_CODES.VANILLA_ICE_CREAM, + codeName = "VanillaIceCream", + ) @RequiresFlagsEnabled(android.content.pm.Flags.FLAG_ASL_IN_APK_APP_METADATA_SOURCE) @Test fun requestCoarseLocationPerm_hasAslInApk_packageSourceStore() { @@ -276,8 +279,10 @@ class PermissionRationalePermissionGrantDialogTest : BaseUsePermissionTest() { } } - @SdkSuppress(minSdkVersion = Build.VERSION_CODES.VANILLA_ICE_CREAM, codeName = - "VanillaIceCream") + @SdkSuppress( + minSdkVersion = Build.VERSION_CODES.VANILLA_ICE_CREAM, + codeName = "VanillaIceCream", + ) @RequiresFlagsEnabled(android.content.pm.Flags.FLAG_ASL_IN_APK_APP_METADATA_SOURCE) @Test fun requestCoarseLocationPerm_hasAslInApk_packageSourceLocalFile() { @@ -290,8 +295,10 @@ class PermissionRationalePermissionGrantDialogTest : BaseUsePermissionTest() { } } - @SdkSuppress(minSdkVersion = Build.VERSION_CODES.VANILLA_ICE_CREAM, codeName = - "VanillaIceCream") + @SdkSuppress( + minSdkVersion = Build.VERSION_CODES.VANILLA_ICE_CREAM, + codeName = "VanillaIceCream", + ) @RequiresFlagsEnabled(android.content.pm.Flags.FLAG_ASL_IN_APK_APP_METADATA_SOURCE) @Test fun requestCoarseLocationPerm_hasAslInApk_packageSourceDownloadedFile() { @@ -304,8 +311,10 @@ class PermissionRationalePermissionGrantDialogTest : BaseUsePermissionTest() { } } - @SdkSuppress(minSdkVersion = Build.VERSION_CODES.VANILLA_ICE_CREAM, codeName = - "VanillaIceCream") + @SdkSuppress( + minSdkVersion = Build.VERSION_CODES.VANILLA_ICE_CREAM, + codeName = "VanillaIceCream", + ) @RequiresFlagsEnabled(android.content.pm.Flags.FLAG_ASL_IN_APK_APP_METADATA_SOURCE) @Test fun requestCoarseLocationPerm_hasAslInApk_packageSourceOther() { @@ -338,7 +347,6 @@ class PermissionRationalePermissionGrantDialogTest : BaseUsePermissionTest() { requestAppPermissionsForNoResult(ACCESS_FINE_LOCATION) { clickPermissionRationaleViewInGrantDialog() assertPermissionRationaleDialogIsVisible(true) - assertPermissionRationaleContainerOnGrantDialogIsVisible(false) } } diff --git a/tests/cts/rolemultiuser/src/android/app/rolemultiuser/cts/RoleManagerMultiUserTest.kt b/tests/cts/rolemultiuser/src/android/app/rolemultiuser/cts/RoleManagerMultiUserTest.kt index 98aa5fbf1..dc2ba42c6 100644 --- a/tests/cts/rolemultiuser/src/android/app/rolemultiuser/cts/RoleManagerMultiUserTest.kt +++ b/tests/cts/rolemultiuser/src/android/app/rolemultiuser/cts/RoleManagerMultiUserTest.kt @@ -27,10 +27,12 @@ import android.os.Process import android.os.UserHandle import android.os.UserManager.DISALLOW_CONFIG_DEFAULT_APPS import android.provider.Settings +import android.util.Log import android.util.Pair import androidx.test.filters.SdkSuppress import androidx.test.rule.ActivityTestRule import androidx.test.uiautomator.By +import com.android.bedstead.enterprise.annotations.EnsureDoesNotHaveUserRestriction import com.android.bedstead.enterprise.annotations.EnsureHasNoWorkProfile import com.android.bedstead.enterprise.annotations.EnsureHasUserRestriction import com.android.bedstead.enterprise.annotations.EnsureHasWorkProfile @@ -53,6 +55,7 @@ import com.android.bedstead.nene.TestApis.context import com.android.bedstead.nene.TestApis.permissions import com.android.bedstead.nene.TestApis.users import com.android.bedstead.nene.types.OptionalBoolean +import com.android.bedstead.nene.userrestrictions.CommonUserRestrictions.DISALLOW_ADD_MANAGED_PROFILE import com.android.bedstead.nene.users.UserReference import com.android.bedstead.nene.users.UserType import com.android.bedstead.permissions.CommonPermissions.INTERACT_ACROSS_USERS_FULL @@ -69,7 +72,6 @@ import com.android.compatibility.common.util.UiAutomatorUtils2.waitFindObject import com.android.compatibility.common.util.UiAutomatorUtils2.waitFindObjectOrNull import com.google.common.truth.Truth.assertThat import com.google.common.truth.Truth.assertWithMessage -import java.util.Objects import java.util.concurrent.CompletableFuture import java.util.concurrent.TimeUnit import java.util.function.Consumer @@ -94,16 +96,24 @@ class RoleManagerMultiUserTest { ActivityTestRule(WaitForResultActivity::class.java) @Before - @Throws(java.lang.Exception::class) fun setUp() { assumeTrue(RoleManagerUtil.isCddCompliantScreenSize()) installAppForAllUsers() + + // If "none" selected in test, ensure we re-enable fallback for other test runs + permissions().withPermission(MANAGE_ROLE_HOLDERS, INTERACT_ACROSS_USERS_FULL).use { + setRoleFallbackEnabledForAllUsers() + } } @After - @Throws(java.lang.Exception::class) fun tearDown() { uninstallAppForAllUsers() + + // If "none" selected in test, ensure we re-enable fallback for other test runs + permissions().withPermission(MANAGE_ROLE_HOLDERS, INTERACT_ACROSS_USERS_FULL).use { + setRoleFallbackEnabledForAllUsers() + } } @RequireFlagsEnabled(com.android.permission.flags.Flags.FLAG_CROSS_USER_ROLE_ENABLED) @@ -315,7 +325,7 @@ class RoleManagerMultiUserTest { // initialUser needs to be not the targetUser val targetActiveUser = users().current().userHandle() val initialUser = - if (Objects.equals(targetActiveUser, deviceState.initialUser().userHandle())) { + if (targetActiveUser == deviceState.initialUser().userHandle()) { deviceState.workProfile().userHandle() } else { deviceState.initialUser().userHandle() @@ -378,7 +388,7 @@ class RoleManagerMultiUserTest { val initialUser = deviceState.workProfile().userHandle() // setActiveUserForRole and getActiveUserForRole is used to ensure initial active users // state and requires INTERACT_ACROSS_USERS_FULL - permissions().withPermission(INTERACT_ACROSS_USERS_FULL).use { _ -> + permissions().withPermission(INTERACT_ACROSS_USERS_FULL).use { roleManager.setActiveUserForRole(PROFILE_GROUP_EXCLUSIVITY_ROLE_NAME, initialUser, 0) assertThat(roleManager.getActiveUserForRole(PROFILE_GROUP_EXCLUSIVITY_ROLE_NAME)) .isEqualTo(initialUser) @@ -406,7 +416,7 @@ class RoleManagerMultiUserTest { // getActiveUserForRole is used to ensure addRoleHolderAsUser didn't set active user, and // requires INTERACT_ACROSS_USERS_FULL - permissions().withPermission(INTERACT_ACROSS_USERS_FULL).use { _ -> + permissions().withPermission(INTERACT_ACROSS_USERS_FULL).use { assertThat(roleManager.getActiveUserForRole(PROFILE_GROUP_EXCLUSIVITY_ROLE_NAME)) .isEqualTo(initialUser) } @@ -483,7 +493,7 @@ class RoleManagerMultiUserTest { val initialUser = deviceState.workProfile().userHandle() // setActiveUserForRole and getActiveUserForRole is used to ensure initial active users // state and requires INTERACT_ACROSS_USERS_FULL - permissions().withPermission(INTERACT_ACROSS_USERS_FULL).use { _ -> + permissions().withPermission(INTERACT_ACROSS_USERS_FULL).use { roleManager.setActiveUserForRole(PROFILE_GROUP_EXCLUSIVITY_ROLE_NAME, initialUser, 0) assertThat(roleManager.getActiveUserForRole(PROFILE_GROUP_EXCLUSIVITY_ROLE_NAME)) .isEqualTo(initialUser) @@ -503,7 +513,7 @@ class RoleManagerMultiUserTest { // getActiveUserForRole is used to ensure setDefaultApplication didn't set active user, // and requires INTERACT_ACROSS_USERS_FULL - permissions().withPermission(INTERACT_ACROSS_USERS_FULL).use { _ -> + permissions().withPermission(INTERACT_ACROSS_USERS_FULL).use { assertThat(roleManager.getActiveUserForRole(PROFILE_GROUP_EXCLUSIVITY_ROLE_NAME)) .isEqualTo(initialUser) } @@ -570,6 +580,7 @@ class RoleManagerMultiUserTest { @EnsureCanAddUser @EnsureHasNoWorkProfile @RequireRunOnPrimaryUser + @EnsureDoesNotHaveUserRestriction(DISALLOW_ADD_MANAGED_PROFILE) @Test @Throws(Exception::class) fun ensureActiveUserSetToParentOnUserRemoved() { @@ -1279,7 +1290,7 @@ class RoleManagerMultiUserTest { // setDefaultHoldersForTestForAllUsers and setRoleVisibleForTestForAllUsers require // INTERACT_ACROSS_USERS_FULL and MANAGE_ROLE_HOLDERS permissions to validate cross user // role active user and role holder states - permissions().withPermission(INTERACT_ACROSS_USERS_FULL, MANAGE_ROLE_HOLDERS).use { _ -> + permissions().withPermission(INTERACT_ACROSS_USERS_FULL, MANAGE_ROLE_HOLDERS).use { // Set test default role holder. Ensures fallbacks to a default holder setDefaultHoldersForTestForAllUsers() setRoleVisibleForTestForAllUsers() @@ -1306,7 +1317,7 @@ class RoleManagerMultiUserTest { // getActiveUserForRole and getRoleHoldersAsUser require INTERACT_ACROSS_USERS_FULL and // MANAGE_ROLE_HOLDERS permissions to validate cross user role active user and role // holder states - permissions().withPermission(INTERACT_ACROSS_USERS_FULL, MANAGE_ROLE_HOLDERS).use { _ -> + permissions().withPermission(INTERACT_ACROSS_USERS_FULL, MANAGE_ROLE_HOLDERS).use { assertThat(roleManager.getActiveUserForRole(PROFILE_GROUP_EXCLUSIVITY_ROLE_NAME)) .isEqualTo(targetActiveUser) assertExpectedProfileHasRoleUsingGetRoleHoldersAsUser(targetActiveUser) @@ -1315,7 +1326,7 @@ class RoleManagerMultiUserTest { // clearDefaultHoldersForTestForAllUsers and clearRoleVisibleForTestForAllUsers require // INTERACT_ACROSS_USERS_FULL and MANAGE_ROLE_HOLDERS permissions to validate cross user // role active user and role holder states - permissions().withPermission(INTERACT_ACROSS_USERS_FULL, MANAGE_ROLE_HOLDERS).use { _ -> + permissions().withPermission(INTERACT_ACROSS_USERS_FULL, MANAGE_ROLE_HOLDERS).use { clearDefaultHoldersForTestForAllUsers() clearRoleVisibleForTestForAllUsers() } @@ -1332,7 +1343,7 @@ class RoleManagerMultiUserTest { // setDefaultHoldersForTestForAllUsers and setRoleVisibleForTestForAllUsers require // INTERACT_ACROSS_USERS_FULL and MANAGE_ROLE_HOLDERS permissions to validate cross user // role active user and role holder states - permissions().withPermission(INTERACT_ACROSS_USERS_FULL, MANAGE_ROLE_HOLDERS).use { _ -> + permissions().withPermission(INTERACT_ACROSS_USERS_FULL, MANAGE_ROLE_HOLDERS).use { // Set test default role holder. Ensures fallbacks to a default holder setDefaultHoldersForTestForAllUsers() setRoleVisibleForTestForAllUsers() @@ -1359,7 +1370,7 @@ class RoleManagerMultiUserTest { // getActiveUserForRole and getRoleHoldersAsUser require INTERACT_ACROSS_USERS_FULL and // MANAGE_ROLE_HOLDERS permissions to validate cross user role active user and role // holder states - permissions().withPermission(INTERACT_ACROSS_USERS_FULL, MANAGE_ROLE_HOLDERS).use { _ -> + permissions().withPermission(INTERACT_ACROSS_USERS_FULL, MANAGE_ROLE_HOLDERS).use { assertThat(roleManager.getActiveUserForRole(PROFILE_GROUP_EXCLUSIVITY_ROLE_NAME)) .isEqualTo(targetActiveUser) assertExpectedProfileHasRoleUsingGetRoleHoldersAsUser(targetActiveUser) @@ -1368,7 +1379,7 @@ class RoleManagerMultiUserTest { // clearDefaultHoldersForTestForAllUsers and clearRoleVisibleForTestForAllUsers require // INTERACT_ACROSS_USERS_FULL and MANAGE_ROLE_HOLDERS permissions to validate cross user // role active user and role holder states - permissions().withPermission(INTERACT_ACROSS_USERS_FULL, MANAGE_ROLE_HOLDERS).use { _ -> + permissions().withPermission(INTERACT_ACROSS_USERS_FULL, MANAGE_ROLE_HOLDERS).use { clearDefaultHoldersForTestForAllUsers() clearRoleVisibleForTestForAllUsers() } @@ -1385,7 +1396,7 @@ class RoleManagerMultiUserTest { // setDefaultHoldersForTestForAllUsers and setRoleVisibleForTestForAllUsers require // INTERACT_ACROSS_USERS_FULL and MANAGE_ROLE_HOLDERS permissions to validate cross user // role active user and role holder states - permissions().withPermission(INTERACT_ACROSS_USERS_FULL, MANAGE_ROLE_HOLDERS).use { _ -> + permissions().withPermission(INTERACT_ACROSS_USERS_FULL, MANAGE_ROLE_HOLDERS).use { // Set test default role holder. Ensures fallbacks to a default holder setDefaultHoldersForTestForAllUsers() setRoleVisibleForTestForAllUsers() @@ -1410,7 +1421,7 @@ class RoleManagerMultiUserTest { // getActiveUserForRole and getRoleHoldersAsUser require INTERACT_ACROSS_USERS_FULL and // MANAGE_ROLE_HOLDERS permissions to validate cross user role active user and role // holder states - permissions().withPermission(INTERACT_ACROSS_USERS_FULL, MANAGE_ROLE_HOLDERS).use { _ -> + permissions().withPermission(INTERACT_ACROSS_USERS_FULL, MANAGE_ROLE_HOLDERS).use { assertThat(roleManager.getActiveUserForRole(PROFILE_GROUP_EXCLUSIVITY_ROLE_NAME)) .isEqualTo(deviceState.initialUser().userHandle()) assertNoRoleHoldersUsingGetRoleHoldersAsUser() @@ -1419,7 +1430,7 @@ class RoleManagerMultiUserTest { // clearDefaultHoldersForTestForAllUsers and clearRoleVisibleForTestForAllUsers require // INTERACT_ACROSS_USERS_FULL and MANAGE_ROLE_HOLDERS permissions to validate cross user // role active user and role holder states - permissions().withPermission(INTERACT_ACROSS_USERS_FULL, MANAGE_ROLE_HOLDERS).use { _ -> + permissions().withPermission(INTERACT_ACROSS_USERS_FULL, MANAGE_ROLE_HOLDERS).use { clearDefaultHoldersForTestForAllUsers() clearRoleVisibleForTestForAllUsers() } @@ -1436,7 +1447,7 @@ class RoleManagerMultiUserTest { // setDefaultHoldersForTestForAllUsers and setRoleVisibleForTestForAllUsers require // INTERACT_ACROSS_USERS_FULL and MANAGE_ROLE_HOLDERS permissions to validate cross user // role active user and role holder states - permissions().withPermission(INTERACT_ACROSS_USERS_FULL, MANAGE_ROLE_HOLDERS).use { _ -> + permissions().withPermission(INTERACT_ACROSS_USERS_FULL, MANAGE_ROLE_HOLDERS).use { // Set test default role holder. Ensures fallbacks to a default holder setDefaultHoldersForTestForAllUsers() setRoleVisibleForTestForAllUsers() @@ -1463,7 +1474,7 @@ class RoleManagerMultiUserTest { // getActiveUserForRole and getRoleHoldersAsUser require INTERACT_ACROSS_USERS_FULL and // MANAGE_ROLE_HOLDERS permissions to validate cross user role active user and role // holder states - permissions().withPermission(INTERACT_ACROSS_USERS_FULL, MANAGE_ROLE_HOLDERS).use { _ -> + permissions().withPermission(INTERACT_ACROSS_USERS_FULL, MANAGE_ROLE_HOLDERS).use { assertThat(roleManager.getActiveUserForRole(PROFILE_GROUP_EXCLUSIVITY_ROLE_NAME)) .isEqualTo(targetActiveUser) assertExpectedProfileHasRoleUsingGetRoleHoldersAsUser(targetActiveUser) @@ -1472,7 +1483,7 @@ class RoleManagerMultiUserTest { // clearDefaultHoldersForTestForAllUsers and clearRoleVisibleForTestForAllUsers require // INTERACT_ACROSS_USERS_FULL and MANAGE_ROLE_HOLDERS permissions to validate cross user // role active user and role holder states - permissions().withPermission(INTERACT_ACROSS_USERS_FULL, MANAGE_ROLE_HOLDERS).use { _ -> + permissions().withPermission(INTERACT_ACROSS_USERS_FULL, MANAGE_ROLE_HOLDERS).use { clearDefaultHoldersForTestForAllUsers() clearRoleVisibleForTestForAllUsers() } @@ -1489,7 +1500,7 @@ class RoleManagerMultiUserTest { // setDefaultHoldersForTestForAllUsers and setRoleVisibleForTestForAllUsers require // INTERACT_ACROSS_USERS_FULL and MANAGE_ROLE_HOLDERS permissions to validate cross user // role active user and role holder states - permissions().withPermission(INTERACT_ACROSS_USERS_FULL, MANAGE_ROLE_HOLDERS).use { _ -> + permissions().withPermission(INTERACT_ACROSS_USERS_FULL, MANAGE_ROLE_HOLDERS).use { // Set test default role holder. Ensures fallbacks to a default holder setDefaultHoldersForTestForAllUsers() setRoleVisibleForTestForAllUsers() @@ -1516,7 +1527,7 @@ class RoleManagerMultiUserTest { // getActiveUserForRole and getRoleHoldersAsUser require INTERACT_ACROSS_USERS_FULL and // MANAGE_ROLE_HOLDERS permissions to validate cross user role active user and role // holder states - permissions().withPermission(INTERACT_ACROSS_USERS_FULL, MANAGE_ROLE_HOLDERS).use { _ -> + permissions().withPermission(INTERACT_ACROSS_USERS_FULL, MANAGE_ROLE_HOLDERS).use { assertThat(roleManager.getActiveUserForRole(PROFILE_GROUP_EXCLUSIVITY_ROLE_NAME)) .isEqualTo(targetActiveUser) assertExpectedProfileHasRoleUsingGetRoleHoldersAsUser(targetActiveUser) @@ -1525,7 +1536,7 @@ class RoleManagerMultiUserTest { // clearDefaultHoldersForTestForAllUsers and clearRoleVisibleForTestForAllUsers require // INTERACT_ACROSS_USERS_FULL and MANAGE_ROLE_HOLDERS permissions to validate cross user // role active user and role holder states - permissions().withPermission(INTERACT_ACROSS_USERS_FULL, MANAGE_ROLE_HOLDERS).use { _ -> + permissions().withPermission(INTERACT_ACROSS_USERS_FULL, MANAGE_ROLE_HOLDERS).use { clearDefaultHoldersForTestForAllUsers() clearRoleVisibleForTestForAllUsers() } @@ -1542,7 +1553,7 @@ class RoleManagerMultiUserTest { // setDefaultHoldersForTestForAllUsers and setRoleVisibleForTestForAllUsers require // INTERACT_ACROSS_USERS_FULL and MANAGE_ROLE_HOLDERS permissions to validate cross user // role active user and role holder states - permissions().withPermission(INTERACT_ACROSS_USERS_FULL, MANAGE_ROLE_HOLDERS).use { _ -> + permissions().withPermission(INTERACT_ACROSS_USERS_FULL, MANAGE_ROLE_HOLDERS).use { // Set test default role holder. Ensures fallbacks to a default holder setDefaultHoldersForTestForAllUsers() setRoleVisibleForTestForAllUsers() @@ -1567,7 +1578,7 @@ class RoleManagerMultiUserTest { // getActiveUserForRole and getRoleHoldersAsUser require INTERACT_ACROSS_USERS_FULL and // MANAGE_ROLE_HOLDERS permissions to validate cross user role active user and role // holder states - permissions().withPermission(INTERACT_ACROSS_USERS_FULL, MANAGE_ROLE_HOLDERS).use { _ -> + permissions().withPermission(INTERACT_ACROSS_USERS_FULL, MANAGE_ROLE_HOLDERS).use { assertThat(roleManager.getActiveUserForRole(PROFILE_GROUP_EXCLUSIVITY_ROLE_NAME)) .isEqualTo(deviceState.initialUser().userHandle()) assertNoRoleHoldersUsingGetRoleHoldersAsUser() @@ -1576,7 +1587,7 @@ class RoleManagerMultiUserTest { // clearDefaultHoldersForTestForAllUsers and clearRoleVisibleForTestForAllUsers require // INTERACT_ACROSS_USERS_FULL and MANAGE_ROLE_HOLDERS permissions to validate cross user // role active user and role holder states - permissions().withPermission(INTERACT_ACROSS_USERS_FULL, MANAGE_ROLE_HOLDERS).use { _ -> + permissions().withPermission(INTERACT_ACROSS_USERS_FULL, MANAGE_ROLE_HOLDERS).use { clearDefaultHoldersForTestForAllUsers() clearRoleVisibleForTestForAllUsers() } @@ -1645,7 +1656,12 @@ class RoleManagerMultiUserTest { getUiDevice().waitForIdle() // CollapsingToolbar title can't be found by text, so using description instead. - assertNull(waitFindObjectOrNull(By.desc(PROFILE_GROUP_EXCLUSIVITY_ROLE_LABEL))) + assertNull( + waitFindObjectOrNull( + By.desc(PROFILE_GROUP_EXCLUSIVITY_ROLE_LABEL), + IDLE_TIMEOUT_MILLIS, + ) + ) pressBack() pressBack() @@ -1681,7 +1697,12 @@ class RoleManagerMultiUserTest { getUiDevice().waitForIdle() // CollapsingToolbar title can't be found by text, so using description instead. - assertNull(waitFindObjectOrNull(By.desc(PROFILE_GROUP_EXCLUSIVITY_ROLE_LABEL))) + assertNull( + waitFindObjectOrNull( + By.desc(PROFILE_GROUP_EXCLUSIVITY_ROLE_LABEL), + IDLE_TIMEOUT_MILLIS, + ) + ) pressBack() pressBack() @@ -1816,7 +1837,8 @@ class RoleManagerMultiUserTest { if (isWatch) { assertNull( waitFindObjectOrNull( - By.clickable(true).checked(true).hasDescendant(By.text(targetAppLabel)) + By.clickable(true).checked(true).hasDescendant(By.text(targetAppLabel)), + IDLE_TIMEOUT_MILLIS, ) ) } else { @@ -1824,7 +1846,8 @@ class RoleManagerMultiUserTest { waitFindObjectOrNull( By.clickable(true) .hasDescendant(By.checkable(true).checked(true)) - .hasDescendant(By.text(targetAppLabel)) + .hasDescendant(By.text(targetAppLabel)), + IDLE_TIMEOUT_MILLIS, ) ) } @@ -1895,7 +1918,8 @@ class RoleManagerMultiUserTest { if (isWatch) { assertNull( waitFindObjectOrNull( - By.clickable(true).checked(true).hasDescendant(By.text(targetAppLabel)) + By.clickable(true).checked(true).hasDescendant(By.text(targetAppLabel)), + IDLE_TIMEOUT_MILLIS, ) ) } else { @@ -1903,7 +1927,8 @@ class RoleManagerMultiUserTest { waitFindObjectOrNull( By.clickable(true) .hasDescendant(By.checkable(true).checked(true)) - .hasDescendant(By.text(targetAppLabel)) + .hasDescendant(By.text(targetAppLabel)), + IDLE_TIMEOUT_MILLIS, ) ) } @@ -1934,7 +1959,7 @@ class RoleManagerMultiUserTest { // setDefaultHoldersForTestForAllUsers and setRoleVisibleForTestForAllUsers require // INTERACT_ACROSS_USERS_FULL and MANAGE_ROLE_HOLDERS permissions to validate cross user // role active user and role holder states - permissions().withPermission(INTERACT_ACROSS_USERS_FULL, MANAGE_ROLE_HOLDERS).use { _ -> + permissions().withPermission(INTERACT_ACROSS_USERS_FULL, MANAGE_ROLE_HOLDERS).use { // Set test default role holder. Ensures fallbacks to a default holder setDefaultHoldersForTestForAllUsers() setRoleVisibleForTestForAllUsers() @@ -1961,7 +1986,7 @@ class RoleManagerMultiUserTest { // getActiveUserForRole and getRoleHoldersAsUser require INTERACT_ACROSS_USERS_FULL and // MANAGE_ROLE_HOLDERS permissions to validate cross user role active user and role // holder states - permissions().withPermission(INTERACT_ACROSS_USERS_FULL, MANAGE_ROLE_HOLDERS).use { _ -> + permissions().withPermission(INTERACT_ACROSS_USERS_FULL, MANAGE_ROLE_HOLDERS).use { assertThat(roleManager.getActiveUserForRole(PROFILE_GROUP_EXCLUSIVITY_ROLE_NAME)) .isEqualTo(targetActiveUser) assertExpectedProfileHasRoleUsingGetRoleHoldersAsUser(targetActiveUser) @@ -1970,7 +1995,7 @@ class RoleManagerMultiUserTest { // clearDefaultHoldersForTestForAllUsers and clearRoleVisibleForTestForAllUsers require // INTERACT_ACROSS_USERS_FULL and MANAGE_ROLE_HOLDERS permissions to validate cross user // role active user and role holder states - permissions().withPermission(INTERACT_ACROSS_USERS_FULL, MANAGE_ROLE_HOLDERS).use { _ -> + permissions().withPermission(INTERACT_ACROSS_USERS_FULL, MANAGE_ROLE_HOLDERS).use { clearDefaultHoldersForTestForAllUsers() clearRoleVisibleForTestForAllUsers() } @@ -1991,7 +2016,7 @@ class RoleManagerMultiUserTest { // setDefaultHoldersForTestForAllUsers and setRoleVisibleForTestForAllUsers require // INTERACT_ACROSS_USERS_FULL and MANAGE_ROLE_HOLDERS permissions to validate cross user // role active user and role holder states - permissions().withPermission(INTERACT_ACROSS_USERS_FULL, MANAGE_ROLE_HOLDERS).use { _ -> + permissions().withPermission(INTERACT_ACROSS_USERS_FULL, MANAGE_ROLE_HOLDERS).use { // Set test default role holder. Ensures fallbacks to a default holder setDefaultHoldersForTestForAllUsers() setRoleVisibleForTestForAllUsers() @@ -2016,7 +2041,7 @@ class RoleManagerMultiUserTest { // clearDefaultHoldersForTestForAllUsers and clearRoleVisibleForTestForAllUsers require // INTERACT_ACROSS_USERS_FULL and MANAGE_ROLE_HOLDERS permissions to validate cross user // role active user and role holder states - permissions().withPermission(INTERACT_ACROSS_USERS_FULL, MANAGE_ROLE_HOLDERS).use { _ -> + permissions().withPermission(INTERACT_ACROSS_USERS_FULL, MANAGE_ROLE_HOLDERS).use { clearDefaultHoldersForTestForAllUsers() clearRoleVisibleForTestForAllUsers() } @@ -2037,7 +2062,7 @@ class RoleManagerMultiUserTest { // setDefaultHoldersForTestForAllUsers and setRoleVisibleForTestForAllUsers require // INTERACT_ACROSS_USERS_FULL and MANAGE_ROLE_HOLDERS permissions to validate cross user // role active user and role holder states - permissions().withPermission(INTERACT_ACROSS_USERS_FULL, MANAGE_ROLE_HOLDERS).use { _ -> + permissions().withPermission(INTERACT_ACROSS_USERS_FULL, MANAGE_ROLE_HOLDERS).use { // Set test default role holder. Ensures fallbacks to a default holder setDefaultHoldersForTestForAllUsers() setRoleVisibleForTestForAllUsers() @@ -2062,17 +2087,15 @@ class RoleManagerMultiUserTest { // clearDefaultHoldersForTestForAllUsers and clearRoleVisibleForTestForAllUsers require // INTERACT_ACROSS_USERS_FULL and MANAGE_ROLE_HOLDERS permissions to validate cross user // role active user and role holder states - permissions().withPermission(INTERACT_ACROSS_USERS_FULL, MANAGE_ROLE_HOLDERS).use { _ -> + permissions().withPermission(INTERACT_ACROSS_USERS_FULL, MANAGE_ROLE_HOLDERS).use { clearDefaultHoldersForTestForAllUsers() clearRoleVisibleForTestForAllUsers() } } } - @Throws(java.lang.Exception::class) private fun installAppForAllUsers() { SystemUtil.runShellCommandOrThrow("pm install -r --user all $APP_APK_PATH") - SystemUtil.waitForBroadcasts() } private fun uninstallAppForAllUsers() { @@ -2099,8 +2122,7 @@ class RoleManagerMultiUserTest { } val result: Pair<Int, Intent?> = clickButtonAndWaitForResult(allow) val expectedResult = - if (allow && Objects.equals(targetActiveUser, users().instrumented().userHandle())) - Activity.RESULT_OK + if (allow && targetActiveUser == users().instrumented().userHandle()) Activity.RESULT_OK else Activity.RESULT_CANCELED assertThat(result.first).isEqualTo(expectedResult) @@ -2118,7 +2140,8 @@ class RoleManagerMultiUserTest { } private fun roleRequestNotShown() { - val requestRoleItem = waitFindObjectOrNull(By.textStartsWith(APP_LABEL)) + val requestRoleItem = + waitFindObjectOrNull(By.textStartsWith(APP_LABEL), IDLE_TIMEOUT_MILLIS) assertNull(requestRoleItem) val result: Pair<Int, Intent?> = waitForResult() @@ -2148,9 +2171,9 @@ class RoleManagerMultiUserTest { ) { for (userReference in users().profileGroup(deviceState.initialUser())) { val user = userReference.userHandle() - if (Objects.equals(user, expectedActiveUser)) { - val roleHolders = - roleManager.getRoleHoldersAsUser(PROFILE_GROUP_EXCLUSIVITY_ROLE_NAME, user) + val roleHolders = + roleManager.getRoleHoldersAsUser(PROFILE_GROUP_EXCLUSIVITY_ROLE_NAME, user) + if (user == expectedActiveUser) { assertWithMessage( "Expected user ${user.identifier} to have a role holder for " + " $PROFILE_GROUP_EXCLUSIVITY_ROLE_NAME" @@ -2169,9 +2192,7 @@ class RoleManagerMultiUserTest { "Expected user ${user.identifier} to not have a role holder for" + " $PROFILE_GROUP_EXCLUSIVITY_ROLE_NAME" ) - .that( - roleManager.getRoleHoldersAsUser(PROFILE_GROUP_EXCLUSIVITY_ROLE_NAME, user) - ) + .that(roleHolders) .isEmpty() } } @@ -2183,7 +2204,7 @@ class RoleManagerMultiUserTest { for (userReference in users().profileGroup(deviceState.initialUser())) { val userRoleManager = getRoleManagerForUser(userReference) val user = userReference.userHandle() - if (Objects.equals(user, expectedActiveUser)) { + if (user == expectedActiveUser) { assertWithMessage("Expected default application for user ${user.identifier}") .that( userRoleManager.getDefaultApplication(PROFILE_GROUP_EXCLUSIVITY_ROLE_NAME) @@ -2203,7 +2224,7 @@ class RoleManagerMultiUserTest { private fun setDefaultHoldersForTestForAllUsers() { // Set test default role holder. Ensures fallbacks to a default holder for (userRoleManager in - users().profileGroup(deviceState.initialUser()).map { getRoleManagerForUser(it) }) { + users().profileGroup(users().current()).map { getRoleManagerForUser(it) }) { userRoleManager.setDefaultHoldersForTest( PROFILE_GROUP_EXCLUSIVITY_ROLE_NAME, listOf(APP_PACKAGE_NAME), @@ -2214,7 +2235,7 @@ class RoleManagerMultiUserTest { private fun clearDefaultHoldersForTestForAllUsers() { // Set test default role holder. Ensures fallbacks to a default holder for (userRoleManager in - users().profileGroup(deviceState.initialUser()).map { getRoleManagerForUser(it) }) { + users().profileGroup(users().current()).map { getRoleManagerForUser(it) }) { userRoleManager.setDefaultHoldersForTest( PROFILE_GROUP_EXCLUSIVITY_ROLE_NAME, emptyList(), @@ -2225,7 +2246,7 @@ class RoleManagerMultiUserTest { private fun setRoleVisibleForTestForAllUsers() { // Set test default role holder. Ensures fallbacks to a default holder for (userRoleManager in - users().profileGroup(deviceState.initialUser()).map { getRoleManagerForUser(it) }) { + users().profileGroup(users().current()).map { getRoleManagerForUser(it) }) { userRoleManager.setRoleVisibleForTest(PROFILE_GROUP_EXCLUSIVITY_ROLE_NAME, true) } } @@ -2233,11 +2254,28 @@ class RoleManagerMultiUserTest { private fun clearRoleVisibleForTestForAllUsers() { // Set test default role holder. Ensures fallbacks to a default holder for (userRoleManager in - users().profileGroup(deviceState.initialUser()).map { getRoleManagerForUser(it) }) { + users().profileGroup(users().current()).map { getRoleManagerForUser(it) }) { userRoleManager.setRoleVisibleForTest(PROFILE_GROUP_EXCLUSIVITY_ROLE_NAME, false) } } + private fun setRoleFallbackEnabledForAllUsers() { + for (userReference in users().profileGroup(users().current())) { + try { + val userRoleManager = getRoleManagerForUser(userReference) + userRoleManager.setRoleFallbackEnabled(PROFILE_GROUP_EXCLUSIVITY_ROLE_NAME, true) + } catch (e: Exception) { + Log.w( + LOG_TAG, + "Encountered error setting fallback enabled for" + + " $PROFILE_GROUP_EXCLUSIVITY_ROLE_NAME@" + + "${userReference.userHandle().identifier}", + e, + ) + } + } + } + private fun getRoleManagerForUser(user: UserReference): RoleManager { val userContext = context().androidContextAsUser(user) return userContext.getSystemService(RoleManager::class.java) @@ -2250,7 +2288,10 @@ class RoleManagerMultiUserTest { } companion object { + private val LOG_TAG = RoleManagerMultiUserTest::class.java.simpleName + private const val TIMEOUT_MILLIS: Long = (15 * 1000).toLong() + private const val IDLE_TIMEOUT_MILLIS: Long = (2 * 1000).toLong() private const val PROFILE_GROUP_EXCLUSIVITY_ROLE_NAME = RoleManager.ROLE_RESERVED_FOR_TESTING_PROFILE_GROUP_EXCLUSIVITY private const val PROFILE_GROUP_EXCLUSIVITY_ROLE_LABEL = diff --git a/tests/cts/safetycenter/AndroidTest.xml b/tests/cts/safetycenter/AndroidTest.xml index 6d8c3069c..ed161f0b6 100644 --- a/tests/cts/safetycenter/AndroidTest.xml +++ b/tests/cts/safetycenter/AndroidTest.xml @@ -47,6 +47,10 @@ <!-- Disable syncing to prevent overwriting flags during testing. --> <option name="run-command" value="device_config set_sync_disabled_for_tests persistent" /> <option name="teardown-command" value="device_config set_sync_disabled_for_tests none" /> + <!-- Belt-and-braces attempt to dismiss keyguard. Tradefed should have already done this + for us, but this is a precaution in an attempt to mitigate b/379620557. --> + <option name="run-command" value="input keyevent KEYCODE_WAKEUP" /> + <option name="run-command" value="wm dismiss-keyguard" /> <!-- Dismiss any system dialogs (e.g. crashes, ANR). --> <option name="run-command" value="am broadcast -a android.intent.action.CLOSE_SYSTEM_DIALOGS --receiver-foreground" /> </target_preparer> diff --git a/tests/functional/safetycenter/multiusers/AndroidTest.xml b/tests/functional/safetycenter/multiusers/AndroidTest.xml index 20032357a..bfb7fdbf2 100644 --- a/tests/functional/safetycenter/multiusers/AndroidTest.xml +++ b/tests/functional/safetycenter/multiusers/AndroidTest.xml @@ -47,6 +47,10 @@ <!-- Disable syncing to prevent overwriting flags during testing. --> <option name="run-command" value="device_config set_sync_disabled_for_tests persistent" /> <option name="teardown-command" value="device_config set_sync_disabled_for_tests none" /> + <!-- Belt-and-braces attempt to dismiss keyguard. Tradefed should have already done this + for us, but this is a precaution in an attempt to mitigate b/379620557. --> + <option name="run-command" value="input keyevent KEYCODE_WAKEUP" /> + <option name="run-command" value="wm dismiss-keyguard" /> <!-- Dismiss any system dialogs (e.g. crashes, ANR). --> <option name="run-command" value="am broadcast -a android.intent.action.CLOSE_SYSTEM_DIALOGS --receiver-foreground" /> </target_preparer> diff --git a/tests/functional/safetycenter/safetycenteractivity/AndroidTest.xml b/tests/functional/safetycenter/safetycenteractivity/AndroidTest.xml index a1826653f..ee79dcd2a 100644 --- a/tests/functional/safetycenter/safetycenteractivity/AndroidTest.xml +++ b/tests/functional/safetycenter/safetycenteractivity/AndroidTest.xml @@ -47,6 +47,10 @@ <!-- Disable syncing to prevent overwriting flags during testing. --> <option name="run-command" value="device_config set_sync_disabled_for_tests persistent" /> <option name="teardown-command" value="device_config set_sync_disabled_for_tests none" /> + <!-- Belt-and-braces attempt to dismiss keyguard. Tradefed should have already done this + for us, but this is a precaution in an attempt to mitigate b/379620557. --> + <option name="run-command" value="input keyevent KEYCODE_WAKEUP" /> + <option name="run-command" value="wm dismiss-keyguard" /> <!-- Dismiss any system dialogs (e.g. crashes, ANR). --> <option name="run-command" value="am broadcast -a android.intent.action.CLOSE_SYSTEM_DIALOGS --receiver-foreground" /> </target_preparer> diff --git a/tests/functional/safetycenter/singleuser/AndroidTest.xml b/tests/functional/safetycenter/singleuser/AndroidTest.xml index af040eb6f..f778ca93e 100644 --- a/tests/functional/safetycenter/singleuser/AndroidTest.xml +++ b/tests/functional/safetycenter/singleuser/AndroidTest.xml @@ -47,8 +47,8 @@ <!-- Disable syncing to prevent overwriting flags during testing. --> <option name="run-command" value="device_config set_sync_disabled_for_tests persistent" /> <option name="teardown-command" value="device_config set_sync_disabled_for_tests none" /> - <!-- TODO(b/379928062): Ensure device not on lockscreen. Reassess when keyguard bug is - closed --> + <!-- Belt-and-braces attempt to dismiss keyguard. Tradefed should have already done this + for us, but this is a precaution in an attempt to mitigate b/379620557. --> <option name="run-command" value="input keyevent KEYCODE_WAKEUP" /> <option name="run-command" value="wm dismiss-keyguard" /> <!-- Dismiss any system dialogs (e.g. crashes, ANR). --> diff --git a/tests/functional/safetycenter/singleuser/src/android/safetycenter/functional/SafetyCenterManagerTest.kt b/tests/functional/safetycenter/singleuser/src/android/safetycenter/functional/SafetyCenterManagerTest.kt index 64db7d47a..f5d230deb 100644 --- a/tests/functional/safetycenter/singleuser/src/android/safetycenter/functional/SafetyCenterManagerTest.kt +++ b/tests/functional/safetycenter/singleuser/src/android/safetycenter/functional/SafetyCenterManagerTest.kt @@ -75,6 +75,7 @@ import com.android.safetycenter.internaldata.SafetyCenterIds import com.android.safetycenter.resources.SafetyCenterResourcesApk import com.android.safetycenter.testing.Coroutines.TIMEOUT_LONG import com.android.safetycenter.testing.Coroutines.TIMEOUT_SHORT +import com.android.safetycenter.testing.Coroutines.assertWithTimeout import com.android.safetycenter.testing.Coroutines.waitForWithTimeout import com.android.safetycenter.testing.SafetyCenterApisWithShellPermissions.dismissSafetyCenterIssueWithPermission import com.android.safetycenter.testing.SafetyCenterApisWithShellPermissions.getSafetyCenterConfigWithPermission @@ -2356,18 +2357,14 @@ class SafetyCenterManagerTest { groupId = MULTIPLE_SOURCES_GROUP_ID_2, ) ) - waitForWithTimeout(timeout = RESURFACE_TIMEOUT, checkPeriod = RESURFACE_CHECK) { - val hasResurfaced = - safetyCenterManager - .getSafetyCenterDataWithPermission() - .issues - .contains( - safetyCenterTestData.safetyCenterIssueCritical( - SOURCE_ID_5, - groupId = MULTIPLE_SOURCES_GROUP_ID_2, - ) + assertWithTimeout(timeout = RESURFACE_TIMEOUT, checkPeriod = RESURFACE_CHECK) { + assertThat(safetyCenterManager.getSafetyCenterDataWithPermission().issues) + .contains( + safetyCenterTestData.safetyCenterIssueCritical( + SOURCE_ID_5, + groupId = MULTIPLE_SOURCES_GROUP_ID_2, ) - hasResurfaced + ) } } @@ -3986,9 +3983,9 @@ class SafetyCenterManagerTest { companion object { private val RESURFACE_DELAY = Duration.ofMillis(500) - // Wait 3 times the RESURFACE_DELAY before asserting whether an issue has or has not + // Wait 5 times the RESURFACE_DELAY before asserting whether an issue has or has not // resurfaced. Use a constant additive error buffer if we increase the delay considerably. - private val RESURFACE_TIMEOUT = RESURFACE_DELAY.multipliedBy(3) + private val RESURFACE_TIMEOUT = RESURFACE_DELAY.multipliedBy(5) // Check more than once during a RESURFACE_DELAY before asserting whether an issue has or // has not resurfaced. Use a different check logic (focused at the expected resurface time) diff --git a/tests/functional/safetycenter/subpages/AndroidTest.xml b/tests/functional/safetycenter/subpages/AndroidTest.xml index c3245e9d7..ac493841f 100644 --- a/tests/functional/safetycenter/subpages/AndroidTest.xml +++ b/tests/functional/safetycenter/subpages/AndroidTest.xml @@ -47,6 +47,10 @@ <!-- Disable syncing to prevent overwriting flags during testing. --> <option name="run-command" value="device_config set_sync_disabled_for_tests persistent" /> <option name="teardown-command" value="device_config set_sync_disabled_for_tests none" /> + <!-- Belt-and-braces attempt to dismiss keyguard. Tradefed should have already done this + for us, but this is a precaution in an attempt to mitigate b/379620557. --> + <option name="run-command" value="input keyevent KEYCODE_WAKEUP" /> + <option name="run-command" value="wm dismiss-keyguard" /> <!-- Dismiss any system dialogs (e.g. crashes, ANR). --> <option name="run-command" value="am broadcast -a android.intent.action.CLOSE_SYSTEM_DIALOGS --receiver-foreground" /> </target_preparer> diff --git a/tests/hostside/safetycenter/AndroidTest.xml b/tests/hostside/safetycenter/AndroidTest.xml index a28b70c3c..41f0bcc40 100644 --- a/tests/hostside/safetycenter/AndroidTest.xml +++ b/tests/hostside/safetycenter/AndroidTest.xml @@ -32,6 +32,10 @@ <!-- Disable syncing to prevent overwriting flags during testing. --> <option name="run-command" value="device_config set_sync_disabled_for_tests persistent" /> <option name="teardown-command" value="device_config set_sync_disabled_for_tests none" /> + <!-- Belt-and-braces attempt to dismiss keyguard. Tradefed should have already done this + for us, but this is a precaution in an attempt to mitigate b/379620557. --> + <option name="run-command" value="input keyevent KEYCODE_WAKEUP" /> + <option name="run-command" value="wm dismiss-keyguard" /> <!-- Dismiss any system dialogs (e.g. crashes, ANR). --> <option name="run-command" value="am broadcast -a android.intent.action.CLOSE_SYSTEM_DIALOGS --receiver-foreground" /> </target_preparer> diff --git a/tests/hostside/safetycenter/helper-app/src/android/safetycenter/hostside/device/SafetyCenterNotificationLoggingHelperTests.kt b/tests/hostside/safetycenter/helper-app/src/android/safetycenter/hostside/device/SafetyCenterNotificationLoggingHelperTests.kt index 60e6e41ec..c56c913b6 100644 --- a/tests/hostside/safetycenter/helper-app/src/android/safetycenter/hostside/device/SafetyCenterNotificationLoggingHelperTests.kt +++ b/tests/hostside/safetycenter/helper-app/src/android/safetycenter/hostside/device/SafetyCenterNotificationLoggingHelperTests.kt @@ -69,6 +69,12 @@ class SafetyCenterNotificationLoggingHelperTests { @Test fun sendNotification() { safetyCenterTestHelper.setData(SINGLE_SOURCE_ID, newTestDataWithNotifiableIssue()) + TestNotificationListener.waitForSingleNotificationMatching( + NotificationCharacteristics( + actions = listOf("See issue"), + safetySourceId = SINGLE_SOURCE_ID, + ) + ) } @Test @@ -104,7 +110,7 @@ class SafetyCenterNotificationLoggingHelperTests { statusBarNotificationWithChannel.statusBarNotification.notification.contentIntent SafetyCenterActivityLauncher.executeBlockAndExit( launchActivity = { PendingIntentSender.send(contentIntent) }, - block = {} // No action required + block = {}, // No action required ) } } diff --git a/tests/utils/safetycenter/java/com/android/safetycenter/testing/Coroutines.kt b/tests/utils/safetycenter/java/com/android/safetycenter/testing/Coroutines.kt index cc8c53d5e..47f5165e2 100644 --- a/tests/utils/safetycenter/java/com/android/safetycenter/testing/Coroutines.kt +++ b/tests/utils/safetycenter/java/com/android/safetycenter/testing/Coroutines.kt @@ -22,6 +22,7 @@ import java.time.Duration import kotlinx.coroutines.DEBUG_PROPERTY_NAME import kotlinx.coroutines.DEBUG_PROPERTY_VALUE_AUTO import kotlinx.coroutines.DEBUG_PROPERTY_VALUE_ON +import kotlinx.coroutines.TimeoutCancellationException import kotlinx.coroutines.delay import kotlinx.coroutines.runBlocking import kotlinx.coroutines.withTimeout @@ -68,6 +69,20 @@ object Coroutines { runBlockingWithTimeout(timeout) { waitFor(checkPeriod, condition) } } + /** Check an assertion passes, with a timeout if it does not. */ + fun assertWithTimeout( + timeout: Duration = TIMEOUT_LONG, + checkPeriod: Duration = CHECK_PERIOD, + assertion: () -> Unit, + ) { + try { + runBlockingWithTimeout(timeout) { assertThatWaiting(checkPeriod, assertion) } + } catch (ex: TimeoutCancellationException) { + // Rerun the assertion to generate a meaningful error message that isn't just "timeout" + assertion() + } + } + /** Retries a [fallibleAction] until no errors are thrown or a timeout occurs. */ fun waitForSuccessWithTimeout( timeout: Duration = TIMEOUT_LONG, @@ -105,6 +120,21 @@ object Coroutines { } } + /** Check an assertion passes using coroutines. */ + private suspend fun assertThatWaiting( + checkPeriod: Duration = CHECK_PERIOD, + assertion: () -> Unit, + ) { + while (true) { + try { + assertion() + break + } catch (ex: AssertionError) { + delay(checkPeriod.toMillis()) + } + } + } + private const val TAG: String = "Coroutines" /** A medium period, to be used for conditions that are expected to change. */ |