Debian Codegraph @

core/java/android/os/BatteryStatsManager.java

raw symbols SCIP
1 /*
2 * Copyright (C) 2019 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 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 * This class provides an API surface for internal system components to report events that are
41 * needed for battery usage/estimation and battery blaming for apps.
42 *
43 * Note: This internally uses the same {@link IBatteryStats} binder service as the public
44 * {@link BatteryManager}.
45 * @hide
46 */
47 @SystemApi
48 @SystemService(Context.BATTERY_STATS_SERVICE)
49 public final class BatteryStatsManager {
50 /**
51 * Wifi states.
52 *
53 * @see #noteWifiState(int, String)
54 */
55 /**
56 * Wifi fully off.
57 */
58 public static final int WIFI_STATE_OFF = 0;
59 /**
60 * Wifi connectivity off, but scanning enabled.
61 */
62 public static final int WIFI_STATE_OFF_SCANNING = 1;
63 /**
64 * Wifi on, but no saved infrastructure networks to connect to.
65 */
66 public static final int WIFI_STATE_ON_NO_NETWORKS = 2;
67 /**
68 * Wifi on, but not connected to any infrastructure networks.
69 */
70 public static final int WIFI_STATE_ON_DISCONNECTED = 3;
71 /**
72 * Wifi on and connected to a infrastructure network.
73 */
74 public static final int WIFI_STATE_ON_CONNECTED_STA = 4;
75 /**
76 * Wifi on and connected to a P2P device, but no infrastructure connection to a network.
77 */
78 public static final int WIFI_STATE_ON_CONNECTED_P2P = 5;
79 /**
80 * Wifi on and connected to both a P2P device and infrastructure connection to a network.
81 */
82 public static final int WIFI_STATE_ON_CONNECTED_STA_P2P = 6;
83 /**
84 * SoftAp/Hotspot turned on.
85 */
86 public static final int WIFI_STATE_SOFT_AP = 7;
87
88 /** @hide */
89 public static final int NUM_WIFI_STATES = WIFI_STATE_SOFT_AP + 1;
90
91 /** @hide */
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 * Wifi supplicant daemon states.
107 *
108 * @see android.net.wifi.SupplicantState for detailed description of states.
109 * @see #noteWifiSupplicantStateChanged(int)
110 */
111 /** @see android.net.wifi.SupplicantState#INVALID */
112 public static final int WIFI_SUPPL_STATE_INVALID = 0;
113 /** @see android.net.wifi.SupplicantState#DISCONNECTED*/
114 public static final int WIFI_SUPPL_STATE_DISCONNECTED = 1;
115 /** @see android.net.wifi.SupplicantState#INTERFACE_DISABLED */
116 public static final int WIFI_SUPPL_STATE_INTERFACE_DISABLED = 2;
117 /** @see android.net.wifi.SupplicantState#INACTIVE*/
118 public static final int WIFI_SUPPL_STATE_INACTIVE = 3;
119 /** @see android.net.wifi.SupplicantState#SCANNING*/
120 public static final int WIFI_SUPPL_STATE_SCANNING = 4;
121 /** @see android.net.wifi.SupplicantState#AUTHENTICATING */
122 public static final int WIFI_SUPPL_STATE_AUTHENTICATING = 5;
123 /** @see android.net.wifi.SupplicantState#ASSOCIATING */
124 public static final int WIFI_SUPPL_STATE_ASSOCIATING = 6;
125 /** @see android.net.wifi.SupplicantState#ASSOCIATED */
126 public static final int WIFI_SUPPL_STATE_ASSOCIATED = 7;
127 /** @see android.net.wifi.SupplicantState#FOUR_WAY_HANDSHAKE */
128 public static final int WIFI_SUPPL_STATE_FOUR_WAY_HANDSHAKE = 8;
129 /** @see android.net.wifi.SupplicantState#GROUP_HANDSHAKE */
130 public static final int WIFI_SUPPL_STATE_GROUP_HANDSHAKE = 9;
131 /** @see android.net.wifi.SupplicantState#COMPLETED */
132 public static final int WIFI_SUPPL_STATE_COMPLETED = 10;
133 /** @see android.net.wifi.SupplicantState#DORMANT */
134 public static final int WIFI_SUPPL_STATE_DORMANT = 11;
135 /** @see android.net.wifi.SupplicantState#UNINITIALIZED */
136 public static final int WIFI_SUPPL_STATE_UNINITIALIZED = 12;
137
138 /** @hide */
139 public static final int NUM_WIFI_SUPPL_STATES = WIFI_SUPPL_STATE_UNINITIALIZED + 1;
140
141 /** @hide */
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 /** @hide */
164 public BatteryStatsManager(IBatteryStats batteryStats) {
165 mBatteryStats = batteryStats;
166 }
167
168
169 /**
170 * Returns BatteryUsageStats, which contains power attribution data on a per-subsystem
171 * and per-UID basis.
172 *
173 * @hide
174 */
175 @RequiresPermission(android.Manifest.permission.BATTERY_STATS)
176 @NonNull
177 public BatteryUsageStats getBatteryUsageStats() {
178 return getBatteryUsageStats(BatteryUsageStatsQuery.DEFAULT);
179 }
180
181 /**
182 * Returns BatteryUsageStats, which contains power attribution data on a per-subsystem
183 * and per-UID basis.
184 *
185 * @hide
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 * Returns BatteryUsageStats, which contains power attribution data on a per-subsystem
195 * and per-UID basis.
196 *
197 * @hide
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 * Indicates that the wifi connection RSSI has changed.
211 *
212 * @param newRssi The new RSSI value.
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 * Indicates that wifi was toggled on.
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 * Indicates that wifi was toggled off.
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 * Indicates that wifi state has changed.
249 *
250 * @param newWifiState The new wifi State.
251 * @param accessPoint SSID of the network if wifi is connected to STA, else null.
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 * Indicates that a new wifi scan has started.
265 *
266 * @param ws worksource (to be used for battery blaming).
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 * Indicates that an ongoing wifi scan has stopped.
279 *
280 * @param ws worksource (to be used for battery blaming).
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 * Indicates that a new wifi batched scan has started.
293 *
294 * @param ws worksource (to be used for battery blaming).
295 * @param csph Channels scanned per hour.
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 * Indicates that an ongoing wifi batched scan has stopped.
309 *
310 * @param ws worksource (to be used for battery blaming).
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 * Retrieves all the cellular related battery stats.
323 *
324 * @return Instance of {@link CellularBatteryStats}.
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 * Retrieves all the wifi related battery stats.
340 *
341 * @return Instance of {@link WifiBatteryStats}.
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 * Retrieves accumulate wake lock stats.
357 *
358 * @hide
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 * Retrieves accumulated bluetooth stats.
372 *
373 * @hide
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 * Indicates an app acquiring full wifi lock.
387 *
388 * @param ws worksource (to be used for battery blaming).
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 * Indicates an app releasing full wifi lock.
401 *
402 * @param ws worksource (to be used for battery blaming).
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 * Indicates that supplicant state has changed.
415 *
416 * @param newSupplState The new Supplicant state.
417 * @param failedAuth Boolean indicating whether there was a connection failure due to
418 * authentication failure.
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 * Indicates that an app has acquired the wifi multicast lock.
432 *
433 * @param ws Worksource with the uid of the app that acquired the wifi lock (to be used for
434 * battery blaming).
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 * Indicates that an app has released the wifi multicast lock.
447 *
448 * @param ws Worksource with the uid of the app that released the wifi lock (to be used for
449 * battery blaming).
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 * Indicates that the radio power state has changed.
462 *
463 * @param isActive indicates if the mobile radio is powered.
464 * @param uid Uid of this event. For the active state it represents the uid that was responsible
465 * for waking the radio, or -1 if the system was responsible for waking the radio.
466 * For inactive state, the UID should always be -1.
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 * Indicates that the wifi power state has changed.
480 *
481 * @param isActive indicates if the wifi radio is powered.
482 * @param uid Uid of this event. For the active state it represents the uid that was responsible
483 * for waking the radio, or -1 if the system was responsible for waking the radio.
484 * For inactive state, the UID should always be -1.
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 * Notifies the battery stats of a new interface, and the transport types of the network that
498 * includes that interface.
499 *
500 * @param iface The interface of the network.
501 * @param transportTypes The transport type of the network {@link Transport}.
502 * @hide
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 * Indicates that Bluetooth was toggled on.
519 *
520 * @param uid calling package uid
521 * @param reason why Bluetooth has been turned on
522 * @param packageName package responsible for this change
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 * Indicates that Bluetooth was toggled off.
535 *
536 * @param uid calling package uid
537 * @param reason why Bluetooth has been turned on
538 * @param packageName package responsible for this change
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 * Indicates that a new Bluetooth LE scan has started.
551 *
552 * @param ws worksource (to be used for battery blaming).
553 * @param isUnoptimized whether or not the scan has a filter.
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 * Indicates that an ongoing Bluetooth LE scan has stopped.
566 *
567 * @param ws worksource (to be used for battery blaming).
568 * @param isUnoptimized whether or not the scan has a filter.
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 * Indicates that Bluetooth LE has been reset.
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 * Indicates that Bluetooth LE scan has received new results.
593 *
594 * @param ws worksource (to be used for battery blaming).
595 * @param numNewResults number of results received since last update.
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 // TODO: DataConnectionRealTimeInfo is under telephony package but the constants are used
608 // for both Wifi and mobile. It would make more sense to separate the constants to a
609 // generic class or move it to generic package.
610 return isActive ? DataConnectionRealTimeInfo.DC_POWER_STATE_HIGH
611 : DataConnectionRealTimeInfo.DC_POWER_STATE_LOW;
612 }
613
614 /**
615 * Sets battery AC charger to enabled/disabled, and freezes the battery state.
616 * @hide
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 * Sets battery level, and freezes the battery state.
630 * @hide
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 * Unplugs battery, and freezes the battery state.
644 * @hide
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 * Unfreezes battery state, returning to current hardware values.
658 * @hide
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 * Suspend charging even if plugged in.
672 * @hide
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 }