diff options
author | Glen Kuhne <kuh@google.com> | 2017-08-02 11:02:50 -0700 |
---|---|---|
committer | Glen Kuhne <kuh@google.com> | 2017-08-02 14:18:16 -0700 |
commit | 5bf1c66cfc5099801abe53fd54cef661740b24b5 (patch) | |
tree | a963c0a4ce17ee7f7eb6714eaab9a5387e5727cc /service | |
parent | b1d6ef28f4a40b4b7384859b52b176d55f7d4bae (diff) |
Restore WifiP2pDevice.primaryDeviceType formatting
This CL restores the formatting of the primaryDeviceType string in
WifiP2pDevice, which was broken when the HAL moved to Treble instead of
wpa_supplicant ctrl-iface (which was applying the appropriate
formatter).
Bug: 63657840
Test: Manually verified, & unit tests updated
Change-Id: Ia86d74801020bf9098a3b7721e464201f99047f5
Diffstat (limited to 'service')
-rw-r--r-- | service/java/com/android/server/wifi/p2p/SupplicantP2pIfaceCallback.java | 7 | ||||
-rw-r--r-- | service/java/com/android/server/wifi/util/NativeUtil.java | 13 |
2 files changed, 14 insertions, 6 deletions
diff --git a/service/java/com/android/server/wifi/p2p/SupplicantP2pIfaceCallback.java b/service/java/com/android/server/wifi/p2p/SupplicantP2pIfaceCallback.java index 802f6435c..b7a4b3bc8 100644 --- a/service/java/com/android/server/wifi/p2p/SupplicantP2pIfaceCallback.java +++ b/service/java/com/android/server/wifi/p2p/SupplicantP2pIfaceCallback.java @@ -30,8 +30,6 @@ import android.util.Log; import com.android.server.wifi.p2p.WifiP2pServiceImpl.P2pStatus; import com.android.server.wifi.util.NativeUtil; -import libcore.util.HexEncoding; - import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -97,7 +95,6 @@ public class SupplicantP2pIfaceCallback extends ISupplicantP2pIfaceCallback.Stub byte[] wfdDeviceInfo) { WifiP2pDevice device = new WifiP2pDevice(); device.deviceName = deviceName; - if (deviceName == null) { Log.e(TAG, "Missing device name."); return; @@ -111,8 +108,7 @@ public class SupplicantP2pIfaceCallback extends ISupplicantP2pIfaceCallback.Stub } try { - device.primaryDeviceType = new String(HexEncoding.encode( - primaryDeviceType, 0, primaryDeviceType.length)); + device.primaryDeviceType = NativeUtil.wpsDevTypeStringFromByteArray(primaryDeviceType); } catch (Exception e) { Log.e(TAG, "Could not encode device primary type.", e); return; @@ -134,7 +130,6 @@ public class SupplicantP2pIfaceCallback extends ISupplicantP2pIfaceCallback.Stub mMonitor.broadcastP2pDeviceFound(mInterface, device); } - /** * Used to indicate that a P2P device has been lost. * diff --git a/service/java/com/android/server/wifi/util/NativeUtil.java b/service/java/com/android/server/wifi/util/NativeUtil.java index 07c3f9b38..95ee11eb8 100644 --- a/service/java/com/android/server/wifi/util/NativeUtil.java +++ b/service/java/com/android/server/wifi/util/NativeUtil.java @@ -30,6 +30,7 @@ import java.nio.charset.CharacterCodingException; import java.nio.charset.CharsetDecoder; import java.nio.charset.StandardCharsets; import java.util.ArrayList; +import java.util.Arrays; /** * Provide utility functions for native interfacing modules. @@ -330,4 +331,16 @@ public class NativeUtil { } return new String(HexEncoding.encode(bytes)).toLowerCase(); } + + /** + * Converts an 8 byte array to a WPS device type string + * { 0, 1, 2, -1, 4, 5, 6, 7 } --> "1-02FF0405-1543"; + */ + public static String wpsDevTypeStringFromByteArray(byte[] devType) { + byte[] a = devType; + int x = ((a[0] & 0xFF) << 8) | (a[1] & 0xFF); + String y = new String(HexEncoding.encode(Arrays.copyOfRange(devType, 2, 6))); + int z = ((a[6] & 0xFF) << 8) | (a[7] & 0xFF); + return String.format("%d-%s-%d", x, y, z); + } } |