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 @@ -1268,6 +1268,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> <string-array name="config_notificationScorers"> <item>com.android.internal.notification.DemoContactNotificationScorer</item> </string-array> Loading core/res/res/values/symbols.xml +3 −0 Original line number Diff line number Diff line Loading @@ -1537,6 +1537,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 +33 −0 Original line number Diff line number Diff line Loading @@ -50,6 +50,7 @@ import android.os.Bundle; import android.os.FactoryTest; import android.os.Handler; import android.os.IBinder; import android.os.IHardwareService; import android.os.IRemoteCallback; import android.os.Looper; import android.os.Message; Loading Loading @@ -203,6 +204,8 @@ public class PhoneWindowManager implements WindowManagerPolicy { */ private final Object mLock = new Object(); private boolean mButtonLightEnabled; Context mContext; IWindowManager mWindowManager; WindowManagerFuncs mWindowManagerFuncs; Loading @@ -211,6 +214,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; // Vibrator pattern for haptic feedback of a long press. Loading Loading @@ -908,6 +912,16 @@ public class PhoneWindowManager implements WindowManagerPolicy { com.android.internal.R.bool.config_lidControlsSleep); mTranslucentDecorEnabled = mContext.getResources().getBoolean( com.android.internal.R.bool.config_enableTranslucentDecor); 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; } readConfigurationDependentBehaviors(); // register for dock events Loading Loading @@ -1969,6 +1983,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 @@ -3985,6 +4009,14 @@ public class PhoneWindowManager implements WindowManagerPolicy { mPowerKeyTriggered = true; mPowerKeyTime = event.getDownTime(); interceptScreenshotChord(); if (mButtonLightEnabled) { try { mLight.setButtonLightEnabled(false); } catch(RemoteException e) { Slog.e(TAG, "remote call for turn off button light failed."); } } } ITelephony telephonyService = getTelephonyService(); Loading Loading @@ -4114,6 +4146,7 @@ public class PhoneWindowManager implements WindowManagerPolicy { case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD: case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: case KeyEvent.KEYCODE_CAMERA: case KeyEvent.KEYCODE_FOCUS: return false; } return true; Loading services/java/com/android/server/LightsService.java +45 −0 Original line number Diff line number Diff line Loading @@ -57,6 +57,14 @@ public class LightsService { private final Light mLights[] = new Light[LIGHT_ID_COUNT]; private static final int MSG_BBL_TIMEOUT = 1; private int mButtonLightTimeout; private int mButtonBrightness; private Handler mLightHandler = null; public final class Light { private Light(int id) { Loading Loading @@ -170,6 +178,25 @@ public class LightsService { // fail silently } } public void setButtonLightEnabled(boolean on) { if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.HARDWARE_TEST) != PackageManager.PERMISSION_GRANTED) { throw new SecurityException("Requires FLASHLIGHT permission"); } mLightHandler.removeMessages(MSG_BBL_TIMEOUT); if (on) { getLight(LIGHT_ID_BUTTONS).setBrightness(mButtonBrightness); mLightHandler.sendMessageDelayed( mLightHandler.obtainMessage(MSG_BBL_TIMEOUT), mButtonLightTimeout); } else { getLight(LIGHT_ID_BUTTONS).setBrightness(0); } } }; LightsService(Context context) { Loading @@ -177,6 +204,24 @@ public class LightsService { mNativePointer = init_native(); mContext = context; mButtonLightTimeout = mContext.getResources().getInteger( com.android.internal.R.integer.config_button_light_timeout_msec); mButtonBrightness = mContext.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(LIGHT_ID_BUTTONS).setBrightness(0); break; } } } }; ServiceManager.addService("hardware", mLegacyFlashlightHack); for (int i = 0; i < LIGHT_ID_COUNT; i++) { 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 @@ -1268,6 +1268,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> <string-array name="config_notificationScorers"> <item>com.android.internal.notification.DemoContactNotificationScorer</item> </string-array> Loading
core/res/res/values/symbols.xml +3 −0 Original line number Diff line number Diff line Loading @@ -1537,6 +1537,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 +33 −0 Original line number Diff line number Diff line Loading @@ -50,6 +50,7 @@ import android.os.Bundle; import android.os.FactoryTest; import android.os.Handler; import android.os.IBinder; import android.os.IHardwareService; import android.os.IRemoteCallback; import android.os.Looper; import android.os.Message; Loading Loading @@ -203,6 +204,8 @@ public class PhoneWindowManager implements WindowManagerPolicy { */ private final Object mLock = new Object(); private boolean mButtonLightEnabled; Context mContext; IWindowManager mWindowManager; WindowManagerFuncs mWindowManagerFuncs; Loading @@ -211,6 +214,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; // Vibrator pattern for haptic feedback of a long press. Loading Loading @@ -908,6 +912,16 @@ public class PhoneWindowManager implements WindowManagerPolicy { com.android.internal.R.bool.config_lidControlsSleep); mTranslucentDecorEnabled = mContext.getResources().getBoolean( com.android.internal.R.bool.config_enableTranslucentDecor); 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; } readConfigurationDependentBehaviors(); // register for dock events Loading Loading @@ -1969,6 +1983,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 @@ -3985,6 +4009,14 @@ public class PhoneWindowManager implements WindowManagerPolicy { mPowerKeyTriggered = true; mPowerKeyTime = event.getDownTime(); interceptScreenshotChord(); if (mButtonLightEnabled) { try { mLight.setButtonLightEnabled(false); } catch(RemoteException e) { Slog.e(TAG, "remote call for turn off button light failed."); } } } ITelephony telephonyService = getTelephonyService(); Loading Loading @@ -4114,6 +4146,7 @@ public class PhoneWindowManager implements WindowManagerPolicy { case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD: case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: case KeyEvent.KEYCODE_CAMERA: case KeyEvent.KEYCODE_FOCUS: return false; } return true; Loading
services/java/com/android/server/LightsService.java +45 −0 Original line number Diff line number Diff line Loading @@ -57,6 +57,14 @@ public class LightsService { private final Light mLights[] = new Light[LIGHT_ID_COUNT]; private static final int MSG_BBL_TIMEOUT = 1; private int mButtonLightTimeout; private int mButtonBrightness; private Handler mLightHandler = null; public final class Light { private Light(int id) { Loading Loading @@ -170,6 +178,25 @@ public class LightsService { // fail silently } } public void setButtonLightEnabled(boolean on) { if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.HARDWARE_TEST) != PackageManager.PERMISSION_GRANTED) { throw new SecurityException("Requires FLASHLIGHT permission"); } mLightHandler.removeMessages(MSG_BBL_TIMEOUT); if (on) { getLight(LIGHT_ID_BUTTONS).setBrightness(mButtonBrightness); mLightHandler.sendMessageDelayed( mLightHandler.obtainMessage(MSG_BBL_TIMEOUT), mButtonLightTimeout); } else { getLight(LIGHT_ID_BUTTONS).setBrightness(0); } } }; LightsService(Context context) { Loading @@ -177,6 +204,24 @@ public class LightsService { mNativePointer = init_native(); mContext = context; mButtonLightTimeout = mContext.getResources().getInteger( com.android.internal.R.integer.config_button_light_timeout_msec); mButtonBrightness = mContext.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(LIGHT_ID_BUTTONS).setBrightness(0); break; } } } }; ServiceManager.addService("hardware", mLegacyFlashlightHack); for (int i = 0; i < LIGHT_ID_COUNT; i++) { Loading