BatteryProperty.java revision 540f4d6db34905b38ee1095ef35fe98d3fa38a9e
1d7b34771cbb89c056e7c0f8976db431cad1ace8cTodd Poynor/* Copyright 2013, The Android Open Source Project
2d7b34771cbb89c056e7c0f8976db431cad1ace8cTodd Poynor *
3d7b34771cbb89c056e7c0f8976db431cad1ace8cTodd Poynor * Licensed under the Apache License, Version 2.0 (the "License");
4d7b34771cbb89c056e7c0f8976db431cad1ace8cTodd Poynor * you may not use this file except in compliance with the License.
5d7b34771cbb89c056e7c0f8976db431cad1ace8cTodd Poynor * You may obtain a copy of the License at
6d7b34771cbb89c056e7c0f8976db431cad1ace8cTodd Poynor *
7d7b34771cbb89c056e7c0f8976db431cad1ace8cTodd Poynor *     http://www.apache.org/licenses/LICENSE-2.0
8d7b34771cbb89c056e7c0f8976db431cad1ace8cTodd Poynor *
9d7b34771cbb89c056e7c0f8976db431cad1ace8cTodd Poynor * Unless required by applicable law or agreed to in writing, software
10d7b34771cbb89c056e7c0f8976db431cad1ace8cTodd Poynor * distributed under the License is distributed on an "AS IS" BASIS,
11d7b34771cbb89c056e7c0f8976db431cad1ace8cTodd Poynor * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12d7b34771cbb89c056e7c0f8976db431cad1ace8cTodd Poynor * See the License for the specific language governing permissions and
13d7b34771cbb89c056e7c0f8976db431cad1ace8cTodd Poynor * limitations under the License.
14d7b34771cbb89c056e7c0f8976db431cad1ace8cTodd Poynor*/
15d7b34771cbb89c056e7c0f8976db431cad1ace8cTodd Poynor
16d7b34771cbb89c056e7c0f8976db431cad1ace8cTodd Poynorpackage android.os;
17d7b34771cbb89c056e7c0f8976db431cad1ace8cTodd Poynor
18d7b34771cbb89c056e7c0f8976db431cad1ace8cTodd Poynorimport android.os.Parcel;
19d7b34771cbb89c056e7c0f8976db431cad1ace8cTodd Poynorimport android.os.Parcelable;
20d7b34771cbb89c056e7c0f8976db431cad1ace8cTodd Poynor
21d7b34771cbb89c056e7c0f8976db431cad1ace8cTodd Poynor/**
22e35872da97ac6bd07d2d9ac5af8a7c18ad290718Todd Poynor * Battery properties that may be queried using
23e35872da97ac6bd07d2d9ac5af8a7c18ad290718Todd Poynor * {@link BatteryManager#getProperty
24e35872da97ac6bd07d2d9ac5af8a7c18ad290718Todd Poynor * BatteryManager.getProperty()}
25d7b34771cbb89c056e7c0f8976db431cad1ace8cTodd Poynor */
26d7b34771cbb89c056e7c0f8976db431cad1ace8cTodd Poynorpublic class BatteryProperty implements Parcelable {
27d7b34771cbb89c056e7c0f8976db431cad1ace8cTodd Poynor    /*
28d7b34771cbb89c056e7c0f8976db431cad1ace8cTodd Poynor     * Battery property identifiers.  These must match the values in
29d7b34771cbb89c056e7c0f8976db431cad1ace8cTodd Poynor     * frameworks/native/include/batteryservice/BatteryService.h
30d7b34771cbb89c056e7c0f8976db431cad1ace8cTodd Poynor     */
31e35872da97ac6bd07d2d9ac5af8a7c18ad290718Todd Poynor    /** Battery capacity in microampere-hours, as an integer. */
32e35872da97ac6bd07d2d9ac5af8a7c18ad290718Todd Poynor    public static final int CHARGE_COUNTER = 1;
33d7b34771cbb89c056e7c0f8976db431cad1ace8cTodd Poynor
34e35872da97ac6bd07d2d9ac5af8a7c18ad290718Todd Poynor    /**
35e35872da97ac6bd07d2d9ac5af8a7c18ad290718Todd Poynor     * Instantaneous battery current in microamperes, as an integer.  Positive
36e35872da97ac6bd07d2d9ac5af8a7c18ad290718Todd Poynor     * values indicate net current entering the battery from a charge source,
37e35872da97ac6bd07d2d9ac5af8a7c18ad290718Todd Poynor     * negative values indicate net current discharging from the battery.
38e35872da97ac6bd07d2d9ac5af8a7c18ad290718Todd Poynor     */
39e35872da97ac6bd07d2d9ac5af8a7c18ad290718Todd Poynor    public static final int CURRENT_NOW = 2;
40e35872da97ac6bd07d2d9ac5af8a7c18ad290718Todd Poynor
41e35872da97ac6bd07d2d9ac5af8a7c18ad290718Todd Poynor    /**
42e35872da97ac6bd07d2d9ac5af8a7c18ad290718Todd Poynor     * Average battery current in microamperes, as an integer.  Positive
43e35872da97ac6bd07d2d9ac5af8a7c18ad290718Todd Poynor     * values indicate net current entering the battery from a charge source,
44e35872da97ac6bd07d2d9ac5af8a7c18ad290718Todd Poynor     * negative values indicate net current discharging from the battery.
45e35872da97ac6bd07d2d9ac5af8a7c18ad290718Todd Poynor     * The time period over which the average is computed may depend on the
46e35872da97ac6bd07d2d9ac5af8a7c18ad290718Todd Poynor     * fuel gauge hardware and its configuration.
47e35872da97ac6bd07d2d9ac5af8a7c18ad290718Todd Poynor     */
48e35872da97ac6bd07d2d9ac5af8a7c18ad290718Todd Poynor    public static final int CURRENT_AVERAGE = 3;
49d7b34771cbb89c056e7c0f8976db431cad1ace8cTodd Poynor
50e35872da97ac6bd07d2d9ac5af8a7c18ad290718Todd Poynor    /**
51e35872da97ac6bd07d2d9ac5af8a7c18ad290718Todd Poynor     * Remaining battery capacity as an integer percentage of total capacity
52e35872da97ac6bd07d2d9ac5af8a7c18ad290718Todd Poynor     * (with no fractional part).
53e35872da97ac6bd07d2d9ac5af8a7c18ad290718Todd Poynor     */
54e35872da97ac6bd07d2d9ac5af8a7c18ad290718Todd Poynor    public static final int CAPACITY = 4;
55e35872da97ac6bd07d2d9ac5af8a7c18ad290718Todd Poynor
56e35872da97ac6bd07d2d9ac5af8a7c18ad290718Todd Poynor    /**
57540f4d6db34905b38ee1095ef35fe98d3fa38a9eTodd Poynor     * Battery remaining energy in nanowatt-hours, as a long integer.
58e35872da97ac6bd07d2d9ac5af8a7c18ad290718Todd Poynor     */
59540f4d6db34905b38ee1095ef35fe98d3fa38a9eTodd Poynor    public static final int ENERGY_COUNTER = 4;
60540f4d6db34905b38ee1095ef35fe98d3fa38a9eTodd Poynor
61540f4d6db34905b38ee1095ef35fe98d3fa38a9eTodd Poynor    private long mValueLong;
62e35872da97ac6bd07d2d9ac5af8a7c18ad290718Todd Poynor
63e35872da97ac6bd07d2d9ac5af8a7c18ad290718Todd Poynor    /**
64e35872da97ac6bd07d2d9ac5af8a7c18ad290718Todd Poynor     * @hide
65e35872da97ac6bd07d2d9ac5af8a7c18ad290718Todd Poynor     */
66d7b34771cbb89c056e7c0f8976db431cad1ace8cTodd Poynor    public BatteryProperty() {
67540f4d6db34905b38ee1095ef35fe98d3fa38a9eTodd Poynor        mValueLong = Long.MIN_VALUE;
68e35872da97ac6bd07d2d9ac5af8a7c18ad290718Todd Poynor    }
69e35872da97ac6bd07d2d9ac5af8a7c18ad290718Todd Poynor
70e35872da97ac6bd07d2d9ac5af8a7c18ad290718Todd Poynor    /**
71e35872da97ac6bd07d2d9ac5af8a7c18ad290718Todd Poynor     * Return the value of a property of integer type previously queried
72e35872da97ac6bd07d2d9ac5af8a7c18ad290718Todd Poynor     * via {@link BatteryManager#getProperty
73e35872da97ac6bd07d2d9ac5af8a7c18ad290718Todd Poynor     * BatteryManager.getProperty()}.  If the platform does
74e35872da97ac6bd07d2d9ac5af8a7c18ad290718Todd Poynor     * not provide the property queried, this value will be
75e35872da97ac6bd07d2d9ac5af8a7c18ad290718Todd Poynor     * Integer.MIN_VALUE.
76e35872da97ac6bd07d2d9ac5af8a7c18ad290718Todd Poynor     *
77e35872da97ac6bd07d2d9ac5af8a7c18ad290718Todd Poynor     * @return The queried property value, or Integer.MIN_VALUE if not supported.
78e35872da97ac6bd07d2d9ac5af8a7c18ad290718Todd Poynor     */
79e35872da97ac6bd07d2d9ac5af8a7c18ad290718Todd Poynor    public int getInt() {
80540f4d6db34905b38ee1095ef35fe98d3fa38a9eTodd Poynor        return (int)mValueLong;
81d7b34771cbb89c056e7c0f8976db431cad1ace8cTodd Poynor    }
82d7b34771cbb89c056e7c0f8976db431cad1ace8cTodd Poynor
83540f4d6db34905b38ee1095ef35fe98d3fa38a9eTodd Poynor    /**
84540f4d6db34905b38ee1095ef35fe98d3fa38a9eTodd Poynor     * Return the value of a property of long type previously queried
85540f4d6db34905b38ee1095ef35fe98d3fa38a9eTodd Poynor     * via {@link BatteryManager#getProperty
86540f4d6db34905b38ee1095ef35fe98d3fa38a9eTodd Poynor     * BatteryManager.getProperty()}.  If the platform does
87540f4d6db34905b38ee1095ef35fe98d3fa38a9eTodd Poynor     * not provide the property queried, this value will be
88540f4d6db34905b38ee1095ef35fe98d3fa38a9eTodd Poynor     * Long.MIN_VALUE.
89540f4d6db34905b38ee1095ef35fe98d3fa38a9eTodd Poynor     *
90540f4d6db34905b38ee1095ef35fe98d3fa38a9eTodd Poynor     * @return The queried property value, or Long.MIN_VALUE if not supported.
91540f4d6db34905b38ee1095ef35fe98d3fa38a9eTodd Poynor     */
92540f4d6db34905b38ee1095ef35fe98d3fa38a9eTodd Poynor    public long getLong() {
93540f4d6db34905b38ee1095ef35fe98d3fa38a9eTodd Poynor        return mValueLong;
94540f4d6db34905b38ee1095ef35fe98d3fa38a9eTodd Poynor    }
95d7b34771cbb89c056e7c0f8976db431cad1ace8cTodd Poynor    /*
96d7b34771cbb89c056e7c0f8976db431cad1ace8cTodd Poynor     * Parcel read/write code must be kept in sync with
97d7b34771cbb89c056e7c0f8976db431cad1ace8cTodd Poynor     * frameworks/native/services/batteryservice/BatteryProperty.cpp
98d7b34771cbb89c056e7c0f8976db431cad1ace8cTodd Poynor     */
99d7b34771cbb89c056e7c0f8976db431cad1ace8cTodd Poynor
100d7b34771cbb89c056e7c0f8976db431cad1ace8cTodd Poynor    private BatteryProperty(Parcel p) {
101d7b34771cbb89c056e7c0f8976db431cad1ace8cTodd Poynor        readFromParcel(p);
102d7b34771cbb89c056e7c0f8976db431cad1ace8cTodd Poynor    }
103d7b34771cbb89c056e7c0f8976db431cad1ace8cTodd Poynor
104d7b34771cbb89c056e7c0f8976db431cad1ace8cTodd Poynor    public void readFromParcel(Parcel p) {
105540f4d6db34905b38ee1095ef35fe98d3fa38a9eTodd Poynor        mValueLong = p.readLong();
106d7b34771cbb89c056e7c0f8976db431cad1ace8cTodd Poynor    }
107d7b34771cbb89c056e7c0f8976db431cad1ace8cTodd Poynor
108d7b34771cbb89c056e7c0f8976db431cad1ace8cTodd Poynor    public void writeToParcel(Parcel p, int flags) {
109540f4d6db34905b38ee1095ef35fe98d3fa38a9eTodd Poynor        p.writeLong(mValueLong);
110d7b34771cbb89c056e7c0f8976db431cad1ace8cTodd Poynor    }
111d7b34771cbb89c056e7c0f8976db431cad1ace8cTodd Poynor
112d7b34771cbb89c056e7c0f8976db431cad1ace8cTodd Poynor    public static final Parcelable.Creator<BatteryProperty> CREATOR
113d7b34771cbb89c056e7c0f8976db431cad1ace8cTodd Poynor        = new Parcelable.Creator<BatteryProperty>() {
114d7b34771cbb89c056e7c0f8976db431cad1ace8cTodd Poynor        public BatteryProperty createFromParcel(Parcel p) {
115d7b34771cbb89c056e7c0f8976db431cad1ace8cTodd Poynor            return new BatteryProperty(p);
116d7b34771cbb89c056e7c0f8976db431cad1ace8cTodd Poynor        }
117d7b34771cbb89c056e7c0f8976db431cad1ace8cTodd Poynor
118d7b34771cbb89c056e7c0f8976db431cad1ace8cTodd Poynor        public BatteryProperty[] newArray(int size) {
119d7b34771cbb89c056e7c0f8976db431cad1ace8cTodd Poynor            return new BatteryProperty[size];
120d7b34771cbb89c056e7c0f8976db431cad1ace8cTodd Poynor        }
121d7b34771cbb89c056e7c0f8976db431cad1ace8cTodd Poynor    };
122d7b34771cbb89c056e7c0f8976db431cad1ace8cTodd Poynor
123d7b34771cbb89c056e7c0f8976db431cad1ace8cTodd Poynor    public int describeContents() {
124d7b34771cbb89c056e7c0f8976db431cad1ace8cTodd Poynor        return 0;
125d7b34771cbb89c056e7c0f8976db431cad1ace8cTodd Poynor    }
126d7b34771cbb89c056e7c0f8976db431cad1ace8cTodd Poynor}
127