summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRebecca Silberstein <silberst@google.com>2017-05-05 11:04:04 -0700
committerRebecca Silberstein <silberst@google.com>2017-05-10 11:09:33 -0700
commita3458ecb3c1b1a7dae295a6c728242dcc06a04f3 (patch)
tree69ea89b28984fa7c6e612daef58f09936e22e3a2
parent0cb7ccda98c48bd45af272d2a888220f8b26e1c8 (diff)
WifiStateMachine: properly update wifi enabling
When switching modes, WifiStateMachine should only update the wifi state to enabling when actually heading to connect mode. This is currently not the case and we end up seeing the UI update the wifi icon to show that wifi is starting up. Bug: 37925273 Test: frameworks/opt/net/wifi/tests/wifitests/runtests.sh Change-Id: Ie3a092c7805b64316c42f2781b14deb3986d2572
-rw-r--r--service/java/com/android/server/wifi/WifiStateMachine.java3
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java48
2 files changed, 44 insertions, 7 deletions
diff --git a/service/java/com/android/server/wifi/WifiStateMachine.java b/service/java/com/android/server/wifi/WifiStateMachine.java
index eaac5560a..179d7f950 100644
--- a/service/java/com/android/server/wifi/WifiStateMachine.java
+++ b/service/java/com/android/server/wifi/WifiStateMachine.java
@@ -4042,7 +4042,6 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiRss
cleanup();
break;
}
- setWifiState(WIFI_STATE_ENABLING);
if (mVerboseLoggingEnabled) log("Supplicant start successful");
mWifiMonitor.startMonitoring(mInterfaceName, true);
setSupplicantLogLevel();
@@ -4202,6 +4201,7 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiRss
setWifiState(WIFI_STATE_DISABLED);
transitionTo(mScanModeState);
} else if (mOperationalMode == CONNECT_MODE) {
+ setWifiState(WIFI_STATE_ENABLING);
// Transitioning to Disconnected state will trigger a scan and subsequently AutoJoin
transitionTo(mDisconnectedState);
} else if (mOperationalMode == DISABLED_MODE) {
@@ -4486,6 +4486,7 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiRss
case CMD_SET_OPERATIONAL_MODE:
if (message.arg1 == CONNECT_MODE) {
mOperationalMode = CONNECT_MODE;
+ setWifiState(WIFI_STATE_ENABLING);
transitionTo(mDisconnectedState);
} else if (message.arg1 == DISABLED_MODE) {
transitionTo(mSupplicantStoppingState);
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java b/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java
index 20dd11757..2e365a048 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java
@@ -26,6 +26,7 @@ import android.app.ActivityManager;
import android.app.test.MockAnswerUtil.AnswerWithArguments;
import android.app.test.TestAlarmManager;
import android.content.Context;
+import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.UserInfo;
import android.content.res.Resources;
@@ -86,6 +87,7 @@ import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
+import org.mockito.ArgumentMatcher;
import org.mockito.InOrder;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
@@ -309,6 +311,7 @@ public class WifiStateMachineTest {
MockWifiMonitor mWifiMonitor;
TestIpManager mTestIpManager;
TestLooper mLooper;
+ Context mContext;
@Mock WifiScanner mWifiScanner;
@Mock SupplicantStateTracker mSupplicantStateTracker;
@@ -381,17 +384,17 @@ public class WifiStateMachineTest {
FrameworkFacade factory = getFrameworkFacade();
- Context context = getContext();
+ mContext = getContext();
Resources resources = getMockResources();
- when(context.getResources()).thenReturn(resources);
+ when(mContext.getResources()).thenReturn(resources);
- when(factory.getIntegerSetting(context,
+ when(factory.getIntegerSetting(mContext,
Settings.Global.WIFI_FREQUENCY_BAND,
WifiManager.WIFI_FREQUENCY_BAND_AUTO)).thenReturn(
WifiManager.WIFI_FREQUENCY_BAND_AUTO);
- when(factory.makeApConfigStore(eq(context), eq(mBackupManagerProxy)))
+ when(factory.makeApConfigStore(eq(mContext), eq(mBackupManagerProxy)))
.thenReturn(mApConfigStore);
when(factory.makeSupplicantStateTracker(
@@ -407,7 +410,7 @@ public class WifiStateMachineTest {
when(mApInterface.asBinder()).thenReturn(mApInterfaceBinder);
when(mClientInterface.asBinder()).thenReturn(mClientInterfaceBinder);
- mWsm = new WifiStateMachine(context, factory, mLooper.getLooper(),
+ mWsm = new WifiStateMachine(mContext, factory, mLooper.getLooper(),
mUserManager, mWifiInjector, mBackupManagerProxy, mCountryCode, mWifiNative);
mWsmThread = getWsmHandlerThread(mWsm);
@@ -430,7 +433,7 @@ public class WifiStateMachineTest {
}
};
- channel.connect(context, handler, mWsm.getMessenger());
+ channel.connect(mContext, handler, mWsm.getMessenger());
mLooper.dispatchAll();
/* Now channel is supposed to be connected */
@@ -465,6 +468,9 @@ public class WifiStateMachineTest {
public void loadComponentsInStaMode() throws Exception {
startSupplicantAndDispatchMessages();
+ verify(mContext).sendStickyBroadcastAsUser(
+ (Intent) argThat(new WifiEnablingStateIntentMatcher()), eq(UserHandle.ALL));
+
assertEquals("DisconnectedState", getCurrentState().getName());
}
@@ -484,6 +490,9 @@ public class WifiStateMachineTest {
mWsm.setSupplicantRunning(true);
mLooper.dispatchAll();
assertEquals("InitialState", getCurrentState().getName());
+ // we should not be sending a wifi enabling update
+ verify(mContext, never()).sendStickyBroadcastAsUser(
+ (Intent) argThat(new WifiEnablingStateIntentMatcher()), any());
}
@Test
@@ -571,6 +580,9 @@ public class WifiStateMachineTest {
assertEquals(WifiStateMachine.SCAN_ONLY_MODE, mWsm.getOperationalModeForTest());
assertEquals("ScanModeState", getCurrentState().getName());
assertEquals(WifiManager.WIFI_STATE_DISABLED, mWsm.syncGetWifiState());
+ verify(mContext, never()).sendStickyBroadcastAsUser(
+ (Intent) argThat(new WifiEnablingStateIntentMatcher()), any());
+
// switch to connect mode and verify wifi is reported as enabled
mWsm.setOperationalMode(WifiStateMachine.CONNECT_MODE);
@@ -578,6 +590,12 @@ public class WifiStateMachineTest {
assertEquals("DisconnectedState", getCurrentState().getName());
assertEquals(WifiStateMachine.CONNECT_MODE, mWsm.getOperationalModeForTest());
assertEquals(WifiManager.WIFI_STATE_ENABLED, mWsm.syncGetWifiState());
+ verify(mContext).sendStickyBroadcastAsUser(
+ (Intent) argThat(new WifiEnablingStateIntentMatcher()), eq(UserHandle.ALL));
+
+ // reset the expectations on mContext since we did get an expected broadcast, but we should
+ // not on the next transition
+ reset(mContext);
// now go back to scan mode with "wifi disabled" to verify the reported wifi state.
mWsm.setOperationalMode(WifiStateMachine.SCAN_ONLY_WITH_WIFI_OFF_MODE);
@@ -586,6 +604,8 @@ public class WifiStateMachineTest {
mWsm.getOperationalModeForTest());
assertEquals("ScanModeState", getCurrentState().getName());
assertEquals(WifiManager.WIFI_STATE_DISABLED, mWsm.syncGetWifiState());
+ verify(mContext, never()).sendStickyBroadcastAsUser(
+ (Intent) argThat(new WifiEnablingStateIntentMatcher()), any());
// now go to AP mode
mWsm.setSupplicantRunning(false);
@@ -595,8 +615,22 @@ public class WifiStateMachineTest {
mLooper.dispatchAll();
assertEquals("SoftApState", getCurrentState().getName());
assertEquals(WifiManager.WIFI_STATE_DISABLED, mWsm.syncGetWifiState());
+ verify(mContext, never()).sendStickyBroadcastAsUser(
+ (Intent) argThat(new WifiEnablingStateIntentMatcher()), any());
}
+ private class WifiEnablingStateIntentMatcher implements ArgumentMatcher<Intent> {
+ @Override
+ public boolean matches(Intent intent) {
+ if (WifiManager.WIFI_STATE_CHANGED_ACTION != intent.getAction()) {
+ // not the correct type
+ return false;
+ }
+ return WifiManager.WIFI_STATE_ENABLING
+ == intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE,
+ WifiManager.WIFI_STATE_DISABLED);
+ }
+ }
/**
* Test that mode changes for WifiStateMachine in the InitialState are realized when supplicant
@@ -620,6 +654,8 @@ public class WifiStateMachineTest {
startSupplicantAndDispatchMessages();
assertEquals("ScanModeState", getCurrentState().getName());
+ verify(mContext, never()).sendStickyBroadcastAsUser(
+ (Intent) argThat(new WifiEnablingStateIntentMatcher()), any());
}
/**