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

Commit 2b03716a authored by Prabir Pradhan's avatar Prabir Pradhan
Browse files

Move stylus hover icon setting to core settings

The secure setting STYLUS_POINTER_ICON_ENABLED needs to be read from
ViewRootImpl, which means it is read in each activity when it starts.

Instead of reading the setting from the app, move it to core settings by
adding it to the CoreSettingsObserver so that the setting is
pre-populated by system_server when the activity starts, eliminating a
settings read in each app launch.

Bug: 324429095
Test: manual with stylus
Change-Id: Ib71a204685a8eb99fe356ea749f7a21614f4a59d
parent cc2959be
Loading
Loading
Loading
Loading
+26 −6
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import android.annotation.NonNull;
import android.annotation.RequiresPermission;
import android.annotation.SuppressLint;
import android.annotation.TestApi;
import android.app.AppGlobals;
import android.content.Context;
import android.os.UserHandle;
import android.provider.Settings;
@@ -393,16 +394,35 @@ public class InputSettings {
     *
     * @hide
     */
    public static boolean isStylusPointerIconEnabled(@NonNull Context context) {
    public static boolean isStylusPointerIconEnabled(@NonNull Context context,
            boolean forceReloadSetting) {
        if (InputProperties.force_enable_stylus_pointer_icon().orElse(false)) {
            // Sysprop override is set
            return true;
        }
        return context.getResources()
                        .getBoolean(com.android.internal.R.bool.config_enableStylusPointerIcon)
                && Settings.Secure.getIntForUser(context.getContentResolver(),
        if (!context.getResources().getBoolean(
                com.android.internal.R.bool.config_enableStylusPointerIcon)) {
            // Stylus pointer icons are disabled for the build
            return false;
        }
        if (forceReloadSetting) {
            return Settings.Secure.getIntForUser(context.getContentResolver(),
                    Settings.Secure.STYLUS_POINTER_ICON_ENABLED,
                    DEFAULT_STYLUS_POINTER_ICON_ENABLED, UserHandle.USER_CURRENT_OR_SELF) != 0;
        }
        return AppGlobals.getIntCoreSetting(Settings.Secure.STYLUS_POINTER_ICON_ENABLED,
                DEFAULT_STYLUS_POINTER_ICON_ENABLED) != 0;
    }

    /**
     * Whether a pointer icon will be shown over the location of a stylus pointer.
     *
     * @hide
     * @see #isStylusPointerIconEnabled(Context, boolean)
     */
    public static boolean isStylusPointerIconEnabled(@NonNull Context context) {
        return isStylusPointerIconEnabled(context, false /* forceReloadSetting */);
    }

    /**
     * Whether Accessibility bounce keys feature is enabled.
+1 −0
Original line number Diff line number Diff line
@@ -80,6 +80,7 @@ final class CoreSettingsObserver extends ContentObserver {
        sSecureSettingToTypeMap.put(Settings.Secure.MULTI_PRESS_TIMEOUT, int.class);
        sSecureSettingToTypeMap.put(Settings.Secure.KEY_REPEAT_TIMEOUT_MS, int.class);
        sSecureSettingToTypeMap.put(Settings.Secure.KEY_REPEAT_DELAY_MS, int.class);
        sSecureSettingToTypeMap.put(Settings.Secure.STYLUS_POINTER_ICON_ENABLED, int.class);
        // add other secure settings here...

        sSystemSettingToTypeMap.put(Settings.System.TIME_12_24, String.class);
+2 −1
Original line number Diff line number Diff line
@@ -258,6 +258,7 @@ class InputSettingsObserver extends ContentObserver {
    }

    private void updateStylusPointerIconEnabled() {
        mNative.setStylusPointerIconEnabled(InputSettings.isStylusPointerIconEnabled(mContext));
        mNative.setStylusPointerIconEnabled(
                InputSettings.isStylusPointerIconEnabled(mContext, true /* forceReloadSetting */));
    }
}