Skip to content

Commit 8a34718

Browse files
isheriffAndroid (Google) Code Review
authored andcommitted
Merge "Control suspend optimizations from framework"
2 parents a003776 + 262f766 commit 8a34718

File tree

3 files changed

+74
-45
lines changed

3 files changed

+74
-45
lines changed

services/java/com/android/server/WifiService.java

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,6 @@ public class WifiService extends IWifiManager.Stub {
101101
private boolean mEmergencyCallbackMode = false;
102102
private int mPluggedType;
103103

104-
/* Chipset supports background scan */
105-
private final boolean mBackgroundScanSupported;
106-
107104
private final LockList mLocks = new LockList();
108105
// some wifi lock statistics
109106
private int mFullHighPerfLocksAcquired;
@@ -435,9 +432,6 @@ public void onReceive(Context context, Intent intent) {
435432
Settings.Secure.WIFI_NETWORKS_AVAILABLE_REPEAT_DELAY, 900) * 1000l;
436433
mNotificationEnabledSettingObserver = new NotificationEnabledSettingObserver(new Handler());
437434
mNotificationEnabledSettingObserver.register();
438-
439-
mBackgroundScanSupported = mContext.getResources().getBoolean(
440-
com.android.internal.R.bool.config_wifi_background_scan_support);
441435
}
442436

