diff options
| author | 2024-10-22 15:55:02 +0000 | |
|---|---|---|
| committer | 2024-10-22 19:28:07 +0000 | |
| commit | a59f33bdee436df943c7c5dad8c89ce95fc459ab (patch) | |
| tree | 21634adb081d1362625e56eeb441a868ce154f3b | |
| parent | 24a5e6b6338769048d5fd9748b2b6ffa82092588 (diff) | |
InputManagerInternal: Add API to set power/wakeup node
This can be used by other system service to set input device's
wakefulness from kernel sleep state when power policy changes.
DD: go/configure-al-kernel-wake
Bug: 372812925
Test: atest inputflinger_tests
Test: Plug in USB mouse with the set of changes:
power/wakeup of mouse becomes enabled and it can wake
up from "echo mem > /sys/power/state".
Flag: com.android.input.flags.set_input_device_kernel_wake
Change-Id: I2cc9e498c8f6b99f5dd00361f17df8cfd2b9d2cd
4 files changed, 40 insertions, 0 deletions
diff --git a/services/core/java/com/android/server/input/InputManagerInternal.java b/services/core/java/com/android/server/input/InputManagerInternal.java index c888eef7f5df..e40d855293cd 100644 --- a/services/core/java/com/android/server/input/InputManagerInternal.java +++ b/services/core/java/com/android/server/input/InputManagerInternal.java @@ -270,4 +270,18 @@ public abstract class InputManagerInternal { * @param scaleFactor the new scale factor to be applied for pointer icons. */ public abstract void setAccessibilityPointerIconScaleFactor(int displayId, float scaleFactor); + + /** + * Set whether the given input device can wake up the kernel from sleep + * when it generates input events. By default, usually only internal (built-in) + * input devices can wake the kernel from sleep. For an external input device + * that supports remote wakeup to be able to wake the kernel, this must be called + * after each time the device is connected/added. + * + * @param deviceId the device ID of the input device. + * @param enabled When true, device will be configured to wake up kernel. + * + * @return true if setting power wakeup was successful. + */ + public abstract boolean setKernelWakeEnabled(int deviceId, boolean enabled); } diff --git a/services/core/java/com/android/server/input/InputManagerService.java b/services/core/java/com/android/server/input/InputManagerService.java index 98e5319cde30..bea520f9429e 100644 --- a/services/core/java/com/android/server/input/InputManagerService.java +++ b/services/core/java/com/android/server/input/InputManagerService.java @@ -3511,6 +3511,11 @@ public class InputManagerService extends IInputManager.Stub public void setAccessibilityPointerIconScaleFactor(int displayId, float scaleFactor) { InputManagerService.this.setAccessibilityPointerIconScaleFactor(displayId, scaleFactor); } + + @Override + public boolean setKernelWakeEnabled(int deviceId, boolean enabled) { + return mNative.setKernelWakeEnabled(deviceId, enabled); + } } @Override diff --git a/services/core/java/com/android/server/input/NativeInputManagerService.java b/services/core/java/com/android/server/input/NativeInputManagerService.java index 21e8bccd2883..283fdea92b63 100644 --- a/services/core/java/com/android/server/input/NativeInputManagerService.java +++ b/services/core/java/com/android/server/input/NativeInputManagerService.java @@ -287,6 +287,17 @@ interface NativeInputManagerService { */ int getLastUsedInputDeviceId(); + /** + * Set whether the given input device can wake up the kernel from sleep + * when it generates input events. By default, usually only internal (built-in) + * input devices can wake the kernel from sleep. For an external input device + * that supports remote wakeup to be able to wake the kernel, this must be called + * after each time the device is connected/added. + * + * Returns true if setting power wakeup was successful. + */ + boolean setKernelWakeEnabled(int deviceId, boolean enabled); + /** The native implementation of InputManagerService methods. */ class NativeImpl implements NativeInputManagerService { /** Pointer to native input manager service object, used by native code. */ @@ -573,5 +584,8 @@ interface NativeInputManagerService { @Override public native int getLastUsedInputDeviceId(); + + @Override + public native boolean setKernelWakeEnabled(int deviceId, boolean enabled); } } diff --git a/services/core/jni/com_android_server_input_InputManagerService.cpp b/services/core/jni/com_android_server_input_InputManagerService.cpp index 248ed1a58b75..416e60f06c06 100644 --- a/services/core/jni/com_android_server_input_InputManagerService.cpp +++ b/services/core/jni/com_android_server_input_InputManagerService.cpp @@ -3056,6 +3056,12 @@ static void nativeSetMouseSwapPrimaryButtonEnabled(JNIEnv* env, jobject nativeIm im->setMouseSwapPrimaryButtonEnabled(enabled); } +static jboolean nativeSetKernelWakeEnabled(JNIEnv* env, jobject nativeImplObj, jint deviceId, + jboolean enabled) { + NativeInputManager* im = getNativeInputManager(env, nativeImplObj); + return im->getInputManager()->getReader().setKernelWakeEnabled(deviceId, enabled); +} + // ---------------------------------------------------------------------------- static const JNINativeMethod gInputManagerMethods[] = { @@ -3172,6 +3178,7 @@ static const JNINativeMethod gInputManagerMethods[] = { (void*)nativeSetAccessibilityStickyKeysEnabled}, {"setInputMethodConnectionIsActive", "(Z)V", (void*)nativeSetInputMethodConnectionIsActive}, {"getLastUsedInputDeviceId", "()I", (void*)nativeGetLastUsedInputDeviceId}, + {"setKernelWakeEnabled", "(IZ)Z", (void*)nativeSetKernelWakeEnabled}, }; #define FIND_CLASS(var, className) \ |