diff options
| author | Chiachang Wang <chiachangwang@google.com> | 2020-12-21 13:32:41 +0800 |
|---|---|---|
| committer | Chiachang Wang <chiachangwang@google.com> | 2020-12-22 08:39:22 +0800 |
| commit | 3f01a7a8c19f1e9450c001e67a6d0c5dc93aa187 (patch) | |
| tree | 53e86dea9721e775a93a661cb0b9f5e76433a49a /core/java | |
| parent | 4ba82f5dba48100b6050a1c18af3ac9f652123bb (diff) | |
[IT02] Expose system api to report radio power state
In order to support ConnectivityService mainline, the dependency
with NMS should be removed. The idle timer control API should be
replaced with calling INetd interface instead of using NMS hidden
API.
The state reporting will be triggered from updating idle timer
and netd unsolicited interface activity changed events.
BatteryStatsService should be able to get the netd event by
registering the listener directly. This commit exposes two system
APIs to report the radio power state for wifi and mobile for
supporting update idle timer from CS directly to INetd.
Bug: 170598012
Test: make update-api ; m
Change-Id: I286d6aa237ecb2653e1464e26a3581b8eeeb9e63
Diffstat (limited to 'core/java')
| -rw-r--r-- | core/java/android/os/BatteryStatsManager.java | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/core/java/android/os/BatteryStatsManager.java b/core/java/android/os/BatteryStatsManager.java index a9585c62866b..258e58d7d019 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; + } } |
