summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorRebecca Silberstein <silberst@google.com>2017-03-20 22:28:54 -0700
committerRebecca Silberstein <silberst@google.com>2017-04-04 05:12:56 +0000
commitef0b931720a26a0aa59e2aa6cf4dcab765c5de75 (patch)
treea7c0f1558b0ba9fc06f261ca404a5bd88ed8cd40 /tests
parent398b7247f7c0928a0320809b5b4efb9cba2d9d51 (diff)
WifiServiceImpl: check device encryption at boot
When a device is booting, it may need to be decrypted. This extra step will restart system services, including wifi. If this restart happens while we are creating interfaces or loading firmware, we can get odd exceptions end up crashing. To avoid this, we add a check to see if the device needs to be decrypted. If it does, we do not start wifi. Added unittests to cover both decrypted and encrypted boot. Also with and without wifi enabled. Bug: 35416881 Test: frameworks/opt/net/wifi/tests/wifitests/runtests.sh Test: frameworks/base/wifi/tests/runtests.sh Test: wifi integration tests Change-Id: I8d471c7d0345611f90782dd3bc1b2261957eee73
Diffstat (limited to 'tests')
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java55
1 files changed, 55 insertions, 0 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java b/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java
index 4a4caec81..e5289ac32 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java
@@ -16,6 +16,10 @@
package com.android.server.wifi;
+import static android.net.wifi.WifiManager.WIFI_STATE_DISABLED;
+
+import static com.android.server.wifi.WifiController.CMD_WIFI_TOGGLED;
+
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.mockito.Matchers.any;
@@ -23,14 +27,17 @@ import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.*;
+import android.content.ContentResolver;
import android.content.Context;
import android.content.res.Resources;
import android.net.wifi.WifiConfiguration;
import android.os.Handler;
import android.os.HandlerThread;
+import android.os.IPowerManager;
import android.os.Looper;
import android.os.Message;
import android.os.Messenger;
+import android.os.PowerManager;
import android.os.test.TestLooper;
import android.test.suitebuilder.annotation.SmallTest;
@@ -63,6 +70,7 @@ public class WifiServiceImplTest {
@Mock WifiInjector mWifiInjector;
WifiServiceImpl mWifiServiceImpl;
+ @Mock WifiController mWifiController;
@Mock WifiTrafficPoller mWifiTrafficPoller;
@Mock WifiStateMachine mWifiStateMachine;
@Mock HandlerThread mHandlerThread;
@@ -77,6 +85,9 @@ public class WifiServiceImplTest {
@Mock WifiMetrics mWifiMetrics;
@Spy FakeWifiLog mLog;
@Mock WifiPermissionsUtil mWifiPermissionsUtil;
+ @Mock WifiSettingsStore mSettingsStore;
+ @Mock ContentResolver mContentResolver;
+ PowerManager mPowerManager;
private class WifiAsyncChannelTester {
private static final String TAG = "WifiAsyncChannelTester";
@@ -135,11 +146,17 @@ public class WifiServiceImplTest {
MockitoAnnotations.initMocks(this);
mLooper = new TestLooper();
+ when(mWifiInjector.getWifiController()).thenReturn(mWifiController);
when(mWifiInjector.getWifiMetrics()).thenReturn(mWifiMetrics);
when(mWifiInjector.getWifiStateMachine()).thenReturn(mWifiStateMachine);
when(mWifiInjector.getWifiServiceHandlerThread()).thenReturn(mHandlerThread);
when(mHandlerThread.getLooper()).thenReturn(mLooper.getLooper());
when(mContext.getResources()).thenReturn(mResources);
+ when(mContext.getContentResolver()).thenReturn(mContentResolver);
+ IPowerManager powerManagerService = mock(IPowerManager.class);
+ mPowerManager = new PowerManager(mContext, powerManagerService, new Handler());
+ when(mContext.getSystemServiceName(PowerManager.class)).thenReturn(Context.POWER_SERVICE);
+ when(mContext.getSystemService(PowerManager.class)).thenReturn(mPowerManager);
WifiAsyncChannel wifiAsyncChannel = new WifiAsyncChannel("WifiServiceImplTest");
wifiAsyncChannel.setWifiLog(mLog);
when(mFrameworkFacade.makeWifiAsyncChannel(anyString())).thenReturn(wifiAsyncChannel);
@@ -153,6 +170,7 @@ public class WifiServiceImplTest {
mLooper.getLooper(), "mockWlan");
when(mWifiInjector.getWifiTrafficPoller()).thenReturn(wifiTrafficPoller);
when(mWifiInjector.getWifiPermissionsUtil()).thenReturn(mWifiPermissionsUtil);
+ when(mWifiInjector.getWifiSettingsStore()).thenReturn(mSettingsStore);
mWifiServiceImpl = new WifiServiceImpl(mContext, mWifiInjector, mAsyncChannel);
mWifiServiceImpl.setWifiHandlerLogForTest(mLog);
}
@@ -245,4 +263,41 @@ public class WifiServiceImplTest {
when(mWifiStateMachine.syncGetWifiApConfiguration()).thenReturn(apConfig);
assertEquals(apConfig, mWifiServiceImpl.getWifiApConfiguration());
}
+
+ /**
+ * Make sure we do not start wifi if System services have to be restarted to decrypt the device.
+ */
+ @Test
+ public void testWifiControllerDoesNotStartWhenDeviceTriggerResetMainAtBoot() {
+ when(mFrameworkFacade.inStorageManagerCryptKeeperBounce()).thenReturn(true);
+ when(mSettingsStore.isWifiToggleEnabled()).thenReturn(false);
+ mWifiServiceImpl.checkAndStartWifi();
+ verify(mWifiController, never()).start();
+ }
+
+ /**
+ * Make sure we do start WifiController (wifi disabled) if the device is already decrypted.
+ */
+ @Test
+ public void testWifiControllerStartsWhenDeviceIsDecryptedAtBootWithWifiDisabled() {
+ when(mFrameworkFacade.inStorageManagerCryptKeeperBounce()).thenReturn(false);
+ when(mSettingsStore.isWifiToggleEnabled()).thenReturn(false);
+ mWifiServiceImpl.checkAndStartWifi();
+ verify(mWifiController).start();
+ verify(mWifiController, never()).sendMessage(CMD_WIFI_TOGGLED);
+ }
+
+ /**
+ * Make sure we do start WifiController (wifi enabled) if the device is already decrypted.
+ */
+ @Test
+ public void testWifiFullyStartsWhenDeviceIsDecryptedAtBootWithWifiEnabled() {
+ when(mFrameworkFacade.inStorageManagerCryptKeeperBounce()).thenReturn(false);
+ when(mSettingsStore.handleWifiToggled(true)).thenReturn(true);
+ when(mSettingsStore.isWifiToggleEnabled()).thenReturn(true);
+ when(mWifiStateMachine.syncGetWifiState()).thenReturn(WIFI_STATE_DISABLED);
+ mWifiServiceImpl.checkAndStartWifi();
+ verify(mWifiController).start();
+ verify(mWifiController).sendMessage(CMD_WIFI_TOGGLED);
+ }
}