Skip to content

Commit 81b0777

Browse files
jruesgatemasek
authored andcommitted
base: dock battery
Change-Id: I8cc3fc465daa49c9010bdbbf876dae18461d7024 Require: topic:dock_battery Signed-off-by: Jorge Ruesga <[email protected]> Improve dock battery strings Change-Id: Iccfa2df4ec608ae02c0bfcef99648788dab95933 systemui: fix battery text level visibility Use present flag instead of plug-in flag to determine the battery present (only hide the text level view if the battery is not present) Change-Id: I8e20e107bbeeecdc846833dc80c1a2754d82a039 Signed-off-by: Jorge Ruesga <[email protected]> systemui: restore space between clock & battery Initialize dock battery to GONE visibility because isn't update on device not supporting dock battery. Change-Id: I23aeafc27db0fc499050a7306e8549293accb507 Signed-off-by: Jorge Ruesga <[email protected]> SystemUI: fix battery icon jump on qs expand The layouts are slightly different for the header and icon layouts. Change-Id: I85d3fc007eb9b2c3e2ba09bb761a91b521b89700 Signed-off-by: Roman Birg <[email protected]> systemui: move dock battery level views outside systemicons layout At not the ideal, this at least will match normal battery level view, puttings battery levels in the correct order. In addition fix two small dock battery bugs: - BatteryLevelTextView not displayed if mode is TEXT - Properly hide DockBatteryMetterView for modes NONE and TEXT - Underline the dock BatteryLevelTextView to differentiate normal from dock text view Screenshot: https://cloud.ruesga.com/f/74fe240c66/ Change-Id: Idfd3a4bb2f19bd29f9f4dd2b0ea7f645bb531986 Signed-off-by: Jorge Ruesga <[email protected]>
1 parent de442a2 commit 81b0777

31 files changed

+1460
-90
lines changed

Android.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ LOCAL_SRC_FILES += \
7272
core/java/android/app/IAppTask.aidl \
7373
core/java/android/app/ITaskStackListener.aidl \
7474
core/java/android/app/IBackupAgent.aidl \
75+
core/java/android/app/IBatteryService.aidl \
7576
core/java/android/app/IInstrumentationWatcher.aidl \
7677
core/java/android/app/INotificationManager.aidl \
7778
core/java/android/app/IProcessObserver.aidl \
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* Copyright (c) 2016, The CyanogenMod 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.app;
18+
19+
/**
20+
* System private API for talking with the battery service.
21+
*
22+
* {@hide}
23+
*/
24+
interface IBatteryService {
25+
boolean isDockBatterySupported();
26+
}

core/java/android/app/SystemServiceRegistry.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,9 @@ public DownloadManager createService(ContextImpl ctx) {
254254
new StaticServiceFetcher<BatteryManager>() {
255255
@Override
256256
public BatteryManager createService() {
257-
return new BatteryManager();
257+
IBinder b = ServiceManager.getService(Context.BATTERY_SERVICE);
258+
IBatteryService service = IBatteryService.Stub.asInterface(b);
259+
return new BatteryManager(service);
258260
}});
259261

260262
registerService(Context.NFC_SERVICE, NfcManager.class,

core/java/android/os/BatteryManager.java

Lines changed: 156 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
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.
@@ -16,6 +17,7 @@
1617

1718
package android.os;
1819

20+
import android.app.IBatteryService;
1921
import android.content.Context;
2022
import android.os.BatteryProperty;
2123
import 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
}

core/java/android/os/BatteryManagerInternal.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/*
22
* Copyright (C) 2014 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.
@@ -42,6 +43,26 @@ public abstract class BatteryManagerInternal {
4243
*/
4344
public abstract boolean getBatteryLevelLow();
4445

46+
/**
47+
* Returns whether dock batteries is supported
48+
*/
49+
public abstract boolean isDockBatterySupported();
50+
51+
/**
52+
* Returns the current dock plug type.
53+
*/
54+
public abstract int getDockPlugType();
55+
56+
/**
57+
* Returns dock battery level as a percentage.
58+
*/
59+
public abstract int getDockBatteryLevel();
60+
61+
/**
62+
* Returns whether we currently consider the dock battery level to be low.
63+
*/
64+
public abstract boolean getDockBatteryLevelLow();
65+
4566
/**
4667
* Returns a non-zero value if an unsupported charger is attached.
4768
*/

