diff --git a/core/api/system-current.txt b/core/api/system-current.txt index 05d7bb6da3615..02ce813cce4e8 100644 --- a/core/api/system-current.txt +++ b/core/api/system-current.txt @@ -6976,12 +6976,14 @@ package android.os { method @NonNull @RequiresPermission(android.Manifest.permission.UPDATE_DEVICE_STATS) public android.os.connectivity.WifiBatteryStats getWifiBatteryStats(); method @RequiresPermission(android.Manifest.permission.UPDATE_DEVICE_STATS) public void reportFullWifiLockAcquiredFromSource(@NonNull android.os.WorkSource); method @RequiresPermission(android.Manifest.permission.UPDATE_DEVICE_STATS) public void reportFullWifiLockReleasedFromSource(@NonNull android.os.WorkSource); + method @RequiresPermission(android.Manifest.permission.UPDATE_DEVICE_STATS) public void reportMobileRadioPowerState(boolean, int) throws java.lang.RuntimeException; method @RequiresPermission(android.Manifest.permission.UPDATE_DEVICE_STATS) public void reportWifiBatchedScanStartedFromSource(@NonNull android.os.WorkSource, @IntRange(from=0) int); method @RequiresPermission(android.Manifest.permission.UPDATE_DEVICE_STATS) public void reportWifiBatchedScanStoppedFromSource(@NonNull android.os.WorkSource); method @RequiresPermission(android.Manifest.permission.UPDATE_DEVICE_STATS) public void reportWifiMulticastDisabled(@NonNull android.os.WorkSource); method @RequiresPermission(android.Manifest.permission.UPDATE_DEVICE_STATS) public void reportWifiMulticastEnabled(@NonNull android.os.WorkSource); method @RequiresPermission(android.Manifest.permission.UPDATE_DEVICE_STATS) public void reportWifiOff(); method @RequiresPermission(android.Manifest.permission.UPDATE_DEVICE_STATS) public void reportWifiOn(); + method @RequiresPermission(android.Manifest.permission.UPDATE_DEVICE_STATS) public void reportWifiRadioPowerState(boolean, int) throws java.lang.RuntimeException; method @RequiresPermission(android.Manifest.permission.UPDATE_DEVICE_STATS) public void reportWifiRssiChanged(@IntRange(from=0xffffff81, to=0) int); method @RequiresPermission(android.Manifest.permission.UPDATE_DEVICE_STATS) public void reportWifiScanStartedFromSource(@NonNull android.os.WorkSource); method @RequiresPermission(android.Manifest.permission.UPDATE_DEVICE_STATS) public void reportWifiScanStoppedFromSource(@NonNull android.os.WorkSource); diff --git a/core/java/android/os/BatteryStatsManager.java b/core/java/android/os/BatteryStatsManager.java index a9585c62866b2..258e58d7d0198 100644 --- a/core/java/android/os/BatteryStatsManager.java +++ b/core/java/android/os/BatteryStatsManager.java @@ -26,6 +26,7 @@ import android.annotation.SystemService; import android.content.Context; import android.os.connectivity.CellularBatteryStats; import android.os.connectivity.WifiBatteryStats; +import android.telephony.DataConnectionRealTimeInfo; import com.android.internal.app.IBatteryStats; @@ -376,4 +377,50 @@ public final class BatteryStatsManager { e.rethrowFromSystemServer(); } } + + /** + * Indicates that the radio power state has changed. + * + * @param isActive indicates if the mobile radio is powered. + * @param uid Uid of this event. For the active state it represents the uid that was responsible + * for waking the radio, or -1 if the system was responsible for waking the radio. + * For inactive state, the UID should always be -1. + * @throws RuntimeException if there are binder remote-invocation errors. + */ + @RequiresPermission(android.Manifest.permission.UPDATE_DEVICE_STATS) + public void reportMobileRadioPowerState(boolean isActive, int uid) throws RuntimeException { + try { + mBatteryStats.noteMobileRadioPowerState(getDataConnectionPowerState(isActive), + SystemClock.elapsedRealtimeNanos(), uid); + } catch (RemoteException e) { + e.rethrowFromSystemServer(); + } + } + + /** + * Indicates that the wifi power state has changed. + * + * @param isActive indicates if the wifi radio is powered. + * @param uid Uid of this event. For the active state it represents the uid that was responsible + * for waking the radio, or -1 if the system was responsible for waking the radio. + * For inactive state, the UID should always be -1. + * @throws RuntimeException if there are binder remote-invocation errors. + */ + @RequiresPermission(android.Manifest.permission.UPDATE_DEVICE_STATS) + public void reportWifiRadioPowerState(boolean isActive, int uid) throws RuntimeException { + try { + mBatteryStats.noteWifiRadioPowerState(getDataConnectionPowerState(isActive), + SystemClock.elapsedRealtimeNanos(), uid); + } catch (RemoteException e) { + e.rethrowFromSystemServer(); + } + } + + private static int getDataConnectionPowerState(boolean isActive) { + // TODO: DataConnectionRealTimeInfo is under telephony package but the constants are used + // for both Wifi and mobile. It would make more sense to separate the constants to a generic + // class or move it to generic package. + return isActive ? DataConnectionRealTimeInfo.DC_POWER_STATE_HIGH + : DataConnectionRealTimeInfo.DC_POWER_STATE_LOW; + } }