diff options
author | Dianne Hackborn <hackbod@google.com> | 2015-06-12 18:11:41 -0700 |
---|---|---|
committer | Dianne Hackborn <hackbod@google.com> | 2015-06-15 11:53:59 -0700 |
commit | 1958e5e7870579337f1d1d3e6c6fae096ba3abb9 (patch) | |
tree | fad208704fc337915aff86df8021895eb1910701 /core/java | |
parent | f63655e49fcccd922e8d5f61c67f58bd4a361211 (diff) | |
download | frameworks_base-1958e5e7870579337f1d1d3e6c6fae096ba3abb9.zip frameworks_base-1958e5e7870579337f1d1d3e6c6fae096ba3abb9.tar.gz frameworks_base-1958e5e7870579337f1d1d3e6c6fae096ba3abb9.tar.bz2 |
Fix issue #21813831: Need API for asking to be added to power whitelist
Add the API. Clean up a few related things.
Change-Id: I190adad1812f36f6095b98a1001fedb94874e8b5
Diffstat (limited to 'core/java')
-rw-r--r-- | core/java/android/content/Context.java | 8 | ||||
-rw-r--r-- | core/java/android/os/PowerManager.java | 21 | ||||
-rw-r--r-- | core/java/android/provider/Settings.java | 9 |
3 files changed, 34 insertions, 4 deletions
diff --git a/core/java/android/content/Context.java b/core/java/android/content/Context.java index 970623a..83ce087 100644 --- a/core/java/android/content/Context.java +++ b/core/java/android/content/Context.java @@ -2248,6 +2248,7 @@ public abstract class Context { //@hide: VOICE_INTERACTION_MANAGER_SERVICE, //@hide: BACKUP_SERVICE, DROPBOX_SERVICE, + //@hide: DEVICE_IDLE_CONTROLLER, DEVICE_POLICY_SERVICE, UI_MODE_SERVICE, DOWNLOAD_SERVICE, @@ -2874,6 +2875,13 @@ public abstract class Context { public static final String DROPBOX_SERVICE = "dropbox"; /** + * System service name for the DeviceIdleController. There is no Java API for this. + * @see #getSystemService + * @hide + */ + public static final String DEVICE_IDLE_CONTROLLER = "deviceidle"; + + /** * Use with {@link #getSystemService} to retrieve a * {@link android.app.admin.DevicePolicyManager} for working with global * device policy management. diff --git a/core/java/android/os/PowerManager.java b/core/java/android/os/PowerManager.java index 7a1aa1e..6ef1cd0 100644 --- a/core/java/android/os/PowerManager.java +++ b/core/java/android/os/PowerManager.java @@ -392,6 +392,8 @@ public final class PowerManager { final IPowerManager mService; final Handler mHandler; + IDeviceIdleController mIDeviceIdleController; + /** * {@hide} */ @@ -892,6 +894,25 @@ public final class PowerManager { } /** + * Return whether the given application package name is on the device's power whitelist. + * Apps can be placed on the whitelist through the settings UI invoked by + * {@link android.provider.Settings#ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS}. + */ + public boolean isIgnoringBatteryOptimizations(String packageName) { + synchronized (this) { + if (mIDeviceIdleController == null) { + mIDeviceIdleController = IDeviceIdleController.Stub.asInterface( + ServiceManager.getService(Context.DEVICE_IDLE_CONTROLLER)); + } + } + try { + return mIDeviceIdleController.isPowerSaveWhitelistApp(packageName); + } catch (RemoteException e) { + return false; + } + } + + /** * Turn off the device. * * @param confirm If true, shows a shutdown confirmation dialog. diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java index e335f6d..dfd72c2 100644 --- a/core/java/android/provider/Settings.java +++ b/core/java/android/provider/Settings.java @@ -579,13 +579,14 @@ public final class Settings { /** * Activity Action: Show screen for controlling which apps can ignore battery optimizations. * <p> - * In some cases, a matching Activity may not exist, so ensure you - * safeguard against this. - * <p> - * Input: The Intent's data URI specifies the application package name + * Input: Optionally, the Intent's data URI specifies the application package name * to be shown, with the "package" scheme. That is "package:com.my.app". * <p> * Output: Nothing. + * <p> + * You can use {@link android.os.PowerManager#isIgnoringBatteryOptimizations + * PowerManager.isIgnoringBatteryOptimizations()} to determine if an application is + * already ignoring optimizations. */ @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) public static final String ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS = |