The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 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.os; |
| 18 | |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 19 | import android.annotation.SystemService; |
| 20 | import android.content.Context; |
Dianne Hackborn | 74ed6ec | 2017-11-21 16:33:44 -0800 | [diff] [blame] | 21 | import android.content.Intent; |
Sandeep Patil | a21c427 | 2016-11-10 14:02:45 -0800 | [diff] [blame] | 22 | import android.hardware.health.V1_0.Constants; |
Yifan Hong | b0f1352 | 2017-10-31 15:48:50 -0700 | [diff] [blame] | 23 | |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 24 | import com.android.internal.app.IBatteryStats; |
Todd Poynor | e35872d | 2013-12-10 11:57:21 -0800 | [diff] [blame] | 25 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 26 | /** |
| 27 | * The BatteryManager class contains strings and constants used for values |
Todd Poynor | e35872d | 2013-12-10 11:57:21 -0800 | [diff] [blame] | 28 | * in the {@link android.content.Intent#ACTION_BATTERY_CHANGED} Intent, and |
| 29 | * provides a method for querying battery and charging properties. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 30 | */ |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 31 | @SystemService(Context.BATTERY_SERVICE) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 32 | public class BatteryManager { |
Dianne Hackborn | edd9316 | 2009-09-19 14:03:05 -0700 | [diff] [blame] | 33 | /** |
| 34 | * Extra for {@link android.content.Intent#ACTION_BATTERY_CHANGED}: |
| 35 | * integer containing the current status constant. |
| 36 | */ |
| 37 | public static final String EXTRA_STATUS = "status"; |
Yifan Hong | b0f1352 | 2017-10-31 15:48:50 -0700 | [diff] [blame] | 38 | |
Dianne Hackborn | edd9316 | 2009-09-19 14:03:05 -0700 | [diff] [blame] | 39 | /** |
| 40 | * Extra for {@link android.content.Intent#ACTION_BATTERY_CHANGED}: |
| 41 | * integer containing the current health constant. |
| 42 | */ |
| 43 | public static final String EXTRA_HEALTH = "health"; |
Yifan Hong | b0f1352 | 2017-10-31 15:48:50 -0700 | [diff] [blame] | 44 | |
Dianne Hackborn | edd9316 | 2009-09-19 14:03:05 -0700 | [diff] [blame] | 45 | /** |
| 46 | * Extra for {@link android.content.Intent#ACTION_BATTERY_CHANGED}: |
| 47 | * boolean indicating whether a battery is present. |
| 48 | */ |
| 49 | public static final String EXTRA_PRESENT = "present"; |
Yifan Hong | b0f1352 | 2017-10-31 15:48:50 -0700 | [diff] [blame] | 50 | |
Dianne Hackborn | edd9316 | 2009-09-19 14:03:05 -0700 | [diff] [blame] | 51 | /** |
| 52 | * Extra for {@link android.content.Intent#ACTION_BATTERY_CHANGED}: |
| 53 | * integer field containing the current battery level, from 0 to |
| 54 | * {@link #EXTRA_SCALE}. |
| 55 | */ |
| 56 | public static final String EXTRA_LEVEL = "level"; |
Yifan Hong | b0f1352 | 2017-10-31 15:48:50 -0700 | [diff] [blame] | 57 | |
Dianne Hackborn | edd9316 | 2009-09-19 14:03:05 -0700 | [diff] [blame] | 58 | /** |
| 59 | * Extra for {@link android.content.Intent#ACTION_BATTERY_CHANGED}: |
Dianne Hackborn | 74ed6ec | 2017-11-21 16:33:44 -0800 | [diff] [blame] | 60 | * Boolean field indicating whether the battery is currently considered to be |
| 61 | * low, that is whether a {@link Intent#ACTION_BATTERY_LOW} broadcast |
| 62 | * has been sent. |
| 63 | */ |
| 64 | public static final String EXTRA_BATTERY_LOW = "battery_low"; |
| 65 | |
| 66 | /** |
| 67 | * Extra for {@link android.content.Intent#ACTION_BATTERY_CHANGED}: |
Dianne Hackborn | edd9316 | 2009-09-19 14:03:05 -0700 | [diff] [blame] | 68 | * integer containing the maximum battery level. |
| 69 | */ |
| 70 | public static final String EXTRA_SCALE = "scale"; |
Yifan Hong | b0f1352 | 2017-10-31 15:48:50 -0700 | [diff] [blame] | 71 | |
Dianne Hackborn | edd9316 | 2009-09-19 14:03:05 -0700 | [diff] [blame] | 72 | /** |
| 73 | * Extra for {@link android.content.Intent#ACTION_BATTERY_CHANGED}: |
| 74 | * integer containing the resource ID of a small status bar icon |
| 75 | * indicating the current battery state. |
| 76 | */ |
| 77 | public static final String EXTRA_ICON_SMALL = "icon-small"; |
Yifan Hong | b0f1352 | 2017-10-31 15:48:50 -0700 | [diff] [blame] | 78 | |
Dianne Hackborn | edd9316 | 2009-09-19 14:03:05 -0700 | [diff] [blame] | 79 | /** |
| 80 | * Extra for {@link android.content.Intent#ACTION_BATTERY_CHANGED}: |
| 81 | * integer indicating whether the device is plugged in to a power |
| 82 | * source; 0 means it is on battery, other constants are different |
| 83 | * types of power sources. |
| 84 | */ |
| 85 | public static final String EXTRA_PLUGGED = "plugged"; |
Yifan Hong | b0f1352 | 2017-10-31 15:48:50 -0700 | [diff] [blame] | 86 | |
Dianne Hackborn | edd9316 | 2009-09-19 14:03:05 -0700 | [diff] [blame] | 87 | /** |
| 88 | * Extra for {@link android.content.Intent#ACTION_BATTERY_CHANGED}: |
| 89 | * integer containing the current battery voltage level. |
| 90 | */ |
| 91 | public static final String EXTRA_VOLTAGE = "voltage"; |
Yifan Hong | b0f1352 | 2017-10-31 15:48:50 -0700 | [diff] [blame] | 92 | |
Dianne Hackborn | edd9316 | 2009-09-19 14:03:05 -0700 | [diff] [blame] | 93 | /** |
| 94 | * Extra for {@link android.content.Intent#ACTION_BATTERY_CHANGED}: |
| 95 | * integer containing the current battery temperature. |
| 96 | */ |
| 97 | public static final String EXTRA_TEMPERATURE = "temperature"; |
Yifan Hong | b0f1352 | 2017-10-31 15:48:50 -0700 | [diff] [blame] | 98 | |
Dianne Hackborn | edd9316 | 2009-09-19 14:03:05 -0700 | [diff] [blame] | 99 | /** |
| 100 | * Extra for {@link android.content.Intent#ACTION_BATTERY_CHANGED}: |
| 101 | * String describing the technology of the current battery. |
| 102 | */ |
| 103 | public static final String EXTRA_TECHNOLOGY = "technology"; |
Mike Lockwood | deff9c8 | 2010-09-04 10:29:17 -0400 | [diff] [blame] | 104 | |
| 105 | /** |
| 106 | * Extra for {@link android.content.Intent#ACTION_BATTERY_CHANGED}: |
Joe Onorato | 4ca7f1e | 2010-10-27 15:32:23 -0700 | [diff] [blame] | 107 | * Int value set to nonzero if an unsupported charger is attached |
Mike Lockwood | deff9c8 | 2010-09-04 10:29:17 -0400 | [diff] [blame] | 108 | * to the device. |
| 109 | * {@hide} |
| 110 | */ |
| 111 | public static final String EXTRA_INVALID_CHARGER = "invalid_charger"; |
| 112 | |
Adrian Roos | 7b04311 | 2015-07-10 13:00:33 -0700 | [diff] [blame] | 113 | /** |
| 114 | * Extra for {@link android.content.Intent#ACTION_BATTERY_CHANGED}: |
| 115 | * Int value set to the maximum charging current supported by the charger in micro amperes. |
| 116 | * {@hide} |
| 117 | */ |
| 118 | public static final String EXTRA_MAX_CHARGING_CURRENT = "max_charging_current"; |
| 119 | |
Badhri Jagan Sridharan | f92fcfe | 2015-10-27 13:59:34 -0700 | [diff] [blame] | 120 | /** |
| 121 | * Extra for {@link android.content.Intent#ACTION_BATTERY_CHANGED}: |
| 122 | * Int value set to the maximum charging voltage supported by the charger in micro volts. |
| 123 | * {@hide} |
| 124 | */ |
| 125 | public static final String EXTRA_MAX_CHARGING_VOLTAGE = "max_charging_voltage"; |
| 126 | |
Ruchi Kandoi | 6361e22 | 2016-04-07 11:28:30 -0700 | [diff] [blame] | 127 | /** |
| 128 | * Extra for {@link android.content.Intent#ACTION_BATTERY_CHANGED}: |
| 129 | * integer containing the charge counter present in the battery. |
| 130 | * {@hide} |
| 131 | */ |
| 132 | public static final String EXTRA_CHARGE_COUNTER = "charge_counter"; |
| 133 | |
Dianne Hackborn | a06ec6a | 2017-02-13 10:08:42 -0800 | [diff] [blame] | 134 | /** |
| 135 | * Extra for {@link android.content.Intent#ACTION_BATTERY_CHANGED}: |
| 136 | * Current int sequence number of the update. |
| 137 | * {@hide} |
| 138 | */ |
| 139 | public static final String EXTRA_SEQUENCE = "seq"; |
| 140 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 141 | // values for "status" field in the ACTION_BATTERY_CHANGED Intent |
Sandeep Patil | a21c427 | 2016-11-10 14:02:45 -0800 | [diff] [blame] | 142 | public static final int BATTERY_STATUS_UNKNOWN = Constants.BATTERY_STATUS_UNKNOWN; |
| 143 | public static final int BATTERY_STATUS_CHARGING = Constants.BATTERY_STATUS_CHARGING; |
| 144 | public static final int BATTERY_STATUS_DISCHARGING = Constants.BATTERY_STATUS_DISCHARGING; |
| 145 | public static final int BATTERY_STATUS_NOT_CHARGING = Constants.BATTERY_STATUS_NOT_CHARGING; |
| 146 | public static final int BATTERY_STATUS_FULL = Constants.BATTERY_STATUS_FULL; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 147 | |
| 148 | // values for "health" field in the ACTION_BATTERY_CHANGED Intent |
Sandeep Patil | a21c427 | 2016-11-10 14:02:45 -0800 | [diff] [blame] | 149 | public static final int BATTERY_HEALTH_UNKNOWN = Constants.BATTERY_HEALTH_UNKNOWN; |
| 150 | public static final int BATTERY_HEALTH_GOOD = Constants.BATTERY_HEALTH_GOOD; |
| 151 | public static final int BATTERY_HEALTH_OVERHEAT = Constants.BATTERY_HEALTH_OVERHEAT; |
| 152 | public static final int BATTERY_HEALTH_DEAD = Constants.BATTERY_HEALTH_DEAD; |
| 153 | public static final int BATTERY_HEALTH_OVER_VOLTAGE = Constants.BATTERY_HEALTH_OVER_VOLTAGE; |
| 154 | public static final int BATTERY_HEALTH_UNSPECIFIED_FAILURE = Constants.BATTERY_HEALTH_UNSPECIFIED_FAILURE; |
| 155 | public static final int BATTERY_HEALTH_COLD = Constants.BATTERY_HEALTH_COLD; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 156 | |
| 157 | // values of the "plugged" field in the ACTION_BATTERY_CHANGED intent. |
| 158 | // These must be powers of 2. |
| 159 | /** Power source is an AC charger. */ |
Bookatz | 1a1b046 | 2018-01-12 11:47:03 -0800 | [diff] [blame] | 160 | public static final int BATTERY_PLUGGED_AC = OsProtoEnums.BATTERY_PLUGGED_AC; // = 1 |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 161 | /** Power source is a USB port. */ |
Bookatz | 1a1b046 | 2018-01-12 11:47:03 -0800 | [diff] [blame] | 162 | public static final int BATTERY_PLUGGED_USB = OsProtoEnums.BATTERY_PLUGGED_USB; // = 2 |
Brian Muramatsu | 37a37f4 | 2012-08-14 15:21:02 -0700 | [diff] [blame] | 163 | /** Power source is wireless. */ |
Bookatz | 1a1b046 | 2018-01-12 11:47:03 -0800 | [diff] [blame] | 164 | public static final int BATTERY_PLUGGED_WIRELESS = OsProtoEnums.BATTERY_PLUGGED_WIRELESS; // = 4 |
Jeff Brown | a4d8204 | 2012-10-02 19:11:19 -0700 | [diff] [blame] | 165 | |
| 166 | /** @hide */ |
| 167 | public static final int BATTERY_PLUGGED_ANY = |
| 168 | BATTERY_PLUGGED_AC | BATTERY_PLUGGED_USB | BATTERY_PLUGGED_WIRELESS; |
Todd Poynor | e35872d | 2013-12-10 11:57:21 -0800 | [diff] [blame] | 169 | |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 170 | /** |
| 171 | * Sent when the device's battery has started charging (or has reached full charge |
| 172 | * and the device is on power). This is a good time to do work that you would like to |
| 173 | * avoid doing while on battery (that is to avoid draining the user's battery due to |
| 174 | * things they don't care enough about). |
| 175 | * |
| 176 | * This is paired with {@link #ACTION_DISCHARGING}. The current state can always |
| 177 | * be retrieved with {@link #isCharging()}. |
| 178 | */ |
| 179 | public static final String ACTION_CHARGING = "android.os.action.CHARGING"; |
| 180 | |
| 181 | /** |
| 182 | * Sent when the device's battery may be discharging, so apps should avoid doing |
| 183 | * extraneous work that would cause it to discharge faster. |
| 184 | * |
| 185 | * This is paired with {@link #ACTION_CHARGING}. The current state can always |
| 186 | * be retrieved with {@link #isCharging()}. |
| 187 | */ |
| 188 | public static final String ACTION_DISCHARGING = "android.os.action.DISCHARGING"; |
| 189 | |
Todd Poynor | 5fde3ff | 2014-06-05 14:49:28 -0700 | [diff] [blame] | 190 | /* |
| 191 | * Battery property identifiers. These must match the values in |
| 192 | * frameworks/native/include/batteryservice/BatteryService.h |
| 193 | */ |
| 194 | /** Battery capacity in microampere-hours, as an integer. */ |
| 195 | public static final int BATTERY_PROPERTY_CHARGE_COUNTER = 1; |
| 196 | |
| 197 | /** |
| 198 | * Instantaneous battery current in microamperes, as an integer. Positive |
| 199 | * values indicate net current entering the battery from a charge source, |
| 200 | * negative values indicate net current discharging from the battery. |
| 201 | */ |
| 202 | public static final int BATTERY_PROPERTY_CURRENT_NOW = 2; |
| 203 | |
| 204 | /** |
| 205 | * Average battery current in microamperes, as an integer. Positive |
| 206 | * values indicate net current entering the battery from a charge source, |
| 207 | * negative values indicate net current discharging from the battery. |
| 208 | * The time period over which the average is computed may depend on the |
| 209 | * fuel gauge hardware and its configuration. |
| 210 | */ |
| 211 | public static final int BATTERY_PROPERTY_CURRENT_AVERAGE = 3; |
| 212 | |
| 213 | /** |
| 214 | * Remaining battery capacity as an integer percentage of total capacity |
| 215 | * (with no fractional part). |
| 216 | */ |
| 217 | public static final int BATTERY_PROPERTY_CAPACITY = 4; |
| 218 | |
| 219 | /** |
| 220 | * Battery remaining energy in nanowatt-hours, as a long integer. |
| 221 | */ |
| 222 | public static final int BATTERY_PROPERTY_ENERGY_COUNTER = 5; |
| 223 | |
Jin Qian | edf0a37 | 2017-02-03 11:08:37 -0800 | [diff] [blame] | 224 | /** |
| 225 | * Battery charge status, from a BATTERY_STATUS_* value. |
| 226 | */ |
Jin Qian | 2e88d4b | 2017-02-28 10:57:17 -0800 | [diff] [blame] | 227 | public static final int BATTERY_PROPERTY_STATUS = 6; |
Jin Qian | edf0a37 | 2017-02-03 11:08:37 -0800 | [diff] [blame] | 228 | |
Yifan Hong | b0f1352 | 2017-10-31 15:48:50 -0700 | [diff] [blame] | 229 | private final Context mContext; |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 230 | private final IBatteryStats mBatteryStats; |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 231 | private final IBatteryPropertiesRegistrar mBatteryPropertiesRegistrar; |
| 232 | |
| 233 | /** |
| 234 | * @removed Was previously made visible by accident. |
| 235 | */ |
| 236 | public BatteryManager() { |
Yifan Hong | b0f1352 | 2017-10-31 15:48:50 -0700 | [diff] [blame] | 237 | mContext = null; |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 238 | mBatteryStats = IBatteryStats.Stub.asInterface( |
| 239 | ServiceManager.getService(BatteryStats.SERVICE_NAME)); |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 240 | mBatteryPropertiesRegistrar = IBatteryPropertiesRegistrar.Stub.asInterface( |
| 241 | ServiceManager.getService("batteryproperties")); |
| 242 | } |
Todd Poynor | e35872d | 2013-12-10 11:57:21 -0800 | [diff] [blame] | 243 | |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 244 | /** {@hide} */ |
Yifan Hong | b0f1352 | 2017-10-31 15:48:50 -0700 | [diff] [blame] | 245 | public BatteryManager(Context context, |
| 246 | IBatteryStats batteryStats, |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 247 | IBatteryPropertiesRegistrar batteryPropertiesRegistrar) { |
Yifan Hong | b0f1352 | 2017-10-31 15:48:50 -0700 | [diff] [blame] | 248 | mContext = context; |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 249 | mBatteryStats = batteryStats; |
| 250 | mBatteryPropertiesRegistrar = batteryPropertiesRegistrar; |
| 251 | } |
| 252 | |
Todd Poynor | e35872d | 2013-12-10 11:57:21 -0800 | [diff] [blame] | 253 | /** |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 254 | * Return true if the battery is currently considered to be charging. This means that |
| 255 | * the device is plugged in and is supplying sufficient power that the battery level is |
| 256 | * going up (or the battery is fully charged). Changes in this state are matched by |
| 257 | * broadcasts of {@link #ACTION_CHARGING} and {@link #ACTION_DISCHARGING}. |
| 258 | */ |
| 259 | public boolean isCharging() { |
| 260 | try { |
| 261 | return mBatteryStats.isCharging(); |
| 262 | } catch (RemoteException e) { |
Jeff Sharkey | c53962d | 2016-03-01 19:27:23 -0700 | [diff] [blame] | 263 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 264 | } |
| 265 | } |
| 266 | |
| 267 | /** |
Todd Poynor | 5fde3ff | 2014-06-05 14:49:28 -0700 | [diff] [blame] | 268 | * Query a battery property from the batteryproperties service. |
Todd Poynor | e35872d | 2013-12-10 11:57:21 -0800 | [diff] [blame] | 269 | * |
Todd Poynor | 5fde3ff | 2014-06-05 14:49:28 -0700 | [diff] [blame] | 270 | * Returns the requested value, or Long.MIN_VALUE if property not |
| 271 | * supported on this system or on other error. |
Todd Poynor | e35872d | 2013-12-10 11:57:21 -0800 | [diff] [blame] | 272 | */ |
Todd Poynor | 5fde3ff | 2014-06-05 14:49:28 -0700 | [diff] [blame] | 273 | private long queryProperty(int id) { |
| 274 | long ret; |
| 275 | |
Todd Poynor | e35872d | 2013-12-10 11:57:21 -0800 | [diff] [blame] | 276 | if (mBatteryPropertiesRegistrar == null) { |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 277 | return Long.MIN_VALUE; |
Todd Poynor | e35872d | 2013-12-10 11:57:21 -0800 | [diff] [blame] | 278 | } |
| 279 | |
Todd Poynor | 5fde3ff | 2014-06-05 14:49:28 -0700 | [diff] [blame] | 280 | try { |
| 281 | BatteryProperty prop = new BatteryProperty(); |
| 282 | |
| 283 | if (mBatteryPropertiesRegistrar.getProperty(id, prop) == 0) |
| 284 | ret = prop.getLong(); |
| 285 | else |
| 286 | ret = Long.MIN_VALUE; |
| 287 | } catch (RemoteException e) { |
Jeff Sharkey | c53962d | 2016-03-01 19:27:23 -0700 | [diff] [blame] | 288 | throw e.rethrowFromSystemServer(); |
Todd Poynor | 5fde3ff | 2014-06-05 14:49:28 -0700 | [diff] [blame] | 289 | } |
| 290 | |
| 291 | return ret; |
| 292 | } |
| 293 | |
| 294 | /** |
Yifan Hong | b0f1352 | 2017-10-31 15:48:50 -0700 | [diff] [blame] | 295 | * Return the value of a battery property of integer type. |
Todd Poynor | 5fde3ff | 2014-06-05 14:49:28 -0700 | [diff] [blame] | 296 | * |
| 297 | * @param id identifier of the requested property |
| 298 | * |
Yifan Hong | b0f1352 | 2017-10-31 15:48:50 -0700 | [diff] [blame] | 299 | * @return the property value. If the property is not supported or there is any other error, |
| 300 | * return (a) 0 if {@code targetSdkVersion < VERSION_CODES.P} or (b) Integer.MIN_VALUE |
| 301 | * if {@code targetSdkVersion >= VERSION_CODES.P}. |
Todd Poynor | 5fde3ff | 2014-06-05 14:49:28 -0700 | [diff] [blame] | 302 | */ |
| 303 | public int getIntProperty(int id) { |
Yifan Hong | b0f1352 | 2017-10-31 15:48:50 -0700 | [diff] [blame] | 304 | long value = queryProperty(id); |
| 305 | if (value == Long.MIN_VALUE && mContext != null |
| 306 | && mContext.getApplicationInfo().targetSdkVersion |
| 307 | >= android.os.Build.VERSION_CODES.P) { |
| 308 | return Integer.MIN_VALUE; |
| 309 | } |
| 310 | |
| 311 | return (int) value; |
Todd Poynor | 5fde3ff | 2014-06-05 14:49:28 -0700 | [diff] [blame] | 312 | } |
| 313 | |
| 314 | /** |
| 315 | * Return the value of a battery property of long type If the |
| 316 | * platform does not provide the property queried, this value will |
| 317 | * be Long.MIN_VALUE. |
| 318 | * |
| 319 | * @param id identifier of the requested property |
| 320 | * |
| 321 | * @return the property value, or Long.MIN_VALUE if not supported. |
| 322 | */ |
| 323 | public long getLongProperty(int id) { |
| 324 | return queryProperty(id); |
Todd Poynor | e35872d | 2013-12-10 11:57:21 -0800 | [diff] [blame] | 325 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 326 | } |