summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRebecca Silberstein <silberst@google.com>2017-04-04 22:22:43 +0000
committerandroid-build-merger <android-build-merger@google.com>2017-04-04 22:22:43 +0000
commitae66570add8d3dd6908d32da11776f9f4046217b (patch)
treea7c0f1558b0ba9fc06f261ca404a5bd88ed8cd40
parent0ca439f9ed48669f192aec950492015c8484be37 (diff)
parent21dea681999cb1b757ff27a2c8ee25cb204591f6 (diff)
Merge "WifiServiceImpl: check device encryption at boot" am: 9b5f1c811b
am: 21dea68199 Change-Id: I239a25854298cf5851a05db7f857dd8f53f806d1
-rw-r--r--service/java/com/android/server/wifi/FrameworkFacade.java10
-rw-r--r--service/java/com/android/server/wifi/WifiServiceImpl.java17
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java55
3 files changed, 78 insertions, 4 deletions
diff --git a/service/java/com/android/server/wifi/FrameworkFacade.java b/service/java/com/android/server/wifi/FrameworkFacade.java
index 42f0161e9..2c3e5f7e0 100644
--- a/service/java/com/android/server/wifi/FrameworkFacade.java
+++ b/service/java/com/android/server/wifi/FrameworkFacade.java
@@ -29,6 +29,7 @@ import android.os.Handler;
import android.os.IBinder;
import android.os.RemoteException;
import android.os.ServiceManager;
+import android.os.storage.StorageManager;
import android.provider.Settings;
import android.telephony.CarrierConfigManager;
@@ -151,4 +152,13 @@ public class FrameworkFacade {
public WifiAsyncChannel makeWifiAsyncChannel(String tag) {
return new WifiAsyncChannel(tag);
}
+
+ /**
+ * Check if the device will be restarting after decrypting during boot by calling {@link
+ * StorageManager.inCryptKeeperBounce}.
+ * @return true if the device will restart, false otherwise
+ */
+ public boolean inStorageManagerCryptKeeperBounce() {
+ return StorageManager.inCryptKeeperBounce();
+ }
}
diff --git a/service/java/com/android/server/wifi/WifiServiceImpl.java b/service/java/com/android/server/wifi/WifiServiceImpl.java
index 757be2dac..03a88bc4e 100644
--- a/service/java/com/android/server/wifi/WifiServiceImpl.java
+++ b/service/java/com/android/server/wifi/WifiServiceImpl.java
@@ -359,14 +359,23 @@ public class WifiServiceImpl extends IWifiManager.Stub {
public void setWifiHandlerLogForTest(WifiLog log) {
mClientHandler.setWifiLog(log);
}
+
/**
- * Check if Wi-Fi needs to be enabled and start
- * if needed
+ * Check if we are ready to start wifi.
+ *
+ * First check if we will be restarting system services to decrypt the device. If the device is
+ * not encrypted, check if Wi-Fi needs to be enabled and start if needed
*
- * This function is used only at boot time
+ * This function is used only at boot time.
*/
public void checkAndStartWifi() {
- /* Check if wi-fi needs to be enabled */
+ // First check if we will end up restarting WifiService
+ if (mFrameworkFacade.inStorageManagerCryptKeeperBounce()) {
+ Log.d(TAG, "Device still encrypted. Need to restart SystemServer. Do not start wifi.");
+ return;
+ }
+
+ // Check if wi-fi needs to be enabled
boolean wifiEnabled = mSettingsStore.isWifiToggleEnabled();
Slog.i(TAG, "WifiService starting up with Wi-Fi " +
(wifiEnabled ? "enabled" : "disabled"));
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);
+ }
}