diff options
15 files changed, 458 insertions, 13 deletions
diff --git a/core/java/android/content/Intent.java b/core/java/android/content/Intent.java index a1a0867..404564b 100644 --- a/core/java/android/content/Intent.java +++ b/core/java/android/content/Intent.java @@ -2864,6 +2864,13 @@ public class Intent implements Parcelable, Cloneable { "android.intent.action.SHOW_BRIGHTNESS_DIALOG"; /** + * Activity Action: Shows the notification brightness setting dialog. + * @hide + */ + public static final String ACTION_SHOW_NOTIFICATION_BRIGHTNESS_DIALOG = + "android.intent.action.SHOW_NOTIFICATION_BRIGHTNESS_DIALOG"; + + /** * Broadcast Action: A global button was pressed. Includes a single * extra field, {@link #EXTRA_KEY_EVENT}, containing the key event that * caused the broadcast. diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java index 3d2118c..81166ea 100644 --- a/core/java/android/provider/Settings.java +++ b/core/java/android/provider/Settings.java @@ -3222,6 +3222,13 @@ public final class Settings { public static final Validator SHOW_WEB_SUGGESTIONS_VALIDATOR = sBooleanValidator; /** + * Contains the notifications light maximum brightness to use. + * @hide + */ + public static final String NOTIFICATION_LIGHT_BRIGHTNESS_LEVEL = + "notification_light_brightness_level"; + + /** * Whether to allow notifications with the screen on or DayDreams. * The value is boolean (1 or 0). Default will always be false. * @hide @@ -3998,6 +4005,7 @@ public final class Settings { PHONE_BLACKLIST_PRIVATE_NUMBER_MODE, PHONE_BLACKLIST_UNKNOWN_NUMBER_MODE, PHONE_BLACKLIST_REGEX_ENABLED, + NOTIFICATION_LIGHT_BRIGHTNESS_LEVEL, NOTIFICATION_LIGHT_SCREEN_ON }; diff --git a/core/res/res/values/cm_symbols.xml b/core/res/res/values/cm_symbols.xml index 26bc0f3..59ea24d 100644 --- a/core/res/res/values/cm_symbols.xml +++ b/core/res/res/values/cm_symbols.xml @@ -40,6 +40,15 @@ <!-- Proximity check on screen on default --> <java-symbol type="bool" name="config_proximityCheckOnWakeEnabledByDefault" /> + <!-- Notification and battery light --> + <java-symbol type="bool" name="config_adjustableNotificationLedBrightness" /> + <java-symbol type="bool" name="config_intrusiveNotificationLed" /> + <java-symbol type="bool" name="config_multiColorNotificationLed" /> + <java-symbol type="bool" name="config_intrusiveBatteryLed" /> + <java-symbol type="bool" name="config_multiColorBatteryLed" /> + <java-symbol type="array" name="notification_light_package_mapping" /> + <java-symbol type="array" name="config_notificationNoAlertsVibePattern" /> + <!-- Package Manager --> <java-symbol type="array" name="config_disabledComponents" /> <java-symbol type="array" name="config_forceEnabledComponents" /> diff --git a/core/res/res/values/config.xml b/core/res/res/values/config.xml index e5203d1..b87a5fc 100755 --- a/core/res/res/values/config.xml +++ b/core/res/res/values/config.xml @@ -875,6 +875,10 @@ <!-- Default value for LED on time when the battery is low on charge in miliseconds --> <integer name="config_notificationsBatteryLedOn">125</integer> + <!-- Is the notification LED brightness adjustable ? + Used to decide if the user can set LED brightness --> + <bool name="config_adjustableNotificationLedBrightness">false</bool> + <!-- Is the notification LED intrusive? Used to decide if there should be a disable option --> <bool name="config_intrusiveNotificationLed">false</bool> diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml index f673fa7..6643cf3 100755 --- a/core/res/res/values/symbols.xml +++ b/core/res/res/values/symbols.xml @@ -2400,14 +2400,6 @@ <java-symbol type="bool" name="config_samsung_stk" /> <java-symbol type="bool" name="config_hasRemovableLid" /> - <!-- Notification and battery light --> - <java-symbol type="bool" name="config_intrusiveNotificationLed" /> - <java-symbol type="bool" name="config_multiColorNotificationLed" /> - <java-symbol type="bool" name="config_intrusiveBatteryLed" /> - <java-symbol type="bool" name="config_multiColorBatteryLed" /> - <java-symbol type="array" name="notification_light_package_mapping" /> - <java-symbol type="array" name="config_notificationNoAlertsVibePattern" /> - <!-- Power menu --> <java-symbol type="drawable" name="ic_lock_screenshot" /> <java-symbol type="string" name="global_action_screenshot" /> diff --git a/packages/SettingsProvider/res/values/defaults.xml b/packages/SettingsProvider/res/values/defaults.xml index a2d9459..d6e2c92 100644 --- a/packages/SettingsProvider/res/values/defaults.xml +++ b/packages/SettingsProvider/res/values/defaults.xml @@ -66,6 +66,10 @@ pending notification --> <bool name="def_notification_pulse">true</bool> + <!-- Default value for the notification LEDs brightness + on devices equiped with configurable LED controller --> + <integer name="def_notification_brightness_level">255</integer> + <bool name="def_mount_play_notification_snd">true</bool> <bool name="def_mount_ums_autostart">false</bool> <bool name="def_mount_ums_prompt">true</bool> diff --git a/packages/SystemUI/AndroidManifest.xml b/packages/SystemUI/AndroidManifest.xml index b2f60f8..fd194c5 100644 --- a/packages/SystemUI/AndroidManifest.xml +++ b/packages/SystemUI/AndroidManifest.xml @@ -400,6 +400,20 @@ </intent-filter> </activity> + <activity + android:name=".settings.NotificationBrightnessDialog" + android:label="@string/quick_settings_brightness_dialog_title" + android:theme="@android:style/Theme.DeviceDefault.Dialog" + android:finishOnCloseSystemDialogs="true" + android:launchMode="singleInstance" + android:excludeFromRecents="true" + android:exported="true"> + <intent-filter> + <action android:name="android.intent.action.SHOW_NOTIFICATION_BRIGHTNESS_DIALOG" /> + <category android:name="android.intent.category.DEFAULT" /> + </intent-filter> + </activity> + <!-- Doze with notifications, run in main sysui process for every user --> <service android:name=".doze.DozeService" diff --git a/packages/SystemUI/res/layout/quick_settings_notification_brightness_dialog.xml b/packages/SystemUI/res/layout/quick_settings_notification_brightness_dialog.xml new file mode 100644 index 0000000..561eff6 --- /dev/null +++ b/packages/SystemUI/res/layout/quick_settings_notification_brightness_dialog.xml @@ -0,0 +1,31 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2012-2015 The CyanogenMod Project + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:systemui="http://schemas.android.com/apk/res/com.android.systemui" + android:paddingStart="16dp" + android:paddingEnd="16dp" + + style="@style/BrightnessDialogContainer"> + + <com.android.systemui.settings.ToggleSlider + android:id="@+id/notification_brightness_slider" + android:layout_width="0dp" + android:layout_height="wrap_content" + android:layout_gravity="center_vertical" + android:layout_weight="1" + systemui:text="" /> + +</LinearLayout> diff --git a/packages/SystemUI/src/com/android/systemui/settings/NotificationBrightnessController.java b/packages/SystemUI/src/com/android/systemui/settings/NotificationBrightnessController.java new file mode 100644 index 0000000..ef1356b --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/settings/NotificationBrightnessController.java @@ -0,0 +1,223 @@ +/* + * Copyright (C) 2012-2015 The CyanogenMod Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.systemui.settings; + +import android.app.Notification; +import android.app.NotificationManager; +import android.content.ContentResolver; +import android.content.Context; +import android.database.ContentObserver; +import android.net.Uri; +import android.os.AsyncTask; +import android.os.Bundle; +import android.os.Handler; +import android.os.UserHandle; +import android.provider.Settings; + +import java.lang.Exception; +import java.util.ArrayList; + +public class NotificationBrightnessController implements ToggleSlider.Listener { + private static final String TAG = "StatusBar.NotificationBrightnessController"; + + public static final int LIGHT_BRIGHTNESS_MINIMUM = 1; + public static final int LIGHT_BRIGHTNESS_MAXIMUM = 255; + + private int mCurrentBrightness; + private final int mMinimumBrightness; + private final int mMaximumBrightness; + + private final Context mContext; + private final ToggleSlider mControl; + private final CurrentUserTracker mUserTracker; + private final Handler mHandler; + private final NotificationBrightnessObserver mBrightnessObserver; + + private ArrayList<BrightnessStateChangeCallback> mChangeCallbacks = + new ArrayList<BrightnessStateChangeCallback>(); + + private boolean mListening; + private boolean mExternalChange; + + private boolean mNotificationAllow; + private final Bundle mNotificationBundle; + private final Notification.Builder mNotificationBuilder; + private NotificationManager mNotificationManager; + + public interface BrightnessStateChangeCallback { + public void onBrightnessLevelChanged(); + } + + /** ContentObserver to watch brightness **/ + private class NotificationBrightnessObserver extends ContentObserver { + + private final Uri NOTIFICATION_LIGHT_BRIGHTNESS_LEVEL_URI = + Settings.System.getUriFor(Settings.System.NOTIFICATION_LIGHT_BRIGHTNESS_LEVEL); + + public NotificationBrightnessObserver(Handler handler) { + super(handler); + } + + @Override + public void onChange(boolean selfChange) { + onChange(selfChange, null); + } + + @Override + public void onChange(boolean selfChange, Uri uri) { + if (selfChange) return; + try { + mExternalChange = true; + updateSlider(); + for (BrightnessStateChangeCallback cb : mChangeCallbacks) { + cb.onBrightnessLevelChanged(); + } + } finally { + mExternalChange = false; + } + } + + public void startObserving() { + final ContentResolver cr = mContext.getContentResolver(); + cr.unregisterContentObserver(this); + cr.registerContentObserver( + NOTIFICATION_LIGHT_BRIGHTNESS_LEVEL_URI, + false, this, UserHandle.USER_ALL); + } + + public void stopObserving() { + final ContentResolver cr = mContext.getContentResolver(); + cr.unregisterContentObserver(this); + } + + } + + public NotificationBrightnessController(Context context, ToggleSlider control) { + mContext = context; + mControl = control; + mHandler = new Handler(); + mUserTracker = new CurrentUserTracker(mContext) { + @Override + public void onUserSwitched(int newUserId) { + updateSlider(); + } + }; + mBrightnessObserver = new NotificationBrightnessObserver(mHandler); + + mMinimumBrightness = LIGHT_BRIGHTNESS_MINIMUM; + mMaximumBrightness = LIGHT_BRIGHTNESS_MAXIMUM; + mCurrentBrightness = LIGHT_BRIGHTNESS_MAXIMUM; + + mNotificationManager = + (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); + + mNotificationBundle = new Bundle(); + mNotificationBuilder = new Notification.Builder(mContext); + + mNotificationBundle.putBoolean(Notification.EXTRA_FORCE_SHOW_LIGHTS, true); + mNotificationBuilder.setExtras(mNotificationBundle); + } + + public void addStateChangedCallback(BrightnessStateChangeCallback cb) { + mChangeCallbacks.add(cb); + } + + public boolean removeStateChangedCallback(BrightnessStateChangeCallback cb) { + return mChangeCallbacks.remove(cb); + } + + @Override + public void onInit(ToggleSlider control) { + // Do nothing + } + + public void registerCallbacks() { + if (mListening) { + return; + } + + // Update the slider and mode before attaching the listener so we don't + // receive the onChanged notifications for the initial values. + mNotificationAllow = true; + updateSlider(); + + mBrightnessObserver.startObserving(); + mUserTracker.startTracking(); + + mControl.setOnChangedListener(this); + mListening = true; + } + + /** Unregister all call backs, both to and from the controller */ + public void unregisterCallbacks() { + if (!mListening) { + return; + } + + mNotificationAllow = false; + mBrightnessObserver.stopObserving(); + mUserTracker.stopTracking(); + mControl.setOnChangedListener(null); + mNotificationManager.cancel(1); + mListening = false; + + Settings.System.putIntForUser(mContext.getContentResolver(), + Settings.System.NOTIFICATION_LIGHT_BRIGHTNESS_LEVEL, + mCurrentBrightness, UserHandle.USER_CURRENT); + } + + @Override + public void onChanged(ToggleSlider view, boolean tracking, boolean automatic, int value, + boolean stopTracking) { + if (mExternalChange) return; + + mCurrentBrightness = value + mMinimumBrightness; + updateNotification(); + + for (BrightnessStateChangeCallback cb : mChangeCallbacks) { + cb.onBrightnessLevelChanged(); + } + } + + /** Fetch the brightness from the system settings and update the slider */ + private void updateSlider() { + mCurrentBrightness = Settings.System.getIntForUser(mContext.getContentResolver(), + Settings.System.NOTIFICATION_LIGHT_BRIGHTNESS_LEVEL, + mMaximumBrightness, UserHandle.USER_CURRENT); + + Settings.System.putIntForUser(mContext.getContentResolver(), + Settings.System.NOTIFICATION_LIGHT_BRIGHTNESS_LEVEL, + mMaximumBrightness, UserHandle.USER_CURRENT); + + mControl.setMax(mMaximumBrightness - mMinimumBrightness); + mControl.setValue(mCurrentBrightness - mMinimumBrightness); + updateNotification(); + } + + /** Fetch the brightness from the system settings and update the slider */ + private void updateNotification() { + if (mNotificationAllow) { + // Instead of canceling the notification, force it to update with the color. + int notificationColor = mCurrentBrightness + + (mCurrentBrightness << 8) + + (mCurrentBrightness << 16); + mNotificationBuilder.setLights(notificationColor, 1, 0); + mNotificationManager.notify(1, mNotificationBuilder.build()); + } + } + +} diff --git a/packages/SystemUI/src/com/android/systemui/settings/NotificationBrightnessDialog.java b/packages/SystemUI/src/com/android/systemui/settings/NotificationBrightnessDialog.java new file mode 100644 index 0000000..dae4e4e --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/settings/NotificationBrightnessDialog.java @@ -0,0 +1,75 @@ +/* + * Copyright (C) 2012-2015 The CyanogenMod Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.systemui.settings; + +import android.app.Activity; +import android.app.Dialog; +import android.content.Context; +import android.content.res.Resources; +import android.os.Bundle; +import android.os.Handler; +import android.view.Gravity; +import android.view.KeyEvent; +import android.view.Window; +import android.view.WindowManager; + +import com.android.systemui.R; + +/** A dialog that provides controls for adjusting the notifications brightness. */ +public class NotificationBrightnessDialog extends Activity { + + private NotificationBrightnessController mNotificationBrightnessController; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + final Window window = getWindow(); + + window.setGravity(Gravity.TOP); + window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND); + window.requestFeature(Window.FEATURE_NO_TITLE); + + setContentView(R.layout.quick_settings_notification_brightness_dialog); + + final ToggleSlider slider = (ToggleSlider) findViewById(R.id.notification_brightness_slider); + mNotificationBrightnessController = new NotificationBrightnessController(this, slider); + } + + @Override + protected void onStart() { + super.onStart(); + mNotificationBrightnessController.registerCallbacks(); + } + + @Override + protected void onStop() { + super.onStop(); + mNotificationBrightnessController.unregisterCallbacks(); + } + + @Override + public boolean onKeyDown(int keyCode, KeyEvent event) { + if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN + || keyCode == KeyEvent.KEYCODE_VOLUME_UP + || keyCode == KeyEvent.KEYCODE_VOLUME_MUTE) { + finish(); + } + + return super.onKeyDown(keyCode, event); + } +} diff --git a/services/core/java/com/android/server/BatteryService.java b/services/core/java/com/android/server/BatteryService.java index 99ce60c..690bde7 100644 --- a/services/core/java/com/android/server/BatteryService.java +++ b/services/core/java/com/android/server/BatteryService.java @@ -99,6 +99,9 @@ public final class BatteryService extends SystemService { private static final int BATTERY_SCALE = 100; // battery capacity is a percentage + // notification light maximum brightness value to use + private static final int LIGHT_BRIGHTNESS_MAXIMUM = 255; + // Used locally for determining when to make a last ditch effort to log // discharge stats before the device dies. private int mCriticalBatteryLevel; @@ -131,6 +134,9 @@ public final class BatteryService extends SystemService { private int mInvalidCharger; private int mLastInvalidCharger; + private boolean mAdjustableNotificationLedBrightness; + private int mNotificationLedBrightnessLevel = LIGHT_BRIGHTNESS_MAXIMUM; + private int mLowBatteryWarningLevel; private int mLowBatteryCloseWarningLevel; private int mShutdownBatteryTemperature; @@ -745,6 +751,10 @@ public final class BatteryService extends SystemService { mMultiColorLed = context.getResources().getBoolean( com.android.internal.R.bool.config_multiColorBatteryLed); + // Is the notification LED brightness changeable ? + mAdjustableNotificationLedBrightness = context.getResources().getBoolean( + com.android.internal.R.bool.config_adjustableNotificationLedBrightness); + mBatteryLedOn = context.getResources().getInteger( com.android.internal.R.integer.config_notificationsBatteryLedOn); mBatteryLedOff = context.getResources().getInteger( @@ -795,6 +805,7 @@ public final class BatteryService extends SystemService { // No lights if explicitly disabled mBatteryLight.turnOff(); } else if (level < mLowBatteryWarningLevel) { + mBatteryLight.setModes(mNotificationLedBrightnessLevel); if (status == BatteryManager.BATTERY_STATUS_CHARGING) { // Battery is charging and low mBatteryLight.setColor(mBatteryLowARGB); @@ -808,6 +819,7 @@ public final class BatteryService extends SystemService { } } else if (status == BatteryManager.BATTERY_STATUS_CHARGING || status == BatteryManager.BATTERY_STATUS_FULL) { + mBatteryLight.setModes(mNotificationLedBrightnessLevel); if (status == BatteryManager.BATTERY_STATUS_FULL || level >= 90) { // Battery is full or charging and nearly full mBatteryLight.setColor(mBatteryFullARGB); @@ -909,6 +921,13 @@ public final class BatteryService extends SystemService { resolver.registerContentObserver(Settings.System.getUriFor( Settings.System.BATTERY_LIGHT_PULSE), false, this, UserHandle.USER_ALL); + // Notification LED brightness + if (mAdjustableNotificationLedBrightness) { + resolver.registerContentObserver(Settings.System.getUriFor( + Settings.System.NOTIFICATION_LIGHT_BRIGHTNESS_LEVEL), + false, this, UserHandle.USER_ALL); + } + // Light colors if (mMultiColorLed) { // Register observer if we have a multi color led @@ -953,6 +972,13 @@ public final class BatteryService extends SystemService { Settings.System.BATTERY_LIGHT_FULL_COLOR, res.getInteger( com.android.internal.R.integer.config_notificationsBatteryFullARGB)); + // Notification LED brightness + if (mAdjustableNotificationLedBrightness) { + mNotificationLedBrightnessLevel = Settings.System.getInt(resolver, + Settings.System.NOTIFICATION_LIGHT_BRIGHTNESS_LEVEL, + LIGHT_BRIGHTNESS_MAXIMUM); + } + updateLedPulse(); } } diff --git a/services/core/java/com/android/server/lights/Light.java b/services/core/java/com/android/server/lights/Light.java index b496b4c..0f58998 100644 --- a/services/core/java/com/android/server/lights/Light.java +++ b/services/core/java/com/android/server/lights/Light.java @@ -1,5 +1,6 @@ /* * Copyright (C) 2013 The Android Open Source Project + * Copyright (C) 2015 The CyanogenMod Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -35,6 +36,7 @@ public abstract class Light { public abstract void setBrightness(int brightness, int brightnessMode); public abstract void setColor(int color); public abstract void setFlashing(int color, int mode, int onMS, int offMS); + public abstract void setModes(int brightnessLevel); public abstract void pulse(); public abstract void pulse(int color, int onMS); public abstract void turnOff(); diff --git a/services/core/java/com/android/server/lights/LightsService.java b/services/core/java/com/android/server/lights/LightsService.java index ed884ef..587795a 100644 --- a/services/core/java/com/android/server/lights/LightsService.java +++ b/services/core/java/com/android/server/lights/LightsService.java @@ -1,5 +1,6 @@ /* * Copyright (C) 2008 The Android Open Source Project + * Copyright (C) 2015 The CyanogenMod Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -65,6 +66,14 @@ public class LightsService extends SystemService { } @Override + public void setModes(int brightnessLevel) { + synchronized (this) { + mBrightnessLevel = brightnessLevel; + mModesUpdate = true; + } + } + + @Override public void pulse() { pulse(0x00ffffff, 7); } @@ -94,17 +103,20 @@ public class LightsService extends SystemService { } private void setLightLocked(int color, int mode, int onMS, int offMS, int brightnessMode) { - if (color != mColor || mode != mMode || onMS != mOnMS || offMS != mOffMS) { + if (mModesUpdate || color != mColor || mode != mMode || onMS != mOnMS || + offMS != mOffMS) { if (DEBUG) Slog.v(TAG, "setLight #" + mId + ": color=#" + Integer.toHexString(color)); mColor = color; mMode = mode; mOnMS = onMS; mOffMS = offMS; + mModesUpdate = false; Trace.traceBegin(Trace.TRACE_TAG_POWER, "setLight(" + mId + ", 0x" + Integer.toHexString(color) + ")"); try { - setLight_native(mNativePointer, mId, color, mode, onMS, offMS, brightnessMode); + setLight_native(mNativePointer, mId, color, mode, onMS, offMS, brightnessMode, + mBrightnessLevel); } finally { Trace.traceEnd(Trace.TRACE_TAG_POWER); } @@ -116,7 +128,9 @@ public class LightsService extends SystemService { private int mMode; private int mOnMS; private int mOffMS; + private int mBrightnessLevel; private boolean mFlashing; + private boolean mModesUpdate; } public LightsService(Context context) { @@ -163,7 +177,7 @@ public class LightsService extends SystemService { private static native void finalize_native(long ptr); static native void setLight_native(long ptr, int light, int color, int mode, - int onMS, int offMS, int brightnessMode); + int onMS, int offMS, int brightnessMode, int brightnessLevel); private long mNativePointer; } diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java index 073432e..e3781f5 100755 --- a/services/core/java/com/android/server/notification/NotificationManagerService.java +++ b/services/core/java/com/android/server/notification/NotificationManagerService.java @@ -216,6 +216,9 @@ public class NotificationManagerService extends SystemService { /** notification_enqueue status value for an ignored notification. */ private static final int EVENTLOG_ENQUEUE_STATUS_IGNORED = 2; + /** notification light maximum brightness value to use. */ + private static final int LIGHT_BRIGHTNESS_MAXIMUM = 255; + private IActivityManager mAm; AudioManager mAudioManager; AudioManagerInternal mAudioManagerInternal; @@ -235,6 +238,9 @@ public class NotificationManagerService extends SystemService { private int mDefaultNotificationLedOff; private long[] mDefaultVibrationPattern; + private boolean mAdjustableNotificationLedBrightness; + private int mNotificationLedBrightnessLevel = LIGHT_BRIGHTNESS_MAXIMUM; + private boolean mScreenOnEnabled = false; private boolean mScreenOnDefault = false; @@ -884,6 +890,11 @@ public class NotificationManagerService extends SystemService { resolver.registerContentObserver(Settings.Global.getUriFor( Settings.Global.ZEN_DISABLE_DUCKING_DURING_MEDIA_PLAYBACK), false, this, UserHandle.USER_ALL); + if (mAdjustableNotificationLedBrightness) { + resolver.registerContentObserver(Settings.System.getUriFor( + Settings.System.NOTIFICATION_LIGHT_BRIGHTNESS_LEVEL), + false, this, UserHandle.USER_ALL); + } update(null); } @@ -923,6 +934,13 @@ public class NotificationManagerService extends SystemService { UserHandle.USER_CURRENT)); } + // Notification LED brightness + if (mAdjustableNotificationLedBrightness) { + mNotificationLedBrightnessLevel = Settings.System.getIntForUser(resolver, + Settings.System.NOTIFICATION_LIGHT_BRIGHTNESS_LEVEL, + LIGHT_BRIGHTNESS_MAXIMUM, UserHandle.USER_CURRENT); + } + // Notification lights with screen on mScreenOnEnabled = (Settings.System.getIntForUser(resolver, Settings.System.NOTIFICATION_LIGHT_SCREEN_ON, @@ -1061,6 +1079,9 @@ public class NotificationManagerService extends SystemService { VIBRATE_PATTERN_MAXLEN, DEFAULT_VIBRATE_PATTERN); + mAdjustableNotificationLedBrightness = resources.getBoolean( + com.android.internal.R.bool.config_adjustableNotificationLedBrightness); + mUseAttentionLight = resources.getBoolean(R.bool.config_useAttentionLight); // Don't start allowing notifications until the setup wizard has run once. @@ -3307,6 +3328,9 @@ public class NotificationManagerService extends SystemService { ledOffMS = ledno.ledOffMS; } + // update the LEDs modes variables + mNotificationLight.setModes(mNotificationLedBrightnessLevel); + if (mNotificationPulseEnabled) { // pulse repeatedly mNotificationLight.setFlashing(ledARGB, Light.LIGHT_FLASH_TIMED, diff --git a/services/core/jni/com_android_server_lights_LightsService.cpp b/services/core/jni/com_android_server_lights_LightsService.cpp index 9c164ed..954619b 100644 --- a/services/core/jni/com_android_server_lights_LightsService.cpp +++ b/services/core/jni/com_android_server_lights_LightsService.cpp @@ -1,5 +1,6 @@ /* * Copyright (C) 2009 The Android Open Source Project + * Copyright (C) 2015 The CyanogenMod Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -110,15 +111,26 @@ static void finalize_native(JNIEnv* /* env */, jobject /* clazz */, jlong ptr) } static void setLight_native(JNIEnv* /* env */, jobject /* clazz */, jlong ptr, - jint light, jint colorARGB, jint flashMode, jint onMS, jint offMS, jint brightnessMode) + jint light, jint colorARGB, jint flashMode, jint onMS, jint offMS, jint brightnessMode, + jint brightnessLevel) { Devices* devices = (Devices*)ptr; light_state_t state; + int colorAlpha; if (light < 0 || light >= LIGHT_COUNT || devices->lights[light] == NULL) { return ; } + if (brightnessLevel > 0 && brightnessLevel <= 0xFF) { + colorAlpha = (colorARGB & 0xFF000000) >> 24; + if (colorAlpha == 0x00) { + colorAlpha = 0xFF; + } + colorAlpha = (colorAlpha * brightnessLevel) / 0xFF; + colorARGB = (colorAlpha << 24) + (colorARGB & 0x00FFFFFF); + } + memset(&state, 0, sizeof(light_state_t)); state.color = colorARGB; state.flashMode = flashMode; @@ -135,7 +147,7 @@ static void setLight_native(JNIEnv* /* env */, jobject /* clazz */, jlong ptr, static JNINativeMethod method_table[] = { { "init_native", "()J", (void*)init_native }, { "finalize_native", "(J)V", (void*)finalize_native }, - { "setLight_native", "(JIIIIII)V", (void*)setLight_native }, + { "setLight_native", "(JIIIIIII)V", (void*)setLight_native }, }; int register_android_server_LightsService(JNIEnv *env) |