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

Commit 290e4c10 authored by Mao Li's avatar Mao Li
Browse files

BackLight: Enable menu/home/back/search button backlight.

 -Add button back-light API to HardwareService.
 -After user press physical key, the button backlight will be turn on.

CRs-fixed: 778104

Change-Id: Ia4c2c4ae0571b4043e1a0d8435c58e72cfe4c668
parent fd2e55d8
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -22,5 +22,6 @@ interface IHardwareService
    // obsolete flashlight support
    boolean getFlashlightEnabled();
    void setFlashlightEnabled(boolean on);
    void setButtonLightEnabled(boolean on);
}
+6 −0
Original line number Diff line number Diff line
@@ -1663,6 +1663,12 @@
        <item>com.android.inputmethod.latin</item>
    </string-array>

    <!-- Button back light brightness value, 2 means 10 mA, friendly user light brightness -->
    <integer name="config_button_light_bright_level">2</integer>
    <!-- Button back light brightness friendly time break. -->
    <integer name="config_button_light_timeout_msec">4000</integer>
    <bool name="config_button_light_enabled">false</bool>

    <!-- The list of classes that should be added to the notification ranking pipline.
     See {@link com.android.server.notification.NotificationSignalExtractor} -->
    <string-array name="config_notificationSignalExtractors">
+3 −0
Original line number Diff line number Diff line
@@ -1691,6 +1691,9 @@
  <java-symbol type="integer" name="config_shutdownBatteryTemperature" />
  <java-symbol type="integer" name="config_undockedHdmiRotation" />
  <java-symbol type="integer" name="config_virtualKeyQuietTimeMillis" />
  <java-symbol type="integer" name="config_button_light_bright_level" />
  <java-symbol type="integer" name="config_button_light_timeout_msec" />
  <java-symbol type="bool" name="config_button_light_enabled" />
  <java-symbol type="layout" name="am_compat_mode_dialog" />
  <java-symbol type="layout" name="launch_warning" />
  <java-symbol type="layout" name="safe_mode" />
+32 −0
Original line number Diff line number Diff line
@@ -52,6 +52,7 @@ import android.os.Bundle;
import android.os.FactoryTest;
import android.os.Handler;
import android.os.IBinder;
import android.os.IHardwareService;
import android.os.Looper;
import android.os.Message;
import android.os.Messenger;
@@ -266,6 +267,8 @@ public class PhoneWindowManager implements WindowManagerPolicy {
    private final Object mLock = new Object();
    private final Object mQuickBootLock = new Object();

    private boolean mButtonLightEnabled;

    Context mContext;
    IWindowManager mWindowManager;
    WindowManagerFuncs mWindowManagerFuncs;
@@ -276,6 +279,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
    boolean mPreloadedRecentApps;
    final Object mServiceAquireLock = new Object();
    Vibrator mVibrator; // Vibrator for giving feedback of orientation changes
    IHardwareService mLight;
    SearchManager mSearchManager;
    AccessibilityManager mAccessibilityManager;

@@ -1178,6 +1182,16 @@ public class PhoneWindowManager implements WindowManagerPolicy {
        mAccessibilityManager = (AccessibilityManager) context.getSystemService(
                Context.ACCESSIBILITY_SERVICE);

        mButtonLightEnabled = mContext.getResources().getBoolean(
                com.android.internal.R.bool.config_button_light_enabled);

        if (mButtonLightEnabled) {
            mLight = IHardwareService.Stub.asInterface(
                    ServiceManager.getService("hardware"));

            if(mLight == null) mButtonLightEnabled = false;
        }

        // register for dock events
        IntentFilter filter = new IntentFilter();
        filter.addAction(UiModeManager.ACTION_ENTER_CAR_MODE);
@@ -2383,6 +2397,16 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                    + " canceled=" + canceled);
        }

        if (mButtonLightEnabled && (down && repeatCount == 0 && (keyCode == KeyEvent.KEYCODE_HOME
                || keyCode == KeyEvent.KEYCODE_BACK || keyCode == KeyEvent.KEYCODE_MENU
                || keyCode == KeyEvent.KEYCODE_SEARCH))) {
            try {
                mLight.setButtonLightEnabled(true);
            } catch(RemoteException e) {
                Slog.e(TAG, "remote call for turn on button light failed.");
            }
        }

        // If we think we might have a volume down & power key chord on the way
        // but we're not sure, then tell the dispatcher to wait a little while and
        // try again later before dispatching.
@@ -4785,6 +4809,14 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                        mPowerKeyTime = event.getDownTime();
                        interceptScreenshotChord();
                        interceptScreenshotLog();

                        if (mButtonLightEnabled) {
                            try {
                                mLight.setButtonLightEnabled(false);
                            } catch(RemoteException e) {
                                Slog.e(TAG, "remote call for turn off button light failed.");
                            }
                        }
                    }

                    TelecomManager telecomManager = getTelecommService();
+50 −0
Original line number Diff line number Diff line
@@ -35,6 +35,14 @@ public class LightsService extends SystemService {

    final LightImpl mLights[] = new LightImpl[LightsManager.LIGHT_ID_COUNT];

    private static final int MSG_BBL_TIMEOUT = 1;

    private int mButtonLightTimeout;

    private int mButtonBrightness;

    private Handler mLightHandler = null;

    private final class LightImpl extends Light {

        private LightImpl(int id) {
@@ -161,6 +169,26 @@ public class LightsService extends SystemService {
                // fail silently
            }
        }

        public void setButtonLightEnabled(boolean on) {
            final Context context = getContext();
            if (context.checkCallingOrSelfPermission(android.Manifest.permission.HARDWARE_TEST)
                    != PackageManager.PERMISSION_GRANTED) {
                throw new SecurityException("Requires FLASHLIGHT permission");
            }

            mLightHandler.removeMessages(MSG_BBL_TIMEOUT);

            if (on) {
                getLight(LightsManager.LIGHT_ID_BUTTONS).setBrightness(mButtonBrightness);

                mLightHandler.sendMessageDelayed(
                        mLightHandler.obtainMessage(MSG_BBL_TIMEOUT),
                        mButtonLightTimeout);
            } else {
                getLight(LightsManager.LIGHT_ID_BUTTONS).setBrightness(0);
            }
        }
    };

    public LightsService(Context context) {
@@ -168,6 +196,24 @@ public class LightsService extends SystemService {

        mNativePointer = init_native();

        mButtonLightTimeout = context.getResources().getInteger(
                com.android.internal.R.integer.config_button_light_timeout_msec);

        mButtonBrightness = context.getResources().getInteger(
                com.android.internal.R.integer.config_button_light_bright_level);

        mLightHandler = new Handler() {
            public void handleMessage(Message msg) {
                synchronized(this) {
                    switch(msg.what) {
                    case MSG_BBL_TIMEOUT:
                        getLight(LightsManager.LIGHT_ID_BUTTONS).setBrightness(0);
                        break;
                    }
                }
            }
        };

        for (int i = 0; i < LightsManager.LIGHT_ID_COUNT; i++) {
            mLights[i] = new LightImpl(i);
        }
@@ -196,6 +242,10 @@ public class LightsService extends SystemService {
        super.finalize();
    }

    public Light getLight(int id) {
        return mLights[id];
    }

    private Handler mH = new Handler() {
        @Override
        public void handleMessage(Message msg) {