diff options
| author | Lee Shombert <shombert@google.com> | 2020-06-01 15:33:36 -0700 |
|---|---|---|
| committer | Lee Shombert <shombert@google.com> | 2020-06-08 11:25:15 -0700 |
| commit | 3a268eaff222b076857b736fc17f2f373d739110 (patch) | |
| tree | e71271adf83c133c57ca4358feeb5950b817f5e0 /framework/java/android/bluetooth/BluetoothAdapter.java | |
| parent | 82069a89cc00378c1bb70fb4790acdab68c3a072 (diff) | |
Create a binder cache for IBluetooth.getConnectionState
Bug: 157935587
This adds a binder cache for the IBluetooth.getConnectionState() method.
There is no change in bluetooth functionality.
Each atest is run twice. Once with the code to be committed and once
with a special build that sets PropertyInvalidatedCache DEBUG and VERIFY
to true. In the latter case, the test passes if the atest passes and if
there are no errors from the cache verification.
Tag: #feature
Test: atest BluetoothInstrumentationTests
Test results are
Passed: 479, Failed: 0, Ignored: 4, Assumption Failed: 75
Change-Id: I2946297ffab557877dc7ec56206834d7c3776662
Diffstat (limited to 'framework/java/android/bluetooth/BluetoothAdapter.java')
| -rw-r--r-- | framework/java/android/bluetooth/BluetoothAdapter.java | 40 |
1 files changed, 37 insertions, 3 deletions
diff --git a/framework/java/android/bluetooth/BluetoothAdapter.java b/framework/java/android/bluetooth/BluetoothAdapter.java index 29a98faf5c..8c3268c6fc 100644 --- a/framework/java/android/bluetooth/BluetoothAdapter.java +++ b/framework/java/android/bluetooth/BluetoothAdapter.java @@ -2348,6 +2348,36 @@ public final class BluetoothAdapter { return supportedProfiles; } + private static final String BLUETOOTH_GET_ADAPTER_CONNECTION_STATE_CACHE_PROPERTY = + "cache_key.bluetooth.get_adapter_connection_state"; + private final PropertyInvalidatedCache<Void, Integer> + mBluetoothGetAdapterConnectionStateCache = + new PropertyInvalidatedCache<Void, Integer> ( + 8, BLUETOOTH_GET_ADAPTER_CONNECTION_STATE_CACHE_PROPERTY) { + /** + * This method must not be called when mService is null. + */ + @Override + protected Integer recompute(Void query) { + try { + return mService.getAdapterConnectionState(); + } catch (RemoteException e) { + throw e.rethrowAsRuntimeException(); + } + } + }; + + /** @hide */ + public void disableGetAdapterConnectionStateCache() { + mBluetoothGetAdapterConnectionStateCache.disableLocal(); + } + + /** @hide */ + public static void invalidateGetAdapterConnectionStateCache() { + PropertyInvalidatedCache.invalidateCache( + BLUETOOTH_GET_ADAPTER_CONNECTION_STATE_CACHE_PROPERTY); + } + /** * Get the current connection state of the local Bluetooth adapter. * This can be used to check whether the local Bluetooth adapter is connected @@ -2368,10 +2398,14 @@ public final class BluetoothAdapter { try { mServiceLock.readLock().lock(); if (mService != null) { - return mService.getAdapterConnectionState(); + return mBluetoothGetAdapterConnectionStateCache.query(null); + } + } catch (RuntimeException e) { + if (e.getCause() instanceof RemoteException) { + Log.e(TAG, "getConnectionState:", e.getCause()); + } else { + throw e; } - } catch (RemoteException e) { - Log.e(TAG, "getConnectionState:", e); } finally { mServiceLock.readLock().unlock(); } |
