Skip to content

Commit 37a37f4

Browse files
author
Brian Muramatsu
committed
add wireless charger support
bug: 6879638 - add new enum value BATTERY_PLUGGED_WIRELESS - check for sys online file with contents "Wireless" Change-Id: I22dc3c40f50573c98643e7b5cbcb237d0216530d
1 parent 82d53ce commit 37a37f4

File tree

8 files changed

+39
-7
lines changed

8 files changed

+39
-7
lines changed

api/current.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15515,6 +15515,7 @@ package android.os {
1551515515
field public static final int BATTERY_HEALTH_UNSPECIFIED_FAILURE = 6; // 0x6
1551615516
field public static final int BATTERY_PLUGGED_AC = 1; // 0x1
1551715517
field public static final int BATTERY_PLUGGED_USB = 2; // 0x2
15518+
field public static final int BATTERY_PLUGGED_WIRELESS = 4; // 0x4
1551815519
field public static final int BATTERY_STATUS_CHARGING = 2; // 0x2
1551915520
field public static final int BATTERY_STATUS_DISCHARGING = 3; // 0x3
1552015521
field public static final int BATTERY_STATUS_FULL = 5; // 0x5

cmds/svc/src/com/android/commands/svc/PowerCommand.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public String shortHelp() {
3737
public String longHelp() {
3838
return shortHelp() + "\n"
3939
+ "\n"
40-
+ "usage: svc power stayon [true|false|usb|ac]\n"
40+
+ "usage: svc power stayon [true|false|usb|ac|wireless]\n"
4141
+ " Set the 'keep awake while plugged in' setting.\n";
4242
}
4343

@@ -48,16 +48,18 @@ public void run(String[] args) {
4848
int val;
4949
if ("true".equals(args[2])) {
5050
val = BatteryManager.BATTERY_PLUGGED_AC |
51-
BatteryManager.BATTERY_PLUGGED_USB;
51+
BatteryManager.BATTERY_PLUGGED_USB |
52+
BatteryManager.BATTERY_PLUGGED_WIRELESS;
5253
}
5354
else if ("false".equals(args[2])) {
5455
val = 0;
5556
} else if ("usb".equals(args[2])) {
5657
val = BatteryManager.BATTERY_PLUGGED_USB;
5758
} else if ("ac".equals(args[2])) {
5859
val = BatteryManager.BATTERY_PLUGGED_AC;
59-
}
60-
else {
60+
} else if ("wireless".equals(args[2])) {
61+
val = BatteryManager.BATTERY_PLUGGED_WIRELESS;
62+
} else {
6163
break fail;
6264
}
6365
IPowerManager pm

core/java/android/os/BatteryManager.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,4 +115,6 @@ public class BatteryManager {
115115
public static final int BATTERY_PLUGGED_AC = 1;
116116
/** Power source is a USB port. */
117117
public static final int BATTERY_PLUGGED_USB = 2;
118+
/** Power source is wireless. */
119+
public static final int BATTERY_PLUGGED_WIRELESS = 4;
118120
}

core/java/android/os/BatteryStats.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2071,6 +2071,9 @@ public void printNextItem(PrintWriter pw, HistoryItem rec, long now) {
20712071
case BatteryManager.BATTERY_PLUGGED_USB:
20722072
pw.print("usb");
20732073
break;
2074+
case BatteryManager.BATTERY_PLUGGED_WIRELESS:
2075+
pw.print("wireless");
2076+
break;
20742077
default:
20752078
pw.print(oldPlug);
20762079
break;

core/java/android/provider/Settings.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1147,6 +1147,7 @@ public static void setShowGTalkServiceStatus(ContentResolver cr, boolean flag) {
11471147
* <li>{@code 0} to never stay on while plugged in</li>
11481148
* <li>{@link BatteryManager#BATTERY_PLUGGED_AC} to stay on for AC charger</li>
11491149
* <li>{@link BatteryManager#BATTERY_PLUGGED_USB} to stay on for USB charger</li>
1150+
* <li>{@link BatteryManager#BATTERY_PLUGGED_WIRELESS} to stay on for wireless charger</li>
11501151
* </ul>
11511152
* These values can be OR-ed together.
11521153
*/

policy/src/com/android/internal/policy/impl/KeyguardUpdateMonitor.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,8 @@ public BatteryStatus(int status, int level, int plugged, int health) {
259259
*/
260260
boolean isPluggedIn() {
261261
return plugged == BatteryManager.BATTERY_PLUGGED_AC
262-
|| plugged == BatteryManager.BATTERY_PLUGGED_USB;
262+
|| plugged == BatteryManager.BATTERY_PLUGGED_USB
263+
|| plugged == BatteryManager.BATTERY_PLUGGED_WIRELESS;
263264
}
264265

265266
/**

services/java/com/android/server/BatteryService.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ public class BatteryService extends Binder {
9393

9494
private boolean mAcOnline;
9595
private boolean mUsbOnline;
96+
private boolean mWirelessOnline;
9697
private int mBatteryStatus;
9798
private int mBatteryHealth;
9899
private boolean mBatteryPresent;
@@ -150,7 +151,8 @@ public BatteryService(Context context, LightsService lights) {
150151

151152
public final boolean isPowered() {
152153
// assume we are powered if battery state is unknown so the "stay on while plugged in" option will work.
153-
return (mAcOnline || mUsbOnline || mBatteryStatus == BatteryManager.BATTERY_STATUS_UNKNOWN);
154+
return (mAcOnline || mUsbOnline || mWirelessOnline
155+
|| mBatteryStatus == BatteryManager.BATTERY_STATUS_UNKNOWN);
154156
}
155157

156158
public final boolean isPowered(int plugTypeSet) {
@@ -169,6 +171,9 @@ public final boolean isPowered(int plugTypeSet) {
169171
if (mUsbOnline) {
170172
plugTypeBit |= BatteryManager.BATTERY_PLUGGED_USB;
171173
}
174+
if (mWirelessOnline) {
175+
plugTypeBit |= BatteryManager.BATTERY_PLUGGED_WIRELESS;
176+
}
172177
return (plugTypeSet & plugTypeBit) != 0;
173178
}
174179

@@ -243,6 +248,8 @@ private void processValues() {
243248
mPlugType = BatteryManager.BATTERY_PLUGGED_AC;
244249
} else if (mUsbOnline) {
245250
mPlugType = BatteryManager.BATTERY_PLUGGED_USB;
251+
} else if (mWirelessOnline) {
252+
mPlugType = BatteryManager.BATTERY_PLUGGED_WIRELESS;
246253
} else {
247254
mPlugType = BATTERY_PLUGGED_NONE;
248255
}
@@ -398,6 +405,7 @@ private final void sendIntent() {
398405
" temperature: " + mBatteryTemperature +
399406
" technology: " + mBatteryTechnology +
400407
" AC powered:" + mAcOnline + " USB powered:" + mUsbOnline +
408+
" Wireless powered:" + mWirelessOnline +
401409
" icon:" + icon + " invalid charger:" + mInvalidCharger);
402410
}
403411

@@ -503,6 +511,7 @@ protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
503511
pw.println("Current Battery Service state:");
504512
pw.println(" AC powered: " + mAcOnline);
505513
pw.println(" USB powered: " + mUsbOnline);
514+
pw.println(" Wireless powered: " + mWirelessOnline);
506515
pw.println(" status: " + mBatteryStatus);
507516
pw.println(" health: " + mBatteryHealth);
508517
pw.println(" present: " + mBatteryPresent);
@@ -523,6 +532,8 @@ protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
523532
mAcOnline = Integer.parseInt(value) != 0;
524533
} else if ("usb".equals(key)) {
525534
mUsbOnline = Integer.parseInt(value) != 0;
535+
} else if ("wireless".equals(key)) {
536+
mWirelessOnline = Integer.parseInt(value) != 0;
526537
} else if ("status".equals(key)) {
527538
mBatteryStatus = Integer.parseInt(value);
528539
} else if ("level".equals(key)) {
@@ -603,4 +614,3 @@ void updateLightsLocked() {
603614
}
604615
}
605616
}
606-

services/jni/com_android_server_BatteryService.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ struct FieldIds {
4242
// members
4343
jfieldID mAcOnline;
4444
jfieldID mUsbOnline;
45+
jfieldID mWirelessOnline;
4546
jfieldID mBatteryStatus;
4647
jfieldID mBatteryHealth;
4748
jfieldID mBatteryPresent;
@@ -71,6 +72,7 @@ static BatteryManagerConstants gConstants;
7172
struct PowerSupplyPaths {
7273
char* acOnlinePath;
7374
char* usbOnlinePath;
75+
char* wirelessOnlinePath;
7476
char* batteryStatusPath;
7577
char* batteryHealthPath;
7678
char* batteryPresentPath;
@@ -198,6 +200,7 @@ static void android_server_BatteryService_update(JNIEnv* env, jobject obj)
198200
{
199201
setBooleanField(env, obj, gPaths.acOnlinePath, gFieldIds.mAcOnline);
200202
setBooleanField(env, obj, gPaths.usbOnlinePath, gFieldIds.mUsbOnline);
203+
setBooleanField(env, obj, gPaths.wirelessOnlinePath, gFieldIds.mWirelessOnline);
201204
setBooleanField(env, obj, gPaths.batteryPresentPath, gFieldIds.mBatteryPresent);
202205

203206
setIntField(env, obj, gPaths.batteryCapacityPath, gFieldIds.mBatteryLevel);
@@ -260,6 +263,11 @@ int register_android_server_BatteryService(JNIEnv* env)
260263
if (access(path, R_OK) == 0)
261264
gPaths.usbOnlinePath = strdup(path);
262265
}
266+
else if (strcmp(buf, "Wireless") == 0) {
267+
snprintf(path, sizeof(path), "%s/%s/online", POWER_SUPPLY_PATH, name);
268+
if (access(path, R_OK) == 0)
269+
gPaths.wirelessOnlinePath = strdup(path);
270+
}
263271
else if (strcmp(buf, "Battery") == 0) {
264272
snprintf(path, sizeof(path), "%s/%s/status", POWER_SUPPLY_PATH, name);
265273
if (access(path, R_OK) == 0)
@@ -307,6 +315,8 @@ int register_android_server_BatteryService(JNIEnv* env)
307315
ALOGE("acOnlinePath not found");
308316
if (!gPaths.usbOnlinePath)
309317
ALOGE("usbOnlinePath not found");
318+
if (!gPaths.wirelessOnlinePath)
319+
ALOGE("wirelessOnlinePath not found");
310320
if (!gPaths.batteryStatusPath)
311321
ALOGE("batteryStatusPath not found");
312322
if (!gPaths.batteryHealthPath)
@@ -331,6 +341,7 @@ int register_android_server_BatteryService(JNIEnv* env)
331341

332342
gFieldIds.mAcOnline = env->GetFieldID(clazz, "mAcOnline", "Z");
333343
gFieldIds.mUsbOnline = env->GetFieldID(clazz, "mUsbOnline", "Z");
344+
gFieldIds.mWirelessOnline = env->GetFieldID(clazz, "mWirelessOnline", "Z");
334345
gFieldIds.mBatteryStatus = env->GetFieldID(clazz, "mBatteryStatus", "I");
335346
gFieldIds.mBatteryHealth = env->GetFieldID(clazz, "mBatteryHealth", "I");
336347
gFieldIds.mBatteryPresent = env->GetFieldID(clazz, "mBatteryPresent", "Z");
@@ -341,6 +352,7 @@ int register_android_server_BatteryService(JNIEnv* env)
341352

342353
LOG_FATAL_IF(gFieldIds.mAcOnline == NULL, "Unable to find BatteryService.AC_ONLINE_PATH");
343354
LOG_FATAL_IF(gFieldIds.mUsbOnline == NULL, "Unable to find BatteryService.USB_ONLINE_PATH");
355+
LOG_FATAL_IF(gFieldIds.mWirelessOnline == NULL, "Unable to find BatteryService.WIRELESS_ONLINE_PATH");
344356
LOG_FATAL_IF(gFieldIds.mBatteryStatus == NULL, "Unable to find BatteryService.BATTERY_STATUS_PATH");
345357
LOG_FATAL_IF(gFieldIds.mBatteryHealth == NULL, "Unable to find BatteryService.BATTERY_HEALTH_PATH");
346358
LOG_FATAL_IF(gFieldIds.mBatteryPresent == NULL, "Unable to find BatteryService.BATTERY_PRESENT_PATH");

0 commit comments

Comments
 (0)