Add method to get bluetooth key missing count
Bug: 388018781
Test: local build and tested. I didn't find a good way to add unit test for reflection
Flag: EXEMPT add utils
Change-Id: I79bb15984cb1ac4085d1b04f26e5d8e88717545f
diff --git a/packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothUtils.java b/packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothUtils.java
index e78a692..ae9ad95 100644
--- a/packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothUtils.java
+++ b/packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothUtils.java
@@ -51,6 +51,8 @@
import com.google.common.collect.ImmutableSet;
import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
import java.util.List;
import java.util.Locale;
import java.util.Objects;
@@ -1268,4 +1270,15 @@
return false;
}
+
+ /** Gets key missing count of the device. This is a workaround before the API is rolled out. */
+ public static Integer getKeyMissingCount(BluetoothDevice device) {
+ try {
+ Method m = BluetoothDevice.class.getDeclaredMethod("getKeyMissingCount");
+ return (int) m.invoke(device);
+ } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) {
+ Log.w(TAG, "error happens when getKeyMissingCount.");
+ return null;
+ }
+ }
}