summaryrefslogtreecommitdiff
path: root/framework/java/android/bluetooth/BluetoothDevice.java
diff options
context:
space:
mode:
authorLee Shombert <shombert@google.com>2022-02-14 20:36:01 +0000
committerAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2022-02-15 03:09:07 +0000
commitf24d484474e4d3fb1188c79f0f2585ce41b039d8 (patch)
tree12ccc8e5f606474c5acbbf4c5f92a02d7e03b8cb /framework/java/android/bluetooth/BluetoothDevice.java
parent6c997399d037790ae71e1edc627be02597ec4fea (diff)
Revert "Enable binder caches in Bluetooth module"
This reverts commit 3e8fdcf3a141216196c27c15eed57cb7d0913877. Reason for revert: Bug: 219424192 Test: No test. Change-Id: Ibe7e246a85d048d55904f2a2f61ec5ac1f97a449 (cherry picked from commit 8deea4b181821016dc637a5ae7e391fd00ba58eb) Merged-In:Ibe7e246a85d048d55904f2a2f61ec5ac1f97a449
Diffstat (limited to 'framework/java/android/bluetooth/BluetoothDevice.java')
-rw-r--r--framework/java/android/bluetooth/BluetoothDevice.java102
1 files changed, 45 insertions, 57 deletions
diff --git a/framework/java/android/bluetooth/BluetoothDevice.java b/framework/java/android/bluetooth/BluetoothDevice.java
index 1d1b2334bd..95e9abc37b 100644
--- a/framework/java/android/bluetooth/BluetoothDevice.java
+++ b/framework/java/android/bluetooth/BluetoothDevice.java
@@ -25,8 +25,7 @@ import android.annotation.RequiresPermission;
import android.annotation.SdkConstant;
import android.annotation.SdkConstant.SdkConstantType;
import android.annotation.SuppressLint;
-import android.annotation.SystemApi;
-import android.app.PropertyInvalidatedCache;
+import android.annotation.SystemApi; //import android.app.PropertyInvalidatedCache;
import android.bluetooth.annotations.RequiresBluetoothConnectPermission;
import android.bluetooth.annotations.RequiresBluetoothLocationPermission;
import android.bluetooth.annotations.RequiresBluetoothScanPermission;
@@ -1811,71 +1810,42 @@ public final class BluetoothDevice implements Parcelable, Attributable {
return defaultValue;
}
- /**
- * There are several instances of PropertyInvalidatedCache used in this class.
- * BluetoothCache wraps up the common code. All caches are created with a maximum of
- * eight entries, and the key is in the bluetooth module. The name is set to the api.
- */
- private static class BluetoothCache<Q, R> extends PropertyInvalidatedCache<Q, R> {
- BluetoothCache(String api, PropertyInvalidatedCache.QueryHandler query) {
- super(8, PropertyInvalidatedCache.MODULE_BLUETOOTH, api, api, query);
- }};
-
- /**
- * Invalidate a bluetooth cache. This method is just a short-hand wrapper that
- * enforces the bluetooth module.
- */
- private static void invalidateCache(@NonNull String api) {
- PropertyInvalidatedCache.invalidateCache(PropertyInvalidatedCache.MODULE_BLUETOOTH, api);
- }
-
- private final
- PropertyInvalidatedCache.QueryHandler<BluetoothDevice, Integer> mBluetoothBondQuery =
- new PropertyInvalidatedCache.QueryHandler<>() {
- @RequiresLegacyBluetoothPermission
- @RequiresBluetoothConnectPermission
- @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)
+ /*
+ 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
- public Integer apply(BluetoothDevice query) {
- if (DBG) log("getBondState() uncached");
- final IBluetooth service = sService;
- final int defaultValue = BOND_NONE;
- if (service == null) {
- Log.e(TAG, "BT not enabled. Cannot get bond state");
- if (DBG) log(Log.getStackTraceString(new Throwable()));
- } else {
- try {
- final SynchronousResultReceiver<Integer> recv =
- new SynchronousResultReceiver();
- service.getBondState(BluetoothDevice.this, mAttributionSource, recv);
- return recv.awaitResultNoInterrupt(getSyncTimeout())
- .getValue(defaultValue);
- } catch (TimeoutException e) {
- Log.e(TAG, e.toString() + "\n"
- + Log.getStackTraceString(new Throwable()));
- } catch (RemoteException e) {
- Log.e(TAG, "failed to ", e);
- e.rethrowFromSystemServer();
- }
+ @SuppressLint("AndroidFrameworkRequiresPermission")
+ public Integer recompute(BluetoothDevice query) {
+ final int defaultValue = BluetoothDevice.BOND_NONE;
+ try {
+ final SynchronousResultReceiver<Integer> recv =
+ new SynchronousResultReceiver();
+ sService.getBondState(query, mAttributionSource, recv);
+ return recv.awaitResultNoInterrupt(getSyncTimeout()).getValue(defaultValue);
+ } catch (TimeoutException e) {
+ Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable()));
+ } catch (RemoteException e) {
+ throw e.rethrowAsRuntimeException();
}
return defaultValue;
}
};
-
- private static final String GET_BOND_STATE_API = "getBondState";
-
- private final BluetoothCache<BluetoothDevice, Integer> mBluetoothBondCache =
- new BluetoothCache<BluetoothDevice, Integer>(GET_BOND_STATE_API, mBluetoothBondQuery);
+ */
/** @hide */
- public void disableBluetoothGetBondStateCache() {
- mBluetoothBondCache.disableForCurrentProcess();
- }
+ /* public void disableBluetoothGetBondStateCache() {
+ mBluetoothBondCache.disableLocal();
+ } */
/** @hide */
+ /*
public static void invalidateBluetoothGetBondStateCache() {
- invalidateCache(GET_BOND_STATE_API);
+ PropertyInvalidatedCache.invalidateCache(BLUETOOTH_BONDING_CACHE_PROPERTY);
}
+ */
/**
* Get the bond state of the remote device.
@@ -1892,7 +1862,25 @@ public final class BluetoothDevice implements Parcelable, Attributable {
@SuppressLint("AndroidFrameworkRequiresPermission")
public int getBondState() {
if (DBG) log("getBondState()");
- return mBluetoothBondCache.query(null);
+ final IBluetooth service = sService;
+ final int defaultValue = BOND_NONE;
+ if (service == null) {
+ Log.e(TAG, "BT not enabled. Cannot get bond state");
+ if (DBG) log(Log.getStackTraceString(new Throwable()));
+ } else {
+ try {
+ final SynchronousResultReceiver<Integer> recv = new SynchronousResultReceiver();
+ //return mBluetoothBondCache.query(this);
+ service.getBondState(this, mAttributionSource, recv);
+ return recv.awaitResultNoInterrupt(getSyncTimeout()).getValue(defaultValue);
+ } catch (TimeoutException e) {
+ Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable()));
+ } catch (RemoteException e) {
+ Log.e(TAG, "failed to ", e);
+ e.rethrowFromSystemServer();
+ }
+ }
+ return defaultValue;
}
/**