diff options
author | 2025-03-21 15:04:33 +0000 | |
---|---|---|
committer | 2025-03-21 18:54:16 +0000 | |
commit | 36859f9960ed12193ab1fcf508090632e7fa9f19 (patch) | |
tree | 30441171e51bc3ca8e56a8aefaadfe5b653e793a | |
parent | 61977132f3a45eaf4f75879171185ecedc146f61 (diff) |
KeyboardBacklightController: Remove sysfs node change detection
This is now handled by SysfsNodeMonitor.
Bug: 397208968
Test: Presubmit
Flag: EXEMPT bug fix
Change-Id: Ic7c1ed8575a1f332011aa35a207e00c2e0c59133
3 files changed, 5 insertions, 114 deletions
diff --git a/services/core/java/com/android/server/input/InputManagerService.java b/services/core/java/com/android/server/input/InputManagerService.java index 07530e1c6f7b..76284fb81814 100644 --- a/services/core/java/com/android/server/input/InputManagerService.java +++ b/services/core/java/com/android/server/input/InputManagerService.java @@ -510,8 +510,7 @@ public class InputManagerService extends IInputManager.Stub KeyboardBacklightControllerInterface getKeyboardBacklightController( NativeInputManagerService nativeService) { - return new KeyboardBacklightController(mContext, nativeService, mLooper, - mUEventManager); + return new KeyboardBacklightController(mContext, nativeService, mLooper); } } diff --git a/services/core/java/com/android/server/input/KeyboardBacklightController.java b/services/core/java/com/android/server/input/KeyboardBacklightController.java index 16368c7678d1..083c0006ad65 100644 --- a/services/core/java/com/android/server/input/KeyboardBacklightController.java +++ b/services/core/java/com/android/server/input/KeyboardBacklightController.java @@ -32,7 +32,6 @@ import android.os.Looper; import android.os.Message; import android.os.RemoteException; import android.os.SystemClock; -import android.os.UEventObserver; import android.sysprop.InputProperties; import android.text.TextUtils; import android.util.IndentingPrintWriter; @@ -83,8 +82,6 @@ final class KeyboardBacklightController implements private static final long TRANSITION_ANIMATION_DURATION_MILLIS = Duration.ofSeconds(1).toMillis(); - private static final String UEVENT_KEYBOARD_BACKLIGHT_TAG = "kbd_backlight"; - @VisibleForTesting static final int[] DEFAULT_BRIGHTNESS_VALUE_FOR_LEVEL = new int[DEFAULT_NUM_BRIGHTNESS_CHANGE_STEPS + 1]; @@ -93,7 +90,6 @@ final class KeyboardBacklightController implements private final NativeInputManagerService mNative; private final Handler mHandler; private final AnimatorFactory mAnimatorFactory; - private final UEventManager mUEventManager; // Always access on handler thread or need to lock this for synchronization. private final SparseArray<KeyboardBacklightState> mKeyboardBacklights = new SparseArray<>(1); // Maintains state if all backlights should be on or turned off @@ -124,19 +120,18 @@ final class KeyboardBacklightController implements } KeyboardBacklightController(Context context, NativeInputManagerService nativeService, - Looper looper, UEventManager uEventManager) { - this(context, nativeService, looper, ValueAnimator::ofInt, uEventManager); + Looper looper) { + this(context, nativeService, looper, ValueAnimator::ofInt); } @VisibleForTesting KeyboardBacklightController(Context context, NativeInputManagerService nativeService, - Looper looper, AnimatorFactory animatorFactory, UEventManager uEventManager) { + Looper looper, AnimatorFactory animatorFactory) { mContext = context; mNative = nativeService; mHandler = new Handler(looper, this::handleMessage); mAnimatorFactory = animatorFactory; mAmbientController = new AmbientKeyboardBacklightController(context, looper); - mUEventManager = uEventManager; Resources res = mContext.getResources(); mUserInactivityThresholdMs = res.getInteger( com.android.internal.R.integer.config_keyboardBacklightTimeoutMs); @@ -154,17 +149,6 @@ final class KeyboardBacklightController implements inputManager.getInputDeviceIds()); mHandler.sendMessage(msg); - // Observe UEvents for "kbd_backlight" sysfs nodes. - // We want to observe creation of such LED nodes since they might be created after device - // FD created and InputDevice creation logic doesn't initialize LED nodes which leads to - // backlight not working. - mUEventManager.addListener(new UEventManager.UEventListener() { - @Override - public void onUEvent(UEventObserver.UEvent event) { - onKeyboardBacklightUEvent(event); - } - }, UEVENT_KEYBOARD_BACKLIGHT_TAG); - // Start ambient backlight controller mAmbientController.systemRunning(); } @@ -414,17 +398,6 @@ final class KeyboardBacklightController implements } } - @VisibleForTesting - public void onKeyboardBacklightUEvent(UEventObserver.UEvent event) { - if ("ADD".equalsIgnoreCase(event.get("ACTION")) && "LEDS".equalsIgnoreCase( - event.get("SUBSYSTEM"))) { - final String devPath = event.get("DEVPATH"); - if (isValidBacklightNodePath(devPath)) { - mNative.sysfsNodeChanged("/sys" + devPath); - } - } - } - private void updateAmbientLightListener() { boolean needToListenAmbientLightSensor = false; for (int i = 0; i < mKeyboardBacklights.size(); i++) { diff --git a/tests/Input/src/com/android/server/input/KeyboardBacklightControllerTests.kt b/tests/Input/src/com/android/server/input/KeyboardBacklightControllerTests.kt index cf09b54753b0..a0cf88809af4 100644 --- a/tests/Input/src/com/android/server/input/KeyboardBacklightControllerTests.kt +++ b/tests/Input/src/com/android/server/input/KeyboardBacklightControllerTests.kt @@ -26,7 +26,6 @@ import android.hardware.input.IKeyboardBacklightState import android.hardware.input.InputManager import android.hardware.lights.Light import android.os.SystemProperties -import android.os.UEventObserver import android.os.test.TestLooper import android.platform.test.annotations.Presubmit import android.util.TypedValue @@ -98,14 +97,12 @@ class KeyboardBacklightControllerTests { @get:Rule val inputManagerRule = MockInputManagerRule() @Mock private lateinit var native: NativeInputManagerService - @Mock private lateinit var uEventManager: UEventManager @Mock private lateinit var resources: Resources private lateinit var keyboardBacklightController: KeyboardBacklightController private lateinit var context: Context private lateinit var testLooper: TestLooper private var lightColorMap: HashMap<Int, Int> = HashMap() private var lastBacklightState: KeyboardBacklightState? = null - private var sysfsNodeChanges = 0 private var lastAnimationValues = IntArray(2) @Before @@ -126,7 +123,6 @@ class KeyboardBacklightControllerTests { lightColorMap.getOrDefault(args[1] as Int, 0) } lightColorMap.clear() - `when`(native.sysfsNodeChanged(any())).then { sysfsNodeChanges++ } } private fun setupConfig() { @@ -158,13 +154,7 @@ class KeyboardBacklightControllerTests { private fun setupController() { keyboardBacklightController = - KeyboardBacklightController( - context, - native, - testLooper.looper, - FakeAnimatorFactory(), - uEventManager, - ) + KeyboardBacklightController(context, native, testLooper.looper, FakeAnimatorFactory()) } @Test @@ -318,77 +308,6 @@ class KeyboardBacklightControllerTests { } @Test - fun testKeyboardBacklightSysfsNodeAdded_AfterInputDeviceAdded() { - setupController() - var counter = sysfsNodeChanges - keyboardBacklightController.onKeyboardBacklightUEvent( - UEventObserver.UEvent( - "ACTION=add\u0000SUBSYSTEM=leds\u0000DEVPATH=/xyz/leds/abc::no_backlight\u0000" - ) - ) - assertEquals( - "Should not reload sysfs node if UEvent path doesn't contain kbd_backlight", - counter, - sysfsNodeChanges, - ) - - keyboardBacklightController.onKeyboardBacklightUEvent( - UEventObserver.UEvent( - "ACTION=add\u0000SUBSYSTEM=power\u0000DEVPATH=/xyz/leds/abc::kbd_backlight\u0000" - ) - ) - assertEquals( - "Should not reload sysfs node if UEvent doesn't belong to subsystem LED", - counter, - sysfsNodeChanges, - ) - - keyboardBacklightController.onKeyboardBacklightUEvent( - UEventObserver.UEvent( - "ACTION=remove\u0000SUBSYSTEM=leds\u0000DEVPATH=/xyz/leds/abc::kbd_backlight\u0000" - ) - ) - assertEquals( - "Should not reload sysfs node if UEvent doesn't have ACTION(add)", - counter, - sysfsNodeChanges, - ) - - keyboardBacklightController.onKeyboardBacklightUEvent( - UEventObserver.UEvent( - "ACTION=add\u0000SUBSYSTEM=leds\u0000DEVPATH=/xyz/pqr/abc::kbd_backlight\u0000" - ) - ) - assertEquals( - "Should not reload sysfs node if UEvent path doesn't belong to leds/ directory", - counter, - sysfsNodeChanges, - ) - - keyboardBacklightController.onKeyboardBacklightUEvent( - UEventObserver.UEvent( - "ACTION=add\u0000SUBSYSTEM=leds\u0000DEVPATH=/xyz/leds/abc::kbd_backlight\u0000" - ) - ) - assertEquals( - "Should reload sysfs node if a valid Keyboard backlight LED UEvent occurs", - ++counter, - sysfsNodeChanges, - ) - - keyboardBacklightController.onKeyboardBacklightUEvent( - UEventObserver.UEvent( - "ACTION=add\u0000SUBSYSTEM=leds\u0000DEVPATH=/xyz/leds/abc:kbd_backlight:red\u0000" - ) - ) - assertEquals( - "Should reload sysfs node if a valid Keyboard backlight LED UEvent occurs", - ++counter, - sysfsNodeChanges, - ) - } - - @Test @UiThreadTest fun testKeyboardBacklightAnimation_onChangeLevels() { ExtendedMockito.doReturn("true").`when` { |