Skip to content

Commit 531522c

Browse files
isheriffAndroid (Google) Code Review
authored andcommitted
Merge "Report open networks without saved networks" into jb-dev
2 parents aac5066 + 027828b commit 531522c

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

@@ -1869,6 +1873,7 @@ public boolean processMessage(Message message) {
18691873
case WifiWatchdogStateMachine.POOR_LINK_DETECTED:
18701874
case WifiWatchdogStateMachine.GOOD_LINK_DETECTED:
18711875
case CMD_CLEAR_SUSPEND_OPTIMIZATIONS:
1876+
case CMD_NO_NETWORKS_PERIODIC_SCAN:
18721877
break;
18731878
case CMD_SET_SUSPEND_OPTIMIZATIONS:
18741879
mSuspendWakeLock.release();
@@ -2268,11 +2273,15 @@ public void enter() {
22682273
mIsScanMode = false;
22692274
/* Wifi is available as long as we have a connection to supplicant */
22702275
mNetworkInfo.setIsAvailable(true);
2271-
/* Set scan interval */
2272-
long supplicantScanIntervalMs = Settings.Secure.getLong(mContext.getContentResolver(),
2276+
2277+
int defaultInterval = mContext.getResources().getInteger(
2278+
com.android.internal.R.integer.config_wifi_supplicant_scan_interval);
2279+
2280+
mSupplicantScanIntervalMs = Settings.Secure.getLong(mContext.getContentResolver(),
22732281
Settings.Secure.WIFI_SUPPLICANT_SCAN_INTERVAL_MS,
2274-
mDefaultSupplicantScanIntervalMs);
2275-
mWifiNative.setScanInterval((int)supplicantScanIntervalMs / 1000);
2282+
defaultInterval);
2283+
2284+
mWifiNative.setScanInterval((int)mSupplicantScanIntervalMs / 1000);
22762285
}
22772286
@Override
22782287
public boolean processMessage(Message message) {
@@ -3273,11 +3282,39 @@ public void enter() {
32733282
} else {
32743283
setScanAlarm(true);
32753284
}
3285+
3286+
/**
3287+
* If we have no networks saved, the supplicant stops doing the periodic scan.
3288+
* The scans are useful to notify the user of the presence of an open network.
3289+
* Note that these are not wake up scans.
3290+
*/
3291+
if (mWifiConfigStore.getConfiguredNetworks().size() == 0) {
3292+
sendMessageDelayed(obtainMessage(CMD_NO_NETWORKS_PERIODIC_SCAN,
3293+
++mPeriodicScanToken, 0), mSupplicantScanIntervalMs);
3294+
}
32763295
}
32773296
@Override
32783297
public boolean processMessage(Message message) {
32793298
if (DBG) log(getName() + message.toString() + "\n");
3299+
boolean ret = HANDLED;
32803300
switch (message.what) {
3301+
case CMD_NO_NETWORKS_PERIODIC_SCAN:
3302+
if (message.arg1 == mPeriodicScanToken &&
3303+
mWifiConfigStore.getConfiguredNetworks().size() == 0) {
3304+
sendMessage(CMD_START_SCAN);
3305+
sendMessageDelayed(obtainMessage(CMD_NO_NETWORKS_PERIODIC_SCAN,
3306+
++mPeriodicScanToken, 0), mSupplicantScanIntervalMs);
3307+
}
3308+
break;
3309+
case WifiManager.FORGET_NETWORK:
3310+
case CMD_REMOVE_NETWORK:
3311+
// Set up a delayed message here. After the forget/remove is handled
3312+
// the handled delayed message will determine if there is a need to
3313+
// scan and continue
3314+
sendMessageDelayed(obtainMessage(CMD_NO_NETWORKS_PERIODIC_SCAN,
3315+
++mPeriodicScanToken, 0), mSupplicantScanIntervalMs);
3316+
ret = NOT_HANDLED;
3317+
break;
32813318
case CMD_SET_SCAN_MODE:
32823319
if (message.arg1 == SCAN_ONLY_MODE) {
32833320
mWifiNative.setScanResultHandling(message.arg1);
@@ -3304,25 +3341,28 @@ public boolean processMessage(Message message) {
33043341
StateChangeResult stateChangeResult = (StateChangeResult) message.obj;
33053342
setNetworkDetailedState(WifiInfo.getDetailedStateOf(stateChangeResult.state));
33063343
/* ConnectModeState does the rest of the handling */
3307-
return NOT_HANDLED;
3344+
ret = NOT_HANDLED;
3345+
break;
33083346
case CMD_START_SCAN:
33093347
/* Disable background scan temporarily during a regular scan */
33103348
if (mEnableBackgroundScan) {
33113349
mWifiNative.enableBackgroundScan(false);
33123350
}
33133351
/* Handled in parent state */
3314-
return NOT_HANDLED;
3352+
ret = NOT_HANDLED;
3353+
break;
33153354
case WifiMonitor.SCAN_RESULTS_EVENT:
33163355
/* Re-enable background scan when a pending scan result is received */
33173356
if (mEnableBackgroundScan && mScanResultIsPending) {
33183357
mWifiNative.enableBackgroundScan(true);
33193358
}
33203359
/* Handled in parent state */
3321-
return NOT_HANDLED;
3360+
ret = NOT_HANDLED;
3361+
break;
33223362
default:
3323-
return NOT_HANDLED;
3363+
ret = NOT_HANDLED;
33243364
}
3325-
return HANDLED;
3365+
return ret;
33263366
}
33273367

33283368
@Override

0 commit comments

Comments
 (0)