diff --git a/core/java/android/hardware/input/IInputManager.aidl b/core/java/android/hardware/input/IInputManager.aidl index 57e84bdb686d1..ead9697854b47 100644 --- a/core/java/android/hardware/input/IInputManager.aidl +++ b/core/java/android/hardware/input/IInputManager.aidl @@ -38,6 +38,8 @@ import android.view.VerifiedInputEvent; /** @hide */ interface IInputManager { + // Gets the current VelocityTracker strategy + String getVelocityTrackerStrategy(); // Gets input device information. InputDevice getInputDevice(int deviceId); int[] getInputDeviceIds(); diff --git a/core/java/android/hardware/input/InputManager.java b/core/java/android/hardware/input/InputManager.java index d8d06531eb2ea..194566dddc475 100644 --- a/core/java/android/hardware/input/InputManager.java +++ b/core/java/android/hardware/input/InputManager.java @@ -273,8 +273,15 @@ public final class InputManager { */ public static final int SWITCH_STATE_ON = 1; + private static String sVelocityTrackerStrategy; + private InputManager(IInputManager im) { mIm = im; + try { + sVelocityTrackerStrategy = mIm.getVelocityTrackerStrategy(); + } catch (RemoteException ex) { + Log.w(TAG, "Could not get VelocityTracker strategy: " + ex); + } } /** @@ -326,6 +333,14 @@ public final class InputManager { } } + /** + * Get the current VelocityTracker strategy. Only works when the system has fully booted up. + * @hide + */ + public String getVelocityTrackerStrategy() { + return sVelocityTrackerStrategy; + } + /** * Gets information about the input device with the specified id. * @param id The device id. diff --git a/core/java/android/view/VelocityTracker.java b/core/java/android/view/VelocityTracker.java index 73322dddfff09..f838d7fed7cf5 100644 --- a/core/java/android/view/VelocityTracker.java +++ b/core/java/android/view/VelocityTracker.java @@ -16,17 +16,10 @@ package android.view; -import static android.Manifest.permission.READ_DEVICE_CONFIG; -import static android.content.pm.PackageManager.PERMISSION_GRANTED; -import static android.provider.DeviceConfig.NAMESPACE_INPUT_NATIVE_BOOT; - import android.annotation.IntDef; -import android.annotation.Nullable; +import android.app.ActivityThread; import android.compat.annotation.UnsupportedAppUsage; import android.os.Build; -import android.os.Process; -import android.permission.PermissionManager; -import android.provider.DeviceConfig; import android.util.ArrayMap; import android.util.Pools.SynchronizedPool; @@ -178,9 +171,6 @@ public final class VelocityTracker { }) public @interface VelocityTrackerStrategy {} - // Feature flag name for the strategy to be used in VelocityTracker - private static final String VELOCITYTRACKER_STRATEGY = "velocitytracker_strategy"; - private long mPtr; @VelocityTrackerStrategy private final int mStrategy; @@ -285,22 +275,13 @@ public final class VelocityTracker { return mStrategy; } - @Nullable - // Read the VelocityTracker strategy property from DeviceConfig - private static String readStrategyProperty() { - if (PermissionManager.checkPermission( - READ_DEVICE_CONFIG, Process.myPid(), Process.myUid()) == PERMISSION_GRANTED) { - return DeviceConfig.getProperty(NAMESPACE_INPUT_NATIVE_BOOT, VELOCITYTRACKER_STRATEGY); - } - // The process using VelocityTracker can't read the config. - return null; - } - private VelocityTracker(@VelocityTrackerStrategy int strategy) { // If user has not selected a specific strategy if (strategy == VELOCITY_TRACKER_STRATEGY_DEFAULT) { + final String strategyProperty = ViewConfiguration.get( + ActivityThread.currentActivityThread().getApplication()) + .getVelocityTrackerStrategy(); // Check if user specified strategy by overriding system property. - final String strategyProperty = readStrategyProperty(); if (strategyProperty == null || strategyProperty.isEmpty()) { mStrategy = strategy; } else { diff --git a/core/java/android/view/ViewConfiguration.java b/core/java/android/view/ViewConfiguration.java index ebc409e470e90..30ae9c826f40e 100644 --- a/core/java/android/view/ViewConfiguration.java +++ b/core/java/android/view/ViewConfiguration.java @@ -27,6 +27,7 @@ import android.content.Context; import android.content.res.Configuration; import android.content.res.Resources; import android.graphics.Rect; +import android.hardware.input.InputManager; import android.os.Build; import android.os.Bundle; import android.os.RemoteException; @@ -348,6 +349,7 @@ public class ViewConfiguration { private final int mSmartSelectionInitializedTimeout; private final int mSmartSelectionInitializingTimeout; private final int mPreferKeepClearForFocusDelay; + private final String mVelocityTrackerStrategy; @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 123768915) private boolean sHasPermanentMenuKey; @@ -394,6 +396,7 @@ public class ViewConfiguration { mSmartSelectionInitializedTimeout = SMART_SELECTION_INITIALIZED_TIMEOUT_IN_MILLISECOND; mSmartSelectionInitializingTimeout = SMART_SELECTION_INITIALIZING_TIMEOUT_IN_MILLISECOND; mPreferKeepClearForFocusDelay = -1; + mVelocityTrackerStrategy = InputManager.getInstance().getVelocityTrackerStrategy(); } /** @@ -510,6 +513,16 @@ public class ViewConfiguration { com.android.internal.R.integer.config_smartSelectionInitializingTimeoutMillis); mPreferKeepClearForFocusDelay = res.getInteger( com.android.internal.R.integer.config_preferKeepClearForFocusDelayMillis); + + mVelocityTrackerStrategy = InputManager.getInstance().getVelocityTrackerStrategy(); + } + + /** + * Get the current VelocityTracker strategy + * @hide + */ + public String getVelocityTrackerStrategy() { + return mVelocityTrackerStrategy; } /** diff --git a/services/core/java/com/android/server/input/InputManagerService.java b/services/core/java/com/android/server/input/InputManagerService.java index 9648844d1354a..f7754e4a4313b 100644 --- a/services/core/java/com/android/server/input/InputManagerService.java +++ b/services/core/java/com/android/server/input/InputManagerService.java @@ -16,6 +16,7 @@ package com.android.server.input; +import static android.provider.DeviceConfig.NAMESPACE_INPUT_NATIVE_BOOT; import static android.view.KeyEvent.KEYCODE_UNKNOWN; import android.annotation.NonNull; @@ -160,6 +161,8 @@ public class InputManagerService extends IInputManager.Stub // Feature flag name for the deep press feature private static final String DEEP_PRESS_ENABLED = "deep_press_enabled"; + // Feature flag name for the strategy to be used in VelocityTracker + private static final String VELOCITYTRACKER_STRATEGY_PROPERTY = "velocitytracker_strategy"; private static final int MSG_DELIVER_INPUT_DEVICES_CHANGED = 1; private static final int MSG_SWITCH_KEYBOARD_LAYOUT = 2; @@ -447,6 +450,8 @@ public class InputManagerService extends IInputManager.Stub public static final int SW_CAMERA_LENS_COVER_BIT = 1 << SW_CAMERA_LENS_COVER; public static final int SW_MUTE_DEVICE_BIT = 1 << SW_MUTE_DEVICE; + private final String mVelocityTrackerStrategy; + /** Whether to use the dev/input/event or uevent subsystem for the audio jack. */ final boolean mUseDevInputEventForAudioJack; @@ -466,6 +471,8 @@ public class InputManagerService extends IInputManager.Stub mDoubleTouchGestureEnableFile = TextUtils.isEmpty(doubleTouchGestureEnablePath) ? null : new File(doubleTouchGestureEnablePath); + mVelocityTrackerStrategy = DeviceConfig.getProperty( + NAMESPACE_INPUT_NATIVE_BOOT, VELOCITYTRACKER_STRATEGY_PROPERTY); LocalServices.addService(InputManagerInternal.class, new LocalService()); } @@ -965,6 +972,11 @@ public class InputManagerService extends IInputManager.Stub return nativeVerifyInputEvent(mPtr, event); } + @Override // Binder call + public String getVelocityTrackerStrategy() { + return mVelocityTrackerStrategy; + } + /** * Gets information about the input device with the specified id. * @param deviceId The device id.