| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.os; |
| 18 |
|
| 19 |
import android.annotation.IntDef; |
| 20 |
import android.annotation.IntRange; |
| 21 |
import android.annotation.NonNull; |
| 22 |
import android.annotation.Nullable; |
| 23 |
import android.annotation.RequiresPermission; |
| 24 |
import android.annotation.SystemApi; |
| 25 |
import android.annotation.SystemService; |
| 26 |
import android.annotation.TestApi; |
| 27 |
import android.content.Context; |
| 28 |
import android.net.NetworkStack; |
| 29 |
import android.os.connectivity.CellularBatteryStats; |
| 30 |
import android.os.connectivity.WifiBatteryStats; |
| 31 |
import android.telephony.DataConnectionRealTimeInfo; |
| 32 |
|
| 33 |
import com.android.internal.app.IBatteryStats; |
| 34 |
|
| 35 |
import java.lang.annotation.Retention; |
| 36 |
import java.lang.annotation.RetentionPolicy; |
| 37 |
import java.util.List; |
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
@SystemApi |
| 48 |
@SystemService(Context.BATTERY_STATS_SERVICE) |
| 49 |
public final class BatteryStatsManager { |
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
public static final int WIFI_STATE_OFF = 0; |
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
public static final int WIFI_STATE_OFF_SCANNING = 1; |
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
public static final int WIFI_STATE_ON_NO_NETWORKS = 2; |
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
public static final int WIFI_STATE_ON_DISCONNECTED = 3; |
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
public static final int WIFI_STATE_ON_CONNECTED_STA = 4; |
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
public static final int WIFI_STATE_ON_CONNECTED_P2P = 5; |
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
public static final int WIFI_STATE_ON_CONNECTED_STA_P2P = 6; |
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
public static final int WIFI_STATE_SOFT_AP = 7; |
| 87 |
|
| 88 |
|
| 89 |
public static final int NUM_WIFI_STATES = WIFI_STATE_SOFT_AP + 1; |
| 90 |
|
| 91 |
|
| 92 |
@IntDef(prefix = { "WIFI_STATE_" }, value = { |
| 93 |
WIFI_STATE_OFF, |
| 94 |
WIFI_STATE_OFF_SCANNING, |
| 95 |
WIFI_STATE_ON_NO_NETWORKS, |
| 96 |
WIFI_STATE_ON_DISCONNECTED, |
| 97 |
WIFI_STATE_ON_CONNECTED_STA, |
| 98 |
WIFI_STATE_ON_CONNECTED_P2P, |
| 99 |
WIFI_STATE_ON_CONNECTED_STA_P2P, |
| 100 |
WIFI_STATE_SOFT_AP |
| 101 |
}) |
| 102 |
@Retention(RetentionPolicy.SOURCE) |
| 103 |
public @interface WifiState {} |
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
public static final int WIFI_SUPPL_STATE_INVALID = 0; |
| 113 |
|
| 114 |
public static final int WIFI_SUPPL_STATE_DISCONNECTED = 1; |
| 115 |
|
| 116 |
public static final int WIFI_SUPPL_STATE_INTERFACE_DISABLED = 2; |
| 117 |
|
| 118 |
public static final int WIFI_SUPPL_STATE_INACTIVE = 3; |
| 119 |
|
| 120 |
public static final int WIFI_SUPPL_STATE_SCANNING = 4; |
| 121 |
|
| 122 |
public static final int WIFI_SUPPL_STATE_AUTHENTICATING = 5; |
| 123 |
|
| 124 |
public static final int WIFI_SUPPL_STATE_ASSOCIATING = 6; |
| 125 |
|
| 126 |
public static final int WIFI_SUPPL_STATE_ASSOCIATED = 7; |
| 127 |
|
| 128 |
public static final int WIFI_SUPPL_STATE_FOUR_WAY_HANDSHAKE = 8; |
| 129 |
|
| 130 |
public static final int WIFI_SUPPL_STATE_GROUP_HANDSHAKE = 9; |
| 131 |
|
| 132 |
public static final int WIFI_SUPPL_STATE_COMPLETED = 10; |
| 133 |
|
| 134 |
public static final int WIFI_SUPPL_STATE_DORMANT = 11; |
| 135 |
|
| 136 |
public static final int WIFI_SUPPL_STATE_UNINITIALIZED = 12; |
| 137 |
|
| 138 |
|
| 139 |
public static final int NUM_WIFI_SUPPL_STATES = WIFI_SUPPL_STATE_UNINITIALIZED + 1; |
| 140 |
|
| 141 |
|
| 142 |
@IntDef(prefix = { "WIFI_SUPPL_STATE_" }, value = { |
| 143 |
WIFI_SUPPL_STATE_INVALID, |
| 144 |
WIFI_SUPPL_STATE_DISCONNECTED, |
| 145 |
WIFI_SUPPL_STATE_INTERFACE_DISABLED, |
| 146 |
WIFI_SUPPL_STATE_INACTIVE, |
| 147 |
WIFI_SUPPL_STATE_SCANNING, |
| 148 |
WIFI_SUPPL_STATE_AUTHENTICATING, |
| 149 |
WIFI_SUPPL_STATE_ASSOCIATING, |
| 150 |
WIFI_SUPPL_STATE_ASSOCIATED, |
| 151 |
WIFI_SUPPL_STATE_FOUR_WAY_HANDSHAKE, |
| 152 |
WIFI_SUPPL_STATE_GROUP_HANDSHAKE, |
| 153 |
WIFI_SUPPL_STATE_COMPLETED, |
| 154 |
WIFI_SUPPL_STATE_DORMANT, |
| 155 |
WIFI_SUPPL_STATE_UNINITIALIZED, |
| 156 |
}) |
| 157 |
@Retention(RetentionPolicy.SOURCE) |
| 158 |
public @interface WifiSupplState {} |
| 159 |
|
| 160 |
|
| 161 |
private final IBatteryStats mBatteryStats; |
| 162 |
|
| 163 |
|
| 164 |
public BatteryStatsManager(IBatteryStats batteryStats) { |
| 165 |
mBatteryStats = batteryStats; |
| 166 |
} |
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
@RequiresPermission(android.Manifest.permission.BATTERY_STATS) |
| 176 |
@NonNull |
| 177 |
public BatteryUsageStats getBatteryUsageStats() { |
| 178 |
return getBatteryUsageStats(BatteryUsageStatsQuery.DEFAULT); |
| 179 |
} |
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
@RequiresPermission(android.Manifest.permission.BATTERY_STATS) |
| 188 |
@NonNull |
| 189 |
public BatteryUsageStats getBatteryUsageStats(BatteryUsageStatsQuery query) { |
| 190 |
return getBatteryUsageStats(List.of(query)).get(0); |
| 191 |
} |
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
@RequiresPermission(android.Manifest.permission.BATTERY_STATS) |
| 200 |
@NonNull |
| 201 |
public List<BatteryUsageStats> getBatteryUsageStats(List<BatteryUsageStatsQuery> queries) { |
| 202 |
try { |
| 203 |
return mBatteryStats.getBatteryUsageStats(queries); |
| 204 |
} catch (RemoteException e) { |
| 205 |
throw e.rethrowFromSystemServer(); |
| 206 |
} |
| 207 |
} |
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
@RequiresPermission(android.Manifest.permission.UPDATE_DEVICE_STATS) |
| 215 |
public void reportWifiRssiChanged(@IntRange(from = -127, to = 0) int newRssi) { |
| 216 |
try { |
| 217 |
mBatteryStats.noteWifiRssiChanged(newRssi); |
| 218 |
} catch (RemoteException e) { |
| 219 |
e.rethrowFromSystemServer(); |
| 220 |
} |
| 221 |
} |
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
@RequiresPermission(android.Manifest.permission.UPDATE_DEVICE_STATS) |
| 227 |
public void reportWifiOn() { |
| 228 |
try { |
| 229 |
mBatteryStats.noteWifiOn(); |
| 230 |
} catch (RemoteException e) { |
| 231 |
e.rethrowFromSystemServer(); |
| 232 |
} |
| 233 |
} |
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
@RequiresPermission(android.Manifest.permission.UPDATE_DEVICE_STATS) |
| 239 |
public void reportWifiOff() { |
| 240 |
try { |
| 241 |
mBatteryStats.noteWifiOff(); |
| 242 |
} catch (RemoteException e) { |
| 243 |
e.rethrowFromSystemServer(); |
| 244 |
} |
| 245 |
} |
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
@RequiresPermission(android.Manifest.permission.UPDATE_DEVICE_STATS) |
| 254 |
public void reportWifiState(@WifiState int newWifiState, |
| 255 |
@Nullable String accessPoint) { |
| 256 |
try { |
| 257 |
mBatteryStats.noteWifiState(newWifiState, accessPoint); |
| 258 |
} catch (RemoteException e) { |
| 259 |
e.rethrowFromSystemServer(); |
| 260 |
} |
| 261 |
} |
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
@RequiresPermission(android.Manifest.permission.UPDATE_DEVICE_STATS) |
| 269 |
public void reportWifiScanStartedFromSource(@NonNull WorkSource ws) { |
| 270 |
try { |
| 271 |
mBatteryStats.noteWifiScanStartedFromSource(ws); |
| 272 |
} catch (RemoteException e) { |
| 273 |
e.rethrowFromSystemServer(); |
| 274 |
} |
| 275 |
} |
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
@RequiresPermission(android.Manifest.permission.UPDATE_DEVICE_STATS) |
| 283 |
public void reportWifiScanStoppedFromSource(@NonNull WorkSource ws) { |
| 284 |
try { |
| 285 |
mBatteryStats.noteWifiScanStoppedFromSource(ws); |
| 286 |
} catch (RemoteException e) { |
| 287 |
e.rethrowFromSystemServer(); |
| 288 |
} |
| 289 |
} |
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
@RequiresPermission(android.Manifest.permission.UPDATE_DEVICE_STATS) |
| 298 |
public void reportWifiBatchedScanStartedFromSource(@NonNull WorkSource ws, |
| 299 |
@IntRange(from = 0) int csph) { |
| 300 |
try { |
| 301 |
mBatteryStats.noteWifiBatchedScanStartedFromSource(ws, csph); |
| 302 |
} catch (RemoteException e) { |
| 303 |
e.rethrowFromSystemServer(); |
| 304 |
} |
| 305 |
} |
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
@RequiresPermission(android.Manifest.permission.UPDATE_DEVICE_STATS) |
| 313 |
public void reportWifiBatchedScanStoppedFromSource(@NonNull WorkSource ws) { |
| 314 |
try { |
| 315 |
mBatteryStats.noteWifiBatchedScanStoppedFromSource(ws); |
| 316 |
} catch (RemoteException e) { |
| 317 |
e.rethrowFromSystemServer(); |
| 318 |
} |
| 319 |
} |
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
@RequiresPermission(anyOf = { |
| 327 |
android.Manifest.permission.BATTERY_STATS, |
| 328 |
android.Manifest.permission.UPDATE_DEVICE_STATS}) |
| 329 |
public @NonNull CellularBatteryStats getCellularBatteryStats() { |
| 330 |
try { |
| 331 |
return mBatteryStats.getCellularBatteryStats(); |
| 332 |
} catch (RemoteException e) { |
| 333 |
e.rethrowFromSystemServer(); |
| 334 |
return null; |
| 335 |
} |
| 336 |
} |
| 337 |
|
| 338 |
|
| 339 |
|
| 340 |
|
| 341 |
|
| 342 |
|
| 343 |
@RequiresPermission(anyOf = { |
| 344 |
android.Manifest.permission.BATTERY_STATS, |
| 345 |
android.Manifest.permission.UPDATE_DEVICE_STATS}) |
| 346 |
public @NonNull WifiBatteryStats getWifiBatteryStats() { |
| 347 |
try { |
| 348 |
return mBatteryStats.getWifiBatteryStats(); |
| 349 |
} catch (RemoteException e) { |
| 350 |
e.rethrowFromSystemServer(); |
| 351 |
return null; |
| 352 |
} |
| 353 |
} |
| 354 |
|
| 355 |
|
| 356 |
|
| 357 |
|
| 358 |
|
| 359 |
|
| 360 |
@RequiresPermission(android.Manifest.permission.BATTERY_STATS) |
| 361 |
@NonNull |
| 362 |
public WakeLockStats getWakeLockStats() { |
| 363 |
try { |
| 364 |
return mBatteryStats.getWakeLockStats(); |
| 365 |
} catch (RemoteException e) { |
| 366 |
throw e.rethrowFromSystemServer(); |
| 367 |
} |
| 368 |
} |
| 369 |
|
| 370 |
|
| 371 |
|
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
@RequiresPermission(android.Manifest.permission.BATTERY_STATS) |
| 376 |
@NonNull |
| 377 |
public BluetoothBatteryStats getBluetoothBatteryStats() { |
| 378 |
try { |
| 379 |
return mBatteryStats.getBluetoothBatteryStats(); |
| 380 |
} catch (RemoteException e) { |
| 381 |
throw e.rethrowFromSystemServer(); |
| 382 |
} |
| 383 |
} |
| 384 |
|
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
@RequiresPermission(android.Manifest.permission.UPDATE_DEVICE_STATS) |
| 391 |
public void reportFullWifiLockAcquiredFromSource(@NonNull WorkSource ws) { |
| 392 |
try { |
| 393 |
mBatteryStats.noteFullWifiLockAcquiredFromSource(ws); |
| 394 |
} catch (RemoteException e) { |
| 395 |
e.rethrowFromSystemServer(); |
| 396 |
} |
| 397 |
} |
| 398 |
|
| 399 |
|
| 400 |
|
| 401 |
|
| 402 |
|
| 403 |
|
| 404 |
@RequiresPermission(android.Manifest.permission.UPDATE_DEVICE_STATS) |
| 405 |
public void reportFullWifiLockReleasedFromSource(@NonNull WorkSource ws) { |
| 406 |
try { |
| 407 |
mBatteryStats.noteFullWifiLockReleasedFromSource(ws); |
| 408 |
} catch (RemoteException e) { |
| 409 |
e.rethrowFromSystemServer(); |
| 410 |
} |
| 411 |
} |
| 412 |
|
| 413 |
|
| 414 |
|
| 415 |
|
| 416 |
|
| 417 |
|
| 418 |
|
| 419 |
|
| 420 |
@RequiresPermission(android.Manifest.permission.UPDATE_DEVICE_STATS) |
| 421 |
public void reportWifiSupplicantStateChanged(@WifiSupplState int newSupplState, |
| 422 |
boolean failedAuth) { |
| 423 |
try { |
| 424 |
mBatteryStats.noteWifiSupplicantStateChanged(newSupplState, failedAuth); |
| 425 |
} catch (RemoteException e) { |
| 426 |
e.rethrowFromSystemServer(); |
| 427 |
} |
| 428 |
} |
| 429 |
|
| 430 |
|
| 431 |
|
| 432 |
|
| 433 |
|
| 434 |
|
| 435 |
|
| 436 |
@RequiresPermission(android.Manifest.permission.UPDATE_DEVICE_STATS) |
| 437 |
public void reportWifiMulticastEnabled(@NonNull WorkSource ws) { |
| 438 |
try { |
| 439 |
mBatteryStats.noteWifiMulticastEnabled(ws.getAttributionUid()); |
| 440 |
} catch (RemoteException e) { |
| 441 |
e.rethrowFromSystemServer(); |
| 442 |
} |
| 443 |
} |
| 444 |
|
| 445 |
|
| 446 |
|
| 447 |
|
| 448 |
|
| 449 |
|
| 450 |
|
| 451 |
@RequiresPermission(android.Manifest.permission.UPDATE_DEVICE_STATS) |
| 452 |
public void reportWifiMulticastDisabled(@NonNull WorkSource ws) { |
| 453 |
try { |
| 454 |
mBatteryStats.noteWifiMulticastDisabled(ws.getAttributionUid()); |
| 455 |
} catch (RemoteException e) { |
| 456 |
e.rethrowFromSystemServer(); |
| 457 |
} |
| 458 |
} |
| 459 |
|
| 460 |
|
| 461 |
|
| 462 |
|
| 463 |
|
| 464 |
|
| 465 |
|
| 466 |
|
| 467 |
|
| 468 |
@RequiresPermission(android.Manifest.permission.UPDATE_DEVICE_STATS) |
| 469 |
public void reportMobileRadioPowerState(boolean isActive, int uid) { |
| 470 |
try { |
| 471 |
mBatteryStats.noteMobileRadioPowerState(getDataConnectionPowerState(isActive), |
| 472 |
SystemClock.elapsedRealtimeNanos(), uid); |
| 473 |
} catch (RemoteException e) { |
| 474 |
e.rethrowFromSystemServer(); |
| 475 |
} |
| 476 |
} |
| 477 |
|
| 478 |
|
| 479 |
|
| 480 |
|
| 481 |
|
| 482 |
|
| 483 |
|
| 484 |
|
| 485 |
|
| 486 |
@RequiresPermission(android.Manifest.permission.UPDATE_DEVICE_STATS) |
| 487 |
public void reportWifiRadioPowerState(boolean isActive, int uid) { |
| 488 |
try { |
| 489 |
mBatteryStats.noteWifiRadioPowerState(getDataConnectionPowerState(isActive), |
| 490 |
SystemClock.elapsedRealtimeNanos(), uid); |
| 491 |
} catch (RemoteException e) { |
| 492 |
e.rethrowFromSystemServer(); |
| 493 |
} |
| 494 |
} |
| 495 |
|
| 496 |
|
| 497 |
|
| 498 |
|
| 499 |
|
| 500 |
|
| 501 |
|
| 502 |
|
| 503 |
|
| 504 |
@SystemApi(client = SystemApi.Client.MODULE_LIBRARIES) |
| 505 |
@RequiresPermission(anyOf = { |
| 506 |
NetworkStack.PERMISSION_MAINLINE_NETWORK_STACK, |
| 507 |
android.Manifest.permission.NETWORK_STACK}) |
| 508 |
public void reportNetworkInterfaceForTransports(@NonNull String iface, |
| 509 |
@NonNull int[] transportTypes) throws RuntimeException { |
| 510 |
try { |
| 511 |
mBatteryStats.noteNetworkInterfaceForTransports(iface, transportTypes); |
| 512 |
} catch (RemoteException e) { |
| 513 |
e.rethrowFromSystemServer(); |
| 514 |
} |
| 515 |
} |
| 516 |
|
| 517 |
|
| 518 |
|
| 519 |
|
| 520 |
|
| 521 |
|
| 522 |
|
| 523 |
|
| 524 |
@RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) |
| 525 |
public void reportBluetoothOn(int uid, int reason, @NonNull String packageName) { |
| 526 |
try { |
| 527 |
mBatteryStats.noteBluetoothOn(uid, reason, packageName); |
| 528 |
} catch (RemoteException e) { |
| 529 |
e.rethrowFromSystemServer(); |
| 530 |
} |
| 531 |
} |
| 532 |
|
| 533 |
|
| 534 |
|
| 535 |
|
| 536 |
|
| 537 |
|
| 538 |
|
| 539 |
|
| 540 |
@RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) |
| 541 |
public void reportBluetoothOff(int uid, int reason, @NonNull String packageName) { |
| 542 |
try { |
| 543 |
mBatteryStats.noteBluetoothOff(uid, reason, packageName); |
| 544 |
} catch (RemoteException e) { |
| 545 |
e.rethrowFromSystemServer(); |
| 546 |
} |
| 547 |
} |
| 548 |
|
| 549 |
|
| 550 |
|
| 551 |
|
| 552 |
|
| 553 |
|
| 554 |
|
| 555 |
@RequiresPermission(android.Manifest.permission.UPDATE_DEVICE_STATS) |
| 556 |
public void reportBleScanStarted(@NonNull WorkSource ws, boolean isUnoptimized) { |
| 557 |
try { |
| 558 |
mBatteryStats.noteBleScanStarted(ws, isUnoptimized); |
| 559 |
} catch (RemoteException e) { |
| 560 |
e.rethrowFromSystemServer(); |
| 561 |
} |
| 562 |
} |
| 563 |
|
| 564 |
|
| 565 |
|
| 566 |
|
| 567 |
|
| 568 |
|
| 569 |
|
| 570 |
@RequiresPermission(android.Manifest.permission.UPDATE_DEVICE_STATS) |
| 571 |
public void reportBleScanStopped(@NonNull WorkSource ws, boolean isUnoptimized) { |
| 572 |
try { |
| 573 |
mBatteryStats.noteBleScanStopped(ws, isUnoptimized); |
| 574 |
} catch (RemoteException e) { |
| 575 |
e.rethrowFromSystemServer(); |
| 576 |
} |
| 577 |
} |
| 578 |
|
| 579 |
|
| 580 |
|
| 581 |
|
| 582 |
@RequiresPermission(android.Manifest.permission.UPDATE_DEVICE_STATS) |
| 583 |
public void reportBleScanReset() { |
| 584 |
try { |
| 585 |
mBatteryStats.noteBleScanReset(); |
| 586 |
} catch (RemoteException e) { |
| 587 |
e.rethrowFromSystemServer(); |
| 588 |
} |
| 589 |
} |
| 590 |
|
| 591 |
|
| 592 |
|
| 593 |
|
| 594 |
|
| 595 |
|
| 596 |
|
| 597 |
@RequiresPermission(android.Manifest.permission.UPDATE_DEVICE_STATS) |
| 598 |
public void reportBleScanResults(@NonNull WorkSource ws, int numNewResults) { |
| 599 |
try { |
| 600 |
mBatteryStats.noteBleScanResults(ws, numNewResults); |
| 601 |
} catch (RemoteException e) { |
| 602 |
e.rethrowFromSystemServer(); |
| 603 |
} |
| 604 |
} |
| 605 |
|
| 606 |
private static int getDataConnectionPowerState(boolean isActive) { |
| 607 |
|
| 608 |
|
| 609 |
|
| 610 |
return isActive ? DataConnectionRealTimeInfo.DC_POWER_STATE_HIGH |
| 611 |
: DataConnectionRealTimeInfo.DC_POWER_STATE_LOW; |
| 612 |
} |
| 613 |
|
| 614 |
|
| 615 |
|
| 616 |
|
| 617 |
|
| 618 |
@TestApi |
| 619 |
@RequiresPermission(android.Manifest.permission.DEVICE_POWER) |
| 620 |
public void setChargerAcOnline(boolean online, boolean forceUpdate) { |
| 621 |
try { |
| 622 |
mBatteryStats.setChargerAcOnline(online, forceUpdate); |
| 623 |
} catch (RemoteException e) { |
| 624 |
e.rethrowFromSystemServer(); |
| 625 |
} |
| 626 |
} |
| 627 |
|
| 628 |
|
| 629 |
|
| 630 |
|
| 631 |
|
| 632 |
@TestApi |
| 633 |
@RequiresPermission(android.Manifest.permission.DEVICE_POWER) |
| 634 |
public void setBatteryLevel(int level, boolean forceUpdate) { |
| 635 |
try { |
| 636 |
mBatteryStats.setBatteryLevel(level, forceUpdate); |
| 637 |
} catch (RemoteException e) { |
| 638 |
e.rethrowFromSystemServer(); |
| 639 |
} |
| 640 |
} |
| 641 |
|
| 642 |
|
| 643 |
|
| 644 |
|
| 645 |
|
| 646 |
@TestApi |
| 647 |
@RequiresPermission(android.Manifest.permission.DEVICE_POWER) |
| 648 |
public void unplugBattery(boolean forceUpdate) { |
| 649 |
try { |
| 650 |
mBatteryStats.unplugBattery(forceUpdate); |
| 651 |
} catch (RemoteException e) { |
| 652 |
e.rethrowFromSystemServer(); |
| 653 |
} |
| 654 |
} |
| 655 |
|
| 656 |
|
| 657 |
|
| 658 |
|
| 659 |
|
| 660 |
@TestApi |
| 661 |
@RequiresPermission(android.Manifest.permission.DEVICE_POWER) |
| 662 |
public void resetBattery(boolean forceUpdate) { |
| 663 |
try { |
| 664 |
mBatteryStats.resetBattery(forceUpdate); |
| 665 |
} catch (RemoteException e) { |
| 666 |
e.rethrowFromSystemServer(); |
| 667 |
} |
| 668 |
} |
| 669 |
|
| 670 |
|
| 671 |
|
| 672 |
|
| 673 |
|
| 674 |
@TestApi |
| 675 |
@RequiresPermission(android.Manifest.permission.DEVICE_POWER) |
| 676 |
public void suspendBatteryInput() { |
| 677 |
try { |
| 678 |
mBatteryStats.suspendBatteryInput(); |
| 679 |
} catch (RemoteException e) { |
| 680 |
e.rethrowFromSystemServer(); |
| 681 |
} |
| 682 |
} |
| 683 |
} |