diff options
author | Mitchell Wills <mwills@google.com> | 2016-02-08 23:43:20 +0000 |
---|---|---|
committer | Android Partner Code Review <android-gerrit-partner@google.com> | 2016-02-08 23:43:20 +0000 |
commit | 5f38b29b5f4b891e59e8c20b210fa9e0e0a28440 (patch) | |
tree | 7ac9f82176824ef7ce17c90291871a8b216a27db | |
parent | d2d3de4c2bea4b949ed78a9b01b920bffa7e51a9 (diff) | |
parent | e4e3b8cb884dd9e754a437ea6feac502191f1767 (diff) |
Merge "Add ScanDetailUtil to convert ScanResult to ScanDetail" into mm-wireless-dev
-rw-r--r-- | service/java/com/android/server/wifi/ScanDetail.java | 2 | ||||
-rw-r--r-- | service/java/com/android/server/wifi/util/ScanDetailUtil.java | 40 | ||||
-rw-r--r-- | tests/wifitests/src/com/android/server/wifi/util/InformationElementUtilTest.java (renamed from tests/wifitests/src/com/android/server/wifi/InformationElementUtilTest.java) | 6 | ||||
-rw-r--r-- | tests/wifitests/src/com/android/server/wifi/util/ScanDetailUtilTest.java | 122 |
4 files changed, 165 insertions, 5 deletions
diff --git a/service/java/com/android/server/wifi/ScanDetail.java b/service/java/com/android/server/wifi/ScanDetail.java index 624dcbefc..4058a58a8 100644 --- a/service/java/com/android/server/wifi/ScanDetail.java +++ b/service/java/com/android/server/wifi/ScanDetail.java @@ -54,7 +54,7 @@ public class ScanDetail { mMatches = null; } - private ScanDetail(ScanResult scanResult, NetworkDetail networkDetail, + public ScanDetail(ScanResult scanResult, NetworkDetail networkDetail, Map<HomeSP, PasspointMatch> matches) { mScanResult = scanResult; mNetworkDetail = networkDetail; diff --git a/service/java/com/android/server/wifi/util/ScanDetailUtil.java b/service/java/com/android/server/wifi/util/ScanDetailUtil.java new file mode 100644 index 000000000..a83900e0a --- /dev/null +++ b/service/java/com/android/server/wifi/util/ScanDetailUtil.java @@ -0,0 +1,40 @@ +/* + * 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.util; + +import android.net.wifi.ScanResult; + +import com.android.server.wifi.ScanDetail; +import com.android.server.wifi.hotspot2.NetworkDetail; + +/** + * Utility for converting a ScanResult to a ScanDetail. + * Only fields that are supported in ScanResult are copied. + */ +public class ScanDetailUtil { + private ScanDetailUtil() { /* not constructable */ } + + /** + * This method should only be used when the informationElements field in the provided scan + * result is filled in with the IEs from the beacon. + */ + public static ScanDetail toScanDetail(ScanResult scanResult) { + NetworkDetail networkDetail = new NetworkDetail(scanResult.BSSID, + scanResult.informationElements, scanResult.anqpLines, scanResult.frequency); + return new ScanDetail(scanResult, networkDetail, null); + } +} diff --git a/tests/wifitests/src/com/android/server/wifi/InformationElementUtilTest.java b/tests/wifitests/src/com/android/server/wifi/util/InformationElementUtilTest.java index 91e8e8324..33ba3d1a6 100644 --- a/tests/wifitests/src/com/android/server/wifi/InformationElementUtilTest.java +++ b/tests/wifitests/src/com/android/server/wifi/util/InformationElementUtilTest.java @@ -11,10 +11,10 @@ * 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 + * limitations under the License. */ -package com.android.server.wifi; +package com.android.server.wifi.util; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; @@ -22,8 +22,6 @@ import static org.junit.Assert.assertEquals; import android.net.wifi.ScanResult.InformationElement; import android.test.suitebuilder.annotation.SmallTest; -import com.android.server.wifi.util.InformationElementUtil; - import org.junit.Test; import java.io.ByteArrayOutputStream; diff --git a/tests/wifitests/src/com/android/server/wifi/util/ScanDetailUtilTest.java b/tests/wifitests/src/com/android/server/wifi/util/ScanDetailUtilTest.java new file mode 100644 index 000000000..07d2521ca --- /dev/null +++ b/tests/wifitests/src/com/android/server/wifi/util/ScanDetailUtilTest.java @@ -0,0 +1,122 @@ +/* + * 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.util; + +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import android.net.wifi.ScanResult; +import android.net.wifi.ScanResult.InformationElement; +import android.net.wifi.WifiSsid; +import android.test.suitebuilder.annotation.SmallTest; + +import com.android.server.wifi.ScanDetail; + +import org.junit.Test; + +import java.nio.charset.StandardCharsets; +import java.util.Arrays; + +/** + * Unit tests for {@link com.android.server.wifi.util.ScanDetailUtil}. + */ +@SmallTest +public class ScanDetailUtilTest { + + @Test + public void convertScanResult() { + final String ssid = "SOME SsId"; + + ScanResult input = new ScanResult(WifiSsid.createFromAsciiEncoded(ssid), ssid, + "ab:cd:01:ef:45:89", 1245, 0, "", -78, 2450, 1025, 22, 33, 20, 0, 0, true); + + input.informationElements = new InformationElement[] { + createIE(InformationElement.EID_SSID, ssid.getBytes(StandardCharsets.UTF_8)) + }; + + ScanDetail output = ScanDetailUtil.toScanDetail(input); + + validateScanDetail(input, output); + } + + @Test + public void convertScanResultWithAnqpLines() { + final String ssid = "SOME SsId"; + + ScanResult input = new ScanResult(WifiSsid.createFromAsciiEncoded(ssid), ssid, + "ab:cd:01:ef:45:89", 1245, 0, "some caps", -78, 2450, 1025, 22, 33, 20, 0, 0, true); + + input.informationElements = new InformationElement[] { + createIE(InformationElement.EID_SSID, ssid.getBytes(StandardCharsets.UTF_8)) + }; + input.anqpLines = Arrays.asList("LINE 1", "line 2", "Line 3"); + + ScanDetail output = ScanDetailUtil.toScanDetail(input); + + validateScanDetail(input, output); + } + + @Test + public void convertScanResultWithoutWifiSsid() { + final String ssid = "Another SSid"; + ScanResult input = new ScanResult(ssid, "ab:cd:01:ef:45:89", 1245, 0, "other caps", + -78, 2450, 1025, 22, 33, 20, 0, 0, true); + input.informationElements = new InformationElement[] { + createIE(InformationElement.EID_SSID, ssid.getBytes(StandardCharsets.UTF_8)) + }; + + ScanDetail output = ScanDetailUtil.toScanDetail(input); + + validateScanDetail(input, output); + } + + private static InformationElement createIE(int id, byte[] bytes) { + InformationElement ie = new InformationElement(); + ie.id = id; + ie.bytes = bytes; + return ie; + } + + private static void validateScanDetail(ScanResult input, ScanDetail output) { + assertNotNull("NetworkDetail was null", output.getNetworkDetail()); + assertNotNull("ScanResult was null", output.getScanResult()); + assertEquals("NetworkDetail SSID", input.SSID, + output.getNetworkDetail().getSSID()); + assertEquals("ScanResult SSID", input.SSID, + output.getScanResult().SSID); + assertEquals("ScanResult wifiSsid", input.wifiSsid, + output.getScanResult().wifiSsid); + assertEquals("getSSID", input.SSID, output.getSSID()); + assertEquals("NetworkDetail BSSID", input.BSSID, + output.getNetworkDetail().getBSSIDString()); + assertEquals("getBSSIDString", input.BSSID, output.getBSSIDString()); + assertEquals("ScanResult frequency", input.frequency, + output.getScanResult().frequency); + assertEquals("ScanResult level", input.level, + output.getScanResult().level); + assertEquals("ScanResult capabilities", input.capabilities, + output.getScanResult().capabilities); + assertEquals("ScanResult timestamp", input.timestamp, + output.getScanResult().timestamp); + assertArrayEquals("ScanResult information elements", input.informationElements, + output.getScanResult().informationElements); + assertEquals("ScanResult anqp lines", input.anqpLines, + output.getScanResult().anqpLines); + } + +} |