blob: ec73952dacdaf3497ab093d8a4ac71a758f29ef1 [file] [log] [blame]
Todd Poynord7b34772013-08-14 20:42:44 -07001/* Copyright 2013, The Android Open Source Project
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14*/
15
16package android.os;
17
18import android.os.Parcel;
19import android.os.Parcelable;
20
21/**
Todd Poynore35872d2013-12-10 11:57:21 -080022 * Battery properties that may be queried using
23 * {@link BatteryManager#getProperty
24 * BatteryManager.getProperty()}
Todd Poynord7b34772013-08-14 20:42:44 -070025 */
26public class BatteryProperty implements Parcelable {
27 /*
28 * Battery property identifiers. These must match the values in
29 * frameworks/native/include/batteryservice/BatteryService.h
30 */
Todd Poynore35872d2013-12-10 11:57:21 -080031 /** Battery capacity in microampere-hours, as an integer. */
32 public static final int CHARGE_COUNTER = 1;
Todd Poynord7b34772013-08-14 20:42:44 -070033
Todd Poynore35872d2013-12-10 11:57:21 -080034 /**
35 * Instantaneous battery current in microamperes, as an integer. Positive
36 * values indicate net current entering the battery from a charge source,
37 * negative values indicate net current discharging from the battery.
38 */
39 public static final int CURRENT_NOW = 2;
Todd Poynord7b34772013-08-14 20:42:44 -070040
Todd Poynore35872d2013-12-10 11:57:21 -080041 /**
42 * Average battery current in microamperes, as an integer. Positive
43 * values indicate net current entering the battery from a charge source,
44 * negative values indicate net current discharging from the battery.
45 * The time period over which the average is computed may depend on the
46 * fuel gauge hardware and its configuration.
47 */
48 public static final int CURRENT_AVERAGE = 3;
49
50 /**
51 * Remaining battery capacity as an integer percentage of total capacity
52 * (with no fractional part).
53 */
54 public static final int CAPACITY = 4;
55
56 private int mValueInt;
57
58 /**
59 * @hide
60 */
61 public BatteryProperty(int value) {
62 mValueInt = value;
63 }
64
65 /**
66 * @hide
67 */
Todd Poynord7b34772013-08-14 20:42:44 -070068 public BatteryProperty() {
Todd Poynore35872d2013-12-10 11:57:21 -080069 mValueInt = Integer.MIN_VALUE;
70 }
71
72 /**
73 * Return the value of a property of integer type previously queried
74 * via {@link BatteryManager#getProperty
75 * BatteryManager.getProperty()}. If the platform does
76 * not provide the property queried, this value will be
77 * Integer.MIN_VALUE.
78 *
79 * @return The queried property value, or Integer.MIN_VALUE if not supported.
80 */
81 public int getInt() {
82 return mValueInt;
Todd Poynord7b34772013-08-14 20:42:44 -070083 }
84
85 /*
86 * Parcel read/write code must be kept in sync with
87 * frameworks/native/services/batteryservice/BatteryProperty.cpp
88 */
89
90 private BatteryProperty(Parcel p) {
91 readFromParcel(p);
92 }
93
94 public void readFromParcel(Parcel p) {
Todd Poynore35872d2013-12-10 11:57:21 -080095 mValueInt = p.readInt();
Todd Poynord7b34772013-08-14 20:42:44 -070096 }
97
98 public void writeToParcel(Parcel p, int flags) {
Todd Poynore35872d2013-12-10 11:57:21 -080099 p.writeInt(mValueInt);
Todd Poynord7b34772013-08-14 20:42:44 -0700100 }
101
102 public static final Parcelable.Creator<BatteryProperty> CREATOR
103 = new Parcelable.Creator<BatteryProperty>() {
104 public BatteryProperty createFromParcel(Parcel p) {
105 return new BatteryProperty(p);
106 }
107
108 public BatteryProperty[] newArray(int size) {
109 return new BatteryProperty[size];
110 }
111 };
112
113 public int describeContents() {
114 return 0;
115 }
116}