BatteryProperty.java revision 540f4d6db34905b38ee1095ef35fe98d3fa38a9e
1/* 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/**
22 * Battery properties that may be queried using
23 * {@link BatteryManager#getProperty
24 * BatteryManager.getProperty()}
25 */
26public class BatteryProperty implements Parcelable {
27    /*
28     * Battery property identifiers.  These must match the values in
29     * frameworks/native/include/batteryservice/BatteryService.h
30     */
31    /** Battery capacity in microampere-hours, as an integer. */
32    public static final int CHARGE_COUNTER = 1;
33
34    /**
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;
40
41    /**
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    /**
57     * Battery remaining energy in nanowatt-hours, as a long integer.
58     */
59    public static final int ENERGY_COUNTER = 4;
60
61    private long mValueLong;
62
63    /**
64     * @hide
65     */
66    public BatteryProperty() {
67        mValueLong = Long.MIN_VALUE;
68    }
69
70    /**
71     * Return the value of a property of integer type previously queried
72     * via {@link BatteryManager#getProperty
73     * BatteryManager.getProperty()}.  If the platform does
74     * not provide the property queried, this value will be
75     * Integer.MIN_VALUE.
76     *
77     * @return The queried property value, or Integer.MIN_VALUE if not supported.
78     */
79    public int getInt() {
80        return (int)mValueLong;
81    }
82
83    /**
84     * Return the value of a property of long type previously queried
85     * via {@link BatteryManager#getProperty
86     * BatteryManager.getProperty()}.  If the platform does
87     * not provide the property queried, this value will be
88     * Long.MIN_VALUE.
89     *
90     * @return The queried property value, or Long.MIN_VALUE if not supported.
91     */
92    public long getLong() {
93        return mValueLong;
94    }
95    /*
96     * Parcel read/write code must be kept in sync with
97     * frameworks/native/services/batteryservice/BatteryProperty.cpp
98     */
99
100    private BatteryProperty(Parcel p) {
101        readFromParcel(p);
102    }
103
104    public void readFromParcel(Parcel p) {
105        mValueLong = p.readLong();
106    }
107
108    public void writeToParcel(Parcel p, int flags) {
109        p.writeLong(mValueLong);
110    }
111
112    public static final Parcelable.Creator<BatteryProperty> CREATOR
113        = new Parcelable.Creator<BatteryProperty>() {
114        public BatteryProperty createFromParcel(Parcel p) {
115            return new BatteryProperty(p);
116        }
117
118        public BatteryProperty[] newArray(int size) {
119            return new BatteryProperty[size];
120        }
121    };
122
123    public int describeContents() {
124        return 0;
125    }
126}
127