Loading core/java/android/os/IHardwareService.aidl +1 −0 Original line number Diff line number Diff line Loading @@ -22,5 +22,6 @@ interface IHardwareService // obsolete flashlight support boolean getFlashlightEnabled(); void setFlashlightEnabled(boolean on); void setButtonLightEnabled(boolean on); } core/res/res/values/config.xml +6 −0 Original line number Diff line number Diff line Loading @@ -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"> Loading core/res/res/values/symbols.xml +3 −0 Original line number Diff line number Diff line Loading @@ -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" /> Loading policy/src/com/android/internal/policy/impl/PhoneWindowManager.java +32 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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; Loading @@ -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; Loading Loading @@ -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); Loading Loading @@ -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. Loading Loading @@ -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(); Loading services/core/java/com/android/server/lights/LightsService.java +50 −0 Original line number Diff line number Diff line Loading @@ -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) { Loading Loading @@ -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) { Loading @@ -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); } Loading Loading @@ -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) { Loading Loading
core/java/android/os/IHardwareService.aidl +1 −0 Original line number Diff line number Diff line Loading @@ -22,5 +22,6 @@ interface IHardwareService // obsolete flashlight support boolean getFlashlightEnabled(); void setFlashlightEnabled(boolean on); void setButtonLightEnabled(boolean on); }
core/res/res/values/config.xml +6 −0 Original line number Diff line number Diff line Loading @@ -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"> Loading
core/res/res/values/symbols.xml +3 −0 Original line number Diff line number Diff line Loading @@ -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" /> Loading
policy/src/com/android/internal/policy/impl/PhoneWindowManager.java +32 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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; Loading @@ -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; Loading Loading @@ -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); Loading Loading @@ -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. Loading Loading @@ -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(); Loading
services/core/java/com/android/server/lights/LightsService.java +50 −0 Original line number Diff line number Diff line Loading @@ -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) { Loading Loading @@ -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) { Loading @@ -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); } Loading Loading @@ -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) { Loading