Update BT header using BT metadata

As for unthethered headset, get BT data from BT metadata, rather than
CachedBluetoothDevice

Bug: 122460277
Test: RunSettingsRoboTests
Change-Id: Ifb5507cbbce9602726ba272c12d1bf95eff91001
This commit is contained in:
jackqdyulei
2019-01-23 13:00:13 -08:00
parent 1fc7629dda
commit 47123c8224
5 changed files with 208 additions and 11 deletions

View File

@@ -47,6 +47,8 @@ public final class Utils {
static final boolean V = BluetoothUtils.V; // verbose logging
static final boolean D = BluetoothUtils.D; // regular logging
public static final int META_INT_ERROR = -1;
private Utils() {
}
@@ -152,4 +154,29 @@ public final class Utils {
return Settings.Global.getInt(context.getContentResolver(),
Settings.Global.BLE_SCAN_ALWAYS_AVAILABLE, 0) == 1;
}
public static boolean getBooleanMetaData(BluetoothDevice bluetoothDevice, int key) {
if (bluetoothDevice == null) {
return false;
}
return Boolean.parseBoolean(bluetoothDevice.getMetadata(key));
}
public static String getStringMetaData(BluetoothDevice bluetoothDevice, int key) {
if (bluetoothDevice == null) {
return null;
}
return bluetoothDevice.getMetadata(key);
}
public static int getIntMetaData(BluetoothDevice bluetoothDevice, int key) {
if (bluetoothDevice == null) {
return META_INT_ERROR;
}
try {
return Integer.parseInt(bluetoothDevice.getMetadata(key));
} catch (NumberFormatException e) {
return META_INT_ERROR;
}
}
}