Skip to content

Commit 027828b

Browse files
committed
Report open networks without saved networks
The supplicant stops periodic scans when there are no saved networks. The framework needs to have a periodic scan to handle this scenario. We do have an infrequent wake up scan (15 mins), but thats way too slow to report an open network. Setup a scan by the supplicant interval when there are no saved networks Bug: 5420656 Change-Id: Id3708ecc874b42971643cc747bb9e7f2efc7d1dd
1 parent faac929 commit 027828b

File tree

1 file changed

+55
-15
lines changed

1 file changed

+55
-15
lines changed

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

Lines changed: 55 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,9 @@ public class WifiStateMachine extends StateMachine {
184184

185185
private LinkProperties mLinkProperties;
186186

187+
/* Tracks sequence number on a periodic scan message */
188+
private int mPeriodicScanToken = 0;
189+
187190
// Wakelock held during wifi start/stop and driver load/unload
188191
private PowerManager.WakeLock mWakeLock;
189192

@@ -331,6 +334,9 @@ public class WifiStateMachine extends StateMachine {
331334
static final int CMD_SET_SUSPEND_OPTIMIZATIONS = BASE + 86;
332335
/* Clear suspend mode optimizations in the driver */
333336
static final int CMD_CLEAR_SUSPEND_OPTIMIZATIONS = BASE + 87;
337+
/* When there are no saved networks, we do a periodic scan to notify user of
338+
* an open network */
339+
static final int CMD_NO_NETWORKS_PERIODIC_SCAN = BASE + 88;
334340

335341
/* arg1 values to CMD_STOP_PACKET_FILTERING and CMD_START_PACKET_FILTERING */
336342
static final int MULTICAST_V6 = 1;
@@ -385,10 +391,11 @@ public class WifiStateMachine extends StateMachine {
385391
private final int mDefaultFrameworkScanIntervalMs;
386392

387393
/**
388-
* Default supplicant scan interval in milliseconds.
389-
* {@link Settings.Secure#WIFI_SUPPLICANT_SCAN_INTERVAL_MS} can override this.
394+
* Supplicant scan interval in milliseconds.
395+
* Comes from {@link Settings.Secure#WIFI_SUPPLICANT_SCAN_INTERVAL_MS} or
396+
* from the default config if the setting is not set
390397
*/
391-
private final int mDefaultSupplicantScanIntervalMs;
398+
private long mSupplicantScanIntervalMs;
392399

393400
/**
394401
* Minimum time interval between enabling all networks.
@@ -568,9 +575,6 @@ public WifiStateMachine(Context context, String wlanInterface) {
568575
mDefaultFrameworkScanIntervalMs = mContext.getResources().getInteger(
569576
com.android.internal.R.integer.config_wifi_framework_scan_interval);
570577

571-
mDefaultSupplicantScanIntervalMs = mContext.getResources().getInteger(
572-
com.android.internal.R.integer.config_wifi_supplicant_scan_interval);
573-
574578
mDriverStopDelayMs = mContext.getResources().getInteger(
575579
com.android.internal.R.integer.config_wifi_driver_stop_delay);
576580

@@ -1870,6 +1874,7 @@ public boolean processMessage(Message message) {
18701874
case WifiWatchdogStateMachine.POOR_LINK_DETECTED:
18711875
case WifiWatchdogStateMachine.GOOD_LINK_DETECTED:
18721876
case CMD_CLEAR_SUSPEND_OPTIMIZATIONS:
1877+
case CMD_NO_NETWORKS_PERIODIC_SCAN:
18731878
break;
18741879
case CMD_SET_SUSPEND_OPTIMIZATIONS:
18751880
mSuspendWakeLock.release();
@@ -2269,11 +2274,15 @@ public void enter() {
22692274
mIsScanMode = false;
22702275
/* Wifi is available as long as we have a connection to supplicant */
22712276
mNetworkInfo.setIsAvailable(true);
2272-
/* Set scan interval */
2273-
long supplicantScanIntervalMs = Settings.Secure.getLong(mContext.getContentResolver(),
2277+
2278+
int defaultInterval = mContext.getResources().getInteger(
2279+
com.android.internal.R.integer.config_wifi_supplicant_scan_interval);
2280+
2281+
mSupplicantScanIntervalMs = Settings.Secure.getLong(mContext.getContentResolver(),
22742282
Settings.Secure.WIFI_SUPPLICANT_SCAN_INTERVAL_MS,
2275-
mDefaultSupplicantScanIntervalMs);
2276-
mWifiNative.setScanInterval((int)supplicantScanIntervalMs / 1000);
2283+
defaultInterval);
2284+
2285+
mWifiNative.setScanInterval((int)mSupplicantScanIntervalMs / 1000);
22772286
}
22782287
@Override
22792288
public boolean processMessage(Message message) {
@@ -3270,11 +3279,39 @@ public void enter() {
32703279
} else {
32713280
setScanAlarm(true);
32723281
}
3282+
3283+
/**
3284+
* If we have no networks saved, the supplicant stops doing the periodic scan.
3285+
* The scans are useful to notify the user of the presence of an open network.
3286+
* Note that these are not wake up scans.
3287+
*/
3288+
if (mWifiConfigStore.getConfiguredNetworks().size() == 0) {
3289+
sendMessageDelayed(obtainMessage(CMD_NO_NETWORKS_PERIODIC_SCAN,
3290+
++mPeriodicScanToken, 0), mSupplicantScanIntervalMs);
3291+
}
32733292
}
32743293
@Override
32753294
public boolean processMessage(Message message) {
32763295
if (DBG) log(getName() + message.toString() + "\n");
3296+
boolean ret = HANDLED;
32773297
switch (message.what) {
3298+
case CMD_NO_NETWORKS_PERIODIC_SCAN:
3299+
if (message.arg1 == mPeriodicScanToken &&
3300+
mWifiConfigStore.getConfiguredNetworks().size() == 0) {
3301+
sendMessage(CMD_START_SCAN);
3302+
sendMessageDelayed(obtainMessage(CMD_NO_NETWORKS_PERIODIC_SCAN,
3303+
++mPeriodicScanToken, 0), mSupplicantScanIntervalMs);
3304+
}
3305+
break;
3306+
case WifiManager.FORGET_NETWORK:
3307+
case CMD_REMOVE_NETWORK:
3308+
// Set up a delayed message here. After the forget/remove is handled
3309+
// the handled delayed message will determine if there is a need to
3310+
// scan and continue
3311+
sendMessageDelayed(obtainMessage(CMD_NO_NETWORKS_PERIODIC_SCAN,
3312+
++mPeriodicScanToken, 0), mSupplicantScanIntervalMs);
3313+
ret = NOT_HANDLED;
3314+
break;
32783315
case CMD_SET_SCAN_MODE:
32793316
if (message.arg1 == SCAN_ONLY_MODE) {
32803317
mWifiNative.setScanResultHandling(message.arg1);
@@ -3301,25 +3338,28 @@ public boolean processMessage(Message message) {
33013338
StateChangeResult stateChangeResult = (StateChangeResult) message.obj;
33023339
setNetworkDetailedState(WifiInfo.getDetailedStateOf(stateChangeResult.state));
33033340
/* ConnectModeState does the rest of the handling */
3304-
return NOT_HANDLED;
3341+
ret = NOT_HANDLED;
3342+
break;
33053343
case CMD_START_SCAN:
33063344
/* Disable background scan temporarily during a regular scan */
33073345
if (mEnableBackgroundScan) {
33083346
mWifiNative.enableBackgroundScan(false);
33093347
}
33103348
/* Handled in parent state */
3311-
return NOT_HANDLED;
3349+
ret = NOT_HANDLED;
3350+
break;
33123351
case WifiMonitor.SCAN_RESULTS_EVENT:
33133352
/* Re-enable background scan when a pending scan result is received */
33143353
if (mEnableBackgroundScan && mScanResultIsPending) {
33153354
mWifiNative.enableBackgroundScan(true);
33163355
}
33173356
/* Handled in parent state */
3318-
return NOT_HANDLED;
3357+
ret = NOT_HANDLED;
3358+
break;
33193359
default:
3320-
return NOT_HANDLED;
3360+
ret = NOT_HANDLED;
33213361
}
3322-
return HANDLED;
3362+
return ret;
33233363
}
33243364

33253365
@Override

0 commit comments

Comments
 (0)