Add opt-out properties for aspect ratio settings
Don't display aspect ratio options if app has opted out. If app has opted out only for fullscreen, other aspect ratio options should still be shown. Bug: 292583399 Test: UserAspectRatioManagerTest Change-Id: Ia0b223536407f703826d775468c8f8a0b4822e23
This commit is contained in:
@@ -201,11 +201,12 @@ public class UserAspectRatioDetails extends AppInfoWithHeader implements
|
||||
if (pref == null) {
|
||||
return;
|
||||
}
|
||||
if (!mUserAspectRatioManager.containsAspectRatioOption(aspectRatio)) {
|
||||
if (!mUserAspectRatioManager.hasAspectRatioOption(aspectRatio, mPackageName)) {
|
||||
pref.setVisible(false);
|
||||
return;
|
||||
}
|
||||
pref.setTitle(mUserAspectRatioManager.getUserMinAspectRatioEntry(aspectRatio));
|
||||
pref.setTitle(mUserAspectRatioManager.getUserMinAspectRatioEntry(aspectRatio,
|
||||
mPackageName));
|
||||
pref.setOnClickListener(this);
|
||||
mAspectRatioPreferences.add(pref);
|
||||
}
|
||||
|
@@ -16,6 +16,11 @@
|
||||
|
||||
package com.android.settings.applications.appcompat;
|
||||
|
||||
import static android.view.WindowManager.PROPERTY_COMPAT_ALLOW_USER_ASPECT_RATIO_FULLSCREEN_OVERRIDE;
|
||||
import static android.view.WindowManager.PROPERTY_COMPAT_ALLOW_USER_ASPECT_RATIO_OVERRIDE;
|
||||
|
||||
import static java.lang.Boolean.FALSE;
|
||||
|
||||
import android.app.AppGlobals;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
@@ -63,7 +68,7 @@ public class UserAspectRatioManager {
|
||||
public UserAspectRatioManager(@NonNull Context context) {
|
||||
mContext = context;
|
||||
mIPm = AppGlobals.getPackageManager();
|
||||
mInfoHasLauncherEntryList = context.getPackageManager().queryIntentActivities(
|
||||
mInfoHasLauncherEntryList = mContext.getPackageManager().queryIntentActivities(
|
||||
UserAspectRatioManager.LAUNCHER_ENTRY_INTENT, PackageManager.GET_META_DATA);
|
||||
mUserAspectRatioMap = getUserMinAspectRatioMapping();
|
||||
}
|
||||
@@ -85,7 +90,7 @@ public class UserAspectRatioManager {
|
||||
public int getUserMinAspectRatioValue(@NonNull String packageName, int uid)
|
||||
throws RemoteException {
|
||||
final int aspectRatio = mIPm.getUserMinAspectRatio(packageName, uid);
|
||||
return containsAspectRatioOption(aspectRatio)
|
||||
return hasAspectRatioOption(aspectRatio, packageName)
|
||||
? aspectRatio : PackageManager.USER_MIN_ASPECT_RATIO_UNSET;
|
||||
}
|
||||
|
||||
@@ -93,8 +98,9 @@ public class UserAspectRatioManager {
|
||||
* @return corresponding string for {@link PackageManager.UserMinAspectRatio} value
|
||||
*/
|
||||
@NonNull
|
||||
public String getUserMinAspectRatioEntry(@PackageManager.UserMinAspectRatio int aspectRatio) {
|
||||
if (!containsAspectRatioOption(aspectRatio)) {
|
||||
public String getUserMinAspectRatioEntry(@PackageManager.UserMinAspectRatio int aspectRatio,
|
||||
String packageName) {
|
||||
if (!hasAspectRatioOption(aspectRatio, packageName)) {
|
||||
return mUserAspectRatioMap.get(PackageManager.USER_MIN_ASPECT_RATIO_UNSET);
|
||||
}
|
||||
return mUserAspectRatioMap.get(aspectRatio);
|
||||
@@ -107,7 +113,7 @@ public class UserAspectRatioManager {
|
||||
public String getUserMinAspectRatioEntry(@NonNull String packageName, int uid)
|
||||
throws RemoteException {
|
||||
final int aspectRatio = getUserMinAspectRatioValue(packageName, uid);
|
||||
return getUserMinAspectRatioEntry(aspectRatio);
|
||||
return getUserMinAspectRatioEntry(aspectRatio, packageName);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -115,9 +121,10 @@ public class UserAspectRatioManager {
|
||||
* {@link R.array.config_userAspectRatioOverrideValues}
|
||||
* and is enabled by device config
|
||||
*/
|
||||
public boolean containsAspectRatioOption(@PackageManager.UserMinAspectRatio int option) {
|
||||
public boolean hasAspectRatioOption(@PackageManager.UserMinAspectRatio int option,
|
||||
String packageName) {
|
||||
if (option == PackageManager.USER_MIN_ASPECT_RATIO_FULLSCREEN
|
||||
&& !isFullscreenOptionEnabled()) {
|
||||
&& !isFullscreenOptionEnabled(packageName)) {
|
||||
return false;
|
||||
}
|
||||
return mUserAspectRatioMap.containsKey(option);
|
||||
@@ -136,21 +143,26 @@ public class UserAspectRatioManager {
|
||||
* will be overridable.
|
||||
*/
|
||||
public boolean canDisplayAspectRatioUi(@NonNull ApplicationInfo app) {
|
||||
Boolean appAllowsUserAspectRatioOverride = readComponentProperty(
|
||||
mContext.getPackageManager(), app.packageName,
|
||||
PROPERTY_COMPAT_ALLOW_USER_ASPECT_RATIO_OVERRIDE);
|
||||
boolean hasLauncherEntry = mInfoHasLauncherEntryList.stream()
|
||||
.anyMatch(info -> info.activityInfo.packageName.equals(app.packageName));
|
||||
return hasLauncherEntry;
|
||||
return !FALSE.equals(appAllowsUserAspectRatioOverride) && hasLauncherEntry;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether fullscreen option in per-app user aspect ratio settings is enabled
|
||||
*/
|
||||
@VisibleForTesting
|
||||
boolean isFullscreenOptionEnabled() {
|
||||
boolean isFullscreenOptionEnabled(String packageName) {
|
||||
Boolean appAllowsFullscreenOption = readComponentProperty(mContext.getPackageManager(),
|
||||
packageName, PROPERTY_COMPAT_ALLOW_USER_ASPECT_RATIO_FULLSCREEN_OVERRIDE);
|
||||
final boolean isBuildTimeFlagEnabled = mContext.getResources().getBoolean(
|
||||
com.android.internal.R.bool.config_appCompatUserAppAspectRatioFullscreenIsEnabled);
|
||||
return isBuildTimeFlagEnabled && getValueFromDeviceConfig(
|
||||
KEY_ENABLE_USER_ASPECT_RATIO_FULLSCREEN,
|
||||
DEFAULT_VALUE_ENABLE_USER_ASPECT_RATIO_FULLSCREEN);
|
||||
return !FALSE.equals(appAllowsFullscreenOption) && isBuildTimeFlagEnabled
|
||||
&& getValueFromDeviceConfig(KEY_ENABLE_USER_ASPECT_RATIO_FULLSCREEN,
|
||||
DEFAULT_VALUE_ENABLE_USER_ASPECT_RATIO_FULLSCREEN);
|
||||
}
|
||||
|
||||
private static boolean getValueFromDeviceConfig(String name, boolean defaultValue) {
|
||||
@@ -217,6 +229,17 @@ public class UserAspectRatioManager {
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static Boolean readComponentProperty(PackageManager pm, String packageName,
|
||||
String propertyName) {
|
||||
try {
|
||||
return pm.getProperty(propertyName, packageName).getBoolean();
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
// No such property name
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
void addInfoHasLauncherEntry(@NonNull ResolveInfo infoHasLauncherEntry) {
|
||||
mInfoHasLauncherEntryList.add(infoHasLauncherEntry);
|
||||
|
@@ -122,7 +122,7 @@ fun UserAspectRatioAppList(
|
||||
|
||||
data class UserAspectRatioAppListItemModel(
|
||||
override val app: ApplicationInfo,
|
||||
val override: Int,
|
||||
val userOverride: Int,
|
||||
val suggested: Boolean,
|
||||
val canDisplay: Boolean,
|
||||
) : AppRecord
|
||||
@@ -137,7 +137,7 @@ class UserAspectRatioAppListModel(private val context: Context)
|
||||
recordList: List<UserAspectRatioAppListItemModel>
|
||||
): List<SpinnerOption> {
|
||||
val hasSuggested = recordList.any { it.suggested }
|
||||
val hasOverride = recordList.any { it.override != USER_MIN_ASPECT_RATIO_UNSET }
|
||||
val hasOverride = recordList.any { it.userOverride != USER_MIN_ASPECT_RATIO_UNSET }
|
||||
val options = mutableListOf(SpinnerItem.All)
|
||||
// Add suggested filter first as default
|
||||
if (hasSuggested) options.add(0, SpinnerItem.Suggested)
|
||||
@@ -165,7 +165,7 @@ class UserAspectRatioAppListModel(private val context: Context)
|
||||
app = app,
|
||||
suggested = !app.isSystemApp && getPackageAndActivityInfo(
|
||||
app)?.isFixedOrientationOrAspectRatio() == true,
|
||||
override = userAspectRatioManager.getUserMinAspectRatioValue(
|
||||
userOverride = userAspectRatioManager.getUserMinAspectRatioValue(
|
||||
app.packageName, uid),
|
||||
canDisplay = userAspectRatioManager.canDisplayAspectRatioUi(app),
|
||||
)
|
||||
@@ -179,7 +179,7 @@ class UserAspectRatioAppListModel(private val context: Context)
|
||||
): Flow<List<UserAspectRatioAppListItemModel>> = recordListFlow.filterItem(
|
||||
when (SpinnerItem.values().getOrNull(option)) {
|
||||
SpinnerItem.Suggested -> ({ it.canDisplay && it.suggested })
|
||||
SpinnerItem.Overridden -> ({ it.override != USER_MIN_ASPECT_RATIO_UNSET })
|
||||
SpinnerItem.Overridden -> ({ it.userOverride != USER_MIN_ASPECT_RATIO_UNSET })
|
||||
else -> ({ it.canDisplay })
|
||||
}
|
||||
)
|
||||
@@ -187,9 +187,10 @@ class UserAspectRatioAppListModel(private val context: Context)
|
||||
@OptIn(ExperimentalLifecycleComposeApi::class)
|
||||
@Composable
|
||||
override fun getSummary(option: Int, record: UserAspectRatioAppListItemModel) : State<String> =
|
||||
remember(record.override) {
|
||||
remember(record.userOverride) {
|
||||
flow {
|
||||
emit(userAspectRatioManager.getUserMinAspectRatioEntry(record.override))
|
||||
emit(userAspectRatioManager.getUserMinAspectRatioEntry(record.userOverride,
|
||||
record.app.packageName))
|
||||
}.flowOn(Dispatchers.IO)
|
||||
}.collectAsStateWithLifecycle(initialValue = stringResource(R.string.summary_placeholder))
|
||||
|
||||
|
@@ -21,7 +21,8 @@ import android.content.pm.ActivityInfo
|
||||
import android.content.pm.ApplicationInfo
|
||||
import android.content.pm.PackageManager
|
||||
import android.content.pm.ResolveInfo
|
||||
import android.os.Build
|
||||
import android.provider.DeviceConfig.NAMESPACE_WINDOW_MANAGER
|
||||
import android.view.WindowManager.PROPERTY_COMPAT_ALLOW_USER_ASPECT_RATIO_OVERRIDE
|
||||
import androidx.compose.runtime.CompositionLocalProvider
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.test.assertIsDisplayed
|
||||
@@ -34,15 +35,13 @@ import androidx.compose.ui.test.performClick
|
||||
import androidx.test.core.app.ApplicationProvider
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import com.android.dx.mockito.inline.extended.ExtendedMockito
|
||||
import android.provider.DeviceConfig.NAMESPACE_WINDOW_MANAGER
|
||||
import com.android.settings.R
|
||||
import com.android.settings.applications.appinfo.AppInfoDashboardFragment
|
||||
import com.android.settings.applications.appcompat.UserAspectRatioDetails
|
||||
import com.android.settings.applications.appcompat.UserAspectRatioManager
|
||||
import com.android.settings.applications.appinfo.AppInfoDashboardFragment
|
||||
import com.android.settings.spa.app.appinfo.AppInfoSettingsProvider
|
||||
import com.android.settings.testutils.TestDeviceConfig
|
||||
import com.android.settingslib.spa.testutils.delay
|
||||
import com.android.settingslib.spa.testutils.waitUntilExists
|
||||
import org.junit.After
|
||||
import org.junit.Before
|
||||
import org.junit.Rule
|
||||
@@ -51,8 +50,6 @@ import org.junit.runner.RunWith
|
||||
import org.mockito.Mock
|
||||
import org.mockito.Mockito.any
|
||||
import org.mockito.Mockito.anyInt
|
||||
import org.mockito.Mockito.eq
|
||||
import org.mockito.Mockito.mock
|
||||
import org.mockito.MockitoSession
|
||||
import org.mockito.Spy
|
||||
import org.mockito.quality.Strictness
|
||||
@@ -77,8 +74,6 @@ class UserAspectRatioAppPreferenceTest {
|
||||
private val aspectRatioEnabledConfig =
|
||||
TestDeviceConfig(NAMESPACE_WINDOW_MANAGER, "enable_app_compat_user_aspect_ratio_settings")
|
||||
|
||||
private lateinit var userAspectRatioManager: UserAspectRatioManager
|
||||
|
||||
@Mock
|
||||
private lateinit var packageManager: PackageManager
|
||||
|
||||
@@ -92,7 +87,6 @@ class UserAspectRatioAppPreferenceTest {
|
||||
.startMocking()
|
||||
whenever(context.resources).thenReturn(resources)
|
||||
whenever(context.packageManager).thenReturn(packageManager)
|
||||
userAspectRatioManager = mock(UserAspectRatioManager::class.java)
|
||||
}
|
||||
|
||||
@After
|
||||
@@ -130,6 +124,8 @@ class UserAspectRatioAppPreferenceTest {
|
||||
|
||||
@Test
|
||||
fun whenCannotDisplayAspectRatioUiAndConfigTrue_notDisplayed() {
|
||||
// True is ignored but need this here or getBoolean will complain null object
|
||||
mockProperty(PROPERTY_COMPAT_ALLOW_USER_ASPECT_RATIO_OVERRIDE, true)
|
||||
setConfig(true)
|
||||
|
||||
setContent()
|
||||
@@ -139,6 +135,8 @@ class UserAspectRatioAppPreferenceTest {
|
||||
|
||||
@Test
|
||||
fun whenCanDisplayAspectRatioUiAndConfigTrue_Displayed() {
|
||||
// True is ignored but need this here or getBoolean will complain null object
|
||||
mockProperty(PROPERTY_COMPAT_ALLOW_USER_ASPECT_RATIO_OVERRIDE, true)
|
||||
setConfig(true)
|
||||
whenever(packageManager.queryIntentActivities(any(), anyInt()))
|
||||
.thenReturn(listOf(RESOLVE_INFO))
|
||||
@@ -155,6 +153,8 @@ class UserAspectRatioAppPreferenceTest {
|
||||
|
||||
@Test
|
||||
fun onClick_startActivity() {
|
||||
// True is ignored but need this here or getBoolean will complain null object
|
||||
mockProperty(PROPERTY_COMPAT_ALLOW_USER_ASPECT_RATIO_OVERRIDE, true)
|
||||
setConfig(true)
|
||||
whenever(packageManager.queryIntentActivities(any(), anyInt()))
|
||||
.thenReturn(listOf(RESOLVE_INFO))
|
||||
@@ -188,8 +188,14 @@ class UserAspectRatioAppPreferenceTest {
|
||||
composeTestRule.delay()
|
||||
}
|
||||
|
||||
private fun mockProperty(propertyName: String, value: Boolean) {
|
||||
val prop = PackageManager.Property(
|
||||
propertyName, value, PACKAGE_NAME, "" /* className */)
|
||||
whenever(packageManager.getProperty(propertyName, PACKAGE_NAME)).thenReturn(prop)
|
||||
}
|
||||
|
||||
private companion object {
|
||||
const val PACKAGE_NAME = "package.name"
|
||||
const val PACKAGE_NAME = "com.test.mypackage"
|
||||
const val UID = 123
|
||||
val APP = ApplicationInfo().apply {
|
||||
packageName = PACKAGE_NAME
|
||||
|
@@ -154,14 +154,14 @@ class UserAspectRatioAppsPageProviderTest {
|
||||
.isEqualTo(context.getString(R.string.user_aspect_ratio_half_screen))
|
||||
}
|
||||
|
||||
private fun setSummaryState(override: Int): State<String> {
|
||||
private fun setSummaryState(userOverride: Int): State<String> {
|
||||
val listModel = UserAspectRatioAppListModel(context)
|
||||
lateinit var summaryState: State<String>
|
||||
composeTestRule.setContent {
|
||||
summaryState = listModel.getSummary(option = 0,
|
||||
record = UserAspectRatioAppListItemModel(
|
||||
app = APP,
|
||||
override = override,
|
||||
userOverride = userOverride,
|
||||
suggested = false,
|
||||
canDisplay = true,
|
||||
))
|
||||
@@ -182,13 +182,13 @@ class UserAspectRatioAppsPageProviderTest {
|
||||
}
|
||||
private val APP_RECORD_SUGGESTED = UserAspectRatioAppListItemModel(
|
||||
APP,
|
||||
override = USER_MIN_ASPECT_RATIO_UNSET,
|
||||
userOverride = USER_MIN_ASPECT_RATIO_UNSET,
|
||||
suggested = true,
|
||||
canDisplay = true
|
||||
)
|
||||
private val APP_RECORD_NOT_DISPLAYED = UserAspectRatioAppListItemModel(
|
||||
APP,
|
||||
override = USER_MIN_ASPECT_RATIO_UNSET,
|
||||
userOverride = USER_MIN_ASPECT_RATIO_UNSET,
|
||||
suggested = true,
|
||||
canDisplay = false
|
||||
)
|
||||
|
@@ -22,6 +22,8 @@ import static android.content.pm.PackageManager.USER_MIN_ASPECT_RATIO_4_3;
|
||||
import static android.content.pm.PackageManager.USER_MIN_ASPECT_RATIO_FULLSCREEN;
|
||||
import static android.content.pm.PackageManager.USER_MIN_ASPECT_RATIO_SPLIT_SCREEN;
|
||||
import static android.content.pm.PackageManager.USER_MIN_ASPECT_RATIO_UNSET;
|
||||
import static android.view.WindowManager.PROPERTY_COMPAT_ALLOW_USER_ASPECT_RATIO_FULLSCREEN_OVERRIDE;
|
||||
import static android.view.WindowManager.PROPERTY_COMPAT_ALLOW_USER_ASPECT_RATIO_OVERRIDE;
|
||||
|
||||
import static com.android.settings.applications.appcompat.UserAspectRatioManager.KEY_ENABLE_USER_ASPECT_RATIO_FULLSCREEN;
|
||||
import static com.android.settings.applications.appcompat.UserAspectRatioManager.KEY_ENABLE_USER_ASPECT_RATIO_SETTINGS;
|
||||
@@ -37,6 +39,7 @@ import static org.mockito.Mockito.when;
|
||||
import android.content.Context;
|
||||
import android.content.pm.ActivityInfo;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.content.res.Resources;
|
||||
import android.provider.DeviceConfig;
|
||||
@@ -63,12 +66,13 @@ public class UserAspectRatioManagerTest {
|
||||
private UserAspectRatioManager mUtils;
|
||||
private String mOriginalSettingsFlag;
|
||||
private String mOriginalFullscreenFlag;
|
||||
private String mPackageName = "com.test.mypackage";
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mContext = spy(ApplicationProvider.getApplicationContext());
|
||||
mResources = spy(mContext.getResources());
|
||||
mUtils = spy(new UserAspectRatioManager(mContext));
|
||||
mUtils = new UserAspectRatioManager(mContext);
|
||||
|
||||
when(mContext.getResources()).thenReturn(mResources);
|
||||
|
||||
@@ -104,6 +108,29 @@ public class UserAspectRatioManagerTest {
|
||||
assertFalse(mUtils.canDisplayAspectRatioUi(noLauncherEntry));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCanDisplayAspectRatioUi_hasLauncher_propertyFalse_returnFalse()
|
||||
throws PackageManager.NameNotFoundException {
|
||||
mockProperty(PROPERTY_COMPAT_ALLOW_USER_ASPECT_RATIO_OVERRIDE, false);
|
||||
|
||||
final ApplicationInfo canDisplay = new ApplicationInfo();
|
||||
canDisplay.packageName = mPackageName;
|
||||
addResolveInfoLauncherEntry(canDisplay.packageName);
|
||||
|
||||
assertFalse(mUtils.canDisplayAspectRatioUi(canDisplay));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCanDisplayAspectRatioUi_noLauncher_propertyTrue_returnFalse()
|
||||
throws PackageManager.NameNotFoundException {
|
||||
mockProperty(PROPERTY_COMPAT_ALLOW_USER_ASPECT_RATIO_OVERRIDE, true);
|
||||
|
||||
final ApplicationInfo noLauncherEntry = new ApplicationInfo();
|
||||
noLauncherEntry.packageName = mPackageName;
|
||||
|
||||
assertFalse(mUtils.canDisplayAspectRatioUi(noLauncherEntry));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsFeatureEnabled() {
|
||||
assertTrue(UserAspectRatioManager.isFeatureEnabled(mContext));
|
||||
@@ -123,33 +150,56 @@ public class UserAspectRatioManagerTest {
|
||||
|
||||
@Test
|
||||
public void testIsFullscreenOptionEnabled() {
|
||||
assertTrue(mUtils.isFullscreenOptionEnabled());
|
||||
assertTrue(mUtils.isFullscreenOptionEnabled(mPackageName));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsFullscreenOptionEnabled_settingsDisabled_returnFalse() {
|
||||
setAspectRatioFullscreenBuildTimeFlagEnabled(false);
|
||||
assertFalse(mUtils.isFullscreenOptionEnabled());
|
||||
assertFalse(mUtils.isFullscreenOptionEnabled(mPackageName));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsFullscreenOptionEnabled_disabledBuildTimeFlag_returnFalse() {
|
||||
setAspectRatioFullscreenBuildTimeFlagEnabled(false);
|
||||
assertFalse(mUtils.isFullscreenOptionEnabled());
|
||||
assertFalse(mUtils.isFullscreenOptionEnabled(mPackageName));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsFullscreenOptionEnabled_disabledRuntimeFlag_returnFalse() {
|
||||
setAspectRatioFullscreenDeviceConfigEnabled("false" /* enabled */, false /*makeDefault */);
|
||||
assertFalse(mUtils.isFullscreenOptionEnabled());
|
||||
assertFalse(mUtils.isFullscreenOptionEnabled(mPackageName));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void containsAspectRatioOption_fullscreen() {
|
||||
assertTrue(mUtils.containsAspectRatioOption(USER_MIN_ASPECT_RATIO_FULLSCREEN));
|
||||
public void testIsFullscreenOptionEnabled_propertyFalse_returnsFalse()
|
||||
throws PackageManager.NameNotFoundException {
|
||||
mockProperty(PROPERTY_COMPAT_ALLOW_USER_ASPECT_RATIO_FULLSCREEN_OVERRIDE, false);
|
||||
assertFalse(mUtils.isFullscreenOptionEnabled(mPackageName));
|
||||
}
|
||||
|
||||
when(mUtils.isFullscreenOptionEnabled()).thenReturn(false);
|
||||
assertFalse(mUtils.containsAspectRatioOption(USER_MIN_ASPECT_RATIO_FULLSCREEN));
|
||||
@Test
|
||||
public void testIsFullscreenOptionEnabled_propertyTrue_configDisabled_returnsFalse()
|
||||
throws PackageManager.NameNotFoundException {
|
||||
mockProperty(PROPERTY_COMPAT_ALLOW_USER_ASPECT_RATIO_FULLSCREEN_OVERRIDE, true);
|
||||
setAspectRatioFullscreenDeviceConfigEnabled("false" /* enabled */, false /*makeDefault */);
|
||||
|
||||
assertFalse(mUtils.isFullscreenOptionEnabled(mPackageName));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHasAspectRatioOption_fullscreen() {
|
||||
assertTrue(mUtils.hasAspectRatioOption(USER_MIN_ASPECT_RATIO_FULLSCREEN,
|
||||
mPackageName));
|
||||
assertTrue(mUtils.hasAspectRatioOption(USER_MIN_ASPECT_RATIO_SPLIT_SCREEN,
|
||||
mPackageName));
|
||||
|
||||
// Only fullscreen option should be disabled
|
||||
when(mUtils.isFullscreenOptionEnabled(mPackageName)).thenReturn(false);
|
||||
assertFalse(mUtils.hasAspectRatioOption(USER_MIN_ASPECT_RATIO_FULLSCREEN,
|
||||
mPackageName));
|
||||
assertTrue(mUtils.hasAspectRatioOption(USER_MIN_ASPECT_RATIO_SPLIT_SCREEN,
|
||||
mPackageName));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -157,38 +207,47 @@ public class UserAspectRatioManagerTest {
|
||||
// R.string.user_aspect_ratio_app_default
|
||||
final String appDefault = ResourcesUtils.getResourcesString(mContext,
|
||||
"user_aspect_ratio_app_default");
|
||||
assertThat(mUtils.getUserMinAspectRatioEntry(USER_MIN_ASPECT_RATIO_UNSET))
|
||||
assertThat(mUtils.getUserMinAspectRatioEntry(USER_MIN_ASPECT_RATIO_UNSET, mPackageName))
|
||||
.isEqualTo(appDefault);
|
||||
// should always return default if value does not correspond to anything
|
||||
assertThat(mUtils.getUserMinAspectRatioEntry(-1))
|
||||
assertThat(mUtils.getUserMinAspectRatioEntry(-1, mPackageName))
|
||||
.isEqualTo(appDefault);
|
||||
// R.string.user_aspect_ratio_half_screen
|
||||
assertThat(mUtils.getUserMinAspectRatioEntry(USER_MIN_ASPECT_RATIO_SPLIT_SCREEN))
|
||||
.isEqualTo(ResourcesUtils.getResourcesString(mContext,
|
||||
assertThat(mUtils.getUserMinAspectRatioEntry(USER_MIN_ASPECT_RATIO_SPLIT_SCREEN,
|
||||
mPackageName)).isEqualTo(ResourcesUtils.getResourcesString(mContext,
|
||||
"user_aspect_ratio_half_screen"));
|
||||
// R.string.user_aspect_ratio_3_2
|
||||
assertThat(mUtils.getUserMinAspectRatioEntry(USER_MIN_ASPECT_RATIO_3_2))
|
||||
assertThat(mUtils.getUserMinAspectRatioEntry(USER_MIN_ASPECT_RATIO_3_2, mPackageName))
|
||||
.isEqualTo(ResourcesUtils.getResourcesString(mContext, "user_aspect_ratio_3_2"));
|
||||
// R,string.user_aspect_ratio_4_3
|
||||
assertThat(mUtils.getUserMinAspectRatioEntry(USER_MIN_ASPECT_RATIO_4_3))
|
||||
assertThat(mUtils.getUserMinAspectRatioEntry(USER_MIN_ASPECT_RATIO_4_3, mPackageName))
|
||||
.isEqualTo(ResourcesUtils.getResourcesString(mContext, "user_aspect_ratio_4_3"));
|
||||
// R.string.user_aspect_ratio_16_9
|
||||
assertThat(mUtils.getUserMinAspectRatioEntry(USER_MIN_ASPECT_RATIO_16_9))
|
||||
assertThat(mUtils.getUserMinAspectRatioEntry(USER_MIN_ASPECT_RATIO_16_9, mPackageName))
|
||||
.isEqualTo(ResourcesUtils.getResourcesString(mContext, "user_aspect_ratio_16_9"));
|
||||
// R.string.user_aspect_ratio_fullscreen
|
||||
assertThat(mUtils.getUserMinAspectRatioEntry(USER_MIN_ASPECT_RATIO_FULLSCREEN))
|
||||
.isEqualTo(ResourcesUtils.getResourcesString(mContext,
|
||||
assertThat(mUtils.getUserMinAspectRatioEntry(USER_MIN_ASPECT_RATIO_FULLSCREEN,
|
||||
mPackageName)).isEqualTo(ResourcesUtils.getResourcesString(mContext,
|
||||
"user_aspect_ratio_fullscreen"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetUserMinAspectRatioEntry_fullscreenDisabled_shouldReturnDefault() {
|
||||
setAspectRatioFullscreenBuildTimeFlagEnabled(false);
|
||||
assertThat(mUtils.getUserMinAspectRatioEntry(USER_MIN_ASPECT_RATIO_FULLSCREEN))
|
||||
.isEqualTo(ResourcesUtils.getResourcesString(mContext,
|
||||
assertThat(mUtils.getUserMinAspectRatioEntry(USER_MIN_ASPECT_RATIO_FULLSCREEN,
|
||||
mPackageName)).isEqualTo(ResourcesUtils.getResourcesString(mContext,
|
||||
"user_aspect_ratio_app_default"));
|
||||
}
|
||||
|
||||
private void mockProperty(String propertyName, boolean value)
|
||||
throws PackageManager.NameNotFoundException {
|
||||
PackageManager.Property prop = new PackageManager.Property(
|
||||
propertyName, value, mPackageName, "" /* className */);
|
||||
PackageManager pm = mock(PackageManager.class);
|
||||
when(mContext.getPackageManager()).thenReturn(pm);
|
||||
when(pm.getProperty(propertyName, mPackageName)).thenReturn(prop);
|
||||
}
|
||||
|
||||
private void setAspectRatioSettingsBuildTimeFlagEnabled(boolean enabled) {
|
||||
when(mResources.getBoolean(R.bool.config_appCompatUserAppAspectRatioSettingsIsEnabled))
|
||||
.thenReturn(enabled);
|
||||
|
Reference in New Issue
Block a user