1 /* 2 * Copyright (C) 2008 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.internal.app; 18 19 import android.bluetooth.BluetoothActivityEnergyInfo; 20 import android.os.BatteryUsageStats; 21 import android.os.BatteryUsageStatsQuery; 22 import android.os.BluetoothBatteryStats; 23 import android.os.ParcelFileDescriptor; 24 import android.os.ResultReceiver; 25 import android.os.WakeLockStats; 26 import android.os.WorkSource; 27 import android.os.connectivity.CellularBatteryStats; 28 import android.os.connectivity.WifiActivityEnergyInfo; 29 import android.os.connectivity.WifiBatteryStats; 30 import android.os.connectivity.GpsBatteryStats; 31 import android.os.health.HealthStatsParceler; 32 import android.telephony.DataConnectionRealTimeInfo; 33 import android.telephony.ModemActivityInfo; 34 import android.telephony.SignalStrength; 35 36 interface IBatteryStats { 37 /** @hide */ 38 const int RESULT_OK = 0; 39 40 /** @hide */ 41 const int RESULT_RUNTIME_EXCEPTION = 1; 42 43 /** @hide */ 44 const int RESULT_SECURITY_EXCEPTION = 2; 45 46 /** @hide */ 47 const String KEY_UID_SNAPSHOTS = "uid_snapshots"; 48 49 /** @hide */ 50 const String KEY_EXCEPTION_MESSAGE = "exception"; 51 52 // These first methods are also called by native code, so must 53 // be kept in sync with frameworks/native/libs/binder/include_batterystats/batterystats/IBatteryStats.h 54 @EnforcePermission("UPDATE_DEVICE_STATS") noteStartSensor(int uid, int sensor)55 void noteStartSensor(int uid, int sensor); 56 @EnforcePermission("UPDATE_DEVICE_STATS") noteStopSensor(int uid, int sensor)57 void noteStopSensor(int uid, int sensor); 58 @EnforcePermission("UPDATE_DEVICE_STATS") noteStartVideo(int uid)59 void noteStartVideo(int uid); 60 @EnforcePermission("UPDATE_DEVICE_STATS") noteStopVideo(int uid)61 void noteStopVideo(int uid); 62 // The audio battery stats interface is oneway to prevent inversion. These calls 63 // are ordered with respect to each other, but not with any other calls. 64 @EnforcePermission("UPDATE_DEVICE_STATS") noteStartAudio(int uid)65 oneway void noteStartAudio(int uid); 66 @EnforcePermission("UPDATE_DEVICE_STATS") noteStopAudio(int uid)67 oneway void noteStopAudio(int uid); 68 @EnforcePermission("UPDATE_DEVICE_STATS") noteResetVideo()69 void noteResetVideo(); 70 @EnforcePermission("UPDATE_DEVICE_STATS") noteResetAudio()71 oneway void noteResetAudio(); 72 @EnforcePermission("UPDATE_DEVICE_STATS") noteFlashlightOn(int uid)73 void noteFlashlightOn(int uid); 74 @EnforcePermission("UPDATE_DEVICE_STATS") noteFlashlightOff(int uid)75 void noteFlashlightOff(int uid); 76 @EnforcePermission("UPDATE_DEVICE_STATS") noteStartCamera(int uid)77 void noteStartCamera(int uid); 78 @EnforcePermission("UPDATE_DEVICE_STATS") noteStopCamera(int uid)79 void noteStopCamera(int uid); 80 @EnforcePermission("UPDATE_DEVICE_STATS") noteResetCamera()81 void noteResetCamera(); 82 @EnforcePermission("UPDATE_DEVICE_STATS") noteResetFlashlight()83 void noteResetFlashlight(); noteWakeupSensorEvent(long elapsedNanos, int uid, int handle)84 void noteWakeupSensorEvent(long elapsedNanos, int uid, int handle); 85 86 // Remaining methods are only used in Java. 87 @EnforcePermission("BATTERY_STATS") getBatteryUsageStats(in List<BatteryUsageStatsQuery> queries)88 List<BatteryUsageStats> getBatteryUsageStats(in List<BatteryUsageStatsQuery> queries); 89 90 // Return true if we see the battery as currently charging. 91 @UnsupportedAppUsage(maxTargetSdk = 30, trackingBug = 170729553) 92 @RequiresNoPermission isCharging()93 boolean isCharging(); 94 95 // Return the computed amount of time remaining on battery, in milliseconds. 96 // Returns -1 if nothing could be computed. 97 @RequiresNoPermission computeBatteryTimeRemaining()98 long computeBatteryTimeRemaining(); 99 100 // Return the computed amount of time remaining to fully charge, in milliseconds. 101 // Returns -1 if nothing could be computed. 102 @UnsupportedAppUsage(maxTargetSdk = 30, trackingBug = 170729553) 103 @RequiresNoPermission computeChargeTimeRemaining()104 long computeChargeTimeRemaining(); 105 106 @EnforcePermission("BATTERY_STATS") computeBatteryScreenOffRealtimeMs()107 long computeBatteryScreenOffRealtimeMs(); 108 @EnforcePermission("BATTERY_STATS") getScreenOffDischargeMah()109 long getScreenOffDischargeMah(); 110 111 @EnforcePermission("UPDATE_DEVICE_STATS") noteEvent(int code, String name, int uid)112 void noteEvent(int code, String name, int uid); 113 114 @EnforcePermission("UPDATE_DEVICE_STATS") noteSyncStart(String name, int uid)115 void noteSyncStart(String name, int uid); 116 @EnforcePermission("UPDATE_DEVICE_STATS") noteSyncFinish(String name, int uid)117 void noteSyncFinish(String name, int uid); 118 @EnforcePermission("UPDATE_DEVICE_STATS") noteJobStart(String name, int uid)119 void noteJobStart(String name, int uid); 120 @EnforcePermission("UPDATE_DEVICE_STATS") noteJobFinish(String name, int uid, int stopReason)121 void noteJobFinish(String name, int uid, int stopReason); 122 123 @EnforcePermission("UPDATE_DEVICE_STATS") noteStartWakelock(int uid, int pid, String name, String historyName, int type, boolean unimportantForLogging)124 void noteStartWakelock(int uid, int pid, String name, String historyName, 125 int type, boolean unimportantForLogging); 126 @EnforcePermission("UPDATE_DEVICE_STATS") noteStopWakelock(int uid, int pid, String name, String historyName, int type)127 void noteStopWakelock(int uid, int pid, String name, String historyName, int type); 128 129 @EnforcePermission("UPDATE_DEVICE_STATS") noteStartWakelockFromSource(in WorkSource ws, int pid, String name, String historyName, int type, boolean unimportantForLogging)130 void noteStartWakelockFromSource(in WorkSource ws, int pid, String name, String historyName, 131 int type, boolean unimportantForLogging); 132 @EnforcePermission("UPDATE_DEVICE_STATS") noteChangeWakelockFromSource(in WorkSource ws, int pid, String name, String histyoryName, int type, in WorkSource newWs, int newPid, String newName, String newHistoryName, int newType, boolean newUnimportantForLogging)133 void noteChangeWakelockFromSource(in WorkSource ws, int pid, String name, String histyoryName, 134 int type, in WorkSource newWs, int newPid, String newName, 135 String newHistoryName, int newType, boolean newUnimportantForLogging); 136 @EnforcePermission("UPDATE_DEVICE_STATS") noteStopWakelockFromSource(in WorkSource ws, int pid, String name, String historyName, int type)137 void noteStopWakelockFromSource(in WorkSource ws, int pid, String name, String historyName, 138 int type); 139 @EnforcePermission("UPDATE_DEVICE_STATS") noteLongPartialWakelockStart(String name, String historyName, int uid)140 void noteLongPartialWakelockStart(String name, String historyName, int uid); 141 @EnforcePermission("UPDATE_DEVICE_STATS") noteLongPartialWakelockStartFromSource(String name, String historyName, in WorkSource workSource)142 void noteLongPartialWakelockStartFromSource(String name, String historyName, 143 in WorkSource workSource); 144 @EnforcePermission("UPDATE_DEVICE_STATS") noteLongPartialWakelockFinish(String name, String historyName, int uid)145 void noteLongPartialWakelockFinish(String name, String historyName, int uid); 146 @EnforcePermission("UPDATE_DEVICE_STATS") noteLongPartialWakelockFinishFromSource(String name, String historyName, in WorkSource workSource)147 void noteLongPartialWakelockFinishFromSource(String name, String historyName, 148 in WorkSource workSource); 149 150 @EnforcePermission("UPDATE_DEVICE_STATS") noteVibratorOn(int uid, long durationMillis)151 void noteVibratorOn(int uid, long durationMillis); 152 @EnforcePermission("UPDATE_DEVICE_STATS") noteVibratorOff(int uid)153 void noteVibratorOff(int uid); 154 @EnforcePermission("UPDATE_DEVICE_STATS") noteGpsChanged(in WorkSource oldSource, in WorkSource newSource)155 void noteGpsChanged(in WorkSource oldSource, in WorkSource newSource); 156 @EnforcePermission("UPDATE_DEVICE_STATS") noteGpsSignalQuality(int signalLevel)157 void noteGpsSignalQuality(int signalLevel); 158 @EnforcePermission("UPDATE_DEVICE_STATS") noteScreenState(int displayId, int state, int reason)159 void noteScreenState(int displayId, int state, int reason); 160 @EnforcePermission("UPDATE_DEVICE_STATS") noteScreenBrightness(int displayId, int brightness)161 void noteScreenBrightness(int displayId, int brightness); 162 @EnforcePermission("UPDATE_DEVICE_STATS") noteUserActivity(int uid, int event)163 void noteUserActivity(int uid, int event); 164 @EnforcePermission("UPDATE_DEVICE_STATS") noteWakeUp(String reason, int reasonUid)165 void noteWakeUp(String reason, int reasonUid); 166 @EnforcePermission("UPDATE_DEVICE_STATS") noteInteractive(boolean interactive)167 void noteInteractive(boolean interactive); 168 @EnforcePermission("UPDATE_DEVICE_STATS") noteConnectivityChanged(int type, String extra)169 void noteConnectivityChanged(int type, String extra); 170 @EnforcePermission("UPDATE_DEVICE_STATS") noteMobileRadioPowerState(int powerState, long timestampNs, int uid)171 void noteMobileRadioPowerState(int powerState, long timestampNs, int uid); 172 @EnforcePermission("UPDATE_DEVICE_STATS") notePhoneOn()173 void notePhoneOn(); 174 @EnforcePermission("UPDATE_DEVICE_STATS") notePhoneOff()175 void notePhoneOff(); 176 @EnforcePermission("UPDATE_DEVICE_STATS") notePhoneSignalStrength(in SignalStrength signalStrength)177 void notePhoneSignalStrength(in SignalStrength signalStrength); 178 @EnforcePermission("UPDATE_DEVICE_STATS") notePhoneDataConnectionState(int dataType, boolean hasData, int serviceType, int nrState, int nrFrequency)179 void notePhoneDataConnectionState(int dataType, boolean hasData, int serviceType, int nrState, 180 int nrFrequency); 181 @EnforcePermission("UPDATE_DEVICE_STATS") notePhoneState(int phoneState)182 void notePhoneState(int phoneState); 183 @EnforcePermission("UPDATE_DEVICE_STATS") noteWifiOn()184 void noteWifiOn(); 185 @EnforcePermission("UPDATE_DEVICE_STATS") noteWifiOff()186 void noteWifiOff(); 187 @EnforcePermission("UPDATE_DEVICE_STATS") noteWifiRunning(in WorkSource ws)188 void noteWifiRunning(in WorkSource ws); 189 @EnforcePermission("UPDATE_DEVICE_STATS") noteWifiRunningChanged(in WorkSource oldWs, in WorkSource newWs)190 void noteWifiRunningChanged(in WorkSource oldWs, in WorkSource newWs); 191 @EnforcePermission("UPDATE_DEVICE_STATS") noteWifiStopped(in WorkSource ws)192 void noteWifiStopped(in WorkSource ws); 193 @EnforcePermission("UPDATE_DEVICE_STATS") noteWifiState(int wifiState, String accessPoint)194 void noteWifiState(int wifiState, String accessPoint); 195 @EnforcePermission("UPDATE_DEVICE_STATS") noteWifiSupplicantStateChanged(int supplState, boolean failedAuth)196 void noteWifiSupplicantStateChanged(int supplState, boolean failedAuth); 197 @EnforcePermission("UPDATE_DEVICE_STATS") noteWifiRssiChanged(int newRssi)198 void noteWifiRssiChanged(int newRssi); 199 @EnforcePermission("UPDATE_DEVICE_STATS") noteFullWifiLockAcquired(int uid)200 void noteFullWifiLockAcquired(int uid); 201 @EnforcePermission("UPDATE_DEVICE_STATS") noteFullWifiLockReleased(int uid)202 void noteFullWifiLockReleased(int uid); 203 @EnforcePermission("UPDATE_DEVICE_STATS") noteWifiScanStarted(int uid)204 void noteWifiScanStarted(int uid); 205 @EnforcePermission("UPDATE_DEVICE_STATS") noteWifiScanStopped(int uid)206 void noteWifiScanStopped(int uid); 207 @EnforcePermission("UPDATE_DEVICE_STATS") noteWifiMulticastEnabled(int uid)208 void noteWifiMulticastEnabled(int uid); 209 @EnforcePermission("UPDATE_DEVICE_STATS") noteWifiMulticastDisabled(int uid)210 void noteWifiMulticastDisabled(int uid); 211 @EnforcePermission("UPDATE_DEVICE_STATS") noteFullWifiLockAcquiredFromSource(in WorkSource ws)212 void noteFullWifiLockAcquiredFromSource(in WorkSource ws); 213 @EnforcePermission("UPDATE_DEVICE_STATS") noteFullWifiLockReleasedFromSource(in WorkSource ws)214 void noteFullWifiLockReleasedFromSource(in WorkSource ws); 215 @EnforcePermission("UPDATE_DEVICE_STATS") noteWifiScanStartedFromSource(in WorkSource ws)216 void noteWifiScanStartedFromSource(in WorkSource ws); 217 @EnforcePermission("UPDATE_DEVICE_STATS") noteWifiScanStoppedFromSource(in WorkSource ws)218 void noteWifiScanStoppedFromSource(in WorkSource ws); 219 @EnforcePermission("UPDATE_DEVICE_STATS") noteWifiBatchedScanStartedFromSource(in WorkSource ws, int csph)220 void noteWifiBatchedScanStartedFromSource(in WorkSource ws, int csph); 221 @EnforcePermission("UPDATE_DEVICE_STATS") noteWifiBatchedScanStoppedFromSource(in WorkSource ws)222 void noteWifiBatchedScanStoppedFromSource(in WorkSource ws); 223 @EnforcePermission("UPDATE_DEVICE_STATS") noteWifiRadioPowerState(int powerState, long timestampNs, int uid)224 void noteWifiRadioPowerState(int powerState, long timestampNs, int uid); 225 @EnforcePermission(anyOf = {"NETWORK_STACK", "android.net.NetworkStack.PERMISSION_MAINLINE_NETWORK_STACK"}) noteNetworkInterfaceForTransports(String iface, in int[] transportTypes)226 void noteNetworkInterfaceForTransports(String iface, in int[] transportTypes); 227 @EnforcePermission("UPDATE_DEVICE_STATS") noteNetworkStatsEnabled()228 void noteNetworkStatsEnabled(); 229 @EnforcePermission("UPDATE_DEVICE_STATS") noteDeviceIdleMode(int mode, String activeReason, int activeUid)230 void noteDeviceIdleMode(int mode, String activeReason, int activeUid); 231 @EnforcePermission("UPDATE_DEVICE_STATS") setBatteryState(int status, int health, int plugType, int level, int temp, int volt, int chargeUAh, int chargeFullUAh, long chargeTimeToFullSeconds)232 void setBatteryState(int status, int health, int plugType, int level, int temp, int volt, 233 int chargeUAh, int chargeFullUAh, long chargeTimeToFullSeconds); 234 235 @UnsupportedAppUsage(maxTargetSdk = 30, trackingBug = 170729553) 236 @EnforcePermission("BATTERY_STATS") getAwakeTimeBattery()237 long getAwakeTimeBattery(); 238 @EnforcePermission("BATTERY_STATS") getAwakeTimePlugged()239 long getAwakeTimePlugged(); 240 241 @EnforcePermission("UPDATE_DEVICE_STATS") noteBleScanStarted(in WorkSource ws, boolean isUnoptimized)242 void noteBleScanStarted(in WorkSource ws, boolean isUnoptimized); 243 @EnforcePermission("UPDATE_DEVICE_STATS") noteBleScanStopped(in WorkSource ws, boolean isUnoptimized)244 void noteBleScanStopped(in WorkSource ws, boolean isUnoptimized); 245 @EnforcePermission("UPDATE_DEVICE_STATS") noteBleScanReset()246 void noteBleScanReset(); 247 @EnforcePermission("UPDATE_DEVICE_STATS") noteBleScanResults(in WorkSource ws, int numNewResults)248 void noteBleScanResults(in WorkSource ws, int numNewResults); 249 250 /** {@hide} */ 251 @EnforcePermission(anyOf = {"UPDATE_DEVICE_STATS", "BATTERY_STATS"}) getCellularBatteryStats()252 CellularBatteryStats getCellularBatteryStats(); 253 254 /** {@hide} */ 255 @EnforcePermission(anyOf = {"UPDATE_DEVICE_STATS", "BATTERY_STATS"}) getWifiBatteryStats()256 WifiBatteryStats getWifiBatteryStats(); 257 258 /** {@hide} */ 259 @EnforcePermission("BATTERY_STATS") getGpsBatteryStats()260 GpsBatteryStats getGpsBatteryStats(); 261 262 /** {@hide} */ 263 @EnforcePermission("BATTERY_STATS") getWakeLockStats()264 WakeLockStats getWakeLockStats(); 265 266 /** {@hide} */ 267 @EnforcePermission("BATTERY_STATS") getBluetoothBatteryStats()268 BluetoothBatteryStats getBluetoothBatteryStats(); 269 270 @PermissionManuallyEnforced takeUidSnapshot(int uid)271 HealthStatsParceler takeUidSnapshot(int uid); 272 @PermissionManuallyEnforced takeUidSnapshots(in int[] uid)273 HealthStatsParceler[] takeUidSnapshots(in int[] uid); 274 275 @PermissionManuallyEnforced takeUidSnapshotsAsync(in int[] uid, in ResultReceiver result)276 oneway void takeUidSnapshotsAsync(in int[] uid, in ResultReceiver result); 277 278 @EnforcePermission("UPDATE_DEVICE_STATS") noteBluetoothControllerActivity(in BluetoothActivityEnergyInfo info)279 oneway void noteBluetoothControllerActivity(in BluetoothActivityEnergyInfo info); 280 @EnforcePermission("UPDATE_DEVICE_STATS") noteModemControllerActivity(in ModemActivityInfo info)281 oneway void noteModemControllerActivity(in ModemActivityInfo info); 282 @EnforcePermission("UPDATE_DEVICE_STATS") noteWifiControllerActivity(in WifiActivityEnergyInfo info)283 oneway void noteWifiControllerActivity(in WifiActivityEnergyInfo info); 284 285 /** {@hide} */ 286 @EnforcePermission("POWER_SAVER") setChargingStateUpdateDelayMillis(int delay)287 boolean setChargingStateUpdateDelayMillis(int delay); 288 289 /** Exposed as a test API. */ 290 @EnforcePermission("DEVICE_POWER") setChargerAcOnline(boolean online, boolean forceUpdate)291 void setChargerAcOnline(boolean online, boolean forceUpdate); 292 /** Exposed as a test API. */ 293 @EnforcePermission("DEVICE_POWER") setBatteryLevel(int level, boolean forceUpdate)294 void setBatteryLevel(int level, boolean forceUpdate); 295 /** Exposed as a test API. */ 296 @EnforcePermission("DEVICE_POWER") unplugBattery(boolean forceUpdate)297 void unplugBattery(boolean forceUpdate); 298 /** Exposed as a test API. */ 299 @EnforcePermission("DEVICE_POWER") resetBattery(boolean forceUpdate)300 void resetBattery(boolean forceUpdate); 301 /** Exposed as a test API. */ 302 @EnforcePermission("DEVICE_POWER") suspendBatteryInput()303 void suspendBatteryInput(); 304 } 305