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