1
1
/*
2
2
* Copyright (C) 2008 The Android Open Source Project
3
+ * Copyright (C) 2016 The CyanogenMod Project
3
4
*
4
5
* Licensed under the Apache License, Version 2.0 (the "License");
5
6
* you may not use this file except in compliance with the License.
16
17
17
18
package android .os ;
18
19
20
+ import android .app .IBatteryService ;
19
21
import android .content .Context ;
20
22
import android .os .BatteryProperty ;
21
23
import android .os .IBatteryPropertiesRegistrar ;
@@ -93,6 +95,79 @@ public class BatteryManager {
93
95
*/
94
96
public static final String EXTRA_TECHNOLOGY = "technology" ;
95
97
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
+
96
171
/**
97
172
* Extra for {@link android.content.Intent#ACTION_BATTERY_CHANGED}:
98
173
* Int value set to nonzero if an unsupported charger is attached
@@ -133,10 +208,23 @@ public class BatteryManager {
133
208
/** Power source is wireless. */
134
209
public static final int BATTERY_PLUGGED_WIRELESS = 4 ;
135
210
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
+
136
220
/** @hide */
137
221
public static final int BATTERY_PLUGGED_ANY =
138
222
BATTERY_PLUGGED_AC | BATTERY_PLUGGED_USB | BATTERY_PLUGGED_WIRELESS ;
139
223
224
+ /** @hide */
225
+ public static final int BATTERY_DOCK_PLUGGED_ANY =
226
+ BATTERY_DOCK_PLUGGED_AC | BATTERY_DOCK_PLUGGED_USB ;
227
+
140
228
/**
141
229
* Sent when the device's battery has started charging (or has reached full charge
142
230
* 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 {
191
279
*/
192
280
public static final int BATTERY_PROPERTY_ENERGY_COUNTER = 5 ;
193
281
282
+ private final IBatteryService mBatteryService ;
194
283
private final IBatteryStats mBatteryStats ;
195
284
private final IBatteryPropertiesRegistrar mBatteryPropertiesRegistrar ;
196
285
@@ -202,6 +291,27 @@ public BatteryManager() {
202
291
ServiceManager .getService (BatteryStats .SERVICE_NAME ));
203
292
mBatteryPropertiesRegistrar = IBatteryPropertiesRegistrar .Stub .asInterface (
204
293
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 ;
205
315
}
206
316
207
317
/**
@@ -223,8 +333,10 @@ public boolean isCharging() {
223
333
*
224
334
* Returns the requested value, or Long.MIN_VALUE if property not
225
335
* 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.
226
338
*/
227
- private long queryProperty (int id ) {
339
+ private long queryProperty (int id , boolean fromDock ) {
228
340
long ret ;
229
341
230
342
if (mBatteryPropertiesRegistrar == null ) {
@@ -234,7 +346,13 @@ private long queryProperty(int id) {
234
346
try {
235
347
BatteryProperty prop = new BatteryProperty ();
236
348
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 )
238
356
ret = prop .getLong ();
239
357
else
240
358
ret = Long .MIN_VALUE ;
@@ -255,7 +373,7 @@ private long queryProperty(int id) {
255
373
* @return the property value, or Integer.MIN_VALUE if not supported.
256
374
*/
257
375
public int getIntProperty (int id ) {
258
- return (int )queryProperty (id );
376
+ return (int )queryProperty (id , false );
259
377
}
260
378
261
379
/**
@@ -268,6 +386,40 @@ public int getIntProperty(int id) {
268
386
* @return the property value, or Long.MIN_VALUE if not supported.
269
387
*/
270
388
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 );
272
424
}
273
425
}
0 commit comments