diff options
| author | 2023-12-14 20:44:08 +0000 | |
|---|---|---|
| committer | 2023-12-14 21:41:10 +0000 | |
| commit | 4c6066e23fc1dc241810bf81d26d8f4ca2f69851 (patch) | |
| tree | afb4276e593371cfd68f3dd964eda33710a9cfc1 | |
| parent | edf588d353b1a751f73278b87aedc9e59ae1123c (diff) | |
Add tests for new CREATE_ACCESSIBILITY_OVERLAY AppOp flow
Bug: 289081465
Test: tests pass locally + presubmit
Change-Id: I769ece4da01aaeb91ad62d376511b191fd48ac44
| -rw-r--r-- | services/tests/wmtests/src/com/android/server/policy/PhoneWindowManagerTests.java | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/services/tests/wmtests/src/com/android/server/policy/PhoneWindowManagerTests.java b/services/tests/wmtests/src/com/android/server/policy/PhoneWindowManagerTests.java index 53635835f164..29467f259ac3 100644 --- a/services/tests/wmtests/src/com/android/server/policy/PhoneWindowManagerTests.java +++ b/services/tests/wmtests/src/com/android/server/policy/PhoneWindowManagerTests.java @@ -16,6 +16,10 @@ package com.android.server.policy; +import static android.view.WindowManager.LayoutParams.TYPE_ACCESSIBILITY_OVERLAY; +import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER; +import static android.view.WindowManagerGlobal.ADD_OKAY; + import static com.android.dx.mockito.inline.extended.ExtendedMockito.doNothing; import static com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn; import static com.android.dx.mockito.inline.extended.ExtendedMockito.mock; @@ -26,11 +30,16 @@ import static com.android.dx.mockito.inline.extended.ExtendedMockito.spyOn; import static com.android.dx.mockito.inline.extended.ExtendedMockito.verify; import static com.android.dx.mockito.inline.extended.ExtendedMockito.when; +import static com.google.common.truth.Truth.assertThat; + +import static org.junit.Assert.assertEquals; import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.anyString; import android.app.ActivityManager; +import android.app.AppOpsManager; +import android.platform.test.flag.junit.SetFlagsRule; import androidx.test.filters.SmallTest; @@ -39,6 +48,7 @@ import com.android.server.wm.ActivityTaskManagerInternal; import org.junit.After; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; /** @@ -50,6 +60,9 @@ import org.junit.Test; @SmallTest public class PhoneWindowManagerTests { + @Rule + public final SetFlagsRule mSetFlagsRule = new SetFlagsRule(); + PhoneWindowManager mPhoneWindowManager; @Before @@ -85,6 +98,36 @@ public class PhoneWindowManagerTests { verify(mPhoneWindowManager).createHomeDockIntent(); } + @Test + public void testCheckAddPermission_withoutAccessibilityOverlay_noAccessibilityAppOpLogged() { + mSetFlagsRule.enableFlags(android.view.contentprotection.flags.Flags + .FLAG_CREATE_ACCESSIBILITY_OVERLAY_APP_OP_ENABLED); + int[] outAppOp = new int[1]; + assertEquals(ADD_OKAY, mPhoneWindowManager.checkAddPermission(TYPE_WALLPAPER, + /* isRoundedCornerOverlay= */ false, "test.pkg", outAppOp)); + assertThat(outAppOp[0]).isEqualTo(AppOpsManager.OP_NONE); + } + + @Test + public void testCheckAddPermission_withAccessibilityOverlay() { + mSetFlagsRule.enableFlags(android.view.contentprotection.flags.Flags + .FLAG_CREATE_ACCESSIBILITY_OVERLAY_APP_OP_ENABLED); + int[] outAppOp = new int[1]; + assertEquals(ADD_OKAY, mPhoneWindowManager.checkAddPermission(TYPE_ACCESSIBILITY_OVERLAY, + /* isRoundedCornerOverlay= */ false, "test.pkg", outAppOp)); + assertThat(outAppOp[0]).isEqualTo(AppOpsManager.OP_CREATE_ACCESSIBILITY_OVERLAY); + } + + @Test + public void testCheckAddPermission_withAccessibilityOverlay_flagDisabled() { + mSetFlagsRule.disableFlags(android.view.contentprotection.flags.Flags + .FLAG_CREATE_ACCESSIBILITY_OVERLAY_APP_OP_ENABLED); + int[] outAppOp = new int[1]; + assertEquals(ADD_OKAY, mPhoneWindowManager.checkAddPermission(TYPE_ACCESSIBILITY_OVERLAY, + /* isRoundedCornerOverlay= */ false, "test.pkg", outAppOp)); + assertThat(outAppOp[0]).isEqualTo(AppOpsManager.OP_NONE); + } + private void mockStartDockOrHome() throws Exception { doNothing().when(ActivityManager.getService()).stopAppSwitches(); ActivityTaskManagerInternal mMockActivityTaskManagerInternal = |