Loading services/core/java/com/android/server/wm/AppCompatSafeRegionPolicy.java +2 −2 Original line number Diff line number Diff line Loading @@ -67,7 +67,7 @@ class AppCompatSafeRegionPolicy { }); } private boolean allowSafeRegionLetterboxing(PackageManager pm) { private boolean allowSafeRegionLetterboxing(@NonNull PackageManager pm) { try { return pm.getPropertyAsUser( PROPERTY_COMPAT_ALLOW_SAFE_REGION_LETTERBOXING, Loading @@ -75,7 +75,7 @@ class AppCompatSafeRegionPolicy { /* className */ null, mActivityRecord.mUserId).getBoolean(); } catch (PackageManager.NameNotFoundException e) { return true; return false; } } Loading services/tests/wmtests/src/com/android/server/wm/SizeCompatTests.java +39 −0 Original line number Diff line number Diff line Loading @@ -49,6 +49,7 @@ import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR; 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.doThrow; import static com.android.dx.mockito.inline.extended.ExtendedMockito.eq; import static com.android.dx.mockito.inline.extended.ExtendedMockito.mock; import static com.android.dx.mockito.inline.extended.ExtendedMockito.never; Loading Loading @@ -4782,6 +4783,34 @@ public class SizeCompatTests extends WindowTestsBase { .getSafeRegionPolicy().isLetterboxedForSafeRegionOnlyAllowed()); } @Test @EnableFlags(Flags.FLAG_SAFE_REGION_LETTERBOXING) public void testIsLetterboxedForSafeRegionOnly_appPropUnset_allowedForActivity_returnsTrue() throws PackageManager.NameNotFoundException { setUpLandscapeLargeScreenDisplayWithApp(); assertFalse(mActivity.areBoundsLetterboxed()); verifyLogAppCompatState(mActivity, APP_COMPAT_STATE_CHANGED__STATE__NOT_LETTERBOXED); setupSafeRegionBoundsParameters(/* dw */ 300, /* dh */ 200); // Activity can opt-out the safe region letterboxing by component level property. final ComponentName name = getUniqueComponentName(mContext.getPackageName()); final PackageManager pm = mContext.getPackageManager(); spyOn(pm); throwExceptionApplicationLevelAllowSafeRegionLetterboxingProperty(name, pm); updateActivityLevelAllowSafeRegionLetterboxingProperty(name, pm, true /* value */); final ActivityRecord optOutActivity = new ActivityBuilder(mAtm) .setComponent(name).setTask(mTask).build(); optOutActivity.mAppCompatController.getSafeRegionPolicy().setNeedsSafeRegionBounds(true); // Since activity manifest property is defined as true, the activity can be letterboxed // for safe region assertTrue(optOutActivity.mAppCompatController .getSafeRegionPolicy().isLetterboxedForSafeRegionOnlyAllowed()); } @Test @EnableFlags(Flags.FLAG_SAFE_REGION_LETTERBOXING) public void testIsLetterboxedForSafeRegionOnlyAllowed_notAllowedForActivity_returnsFalse() { Loading Loading @@ -4857,6 +4886,16 @@ public class SizeCompatTests extends WindowTestsBase { .getSafeRegionPolicy().isLetterboxedForSafeRegionOnlyAllowed()); } private void throwExceptionApplicationLevelAllowSafeRegionLetterboxingProperty( ComponentName name, PackageManager pm) throws PackageManager.NameNotFoundException { PackageManager.NameNotFoundException e = new PackageManager.NameNotFoundException( "Application level property not set"); doThrow(e).when(pm).getPropertyAsUser( WindowManager.PROPERTY_COMPAT_ALLOW_SAFE_REGION_LETTERBOXING, name.getPackageName(), /* className */ null, /* userId */ 0); } private void updateApplicationLevelAllowSafeRegionLetterboxingProperty(ComponentName name, PackageManager pm, boolean propertyValueForApplication) { final PackageManager.Property propertyForApplication = new PackageManager.Property( Loading Loading
services/core/java/com/android/server/wm/AppCompatSafeRegionPolicy.java +2 −2 Original line number Diff line number Diff line Loading @@ -67,7 +67,7 @@ class AppCompatSafeRegionPolicy { }); } private boolean allowSafeRegionLetterboxing(PackageManager pm) { private boolean allowSafeRegionLetterboxing(@NonNull PackageManager pm) { try { return pm.getPropertyAsUser( PROPERTY_COMPAT_ALLOW_SAFE_REGION_LETTERBOXING, Loading @@ -75,7 +75,7 @@ class AppCompatSafeRegionPolicy { /* className */ null, mActivityRecord.mUserId).getBoolean(); } catch (PackageManager.NameNotFoundException e) { return true; return false; } } Loading
services/tests/wmtests/src/com/android/server/wm/SizeCompatTests.java +39 −0 Original line number Diff line number Diff line Loading @@ -49,6 +49,7 @@ import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR; 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.doThrow; import static com.android.dx.mockito.inline.extended.ExtendedMockito.eq; import static com.android.dx.mockito.inline.extended.ExtendedMockito.mock; import static com.android.dx.mockito.inline.extended.ExtendedMockito.never; Loading Loading @@ -4782,6 +4783,34 @@ public class SizeCompatTests extends WindowTestsBase { .getSafeRegionPolicy().isLetterboxedForSafeRegionOnlyAllowed()); } @Test @EnableFlags(Flags.FLAG_SAFE_REGION_LETTERBOXING) public void testIsLetterboxedForSafeRegionOnly_appPropUnset_allowedForActivity_returnsTrue() throws PackageManager.NameNotFoundException { setUpLandscapeLargeScreenDisplayWithApp(); assertFalse(mActivity.areBoundsLetterboxed()); verifyLogAppCompatState(mActivity, APP_COMPAT_STATE_CHANGED__STATE__NOT_LETTERBOXED); setupSafeRegionBoundsParameters(/* dw */ 300, /* dh */ 200); // Activity can opt-out the safe region letterboxing by component level property. final ComponentName name = getUniqueComponentName(mContext.getPackageName()); final PackageManager pm = mContext.getPackageManager(); spyOn(pm); throwExceptionApplicationLevelAllowSafeRegionLetterboxingProperty(name, pm); updateActivityLevelAllowSafeRegionLetterboxingProperty(name, pm, true /* value */); final ActivityRecord optOutActivity = new ActivityBuilder(mAtm) .setComponent(name).setTask(mTask).build(); optOutActivity.mAppCompatController.getSafeRegionPolicy().setNeedsSafeRegionBounds(true); // Since activity manifest property is defined as true, the activity can be letterboxed // for safe region assertTrue(optOutActivity.mAppCompatController .getSafeRegionPolicy().isLetterboxedForSafeRegionOnlyAllowed()); } @Test @EnableFlags(Flags.FLAG_SAFE_REGION_LETTERBOXING) public void testIsLetterboxedForSafeRegionOnlyAllowed_notAllowedForActivity_returnsFalse() { Loading Loading @@ -4857,6 +4886,16 @@ public class SizeCompatTests extends WindowTestsBase { .getSafeRegionPolicy().isLetterboxedForSafeRegionOnlyAllowed()); } private void throwExceptionApplicationLevelAllowSafeRegionLetterboxingProperty( ComponentName name, PackageManager pm) throws PackageManager.NameNotFoundException { PackageManager.NameNotFoundException e = new PackageManager.NameNotFoundException( "Application level property not set"); doThrow(e).when(pm).getPropertyAsUser( WindowManager.PROPERTY_COMPAT_ALLOW_SAFE_REGION_LETTERBOXING, name.getPackageName(), /* className */ null, /* userId */ 0); } private void updateApplicationLevelAllowSafeRegionLetterboxingProperty(ComponentName name, PackageManager pm, boolean propertyValueForApplication) { final PackageManager.Property propertyForApplication = new PackageManager.Property( Loading