443437
/**
@@ -956,22 +950,13 @@ public void onReceive(Context context, Intent intent) {
956950
mAlarmManager.cancel(mIdleIntent);
957951
mScreenOff = false;
958952
evaluateTrafficStatsPolling();
959-
mWifiStateMachine.enableRssiPolling(true);
960-
if (mBackgroundScanSupported) {
961-
mWifiStateMachine.enableBackgroundScanCommand(false);
962-
}
963-
mWifiStateMachine.enableAllNetworks();
964953
setDeviceIdleAndUpdateWifi(false);
965954
} else if (action.equals(Intent.ACTION_SCREEN_OFF)) {
966955
if (DBG) {
967956
Slog.d(TAG, "ACTION_SCREEN_OFF");
968957
}
969958
mScreenOff = true;
970959
evaluateTrafficStatsPolling();
971-
mWifiStateMachine.enableRssiPolling(false);
972-
if (mBackgroundScanSupported) {
973-
mWifiStateMachine.enableBackgroundScanCommand(true);
974-
}
975960
/*
976961
* Set a timer to put Wi-Fi to sleep, but only if the screen is off
977962
* AND the "stay on while plugged in" setting doesn't match the

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -354,9 +354,9 @@ public boolean clearBlacklist() {
354354

355355
public boolean setSuspendOptimizations(boolean enabled) {
356356
if (enabled) {
357-
return doBooleanCommand("DRIVER SETSUSPENDOPT 0");
357+
return doBooleanCommand("DRIVER SETSUSPENDMODE 1");
358358
} else {
359-
return doBooleanCommand("DRIVER SETSUSPENDOPT 1");
359+
return doBooleanCommand("DRIVER SETSUSPENDMODE 0");
360360
}
361361
}
362362

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

Lines changed: 72 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,9 @@ public class WifiStateMachine extends StateMachine {
127127
private static final int SCAN_RESULT_CACHE_SIZE = 80;
128128
private final LruCache<String, ScanResult> mScanResultCache;
129129

130+
/* Chipset supports background scan */
131+
private final boolean mBackgroundScanSupported;
132+
130133
private String mInterfaceName;
131134
/* Tethering interface could be seperate from wlan interface */
132135
private String mTetherInterfaceName;
@@ -142,9 +145,15 @@ public class WifiStateMachine extends StateMachine {
142145
private boolean mScanResultIsPending = false;
143146
/* Tracks if the current scan settings are active */
144147
private boolean mSetScanActive = false;
148+
/* High perf mode is true if an app has held a high perf Wifi Lock */
149+
private boolean mHighPerfMode = false;
145150

146151
private boolean mBluetoothConnectionActive = false;
147152

153+
private BroadcastReceiver mScreenReceiver;
154+
private IntentFilter mScreenFilter;
155+
private PowerManager.WakeLock mSuspendWakeLock;
156+
148157
/**
149158
* Interval in milliseconds between polling for RSSI
150159
* and linkspeed information
@@ -320,6 +329,10 @@ public class WifiStateMachine extends StateMachine {
320329
static final int CMD_START_PACKET_FILTERING = BASE + 84;
321330
/* Clear packet filter */
322331
static final int CMD_STOP_PACKET_FILTERING = BASE + 85;
332+
/* Set suspend mode optimizations in the driver */
333+
static final int CMD_SET_SUSPEND_OPTIMIZATIONS = BASE + 86;
334+
/* Clear suspend mode optimizations in the driver */
335+
static final int CMD_CLEAR_SUSPEND_OPTIMIZATIONS = BASE + 87;
323336

324337
/* arg1 values to CMD_STOP_PACKET_FILTERING and CMD_START_PACKET_FILTERING */
325338
static final int MULTICAST_V6 = 1;
@@ -566,6 +579,9 @@ public WifiStateMachine(Context context, String wlanInterface) {
566579
mDriverStopDelayMs = mContext.getResources().getInteger(
567580
com.android.internal.R.integer.config_wifi_driver_stop_delay);
568581

582+
mBackgroundScanSupported = mContext.getResources().getBoolean(
583+
com.android.internal.R.bool.config_wifi_background_scan_support);
584+
569585
mContext.registerReceiver(
570586
new BroadcastReceiver() {
571587
@Override
@@ -587,11 +603,41 @@ public void onReceive(Context context, Intent intent) {
587603
},
588604
new IntentFilter(ACTION_START_SCAN));
589605

606+
mScreenFilter = new IntentFilter();
607+
mScreenFilter.addAction(Intent.ACTION_SCREEN_ON);
608+
mScreenFilter.addAction(Intent.ACTION_SCREEN_OFF);
609+
mScreenReceiver = new BroadcastReceiver() {
610+
@Override
611+
public void onReceive(Context context, Intent intent) {
612+
String action = intent.getAction();
613+
614+
if (action.equals(Intent.ACTION_SCREEN_ON)) {
615+
enableRssiPolling(true);
616+
if (mBackgroundScanSupported) {
617+
enableBackgroundScanCommand(false);
618+
}
619+
enableAllNetworks();
620+
sendMessage(CMD_CLEAR_SUSPEND_OPTIMIZATIONS);
621+
} else if (action.equals(Intent.ACTION_SCREEN_OFF)) {
622+
enableRssiPolling(false);
623+
if (mBackgroundScanSupported) {
624+
enableBackgroundScanCommand(true);
625+
}
626+
//Allow 2s for suspend optimizations to be set
627+
mSuspendWakeLock.acquire(2000);
628+
sendMessage(CMD_SET_SUSPEND_OPTIMIZATIONS);
629+
}
630+
}
631+
};
632+
590633
mScanResultCache = new LruCache<String, ScanResult>(SCAN_RESULT_CACHE_SIZE);
591634

592635
PowerManager powerManager = (PowerManager)mContext.getSystemService(Context.POWER_SERVICE);
593636
mWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG);
594637

638+
mSuspendWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "WifiSuspend");
639+
mSuspendWakeLock.setReferenceCounted(false);
640+
595641
addState(mDefaultState);
596642
addState(mInitialState, mDefaultState);
597643
addState(mDriverUnloadingState, mDefaultState);
@@ -1436,21 +1482,6 @@ private void fetchRssiAndLinkSpeedNative() {
14361482
}
14371483
}
14381484

