summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--service/java/com/android/server/wifi/wificond/PnoNetwork.java67
-rw-r--r--service/java/com/android/server/wifi/wificond/PnoSettings.java77
-rw-r--r--tests/wifitests/src/com/android/server/wifi/wificond/PnoSettingsTest.java91
3 files changed, 235 insertions, 0 deletions
diff --git a/service/java/com/android/server/wifi/wificond/PnoNetwork.java b/service/java/com/android/server/wifi/wificond/PnoNetwork.java
new file mode 100644
index 000000000..fd0d4715f
--- /dev/null
+++ b/service/java/com/android/server/wifi/wificond/PnoNetwork.java
@@ -0,0 +1,67 @@
+/*
+ * 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.wificond;
+
+import android.os.Parcel;
+import android.os.Parcelable;
+
+/**
+ * PnoNetwork for wificond
+ *
+ * @hide
+ */
+public class PnoNetwork implements Parcelable {
+
+ public boolean isHidden;
+ public byte[] ssid;
+
+ /** public constructor */
+ public PnoNetwork() { }
+
+ /** implement Parcelable interface */
+ @Override
+ public int describeContents() {
+ return 0;
+ }
+
+ /**
+ * implement Parcelable interface
+ * |flag| is ignored.
+ */
+ @Override
+ public void writeToParcel(Parcel out, int flags) {
+ out.writeInt(isHidden ? 1 : 0);
+ out.writeByteArray(ssid);
+ }
+
+ /** implement Parcelable interface */
+ public static final Parcelable.Creator<PnoNetwork> CREATOR =
+ new Parcelable.Creator<PnoNetwork>() {
+ @Override
+ public PnoNetwork createFromParcel(Parcel in) {
+ PnoNetwork result = new PnoNetwork();
+ result.isHidden = in.readInt() != 0 ? true : false;
+ result.ssid = in.createByteArray();
+ return result;
+ }
+
+ @Override
+ public PnoNetwork[] newArray(int size) {
+ return new PnoNetwork[size];
+ }
+ };
+}
diff --git a/service/java/com/android/server/wifi/wificond/PnoSettings.java b/service/java/com/android/server/wifi/wificond/PnoSettings.java
new file mode 100644
index 000000000..42fae3974
--- /dev/null
+++ b/service/java/com/android/server/wifi/wificond/PnoSettings.java
@@ -0,0 +1,77 @@
+/*
+ * 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.wificond;
+
+import android.os.Parcel;
+import android.os.Parcelable;
+
+import java.util.ArrayList;
+
+/**
+ * PnoSettings for wificond
+ *
+ * @hide
+ */
+public class PnoSettings implements Parcelable {
+ public int intervalMs;
+ public int min2gRssi;
+ public int min5gRssi;
+ public ArrayList<PnoNetwork> pnoNetworks;
+
+ /** public constructor */
+ public PnoSettings() { }
+
+ /** implement Parcelable interface */
+ @Override
+ public int describeContents() {
+ return 0;
+ }
+
+ /**
+ * implement Parcelable interface
+ * |flag| is ignored.
+ * */
+ @Override
+ public void writeToParcel(Parcel out, int flags) {
+ out.writeInt(intervalMs);
+ out.writeInt(min2gRssi);
+ out.writeInt(min5gRssi);
+ out.writeTypedList(pnoNetworks);
+ }
+
+ /** implement Parcelable interface */
+ public static final Parcelable.Creator<PnoSettings> CREATOR =
+ new Parcelable.Creator<PnoSettings>() {
+ @Override
+ public PnoSettings createFromParcel(Parcel in) {
+ PnoSettings result = new PnoSettings();
+ result.intervalMs = in.readInt();
+ result.min2gRssi = in.readInt();
+ result.min5gRssi = in.readInt();
+
+ result.pnoNetworks = new ArrayList<PnoNetwork>();
+ in.readTypedList(result.pnoNetworks, PnoNetwork.CREATOR);
+
+ return result;
+ }
+
+ @Override
+ public PnoSettings[] newArray(int size) {
+ return new PnoSettings[size];
+ }
+ };
+}
diff --git a/tests/wifitests/src/com/android/server/wifi/wificond/PnoSettingsTest.java b/tests/wifitests/src/com/android/server/wifi/wificond/PnoSettingsTest.java
new file mode 100644
index 000000000..98e913da9
--- /dev/null
+++ b/tests/wifitests/src/com/android/server/wifi/wificond/PnoSettingsTest.java
@@ -0,0 +1,91 @@
+/*
+ * Copyright (C) 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.wificond;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import android.os.Parcel;
+import android.test.suitebuilder.annotation.SmallTest;
+
+import org.junit.Test;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+
+/**
+ * Unit tests for {@link com.android.server.wifi.wificond.PnoSettingsResult}.
+ */
+@SmallTest
+public class PnoSettingsTest {
+
+ private static final byte[] TEST_SSID_1 =
+ new byte[] {'G', 'o', 'o', 'g', 'l', 'e', 'G', 'u', 'e', 's', 't'};
+ private static final byte[] TEST_SSID_2 =
+ new byte[] {'A', 'n', 'd', 'r', 'o', 'i', 'd', 'T', 'e', 's', 't'};
+ private static final int TEST_INTERVAL_MS = 30000;
+ private static final int TEST_MIN_2G_RSSI = -60;
+ private static final int TEST_MIN_5G_RSSI = -65;
+
+ @Test
+ public void canSerializeAndDeserialize() throws Exception {
+
+ PnoSettings pnoSettings = new PnoSettings();
+
+ PnoNetwork pnoNetwork1 = new PnoNetwork();
+ pnoNetwork1.ssid = TEST_SSID_1;
+ pnoNetwork1.isHidden = true;
+
+ PnoNetwork pnoNetwork2 = new PnoNetwork();
+ pnoNetwork2.ssid = TEST_SSID_2;
+ pnoNetwork2.isHidden = false;
+
+ pnoSettings.pnoNetworks = new ArrayList(Arrays.asList(pnoNetwork1, pnoNetwork2));
+
+ pnoSettings.intervalMs = TEST_INTERVAL_MS;
+ pnoSettings.min2gRssi = TEST_MIN_2G_RSSI;
+ pnoSettings.min5gRssi = TEST_MIN_5G_RSSI;
+
+ Parcel parcel = Parcel.obtain();
+ pnoSettings.writeToParcel(parcel, 0);
+ // Rewind the pointer to the head of the parcel.
+ parcel.setDataPosition(0);
+ PnoSettings pnoSettingsDeserialized =
+ pnoSettings.CREATOR.createFromParcel(parcel);
+
+ assertEquals(pnoSettings.intervalMs,
+ pnoSettingsDeserialized.intervalMs);
+ assertEquals(pnoSettings.min2gRssi,
+ pnoSettingsDeserialized.min2gRssi);
+ assertEquals(pnoSettings.min5gRssi,
+ pnoSettingsDeserialized.min5gRssi);
+
+ assertNotNull(pnoSettingsDeserialized.pnoNetworks);
+ assertEquals(pnoSettings.pnoNetworks.size(),
+ pnoSettingsDeserialized.pnoNetworks.size());
+ assertArrayEquals(pnoSettings.pnoNetworks.get(0).ssid,
+ pnoSettingsDeserialized.pnoNetworks.get(0).ssid);
+ assertArrayEquals(pnoSettings.pnoNetworks.get(1).ssid,
+ pnoSettingsDeserialized.pnoNetworks.get(1).ssid);
+ assertEquals(pnoSettings.pnoNetworks.get(0).isHidden,
+ pnoSettingsDeserialized.pnoNetworks.get(0).isHidden);
+ assertEquals(pnoSettings.pnoNetworks.get(1).isHidden,
+ pnoSettingsDeserialized.pnoNetworks.get(1).isHidden);
+
+ }
+}