summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoshan Pius <rpius@google.com>2018-12-11 08:26:57 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2018-12-11 08:26:57 +0000
commitdd5ac175c733c7be1dd6dddf1452d34502cdac1d (patch)
tree017fcb845307c3e042eda16509055b4dc6363d75
parentd3a4ffb3002798ed3cca0dc6c5430223f2220c95 (diff)
parentc7607bb29a35d3b04d300235905317ee8ef5f6d8 (diff)
downloadandroid_frameworks_opt_net_wifi-dd5ac175c733c7be1dd6dddf1452d34502cdac1d.tar.gz
android_frameworks_opt_net_wifi-dd5ac175c733c7be1dd6dddf1452d34502cdac1d.tar.bz2
android_frameworks_opt_net_wifi-dd5ac175c733c7be1dd6dddf1452d34502cdac1d.zip
Merge "WifiNetworkFactory: Defer disconnecting from connected request"
-rw-r--r--service/java/com/android/server/wifi/WifiNetworkFactory.java149
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiNetworkFactoryTest.java194
2 files changed, 279 insertions, 64 deletions
diff --git a/service/java/com/android/server/wifi/WifiNetworkFactory.java b/service/java/com/android/server/wifi/WifiNetworkFactory.java
index ea16cd20f..ba3407b5f 100644
--- a/service/java/com/android/server/wifi/WifiNetworkFactory.java
+++ b/service/java/com/android/server/wifi/WifiNetworkFactory.java
@@ -95,8 +95,14 @@ public class WifiNetworkFactory extends NetworkFactory {
private WifiScanner mWifiScanner;
private int mGenericConnectionReqCount = 0;
+ // Request that is being actively processed. All new requests start out as an "active" request
+ // because we're processing it & handling all the user interactions associated with it. Once we
+ // successfully connect to the network, we transition that request to "connected".
private NetworkRequest mActiveSpecificNetworkRequest;
private WifiNetworkSpecifier mActiveSpecificNetworkRequestSpecifier;
+ // Request corresponding to the the network that the device is currently connected to.
+ private NetworkRequest mConnectedSpecificNetworkRequest;
+ private WifiNetworkSpecifier mConnectedSpecificNetworkRequestSpecifier;
private WifiConfiguration mUserSelectedNetwork;
private int mUserSelectedNetworkConnectRetryCount;
private List<ScanResult> mActiveMatchedScanResults;
@@ -104,7 +110,6 @@ public class WifiNetworkFactory extends NetworkFactory {
private boolean mVerboseLoggingEnabled = false;
private boolean mPeriodicScanTimerSet = false;
private boolean mConnectionTimeoutSet = false;
- private boolean mIsConnectedToUserSelectedNetwork = false;
private boolean mIsPeriodicScanPaused = false;
private boolean mWifiEnabled = false;
@@ -302,6 +307,23 @@ public class WifiNetworkFactory extends NetworkFactory {
}
}
+ private boolean canNewRequestOverrideExistingRequest(
+ WifiNetworkSpecifier newRequest, WifiNetworkSpecifier existingRequest) {
+ if (existingRequest == null) return true;
+ // Request from app with NETWORK_SETTINGS can override any existing requests.
+ if (mWifiPermissionsUtil.checkNetworkSettingsPermission(newRequest.requestorUid)) {
+ return true;
+ }
+ // Request from fg app can override any existing requests.
+ if (isRequestFromForegroundApp(newRequest.requestorUid)) return true;
+ // Request from fg service can override only if the existing request is not from a fg app.
+ if (!isRequestFromForegroundApp(existingRequest.requestorUid)) return true;
+ Log.e(TAG, "Already processing request from a foreground app "
+ + existingRequest.requestorUid + ". Rejecting request from "
+ + newRequest.requestorUid);
+ return false;
+ }
+
/**
* Check whether to accept the new network connection request.
*
@@ -337,20 +359,17 @@ public class WifiNetworkFactory extends NetworkFactory {
+ " Rejecting request from " + wns.requestorUid);
return false;
}
- // If there is a pending request, only proceed if the new request is from a foreground
+ // If there is an active request, only proceed if the new request is from a foreground
// app.
- if (mActiveSpecificNetworkRequest != null
- && !mWifiPermissionsUtil.checkNetworkSettingsPermission(wns.requestorUid)
- && !isRequestFromForegroundApp(wns.requestorUid)) {
- WifiNetworkSpecifier aWns =
- (WifiNetworkSpecifier) mActiveSpecificNetworkRequest
- .networkCapabilities
- .getNetworkSpecifier();
- if (isRequestFromForegroundApp(aWns.requestorUid)) {
- Log.e(TAG, "Already processing active request from a foreground app "
- + aWns.requestorUid + ". Rejecting request from " + wns.requestorUid);
- return false;
- }
+ if (!canNewRequestOverrideExistingRequest(
+ wns, mActiveSpecificNetworkRequestSpecifier)) {
+ return false;
+ }
+ // If there is a connected request, only proceed if the new request is from a foreground
+ // app.
+ if (!canNewRequestOverrideExistingRequest(
+ wns, mConnectedSpecificNetworkRequestSpecifier)) {
+ return false;
}
if (mVerboseLoggingEnabled) {
Log.v(TAG, "Accepted network request with specifier from fg "
@@ -389,7 +408,7 @@ public class WifiNetworkFactory extends NetworkFactory {
}
retrieveWifiScanner();
// Reset state from any previous request.
- resetStateForActiveRequestStart();
+ setupForActiveRequest();
// Store the active network request.
mActiveSpecificNetworkRequest = new NetworkRequest(networkRequest);
@@ -427,16 +446,23 @@ public class WifiNetworkFactory extends NetworkFactory {
Log.e(TAG, "Wifi off. Ignoring");
return;
}
- if (mActiveSpecificNetworkRequest == null) {
- Log.e(TAG, "Network release received with no active request. Ignoring");
+ if (mActiveSpecificNetworkRequest == null && mConnectedSpecificNetworkRequest == null) {
+ Log.e(TAG, "Network release received with no active/connected request."
+ + " Ignoring");
return;
}
- if (!mActiveSpecificNetworkRequest.equals(networkRequest)) {
- Log.e(TAG, "Network specifier does not match the active request. Ignoring");
- return;
+ if (Objects.equals(mActiveSpecificNetworkRequest, networkRequest)) {
+ Log.i(TAG, "App released request, cancelling "
+ + mActiveSpecificNetworkRequest);
+ teardownForActiveRequest();
+ } else if (Objects.equals(mConnectedSpecificNetworkRequest, networkRequest)) {
+ Log.i(TAG, "App released request, cancelling "
+ + mConnectedSpecificNetworkRequest);
+ teardownForConnectedNetwork();
+ } else {
+ Log.e(TAG, "Network specifier does not match the active/connected request."
+ + " Ignoring");
}
- Log.w(TAG, "App released request, cancelling " + mActiveSpecificNetworkRequest);
- resetStateForActiveRequestEnd();
}
}
@@ -448,10 +474,11 @@ public class WifiNetworkFactory extends NetworkFactory {
}
/**
- * Check if there is at-least one connection request.
+ * Check if there is at least one connection request.
*/
public boolean hasConnectionRequests() {
- return mGenericConnectionReqCount > 0 || mActiveSpecificNetworkRequest != null;
+ return mGenericConnectionReqCount > 0 || mActiveSpecificNetworkRequest != null
+ || mConnectedSpecificNetworkRequest != null;
}
/**
@@ -534,7 +561,7 @@ public class WifiNetworkFactory extends NetworkFactory {
private void handleRejectUserSelection() {
Log.w(TAG, "User dismissed notification, cancelling " + mActiveSpecificNetworkRequest);
- resetStateForActiveRequestEnd();
+ teardownForActiveRequest();
}
private boolean isUserSelectedNetwork(WifiConfiguration config) {
@@ -578,10 +605,8 @@ public class WifiNetworkFactory extends NetworkFactory {
+ callback, e);
}
}
- // Cancel connection timeout alarm.
- cancelConnectionTimeout();
- // Set the connection status.
- mIsConnectedToUserSelectedNetwork = true;
+ // transition the request from "active" to "connected".
+ setupForConnectedRequest();
}
/**
@@ -609,7 +634,7 @@ public class WifiNetworkFactory extends NetworkFactory {
+ callback, e);
}
}
- resetStateForActiveRequestEnd();
+ teardownForActiveRequest();
}
/**
@@ -642,18 +667,19 @@ public class WifiNetworkFactory extends NetworkFactory {
} else {
if (mActiveSpecificNetworkRequest != null) {
Log.w(TAG, "Wifi off, cancelling " + mActiveSpecificNetworkRequest);
- resetStateForActiveRequestEnd();
+ teardownForActiveRequest();
+ }
+ if (mConnectedSpecificNetworkRequest != null) {
+ Log.w(TAG, "Wifi off, cancelling " + mConnectedSpecificNetworkRequest);
+ teardownForConnectedNetwork();
}
}
mWifiEnabled = enabled;
}
- private void resetState() {
- if (mIsConnectedToUserSelectedNetwork) {
- Log.i(TAG, "Disconnecting from network on reset");
- mWifiInjector.getClientModeImpl().disconnectCommand();
- }
- // Send the abort to the UI.
+ // Common helper method for start/end of active request processing.
+ private void cleanupActiveRequest() {
+ // Send the abort to the UI for the current active request.
for (INetworkRequestMatchCallback callback : mRegisteredCallbacks.getCallbacks()) {
try {
callback.onAbort();
@@ -666,8 +692,8 @@ public class WifiNetworkFactory extends NetworkFactory {
mActiveSpecificNetworkRequestSpecifier = null;
mUserSelectedNetwork = null;
mUserSelectedNetworkConnectRetryCount = 0;
- mIsConnectedToUserSelectedNetwork = false;
mIsPeriodicScanPaused = false;
+ // Cancel periodic scan, connection timeout alarm.
cancelPeriodicScans();
cancelConnectionTimeout();
// Remove any callbacks registered for the request.
@@ -676,15 +702,42 @@ public class WifiNetworkFactory extends NetworkFactory {
// attempt failed.
}
- // 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 setupForActiveRequest() {
+ if (mActiveSpecificNetworkRequest != null) {
+ cleanupActiveRequest();
+ }
+ }
+
+ // Invoked at the termination of current active request processing.
+ private void teardownForActiveRequest() {
+ cleanupActiveRequest();
+ // ensure there is no connected request in progress.
+ if (mConnectedSpecificNetworkRequest == null) {
+ mWifiConnectivityManager.setSpecificNetworkRequestInProgress(false);
+ }
}
- // Invoked at the start of new active request processing.
- private void resetStateForActiveRequestStart() {
- resetState();
+ // Invoked at the start of new connected request processing.
+ private void setupForConnectedRequest() {
+ mConnectedSpecificNetworkRequest = mActiveSpecificNetworkRequest;
+ mConnectedSpecificNetworkRequestSpecifier = mActiveSpecificNetworkRequestSpecifier;
+ mActiveSpecificNetworkRequest = null;
+ mActiveSpecificNetworkRequestSpecifier = null;
+ // Cancel connection timeout alarm.
+ cancelConnectionTimeout();
+ }
+
+ // Invoked at the termination of current connected request processing.
+ private void teardownForConnectedNetwork() {
+ Log.i(TAG, "Disconnecting from network on reset");
+ mWifiInjector.getClientModeImpl().disconnectCommand();
+ mConnectedSpecificNetworkRequest = null;
+ mConnectedSpecificNetworkRequestSpecifier = null;
+ // ensure there is no active request in progress.
+ if (mActiveSpecificNetworkRequest == null) {
+ mWifiConnectivityManager.setSpecificNetworkRequestInProgress(false);
+ }
}
/**
@@ -798,14 +851,12 @@ public class WifiNetworkFactory extends NetworkFactory {
// request.
private List<ScanResult> getNetworksMatchingActiveNetworkRequest(
ScanResult[] scanResults) {
- if (mActiveSpecificNetworkRequest == null) {
+ if (mActiveSpecificNetworkRequestSpecifier == null) {
Log.e(TAG, "Scan results received with no active network request. Ignoring...");
return new ArrayList<>();
}
List<ScanResult> matchedScanResults = new ArrayList<>();
- WifiNetworkSpecifier wns = (WifiNetworkSpecifier)
- mActiveSpecificNetworkRequest.networkCapabilities.getNetworkSpecifier();
- checkNotNull(wns);
+ WifiNetworkSpecifier wns = mActiveSpecificNetworkRequestSpecifier;
for (ScanResult scanResult : scanResults) {
if (doesScanResultMatchWifiNetworkSpecifier(wns, scanResult)) {
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiNetworkFactoryTest.java b/tests/wifitests/src/com/android/server/wifi/WifiNetworkFactoryTest.java
index dfaceb099..b3c498aec 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiNetworkFactoryTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiNetworkFactoryTest.java
@@ -353,6 +353,60 @@ public class WifiNetworkFactoryTest {
}
/**
+ * Validates handling of acceptNetwork with a network specifier from a foreground
+ * app when we're connected to a request from a foreground app.
+ */
+ @Test
+ public void
+ testHandleAcceptNetworkRequestFromFgAppWithSpecifierWithConnectedRequestFromFgApp()
+ throws Exception {
+ when(mActivityManager.getPackageImportance(TEST_PACKAGE_NAME_1))
+ .thenReturn(IMPORTANCE_FOREGROUND);
+ when(mActivityManager.getPackageImportance(TEST_PACKAGE_NAME_2))
+ .thenReturn(IMPORTANCE_FOREGROUND);
+
+ // Connect to request 1
+ sendNetworkRequestAndSetupForConnectionStatus(TEST_SSID_1);
+ // Send network connection success indication.
+ assertNotNull(mSelectedNetwork);
+ mWifiNetworkFactory.handleConnectionAttemptEnded(
+ WifiMetrics.ConnectionEvent.FAILURE_NONE, mSelectedNetwork);
+
+ // Make request 2 which will be accepted because a fg app request can
+ // override an existing fg app request.
+ WifiNetworkSpecifier specifier2 = createWifiNetworkSpecifier(TEST_UID_2, false);
+ mNetworkRequest.networkCapabilities.setNetworkSpecifier(specifier2);
+ assertTrue(mWifiNetworkFactory.acceptRequest(mNetworkRequest, 0));
+ }
+
+ /**
+ * Validates handling of acceptNetwork with a network specifier from a foreground
+ * service when we're connected to a request from a foreground app.
+ */
+ @Test
+ public void
+ testHandleAcceptNetworkRequestFromFgSvcWithSpecifierWithConnectedRequestFromFgApp()
+ throws Exception {
+ when(mActivityManager.getPackageImportance(TEST_PACKAGE_NAME_1))
+ .thenReturn(IMPORTANCE_FOREGROUND);
+ when(mActivityManager.getPackageImportance(TEST_PACKAGE_NAME_2))
+ .thenReturn(IMPORTANCE_FOREGROUND_SERVICE);
+
+ // Connect to request 1
+ sendNetworkRequestAndSetupForConnectionStatus(TEST_SSID_1);
+ // Send network connection success indication.
+ assertNotNull(mSelectedNetwork);
+ mWifiNetworkFactory.handleConnectionAttemptEnded(
+ WifiMetrics.ConnectionEvent.FAILURE_NONE, mSelectedNetwork);
+
+ // Make request 2 which will be rejected because a fg service request cannot
+ // override a fg app request.
+ WifiNetworkSpecifier specifier2 = createWifiNetworkSpecifier(TEST_UID_2, false);
+ mNetworkRequest.networkCapabilities.setNetworkSpecifier(specifier2);
+ assertFalse(mWifiNetworkFactory.acceptRequest(mNetworkRequest, 0));
+ }
+
+ /**
* Verify handling of new network request with network specifier.
*/
@Test
@@ -1048,7 +1102,7 @@ public class WifiNetworkFactoryTest {
// verify we canceled the timeout alarm.
verify(mAlarmManager, never())
.cancel(mConnectionTimeoutAlarmListenerArgumentCaptor.getValue());
- // Verify we reset the network request handling.
+ // Verify we don't reset the network request handling.
verify(mWifiConnectivityManager, never())
.setSpecificNetworkRequestInProgress(false);
@@ -1172,7 +1226,7 @@ public class WifiNetworkFactoryTest {
* Verify handling for new network request while processing another one.
*/
@Test
- public void testHandleNetworkRequestWithSpecifierWhenScanning() throws Exception {
+ public void testHandleNewNetworkRequestWithSpecifierWhenScanning() throws Exception {
WifiNetworkSpecifier specifier1 = createWifiNetworkSpecifier(TEST_UID_1, false);
mNetworkRequest.networkCapabilities.setNetworkSpecifier(specifier1);
mWifiNetworkFactory.needNetworkFor(mNetworkRequest, 0);
@@ -1208,7 +1262,7 @@ public class WifiNetworkFactoryTest {
* Verify handling for new network request while processing another one.
*/
@Test
- public void testHandleNetworkRequestWithSpecifierAfterMatch() throws Exception {
+ public void testHandleNewNetworkRequestWithSpecifierAfterMatch() throws Exception {
sendNetworkRequestAndSetupForUserSelection();
WifiNetworkSpecifier specifier1 =
(WifiNetworkSpecifier) mNetworkRequest.networkCapabilities.getNetworkSpecifier();
@@ -1249,7 +1303,7 @@ public class WifiNetworkFactoryTest {
* Verify handling for new network request while processing another one.
*/
@Test
- public void testHandleNetworkRequestWithSpecifierAfterConnect() throws Exception {
+ public void testHandleNewNetworkRequestWithSpecifierAfterConnect() throws Exception {
sendNetworkRequestAndSetupForConnectionStatus();
WifiNetworkSpecifier specifier1 =
(WifiNetworkSpecifier) mNetworkRequest.networkCapabilities.getNetworkSpecifier();
@@ -1282,7 +1336,7 @@ public class WifiNetworkFactoryTest {
* Verify handling for new network request while processing another one.
*/
@Test
- public void testHandleNetworkRequestWithSpecifierAfterConnectionSuccess() throws Exception {
+ public void testHandleNewNetworkRequestWithSpecifierAfterConnectionSuccess() throws Exception {
sendNetworkRequestAndSetupForConnectionStatus();
WifiNetworkSpecifier specifier1 =
(WifiNetworkSpecifier) mNetworkRequest.networkCapabilities.getNetworkSpecifier();
@@ -1291,7 +1345,6 @@ public class WifiNetworkFactoryTest {
assertNotNull(mSelectedNetwork);
mWifiNetworkFactory.handleConnectionAttemptEnded(
WifiMetrics.ConnectionEvent.FAILURE_NONE, mSelectedNetwork);
-
// Cancel the connection timeout.
verify(mAlarmManager).cancel(mConnectionTimeoutAlarmListenerArgumentCaptor.getValue());
@@ -1302,20 +1355,123 @@ public class WifiNetworkFactoryTest {
verify(mWifiConnectivityManager, times(1)).setSpecificNetworkRequestInProgress(true);
verify(mWifiScanner, times(2)).startScan(any(), any(), any());
+ // we shouldn't disconnect until the user accepts the next request.
+ verify(mClientModeImpl, never()).disconnectCommand();
+
+ // Remove the connected request1 & ensure we disconnect.
+ mNetworkRequest.networkCapabilities.setNetworkSpecifier(specifier1);
+ mWifiNetworkFactory.releaseNetworkFor(mNetworkRequest);
verify(mClientModeImpl).disconnectCommand();
- // Remove the stale request1 & ensure nothing happens.
+ verifyNoMoreInteractions(mWifiConnectivityManager, mWifiScanner, mClientModeImpl,
+ mAlarmManager);
+
+ // Now remove the active request2 & ensure auto-join is re-enabled.
+ mNetworkRequest.networkCapabilities.setNetworkSpecifier(specifier2);
+ mWifiNetworkFactory.releaseNetworkFor(mNetworkRequest);
+
+ verify(mWifiConnectivityManager).setSpecificNetworkRequestInProgress(false);
+
+ verifyNoMoreInteractions(mWifiConnectivityManager, mWifiScanner, mClientModeImpl,
+ mAlarmManager);
+ }
+
+ /**
+ * Verify handling for new network request while processing another one.
+ */
+ @Test
+ public void testHandleNewNetworkRequestWithSpecifierWhichUserSelectedAfterConnectionSuccess()
+ throws Exception {
+ sendNetworkRequestAndSetupForConnectionStatus(TEST_SSID_1);
+ WifiNetworkSpecifier specifier1 =
+ (WifiNetworkSpecifier) mNetworkRequest.networkCapabilities.getNetworkSpecifier();
+
+ // Send network connection success indication.
+ assertNotNull(mSelectedNetwork);
+ mWifiNetworkFactory.handleConnectionAttemptEnded(
+ WifiMetrics.ConnectionEvent.FAILURE_NONE, mSelectedNetwork);
+ // Cancel the connection timeout.
+ verify(mAlarmManager).cancel(mConnectionTimeoutAlarmListenerArgumentCaptor.getValue());
+
+ // Send second request & we simulate the user selecting the request & connecting to it.
+ reset(mNetworkRequestMatchCallback, mWifiScanner, mAlarmManager);
+ sendNetworkRequestAndSetupForConnectionStatus(TEST_SSID_2);
+ WifiNetworkSpecifier specifier2 =
+ (WifiNetworkSpecifier) mNetworkRequest.networkCapabilities.getNetworkSpecifier();
+ assertNotNull(mSelectedNetwork);
+ mWifiNetworkFactory.handleConnectionAttemptEnded(
+ WifiMetrics.ConnectionEvent.FAILURE_NONE, mSelectedNetwork);
+ // Cancel the connection timeout.
+ verify(mAlarmManager).cancel(mConnectionTimeoutAlarmListenerArgumentCaptor.getValue());
+
+ // We shouldn't explicitly disconnect, the new connection attempt will implicitly disconnect
+ // from the connected network.
+ verify(mClientModeImpl, never()).disconnectCommand();
+
+ // Remove the stale request1 & ensure nothing happens (because it was replaced by the
+ // second request)
mNetworkRequest.networkCapabilities.setNetworkSpecifier(specifier1);
mWifiNetworkFactory.releaseNetworkFor(mNetworkRequest);
verifyNoMoreInteractions(mWifiConnectivityManager, mWifiScanner, mClientModeImpl,
mAlarmManager);
- // Remove the active request2 & ensure auto-join is re-enabled.
+ // Now remove the rejected request2, ensure we disconnect & re-enable auto-join.
mNetworkRequest.networkCapabilities.setNetworkSpecifier(specifier2);
mWifiNetworkFactory.releaseNetworkFor(mNetworkRequest);
+ verify(mClientModeImpl).disconnectCommand();
+ verify(mWifiConnectivityManager).setSpecificNetworkRequestInProgress(false);
+ verifyNoMoreInteractions(mWifiConnectivityManager, mWifiScanner, mClientModeImpl,
+ mAlarmManager);
+ }
+
+ /**
+ * Verify handling for new network request while processing another one.
+ */
+ @Test
+ public void testHandleNewNetworkRequestWithSpecifierWhichUserRejectedAfterConnectionSuccess()
+ throws Exception {
+ sendNetworkRequestAndSetupForConnectionStatus(TEST_SSID_1);
+ WifiNetworkSpecifier specifier1 =
+ (WifiNetworkSpecifier) mNetworkRequest.networkCapabilities.getNetworkSpecifier();
+
+ // Send network connection success indication.
+ assertNotNull(mSelectedNetwork);
+ mWifiNetworkFactory.handleConnectionAttemptEnded(
+ WifiMetrics.ConnectionEvent.FAILURE_NONE, mSelectedNetwork);
+ // Cancel the connection timeout.
+ verify(mAlarmManager).cancel(mConnectionTimeoutAlarmListenerArgumentCaptor.getValue());
+
+ // Send second request & we simulate the user rejecting the request.
+ reset(mNetworkRequestMatchCallback, mWifiScanner, mAlarmManager);
+ sendNetworkRequestAndSetupForUserSelection(TEST_SSID_2);
+ WifiNetworkSpecifier specifier2 =
+ (WifiNetworkSpecifier) mNetworkRequest.networkCapabilities.getNetworkSpecifier();
+ mNetworkRequestUserSelectionCallback.getValue().reject();
+ mLooper.dispatchAll();
+ // cancel periodic scans.
+ verify(mAlarmManager).cancel(mPeriodicScanListenerArgumentCaptor.getValue());
+
+ // we shouldn't disconnect/re-enable auto-join until the connected request is released.
+ verify(mWifiConnectivityManager, never()).setSpecificNetworkRequestInProgress(false);
+ verify(mClientModeImpl, never()).disconnectCommand();
+
+ // Remove the connected request1 & ensure we disconnect & ensure auto-join is re-enabled.
+ mNetworkRequest.networkCapabilities.setNetworkSpecifier(specifier1);
+ mWifiNetworkFactory.releaseNetworkFor(mNetworkRequest);
+ verify(mClientModeImpl).disconnectCommand();
verify(mWifiConnectivityManager).setSpecificNetworkRequestInProgress(false);
+
+ verifyNoMoreInteractions(mWifiConnectivityManager, mWifiScanner, mClientModeImpl,
+ mAlarmManager);
+
+ // Now remove the rejected request2 & ensure nothing happens
+ mNetworkRequest.networkCapabilities.setNetworkSpecifier(specifier2);
+ mWifiNetworkFactory.releaseNetworkFor(mNetworkRequest);
+
+ verifyNoMoreInteractions(mWifiConnectivityManager, mWifiScanner, mClientModeImpl,
+ mAlarmManager);
}
/**
@@ -1488,13 +1644,16 @@ public class WifiNetworkFactoryTest {
verify(mWifiScanner).startScan(any(), any(), any());
}
-
+ private Messenger sendNetworkRequestAndSetupForConnectionStatus() throws RemoteException {
+ return sendNetworkRequestAndSetupForConnectionStatus(TEST_SSID_1);
+ }
// Helper method to setup the necessary pre-requisite steps for tracking connection status.
- private Messenger sendNetworkRequestAndSetupForConnectionStatus() throws RemoteException {
+ private Messenger sendNetworkRequestAndSetupForConnectionStatus(String targetSsid)
+ throws RemoteException {
when(mClock.getElapsedSinceBootMillis()).thenReturn(0L);
- sendNetworkRequestAndSetupForUserSelection();
+ sendNetworkRequestAndSetupForUserSelection(targetSsid);
INetworkRequestUserSelectionCallback networkRequestUserSelectionCallback =
mNetworkRequestUserSelectionCallback.getValue();
@@ -1508,10 +1667,10 @@ public class WifiNetworkFactoryTest {
// Cancel the periodic scan timer.
mInOrder.verify(mAlarmManager).cancel(mPeriodicScanListenerArgumentCaptor.getValue());
// Disable connectivity manager
- verify(mWifiConnectivityManager).setSpecificNetworkRequestInProgress(true);
+ verify(mWifiConnectivityManager, atLeastOnce()).setSpecificNetworkRequestInProgress(true);
ArgumentCaptor<Message> messageCaptor = ArgumentCaptor.forClass(Message.class);
- verify(mClientModeImpl).sendMessage(messageCaptor.capture());
+ verify(mClientModeImpl, atLeastOnce()).sendMessage(messageCaptor.capture());
Message message = messageCaptor.getValue();
assertNotNull(message);
@@ -1525,15 +1684,20 @@ public class WifiNetworkFactoryTest {
return message.replyTo;
}
- // Helper method to setup the necessary pre-requisite steps for user selection.
private void sendNetworkRequestAndSetupForUserSelection() throws RemoteException {
+ sendNetworkRequestAndSetupForUserSelection(TEST_SSID_1);
+ }
+
+ // Helper method to setup the necessary pre-requisite steps for user selection.
+ private void sendNetworkRequestAndSetupForUserSelection(String targetSsid)
+ throws RemoteException {
// Setup scan data for open networks.
setupScanData(SCAN_RESULT_TYPE_WPA_PSK,
TEST_SSID_1, TEST_SSID_2, TEST_SSID_3, TEST_SSID_4);
// Setup network specifier for open networks.
PatternMatcher ssidPatternMatch =
- new PatternMatcher(TEST_SSID_1, PatternMatcher.PATTERN_LITERAL);
+ new PatternMatcher(targetSsid, PatternMatcher.PATTERN_LITERAL);
Pair<MacAddress, MacAddress> bssidPatternMatch =
Pair.create(MacAddress.ALL_ZEROS_ADDRESS, MacAddress.ALL_ZEROS_ADDRESS);
WifiConfiguration wifiConfiguration = new WifiConfiguration();