core/java/android/os/BatteryProperties.java

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/* Copyright 2013, The Android Open Source Project
2+
* Copyright 2016, The CyanogenMod Project
23
*
34
* Licensed under the Apache License, Version 2.0 (the "License");
45
* you may not use this file except in compliance with the License.
@@ -31,6 +32,16 @@ public class BatteryProperties implements Parcelable {
3132
public int batteryTemperature;
3233
public String batteryTechnology;
3334

35+
public boolean dockBatterySupported;
36+
public boolean chargerDockAcOnline;
37+
public int dockBatteryStatus;
38+
public int dockBatteryHealth;
39+
public boolean dockBatteryPresent;
40+
public int dockBatteryLevel;
41+
public int dockBatteryVoltage;
42+
public int dockBatteryTemperature;
43+
public String dockBatteryTechnology;
44+
3445
public BatteryProperties() {
3546
}
3647

@@ -46,6 +57,16 @@ public void set(BatteryProperties other) {
4657
batteryVoltage = other.batteryVoltage;
4758
batteryTemperature = other.batteryTemperature;
4859
batteryTechnology = other.batteryTechnology;
60+
61+
dockBatterySupported = other.dockBatterySupported;
62+
chargerDockAcOnline = other.chargerDockAcOnline;
63+
dockBatteryStatus = other.dockBatteryStatus;
64+
dockBatteryHealth = other.dockBatteryHealth;
65+
dockBatteryPresent = other.dockBatteryPresent;
66+
dockBatteryLevel = other.dockBatteryLevel;
67+
dockBatteryVoltage = other.dockBatteryVoltage;
68+
dockBatteryTemperature = other.dockBatteryTemperature;
69+
dockBatteryTechnology = other.dockBatteryTechnology;
4970
}
5071

5172
/*
@@ -65,6 +86,27 @@ private BatteryProperties(Parcel p) {
6586
batteryVoltage = p.readInt();
6687
batteryTemperature = p.readInt();
6788
batteryTechnology = p.readString();
89+
90+
dockBatterySupported = p.readInt() == 1 ? true : false;
91+
if (dockBatterySupported) {
92+
chargerDockAcOnline = p.readInt() == 1 ? true : false;
93+
dockBatteryStatus = p.readInt();
94+
dockBatteryHealth = p.readInt();
95+
dockBatteryPresent = p.readInt() == 1 ? true : false;
96+
dockBatteryLevel = p.readInt();
97+
dockBatteryVoltage = p.readInt();
98+
dockBatteryTemperature = p.readInt();
99+
dockBatteryTechnology = p.readString();
100+
} else {
101+
chargerDockAcOnline = false;
102+
dockBatteryStatus = BatteryManager.BATTERY_STATUS_UNKNOWN;
103+
dockBatteryHealth = BatteryManager.BATTERY_HEALTH_UNKNOWN;
104+
dockBatteryPresent = false;
105+
dockBatteryLevel = 0;
106+
dockBatteryVoltage = 0;
107+
dockBatteryTemperature = 0;
108+
dockBatteryTechnology = "";
109+
}
68110
}
69111

70112
public void writeToParcel(Parcel p, int flags) {
@@ -79,6 +121,18 @@ public void writeToParcel(Parcel p, int flags) {
79121
p.writeInt(batteryVoltage);
80122
p.writeInt(batteryTemperature);
81123
p.writeString(batteryTechnology);
124+
125+
p.writeInt(dockBatterySupported ? 1 : 0);
126+
if (dockBatterySupported) {
127+
p.writeInt(chargerDockAcOnline ? 1 : 0);
128+
p.writeInt(dockBatteryStatus);
129+
p.writeInt(dockBatteryHealth);
130+
p.writeInt(dockBatteryPresent ? 1 : 0);
131+
p.writeInt(dockBatteryLevel);
132+
p.writeInt(dockBatteryVoltage);
133+
p.writeInt(dockBatteryTemperature);
134+
p.writeString(dockBatteryTechnology);
135+
}
82136
}
83137

84138
public static final Parcelable.Creator<BatteryProperties> CREATOR

0 commit comments

Comments
 (0)