Loading api/current.txt +15 −0 Original line number Diff line number Diff line Loading @@ -34297,6 +34297,7 @@ package android.os { } public final class PowerManager { method public int getCurrentThermalStatus(); method public int getLocationPowerSaveMode(); method public boolean isDeviceIdleMode(); method public boolean isIgnoringBatteryOptimizations(java.lang.String); Loading @@ -34307,6 +34308,8 @@ package android.os { method public boolean isWakeLockLevelSupported(int); method public android.os.PowerManager.WakeLock newWakeLock(int, java.lang.String); method public void reboot(java.lang.String); method public void registerThermalStatusCallback(android.os.PowerManager.ThermalStatusCallback, java.util.concurrent.Executor); method public void unregisterThermalStatusCallback(android.os.PowerManager.ThermalStatusCallback); field public static final int ACQUIRE_CAUSES_WAKEUP = 268435456; // 0x10000000 field public static final java.lang.String ACTION_DEVICE_IDLE_MODE_CHANGED = "android.os.action.DEVICE_IDLE_MODE_CHANGED"; field public static final java.lang.String ACTION_POWER_SAVE_MODE_CHANGED = "android.os.action.POWER_SAVE_MODE_CHANGED"; Loading @@ -34321,6 +34324,18 @@ package android.os { field public static final int RELEASE_FLAG_WAIT_FOR_NO_PROXIMITY = 1; // 0x1 field public static final deprecated int SCREEN_BRIGHT_WAKE_LOCK = 10; // 0xa field public static final deprecated int SCREEN_DIM_WAKE_LOCK = 6; // 0x6 field public static final int THERMAL_STATUS_CRITICAL = 4; // 0x4 field public static final int THERMAL_STATUS_EMERGENCY = 5; // 0x5 field public static final int THERMAL_STATUS_LIGHT = 1; // 0x1 field public static final int THERMAL_STATUS_MODERATE = 2; // 0x2 field public static final int THERMAL_STATUS_NONE = 0; // 0x0 field public static final int THERMAL_STATUS_SEVERE = 3; // 0x3 field public static final int THERMAL_STATUS_SHUTDOWN = 6; // 0x6 } public static abstract class PowerManager.ThermalStatusCallback { ctor public PowerManager.ThermalStatusCallback(); method public void onStatusChange(int); } public final class PowerManager.WakeLock { core/java/android/os/PowerManager.java +162 −0 Original line number Diff line number Diff line Loading @@ -17,7 +17,9 @@ package android.os; import android.Manifest.permission; import android.annotation.CallbackExecutor; import android.annotation.IntDef; import android.annotation.NonNull; import android.annotation.RequiresPermission; import android.annotation.SdkConstant; import android.annotation.SystemApi; Loading @@ -25,11 +27,15 @@ import android.annotation.SystemService; import android.annotation.TestApi; import android.content.Context; import android.service.dreams.Sandman; import android.util.ArrayMap; import android.util.Log; import android.util.proto.ProtoOutputStream; import com.android.internal.util.Preconditions; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.util.concurrent.Executor; /** * This class gives you control of the power state of the device. Loading Loading @@ -643,6 +649,9 @@ public final class PowerManager { final IPowerManager mService; final Handler mHandler; IThermalService mThermalService; private ArrayMap<ThermalStatusCallback, IThermalStatusListener> mCallbackMap = new ArrayMap<>(); IDeviceIdleController mIDeviceIdleController; /** Loading Loading @@ -1442,6 +1451,159 @@ public final class PowerManager { com.android.internal.R.bool.config_sustainedPerformanceModeSupported); } /** * Thermal status code: Not under throttling. */ public static final int THERMAL_STATUS_NONE = Temperature.THROTTLING_NONE; /** * Thermal status code: Light throttling where UX is not impacted. */ public static final int THERMAL_STATUS_LIGHT = Temperature.THROTTLING_LIGHT; /** * Thermal status code: Moderate throttling where UX is not largely impacted. */ public static final int THERMAL_STATUS_MODERATE = Temperature.THROTTLING_MODERATE; /** * Thermal status code: Severe throttling where UX is largely impacted. */ public static final int THERMAL_STATUS_SEVERE = Temperature.THROTTLING_SEVERE; /** * Thermal status code: Platform has done everything to reduce power. */ public static final int THERMAL_STATUS_CRITICAL = Temperature.THROTTLING_CRITICAL; /** * Thermal status code: Key components in platform are shutting down due to thermal condition. * Device functionalities will be limited. */ public static final int THERMAL_STATUS_EMERGENCY = Temperature.THROTTLING_EMERGENCY; /** * Thermal status code: Need shutdown immediately. */ public static final int THERMAL_STATUS_SHUTDOWN = Temperature.THROTTLING_SHUTDOWN; /** @hide */ @IntDef(prefix = { "THERMAL_STATUS_" }, value = { THERMAL_STATUS_NONE, THERMAL_STATUS_LIGHT, THERMAL_STATUS_MODERATE, THERMAL_STATUS_SEVERE, THERMAL_STATUS_CRITICAL, THERMAL_STATUS_EMERGENCY, THERMAL_STATUS_SHUTDOWN, }) @Retention(RetentionPolicy.SOURCE) public @interface ThermalStatus {} /** * This function returns the current thermal status of the device. * * @return thermal status as int, {@link #THERMAL_STATUS_NONE} if device in not under * thermal throttling. */ public @ThermalStatus int getCurrentThermalStatus() { synchronized (this) { if (mThermalService == null) { mThermalService = IThermalService.Stub.asInterface( ServiceManager.getService(Context.THERMAL_SERVICE)); } try { return mThermalService.getCurrentThermalStatus(); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } } } /** * Callback passed to * {@link PowerManager#registerThermalStatusCallback} and * {@link PowerManager#unregisterThermalStatusCallback} * to notify caller of thermal status. */ public abstract static class ThermalStatusCallback { /** * Called when overall thermal throttling status changed. * @param status defined in {@link android.os.Temperature}. */ public void onStatusChange(@ThermalStatus int status) {} } /** * This function registers a callback for thermal status change. * * @param callback callback to be registered. * @param executor {@link Executor} to handle the callbacks. */ public void registerThermalStatusCallback( @NonNull ThermalStatusCallback callback, @NonNull @CallbackExecutor Executor executor) { Preconditions.checkNotNull(callback, "callback cannnot be null"); Preconditions.checkNotNull(executor, "executor cannnot be null"); synchronized (this) { if (mThermalService == null) { mThermalService = IThermalService.Stub.asInterface( ServiceManager.getService(Context.THERMAL_SERVICE)); } try { if (mCallbackMap.containsKey(callback)) { throw new IllegalArgumentException("ThermalStatusCallback already registered"); } IThermalStatusListener listener = new IThermalStatusListener.Stub() { @Override public void onStatusChange(int status) { executor.execute(() -> { callback.onStatusChange(status); }); } }; if (mThermalService.registerThermalStatusListener(listener)) { mCallbackMap.put(callback, listener); } else { throw new RuntimeException("ThermalStatusCallback failed to register"); } } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } } } /** * This function unregisters a callback for thermal status change. * * @param callback to be unregistered. * * see {@link #registerThermalStatusCallback} */ public void unregisterThermalStatusCallback(ThermalStatusCallback callback) { Preconditions.checkNotNull(callback, "callback cannnot be null"); synchronized (this) { if (mThermalService == null) { mThermalService = IThermalService.Stub.asInterface( ServiceManager.getService(Context.THERMAL_SERVICE)); } try { IThermalStatusListener listener = mCallbackMap.get(callback); if (listener == null) { throw new IllegalArgumentException("ThermalStatusCallback not registered"); } if (mThermalService.unregisterThermalStatusListener(listener)) { mCallbackMap.remove(callback); } else { throw new RuntimeException("ThermalStatusCallback failed to unregister"); } } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } } } /** * If true, the doze component is not started until after the screen has been * turned off and the screen off animation has been performed. Loading Loading
api/current.txt +15 −0 Original line number Diff line number Diff line Loading @@ -34297,6 +34297,7 @@ package android.os { } public final class PowerManager { method public int getCurrentThermalStatus(); method public int getLocationPowerSaveMode(); method public boolean isDeviceIdleMode(); method public boolean isIgnoringBatteryOptimizations(java.lang.String); Loading @@ -34307,6 +34308,8 @@ package android.os { method public boolean isWakeLockLevelSupported(int); method public android.os.PowerManager.WakeLock newWakeLock(int, java.lang.String); method public void reboot(java.lang.String); method public void registerThermalStatusCallback(android.os.PowerManager.ThermalStatusCallback, java.util.concurrent.Executor); method public void unregisterThermalStatusCallback(android.os.PowerManager.ThermalStatusCallback); field public static final int ACQUIRE_CAUSES_WAKEUP = 268435456; // 0x10000000 field public static final java.lang.String ACTION_DEVICE_IDLE_MODE_CHANGED = "android.os.action.DEVICE_IDLE_MODE_CHANGED"; field public static final java.lang.String ACTION_POWER_SAVE_MODE_CHANGED = "android.os.action.POWER_SAVE_MODE_CHANGED"; Loading @@ -34321,6 +34324,18 @@ package android.os { field public static final int RELEASE_FLAG_WAIT_FOR_NO_PROXIMITY = 1; // 0x1 field public static final deprecated int SCREEN_BRIGHT_WAKE_LOCK = 10; // 0xa field public static final deprecated int SCREEN_DIM_WAKE_LOCK = 6; // 0x6 field public static final int THERMAL_STATUS_CRITICAL = 4; // 0x4 field public static final int THERMAL_STATUS_EMERGENCY = 5; // 0x5 field public static final int THERMAL_STATUS_LIGHT = 1; // 0x1 field public static final int THERMAL_STATUS_MODERATE = 2; // 0x2 field public static final int THERMAL_STATUS_NONE = 0; // 0x0 field public static final int THERMAL_STATUS_SEVERE = 3; // 0x3 field public static final int THERMAL_STATUS_SHUTDOWN = 6; // 0x6 } public static abstract class PowerManager.ThermalStatusCallback { ctor public PowerManager.ThermalStatusCallback(); method public void onStatusChange(int); } public final class PowerManager.WakeLock {
core/java/android/os/PowerManager.java +162 −0 Original line number Diff line number Diff line Loading @@ -17,7 +17,9 @@ package android.os; import android.Manifest.permission; import android.annotation.CallbackExecutor; import android.annotation.IntDef; import android.annotation.NonNull; import android.annotation.RequiresPermission; import android.annotation.SdkConstant; import android.annotation.SystemApi; Loading @@ -25,11 +27,15 @@ import android.annotation.SystemService; import android.annotation.TestApi; import android.content.Context; import android.service.dreams.Sandman; import android.util.ArrayMap; import android.util.Log; import android.util.proto.ProtoOutputStream; import com.android.internal.util.Preconditions; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.util.concurrent.Executor; /** * This class gives you control of the power state of the device. Loading Loading @@ -643,6 +649,9 @@ public final class PowerManager { final IPowerManager mService; final Handler mHandler; IThermalService mThermalService; private ArrayMap<ThermalStatusCallback, IThermalStatusListener> mCallbackMap = new ArrayMap<>(); IDeviceIdleController mIDeviceIdleController; /** Loading Loading @@ -1442,6 +1451,159 @@ public final class PowerManager { com.android.internal.R.bool.config_sustainedPerformanceModeSupported); } /** * Thermal status code: Not under throttling. */ public static final int THERMAL_STATUS_NONE = Temperature.THROTTLING_NONE; /** * Thermal status code: Light throttling where UX is not impacted. */ public static final int THERMAL_STATUS_LIGHT = Temperature.THROTTLING_LIGHT; /** * Thermal status code: Moderate throttling where UX is not largely impacted. */ public static final int THERMAL_STATUS_MODERATE = Temperature.THROTTLING_MODERATE; /** * Thermal status code: Severe throttling where UX is largely impacted. */ public static final int THERMAL_STATUS_SEVERE = Temperature.THROTTLING_SEVERE; /** * Thermal status code: Platform has done everything to reduce power. */ public static final int THERMAL_STATUS_CRITICAL = Temperature.THROTTLING_CRITICAL; /** * Thermal status code: Key components in platform are shutting down due to thermal condition. * Device functionalities will be limited. */ public static final int THERMAL_STATUS_EMERGENCY = Temperature.THROTTLING_EMERGENCY; /** * Thermal status code: Need shutdown immediately. */ public static final int THERMAL_STATUS_SHUTDOWN = Temperature.THROTTLING_SHUTDOWN; /** @hide */ @IntDef(prefix = { "THERMAL_STATUS_" }, value = { THERMAL_STATUS_NONE, THERMAL_STATUS_LIGHT, THERMAL_STATUS_MODERATE, THERMAL_STATUS_SEVERE, THERMAL_STATUS_CRITICAL, THERMAL_STATUS_EMERGENCY, THERMAL_STATUS_SHUTDOWN, }) @Retention(RetentionPolicy.SOURCE) public @interface ThermalStatus {} /** * This function returns the current thermal status of the device. * * @return thermal status as int, {@link #THERMAL_STATUS_NONE} if device in not under * thermal throttling. */ public @ThermalStatus int getCurrentThermalStatus() { synchronized (this) { if (mThermalService == null) { mThermalService = IThermalService.Stub.asInterface( ServiceManager.getService(Context.THERMAL_SERVICE)); } try { return mThermalService.getCurrentThermalStatus(); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } } } /** * Callback passed to * {@link PowerManager#registerThermalStatusCallback} and * {@link PowerManager#unregisterThermalStatusCallback} * to notify caller of thermal status. */ public abstract static class ThermalStatusCallback { /** * Called when overall thermal throttling status changed. * @param status defined in {@link android.os.Temperature}. */ public void onStatusChange(@ThermalStatus int status) {} } /** * This function registers a callback for thermal status change. * * @param callback callback to be registered. * @param executor {@link Executor} to handle the callbacks. */ public void registerThermalStatusCallback( @NonNull ThermalStatusCallback callback, @NonNull @CallbackExecutor Executor executor) { Preconditions.checkNotNull(callback, "callback cannnot be null"); Preconditions.checkNotNull(executor, "executor cannnot be null"); synchronized (this) { if (mThermalService == null) { mThermalService = IThermalService.Stub.asInterface( ServiceManager.getService(Context.THERMAL_SERVICE)); } try { if (mCallbackMap.containsKey(callback)) { throw new IllegalArgumentException("ThermalStatusCallback already registered"); } IThermalStatusListener listener = new IThermalStatusListener.Stub() { @Override public void onStatusChange(int status) { executor.execute(() -> { callback.onStatusChange(status); }); } }; if (mThermalService.registerThermalStatusListener(listener)) { mCallbackMap.put(callback, listener); } else { throw new RuntimeException("ThermalStatusCallback failed to register"); } } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } } } /** * This function unregisters a callback for thermal status change. * * @param callback to be unregistered. * * see {@link #registerThermalStatusCallback} */ public void unregisterThermalStatusCallback(ThermalStatusCallback callback) { Preconditions.checkNotNull(callback, "callback cannnot be null"); synchronized (this) { if (mThermalService == null) { mThermalService = IThermalService.Stub.asInterface( ServiceManager.getService(Context.THERMAL_SERVICE)); } try { IThermalStatusListener listener = mCallbackMap.get(callback); if (listener == null) { throw new IllegalArgumentException("ThermalStatusCallback not registered"); } if (mThermalService.unregisterThermalStatusListener(listener)) { mCallbackMap.remove(callback); } else { throw new RuntimeException("ThermalStatusCallback failed to unregister"); } } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } } } /** * If true, the doze component is not started until after the screen has been * turned off and the screen off animation has been performed. Loading