[4/n] Add fullscreen option in user aspect ratio settings
Apps > App Info > Advanced > Aspect ratio Adds fullscreen option to aspect ratio settings gated by fullscreen build time and runtime flags. If fullscreen option is disabled, return app default option. To enable feature: adb shell device_config put window_manager enable_app_compat_user_aspect_ratio_settings true adb shell am force-stop com.android.settings Bug: 291900454 Test: All Settings CUJs passed atest SettingsUnitTests:UserAspectRatioManagerTest Change-Id: I8f8d0c08ac81f088d6c25e8dfb3550f807f336b6
This commit is contained in:
@@ -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:
|
||||
|
Reference in New Issue
Block a user