summaryrefslogtreecommitdiffstats
path: root/service/java/com/android/server/wifi/WifiNetworkFactory.java
diff options
context:
space:
mode:
authorRoshan Pius <rpius@google.com>2018-11-08 18:42:28 -0800
committerRoshan Pius <rpius@google.com>2018-11-16 16:30:41 -0800
commit48aa05701730ec031603c311de057d106eee65fc (patch)
treeecc5662e4f7fd6404f22d10e73ab9d3480e24f44 /service/java/com/android/server/wifi/WifiNetworkFactory.java
parent26672dba37034ce8ffdaa1350e9fb1529e2f0b70 (diff)
downloadandroid_frameworks_opt_net_wifi-48aa05701730ec031603c311de057d106eee65fc.tar.gz
android_frameworks_opt_net_wifi-48aa05701730ec031603c311de057d106eee65fc.tar.bz2
android_frameworks_opt_net_wifi-48aa05701730ec031603c311de057d106eee65fc.zip
WifiNetworkFactory: Handle new request while processing
Handle new network request while processing a previous request. Also, refactored the resetState() method to ensure there is a single abort method for the active request. Bug: 113878056 Test: ./frameworks/opt/net/wifi/tests/wifitests/runtests.sh Change-Id: I1e17b115f039036e069acde52d1f99cefe5f5b4d
Diffstat (limited to 'service/java/com/android/server/wifi/WifiNetworkFactory.java')
-rw-r--r--service/java/com/android/server/wifi/WifiNetworkFactory.java55
1 files changed, 40 insertions, 15 deletions
diff --git a/service/java/com/android/server/wifi/WifiNetworkFactory.java b/service/java/com/android/server/wifi/WifiNetworkFactory.java
index 1c1d5e57c..aaf2b2e6b 100644
--- a/service/java/com/android/server/wifi/WifiNetworkFactory.java
+++ b/service/java/com/android/server/wifi/WifiNetworkFactory.java
@@ -93,6 +93,7 @@ public class WifiNetworkFactory extends NetworkFactory {
// Verbose logging flag.
private boolean mVerboseLoggingEnabled = false;
private boolean mPeriodicScanTimerSet = false;
+ private boolean mConnectionTimeoutSet = false;
private boolean mIsConnectedToUserSelectedNetwork = false;
// Scan listener for scan requests.
@@ -365,6 +366,8 @@ public class WifiNetworkFactory extends NetworkFactory {
return;
}
retrieveWifiScanner();
+ // Reset state from any previous request.
+ resetStateForActiveRequestStart();
// Store the active network request.
mActiveSpecificNetworkRequest = new NetworkRequest(networkRequest);
@@ -408,11 +411,7 @@ public class WifiNetworkFactory extends NetworkFactory {
Log.e(TAG, "Network specifier does not match the active request. Ignoring");
return;
}
- if (mIsConnectedToUserSelectedNetwork) {
- Log.i(TAG, "Disconnecting from network on request release");
- mWifiInjector.getClientModeImpl().disconnectCommand();
- }
- resetState();
+ resetStateForActiveRequestEnd();
}
}
@@ -470,14 +469,12 @@ public class WifiNetworkFactory extends NetworkFactory {
mUserSelectedNetwork = network;
// Post an alarm to handle connection timeout.
- mAlarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP,
- mClock.getElapsedSinceBootMillis() + NETWORK_CONNECTION_TIMEOUT_MS,
- TAG, mConnectionTimeoutAlarmListener, mHandler);
+ scheduleConnectionTimeout();
}
private void handleRejectUserSelection() {
Log.w(TAG, "User dismissed notification");
- resetState();
+ resetStateForActiveRequestEnd();
}
private boolean isUserSelectedNetwork(WifiConfiguration config) {
@@ -522,7 +519,7 @@ public class WifiNetworkFactory extends NetworkFactory {
}
}
// Cancel connection timeout alarm.
- mAlarmManager.cancel(mConnectionTimeoutAlarmListener);
+ cancelConnectionTimeout();
// Set the connection status.
mIsConnectedToUserSelectedNetwork = true;
}
@@ -545,25 +542,39 @@ public class WifiNetworkFactory extends NetworkFactory {
+ callback, e);
}
}
- // Cancel any connection timeout alarm.
- mAlarmManager.cancel(mConnectionTimeoutAlarmListener);
- resetState();
+ resetStateForActiveRequestEnd();
}
private void resetState() {
+ if (mIsConnectedToUserSelectedNetwork) {
+ Log.i(TAG, "Disconnecting from network on reset");
+ mWifiInjector.getClientModeImpl().disconnectCommand();
+ }
// Reset the active network request.
mActiveSpecificNetworkRequest = null;
mActiveSpecificNetworkRequestSpecifier = null;
mUserSelectedNetwork = null;
mIsConnectedToUserSelectedNetwork = false;
cancelPeriodicScans();
- // Re-enable Auto-join.
- mWifiConnectivityManager.setSpecificNetworkRequestInProgress(false);
+ cancelConnectionTimeout();
+ // Remove any callbacks registered for the request.
+ mRegisteredCallbacks.clear();
// TODO(b/113878056): Force-release the network request to let the app know early that the
// attempt failed.
// TODO(b/113878056): End UI flow here.
}
+ // Invoked at the termination of previous active request processing.
+ private void resetStateForActiveRequestEnd() {
+ resetState();
+ mWifiConnectivityManager.setSpecificNetworkRequestInProgress(false);
+ }
+
+ // Invoked at the start of new active request processing.
+ private void resetStateForActiveRequestStart() {
+ resetState();
+ }
+
/**
* Check if the request comes from foreground app/service.
*/
@@ -707,5 +718,19 @@ public class WifiNetworkFactory extends NetworkFactory {
}
}
}
+
+ private void cancelConnectionTimeout() {
+ if (mConnectionTimeoutSet) {
+ mAlarmManager.cancel(mConnectionTimeoutAlarmListener);
+ mConnectionTimeoutSet = false;
+ }
+ }
+
+ private void scheduleConnectionTimeout() {
+ mAlarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP,
+ mClock.getElapsedSinceBootMillis() + NETWORK_CONNECTION_TIMEOUT_MS,
+ TAG, mConnectionTimeoutAlarmListener, mHandler);
+ mConnectionTimeoutSet = true;
+ }
}