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
This commit is contained in:
Vania Januar
2022-09-21 15:47:55 +01:00
parent 93aba1ca57
commit 1191ce4d2c
6 changed files with 47 additions and 0 deletions

View File

@@ -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

View File

@@ -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.
*

View File

@@ -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);

View File

@@ -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,

View File

@@ -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) {

View File

@@ -412,6 +412,9 @@ object Flags {
@JvmField val UDFPS_ELLIPSE_DEBUG_UI = unreleasedFlag(2201, "udfps_ellipse_debug")
@JvmField val UDFPS_ELLIPSE_DETECTION = unreleasedFlag(2202, "udfps_ellipse_detection")
// 2300 - stylus
@JvmField val TRACK_STYLUS_EVER_USED = unreleasedFlag(2300, "track_stylus_ever_used")
// TODO(b259590361): Tracking bug
val EXPERIMENTAL_FLAG = unreleasedFlag(2, "exp_flag_release")
}