Todd Poynor | d7b3477 | 2013-08-14 20:42:44 -0700 | [diff] [blame] | 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 | |
| 16 | package android.os; |
| 17 | |
| 18 | import android.os.Parcel; |
| 19 | import android.os.Parcelable; |
| 20 | |
| 21 | /** |
Todd Poynor | e35872d | 2013-12-10 11:57:21 -0800 | [diff] [blame] | 22 | * Battery properties that may be queried using |
| 23 | * {@link BatteryManager#getProperty |
| 24 | * BatteryManager.getProperty()} |
Todd Poynor | d7b3477 | 2013-08-14 20:42:44 -0700 | [diff] [blame] | 25 | */ |
| 26 | public class BatteryProperty implements Parcelable { |
| 27 | /* |
| 28 | * Battery property identifiers. These must match the values in |
| 29 | * frameworks/native/include/batteryservice/BatteryService.h |
| 30 | */ |
Todd Poynor | e35872d | 2013-12-10 11:57:21 -0800 | [diff] [blame] | 31 | /** Battery capacity in microampere-hours, as an integer. */ |
| 32 | public static final int CHARGE_COUNTER = 1; |
Todd Poynor | d7b3477 | 2013-08-14 20:42:44 -0700 | [diff] [blame] | 33 | |
Todd Poynor | e35872d | 2013-12-10 11:57:21 -0800 | [diff] [blame] | 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; |
Todd Poynor | d7b3477 | 2013-08-14 20:42:44 -0700 | [diff] [blame] | 40 | |
Todd Poynor | e35872d | 2013-12-10 11:57:21 -0800 | [diff] [blame] | 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 | private int mValueInt; |
| 57 | |
| 58 | /** |
| 59 | * @hide |
| 60 | */ |
| 61 | public BatteryProperty(int value) { |
| 62 | mValueInt = value; |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * @hide |
| 67 | */ |
Todd Poynor | d7b3477 | 2013-08-14 20:42:44 -0700 | [diff] [blame] | 68 | public BatteryProperty() { |
Todd Poynor | e35872d | 2013-12-10 11:57:21 -0800 | [diff] [blame] | 69 | 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 Poynor | d7b3477 | 2013-08-14 20:42:44 -0700 | [diff] [blame] | 83 | } |
| 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 Poynor | e35872d | 2013-12-10 11:57:21 -0800 | [diff] [blame] | 95 | mValueInt = p.readInt(); |
Todd Poynor | d7b3477 | 2013-08-14 20:42:44 -0700 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | public void writeToParcel(Parcel p, int flags) { |
Todd Poynor | e35872d | 2013-12-10 11:57:21 -0800 | [diff] [blame] | 99 | p.writeInt(mValueInt); |
Todd Poynor | d7b3477 | 2013-08-14 20:42:44 -0700 | [diff] [blame] | 100 | } |
| 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 | } |