• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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.hardware;
18 
19 import android.annotation.FloatRange;
20 import android.annotation.IntDef;
21 import android.os.BatteryManager;
22 
23 import java.lang.annotation.Retention;
24 import java.lang.annotation.RetentionPolicy;
25 
26 /**
27  * The BatteryState class is a representation of a single battery on a device.
28  */
29 public abstract class BatteryState {
30     /** @hide */
31     @Retention(RetentionPolicy.SOURCE)
32     @IntDef(prefix = { "STATUS_" }, value = {
33             STATUS_UNKNOWN,
34             STATUS_CHARGING,
35             STATUS_DISCHARGING,
36             STATUS_NOT_CHARGING,
37             STATUS_FULL
38     })
39     public @interface BatteryStatus {
40     }
41 
42     /** Battery status is unknown. */
43     public static final int STATUS_UNKNOWN = BatteryManager.BATTERY_STATUS_UNKNOWN;
44     /** Battery is charging. */
45     public static final int STATUS_CHARGING = BatteryManager.BATTERY_STATUS_CHARGING;
46     /** Battery is discharging. */
47     public static final int STATUS_DISCHARGING = BatteryManager.BATTERY_STATUS_DISCHARGING;
48     /** Battery is connected to power but not charging. */
49     public static final int STATUS_NOT_CHARGING = BatteryManager.BATTERY_STATUS_NOT_CHARGING;
50     /** Battery is full. */
51     public static final int STATUS_FULL = BatteryManager.BATTERY_STATUS_FULL;
52 
53     /**
54      * Check whether the hardware has a battery.
55      *
56      * @return True if the hardware has a battery, else false.
57      */
isPresent()58     public abstract boolean isPresent();
59 
60     /**
61      * Get the battery status.
62      *
63      * @return the battery status.
64      */
65     @BatteryStatus
getStatus()66     public abstract int getStatus();
67 
68     /**
69      * Get remaining battery capacity as float percentage [0.0f, 1.0f] of total capacity
70      * Returns NaN when battery capacity can't be read.
71      *
72      * @return the battery capacity.
73      */
74     @FloatRange(from = -1.0f, to = 1.0f)
getCapacity()75     public abstract float getCapacity();
76 }
77