diff options
author | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2023-08-01 23:08:30 +0000 |
---|---|---|
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2023-08-01 23:08:30 +0000 |
commit | 6f86ee0c341bd7f37c57d40f064a47a41928f1bd (patch) | |
tree | 96e4fe0ad770a3fdc1f1850c05a0c77b88f23de5 /src/main/java/com/google/android/mobly/snippet/bundled/utils/JsonDeserializer.java | |
parent | 9db2ea350918eaecdf676188364a26d0974c7315 (diff) | |
parent | ed17dbb8710329d4d841986f903620dea4071174 (diff) | |
download | mobly-bundled-snippets-android14-qpr1-s2-release.tar.gz |
Snap for 10594510 from ed17dbb8710329d4d841986f903620dea4071174 to udc-qpr1-releaseandroid-14.0.0_r27android-14.0.0_r26android-14.0.0_r25android-14.0.0_r24android-14.0.0_r23android-14.0.0_r22android-14.0.0_r21android-14.0.0_r20android-14.0.0_r19android-14.0.0_r18android-14.0.0_r17android-14.0.0_r16android14-qpr1-s2-releaseandroid14-qpr1-release
Change-Id: I575c244d26ea4d9dfb5e2c4b55da8f9f54933d48
Diffstat (limited to 'src/main/java/com/google/android/mobly/snippet/bundled/utils/JsonDeserializer.java')
-rw-r--r-- | src/main/java/com/google/android/mobly/snippet/bundled/utils/JsonDeserializer.java | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/src/main/java/com/google/android/mobly/snippet/bundled/utils/JsonDeserializer.java b/src/main/java/com/google/android/mobly/snippet/bundled/utils/JsonDeserializer.java index 2f943e0..a3d5325 100644 --- a/src/main/java/com/google/android/mobly/snippet/bundled/utils/JsonDeserializer.java +++ b/src/main/java/com/google/android/mobly/snippet/bundled/utils/JsonDeserializer.java @@ -17,12 +17,17 @@ package com.google.android.mobly.snippet.bundled.utils; import android.annotation.TargetApi; +import android.bluetooth.BluetoothGattCharacteristic; +import android.bluetooth.BluetoothGattService; import android.bluetooth.le.AdvertiseData; import android.bluetooth.le.AdvertiseSettings; +import android.bluetooth.le.ScanFilter; +import android.bluetooth.le.ScanSettings; import android.net.wifi.WifiConfiguration; import android.os.Build; import android.os.ParcelUuid; import android.util.Base64; +import java.util.UUID; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; @@ -101,4 +106,52 @@ public class JsonDeserializer { } return builder.build(); } + + @TargetApi(Build.VERSION_CODES.LOLLIPOP) + public static BluetoothGattService jsonToBluetoothGattService( + DataHolder dataHolder, JSONObject jsonObject) throws JSONException { + BluetoothGattService service = + new BluetoothGattService( + UUID.fromString(jsonObject.getString("UUID")), + MbsEnums.BLE_SERVICE_TYPE.getInt(jsonObject.getString("Type"))); + JSONArray characteristics = jsonObject.getJSONArray("Characteristics"); + for (int i = 0; i < characteristics.length(); i++) { + BluetoothGattCharacteristic characteristic = + jsonToBluetoothGattCharacteristic(dataHolder, characteristics.getJSONObject(i)); + service.addCharacteristic(characteristic); + } + return service; + } + + @TargetApi(Build.VERSION_CODES.LOLLIPOP) + public static BluetoothGattCharacteristic jsonToBluetoothGattCharacteristic( + DataHolder dataHolder, JSONObject jsonObject) throws JSONException { + BluetoothGattCharacteristic characteristic = + new BluetoothGattCharacteristic( + UUID.fromString(jsonObject.getString("UUID")), + MbsEnums.BLE_PROPERTY_TYPE.getInt(jsonObject.getString("Property")), + MbsEnums.BLE_PERMISSION_TYPE.getInt(jsonObject.getString("Permission"))); + if (jsonObject.has("Data")) { + dataHolder.insertData(characteristic, jsonObject.getString("Data")); + } + return characteristic; + } + + @TargetApi(Build.VERSION_CODES.LOLLIPOP) + public static ScanFilter jsonToScanFilter(JSONObject jsonObject) throws JSONException { + ScanFilter.Builder builder = new ScanFilter.Builder(); + if (jsonObject.has("ServiceUuid")) { + builder.setServiceUuid(ParcelUuid.fromString(jsonObject.getString("ServiceUuid"))); + } + return builder.build(); + } + + @TargetApi(Build.VERSION_CODES.LOLLIPOP) + public static ScanSettings jsonToScanSettings(JSONObject jsonObject) throws JSONException { + ScanSettings.Builder builder = new ScanSettings.Builder(); + if (jsonObject.has("ScanMode")) { + builder.setScanMode(MbsEnums.BLE_SCAN_MODE.getInt(jsonObject.getString("ScanMode"))); + } + return builder.build(); + } } |