diff options
author | Ang Li <angli@google.com> | 2017-04-27 16:03:45 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-04-27 16:03:45 -0700 |
commit | dcae801dceef228c4c9be81f5ba61660ce90369f (patch) | |
tree | 993f7b142de45cca47974519fa59a56f68648364 /src/main | |
parent | 4c0c5d68410dda9845e457a37fbb2098e743b550 (diff) | |
download | mobly-bundled-snippets-dcae801dceef228c4c9be81f5ba61660ce90369f.tar.gz |
Fixes in `serializeBluetoothDevice`. (#34)
Diffstat (limited to 'src/main')
3 files changed, 34 insertions, 31 deletions
diff --git a/src/main/java/com/google/android/mobly/snippet/bundled/AccountSnippet.java b/src/main/java/com/google/android/mobly/snippet/bundled/AccountSnippet.java index dc1fac1..627d1b4 100644 --- a/src/main/java/com/google/android/mobly/snippet/bundled/AccountSnippet.java +++ b/src/main/java/com/google/android/mobly/snippet/bundled/AccountSnippet.java @@ -54,6 +54,7 @@ public class AccountSnippet implements Snippet { private static class AccountSnippetException extends Exception { private static final long serialVersionUID = 1; + public AccountSnippetException(String msg) { super(msg); } diff --git a/src/main/java/com/google/android/mobly/snippet/bundled/WifiManagerSnippet.java b/src/main/java/com/google/android/mobly/snippet/bundled/WifiManagerSnippet.java index ba9569c..ea75b5a 100644 --- a/src/main/java/com/google/android/mobly/snippet/bundled/WifiManagerSnippet.java +++ b/src/main/java/com/google/android/mobly/snippet/bundled/WifiManagerSnippet.java @@ -43,6 +43,7 @@ import org.json.JSONObject; public class WifiManagerSnippet implements Snippet { private static class WifiManagerSnippetException extends Exception { private static final long serialVersionUID = 1; + public WifiManagerSnippetException(String msg) { super(msg); } diff --git a/src/main/java/com/google/android/mobly/snippet/bundled/utils/JsonSerializer.java b/src/main/java/com/google/android/mobly/snippet/bundled/utils/JsonSerializer.java index 45af4a4..fc7d17b 100644 --- a/src/main/java/com/google/android/mobly/snippet/bundled/utils/JsonSerializer.java +++ b/src/main/java/com/google/android/mobly/snippet/bundled/utils/JsonSerializer.java @@ -21,6 +21,7 @@ import android.net.DhcpInfo; import android.net.wifi.SupplicantState; import android.net.wifi.WifiConfiguration; import android.net.wifi.WifiInfo; +import android.os.Build; import android.os.ParcelUuid; import com.google.gson.Gson; import com.google.gson.GsonBuilder; @@ -28,7 +29,6 @@ import java.lang.reflect.Modifier; import java.net.InetAddress; import java.net.UnknownHostException; import java.util.ArrayList; -import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; @@ -127,42 +127,43 @@ public class JsonSerializer { private JSONObject serializeBluetoothDevice(BluetoothDevice data) throws JSONException { JSONObject result = new JSONObject(); result.put("Address", data.getAddress()); + final String bondStateFieldName = "BondState"; switch (data.getBondState()) { - case 10: - result.put("BondState", "None"); + case BluetoothDevice.BOND_NONE: + result.put(bondStateFieldName, "BOND_NONE"); break; - case 11: - result.put("BondState", "Bonding"); + case BluetoothDevice.BOND_BONDING: + result.put(bondStateFieldName, "BOND_BONDING"); break; - case 12: - result.put("BondState", "Bonded"); - } - if (data.getName() == null) { - result.put("Name", "Null"); - } else { - result.put("Name", data.getName()); - } - switch (data.getType()) { - case 0: - result.put("Type", "Unknown"); - break; - case 1: - result.put("Type", "Classic"); + case BluetoothDevice.BOND_BONDED: + result.put(bondStateFieldName, "BOND_BONDED"); break; - case 2: - result.put("Type", "Le"); - break; - case 3: - result.put("Type", "Dual"); } - if (data.getUuids() == null) { - result.put("UUIDs", "Null"); - } else { - ArrayList<String> uuids = new ArrayList<String>(); - for (ParcelUuid uuid : data.getUuids()) { - uuids.add(uuid.toString()); + result.put("Name", data.getName()); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { + final String deviceTypeFieldName = "DeviceType"; + switch (data.getType()) { + case BluetoothDevice.DEVICE_TYPE_CLASSIC: + result.put(deviceTypeFieldName, "DEVICE_TYPE_CLASSIC"); + break; + case BluetoothDevice.DEVICE_TYPE_LE: + result.put(deviceTypeFieldName, "DEVICE_TYPE_LE"); + break; + case BluetoothDevice.DEVICE_TYPE_DUAL: + result.put(deviceTypeFieldName, "DEVICE_TYPE_DUAL"); + break; + case BluetoothDevice.DEVICE_TYPE_UNKNOWN: + result.put(deviceTypeFieldName, "DEVICE_TYPE_UNKNOWN"); + break; + } + ParcelUuid[] parcelUuids = data.getUuids(); + if (parcelUuids != null) { + ArrayList<String> uuidStrings = new ArrayList<>(parcelUuids.length); + for (ParcelUuid parcelUuid : parcelUuids) { + uuidStrings.add(parcelUuid.getUuid().toString()); + } + result.put("UUIDs", uuidStrings); } - result.put("UUIDs", new JSONArray(uuids)); } return result; } |