Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 86da3371 authored by Vaibhav Devmurari's avatar Vaibhav Devmurari Committed by Android (Google) Code Review
Browse files

Merge "Flag guard keyboard backlight controller"

parents a1176034 a0572e78
Loading
Loading
Loading
Loading
+20 −3
Original line number Diff line number Diff line
@@ -70,6 +70,7 @@ import android.os.RemoteCallbackList;
import android.os.RemoteException;
import android.os.ResultReceiver;
import android.os.ShellCallback;
import android.os.SystemProperties;
import android.os.UserHandle;
import android.os.VibrationEffect;
import android.os.vibrator.StepSegment;
@@ -158,6 +159,11 @@ public class InputManagerService extends IInputManager.Stub
    private static final AdditionalDisplayInputProperties
            DEFAULT_ADDITIONAL_DISPLAY_INPUT_PROPERTIES = new AdditionalDisplayInputProperties();

    // To disable Keyboard backlight control via Framework, run:
    // 'adb shell setprop persist.input.keyboard_backlight_control.enabled false' (requires restart)
    private static final boolean KEYBOARD_BACKLIGHT_CONTROL_ENABLED = SystemProperties.getBoolean(
            "persist.input.keyboard.backlight_control.enabled", true);

    private final NativeInputManagerService mNative;

    private final Context mContext;
@@ -305,7 +311,7 @@ public class InputManagerService extends IInputManager.Stub
    private final BatteryController mBatteryController;

    // Manages Keyboard backlight
    private final KeyboardBacklightController mKeyboardBacklightController;
    private final KeyboardBacklightControllerInterface mKeyboardBacklightController;

    // Manages Keyboard modifier keys remapping
    private final KeyRemapper mKeyRemapper;
@@ -422,8 +428,10 @@ public class InputManagerService extends IInputManager.Stub
        mKeyboardLayoutManager = new KeyboardLayoutManager(mContext, mNative, mDataStore,
                injector.getLooper());
        mBatteryController = new BatteryController(mContext, mNative, injector.getLooper());
        mKeyboardBacklightController = new KeyboardBacklightController(mContext, mNative,
                mDataStore, injector.getLooper());
        mKeyboardBacklightController =
                KEYBOARD_BACKLIGHT_CONTROL_ENABLED ? new KeyboardBacklightController(mContext,
                        mNative, mDataStore, injector.getLooper())
                        : new KeyboardBacklightControllerInterface() {};
        mKeyRemapper = new KeyRemapper(mContext, mNative, mDataStore, injector.getLooper());

        mUseDevInputEventForAudioJack =
@@ -3475,4 +3483,13 @@ public class InputManagerService extends IInputManager.Stub
            applyAdditionalDisplayInputPropertiesLocked(properties);
        }
    }

    interface KeyboardBacklightControllerInterface {
        default void incrementKeyboardBacklight(int deviceId) {}
        default void decrementKeyboardBacklight(int deviceId) {}
        default void registerKeyboardBacklightListener(IKeyboardBacklightListener l, int pid) {}
        default void unregisterKeyboardBacklightListener(IKeyboardBacklightListener l, int pid) {}
        default void systemRunning() {}
        default void dump(PrintWriter pw) {}
    }
}
+10 −3
Original line number Diff line number Diff line
@@ -47,7 +47,8 @@ import java.util.TreeSet;
 * A thread-safe component of {@link InputManagerService} responsible for managing the keyboard
 * backlight for supported keyboards.
 */
final class KeyboardBacklightController implements InputManager.InputDeviceListener {
final class KeyboardBacklightController implements
        InputManagerService.KeyboardBacklightControllerInterface, InputManager.InputDeviceListener {

    private static final String TAG = "KbdBacklightController";

@@ -96,7 +97,8 @@ final class KeyboardBacklightController implements InputManager.InputDeviceListe
        mHandler = new Handler(looper, this::handleMessage);
    }

    void systemRunning() {
    @Override
    public void systemRunning() {
        InputManager inputManager = Objects.requireNonNull(
                mContext.getSystemService(InputManager.class));
        inputManager.registerInputDeviceListener(this, mHandler);
@@ -106,11 +108,13 @@ final class KeyboardBacklightController implements InputManager.InputDeviceListe
        }
    }

    @Override
    public void incrementKeyboardBacklight(int deviceId) {
        Message msg = Message.obtain(mHandler, MSG_INCREMENT_KEYBOARD_BACKLIGHT, deviceId);
        mHandler.sendMessage(msg);
    }

    @Override
    public void decrementKeyboardBacklight(int deviceId) {
        Message msg = Message.obtain(mHandler, MSG_DECREMENT_KEYBOARD_BACKLIGHT, deviceId);
        mHandler.sendMessage(msg);
@@ -232,6 +236,7 @@ final class KeyboardBacklightController implements InputManager.InputDeviceListe

    /** Register the keyboard backlight listener for a process. */
    @BinderThread
    @Override
    public void registerKeyboardBacklightListener(IKeyboardBacklightListener listener,
            int pid) {
        synchronized (mKeyboardBacklightListenerRecords) {
@@ -252,6 +257,7 @@ final class KeyboardBacklightController implements InputManager.InputDeviceListe

    /** Unregister the keyboard backlight listener for a process. */
    @BinderThread
    @Override
    public void unregisterKeyboardBacklightListener(IKeyboardBacklightListener listener,
            int pid) {
        synchronized (mKeyboardBacklightListenerRecords) {
@@ -286,7 +292,8 @@ final class KeyboardBacklightController implements InputManager.InputDeviceListe
        }
    }

    void dump(PrintWriter pw) {
    @Override
    public void dump(PrintWriter pw) {
        IndentingPrintWriter ipw = new IndentingPrintWriter(pw);
        ipw.println(TAG + ": " + mKeyboardBacklights.size() + " keyboard backlights");
        ipw.increaseIndent();