Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1f1c2a7d authored by Graciela Putri's avatar Graciela Putri Committed by Android (Google) Code Review
Browse files

Merge "[4/n] Add fullscreen option in user aspect ratio settings" into udc-qpr-dev

parents 386b02e9 fa945cc8
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -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 -->
+2 −0
Original line number Diff line number Diff line
@@ -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 -->
+4 −0
Original line number Diff line number Diff line
@@ -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"/>
+7 −0
Original line number Diff line number Diff line
@@ -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);
+34 −9
Original line number Diff line number Diff line
@@ -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:
Loading