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

Commit 95d67cf1 authored by rmcc's avatar rmcc Committed by Steve Kondik
Browse files

Add framework support for keyboard LEDs (Caps/FN)

Change-Id: I7a6989b53f15e86ced59e5fd31464a2334bbfd68
parent b160ab0a
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -46,4 +46,6 @@ interface IPowerManager
    int getLightSensorScreenBrightness();
    int getLightSensorButtonBrightness();
    int getLightSensorKeyboardBrightness();

    void setKeyboardLight(boolean on, int key);
}
+16 −0
Original line number Diff line number Diff line
@@ -421,6 +421,22 @@ public class PowerManager
        }
    }

    /**
     * sets the keyboard LED state
     *
     * @param on boolean state
     * @param key 1 for caps, 2 for fn
     *
     * {@hide}
     */
    public void setKeyboardLight(boolean on, int key)
    {
        try {
            mService.setKeyboardLight(on, key);
        } catch (RemoteException e) {
        }
    }

   /**
     * Returns the set of flags for {@link #newWakeLock(int, String) newWakeLock()}
     * that are supported on the device.
+34 −0
Original line number Diff line number Diff line
@@ -20,6 +20,12 @@ import android.view.KeyEvent;
import android.view.View;
import android.text.*;

/* For the hardware keyboard lights */
import android.os.IPowerManager;
import android.os.RemoteException;
import android.os.ServiceManager;


/**
 * This base class encapsulates the behavior for handling the meta keys
 * (shift and alt) and the pseudo-meta state of selecting text.
@@ -155,6 +161,14 @@ public abstract class MetaKeyKeyListener {
        adjust(content, CAP);
        adjust(content, ALT);
        adjust(content, SYM);
        try {
            IPowerManager power = IPowerManager.Stub.asInterface(
                ServiceManager.getService("power"));
            if (getMetaState(content, META_SHIFT_ON) <= 0)
                power.setKeyboardLight(false, 1);
            if (getMetaState(content, META_ALT_ON) <= 0)
                power.setKeyboardLight(false, 2);
        } catch (RemoteException doe) {}
    }

    /**
@@ -208,12 +222,32 @@ public abstract class MetaKeyKeyListener {
                             int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_SHIFT_LEFT || keyCode == KeyEvent.KEYCODE_SHIFT_RIGHT) {
            press(content, CAP);
            try {
                IPowerManager power = IPowerManager.Stub.asInterface(
                    ServiceManager.getService("power"));
                int state = content.getSpanFlags(CAP);
                if (state == PRESSED || state == LOCKED) {
                    power.setKeyboardLight(true, 1);
                } else {
                    power.setKeyboardLight(false, 1);
                }
            } catch (RemoteException doe) {}
            return true;
        }

        if (keyCode == KeyEvent.KEYCODE_ALT_LEFT || keyCode == KeyEvent.KEYCODE_ALT_RIGHT
                || keyCode == KeyEvent.KEYCODE_NUM) {
            press(content, ALT);
            try {
                IPowerManager power = IPowerManager.Stub.asInterface(
                    ServiceManager.getService("power"));
                int state = content.getSpanFlags(ALT);
                if (state == PRESSED || state == LOCKED) {
                    power.setKeyboardLight(true, 2);
                } else {
                    power.setKeyboardLight(false, 2);
                }
            } catch (RemoteException doe) {}
            return true;
        }

+24 −0
Original line number Diff line number Diff line
@@ -189,6 +189,8 @@ class PowerManagerService extends IPowerManager.Stub
    private LightsService.Light mButtonLight;
    private LightsService.Light mKeyboardLight;
    private LightsService.Light mAttentionLight;
    private LightsService.Light mCapsLight;
    private LightsService.Light mFnLight;
    private UnsynchronizedWakeLock mBroadcastWakeLock;
    private UnsynchronizedWakeLock mStayOnWhilePluggedInScreenDimLock;
    private UnsynchronizedWakeLock mStayOnWhilePluggedInPartialLock;
@@ -495,6 +497,8 @@ class PowerManagerService extends IPowerManager.Stub
        mButtonLight = lights.getLight(LightsService.LIGHT_ID_BUTTONS);
        mKeyboardLight = lights.getLight(LightsService.LIGHT_ID_KEYBOARD);
        mAttentionLight = lights.getLight(LightsService.LIGHT_ID_ATTENTION);
        mCapsLight = lights.getLight(LightsService.LIGHT_ID_CAPS);
        mFnLight = lights.getLight(LightsService.LIGHT_ID_FUNC);

        mHandlerThread = new HandlerThread("PowerManagerService") {
            @Override
@@ -2577,6 +2581,11 @@ class PowerManagerService extends IPowerManager.Stub
                    }
                    userActivity(SystemClock.uptimeMillis(), false, BUTTON_EVENT, true);
                }
                // If hiding keyboard, turn off leds
                if (!visible) {
                    setKeyboardLight(false, 1);
                    setKeyboardLight(false, 2);
                }
            }
        }
    }
@@ -3073,6 +3082,21 @@ class PowerManagerService extends IPowerManager.Stub
        }
    }

    public void setKeyboardLight(boolean on, int key) {
        if (key == 1) {
            if (on) 
                mCapsLight.setColor(0x00ffffff);
            else
                mCapsLight.turnOff();
        } else if (key == 2) {
            if (on) 
                mFnLight.setColor(0x00ffffff);
            else
                mFnLight.turnOff();
        }
    }


    SensorEventListener mProximityListener = new SensorEventListener() {
        public void onSensorChanged(SensorEvent event) {
            long milliseconds = SystemClock.elapsedRealtime();