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

Commit 9e139179 authored by Nikita Dubrovsky's avatar Nikita Dubrovsky
Browse files

Allow setting defaults for DeviceConfig flags plumbed via settings

Bug: 149790259
Test: Manually
Change-Id: Ie456cf27edab204dfc028023c6364a11b7e5de48
parent ac919b0e
Loading
Loading
Loading
Loading
+14 −7
Original line number Diff line number Diff line
@@ -399,11 +399,14 @@ public class Editor {
                com.android.internal.R.bool.config_enableHapticTextHandle);

        mFlagCursorDragFromAnywhereEnabled = AppGlobals.getIntCoreSetting(
                WidgetFlags.KEY_ENABLE_CURSOR_DRAG_FROM_ANYWHERE , 1) != 0;
                WidgetFlags.KEY_ENABLE_CURSOR_DRAG_FROM_ANYWHERE,
                WidgetFlags.ENABLE_CURSOR_DRAG_FROM_ANYWHERE_DEFAULT ? 1 : 0) != 0;
        mFlagInsertionHandleGesturesEnabled = AppGlobals.getIntCoreSetting(
                WidgetFlags.KEY_ENABLE_INSERTION_HANDLE_GESTURES , 0) != 0;
                WidgetFlags.KEY_ENABLE_INSERTION_HANDLE_GESTURES,
                WidgetFlags.ENABLE_INSERTION_HANDLE_GESTURES_DEFAULT ? 1 : 0) != 0;
        mNewMagnifierEnabled = AppGlobals.getIntCoreSetting(
                WidgetFlags.KEY_ENABLE_NEW_MAGNIFIER, 0) != 0;
                WidgetFlags.KEY_ENABLE_NEW_MAGNIFIER,
                WidgetFlags.ENABLE_NEW_MAGNIFIER_DEFAULT ? 1 : 0) != 0;
        if (TextView.DEBUG_CURSOR) {
            logCursor("Editor", "Cursor drag from anywhere is %s.",
                    mFlagCursorDragFromAnywhereEnabled ? "enabled" : "disabled");
@@ -453,9 +456,11 @@ public class Editor {
        // TODO: supports changing the height/width dynamically because the text height can be
        // dynamically changed.
        float zoom = AppGlobals.getFloatCoreSetting(
                WidgetFlags.KEY_MAGNIFIER_ZOOM_FACTOR, 1.5f);
                WidgetFlags.KEY_MAGNIFIER_ZOOM_FACTOR,
                WidgetFlags.MAGNIFIER_ZOOM_FACTOR_DEFAULT);
        float aspectRatio = AppGlobals.getFloatCoreSetting(
                WidgetFlags.KEY_MAGNIFIER_ASPECT_RATIO, 5.5f);
                WidgetFlags.KEY_MAGNIFIER_ASPECT_RATIO,
                WidgetFlags.MAGNIFIER_ASPECT_RATIO_DEFAULT);
        // Avoid invalid/unsupported values.
        if (zoom < 1.2f || zoom > 1.8f) {
            zoom = 1.5f;
@@ -5271,9 +5276,11 @@ public class Editor {
            int opacity = 255;
            if (mFlagInsertionHandleGesturesEnabled) {
                deltaHeight = AppGlobals.getIntCoreSetting(
                        WidgetFlags.KEY_INSERTION_HANDLE_DELTA_HEIGHT, 25);
                        WidgetFlags.KEY_INSERTION_HANDLE_DELTA_HEIGHT,
                        WidgetFlags.INSERTION_HANDLE_DELTA_HEIGHT_DEFAULT);
                opacity = AppGlobals.getIntCoreSetting(
                        WidgetFlags.KEY_INSERTION_HANDLE_OPACITY, 50);
                        WidgetFlags.KEY_INSERTION_HANDLE_OPACITY,
                        WidgetFlags.INSERTION_HANDLE_OPACITY_DEFAULT);
                // Avoid invalid/unsupported values.
                if (deltaHeight < -25 || deltaHeight > 50) {
                    deltaHeight = 25;
+36 −4
Original line number Diff line number Diff line
@@ -35,6 +35,11 @@ public final class WidgetFlags {
    public static final String KEY_ENABLE_CURSOR_DRAG_FROM_ANYWHERE =
            "widget__enable_cursor_drag_from_anywhere";

    /**
     * Default value for the flag {@link #ENABLE_CURSOR_DRAG_FROM_ANYWHERE}.
     */
    public static final boolean ENABLE_CURSOR_DRAG_FROM_ANYWHERE_DEFAULT = true;

    /**
     * Whether additional gestures should be enabled for the insertion cursor handle (e.g.
     * long-press or double-tap on the handle to trigger selection).
@@ -48,9 +53,13 @@ public final class WidgetFlags {
    public static final String KEY_ENABLE_INSERTION_HANDLE_GESTURES =
            "widget__enable_insertion_handle_gestures";

    /**
     * Default value for the flag {@link #ENABLE_INSERTION_HANDLE_GESTURES}.
     */
    public static final boolean ENABLE_INSERTION_HANDLE_GESTURES_DEFAULT = false;

    /**
     * The flag of delta height applies to the insertion handle when cursor control flag is enabled.
     * The default value is 25.
     */
    public static final String INSERTION_HANDLE_DELTA_HEIGHT =
            "CursorControlFeature__insertion_handle_delta_height";
@@ -61,9 +70,14 @@ public final class WidgetFlags {
    public static final String KEY_INSERTION_HANDLE_DELTA_HEIGHT =
            "widget__insertion_handle_delta_height";

    /**
     * Default value for the flag {@link #INSERTION_HANDLE_DELTA_HEIGHT}.
     */
    public static final int INSERTION_HANDLE_DELTA_HEIGHT_DEFAULT = 25;

    /**
     * The flag of opacity applies to the insertion handle when cursor control flag is enabled.
     * The opacity value is in the range of {0..100}. The default value is 50.
     * The opacity value is in the range of {0..100}.
     */
    public static final String INSERTION_HANDLE_OPACITY =
            "CursorControlFeature__insertion_handle_opacity";
@@ -74,6 +88,11 @@ public final class WidgetFlags {
    public static final String KEY_INSERTION_HANDLE_OPACITY =
            "widget__insertion_handle_opacity";

    /**
     * Default value for the flag {@link #INSERTION_HANDLE_OPACITY}.
     */
    public static final int INSERTION_HANDLE_OPACITY_DEFAULT = 50;

    /**
     * The flag of enabling the new magnifier.
     */
@@ -84,9 +103,13 @@ public final class WidgetFlags {
     */
    public static final String KEY_ENABLE_NEW_MAGNIFIER = "widget__enable_new_magnifier";

    /**
     * Default value for the flag {@link #ENABLE_NEW_MAGNIFIER}.
     */
    public static final boolean ENABLE_NEW_MAGNIFIER_DEFAULT = false;

    /**
     * The flag of zoom factor applies to the new magnifier.
     * The default value is 1.5f.
     */
    public static final String MAGNIFIER_ZOOM_FACTOR =
            "CursorControlFeature__magnifier_zoom_factor";
@@ -96,9 +119,13 @@ public final class WidgetFlags {
     */
    public static final String KEY_MAGNIFIER_ZOOM_FACTOR = "widget__magnifier_zoom_factor";

    /**
     * Default value for the flag {@link #MAGNIFIER_ZOOM_FACTOR}.
     */
    public static final float MAGNIFIER_ZOOM_FACTOR_DEFAULT = 1.5f;

    /**
     * The flag of aspect ratio (width/height) applies to the new magnifier.
     * The default value is 5.5f.
     */
    public static final String MAGNIFIER_ASPECT_RATIO =
            "CursorControlFeature__magnifier_aspect_ratio";
@@ -108,6 +135,11 @@ public final class WidgetFlags {
     */
    public static final String KEY_MAGNIFIER_ASPECT_RATIO = "widget__magnifier_aspect_ratio";

    /**
     * Default value for the flag {@link #MAGNIFIER_ASPECT_RATIO}.
     */
    public static final float MAGNIFIER_ASPECT_RATIO_DEFAULT = 5.5f;

    private WidgetFlags() {
    }
}
+42 −23
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.server.am;

import android.annotation.NonNull;
import android.app.ActivityThread;
import android.content.Context;
import android.database.ContentObserver;
@@ -32,6 +33,7 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * Helper class for watching a set of core settings which the framework
@@ -42,16 +44,20 @@ import java.util.Map;
final class CoreSettingsObserver extends ContentObserver {
    private static final String LOG_TAG = CoreSettingsObserver.class.getSimpleName();

    private static class DeviceConfigEntry {
    private static class DeviceConfigEntry<T> {
        String namespace;
        String flag;
        String coreSettingKey;
        Class<?> type;
        DeviceConfigEntry(String namespace, String flag, String coreSettingKey, Class<?> type) {
        Class<T> type;
        T defaultValue;

        DeviceConfigEntry(String namespace, String flag, String coreSettingKey, Class<T> type,
                @NonNull T defaultValue) {
            this.namespace = namespace;
            this.flag = flag;
            this.coreSettingKey = coreSettingKey;
            this.type = type;
            this.defaultValue = Objects.requireNonNull(defaultValue);
        }
    }

@@ -105,27 +111,34 @@ final class CoreSettingsObserver extends ContentObserver {
        sGlobalSettingToTypeMap.put(Settings.Global.GAME_DRIVER_SPHAL_LIBRARIES, String.class);
        // add other global settings here...

        sDeviceConfigEntries.add(new DeviceConfigEntry(
        sDeviceConfigEntries.add(new DeviceConfigEntry<Boolean>(
                DeviceConfig.NAMESPACE_WIDGET, WidgetFlags.ENABLE_CURSOR_DRAG_FROM_ANYWHERE,
                WidgetFlags.KEY_ENABLE_CURSOR_DRAG_FROM_ANYWHERE, boolean.class));
        sDeviceConfigEntries.add(new DeviceConfigEntry(
                WidgetFlags.KEY_ENABLE_CURSOR_DRAG_FROM_ANYWHERE, boolean.class,
                WidgetFlags.ENABLE_CURSOR_DRAG_FROM_ANYWHERE_DEFAULT));
        sDeviceConfigEntries.add(new DeviceConfigEntry<Boolean>(
                DeviceConfig.NAMESPACE_WIDGET, WidgetFlags.ENABLE_INSERTION_HANDLE_GESTURES,
                WidgetFlags.KEY_ENABLE_INSERTION_HANDLE_GESTURES, boolean.class));
        sDeviceConfigEntries.add(new DeviceConfigEntry(
                WidgetFlags.KEY_ENABLE_INSERTION_HANDLE_GESTURES, boolean.class,
                WidgetFlags.ENABLE_INSERTION_HANDLE_GESTURES_DEFAULT));
        sDeviceConfigEntries.add(new DeviceConfigEntry<Integer>(
                DeviceConfig.NAMESPACE_WIDGET, WidgetFlags.INSERTION_HANDLE_DELTA_HEIGHT,
                WidgetFlags.KEY_INSERTION_HANDLE_DELTA_HEIGHT, int.class));
        sDeviceConfigEntries.add(new DeviceConfigEntry(
                WidgetFlags.KEY_INSERTION_HANDLE_DELTA_HEIGHT, int.class,
                WidgetFlags.INSERTION_HANDLE_DELTA_HEIGHT_DEFAULT));
        sDeviceConfigEntries.add(new DeviceConfigEntry<Integer>(
                DeviceConfig.NAMESPACE_WIDGET, WidgetFlags.INSERTION_HANDLE_OPACITY,
                WidgetFlags.KEY_INSERTION_HANDLE_OPACITY, int.class));
        sDeviceConfigEntries.add(new DeviceConfigEntry(
                WidgetFlags.KEY_INSERTION_HANDLE_OPACITY, int.class,
                WidgetFlags.INSERTION_HANDLE_OPACITY_DEFAULT));
        sDeviceConfigEntries.add(new DeviceConfigEntry<Boolean>(
                DeviceConfig.NAMESPACE_WIDGET, WidgetFlags.ENABLE_NEW_MAGNIFIER,
                WidgetFlags.KEY_ENABLE_NEW_MAGNIFIER, boolean.class));
        sDeviceConfigEntries.add(new DeviceConfigEntry(
                WidgetFlags.KEY_ENABLE_NEW_MAGNIFIER, boolean.class,
                WidgetFlags.ENABLE_NEW_MAGNIFIER_DEFAULT));
        sDeviceConfigEntries.add(new DeviceConfigEntry<Float>(
                DeviceConfig.NAMESPACE_WIDGET, WidgetFlags.MAGNIFIER_ZOOM_FACTOR,
                WidgetFlags.KEY_MAGNIFIER_ZOOM_FACTOR, float.class));
        sDeviceConfigEntries.add(new DeviceConfigEntry(
                WidgetFlags.KEY_MAGNIFIER_ZOOM_FACTOR, float.class,
                WidgetFlags.MAGNIFIER_ZOOM_FACTOR_DEFAULT));
        sDeviceConfigEntries.add(new DeviceConfigEntry<Float>(
                DeviceConfig.NAMESPACE_WIDGET, WidgetFlags.MAGNIFIER_ASPECT_RATIO,
                WidgetFlags.KEY_MAGNIFIER_ASPECT_RATIO, float.class));
                WidgetFlags.KEY_MAGNIFIER_ASPECT_RATIO, float.class,
                WidgetFlags.MAGNIFIER_ASPECT_RATIO_DEFAULT));
        // add other device configs here...
    }

@@ -219,23 +232,29 @@ final class CoreSettingsObserver extends ContentObserver {
        }
    }

    @SuppressWarnings("unchecked")
    private void populateSettingsFromDeviceConfig() {
        for (DeviceConfigEntry entry : sDeviceConfigEntries) {
        for (DeviceConfigEntry<?> entry : sDeviceConfigEntries) {
            if (entry.type == String.class) {
                String defaultValue = ((DeviceConfigEntry<String>) entry).defaultValue;
                mCoreSettings.putString(entry.coreSettingKey,
                        DeviceConfig.getString(entry.namespace, entry.flag, ""));
                        DeviceConfig.getString(entry.namespace, entry.flag, defaultValue));
            } else if (entry.type == int.class) {
                int defaultValue = ((DeviceConfigEntry<Integer>) entry).defaultValue;
                mCoreSettings.putInt(entry.coreSettingKey,
                        DeviceConfig.getInt(entry.namespace, entry.flag, 0));
                        DeviceConfig.getInt(entry.namespace, entry.flag, defaultValue));
            } else if (entry.type == float.class) {
                float defaultValue = ((DeviceConfigEntry<Float>) entry).defaultValue;
                mCoreSettings.putFloat(entry.coreSettingKey,
                        DeviceConfig.getFloat(entry.namespace, entry.flag, 0));
                        DeviceConfig.getFloat(entry.namespace, entry.flag, defaultValue));
            } else if (entry.type == long.class) {
                long defaultValue = ((DeviceConfigEntry<Long>) entry).defaultValue;
                mCoreSettings.putLong(entry.coreSettingKey,
                        DeviceConfig.getLong(entry.namespace, entry.flag, 0));
                        DeviceConfig.getLong(entry.namespace, entry.flag, defaultValue));
            } else if (entry.type == boolean.class) {
                boolean defaultValue = ((DeviceConfigEntry<Boolean>) entry).defaultValue;
                mCoreSettings.putInt(entry.coreSettingKey,
                        DeviceConfig.getBoolean(entry.namespace, entry.flag, false) ? 1 : 0);
                        DeviceConfig.getBoolean(entry.namespace, entry.flag, defaultValue) ? 1 : 0);
            }
        }
    }