diff options
| -rw-r--r-- | api/system-current.txt | 2 | ||||
| -rw-r--r-- | core/java/android/os/IPowerManager.aidl | 1 | ||||
| -rw-r--r-- | core/java/android/os/PowerManager.java | 26 | ||||
| -rw-r--r-- | core/res/AndroidManifest.xml | 2 | ||||
| -rw-r--r-- | services/core/java/com/android/server/power/Notifier.java | 38 | ||||
| -rw-r--r-- | services/core/java/com/android/server/power/PowerManagerService.java | 22 |
6 files changed, 90 insertions, 1 deletions
diff --git a/api/system-current.txt b/api/system-current.txt index c3e0e573e02f..fe0e2e4496c3 100644 --- a/api/system-current.txt +++ b/api/system-current.txt @@ -23738,6 +23738,7 @@ package android.os { public final class PowerManager { method public boolean isInteractive(); method public boolean isPowerSaveMode(); + method public boolean isScreenBrightnessBoosted(); method public deprecated boolean isScreenOn(); method public boolean isWakeLockLevelSupported(int); method public android.os.PowerManager.WakeLock newWakeLock(int, java.lang.String); @@ -23745,6 +23746,7 @@ package android.os { method public void userActivity(long, int, int); field public static final int ACQUIRE_CAUSES_WAKEUP = 268435456; // 0x10000000 field public static final java.lang.String ACTION_POWER_SAVE_MODE_CHANGED = "android.os.action.POWER_SAVE_MODE_CHANGED"; + field public static final java.lang.String ACTION_SCREEN_BRIGHTNESS_BOOST_CHANGED = "android.os.action.SCREEN_BRIGHTNESS_BOOST_CHANGED"; field public static final deprecated int FULL_WAKE_LOCK = 26; // 0x1a field public static final int ON_AFTER_RELEASE = 536870912; // 0x20000000 field public static final int PARTIAL_WAKE_LOCK = 1; // 0x1 diff --git a/core/java/android/os/IPowerManager.aidl b/core/java/android/os/IPowerManager.aidl index 16dac7d5ff27..f187934aeec7 100644 --- a/core/java/android/os/IPowerManager.aidl +++ b/core/java/android/os/IPowerManager.aidl @@ -50,6 +50,7 @@ interface IPowerManager void setStayOnSetting(int val); void boostScreenBrightness(long time); + boolean isScreenBrightnessBoosted(); // temporarily overrides the screen brightness settings to allow the user to // see the effect of a settings change without applying it immediately diff --git a/core/java/android/os/PowerManager.java b/core/java/android/os/PowerManager.java index de970cbe525a..0145c965ab78 100644 --- a/core/java/android/os/PowerManager.java +++ b/core/java/android/os/PowerManager.java @@ -712,6 +712,22 @@ public final class PowerManager { } /** + * Returns whether the screen brightness is currently boosted to maximum, caused by a call + * to {@link #boostScreenBrightness(long)}. + * @return {@code True} if the screen brightness is currently boosted. {@code False} otherwise. + * + * @hide + */ + @SystemApi + public boolean isScreenBrightnessBoosted() { + try { + return mService.isScreenBrightnessBoosted(); + } catch (RemoteException e) { + return false; + } + } + + /** * Sets the brightness of the backlights (screen, keyboard, button). * <p> * Requires the {@link android.Manifest.permission#DEVICE_POWER} permission. @@ -892,6 +908,16 @@ public final class PowerManager { public static final String EXTRA_POWER_SAVE_MODE = "mode"; /** + * Intent that is broadcast when the state of {@link #isScreenBrightnessBoosted()} has changed. + * This broadcast is only sent to registered receivers. + * + * @hide + **/ + @SystemApi + public static final String ACTION_SCREEN_BRIGHTNESS_BOOST_CHANGED + = "android.os.action.SCREEN_BRIGHTNESS_BOOST_CHANGED"; + + /** * A wake lock is a mechanism to indicate that your application needs * to have the device stay on. * <p> diff --git a/core/res/AndroidManifest.xml b/core/res/AndroidManifest.xml index 59dafed7c84e..75ba16bcc32c 100644 --- a/core/res/AndroidManifest.xml +++ b/core/res/AndroidManifest.xml @@ -77,6 +77,8 @@ <protected-broadcast android:name="android.os.action.POWER_SAVE_MODE_CHANGED" /> <protected-broadcast android:name="android.os.action.POWER_SAVE_MODE_CHANGING" /> + <protected-broadcast android:name="android.os.action.SCREEN_BRIGHTNESS_BOOST_CHANGED" /> + <protected-broadcast android:name="android.app.action.ENTER_CAR_MODE" /> <protected-broadcast android:name="android.app.action.EXIT_CAR_MODE" /> <protected-broadcast android:name="android.app.action.ENTER_DESK_MODE" /> diff --git a/services/core/java/com/android/server/power/Notifier.java b/services/core/java/com/android/server/power/Notifier.java index 1349926e8697..c48367e3e6d0 100644 --- a/services/core/java/com/android/server/power/Notifier.java +++ b/services/core/java/com/android/server/power/Notifier.java @@ -78,6 +78,7 @@ final class Notifier { private static final int MSG_USER_ACTIVITY = 1; private static final int MSG_BROADCAST = 2; private static final int MSG_WIRELESS_CHARGING_STARTED = 3; + private static final int MSG_SCREEN_BRIGHTNESS_BOOST_CHANGED = 4; private final Object mLock = new Object(); @@ -92,6 +93,7 @@ final class Notifier { private final NotifierHandler mHandler; private final Intent mScreenOnIntent; private final Intent mScreenOffIntent; + private final Intent mScreenBrightnessBoostIntent; // The current interactive state. private int mActualInteractiveState; @@ -128,6 +130,10 @@ final class Notifier { mScreenOffIntent = new Intent(Intent.ACTION_SCREEN_OFF); mScreenOffIntent.addFlags( Intent.FLAG_RECEIVER_REGISTERED_ONLY | Intent.FLAG_RECEIVER_FOREGROUND); + mScreenBrightnessBoostIntent = + new Intent(PowerManager.ACTION_SCREEN_BRIGHTNESS_BOOST_CHANGED); + mScreenBrightnessBoostIntent.addFlags( + Intent.FLAG_RECEIVER_REGISTERED_ONLY | Intent.FLAG_RECEIVER_FOREGROUND); // Initialize interactive state for battery stats. try { @@ -349,6 +355,19 @@ final class Notifier { } /** + * Called when screen brightness boost begins or ends. + */ + public void onScreenBrightnessBoostChanged() { + if (DEBUG) { + Slog.d(TAG, "onScreenBrightnessBoostChanged"); + } + + mSuspendBlocker.acquire(); + Message msg = mHandler.obtainMessage(MSG_SCREEN_BRIGHTNESS_BOOST_CHANGED); + msg.setAsynchronous(true); + mHandler.sendMessage(msg); + } + /** * Called when there has been user activity. */ public void onUserActivity(int event, int uid) { @@ -457,6 +476,22 @@ final class Notifier { } } + private void sendBrightnessBoostChangedBroadcast() { + if (DEBUG) { + Slog.d(TAG, "Sending brightness boost changed broadcast."); + } + + mContext.sendOrderedBroadcastAsUser(mScreenBrightnessBoostIntent, UserHandle.ALL, null, + mScreeBrightnessBoostChangedDone, mHandler, 0, null, null); + } + + private final BroadcastReceiver mScreeBrightnessBoostChangedDone = new BroadcastReceiver() { + @Override + public void onReceive(Context context, Intent intent) { + mSuspendBlocker.release(); + } + }; + private void sendWakeUpBroadcast() { if (DEBUG) { Slog.d(TAG, "Sending wake up broadcast."); @@ -539,6 +574,9 @@ final class Notifier { case MSG_WIRELESS_CHARGING_STARTED: playWirelessChargingStartedSound(); break; + case MSG_SCREEN_BRIGHTNESS_BOOST_CHANGED: + sendBrightnessBoostChangedBroadcast(); + break; } } } diff --git a/services/core/java/com/android/server/power/PowerManagerService.java b/services/core/java/com/android/server/power/PowerManagerService.java index 9e373b72d445..9d6cc5e170c8 100644 --- a/services/core/java/com/android/server/power/PowerManagerService.java +++ b/services/core/java/com/android/server/power/PowerManagerService.java @@ -1900,6 +1900,7 @@ public final class PowerManagerService extends SystemService } } mScreenBrightnessBoostInProgress = false; + mNotifier.onScreenBrightnessBoostChanged(); userActivityNoUpdateLocked(now, PowerManager.USER_ACTIVITY_EVENT_OTHER, 0, Process.SYSTEM_UID); } @@ -2275,7 +2276,10 @@ public final class PowerManagerService extends SystemService Slog.i(TAG, "Brightness boost activated (uid " + uid +")..."); mLastScreenBrightnessBoostTime = eventTime; - mScreenBrightnessBoostInProgress = true; + if (!mScreenBrightnessBoostInProgress) { + mScreenBrightnessBoostInProgress = true; + mNotifier.onScreenBrightnessBoostChanged(); + } mDirty |= DIRTY_SCREEN_BRIGHTNESS_BOOST; userActivityNoUpdateLocked(eventTime, @@ -2284,6 +2288,12 @@ public final class PowerManagerService extends SystemService } } + private boolean isScreenBrightnessBoostedInternal() { + synchronized (mLock) { + return mScreenBrightnessBoostInProgress; + } + } + /** * Called when a screen brightness boost timeout has occurred. * @@ -3218,6 +3228,16 @@ public final class PowerManagerService extends SystemService } @Override // Binder call + public boolean isScreenBrightnessBoosted() { + final long ident = Binder.clearCallingIdentity(); + try { + return isScreenBrightnessBoostedInternal(); + } finally { + Binder.restoreCallingIdentity(ident); + } + } + + @Override // Binder call protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) { if (mContext.checkCallingOrSelfPermission(Manifest.permission.DUMP) != PackageManager.PERMISSION_GRANTED) { |