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

Commit 6917110a authored by ryanlwlin's avatar ryanlwlin
Browse files

Set default value of A11y magnification capabilities

We set magnification capabilities all by default, but if the user
is using full-screen magnification before migration, we will set it to
full-screen.If the above situation happens, we show a prompt dialog to
inform theuser the new feature when using full-screen magnification
first time.

Note the default value will be applied if the user erases all datas.

Test: 1. Enable/Disalbe full-screen magnification and observe
         the values after flashing.
      2. Erase all datas and observes the settings values.
      atest SettingsBackupTest
Bug: 162525393
Change-Id: I3dc749c2414f3aa9162c0f2a31b512c5e6a3ae80
parent 8c213752
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -9127,6 +9127,15 @@ public final class Settings {
        public static final String ACCESSIBILITY_MAGNIFICATION_CAPABILITY =
                "accessibility_magnification_capability";
        /**
         *  Whether to show the window magnification prompt dialog when the user uses full-screen
         *  magnification first time after database is upgraded .
         *
         * @hide
         */
        public static final String ACCESSIBILITY_SHOW_WINDOW_MAGNIFICATION_PROMPT =
                "accessibility_show_window_magnification_prompt";
        /**
         * Whether the Adaptive connectivity option is enabled.
         *
+3 −0
Original line number Diff line number Diff line
@@ -240,4 +240,7 @@

    <!-- Default for setting for Settings.Global.HDMI_CONTROL_AUTO_DEVICE_OFF_ENABLED -->
    <bool name="def_hdmiControlAutoDeviceOff">false</bool>

    <!-- Default for Settings.Secure.ACCESSIBILITY_MAGNIFICATION_CAPABILITY -->
    <integer name="def_accessibility_magnification_capabilities">3</integer>
</resources>
+71 −1
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_2BUTTON_OVE
import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_GESTURAL;
import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_GESTURAL_OVERLAY;

import static com.android.internal.accessibility.AccessibilityShortcutController.MAGNIFICATION_CONTROLLER_NAME;
import static com.android.providers.settings.SettingsState.FALLBACK_FILE_SUFFIX;

import android.Manifest;
@@ -3341,7 +3342,7 @@ public class SettingsProvider extends ContentProvider {
        }

        private final class UpgradeController {
            private static final int SETTINGS_VERSION = 192;
            private static final int SETTINGS_VERSION = 193;

            private final int mUserId;

@@ -4724,6 +4725,35 @@ public class SettingsProvider extends ContentProvider {
                    currentVersion = 192;
                }

                if (currentVersion == 192) {
                    // Version 192: set the default value for magnification capabilities. If
                    // magnification is enabled by the user, set it to full-screen, and set a value
                    // to show a prompt when using the magnification first time after upgrading.
                    final SettingsState secureSettings = getSecureSettingsLocked(userId);
                    final Setting magnificationCapabilities = secureSettings.getSettingLocked(
                            Secure.ACCESSIBILITY_MAGNIFICATION_CAPABILITY);
                    if (magnificationCapabilities.isNull()) {
                        secureSettings.insertSettingLocked(
                                Secure.ACCESSIBILITY_MAGNIFICATION_CAPABILITY,
                                String.valueOf(getContext().getResources().getInteger(
                                        R.integer.def_accessibility_magnification_capabilities)),
                                null, true, SettingsState.SYSTEM_PACKAGE_NAME);

                        if (isMagnificationSettingsOn(secureSettings)) {
                            secureSettings.insertSettingLocked(
                                    Secure.ACCESSIBILITY_MAGNIFICATION_CAPABILITY, String.valueOf(
                                            Secure.ACCESSIBILITY_MAGNIFICATION_MODE_FULLSCREEN),
                                    null, false  /* makeDefault */,
                                    SettingsState.SYSTEM_PACKAGE_NAME);
                            secureSettings.insertSettingLocked(
                                    Secure.ACCESSIBILITY_SHOW_WINDOW_MAGNIFICATION_PROMPT, "1",
                                    null, false /* makeDefault */,
                                    SettingsState.SYSTEM_PACKAGE_NAME);
                        }
                    }
                    currentVersion = 193;
                }

                // vXXX: Add new settings above this point.

                if (currentVersion != newVersion) {
@@ -4862,5 +4892,45 @@ public class SettingsProvider extends ContentProvider {
                }
            }
        }

        private boolean isMagnificationSettingsOn(SettingsState secureSettings) {
            if ("1".equals(secureSettings.getSettingLocked(
                    Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED).getValue())) {
                return true;
            }

            final Set<String> a11yButtonTargets = transformColonDelimitedStringToSet(
                    secureSettings.getSettingLocked(
                            Secure.ACCESSIBILITY_BUTTON_TARGETS).getValue());
            if (a11yButtonTargets != null && a11yButtonTargets.contains(
                    MAGNIFICATION_CONTROLLER_NAME)) {
                return true;
            }

            final Set<String> a11yShortcutServices = transformColonDelimitedStringToSet(
                    secureSettings.getSettingLocked(
                            Secure.ACCESSIBILITY_SHORTCUT_TARGET_SERVICE).getValue());
            if (a11yShortcutServices != null && a11yShortcutServices.contains(
                    MAGNIFICATION_CONTROLLER_NAME)) {
                return true;
            }
            return false;
        }

        @Nullable
        private Set<String> transformColonDelimitedStringToSet(String value) {
            if (TextUtils.isEmpty(value)) return null;
            final TextUtils.SimpleStringSplitter splitter = new TextUtils.SimpleStringSplitter(':');
            splitter.setString(value);
            final Set<String> items = new HashSet<>();
            while (splitter.hasNext()) {
                final String str = splitter.next();
                if (TextUtils.isEmpty(str)) {
                    continue;
                }
                items.add(str);
            }
            return items;
        }
    }
}
+2 −1
Original line number Diff line number Diff line
@@ -747,7 +747,8 @@ public class SettingsBackupTest {
                 Settings.Secure.WINDOW_MAGNIFICATION,
                 Settings.Secure.ACCESSIBILITY_SHORTCUT_TARGET_MAGNIFICATION_CONTROLLER,
                 Settings.Secure.SUPPRESS_DOZE,
                 Settings.Secure.REDUCE_BRIGHT_COLORS_ACTIVATED);
                 Settings.Secure.REDUCE_BRIGHT_COLORS_ACTIVATED,
                 Settings.Secure.ACCESSIBILITY_SHOW_WINDOW_MAGNIFICATION_PROMPT);

    @Test
    public void systemSettingsBackedUpOrDenied() {