Skip to content

Commit 8a4cd3b

Browse files
isheriffAndroid (Google) Code Review
authored andcommitted
Merge "Disable poor network connection alone" into ics-mr1
2 parents 0a83e9d + 19380da commit 8a4cd3b

File tree

2 files changed

+49
-11
lines changed

2 files changed

+49
-11
lines changed

core/java/android/provider/Settings.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3111,6 +3111,14 @@ public static final String getBluetoothInputDevicePriorityKey(String address) {
31113111
public static final String WIFI_WATCHDOG_BLACKLIST_FOLLOWUP_INTERVAL_MS =
31123112
"wifi_watchdog_blacklist_followup_interval_ms";
31133113

3114+
/**
3115+
* Setting to turn off poor network avoidance on Wi-Fi. Feature is disabled by default and
3116+
* the setting needs to be set to 1 to enable it.
3117+
* @hide
3118+
*/
3119+
public static final String WIFI_WATCHDOG_POOR_NETWORK_TEST_ENABLED =
3120+
"wifi_watchdog_poor_network_test_enabled";
3121+
31143122
/**
31153123
* Setting to turn off walled garden test on Wi-Fi. Feature is enabled by default and
31163124
* the setting needs to be set to 0 to disable it.

wifi/java/android/net/wifi/WifiWatchdogStateMachine.java

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ public class WifiWatchdogStateMachine extends StateMachine {
150150
private ConnectedState mConnectedState = new ConnectedState();
151151
private DnsCheckingState mDnsCheckingState = new DnsCheckingState();
152152
private OnlineWatchState mOnlineWatchState = new OnlineWatchState();
153+
private OnlineState mOnlineState = new OnlineState();
153154
private DnsCheckFailureState mDnsCheckFailureState = new DnsCheckFailureState();
154155
private DelayWalledGardenState mDelayWalledGardenState = new DelayWalledGardenState();
155156
private WalledGardenState mWalledGardenState = new WalledGardenState();
@@ -163,6 +164,7 @@ public class WifiWatchdogStateMachine extends StateMachine {
163164
private int mMinDnsResponses;
164165
private int mDnsPingTimeoutMs;
165166
private long mBlacklistFollowupIntervalMs;
167+
private boolean mPoorNetworkDetectionEnabled;
166168
private boolean mWalledGardenTestEnabled;
167169
private String mWalledGardenUrl;
168170

@@ -226,6 +228,7 @@ private WifiWatchdogStateMachine(Context context) {
226228
addState(mWalledGardenState, mConnectedState);
227229
addState(mBlacklistedApState, mConnectedState);
228230
addState(mOnlineWatchState, mConnectedState);
231+
addState(mOnlineState, mConnectedState);
229232

230233
setInitialState(mWatchdogDisabledState);
231234
updateSettings();
@@ -386,9 +389,7 @@ public void dump(PrintWriter pw) {
386389
}
387390

388391
private boolean isWatchdogEnabled() {
389-
//return getSettingsBoolean(mContentResolver, Settings.Secure.WIFI_WATCHDOG_ON, true);
390-
//TODO: fix this when we do aggressive monitoring
391-
return false;
392+
return getSettingsBoolean(mContentResolver, Settings.Secure.WIFI_WATCHDOG_ON, true);
392393
}
393394

394395
private void updateSettings() {
@@ -413,6 +414,10 @@ private void updateSettings() {
413414
mBlacklistFollowupIntervalMs = Secure.getLong(mContentResolver,
414415
Settings.Secure.WIFI_WATCHDOG_BLACKLIST_FOLLOWUP_INTERVAL_MS,
415416
DEFAULT_BLACKLIST_FOLLOWUP_INTERVAL_MS);
417+
//TODO: enable this by default after changing watchdog behavior
418+
//Also, update settings description
419+
mPoorNetworkDetectionEnabled = getSettingsBoolean(mContentResolver,
420+
Settings.Secure.WIFI_WATCHDOG_POOR_NETWORK_TEST_ENABLED, false);
416421
mWalledGardenTestEnabled = getSettingsBoolean(mContentResolver,
417422
Settings.Secure.WIFI_WATCHDOG_WALLED_GARDEN_TEST_ENABLED, true);
418423
mWalledGardenUrl = getSettingsStr(mContentResolver,
@@ -625,9 +630,13 @@ public boolean processMessage(Message msg) {
625630

626631
initConnection(wifiInfo);
627632
mConnectionInfo = wifiInfo;
628-
updateBssids();
629-
transitionTo(mDnsCheckingState);
630633
mNetEventCounter++;
634+
if (mPoorNetworkDetectionEnabled) {
635+
updateBssids();
636+
transitionTo(mDnsCheckingState);
637+
} else {
638+
transitionTo(mDelayWalledGardenState);
639+
}
631640
break;
632641
default:
633642
mNetEventCounter++;
@@ -679,12 +688,18 @@ class ConnectedState extends State {
679688
public boolean processMessage(Message msg) {
680689
switch (msg.what) {
681690
case EVENT_SCAN_RESULTS_AVAILABLE:
682-
updateBssids();
691+
if (mPoorNetworkDetectionEnabled) {
692+
updateBssids();
693+
}
683694
return HANDLED;
684695
case EVENT_WATCHDOG_SETTINGS_CHANGE:
685-
// Stop current checks, but let state update
686-
transitionTo(mOnlineWatchState);
687-
return NOT_HANDLED;
696+
updateSettings();
697+
if (mPoorNetworkDetectionEnabled) {
698+
transitionTo(mOnlineWatchState);
699+
} else {
700+
transitionTo(mOnlineState);
701+
}
702+
return HANDLED;
688703
}
689704
return NOT_HANDLED;
690705
}
@@ -831,7 +846,11 @@ public boolean processMessage(Message msg) {
831846
transitionTo(mWalledGardenState);
832847
} else {
833848
if (DBG) log("Walled garden test complete - online");
834-
transitionTo(mOnlineWatchState);
849+
if (mPoorNetworkDetectionEnabled) {
850+
transitionTo(mOnlineWatchState);
851+
} else {
852+
transitionTo(mOnlineState);
853+
}
835854
}
836855
return HANDLED;
837856
default:
@@ -963,6 +982,13 @@ private void triggerSingleDnsCheck() {
963982
}
964983
}
965984

985+
986+
/* Child state of ConnectedState indicating that we are online
987+
* and there is nothing to do
988+
*/
989+
class OnlineState extends State {
990+
}
991+
966992
class DnsCheckFailureState extends State {
967993

968994
@Override
@@ -1039,7 +1065,11 @@ public boolean processMessage(Message msg) {
10391065
return HANDLED;
10401066
}
10411067
setWalledGardenNotificationVisible(true);
1042-
transitionTo(mOnlineWatchState);
1068+
if (mPoorNetworkDetectionEnabled) {
1069+
transitionTo(mOnlineWatchState);
1070+
} else {
1071+
transitionTo(mOnlineState);
1072+
}
10431073
return HANDLED;
10441074
}
10451075
}

0 commit comments

Comments
 (0)