Merge "[HDM] New chip configuration: priority updates & tests"
diff --git a/service/java/com/android/server/wifi/WakeupConfigStoreData.java b/service/java/com/android/server/wifi/WakeupConfigStoreData.java
new file mode 100644
index 0000000..f839ac8
--- /dev/null
+++ b/service/java/com/android/server/wifi/WakeupConfigStoreData.java
@@ -0,0 +1,177 @@
+/*
+ * Copyright 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.server.wifi;
+
+import android.util.ArraySet;
+
+import com.android.server.wifi.WifiConfigStore.StoreData;
+import com.android.server.wifi.util.XmlUtil;
+
+import org.xmlpull.v1.XmlPullParser;
+import org.xmlpull.v1.XmlPullParserException;
+import org.xmlpull.v1.XmlSerializer;
+
+import java.io.IOException;
+import java.util.Collections;
+import java.util.Set;
+
+/**
+ * Config store data for Wifi Wake.
+ */
+public class WakeupConfigStoreData implements StoreData {
+ private static final String TAG = "WakeupConfigStoreData";
+
+ private static final String XML_TAG_IS_ACTIVE = "IsActive";
+ private static final String XML_TAG_NETWORK_SECTION = "Network";
+ private static final String XML_TAG_SSID = "SSID";
+ private static final String XML_TAG_SECURITY = "Security";
+
+ private final DataSource<Boolean> mIsActiveDataSource;
+ private final DataSource<Set<ScanResultMatchInfo>> mNetworkDataSource;
+
+ /**
+ * Interface defining a data source for the store data.
+ */
+ interface DataSource<T> {
+ /**
+ * Returns the data from the data source.
+ */
+ T getData();
+
+ /**
+ * Updates the data in the data source.
+ *
+ * @param data Data retrieved from the store
+ */
+ void setData(T data);
+ }
+
+ /**
+ * Creates the config store data with its data sources.
+ *
+ * @param isActiveDataSource Data source for isActive
+ * @param networkDataSource Data source for the locked network list
+ */
+ public WakeupConfigStoreData(
+ DataSource<Boolean> isActiveDataSource,
+ DataSource<Set<ScanResultMatchInfo>> networkDataSource) {
+ mIsActiveDataSource = isActiveDataSource;
+ mNetworkDataSource = networkDataSource;
+ }
+
+ @Override
+ public void serializeData(XmlSerializer out, boolean shared)
+ throws XmlPullParserException, IOException {
+ if (shared) {
+ throw new XmlPullParserException("Share data not supported");
+ }
+
+ XmlUtil.writeNextValue(out, XML_TAG_IS_ACTIVE, mIsActiveDataSource.getData());
+
+ for (ScanResultMatchInfo scanResultMatchInfo : mNetworkDataSource.getData()) {
+ writeNetwork(out, scanResultMatchInfo);
+ }
+ }
+
+ /**
+ * Writes a {@link ScanResultMatchInfo} to an XML output stream.
+ *
+ * @param out XML output stream
+ * @param scanResultMatchInfo The ScanResultMatchInfo to serizialize
+ * @throws XmlPullParserException
+ * @throws IOException
+ */
+ private void writeNetwork(XmlSerializer out, ScanResultMatchInfo scanResultMatchInfo)
+ throws XmlPullParserException, IOException {
+ XmlUtil.writeNextSectionStart(out, XML_TAG_NETWORK_SECTION);
+
+ XmlUtil.writeNextValue(out, XML_TAG_SSID, scanResultMatchInfo.networkSsid);
+ XmlUtil.writeNextValue(out, XML_TAG_SECURITY, scanResultMatchInfo.networkType);
+
+ XmlUtil.writeNextSectionEnd(out, XML_TAG_NETWORK_SECTION);
+ }
+
+ @Override
+ public void deserializeData(XmlPullParser in, int outerTagDepth, boolean shared)
+ throws XmlPullParserException, IOException {
+ if (shared) {
+ throw new XmlPullParserException("Shared data not supported");
+ }
+
+ boolean isActive = (Boolean) XmlUtil.readNextValueWithName(in, XML_TAG_IS_ACTIVE);
+ mIsActiveDataSource.setData(isActive);
+
+ Set<ScanResultMatchInfo> networks = new ArraySet<>();
+ while (XmlUtil.gotoNextSectionWithNameOrEnd(in, XML_TAG_NETWORK_SECTION, outerTagDepth)) {
+ networks.add(parseNetwork(in, outerTagDepth + 1));
+ }
+
+ mNetworkDataSource.setData(networks);
+ }
+
+ /**
+ * Parses a {@link ScanResultMatchInfo} from an XML input stream.
+ *
+ * @param in XML input stream
+ * @param outerTagDepth XML tag depth of the containing section
+ * @return The {@link ScanResultMatchInfo}
+ * @throws IOException
+ * @throws XmlPullParserException
+ */
+ private ScanResultMatchInfo parseNetwork(XmlPullParser in, int outerTagDepth)
+ throws IOException, XmlPullParserException {
+ ScanResultMatchInfo scanResultMatchInfo = new ScanResultMatchInfo();
+ while (!XmlUtil.isNextSectionEnd(in, outerTagDepth)) {
+ String[] valueName = new String[1];
+ Object value = XmlUtil.readCurrentValue(in, valueName);
+ if (valueName[0] == null) {
+ throw new XmlPullParserException("Missing value name");
+ }
+ switch (valueName[0]) {
+ case XML_TAG_SSID:
+ scanResultMatchInfo.networkSsid = (String) value;
+ break;
+ case XML_TAG_SECURITY:
+ scanResultMatchInfo.networkType = (int) value;
+ break;
+ default:
+ throw new XmlPullParserException("Unknown tag under " + TAG + ": "
+ + valueName[0]);
+ }
+ }
+
+ return scanResultMatchInfo;
+ }
+
+ @Override
+ public void resetData(boolean shared) {
+ if (!shared) {
+ mNetworkDataSource.setData(Collections.emptySet());
+ mIsActiveDataSource.setData(false);
+ }
+ }
+
+ @Override
+ public String getName() {
+ return TAG;
+ }
+
+ @Override
+ public boolean supportShareData() {
+ return false;
+ }
+}
diff --git a/service/java/com/android/server/wifi/WifiCertManager.java b/service/java/com/android/server/wifi/WifiCertManager.java
deleted file mode 100644
index e180f51..0000000
--- a/service/java/com/android/server/wifi/WifiCertManager.java
+++ /dev/null
@@ -1,156 +0,0 @@
-/*
- * Copyright (C) 2015 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.server.wifi;
-
-import android.app.admin.IDevicePolicyManager;
-import android.content.Context;
-import android.os.Environment;
-import android.os.ServiceManager;
-import android.os.UserHandle;
-import android.security.Credentials;
-import android.security.KeyStore;
-import android.text.TextUtils;
-import android.util.Log;
-
-import com.android.server.net.DelayedDiskWrite;
-
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.nio.charset.StandardCharsets;
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.Set;
-
-/**
- * Manager class for affiliated Wifi certificates.
- */
-public class WifiCertManager {
- private static final String TAG = "WifiCertManager";
- private static final String SEP = "\n";
-
- private final Context mContext;
- private final Set<String> mAffiliatedUserOnlyCerts = new HashSet<String>();
- private final String mConfigFile;
-
- private static final String CONFIG_FILE =
- Environment.getDataDirectory() + "/misc/wifi/affiliatedcerts.txt";
-
- private final DelayedDiskWrite mWriter = new DelayedDiskWrite();
-
-
- WifiCertManager(Context context) {
- this(context, CONFIG_FILE);
- }
-
- WifiCertManager(Context context, String configFile) {
- mContext = context;
- mConfigFile = configFile;
- final byte[] bytes = readConfigFile();
- if (bytes == null) {
- // Config file does not exist or empty.
- return;
- }
-
- String[] keys = new String(bytes, StandardCharsets.UTF_8).split(SEP);
- for (String key : keys) {
- mAffiliatedUserOnlyCerts.add(key);
- }
-
- // Remove keys that no longer exist in KeyStore.
- if (mAffiliatedUserOnlyCerts.retainAll(Arrays.asList(listClientCertsForAllUsers()))) {
- writeConfig();
- }
- }
-
- /** @param key Unprefixed cert key to hide from unaffiliated users. */
- public void hideCertFromUnaffiliatedUsers(String key) {
- if (mAffiliatedUserOnlyCerts.add(Credentials.USER_PRIVATE_KEY + key)) {
- writeConfig();
- }
- }
-
- /** @return Prefixed cert keys that are visible to the current user. */
- public String[] listClientCertsForCurrentUser() {
- HashSet<String> results = new HashSet<String>();
-
- String[] keys = listClientCertsForAllUsers();
- if (isAffiliatedUser()) {
- return keys;
- }
-
- for (String key : keys) {
- if (!mAffiliatedUserOnlyCerts.contains(key)) {
- results.add(key);
- }
- }
- return results.toArray(new String[results.size()]);
- }
-
- private void writeConfig() {
- String[] values =
- mAffiliatedUserOnlyCerts.toArray(new String[mAffiliatedUserOnlyCerts.size()]);
- String value = TextUtils.join(SEP, values);
- writeConfigFile(value.getBytes(StandardCharsets.UTF_8));
- }
-
- protected byte[] readConfigFile() {
- byte[] bytes = null;
- try {
- final File file = new File(mConfigFile);
- final long fileSize = file.exists() ? file.length() : 0;
- if (fileSize == 0 || fileSize >= Integer.MAX_VALUE) {
- // Config file is empty/corrupted/non-existing.
- return bytes;
- }
-
- bytes = new byte[(int) file.length()];
- final DataInputStream stream = new DataInputStream(new FileInputStream(file));
- stream.readFully(bytes);
- } catch (IOException e) {
- Log.e(TAG, "readConfigFile: failed to read " + e, e);
- }
- return bytes;
- }
-
- protected void writeConfigFile(byte[] payload) {
- final byte[] data = payload;
- mWriter.write(mConfigFile, new DelayedDiskWrite.Writer() {
- public void onWriteCalled(DataOutputStream out) throws IOException {
- out.write(data, 0, data.length);
- }
- });
- }
-
- protected String[] listClientCertsForAllUsers() {
- return KeyStore.getInstance().list(Credentials.USER_PRIVATE_KEY, UserHandle.myUserId());
- }
-
- protected boolean isAffiliatedUser() {
- IDevicePolicyManager pm = IDevicePolicyManager.Stub.asInterface(
- ServiceManager.getService(Context.DEVICE_POLICY_SERVICE));
- boolean result = false;
- try {
- result = pm.isAffiliatedUser();
- } catch (Exception e) {
- Log.e(TAG, "failed to check user affiliation", e);
- }
- return result;
- }
-}
diff --git a/service/java/com/android/server/wifi/WifiInjector.java b/service/java/com/android/server/wifi/WifiInjector.java
index f14a57f..f6770a5 100644
--- a/service/java/com/android/server/wifi/WifiInjector.java
+++ b/service/java/com/android/server/wifi/WifiInjector.java
@@ -85,7 +85,6 @@
private final WifiVendorHal mWifiVendorHal;
private final WifiStateMachine mWifiStateMachine;
private final WifiSettingsStore mSettingsStore;
- private final WifiCertManager mCertManager;
private final OpenNetworkNotifier mOpenNetworkNotifier;
private final WifiLockManager mLockManager;
private final WifiController mWifiController;
@@ -225,7 +224,6 @@
wifiStateMachineLooper, UserManager.get(mContext),
this, mBackupManagerProxy, mCountryCode, mWifiNative,
new WrongPasswordNotifier(mContext, mFrameworkFacade));
- mCertManager = new WifiCertManager(mContext);
mOpenNetworkNotifier = new OpenNetworkNotifier(mContext,
mWifiStateMachineHandlerThread.getLooper(), mFrameworkFacade, mClock, mWifiMetrics,
mWifiConfigManager, mWifiConfigStore, mWifiStateMachine,
@@ -304,10 +302,6 @@
return mSettingsStore;
}
- public WifiCertManager getWifiCertManager() {
- return mCertManager;
- }
-
public WifiLockManager getWifiLockManager() {
return mLockManager;
}
diff --git a/service/java/com/android/server/wifi/WifiServiceImpl.java b/service/java/com/android/server/wifi/WifiServiceImpl.java
index 8e6a819..e590c76 100644
--- a/service/java/com/android/server/wifi/WifiServiceImpl.java
+++ b/service/java/com/android/server/wifi/WifiServiceImpl.java
@@ -170,8 +170,6 @@
final WifiSettingsStore mSettingsStore;
/* Logs connection events and some general router and scan stats */
private final WifiMetrics mWifiMetrics;
- /* Manages affiliated certificates for current user */
- private final WifiCertManager mCertManager;
private final WifiInjector mWifiInjector;
/* Backup/Restore Module */
@@ -433,7 +431,6 @@
mPowerManager = mContext.getSystemService(PowerManager.class);
mAppOps = (AppOpsManager) mContext.getSystemService(Context.APP_OPS_SERVICE);
mActivityManager = (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE);
- mCertManager = mWifiInjector.getWifiCertManager();
mWifiLockManager = mWifiInjector.getWifiLockManager();
mWifiMulticastLockManager = mWifiInjector.getWifiMulticastLockManager();
HandlerThread wifiServiceHandlerThread = mWifiInjector.getWifiServiceHandlerThread();
@@ -2410,38 +2407,6 @@
return mWifiStateMachine.getAggressiveHandover();
}
- @Override
- public void setAllowScansWithTraffic(int enabled) {
- enforceAccessPermission();
- mLog.info("setAllowScansWithTraffic uid=% enabled=%")
- .c(Binder.getCallingUid())
- .c(enabled).flush();
- mWifiStateMachine.setAllowScansWithTraffic(enabled);
- }
-
- @Override
- public int getAllowScansWithTraffic() {
- enforceAccessPermission();
- mLog.info("getAllowScansWithTraffic uid=%").c(Binder.getCallingUid()).flush();
- return mWifiStateMachine.getAllowScansWithTraffic();
- }
-
- @Override
- public boolean setEnableAutoJoinWhenAssociated(boolean enabled) {
- enforceChangePermission();
- mLog.info("setEnableAutoJoinWhenAssociated uid=% enabled=%")
- .c(Binder.getCallingUid())
- .c(enabled).flush();
- return mWifiStateMachine.setEnableAutoJoinWhenAssociated(enabled);
- }
-
- @Override
- public boolean getEnableAutoJoinWhenAssociated() {
- enforceAccessPermission();
- mLog.info("getEnableAutoJoinWhenAssociated uid=%").c(Binder.getCallingUid()).flush();
- return mWifiStateMachine.getEnableAutoJoinWhenAssociated();
- }
-
/* Return the Wifi Connection statistics object */
@Override
public WifiConnectionStatistics getConnectionStatistics() {
@@ -2549,14 +2514,6 @@
return sb.toString();
}
- public void hideCertFromUnaffiliatedUsers(String alias) {
- mCertManager.hideCertFromUnaffiliatedUsers(alias);
- }
-
- public String[] listClientCertsForCurrentUser() {
- return mCertManager.listClientCertsForCurrentUser();
- }
-
/**
* Enable/disable WifiConnectivityManager at runtime
*
diff --git a/service/java/com/android/server/wifi/WifiStateMachine.java b/service/java/com/android/server/wifi/WifiStateMachine.java
index b69d67b..9b4a99f 100644
--- a/service/java/com/android/server/wifi/WifiStateMachine.java
+++ b/service/java/com/android/server/wifi/WifiStateMachine.java
@@ -700,8 +700,6 @@
/* Enable/Disable WifiConnectivityManager */
static final int CMD_ENABLE_WIFI_CONNECTIVITY_MANAGER = BASE + 166;
- /* Enable/Disable AutoJoin when associated */
- static final int CMD_ENABLE_AUTOJOIN_WHEN_ASSOCIATED = BASE + 167;
/* Get all matching Passpoint configurations */
static final int CMD_GET_ALL_MATCHING_CONFIGS = BASE + 168;
@@ -799,8 +797,6 @@
*/
private long mSupplicantScanIntervalMs;
- private boolean mEnableAutoJoinWhenAssociated;
- private int mAlwaysEnableScansWhileAssociated;
private final int mThresholdQualifiedRssi24;
private final int mThresholdQualifiedRssi5;
private final int mThresholdSaturatedRssi24;
@@ -1040,8 +1036,6 @@
com.android.internal.R.string.config_wifi_tcp_buffers);
// Load Device configs
- mEnableAutoJoinWhenAssociated = context.getResources().getBoolean(
- R.bool.config_wifi_framework_enable_associated_network_selection);
mThresholdQualifiedRssi24 = context.getResources().getInteger(
R.integer.config_wifi_framework_wifi_score_low_rssi_threshold_24GHz);
mThresholdQualifiedRssi5 = context.getResources().getInteger(
@@ -1280,26 +1274,6 @@
// mWifiConfigManager.trimANQPCache(true);
}
- public void setAllowScansWithTraffic(int enabled) {
- mAlwaysEnableScansWhileAssociated = enabled;
- }
-
- public int getAllowScansWithTraffic() {
- return mAlwaysEnableScansWhileAssociated;
- }
-
- /*
- * Dynamically turn on/off if switching networks while connected is allowd.
- */
- public boolean setEnableAutoJoinWhenAssociated(boolean enabled) {
- sendMessage(CMD_ENABLE_AUTOJOIN_WHEN_ASSOCIATED, enabled ? 1 : 0);
- return true;
- }
-
- public boolean getEnableAutoJoinWhenAssociated() {
- return mEnableAutoJoinWhenAssociated;
- }
-
private boolean setRandomMacOui() {
String oui = mContext.getResources().getString(R.string.config_wifi_random_mac_oui);
if (TextUtils.isEmpty(oui)) {
@@ -4557,15 +4531,6 @@
case CMD_ENABLE_WIFI_CONNECTIVITY_MANAGER:
mWifiConnectivityManager.enable(message.arg1 == 1 ? true : false);
break;
- case CMD_ENABLE_AUTOJOIN_WHEN_ASSOCIATED:
- final boolean allowed = (message.arg1 > 0);
- boolean old_state = mEnableAutoJoinWhenAssociated;
- mEnableAutoJoinWhenAssociated = allowed;
- if (!old_state && allowed && mScreenOn
- && getCurrentState() == mConnectedState) {
- mWifiConnectivityManager.forceConnectivityScan(WIFI_WORK_SOURCE);
- }
- break;
case CMD_SELECT_TX_POWER_SCENARIO:
int txPowerScenario = message.arg1;
logd("Setting Tx power scenario to " + txPowerScenario);
diff --git a/tests/wifitests/src/com/android/server/wifi/WakeupConfigStoreDataTest.java b/tests/wifitests/src/com/android/server/wifi/WakeupConfigStoreDataTest.java
new file mode 100644
index 0000000..6db9cf5
--- /dev/null
+++ b/tests/wifitests/src/com/android/server/wifi/WakeupConfigStoreDataTest.java
@@ -0,0 +1,164 @@
+/*
+ * Copyright 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.server.wifi;
+
+import static org.mockito.Mockito.eq;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import android.util.Xml;
+
+import com.android.internal.util.FastXmlSerializer;
+
+import com.google.android.collect.Sets;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.xmlpull.v1.XmlPullParser;
+import org.xmlpull.v1.XmlPullParserException;
+import org.xmlpull.v1.XmlSerializer;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.nio.charset.StandardCharsets;
+import java.util.Collections;
+import java.util.Set;
+
+/**
+ * Unit tests for {@link WakeupConfigStoreData}.
+ */
+public class WakeupConfigStoreDataTest {
+
+ @Mock private WakeupConfigStoreData.DataSource<Boolean> mActiveDataSource;
+ @Mock private WakeupConfigStoreData.DataSource<Set<ScanResultMatchInfo>> mNetworkDataSource;
+
+ private WakeupConfigStoreData mWakeupConfigData;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+
+ mWakeupConfigData = new WakeupConfigStoreData(mActiveDataSource, mNetworkDataSource);
+ }
+
+ /**
+ * Helper function for serializing configuration data to a XML block.
+ *
+ * @param shared Flag indicating serializing shared or user configurations
+ * @return byte[] of the XML data
+ */
+ private byte[] serializeData(boolean shared) throws Exception {
+ final XmlSerializer out = new FastXmlSerializer();
+ final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+ out.setOutput(outputStream, StandardCharsets.UTF_8.name());
+ mWakeupConfigData.serializeData(out, shared);
+ out.flush();
+ return outputStream.toByteArray();
+ }
+
+ /**
+ * Helper function for parsing configuration data from a XML block.
+ *
+ * @param data XML data to parse from
+ * @param shared Flag indicating parsing of shared or user configurations
+ */
+ private void deserializeData(byte[] data, boolean shared) throws Exception {
+ final XmlPullParser in = Xml.newPullParser();
+ final ByteArrayInputStream inputStream = new ByteArrayInputStream(data);
+ in.setInput(inputStream, StandardCharsets.UTF_8.name());
+ mWakeupConfigData.deserializeData(in, in.getDepth(), shared);
+ }
+
+ /**
+ * Verify that a XmlPullParserException will be thrown when attempting to serialize data
+ * to the share store.
+ */
+ @Test(expected = XmlPullParserException.class)
+ public void serializeShareDataThrowsException() throws Exception {
+ serializeData(true /* shared */);
+ }
+
+ /**
+ * Verify that a XmlPullParserException will be thrown when attempting to deserialize
+ * data from the share store.
+ */
+ @Test(expected = XmlPullParserException.class)
+ public void deserializeShareDataThrowsException() throws Exception {
+ deserializeData(new byte[0], true /* shared */);
+ }
+
+ /**
+ * Can correctly serialize and deserialize the empty set case.
+ */
+ @Test
+ public void deserializeSerializedData_emptySet() throws Exception {
+ Set<ScanResultMatchInfo> networks = Collections.emptySet();
+ boolean isActive = false;
+
+ when(mActiveDataSource.getData()).thenReturn(isActive);
+ when(mNetworkDataSource.getData()).thenReturn(networks);
+
+ byte[] bytes = serializeData(false /* shared */);
+ deserializeData(bytes, false /* shared */);
+
+ verify(mActiveDataSource).setData(eq(isActive));
+ verify(mNetworkDataSource).setData(eq(networks));
+ }
+
+ /**
+ * Can correctly serialize and deserialize a standard working case.
+ */
+ @Test
+ public void deserializeSerializedData() throws Exception {
+ ScanResultMatchInfo network1 = new ScanResultMatchInfo();
+ network1.networkSsid = "ssid 1";
+ network1.networkType = 0;
+
+ ScanResultMatchInfo network2 = new ScanResultMatchInfo();
+ network2.networkSsid = ",.23;4@, .#,%(,";
+ network2.networkType = 1;
+
+ ScanResultMatchInfo network3 = new ScanResultMatchInfo();
+ network3.networkSsid = "";
+ network3.networkType = 2;
+
+ Set<ScanResultMatchInfo> networks = Sets.newArraySet(network1, network2, network3);
+ boolean isActive = true;
+
+ when(mActiveDataSource.getData()).thenReturn(isActive);
+ when(mNetworkDataSource.getData()).thenReturn(networks);
+
+ byte[] bytes = serializeData(false /* shared */);
+ deserializeData(bytes, false /* shared */);
+
+ verify(mActiveDataSource).setData(eq(isActive));
+ verify(mNetworkDataSource).setData(eq(networks));
+ }
+
+ /**
+ * Verify that reset data wipes the data sources.
+ */
+ @Test
+ public void resetDataWipesDataSources() {
+ mWakeupConfigData.resetData(false /* shared */);
+
+ verify(mActiveDataSource).setData(false);
+ verify(mNetworkDataSource).setData(eq(Collections.emptySet()));
+ }
+}
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiCertManagerTest.java b/tests/wifitests/src/com/android/server/wifi/WifiCertManagerTest.java
deleted file mode 100644
index b123d80..0000000
--- a/tests/wifitests/src/com/android/server/wifi/WifiCertManagerTest.java
+++ /dev/null
@@ -1,143 +0,0 @@
-/*
- * Copyright (C) 2016 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.server.wifi;
-
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-
-import android.content.Context;
-import android.os.UserHandle;
-import android.security.Credentials;
-import android.security.KeyStore;
-import android.test.suitebuilder.annotation.SmallTest;
-import android.util.Log;
-
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
-import org.mockito.Mock;
-
-import java.io.File;
-import java.util.Arrays;
-import java.util.HashSet;
-
-/**
- * Unit tests for {@link com.android.server.wifi.WifiCertManager}.
- */
-@SmallTest
-public class WifiCertManagerTest {
- private static final String TAG = "WifiCertManagerTest";
- private byte[] mConfig;
- private String mConfigFile = "";
-
- @Mock private Context mContext;
- @Rule public TemporaryFolder mTempFolder = new TemporaryFolder();
-
- public WifiCertManagerTest() {
- mConfig = null;
- }
-
- @Before
- public void setUp() {
- try {
- File configFile = mTempFolder.newFile();
- mConfigFile = configFile.getAbsolutePath();
- configFile.delete();
- } catch (Exception e) {
- Log.e(TAG, "Failed to construct test", e);
- }
- }
-
- /**
- * This class is created to avoid mocking file system and KeyStore.
- */
- private class TestWifiCertManager extends WifiCertManager {
- private boolean mAffiliatedUser;
-
- public TestWifiCertManager(Context context) {
- super(context, mConfigFile);
- mAffiliatedUser = false;
- }
-
- protected String[] listClientCertsForAllUsers() {
- String prefix = Credentials.USER_PRIVATE_KEY;
- String mockAnswer[] = {prefix + "abc", prefix + "def", prefix + "ghi"};
- return mockAnswer;
- }
-
- protected byte[] readConfigFile() {
- return mConfig;
- }
-
- protected void writeConfigFile(byte[] payload) {
- mConfig = payload;
- }
-
- protected boolean isAffiliatedUser() {
- return mAffiliatedUser;
- }
-
- public void setAffiliatedUser(boolean value) {
- mAffiliatedUser = value;
- }
- }
-
- // TODO: b/69555027 - determine if test can be removed. for now, disable failing test
- public void testEmptyConfigFile() {
- WifiCertManager certManager = new WifiCertManager(mContext, mConfigFile);
- final String[] expected =
- KeyStore.getInstance().list(
- Credentials.USER_PRIVATE_KEY, UserHandle.myUserId());
- assertArrayEquals(expected, certManager.listClientCertsForCurrentUser());
- }
-
- @Test
- public void testOperations() {
- TestWifiCertManager certManager = new TestWifiCertManager(mContext);
- final HashSet<String> expected1 = new HashSet<>();
- String prefix = Credentials.USER_PRIVATE_KEY;
- expected1.add(prefix + "abc");
- expected1.add(prefix + "def");
- expected1.add(prefix + "ghi");
-
- final HashSet<String> expected2 = new HashSet<>();
- expected2.add(prefix + "abc");
-
- certManager.setAffiliatedUser(false);
- assertEquals(expected1,
- new HashSet<>(Arrays.asList(certManager.listClientCertsForCurrentUser())));
-
- certManager.hideCertFromUnaffiliatedUsers("def");
- certManager.hideCertFromUnaffiliatedUsers("ghi");
- assertEquals(expected2,
- new HashSet<>(Arrays.asList(certManager.listClientCertsForCurrentUser())));
-
- certManager.setAffiliatedUser(true);
- assertEquals(expected1,
- new HashSet<>(Arrays.asList(certManager.listClientCertsForCurrentUser())));
-
- TestWifiCertManager certManager2 = new TestWifiCertManager(mContext);
- certManager2.setAffiliatedUser(false);
- assertEquals(expected2,
- new HashSet<>(Arrays.asList(certManager2.listClientCertsForCurrentUser())));
-
- certManager2.setAffiliatedUser(true);
- assertEquals(expected1,
- new HashSet<>(Arrays.asList(certManager2.listClientCertsForCurrentUser())));
- }
-}