Skip to content

Commit e2639d7

Browse files
committed
Switch to standard commands for pno & power save
Remove DRIVER commands and switch to cfg based commands Bug: 6318223 Change-Id: I5e21c4bb554c2992a52fd3c1741629645b22ae43
1 parent ca7086f commit e2639d7

File tree

3 files changed

+25
-45
lines changed

3 files changed

+25
-45
lines changed

core/res/res/values/config.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,8 +271,7 @@
271271
<!-- Boolean indicating whether the wifi chipset supports background scanning mechanism.
272272
This mechanism allows the host to remain in suspend state and the dongle to actively
273273
scan and wake the host when a configured SSID is detected by the dongle. This chipset
274-
capability can provide power savings when wifi needs to be always kept on.
275-
The driver commands needed to support the feature are BGSCAN-START and BGSCAN-STOP -->
274+
capability can provide power savings when wifi needs to be always kept on. -->
276275
<bool translatable="false" name="config_wifi_background_scan_support">false</bool>
277276

278277
<!-- Integer indicating wpa_supplicant scan interval in milliseconds -->

wifi/java/android/net/wifi/WifiNative.java

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -270,25 +270,6 @@ && doBooleanCommand("DRIVER RXFILTER-ADD 3")
270270
&& doBooleanCommand("DRIVER RXFILTER-START");
271271
}
272272

273-
public int getPowerMode() {
274-
String ret = doStringCommand("DRIVER GETPOWER");
275-
if (!TextUtils.isEmpty(ret)) {
276-
// reply comes back in the form "powermode = XX" where XX is the
277-
// number we're interested in.
278-
String[] tokens = ret.split(" = ");
279-
try {
280-
if (tokens.length == 2) return Integer.parseInt(tokens[1]);
281-
} catch (NumberFormatException e) {
282-
return -1;
283-
}
284-
}
285-
return -1;
286-
}
287-
288-
public boolean setPowerMode(int mode) {
289-
return doBooleanCommand("DRIVER POWERMODE " + mode);
290-
}
291-
292273
public int getBand() {
293274
String ret = doStringCommand("DRIVER GETBAND");
294275
if (!TextUtils.isEmpty(ret)) {
@@ -366,12 +347,10 @@ public boolean setCountryCode(String countryCode) {
366347
}
367348

368349
public void enableBackgroundScan(boolean enable) {
369-
//Note: BGSCAN-START and BGSCAN-STOP are documented in core/res/res/values/config.xml
370-
//and will need an update if the names are changed
371350
if (enable) {
372-
doBooleanCommand("DRIVER BGSCAN-START");
351+
doBooleanCommand("SET pno 1");
373352
} else {
374-
doBooleanCommand("DRIVER BGSCAN-STOP");
353+
doBooleanCommand("SET pno 0");
375354
}
376355
}
377356

@@ -467,6 +446,14 @@ public boolean setP2pGroupIdle(String iface, int time) {
467446
return doBooleanCommand("SET interface=" + iface + " p2p_group_idle " + time);
468447
}
469448

449+
public void setPowerSave(boolean enabled) {
450+
if (enabled) {
451+
doBooleanCommand("SET ps 1");
452+
} else {
453+
doBooleanCommand("SET ps 0");
454+
}
455+
}
456+
470457
public boolean setP2pPowerSave(String iface, boolean enabled) {
471458
if (enabled) {
472459
return doBooleanCommand("P2P_SET interface=" + iface + " ps 1");

wifi/java/android/net/wifi/WifiStateMachine.java

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -305,13 +305,11 @@ public class WifiStateMachine extends StateMachine {
305305
static final int CMD_RECONNECT = BASE + 75;
306306
/* Reassociate to a network */
307307
static final int CMD_REASSOCIATE = BASE + 76;
308-
/* Controls power mode and suspend mode optimizations
308+
/* Controls suspend mode optimizations
309309
*
310-
* When high perf mode is enabled, power mode is set to
311-
* POWER_MODE_ACTIVE and suspend mode optimizations are disabled
310+
* When high perf mode is enabled, suspend mode optimizations are disabled
312311
*
313-
* When high perf mode is disabled, power mode is set to
314-
* POWER_MODE_AUTO and suspend mode optimizations are enabled
312+
* When high perf mode is disabled, suspend mode optimizations are enabled
315313
*
316314
* Suspend mode optimizations include:
317315
* - packet filtering
@@ -374,11 +372,8 @@ public class WifiStateMachine extends StateMachine {
374372
*/
375373
private static final int DEFAULT_MAX_DHCP_RETRIES = 9;
376374

377-
static final int POWER_MODE_ACTIVE = 1;
378-
static final int POWER_MODE_AUTO = 0;
379-
380-
/* Tracks the power mode for restoration after a DHCP request/renewal goes through */
381-
private int mPowerMode = POWER_MODE_AUTO;
375+
/* Tracks if power save is enabled in driver */
376+
private boolean mPowerSaveEnabled = true;;
382377

383378
/**
384379
* Default framework scan interval in milliseconds. This is used in the scenario in which
@@ -1683,21 +1678,18 @@ void handlePreDhcpSetup() {
16831678
mWifiNative.BLUETOOTH_COEXISTENCE_MODE_DISABLED);
16841679
}
16851680

1686-
mPowerMode = mWifiNative.getPowerMode();
1687-
if (mPowerMode < 0) {
1688-
// Handle the case where supplicant driver does not support
1689-
// getPowerModeCommand.
1690-
mPowerMode = WifiStateMachine.POWER_MODE_AUTO;
1691-
}
1692-
if (mPowerMode != WifiStateMachine.POWER_MODE_ACTIVE) {
1693-
mWifiNative.setPowerMode(WifiStateMachine.POWER_MODE_ACTIVE);
1681+
/* Disable power save during DHCP */
1682+
if (mPowerSaveEnabled) {
1683+
mPowerSaveEnabled = false;
1684+
mWifiNative.setPowerSave(mPowerSaveEnabled);
16941685
}
16951686
}
16961687

16971688

16981689
void handlePostDhcpSetup() {
1699-
/* restore power mode */
1700-
mWifiNative.setPowerMode(mPowerMode);
1690+
/* Restore power save */
1691+
mPowerSaveEnabled = true;
1692+
mWifiNative.setPowerSave(mPowerSaveEnabled);
17011693

17021694
// Set the coexistence mode back to its default value
17031695
mWifiNative.setBluetoothCoexistenceMode(
@@ -2549,6 +2541,8 @@ public void enter() {
25492541
mWifiNative.stopFilteringMulticastV4Packets();
25502542
}
25512543

2544+
mWifiNative.setPowerSave(mPowerSaveEnabled);
2545+
25522546
if (mIsScanMode) {
25532547
mWifiNative.setScanResultHandling(SCAN_ONLY_MODE);
25542548
mWifiNative.disconnect();

0 commit comments

Comments
 (0)