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

Commit 1191ce4d authored by Vania Januar's avatar Vania Januar
Browse files

Implement StylusListener SystemUI CoreStartable.

StylusListener detects first usage of a stylus, and
updates the STYLUS_EVER_USED Settings flag.

Bug: 251206662
DD: go/stylus-first-usage-options
Test: StylusListenerTest
Change-Id: I165481d1166e31b5b8560da5c695003d105068ef
parent 93aba1ca
Loading
Loading
Loading
Loading
+26 −0
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ import android.app.ActivityThread;
import android.compat.annotation.ChangeId;
import android.compat.annotation.UnsupportedAppUsage;
import android.content.Context;
import android.content.pm.PackageManager;
import android.hardware.BatteryState;
import android.hardware.SensorManager;
import android.hardware.lights.Light;
@@ -1893,6 +1894,31 @@ public final class InputManager {
        }
    }

    /**
     * Whether stylus has ever been used on device (false by default).
     * @hide
     */
    public boolean isStylusEverUsed(@NonNull Context context) {
        return Settings.Global.getInt(context.getContentResolver(),
                        Settings.Global.STYLUS_EVER_USED, 0) == 1;
    }

    /**
     * Set whether stylus has ever been used on device.
     * Should only ever be set to true once after stylus first usage.
     * @hide
     */
    @RequiresPermission(Manifest.permission.WRITE_SECURE_SETTINGS)
    public void setStylusEverUsed(@NonNull Context context, boolean stylusEverUsed) {
        if (context.checkCallingPermission(Manifest.permission.WRITE_SECURE_SETTINGS)
                != PackageManager.PERMISSION_GRANTED) {
            throw new SecurityException("You need WRITE_SECURE_SETTINGS permission "
                + "to set stylus ever used.");
        }
        Settings.Global.putInt(context.getContentResolver(),
                Settings.Global.STYLUS_EVER_USED, stylusEverUsed ? 1 : 0);
    }

    /**
     * A callback used to be notified about battery state changes for an input device. The
     * {@link #onBatteryStateChanged(int, long, BatteryState)} method will be called once after the
+9 −0
Original line number Diff line number Diff line
@@ -15787,6 +15787,15 @@ public final class Settings {
        @SuppressLint("NoSettingsProvider")
        public static final String STYLUS_HANDWRITING_ENABLED = "stylus_handwriting_enabled";
        /**
         * Indicates whether a stylus has ever been used on the device.
         *
         * @hide
         */
        @Readable
        @SuppressLint("NoSettingsProvider")
        public static final String STYLUS_EVER_USED = "stylus_ever_used";
        /**
         * Exemptions to the hidden API blacklist.
         *
+1 −0
Original line number Diff line number Diff line
@@ -175,6 +175,7 @@ public class GlobalSettingsValidators {
        VALIDATORS.put(Global.ADVANCED_BATTERY_USAGE_AMOUNT, PERCENTAGE_INTEGER_VALIDATOR);
        VALIDATORS.put(Global.ADAPTIVE_BATTERY_MANAGEMENT_ENABLED, BOOLEAN_VALIDATOR);
        VALIDATORS.put(Global.POWER_BUTTON_LONG_PRESS_DURATION_MS, NONE_NEGATIVE_LONG_VALIDATOR);
        VALIDATORS.put(Global.STYLUS_EVER_USED, BOOLEAN_VALIDATOR);

        VALIDATORS.put(Global.Wearable.HAS_PAY_TOKENS, BOOLEAN_VALIDATOR);
        VALIDATORS.put(Global.Wearable.GMS_CHECKIN_TIMEOUT_MIN, ANY_INTEGER_VALIDATOR);
+1 −0
Original line number Diff line number Diff line
@@ -276,6 +276,7 @@ public class SettingsBackupTest {
                    Settings.Global.SMART_REPLIES_IN_NOTIFICATIONS_FLAGS,
                    Settings.Global.SMART_SUGGESTIONS_IN_NOTIFICATIONS_FLAGS,
                    Settings.Global.STYLUS_HANDWRITING_ENABLED,
                    Settings.Global.STYLUS_EVER_USED,
                    Settings.Global.ENABLE_ADB_INCREMENTAL_INSTALL_DEFAULT,
                    Settings.Global.ENABLE_MULTI_SLOT_TIMEOUT_MILLIS,
                    Settings.Global.ENHANCED_4G_MODE_ENABLED,
+7 −0
Original line number Diff line number Diff line
@@ -55,6 +55,7 @@ import android.hardware.display.ColorDisplayManager;
import android.hardware.display.DisplayManager;
import android.hardware.face.FaceManager;
import android.hardware.fingerprint.FingerprintManager;
import android.hardware.input.InputManager;
import android.media.AudioManager;
import android.media.IAudioService;
import android.media.MediaRouter2Manager;
@@ -282,6 +283,12 @@ public class FrameworkServicesModule {
        return InteractionJankMonitor.getInstance();
    }

    @Provides
    @Singleton
    static InputManager provideInputManager(Context context) {
        return context.getSystemService(InputManager.class);
    }

    @Provides
    @Singleton
    static InputMethodManager provideInputMethodManager(Context context) {
Loading