summaryrefslogtreecommitdiff
path: root/framework/java/android/bluetooth/BluetoothDevice.java
diff options
context:
space:
mode:
authorLee Shombert <shombert@google.com>2020-02-13 11:34:40 -0800
committerLee Shombert <shombert@google.com>2020-02-19 01:04:44 +0000
commitc3389265edab7bf009a17e30fcd4069d06bd1230 (patch)
treef83e9c3ca6d5e95fb2e49fb5e2f160147ce0e32c /framework/java/android/bluetooth/BluetoothDevice.java
parent1bacc8d3bf18987f2ef385e6d7f9800ff4c2bfa1 (diff)
Binder cache for Bluetooth getBondState()
Bug: 140788621 Test: A special build that puts the PropertyInvalidatedCache in verification mode was loaded on the device. Then one iteration of MPTS was executed. No cache inconsistencies were found and no SELinux violations (associated with the binder cache) were found. The number of cache misses was approximately 10% of the total binder calls. Then the phone was cycled through bluetooth pairing and unpairing events. Change-Id: Ia494f0ad58b889130052e5beb3bec6d1011508ef
Diffstat (limited to 'framework/java/android/bluetooth/BluetoothDevice.java')
-rw-r--r--framework/java/android/bluetooth/BluetoothDevice.java36
1 files changed, 33 insertions, 3 deletions
diff --git a/framework/java/android/bluetooth/BluetoothDevice.java b/framework/java/android/bluetooth/BluetoothDevice.java
index 5b60b85f47..3e1a480b4f 100644
--- a/framework/java/android/bluetooth/BluetoothDevice.java
+++ b/framework/java/android/bluetooth/BluetoothDevice.java
@@ -25,6 +25,7 @@ import android.annotation.SdkConstant;
import android.annotation.SdkConstant.SdkConstantType;
import android.annotation.SuppressLint;
import android.annotation.SystemApi;
+import android.app.PropertyInvalidatedCache;
import android.compat.annotation.UnsupportedAppUsage;
import android.content.Context;
import android.os.Handler;
@@ -1299,6 +1300,31 @@ public final class BluetoothDevice implements Parcelable {
return false;
}
+ private static final String BLUETOOTH_BONDING_CACHE_PROPERTY =
+ "cache_key.bluetooth.get_bond_state";
+ private final PropertyInvalidatedCache<BluetoothDevice, Integer> mBluetoothBondCache =
+ new PropertyInvalidatedCache<BluetoothDevice, Integer>(
+ 8, BLUETOOTH_BONDING_CACHE_PROPERTY) {
+ @Override
+ protected Integer recompute(BluetoothDevice query) {
+ try {
+ return sService.getBondState(query);
+ } catch (RemoteException e) {
+ throw e.rethrowAsRuntimeException();
+ }
+ }
+ };
+
+ /** @hide */
+ public void disableBluetoothGetBondStateCache() {
+ mBluetoothBondCache.disableLocal();
+ }
+
+ /** @hide */
+ public static void invalidateBluetoothGetBondStateCache() {
+ PropertyInvalidatedCache.invalidateCache(BLUETOOTH_BONDING_CACHE_PROPERTY);
+ }
+
/**
* Get the bond state of the remote device.
* <p>Possible values for the bond state are:
@@ -1316,9 +1342,13 @@ public final class BluetoothDevice implements Parcelable {
return BOND_NONE;
}
try {
- return service.getBondState(this);
- } catch (RemoteException e) {
- Log.e(TAG, "", e);
+ return mBluetoothBondCache.query(this);
+ } catch (RuntimeException e) {
+ if (e.getCause() instanceof RemoteException) {
+ Log.e(TAG, "", e);
+ } else {
+ throw e;
+ }
}
return BOND_NONE;
}