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-11 17:58:24 +0000
commit36f52ffb5fd16c89f022dead27d8df9e51874160 (patch)
treeac454eb5e81df09b33d9dbeb255e47097dc89814 /tests
parented71d5209d66544a46a7dc543a0ee94e1be39eab (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 Merged-In: 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 fa34e07f9..71ca0204f 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.junit.Assert.assertTrue;
@@ -24,15 +28,18 @@ 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.IpConfiguration;
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;
@@ -65,6 +72,7 @@ public class WifiServiceImplTest {
@Mock WifiInjector mWifiInjector;
WifiServiceImpl mWifiServiceImpl;
+ @Mock WifiController mWifiController;
@Mock WifiTrafficPoller mWifiTrafficPoller;
@Mock WifiStateMachine mWifiStateMachine;
@Mock HandlerThread mHandlerThread;
@@ -79,6 +87,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";
@@ -137,11 +148,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);
@@ -155,6 +172,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);
}
@@ -265,4 +283,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);
+ }
}