diff options
author | Kolin Lu <kolinlu@google.com> | 2022-09-26 11:34:33 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-26 11:34:33 -0700 |
commit | 6fafa831e619df6845071310c36e83497e5a5e4d (patch) | |
tree | 0da17aca6e23397d518318514d44194ded75833d | |
parent | 701c0a3d2440d8aa49e47cfed23109a7aaa45fae (diff) | |
download | mobly-bundled-snippets-6fafa831e619df6845071310c36e83497e5a5e4d.tar.gz |
Add ScanRecord#getManufacturerSpecificData() to BLE Scan result. (#155)
-rw-r--r-- | src/main/java/com/google/android/mobly/snippet/bundled/utils/JsonSerializer.java | 15 |
1 files changed, 15 insertions, 0 deletions
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 82e1e4f..f00229f 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 @@ -27,6 +27,7 @@ import android.net.wifi.WifiInfo; import android.os.Build; import android.os.Bundle; import android.os.ParcelUuid; +import android.util.SparseArray; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import java.lang.reflect.Modifier; @@ -187,6 +188,20 @@ public class JsonSerializer { Bundle result = new Bundle(); result.putString("DeviceName", record.getDeviceName()); result.putInt("TxPowerLevel", record.getTxPowerLevel()); + result.putBundle( + "manufacturerSpecificData", serializeBleScanManufacturerSpecificData(record)); + return result; + } + + /** Serialize manufacturer specific data from ScanRecord for Bluetooth LE. */ + @TargetApi(Build.VERSION_CODES.LOLLIPOP) + private Bundle serializeBleScanManufacturerSpecificData(ScanRecord record) { + Bundle result = new Bundle(); + SparseArray<byte[]> sparseArray = record.getManufacturerSpecificData(); + for (int i = 0; i < sparseArray.size(); i++) { + int key = sparseArray.keyAt(i); + result.putByteArray(String.valueOf(key), sparseArray.get(key)); + } return result; } |