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

Commit 11165e59 authored by Michael Gernoth's avatar Michael Gernoth Committed by Steve Kondik
Browse files

keyboard: re-add code to detect lid state and handle lights

Depends on libhardware patch for the light ids:
http://review.cyanogenmod.org/77944

This squashes the following commits from cm-11.0 and updates
them for cm-12.0:

From: Dave Daynard <nardholio@gmail.com>
Date: Tue, 19 Nov 2013 18:22:45 -0500
Subject: keyboard: re-add code to detect lid state

keyboard: re-add code to detect lid state

This was lost in the cm-11 merge. Without this, a change in lid state
isn't generated to light up the keyboard backlight

Change-Id: Ief35cebcb62da13afe1ae7531d69ab58e196be9e

From: YuanQY <yuanqingyun@gmail.com>
Date: Fri, 8 Feb 2013 10:59:22 +0800
Subject: Keyboard light: Fix the physical keyboard not light when

Keyboard light: Fix the physical keyboard not light when it's visiable.

Change-Id: I595afd3cb6b422a17ae0f6ec20aa51979db13810

From: tbalden <illespal@gmail.com>
Date: Sun, 31 Mar 2013 18:33:53 +0200
Subject: keyboard: adding functional alt/shift lights

keyboard: adding functional alt/shift lights

This is useful for devices that has QWERTY keyboard
and leds for the Alt/Shift (Fn/Caps) keys, like
htc doubleshot.

Change-Id: I66ebc2d881438f5b51db77eaa885421e65a7da0d
parent 4f8045a2
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -62,4 +62,9 @@ interface IPowerManager
    void setAttentionLight(boolean on, int color);
    // update the uids being synchronized by network socket request manager
    void updateBlockedUids(int uid, boolean isBlocked);

    void setKeyboardVisibility(boolean visible);

    void setKeyboardLight(boolean on, int key);

}
+31 −0
Original line number Diff line number Diff line
@@ -1235,4 +1235,35 @@ public final class PowerManager {
            }
        }
    }

    /**
     * @hide
     */
    public void setKeyboardVisibility(boolean visible)
    {
        try {
            if (mService != null) {
                mService.setKeyboardVisibility(visible);
            }
        } catch (RemoteException e) {
        }
    }

    /**
     * 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) {
        }
    }


}
+31 −0
Original line number Diff line number Diff line
@@ -23,6 +23,9 @@ import android.text.Spanned;
import android.view.KeyEvent;
import android.view.View;
import android.view.KeyCharacterMap;
import android.os.IPowerManager;
import android.os.RemoteException;
import android.os.ServiceManager;

/**
 * This base class encapsulates the behavior for tracking the state of
@@ -273,6 +276,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) {}
    }

    /**
@@ -325,12 +336,32 @@ public abstract class MetaKeyKeyListener {
    public boolean onKeyDown(View view, Editable content, 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;
        }

+2 −0
Original line number Diff line number Diff line
@@ -601,11 +601,13 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
        if (state == Display.STATE_OFF) {
            brightness = PowerManager.BRIGHTNESS_OFF;
            mLights.getLight(LightsManager.LIGHT_ID_BUTTONS).setBrightness(brightness);
            mLights.getLight(LightsManager.LIGHT_ID_KEYBOARD).setBrightness(brightness);
        }

        // Disable button lights when dozing
        if (state == Display.STATE_DOZE || state == Display.STATE_DOZE_SUSPEND) {
            mLights.getLight(LightsManager.LIGHT_ID_BUTTONS).setBrightness(PowerManager.BRIGHTNESS_OFF);
            mLights.getLight(LightsManager.LIGHT_ID_KEYBOARD).setBrightness(brightness);
        }

        // Configure auto-brightness.
+3 −1
Original line number Diff line number Diff line
@@ -25,7 +25,9 @@ public abstract class LightsManager {
    public static final int LIGHT_ID_ATTENTION = 5;
    public static final int LIGHT_ID_BLUETOOTH = 6;
    public static final int LIGHT_ID_WIFI = 7;
    public static final int LIGHT_ID_COUNT = 8;
    public static final int LIGHT_ID_CAPS = 8;
    public static final int LIGHT_ID_FUNC = 9;
    public static final int LIGHT_ID_COUNT = 10;

    public abstract Light getLight(int id);
}
Loading