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

Commit 9677ab18 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 7db99f29
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -62,4 +62,9 @@ interface IPowerManager
    void updateBlockedUids(int uid, boolean isBlocked);

    void cpuBoost(int duration);

    void setKeyboardVisibility(boolean visible);

    void setKeyboardLight(boolean on, int key);

}
+31 −0
Original line number Diff line number Diff line
@@ -1094,4 +1094,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;
        }

+6 −0
Original line number Diff line number Diff line
@@ -1799,6 +1799,10 @@ public class PhoneWindowManager implements WindowManagerPolicy {
        }
    }

    private boolean isBuiltInKeyboardVisible() {
        return mHaveBuiltInKeyboard && !isHidden(mLidKeyboardAccessibility);
    }

    /** {@inheritDoc} */
    @Override
    public void adjustConfigurationLw(Configuration config, int keyboardPresence,
@@ -5883,6 +5887,8 @@ public class PhoneWindowManager implements WindowManagerPolicy {
    }

    private void applyLidSwitchState() {
        mPowerManager.setKeyboardVisibility(isBuiltInKeyboardVisible());

        if (mLidState == LID_CLOSED && mLidControlsSleep) {
            mPowerManager.goToSleep(SystemClock.uptimeMillis(),
                    PowerManager.GO_TO_SLEEP_REASON_LID_SWITCH,
+2 −0
Original line number Diff line number Diff line
@@ -573,6 +573,7 @@ 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);
        }

        // Use default brightness when dozing unless overridden.
@@ -580,6 +581,7 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
                || state == Display.STATE_DOZE_SUSPEND)) {
            brightness = mScreenBrightnessDozeConfig;
            mLights.getLight(LightsManager.LIGHT_ID_BUTTONS).setBrightness(PowerManager.BRIGHTNESS_OFF);
            mLights.getLight(LightsManager.LIGHT_ID_KEYBOARD).setBrightness(brightness);
        }


Loading