11/*
22 * Copyright (C) 2008 The Android Open Source Project
3+ * Copyright (C) 2016 The CyanogenMod Project
34 *
45 * Licensed under the Apache License, Version 2.0 (the "License");
56 * you may not use this file except in compliance with the License.
1617
1718package android .os ;
1819
20+ import android .app .IBatteryService ;
1921import android .content .Context ;
2022import android .os .BatteryProperty ;
2123import android .os .IBatteryPropertiesRegistrar ;
@@ -93,6 +95,79 @@ public class BatteryManager {
9395 */
9496 public static final String EXTRA_TECHNOLOGY = "technology" ;
9597
98+ /**
99+ * Extra for {@link android.content.Intent#ACTION_BATTERY_CHANGED}:
100+ * integer containing the current dock status constant.
101+ * @hide
102+ */
103+ public static final String EXTRA_DOCK_STATUS = "dock_status" ;
104+
105+ /**
106+ * Extra for {@link android.content.Intent#ACTION_BATTERY_CHANGED}:
107+ * integer containing the current dock health constant.
108+ * @hide
109+ */
110+ public static final String EXTRA_DOCK_HEALTH = "dock_health" ;
111+
112+ /**
113+ * Extra for {@link android.content.Intent#ACTION_BATTERY_CHANGED}:
114+ * boolean indicating whether a dock battery is present.
115+ * @hide
116+ */
117+ public static final String EXTRA_DOCK_PRESENT = "dock_present" ;
118+
119+ /**
120+ * Extra for {@link android.content.Intent#ACTION_BATTERY_CHANGED}:
121+ * integer field containing the current dock battery level, from 0 to
122+ * {@link #EXTRA_SCALE}.
123+ * @hide
124+ */
125+ public static final String EXTRA_DOCK_LEVEL = "dock_level" ;
126+
127+ /**
128+ * Extra for {@link android.content.Intent#ACTION_BATTERY_CHANGED}:
129+ * integer containing the maximum dock battery level.
130+ * @hide
131+ */
132+ public static final String EXTRA_DOCK_SCALE = "dock_scale" ;
133+
134+ /**
135+ * Extra for {@link android.content.Intent#ACTION_BATTERY_CHANGED}:
136+ * integer containing the resource ID of a small status bar icon
137+ * indicating the current dock battery state.
138+ * @hide
139+ */
140+ public static final String EXTRA_DOCK_ICON_SMALL = "dock_icon-small" ;
141+
142+ /**
143+ * Extra for {@link android.content.Intent#ACTION_BATTERY_CHANGED}:
144+ * integer indicating whether the device is plugged in to a dock power
145+ * source.
146+ * @hide
147+ */
148+ public static final String EXTRA_DOCK_PLUGGED = "dock_plugged" ;
149+
150+ /**
151+ * Extra for {@link android.content.Intent#ACTION_BATTERY_CHANGED}:
152+ * integer containing the current dock battery voltage level.
153+ * @hide
154+ */
155+ public static final String EXTRA_DOCK_VOLTAGE = "dock_voltage" ;
156+
157+ /**
158+ * Extra for {@link android.content.Intent#ACTION_BATTERY_CHANGED}:
159+ * integer containing the current dock battery temperature.
160+ * @hide
161+ */
162+ public static final String EXTRA_DOCK_TEMPERATURE = "dock_temperature" ;
163+
164+ /**
165+ * Extra for {@link android.content.Intent#ACTION_BATTERY_CHANGED}:
166+ * String describing the technology of the current dock battery.
167+ * @hide
168+ */
169+ public static final String EXTRA_DOCK_TECHNOLOGY = "dock_technology" ;
170+
96171 /**
97172 * Extra for {@link android.content.Intent#ACTION_BATTERY_CHANGED}:
98173 * Int value set to nonzero if an unsupported charger is attached
@@ -133,10 +208,23 @@ public class BatteryManager {
133208 /** Power source is wireless. */
134209 public static final int BATTERY_PLUGGED_WIRELESS = 4 ;
135210
211+ // values of the "dock_plugged" field in the ACTION_BATTERY_CHANGED intent.
212+ // These must be powers of 2.
213+ /** Power source is an DockAC charger.
214+ * @hide*/
215+ public static final int BATTERY_DOCK_PLUGGED_AC = 1 ;
216+ /** Power source is an DockUSB charger.
217+ * @hide*/
218+ public static final int BATTERY_DOCK_PLUGGED_USB = 2 ;
219+
136220 /** @hide */
137221 public static final int BATTERY_PLUGGED_ANY =
138222 BATTERY_PLUGGED_AC | BATTERY_PLUGGED_USB | BATTERY_PLUGGED_WIRELESS ;
139223
224+ /** @hide */
225+ public static final int BATTERY_DOCK_PLUGGED_ANY =
226+ BATTERY_DOCK_PLUGGED_AC | BATTERY_DOCK_PLUGGED_USB ;
227+
140228 /**
141229 * Sent when the device's battery has started charging (or has reached full charge
142230 * and the device is on power). This is a good time to do work that you would like to
@@ -191,6 +279,7 @@ public class BatteryManager {
191279 */
192280 public static final int BATTERY_PROPERTY_ENERGY_COUNTER = 5 ;
193281
282+ private final IBatteryService mBatteryService ;
194283 private final IBatteryStats mBatteryStats ;
195284 private final IBatteryPropertiesRegistrar mBatteryPropertiesRegistrar ;
196285
@@ -202,6 +291,27 @@ public BatteryManager() {
202291 ServiceManager .getService (BatteryStats .SERVICE_NAME ));
203292 mBatteryPropertiesRegistrar = IBatteryPropertiesRegistrar .Stub .asInterface (
204293 ServiceManager .getService ("batteryproperties" ));
294+ mBatteryService = null ;
295+ }
296+
297+ /** @hide */
298+ public BatteryManager (IBatteryService service ) {
299+ super ();
300+ mBatteryStats = IBatteryStats .Stub .asInterface (
301+ ServiceManager .getService (BatteryStats .SERVICE_NAME ));
302+ mBatteryPropertiesRegistrar = IBatteryPropertiesRegistrar .Stub .asInterface (
303+ ServiceManager .getService ("batteryproperties" ));
304+ mBatteryService = service ;
305+ }
306+
307+ /** @hide */
308+ public boolean isDockBatterySupported () {
309+ try {
310+ return mBatteryService != null && mBatteryService .isDockBatterySupported ();
311+ } catch (RemoteException ex ) {
312+ // Ignore
313+ }
314+ return false ;
205315 }
206316
207317 /**
@@ -223,8 +333,10 @@ public boolean isCharging() {
223333 *
224334 * Returns the requested value, or Long.MIN_VALUE if property not
225335 * supported on this system or on other error.
336+ * fromDock determines if the property is query from the normal battery
337+ * or the dock battery.
226338 */
227- private long queryProperty (int id ) {
339+ private long queryProperty (int id , boolean fromDock ) {
228340 long ret ;
229341
230342 if (mBatteryPropertiesRegistrar == null ) {
@@ -234,7 +346,13 @@ private long queryProperty(int id) {
234346 try {
235347 BatteryProperty prop = new BatteryProperty ();
236348
237- if (mBatteryPropertiesRegistrar .getProperty (id , prop ) == 0 )
349+ final int callResult ;
350+ if (!fromDock ) {
351+ callResult = mBatteryPropertiesRegistrar .getProperty (id , prop );
352+ } else {
353+ callResult = mBatteryPropertiesRegistrar .getDockProperty (id , prop );
354+ }
355+ if (callResult == 0 )
238356 ret = prop .getLong ();
239357 else
240358 ret = Long .MIN_VALUE ;
@@ -255,7 +373,7 @@ private long queryProperty(int id) {
255373 * @return the property value, or Integer.MIN_VALUE if not supported.
256374 */
257375 public int getIntProperty (int id ) {
258- return (int )queryProperty (id );
376+ return (int )queryProperty (id , false );
259377 }
260378
261379 /**
@@ -268,6 +386,40 @@ public int getIntProperty(int id) {
268386 * @return the property value, or Long.MIN_VALUE if not supported.
269387 */
270388 public long getLongProperty (int id ) {
271- return queryProperty (id );
389+ return queryProperty (id , false );
390+ }
391+
392+ /**
393+ * Return the value of a dock battery property of integer type. If the
394+ * platform does not provide the property queried, this value will
395+ * be Integer.MIN_VALUE.
396+ *
397+ * @param id identifier of the requested property
398+ *
399+ * @return the property value, or Integer.MIN_VALUE if not supported.
400+ * @hide
401+ */
402+ public int getIntDockProperty (int id ) {
403+ if (!isDockBatterySupported ()) {
404+ return Integer .MIN_VALUE ;
405+ }
406+ return (int )queryProperty (id , true );
407+ }
408+
409+ /**
410+ * Return the value of a dock battery property of long type If the
411+ * platform does not provide the property queried, this value will
412+ * be Long.MIN_VALUE.
413+ *
414+ * @param id identifier of the requested property
415+ *
416+ * @return the property value, or Long.MIN_VALUE if not supported.
417+ * @hide
418+ */
419+ public long getLongDockProperty (int id ) {
420+ if (!isDockBatterySupported ()) {
421+ return Long .MIN_VALUE ;
422+ }
423+ return queryProperty (id , true );
272424 }
273425}
0 commit comments