summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tests/wifitests/Android.bp49
-rw-r--r--tests/wifitests/src/com/android/server/wifi/IpConfigStoreTestWriter.java147
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiBackupRestoreTest.java8
3 files changed, 160 insertions, 44 deletions
diff --git a/tests/wifitests/Android.bp b/tests/wifitests/Android.bp
index 851a6016e..6c48c3b60 100644
--- a/tests/wifitests/Android.bp
+++ b/tests/wifitests/Android.bp
@@ -17,13 +17,7 @@
android_test {
name: "FrameworksWifiTests",
- srcs: [
- "**/*.java",
- // wifi-service sources must be included here so that the latest changes
- // will be used when tests. Otherwise the tests would run against the installed
- // system.
- ":wifi-service-srcs",
- ],
+ srcs: [ "**/*.java" ],
dxflags: ["--multi-dex"],
@@ -34,35 +28,14 @@ android_test {
"hamcrest-library",
"mockito-target-extended-minus-junit4",
"frameworks-base-testutils",
- "truth-prebuilt",
+ "truth-prebuilt",
- // Libraries needed by wifi-service
- "android.hardware.wifi-V1.0-java",
- "android.hardware.wifi-V1.1-java",
- "android.hardware.wifi-V1.2-java",
- "android.hardware.wifi-V1.3-java",
- "android.hardware.wifi-V1.4-java",
- "android.hardware.wifi.hostapd-V1.0-java",
- "android.hardware.wifi.hostapd-V1.1-java",
- "android.hardware.wifi.hostapd-V1.2-java",
- "android.hardware.wifi.supplicant-V1.0-java",
- "android.hardware.wifi.supplicant-V1.1-java",
- "android.hardware.wifi.supplicant-V1.2-java",
- "android.hardware.wifi.supplicant-V1.3-java",
- "android.hidl.manager-V1.2-java",
- "androidx.annotation_annotation",
- "bouncycastle-unbundled",
- "ksoap2",
- // Note: libprotobuf-java-lite uses a few core platform APIs which
- // does show up as @hide API usage. But, this can be safely ignored
- // since the library uses reflection to ensure that the OS does provide
- // the necessary core platform APIs.
- "libprotobuf-java-lite",
- "libnanohttpd",
- "services.net-module-wifi",
- "services.core",
- "wifi-lite-protos",
- "wifi-nano-protos",
+ // Statically link wifi-service-pre-jarjar since we want to test the working copy of
+ // service-wifi, not the on-device copy.
+ // Use pre-jarjar version so that we can reference symbols before they are renamed.
+ // Then, the jarjar_rules here will perform the rename for the entire APK
+ // i.e. service-wifi + test code
+ "wifi-service-pre-jarjar",
],
jarjar_rules: ":wifi-jarjar-rules",
@@ -80,14 +53,8 @@ android_test {
"android.test.runner",
"android.test.base",
"android.test.mock",
-
- // Libraries needed by wifi-service
- "error_prone_annotations",
- "jsr305",
- "services",
// load the resources from the resources APK.
"ServiceWifiResources",
- "unsupportedappusage",
],
// These must be explicitly included because they are not normally accessible
diff --git a/tests/wifitests/src/com/android/server/wifi/IpConfigStoreTestWriter.java b/tests/wifitests/src/com/android/server/wifi/IpConfigStoreTestWriter.java
new file mode 100644
index 000000000..f5a81bcb4
--- /dev/null
+++ b/tests/wifitests/src/com/android/server/wifi/IpConfigStoreTestWriter.java
@@ -0,0 +1,147 @@
+/*
+ * Copyright (C) 2020 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.net.IpConfiguration;
+import android.net.LinkAddress;
+import android.net.ProxyInfo;
+import android.net.StaticIpConfiguration;
+import android.util.Log;
+
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.net.InetAddress;
+
+/**
+ * Copied from frameworks/base/services/core/java/com/android/server/net/IpConfigStore.java
+ */
+public class IpConfigStoreTestWriter {
+ private static final String TAG = "IpConfigStoreTestWriter";
+
+ private static final String ID_KEY = "id";
+ private static final String IP_ASSIGNMENT_KEY = "ipAssignment";
+ private static final String LINK_ADDRESS_KEY = "linkAddress";
+ private static final String GATEWAY_KEY = "gateway";
+ private static final String DNS_KEY = "dns";
+ private static final String PROXY_SETTINGS_KEY = "proxySettings";
+ private static final String PROXY_HOST_KEY = "proxyHost";
+ private static final String PROXY_PORT_KEY = "proxyPort";
+ private static final String PROXY_PAC_FILE = "proxyPac";
+ private static final String EXCLUSION_LIST_KEY = "exclusionList";
+ private static final String EOS = "eos";
+
+ /** Serialize an IpConfiguration object */
+ public static boolean writeConfig(DataOutputStream out, String configKey,
+ IpConfiguration config, int version) throws IOException {
+ boolean written = false;
+
+ try {
+ switch (config.ipAssignment) {
+ case STATIC:
+ out.writeUTF(IP_ASSIGNMENT_KEY);
+ out.writeUTF(config.ipAssignment.toString());
+ StaticIpConfiguration staticIpConfiguration = config.staticIpConfiguration;
+ if (staticIpConfiguration != null) {
+ if (staticIpConfiguration.ipAddress != null) {
+ LinkAddress ipAddress = staticIpConfiguration.ipAddress;
+ out.writeUTF(LINK_ADDRESS_KEY);
+ out.writeUTF(ipAddress.getAddress().getHostAddress());
+ out.writeInt(ipAddress.getPrefixLength());
+ }
+ if (staticIpConfiguration.gateway != null) {
+ out.writeUTF(GATEWAY_KEY);
+ out.writeInt(0); // Default route.
+ out.writeInt(1); // Have a gateway.
+ out.writeUTF(staticIpConfiguration.gateway.getHostAddress());
+ }
+ for (InetAddress inetAddr : staticIpConfiguration.dnsServers) {
+ out.writeUTF(DNS_KEY);
+ out.writeUTF(inetAddr.getHostAddress());
+ }
+ }
+ written = true;
+ break;
+ case DHCP:
+ out.writeUTF(IP_ASSIGNMENT_KEY);
+ out.writeUTF(config.ipAssignment.toString());
+ written = true;
+ break;
+ case UNASSIGNED:
+ /* Ignore */
+ break;
+ default:
+ loge("Ignore invalid ip assignment while writing");
+ break;
+ }
+
+ switch (config.proxySettings) {
+ case STATIC:
+ ProxyInfo proxyProperties = config.httpProxy;
+ String exclusionList = proxyProperties.getExclusionListAsString();
+ out.writeUTF(PROXY_SETTINGS_KEY);
+ out.writeUTF(config.proxySettings.toString());
+ out.writeUTF(PROXY_HOST_KEY);
+ out.writeUTF(proxyProperties.getHost());
+ out.writeUTF(PROXY_PORT_KEY);
+ out.writeInt(proxyProperties.getPort());
+ if (exclusionList != null) {
+ out.writeUTF(EXCLUSION_LIST_KEY);
+ out.writeUTF(exclusionList);
+ }
+ written = true;
+ break;
+ case PAC:
+ ProxyInfo proxyPacProperties = config.httpProxy;
+ out.writeUTF(PROXY_SETTINGS_KEY);
+ out.writeUTF(config.proxySettings.toString());
+ out.writeUTF(PROXY_PAC_FILE);
+ out.writeUTF(proxyPacProperties.getPacFileUrl().toString());
+ written = true;
+ break;
+ case NONE:
+ out.writeUTF(PROXY_SETTINGS_KEY);
+ out.writeUTF(config.proxySettings.toString());
+ written = true;
+ break;
+ case UNASSIGNED:
+ /* Ignore */
+ break;
+ default:
+ loge("Ignore invalid proxy settings while writing");
+ break;
+ }
+
+ if (written) {
+ out.writeUTF(ID_KEY);
+ if (version < 3) {
+ out.writeInt(Integer.valueOf(configKey));
+ } else {
+ out.writeUTF(configKey);
+ }
+ }
+ } catch (NullPointerException e) {
+ loge("Failure in writing " + config + e);
+ }
+ out.writeUTF(EOS);
+
+ return written;
+ }
+
+ private static void loge(String s) {
+ Log.e(TAG, s);
+ }
+}
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiBackupRestoreTest.java b/tests/wifitests/src/com/android/server/wifi/WifiBackupRestoreTest.java
index 6b01f8e45..e640c4232 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiBackupRestoreTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiBackupRestoreTest.java
@@ -25,7 +25,6 @@ import android.os.Process;
import androidx.test.filters.SmallTest;
-import com.android.server.net.IpConfigStore;
import com.android.server.wifi.util.WifiPermissionsUtil;
import org.junit.After;
@@ -1183,8 +1182,11 @@ public class WifiBackupRestoreTest extends WifiBaseTest {
out.writeInt(configStoreVersion);
for (WifiConfiguration configuration : configurations) {
// TODO: store configKey as a string instead of calculating its hash
- IpConfigStore.writeConfig(out, String.valueOf(configuration.getKey().hashCode()),
- configuration.getIpConfiguration(), configStoreVersion);
+ IpConfigStoreTestWriter.writeConfig(
+ out,
+ String.valueOf(configuration.getKey().hashCode()),
+ configuration.getIpConfiguration(),
+ configStoreVersion);
}
out.flush();
return bos.toByteArray();