1439-
private void setHighPerfModeEnabledNative(boolean enable) {
1440-
if(!mWifiNative.setSuspendOptimizations(!enable)) {
1441-
loge("set suspend optimizations failed!");
1442-
}
1443-
if (enable) {
1444-
if (!mWifiNative.setPowerMode(POWER_MODE_ACTIVE)) {
1445-
loge("set power mode active failed!");
1446-
}
1447-
} else {
1448-
if (!mWifiNative.setPowerMode(POWER_MODE_AUTO)) {
1449-
loge("set power mode auto failed!");
1450-
}
1451-
}
1452-
}
1453-
14541485
private void configureLinkProperties() {
14551486
if (mWifiConfigStore.isUsingStaticIp(mLastNetworkId)) {
14561487
mLinkProperties = mWifiConfigStore.getLinkProperties(mLastNetworkId);
@@ -1781,6 +1812,9 @@ public boolean processMessage(Message message) {
17811812
case CMD_ENABLE_BACKGROUND_SCAN:
17821813
mEnableBackgroundScan = (message.arg1 == 1);
17831814
break;
1815+
case CMD_SET_HIGH_PERF_MODE:
1816+
mHighPerfMode = (message.arg1 == 1);
1817+
break;
17841818
/* Discard */
17851819
case CMD_LOAD_DRIVER:
17861820
case CMD_UNLOAD_DRIVER:
@@ -1812,7 +1846,6 @@ public boolean processMessage(Message message) {
18121846
case CMD_CLEAR_BLACKLIST:
18131847
case CMD_SET_SCAN_MODE:
18141848
case CMD_SET_SCAN_TYPE:
1815-
case CMD_SET_HIGH_PERF_MODE:
18161849
case CMD_SET_COUNTRY_CODE:
18171850
case CMD_SET_FREQUENCY_BAND:
18181851
case CMD_RSSI_POLL:
@@ -1826,6 +1859,10 @@ public boolean processMessage(Message message) {
18261859
case CMD_RESPONSE_AP_CONFIG:
18271860
case WifiWatchdogStateMachine.POOR_LINK_DETECTED:
18281861
case WifiWatchdogStateMachine.GOOD_LINK_DETECTED:
1862+
case CMD_CLEAR_SUSPEND_OPTIMIZATIONS:
1863+
break;
1864+
case CMD_SET_SUSPEND_OPTIMIZATIONS:
1865+
mSuspendWakeLock.release();
18291866
break;
18301867
case WifiMonitor.DRIVER_HUNG_EVENT:
18311868
setWifiEnabled(false);
@@ -1969,7 +2006,6 @@ public boolean processMessage(Message message) {
19692006
case CMD_STOP_DRIVER:
19702007
case CMD_SET_SCAN_MODE:
19712008
case CMD_SET_SCAN_TYPE:
1972-
case CMD_SET_HIGH_PERF_MODE:
19732009
case CMD_SET_COUNTRY_CODE:
19742010
case CMD_SET_FREQUENCY_BAND:
19752011
case CMD_START_PACKET_FILTERING:
@@ -2103,7 +2139,6 @@ public boolean processMessage(Message message) {
21032139
case CMD_STOP_DRIVER:
21042140
case CMD_SET_SCAN_MODE:
21052141
case CMD_SET_SCAN_TYPE:
2106-
case CMD_SET_HIGH_PERF_MODE:
21072142
case CMD_SET_COUNTRY_CODE:
21082143
case CMD_SET_FREQUENCY_BAND:
21092144
case CMD_START_PACKET_FILTERING:
@@ -2206,7 +2241,6 @@ public boolean processMessage(Message message) {
22062241
case CMD_STOP_DRIVER:
22072242
case CMD_SET_SCAN_MODE:
22082243
case CMD_SET_SCAN_TYPE:
2209-
case CMD_SET_HIGH_PERF_MODE:
22102244
case CMD_SET_COUNTRY_CODE:
22112245
case CMD_SET_FREQUENCY_BAND:
22122246
case CMD_START_PACKET_FILTERING:
@@ -2416,7 +2450,6 @@ public boolean processMessage(Message message) {
24162450
case CMD_STOP_DRIVER:
24172451
case CMD_SET_SCAN_MODE:
24182452
case CMD_SET_SCAN_TYPE:
2419-
case CMD_SET_HIGH_PERF_MODE:
24202453
case CMD_SET_COUNTRY_CODE:
24212454
case CMD_SET_FREQUENCY_BAND:
24222455
case CMD_START_PACKET_FILTERING:
@@ -2459,7 +2492,6 @@ public boolean processMessage(Message message) {
24592492
case WifiMonitor.AUTHENTICATION_FAILURE_EVENT:
24602493
case WifiMonitor.WPS_OVERLAP_EVENT:
24612494
case CMD_SET_SCAN_TYPE:
2462-
case CMD_SET_HIGH_PERF_MODE:
24632495
case CMD_SET_COUNTRY_CODE:
24642496
case CMD_SET_FREQUENCY_BAND:
24652497
case CMD_START_PACKET_FILTERING:
@@ -2526,6 +2558,8 @@ public void enter() {
25262558
}
25272559

25282560
if (mP2pSupported) mWifiP2pChannel.sendMessage(WifiStateMachine.CMD_ENABLE_P2P);
2561+
2562+
mContext.registerReceiver(mScreenReceiver, mScreenFilter);
25292563
}
25302564
@Override
25312565
public boolean processMessage(Message message) {
@@ -2548,9 +2582,6 @@ public boolean processMessage(Message message) {
25482582
}
25492583
mScanResultIsPending = true;
25502584
break;
2551-
case CMD_SET_HIGH_PERF_MODE:
2552-
setHighPerfModeEnabledNative(message.arg1 == 1);
2553-
break;
25542585
case CMD_SET_COUNTRY_CODE:
25552586
String country = (String) message.obj;
25562587
if (DBG) log("set country code " + country);
@@ -2631,6 +2662,22 @@ public boolean processMessage(Message message) {
26312662
loge("Illegal arugments to CMD_STOP_PACKET_FILTERING");
26322663
}
26332664
break;
2665+
case CMD_SET_SUSPEND_OPTIMIZATIONS:
2666+
if (!mHighPerfMode) {
2667+
mWifiNative.setSuspendOptimizations(true);
2668+
}
2669+
mSuspendWakeLock.release();
2670+
break;
2671+
case CMD_CLEAR_SUSPEND_OPTIMIZATIONS:
2672+
mWifiNative.setSuspendOptimizations(false);
2673+
break;
2674+
case CMD_SET_HIGH_PERF_MODE:
2675+
mHighPerfMode = (message.arg1 == 1);
2676+
if (mHighPerfMode) {
2677+
//Disable any suspend optimizations
2678+
mWifiNative.setSuspendOptimizations(false);
2679+
}
2680+
break;
26342681
default:
26352682
return NOT_HANDLED;
26362683
}
@@ -2647,6 +2694,7 @@ public void exit() {
26472694
mScanResults = null;
26482695

26492696
if (mP2pSupported) mWifiP2pChannel.sendMessage(WifiStateMachine.CMD_DISABLE_P2P);
2697+
mContext.unregisterReceiver(mScreenReceiver);
26502698
}
26512699
}
26522700

@@ -2670,7 +2718,6 @@ public boolean processMessage(Message message) {
26702718
case CMD_START_DRIVER:
26712719
case CMD_STOP_DRIVER:
26722720
case CMD_SET_SCAN_TYPE:
2673-
case CMD_SET_HIGH_PERF_MODE:
26742721
case CMD_SET_COUNTRY_CODE:
26752722
case CMD_SET_FREQUENCY_BAND:
26762723
case CMD_START_PACKET_FILTERING:
@@ -3430,7 +3477,6 @@ public boolean processMessage(Message message) {
34303477
case CMD_STOP_DRIVER:
34313478
case CMD_SET_SCAN_MODE:
34323479
case CMD_SET_SCAN_TYPE:
3433-
case CMD_SET_HIGH_PERF_MODE:
34343480
case CMD_SET_COUNTRY_CODE:
34353481
case CMD_SET_FREQUENCY_BAND:
34363482
case CMD_START_PACKET_FILTERING:
@@ -3543,7 +3589,6 @@ public boolean processMessage(Message message) {
35433589
case CMD_STOP_DRIVER:
35443590
case CMD_SET_SCAN_MODE:
35453591
case CMD_SET_SCAN_TYPE:
3546-
case CMD_SET_HIGH_PERF_MODE:
35473592
case CMD_SET_COUNTRY_CODE:
35483593
case CMD_SET_FREQUENCY_BAND:
35493594
case CMD_START_PACKET_FILTERING:
@@ -3638,7 +3683,6 @@ public boolean processMessage(Message message) {
36383683
case CMD_STOP_DRIVER:
36393684
case CMD_SET_SCAN_MODE:
36403685
case CMD_SET_SCAN_TYPE:
3641-
case CMD_SET_HIGH_PERF_MODE:
36423686
case CMD_SET_COUNTRY_CODE:
36433687
case CMD_SET_FREQUENCY_BAND:
36443688
case CMD_START_PACKET_FILTERING:

0 commit comments

Comments
 (0)