Merge "[4/n] Add fullscreen option in user aspect ratio settings" into udc-qpr-dev am: 1f1c2a7db9
Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Settings/+/24213103 Change-Id: Ie0f2338c707cc45dd1cbe57931102bf22df4184a Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -615,6 +615,7 @@
|
||||
length and order as config_userAspectRatioOverrideValues below. -->
|
||||
<string-array name="config_userAspectRatioOverrideEntries" translatable="false">
|
||||
<item>@string/user_aspect_ratio_app_default</item>
|
||||
<item>@string/user_aspect_ratio_fullscreen</item>
|
||||
<item>@string/user_aspect_ratio_half_screen</item>
|
||||
<item>@string/user_aspect_ratio_device_size</item>
|
||||
<item>@string/user_aspect_ratio_16_9</item>
|
||||
@@ -627,6 +628,7 @@
|
||||
correspond to PackageManager.UserMinAspectRatio -->
|
||||
<integer-array name="config_userAspectRatioOverrideValues" translatable="false">
|
||||
<item>0</item> <!-- USER_MIN_ASPECT_RATIO_UNSET -->
|
||||
<item>6</item> <!-- USER_MIN_ASPECT_RATIO_FULLSCREEN -->
|
||||
<item>1</item> <!-- USER_MIN_ASPECT_RATIO_SPLIT_SCREEN -->
|
||||
<item>2</item> <!-- USER_MIN_ASPECT_RATIO_DISPLAY_SIZE -->
|
||||
<item>4</item> <!-- USER_MIN_ASPECT_RATIO_16_9 -->
|
||||
|
@@ -12092,6 +12092,8 @@
|
||||
<string name="user_aspect_ratio_overridden_apps_label">Apps you have overridden</string>
|
||||
<!-- [CHAR LIMIT=NONE] App default aspect ratio entry -->
|
||||
<string name="user_aspect_ratio_app_default">App default</string>
|
||||
<!-- [CHAR LIMIT=NONE] Fullscreen aspect ratio entry -->
|
||||
<string name="user_aspect_ratio_fullscreen">Full screen</string>
|
||||
<!-- [CHAR LIMIT=NONE] Half screen aspect ratio entry -->
|
||||
<string name="user_aspect_ratio_half_screen">Half screen</string>
|
||||
<!-- [CHAR LIMIT=NONE] Device display size aspect ratio entry -->
|
||||
|
@@ -27,6 +27,10 @@
|
||||
android:key="app_default_pref"
|
||||
android:title="@string/user_aspect_ratio_app_default"/>
|
||||
|
||||
<com.android.settingslib.widget.SelectorWithWidgetPreference
|
||||
android:key="fullscreen_pref"
|
||||
android:title="@string/user_aspect_ratio_fullscreen"/>
|
||||
|
||||
<com.android.settingslib.widget.SelectorWithWidgetPreference
|
||||
android:key="half_screen_pref"
|
||||
android:title="@string/user_aspect_ratio_half_screen"/>
|
||||
|
@@ -22,6 +22,7 @@ import static android.content.pm.PackageManager.USER_MIN_ASPECT_RATIO_16_9;
|
||||
import static android.content.pm.PackageManager.USER_MIN_ASPECT_RATIO_3_2;
|
||||
import static android.content.pm.PackageManager.USER_MIN_ASPECT_RATIO_4_3;
|
||||
import static android.content.pm.PackageManager.USER_MIN_ASPECT_RATIO_DISPLAY_SIZE;
|
||||
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;
|
||||
|
||||
@@ -54,6 +55,7 @@ public class UserAspectRatioDetails extends AppInfoWithHeader implements
|
||||
private static final String TAG = UserAspectRatioDetails.class.getSimpleName();
|
||||
|
||||
private static final String KEY_HEADER_BUTTONS = "header_view";
|
||||
private static final String KEY_PREF_FULLSCREEN = "fullscreen_pref";
|
||||
private static final String KEY_PREF_HALF_SCREEN = "half_screen_pref";
|
||||
private static final String KEY_PREF_DISPLAY_SIZE = "display_size_pref";
|
||||
private static final String KEY_PREF_16_9 = "16_9_pref";
|
||||
@@ -140,6 +142,8 @@ public class UserAspectRatioDetails extends AppInfoWithHeader implements
|
||||
@PackageManager.UserMinAspectRatio
|
||||
private int getSelectedUserMinAspectRatio(@NonNull String selectedKey) {
|
||||
switch (selectedKey) {
|
||||
case KEY_PREF_FULLSCREEN:
|
||||
return USER_MIN_ASPECT_RATIO_FULLSCREEN;
|
||||
case KEY_PREF_HALF_SCREEN:
|
||||
return USER_MIN_ASPECT_RATIO_SPLIT_SCREEN;
|
||||
case KEY_PREF_DISPLAY_SIZE:
|
||||
@@ -158,6 +162,8 @@ public class UserAspectRatioDetails extends AppInfoWithHeader implements
|
||||
@NonNull
|
||||
private String getSelectedKey(@PackageManager.UserMinAspectRatio int userMinAspectRatio) {
|
||||
switch (userMinAspectRatio) {
|
||||
case USER_MIN_ASPECT_RATIO_FULLSCREEN:
|
||||
return KEY_PREF_FULLSCREEN;
|
||||
case USER_MIN_ASPECT_RATIO_SPLIT_SCREEN:
|
||||
return KEY_PREF_HALF_SCREEN;
|
||||
case USER_MIN_ASPECT_RATIO_DISPLAY_SIZE:
|
||||
@@ -182,6 +188,7 @@ public class UserAspectRatioDetails extends AppInfoWithHeader implements
|
||||
.setButton1OnClickListener(v -> launchApplication());
|
||||
|
||||
addPreference(KEY_PREF_DEFAULT, USER_MIN_ASPECT_RATIO_UNSET);
|
||||
addPreference(KEY_PREF_FULLSCREEN, USER_MIN_ASPECT_RATIO_FULLSCREEN);
|
||||
addPreference(KEY_PREF_DISPLAY_SIZE, USER_MIN_ASPECT_RATIO_DISPLAY_SIZE);
|
||||
addPreference(KEY_PREF_HALF_SCREEN, USER_MIN_ASPECT_RATIO_SPLIT_SCREEN);
|
||||
addPreference(KEY_PREF_16_9, USER_MIN_ASPECT_RATIO_16_9);
|
||||
|
@@ -50,6 +50,9 @@ public class UserAspectRatioManager {
|
||||
@VisibleForTesting
|
||||
static final String KEY_ENABLE_USER_ASPECT_RATIO_SETTINGS =
|
||||
"enable_app_compat_user_aspect_ratio_settings";
|
||||
static final String KEY_ENABLE_USER_ASPECT_RATIO_FULLSCREEN =
|
||||
"enable_app_compat_user_aspect_ratio_fullscreen";
|
||||
private static final boolean DEFAULT_VALUE_ENABLE_USER_ASPECT_RATIO_FULLSCREEN = true;
|
||||
|
||||
private final Context mContext;
|
||||
private final IPackageManager mIPm;
|
||||
@@ -71,7 +74,8 @@ public class UserAspectRatioManager {
|
||||
public static boolean isFeatureEnabled(Context context) {
|
||||
final boolean isBuildTimeFlagEnabled = context.getResources().getBoolean(
|
||||
com.android.internal.R.bool.config_appCompatUserAppAspectRatioSettingsIsEnabled);
|
||||
return isBuildTimeFlagEnabled && getValueFromDeviceConfig();
|
||||
return getValueFromDeviceConfig(KEY_ENABLE_USER_ASPECT_RATIO_SETTINGS,
|
||||
DEFAULT_VALUE_ENABLE_USER_ASPECT_RATIO_SETTINGS) && isBuildTimeFlagEnabled;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -80,7 +84,9 @@ public class UserAspectRatioManager {
|
||||
@PackageManager.UserMinAspectRatio
|
||||
public int getUserMinAspectRatioValue(@NonNull String packageName, int uid)
|
||||
throws RemoteException {
|
||||
return mIPm.getUserMinAspectRatio(packageName, uid);
|
||||
final int aspectRatio = mIPm.getUserMinAspectRatio(packageName, uid);
|
||||
return containsAspectRatioOption(aspectRatio)
|
||||
? aspectRatio : PackageManager.USER_MIN_ASPECT_RATIO_UNSET;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -88,8 +94,10 @@ public class UserAspectRatioManager {
|
||||
*/
|
||||
@NonNull
|
||||
public String getUserMinAspectRatioEntry(@PackageManager.UserMinAspectRatio int aspectRatio) {
|
||||
return mUserAspectRatioMap.getOrDefault(
|
||||
aspectRatio, mContext.getString(R.string.user_aspect_ratio_app_default));
|
||||
if (!containsAspectRatioOption(aspectRatio)) {
|
||||
return mUserAspectRatioMap.get(PackageManager.USER_MIN_ASPECT_RATIO_UNSET);
|
||||
}
|
||||
return mUserAspectRatioMap.get(aspectRatio);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -105,8 +113,13 @@ public class UserAspectRatioManager {
|
||||
/**
|
||||
* Whether user aspect ratio option is specified in
|
||||
* {@link R.array.config_userAspectRatioOverrideValues}
|
||||
* and is enabled by device config
|
||||
*/
|
||||
public boolean containsAspectRatioOption(@PackageManager.UserMinAspectRatio int option) {
|
||||
if (option == PackageManager.USER_MIN_ASPECT_RATIO_FULLSCREEN
|
||||
&& !isFullscreenOptionEnabled()) {
|
||||
return false;
|
||||
}
|
||||
return mUserAspectRatioMap.containsKey(option);
|
||||
}
|
||||
|
||||
@@ -128,11 +141,20 @@ public class UserAspectRatioManager {
|
||||
return hasLauncherEntry;
|
||||
}
|
||||
|
||||
private static boolean getValueFromDeviceConfig() {
|
||||
return DeviceConfig.getBoolean(
|
||||
DeviceConfig.NAMESPACE_WINDOW_MANAGER,
|
||||
KEY_ENABLE_USER_ASPECT_RATIO_SETTINGS,
|
||||
DEFAULT_VALUE_ENABLE_USER_ASPECT_RATIO_SETTINGS);
|
||||
/**
|
||||
* Whether fullscreen option in per-app user aspect ratio settings is enabled
|
||||
*/
|
||||
@VisibleForTesting
|
||||
boolean isFullscreenOptionEnabled() {
|
||||
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);
|
||||
}
|
||||
|
||||
private static boolean getValueFromDeviceConfig(String name, boolean defaultValue) {
|
||||
return DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_WINDOW_MANAGER, name, defaultValue);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@@ -153,6 +175,7 @@ public class UserAspectRatioManager {
|
||||
userMinAspectRatioStrings[i], aspectRatioVal);
|
||||
switch (aspectRatioVal) {
|
||||
// Only map known values of UserMinAspectRatio and ignore unknown entries
|
||||
case PackageManager.USER_MIN_ASPECT_RATIO_FULLSCREEN:
|
||||
case PackageManager.USER_MIN_ASPECT_RATIO_UNSET:
|
||||
case PackageManager.USER_MIN_ASPECT_RATIO_SPLIT_SCREEN:
|
||||
case PackageManager.USER_MIN_ASPECT_RATIO_DISPLAY_SIZE:
|
||||
@@ -177,6 +200,8 @@ public class UserAspectRatioManager {
|
||||
}
|
||||
// Options are customized per device and if strings are set to @null, use default
|
||||
switch (aspectRatioVal) {
|
||||
case PackageManager.USER_MIN_ASPECT_RATIO_FULLSCREEN:
|
||||
return mContext.getString(R.string.user_aspect_ratio_fullscreen);
|
||||
case PackageManager.USER_MIN_ASPECT_RATIO_SPLIT_SCREEN:
|
||||
return mContext.getString(R.string.user_aspect_ratio_half_screen);
|
||||
case PackageManager.USER_MIN_ASPECT_RATIO_DISPLAY_SIZE:
|
||||
|
@@ -19,9 +19,11 @@ package com.android.settings.applications.appcompat;
|
||||
import static android.content.pm.PackageManager.USER_MIN_ASPECT_RATIO_16_9;
|
||||
import static android.content.pm.PackageManager.USER_MIN_ASPECT_RATIO_3_2;
|
||||
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 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;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
@@ -30,16 +32,19 @@ import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.pm.ActivityInfo;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.content.res.Resources;
|
||||
import android.provider.DeviceConfig;
|
||||
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
|
||||
import com.android.internal.R;
|
||||
import com.android.settings.testutils.ResourcesUtils;
|
||||
|
||||
import org.junit.After;
|
||||
@@ -54,21 +59,35 @@ import org.junit.runner.RunWith;
|
||||
public class UserAspectRatioManagerTest {
|
||||
|
||||
private Context mContext;
|
||||
private Resources mResources;
|
||||
private UserAspectRatioManager mUtils;
|
||||
private String mOriginalFlag;
|
||||
private String mOriginalSettingsFlag;
|
||||
private String mOriginalFullscreenFlag;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mContext = spy(ApplicationProvider.getApplicationContext());
|
||||
mResources = spy(mContext.getResources());
|
||||
mUtils = spy(new UserAspectRatioManager(mContext));
|
||||
mOriginalFlag = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_WINDOW_MANAGER,
|
||||
KEY_ENABLE_USER_ASPECT_RATIO_SETTINGS);
|
||||
|
||||
when(mContext.getResources()).thenReturn(mResources);
|
||||
|
||||
mOriginalSettingsFlag = DeviceConfig.getProperty(
|
||||
DeviceConfig.NAMESPACE_WINDOW_MANAGER, KEY_ENABLE_USER_ASPECT_RATIO_SETTINGS);
|
||||
setAspectRatioSettingsBuildTimeFlagEnabled(true);
|
||||
setAspectRatioSettingsDeviceConfigEnabled("true" /* enabled */, false /* makeDefault */);
|
||||
|
||||
mOriginalFullscreenFlag = DeviceConfig.getProperty(
|
||||
DeviceConfig.NAMESPACE_WINDOW_MANAGER, KEY_ENABLE_USER_ASPECT_RATIO_FULLSCREEN);
|
||||
setAspectRatioFullscreenBuildTimeFlagEnabled(true);
|
||||
setAspectRatioFullscreenDeviceConfigEnabled("true" /* enabled */, false /* makeDefault */);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
DeviceConfig.setProperty(DeviceConfig.NAMESPACE_WINDOW_MANAGER,
|
||||
KEY_ENABLE_USER_ASPECT_RATIO_SETTINGS, mOriginalFlag, true /* makeDefault */);
|
||||
setAspectRatioSettingsDeviceConfigEnabled(mOriginalSettingsFlag, true /* makeDefault */);
|
||||
setAspectRatioFullscreenDeviceConfigEnabled(mOriginalFullscreenFlag,
|
||||
true /* makeDefault */);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -87,13 +106,52 @@ public class UserAspectRatioManagerTest {
|
||||
|
||||
@Test
|
||||
public void testIsFeatureEnabled() {
|
||||
assertFalse(UserAspectRatioManager.isFeatureEnabled(mContext));
|
||||
|
||||
DeviceConfig.setProperty(DeviceConfig.NAMESPACE_WINDOW_MANAGER,
|
||||
KEY_ENABLE_USER_ASPECT_RATIO_SETTINGS, "true", false /* makeDefault */);
|
||||
assertTrue(UserAspectRatioManager.isFeatureEnabled(mContext));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsFeatureEnabled_disabledBuildTimeFlag_returnFalse() {
|
||||
setAspectRatioSettingsBuildTimeFlagEnabled(false);
|
||||
assertFalse(UserAspectRatioManager.isFeatureEnabled(mContext));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsFeatureEnabled_disabledRuntimeFlag_returnFalse() {
|
||||
setAspectRatioSettingsDeviceConfigEnabled("false" /* enabled */, false /* makeDefault */);
|
||||
assertFalse(UserAspectRatioManager.isFeatureEnabled(mContext));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsFullscreenOptionEnabled() {
|
||||
assertTrue(mUtils.isFullscreenOptionEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsFullscreenOptionEnabled_settingsDisabled_returnFalse() {
|
||||
setAspectRatioFullscreenBuildTimeFlagEnabled(false);
|
||||
assertFalse(mUtils.isFullscreenOptionEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsFullscreenOptionEnabled_disabledBuildTimeFlag_returnFalse() {
|
||||
setAspectRatioFullscreenBuildTimeFlagEnabled(false);
|
||||
assertFalse(mUtils.isFullscreenOptionEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsFullscreenOptionEnabled_disabledRuntimeFlag_returnFalse() {
|
||||
setAspectRatioFullscreenDeviceConfigEnabled("false" /* enabled */, false /*makeDefault */);
|
||||
assertFalse(mUtils.isFullscreenOptionEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void containsAspectRatioOption_fullscreen() {
|
||||
assertTrue(mUtils.containsAspectRatioOption(USER_MIN_ASPECT_RATIO_FULLSCREEN));
|
||||
|
||||
when(mUtils.isFullscreenOptionEnabled()).thenReturn(false);
|
||||
assertFalse(mUtils.containsAspectRatioOption(USER_MIN_ASPECT_RATIO_FULLSCREEN));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetUserMinAspectRatioEntry() {
|
||||
// R.string.user_aspect_ratio_app_default
|
||||
@@ -117,6 +175,38 @@ public class UserAspectRatioManagerTest {
|
||||
// R.string.user_aspect_ratio_16_9
|
||||
assertThat(mUtils.getUserMinAspectRatioEntry(USER_MIN_ASPECT_RATIO_16_9))
|
||||
.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,
|
||||
"user_aspect_ratio_fullscreen"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetUserMinAspectRatioEntry_fullscreenDisabled_shouldReturnDefault() {
|
||||
setAspectRatioFullscreenBuildTimeFlagEnabled(false);
|
||||
assertThat(mUtils.getUserMinAspectRatioEntry(USER_MIN_ASPECT_RATIO_FULLSCREEN))
|
||||
.isEqualTo(ResourcesUtils.getResourcesString(mContext,
|
||||
"user_aspect_ratio_app_default"));
|
||||
}
|
||||
|
||||
private void setAspectRatioSettingsBuildTimeFlagEnabled(boolean enabled) {
|
||||
when(mResources.getBoolean(R.bool.config_appCompatUserAppAspectRatioSettingsIsEnabled))
|
||||
.thenReturn(enabled);
|
||||
}
|
||||
|
||||
private void setAspectRatioSettingsDeviceConfigEnabled(String enabled, boolean makeDefault) {
|
||||
DeviceConfig.setProperty(DeviceConfig.NAMESPACE_WINDOW_MANAGER,
|
||||
KEY_ENABLE_USER_ASPECT_RATIO_SETTINGS, enabled, makeDefault);
|
||||
}
|
||||
|
||||
private void setAspectRatioFullscreenBuildTimeFlagEnabled(boolean enabled) {
|
||||
when(mResources.getBoolean(R.bool.config_appCompatUserAppAspectRatioFullscreenIsEnabled))
|
||||
.thenReturn(enabled);
|
||||
}
|
||||
|
||||
private void setAspectRatioFullscreenDeviceConfigEnabled(String enabled, boolean makeDefault) {
|
||||
DeviceConfig.setProperty(DeviceConfig.NAMESPACE_WINDOW_MANAGER,
|
||||
KEY_ENABLE_USER_ASPECT_RATIO_FULLSCREEN, enabled, makeDefault);
|
||||
}
|
||||
|
||||
private void addResolveInfoLauncherEntry(String packageName) {
|
||||
|
Reference in New Issue
Block a user