diff --git a/services/core/java/com/android/server/input/NativeInputManagerService.java b/services/core/java/com/android/server/input/NativeInputManagerService.java index 325c3089f89a4..6b568b74c4055 100644 --- a/services/core/java/com/android/server/input/NativeInputManagerService.java +++ b/services/core/java/com/android/server/input/NativeInputManagerService.java @@ -16,6 +16,7 @@ package com.android.server.input; +import android.annotation.Nullable; import android.hardware.display.DisplayViewport; import android.hardware.input.InputSensorInfo; import android.hardware.lights.Light; @@ -141,6 +142,13 @@ public interface NativeInputManagerService { int getBatteryStatus(int deviceId); + /** + * Get the device path of the battery for an input device. + * @return the path for the input device battery, or null if there is none. + */ + @Nullable + String getBatteryDevicePath(int deviceId); + List getLights(int deviceId); int getLightPlayerId(int deviceId, int lightId); @@ -326,6 +334,9 @@ public interface NativeInputManagerService { @Override public native int getBatteryStatus(int deviceId); + @Override + public native String getBatteryDevicePath(int deviceId); + @Override public native List getLights(int deviceId); diff --git a/services/core/jni/com_android_server_input_InputManagerService.cpp b/services/core/jni/com_android_server_input_InputManagerService.cpp index 891bc0f06f2c6..78b4ce222dd32 100644 --- a/services/core/jni/com_android_server_input_InputManagerService.cpp +++ b/services/core/jni/com_android_server_input_InputManagerService.cpp @@ -2090,6 +2090,14 @@ static jint nativeGetBatteryStatus(JNIEnv* env, jobject nativeImplObj, jint devi return static_cast(ret.value_or(BATTERY_STATUS_UNKNOWN)); } +static jstring nativeGetBatteryDevicePath(JNIEnv* env, jobject nativeImplObj, jint deviceId) { + NativeInputManager* im = getNativeInputManager(env, nativeImplObj); + + const std::optional batteryPath = + im->getInputManager()->getReader().getBatteryDevicePath(deviceId); + return batteryPath ? env->NewStringUTF(batteryPath->c_str()) : nullptr; +} + static void nativeReloadKeyboardLayouts(JNIEnv* env, jobject nativeImplObj) { NativeInputManager* im = getNativeInputManager(env, nativeImplObj); @@ -2371,6 +2379,7 @@ static const JNINativeMethod gInputManagerMethods[] = { {"setLightColor", "(III)V", (void*)nativeSetLightColor}, {"getBatteryCapacity", "(I)I", (void*)nativeGetBatteryCapacity}, {"getBatteryStatus", "(I)I", (void*)nativeGetBatteryStatus}, + {"getBatteryDevicePath", "(I)Ljava/lang/String;", (void*)nativeGetBatteryDevicePath}, {"reloadKeyboardLayouts", "()V", (void*)nativeReloadKeyboardLayouts}, {"reloadDeviceAliases", "()V", (void*)nativeReloadDeviceAliases}, {"dump", "()Ljava/lang/String;", (void*)nativeDump},