From d6b3cb6b411849786763c52d84db2f6109b1a911 Mon Sep 17 00:00:00 2001 From: Himanshu Rohilla Date: Tue, 25 Feb 2025 20:02:09 -0800 Subject: Add metadata to save ACTION_KEY_MISSING intent count Add get/updateKeyMissingCount() APIs for BluetoothDevice. This allows 1P apps to get/update key missing count for a BluetoothDevice. The key missing count is persisted in the Metadata database. Change-Id: I6ec8c4921547850ed7188b6862e1fe99a46c8be6 Flag: EXEMPT adding metadata Test: m com.android.btservices Test: m statsd_testdrive Test: m statsd_testdrive -terse 390 Test: atest DatabaseManagerTest BluetoothDeviceTest Bug: 394650229 --- .../java/android/bluetooth/BluetoothDevice.java | 32 +++++++++++++++++++--- 1 file changed, 28 insertions(+), 4 deletions(-) (limited to 'framework/java') diff --git a/framework/java/android/bluetooth/BluetoothDevice.java b/framework/java/android/bluetooth/BluetoothDevice.java index 0c3f4288e6..8c053201e9 100644 --- a/framework/java/android/bluetooth/BluetoothDevice.java +++ b/framework/java/android/bluetooth/BluetoothDevice.java @@ -896,8 +896,7 @@ public final class BluetoothDevice implements Parcelable, Attributable { * * @hide */ - @SystemApi - public static final int METADATA_EXCLUSIVE_MANAGER = 29; + @SystemApi public static final int METADATA_EXCLUSIVE_MANAGER = 29; private static final int METADATA_MAX_KEY = METADATA_EXCLUSIVE_MANAGER; @@ -1727,8 +1726,8 @@ public final class BluetoothDevice implements Parcelable, Attributable { /** * Returns the identity address and identity address type of this BluetoothDevice. An identity - * address is a public or static random Bluetooth LE device address that serves as a - * unique identifier. + * address is a public or static random Bluetooth LE device address that serves as a unique + * identifier. * * @return a {@link BluetoothAddress} containing identity address and identity address type. If * Bluetooth is not enabled or identity address type is not available, it will return a @@ -3791,6 +3790,31 @@ public final class BluetoothDevice implements Parcelable, Attributable { return true; } + /** + * Get the number of times {@link ACTION_KEY_MISSING} intent is thrown for this device since + * last successful encrypted connection + * + * @return number of times {@link ACTION_KEY_MISSING} intent is thrown for this device since + * last successful encrypted connection + * + * @hide + */ + @RequiresPermission(BLUETOOTH_CONNECT) + public int getKeyMissingCount() { + final IBluetooth service = getService(); + if (service == null || !isBluetoothEnabled()) { + Log.e(TAG, "Bluetooth is not enabled. Cannot get key missing counter."); + if (DBG) log(Log.getStackTraceString(new Throwable())); + } else { + try { + return service.getKeyMissingCount(this, mAttributionSource); + } catch (RemoteException e) { + Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable())); + } + } + return -1; + } + private static void log(String msg) { Log.d(TAG, msg); } -- cgit v1.2.3-59-g8ed1b