Loading android/app/src/com/android/bluetooth/btservice/AdapterProperties.java +9 −10 Original line number Diff line number Diff line Loading @@ -200,7 +200,7 @@ class AdapterProperties { AdapterProperties(AdapterService service) { mService = service; mAdapter = BluetoothAdapter.getDefaultAdapter(); //invalidateBluetoothCaches(); invalidateBluetoothCaches(); } public void init(RemoteDevices remoteDevices) { Loading Loading @@ -242,7 +242,7 @@ class AdapterProperties { filter.addAction(BluetoothPbapClient.ACTION_CONNECTION_STATE_CHANGED); mService.registerReceiver(mReceiver, filter); mReceiverRegistered = true; //invalidateBluetoothCaches(); invalidateBluetoothCaches(); } public void cleanup() { Loading @@ -254,9 +254,9 @@ class AdapterProperties { } mService = null; mBondedDevices.clear(); //invalidateBluetoothCaches(); invalidateBluetoothCaches(); } /* private static void invalidateGetProfileConnectionStateCache() { BluetoothAdapter.invalidateGetProfileConnectionStateCache(); } Loading @@ -275,7 +275,6 @@ class AdapterProperties { invalidateGetConnectionStateCache(); invalidateGetBondStateCache(); } */ @Override public Object clone() throws CloneNotSupportedException { Loading Loading @@ -413,7 +412,7 @@ class AdapterProperties { */ void setConnectionState(int connectionState) { mConnectionState = connectionState; //invalidateGetConnectionStateCache(); invalidateGetConnectionStateCache(); } /** Loading Loading @@ -647,7 +646,7 @@ class AdapterProperties { debugLog("Failed to remove device: " + device); } } //invalidateGetBondStateCache(); invalidateGetBondStateCache(); } catch (Exception ee) { Log.w(TAG, "onBondStateChanged: Exception ", ee); } Loading Loading @@ -876,7 +875,7 @@ class AdapterProperties { if (update) { mProfileConnectionState.put(profile, new Pair<Integer, Integer>(newHashState, numDev)); //invalidateGetProfileConnectionStateCache(); invalidateGetProfileConnectionStateCache(); } } Loading Loading @@ -1028,7 +1027,7 @@ class AdapterProperties { + mIsLeIsochronousBroadcasterSupported + " mIsLePeriodicAdvertisingSyncTransferRecipientSupported = " + mIsLePeriodicAdvertisingSyncTransferRecipientSupported); //invalidateIsOffloadedFilteringSupportedCache(); invalidateIsOffloadedFilteringSupportedCache(); } private void updateDynamicAudioBufferSupport(byte[] val) { Loading Loading @@ -1061,7 +1060,7 @@ class AdapterProperties { // Reset adapter and profile connection states setConnectionState(BluetoothAdapter.STATE_DISCONNECTED); mProfileConnectionState.clear(); //invalidateGetProfileConnectionStateCache(); invalidateGetProfileConnectionStateCache(); mProfilesConnected = 0; mProfilesConnecting = 0; mProfilesDisconnecting = 0; Loading android/app/src/com/android/bluetooth/btservice/AdapterService.java +5 −9 Original line number Diff line number Diff line Loading @@ -539,7 +539,7 @@ public class AdapterService extends Service { setAdapterService(this); //invalidateBluetoothCaches(); invalidateBluetoothCaches(); // First call to getSharedPreferences will result in a file read into // memory cache. Call it here asynchronously to avoid potential ANR Loading Loading @@ -729,11 +729,9 @@ public class AdapterService extends Service { setProfileServiceState(GattService.class, BluetoothAdapter.STATE_OFF); } /* private void invalidateBluetoothGetStateCache() { BluetoothAdapter.invalidateBluetoothGetStateCache(); } */ void updateLeAudioProfileServiceState(boolean isCisCentralSupported) { if (isCisCentralSupported) { Loading @@ -754,7 +752,7 @@ public class AdapterService extends Service { void updateAdapterState(int prevState, int newState) { mAdapterProperties.setState(newState); //invalidateBluetoothGetStateCache(); invalidateBluetoothGetStateCache(); if (mCallbacks != null) { int n = mCallbacks.beginBroadcast(); debugLog("updateAdapterState() - Broadcasting state " + BluetoothAdapter.nameForState( Loading Loading @@ -916,7 +914,7 @@ public class AdapterService extends Service { clearAdapterService(this); mCleaningUp = true; //invalidateBluetoothCaches(); invalidateBluetoothCaches(); unregisterReceiver(mAlarmBroadcastReceiver); Loading Loading @@ -1013,7 +1011,6 @@ public class AdapterService extends Service { } } /* private void invalidateBluetoothCaches() { BluetoothAdapter.invalidateGetProfileConnectionStateCache(); BluetoothAdapter.invalidateIsOffloadedFilteringSupportedCache(); Loading @@ -1021,7 +1018,6 @@ public class AdapterService extends Service { BluetoothAdapter.invalidateBluetoothGetStateCache(); BluetoothAdapter.invalidateGetAdapterConnectionStateCache(); } */ private void setProfileServiceState(Class service, int state) { if (state == BluetoothAdapter.STATE_ON) { Loading Loading @@ -1573,8 +1569,8 @@ public class AdapterService extends Service { AdapterServiceBinder(AdapterService svc) { mService = svc; //mService.invalidateBluetoothGetStateCache(); //BluetoothAdapter.getDefaultAdapter().disableBluetoothGetStateCache(); mService.invalidateBluetoothGetStateCache(); BluetoothAdapter.getDefaultAdapter().disableBluetoothGetStateCache(); } public void cleanup() { Loading framework/java/android/bluetooth/BluetoothAdapter.java +146 −194 Original line number Diff line number Diff line Loading @@ -30,8 +30,9 @@ 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.PendingIntent; import android.app.PropertyInvalidatedCache; import android.bluetooth.BluetoothDevice.AddressType; import android.bluetooth.BluetoothDevice.Transport; import android.bluetooth.BluetoothProfile.ConnectionPolicy; Loading Loading @@ -1123,45 +1124,69 @@ public final class BluetoothAdapter { return false; } /* private static final String BLUETOOTH_GET_STATE_CACHE_PROPERTY = "cache_key.bluetooth.get_state"; /** * 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); }}; private final PropertyInvalidatedCache<Void, Integer> mBluetoothGetStateCache = new PropertyInvalidatedCache<Void, Integer>( 8, BLUETOOTH_GET_STATE_CACHE_PROPERTY) { /** * 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); } /** * The binder cache for getState(). */ private static final String GET_STATE_API = "getState"; private final PropertyInvalidatedCache.QueryHandler<Void, Integer> mBluetoothGetStateQuery = new PropertyInvalidatedCache.QueryHandler<>() { @RequiresLegacyBluetoothPermission @RequiresNoPermission @AdapterState @Override @SuppressLint("AndroidFrameworkRequiresPermission") public Integer recompute(Void query) { public Integer apply(Void query) { int state = BluetoothAdapter.STATE_OFF; mServiceLock.readLock().lock(); try { if (mService != null) { final SynchronousResultReceiver<Integer> recv = new SynchronousResultReceiver(); mService.getState(recv); return recv.awaitResultNoInterrupt(getSyncTimeout()) .getValue(BluetoothAdapter.STATE_OFF); return recv.awaitResultNoInterrupt(getSyncTimeout()).getValue(state); } } catch (TimeoutException e) { Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable())); return BluetoothAdapter.STATE_OFF; } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } Log.e(TAG, "", e); e.rethrowFromSystemServer(); } finally { mServiceLock.readLock().unlock(); } }; */ return state; }}; private final PropertyInvalidatedCache<Void, Integer> mBluetoothGetStateCache = new BluetoothCache<Void, Integer>(GET_STATE_API, mBluetoothGetStateQuery); /** @hide */ /* @RequiresNoPermission public void disableBluetoothGetStateCache() { mBluetoothGetStateCache.disableLocal(); mBluetoothGetStateCache.disableForCurrentProcess(); } */ /** @hide */ /* public static void invalidateBluetoothGetStateCache() { PropertyInvalidatedCache.invalidateCache(BLUETOOTH_GET_STATE_CACHE_PROPERTY); invalidateCache(GET_STATE_API); } */ /** * Fetch the current bluetooth state. If the service is down, return Loading @@ -1169,22 +1194,7 @@ public final class BluetoothAdapter { */ @AdapterState private int getStateInternal() { int state = BluetoothAdapter.STATE_OFF; try { mServiceLock.readLock().lock(); if (mService != null) { //state = mBluetoothGetStateCache.query(null); final SynchronousResultReceiver<Integer> recv = new SynchronousResultReceiver(); //return mBluetoothBondCache.query(this); mService.getState(recv); return recv.awaitResultNoInterrupt(getSyncTimeout()).getValue(state); } } catch (RemoteException | TimeoutException e) { Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable())); } finally { mServiceLock.readLock().unlock(); } return state; return mBluetoothGetStateCache.query(null); } /** Loading Loading @@ -2257,20 +2267,16 @@ public final class BluetoothAdapter { } } /* private static final String BLUETOOTH_FILTERING_CACHE_PROPERTY = "cache_key.bluetooth.is_offloaded_filtering_supported"; private final PropertyInvalidatedCache<Void, Boolean> mBluetoothFilteringCache = new PropertyInvalidatedCache<Void, Boolean>( 8, BLUETOOTH_FILTERING_CACHE_PROPERTY) { private final PropertyInvalidatedCache.QueryHandler<Void, Boolean> mBluetoothFilteringQuery = new PropertyInvalidatedCache.QueryHandler<>() { @RequiresLegacyBluetoothPermission @RequiresNoPermission @Override @SuppressLint("AndroidFrameworkRequiresPermission") public Boolean recompute(Void query) { try { public Boolean apply(Void query) { mServiceLock.readLock().lock(); try { if (mService != null) { final SynchronousResultReceiver<Boolean> recv = new SynchronousResultReceiver(); final SynchronousResultReceiver<Boolean> recv = new SynchronousResultReceiver(); mService.isOffloadedFilteringSupported(recv); return recv.awaitResultNoInterrupt(getSyncTimeout()).getValue(false); } Loading @@ -2280,25 +2286,23 @@ public final class BluetoothAdapter { mServiceLock.readLock().unlock(); } return false; }}; } }; */ private static final String FILTERING_API = "isOffloadedFilteringSupported"; private final PropertyInvalidatedCache<Void, Boolean> mBluetoothFilteringCache = new BluetoothCache<Void, Boolean>(FILTERING_API, mBluetoothFilteringQuery); /** @hide */ /* @RequiresNoPermission public void disableIsOffloadedFilteringSupportedCache() { mBluetoothFilteringCache.disableLocal(); mBluetoothFilteringCache.disableForCurrentProcess(); } */ /** @hide */ /* public static void invalidateIsOffloadedFilteringSupportedCache() { PropertyInvalidatedCache.invalidateCache(BLUETOOTH_FILTERING_CACHE_PROPERTY); invalidateCache(FILTERING_API); } */ /** * Return true if offloaded filters are supported Loading @@ -2311,22 +2315,7 @@ public final class BluetoothAdapter { if (!getLeAccess()) { return false; } //return mBluetoothFilteringCache.query(null); try { mServiceLock.readLock().lock(); if (mService != null) { final SynchronousResultReceiver<Boolean> recv = new SynchronousResultReceiver(); mService.isOffloadedFilteringSupported(recv); return recv.awaitResultNoInterrupt(getSyncTimeout()).getValue(false); } } catch (TimeoutException e) { Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable())); } catch (RemoteException e) { Log.e(TAG, "failed to get isOffloadedFilteringSupported, error: ", e); } finally { mServiceLock.readLock().unlock(); } return false; return mBluetoothFilteringCache.query(null); } /** Loading Loading @@ -2809,47 +2798,46 @@ 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) { private final PropertyInvalidatedCache.QueryHandler<Void, Integer> mBluetoothGetAdapterQuery = new PropertyInvalidatedCache.QueryHandler<>() { @RequiresLegacyBluetoothPermission @RequiresNoPermission @Override @SuppressLint("AndroidFrameworkRequiresPermission") public Integer recompute(Void query) { public Integer apply(Void query) { mServiceLock.readLock().lock(); try { if (mService != null) { final SynchronousResultReceiver<Integer> recv = new SynchronousResultReceiver(); mService.getAdapterConnectionState(recv); return recv.awaitResultNoInterrupt(getSyncTimeout()) .getValue(BluetoothAdapter.STATE_DISCONNECTED); .getValue(STATE_DISCONNECTED); } } catch (TimeoutException e) { Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable())); } catch (RemoteException e) { throw e.rethrowAsRuntimeException(); Log.e(TAG, "failed to getConnectionState, error: ", e); } finally { mServiceLock.readLock().unlock(); } return BluetoothAdapter.STATE_DISCONNECTED; } }; */ }}; private static final String GET_CONNECTION_API = "getAdapterConnectionState"; private final PropertyInvalidatedCache<Void, Integer> mBluetoothGetAdapterConnectionStateCache = new BluetoothCache<Void, Integer>(GET_CONNECTION_API, mBluetoothGetAdapterQuery); /** @hide */ /* @RequiresNoPermission public void disableGetAdapterConnectionStateCache() { mBluetoothGetAdapterConnectionStateCache.disableLocal(); mBluetoothGetAdapterConnectionStateCache.disableForCurrentProcess(); } */ /** @hide */ /* public static void invalidateGetAdapterConnectionStateCache() { PropertyInvalidatedCache.invalidateCache( BLUETOOTH_GET_ADAPTER_CONNECTION_STATE_CACHE_PROPERTY); invalidateCache(GET_CONNECTION_API); } */ /** * Get the current connection state of the local Bluetooth adapter. Loading @@ -2869,72 +2857,51 @@ public final class BluetoothAdapter { if (getState() != STATE_ON) { return BluetoothAdapter.STATE_DISCONNECTED; } try { mServiceLock.readLock().lock(); if (mService != null) { final SynchronousResultReceiver<Integer> recv = new SynchronousResultReceiver(); mService.getAdapterConnectionState(recv); return recv.awaitResultNoInterrupt(getSyncTimeout()).getValue(STATE_DISCONNECTED); } //return mBluetoothGetAdapterConnectionStateCache.query(null); } catch (TimeoutException e) { Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable())); } catch (RemoteException e) { Log.e(TAG, "failed to getConnectionState, error: ", e); } finally { mServiceLock.readLock().unlock(); } return BluetoothAdapter.STATE_DISCONNECTED; return mBluetoothGetAdapterConnectionStateCache.query(null); } /* private static final String BLUETOOTH_PROFILE_CACHE_PROPERTY = "cache_key.bluetooth.get_profile_connection_state"; private final PropertyInvalidatedCache<Integer, Integer> mGetProfileConnectionStateCache = new PropertyInvalidatedCache<Integer, Integer>( 8, BLUETOOTH_PROFILE_CACHE_PROPERTY) { private final PropertyInvalidatedCache.QueryHandler<Integer, Integer> mBluetoothProfileQuery = new PropertyInvalidatedCache.QueryHandler<>() { @RequiresNoPermission @Override @SuppressLint("AndroidFrameworkRequiresPermission") public Integer recompute(Integer query) { public Integer apply(Integer query) { try { mServiceLock.readLock().lock(); if (mService != null) { final SynchronousResultReceiver<Integer> recv = new SynchronousResultReceiver(); final SynchronousResultReceiver<Integer> recv = new SynchronousResultReceiver(); mService.getProfileConnectionState(query, recv); return recv.awaitResultNoInterrupt(getSyncTimeout()) .getValue(BluetoothProfile.STATE_DISCONNECTED); } } catch (RemoteException | TimeoutException e) { } catch (TimeoutException e) { Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable())); } catch (RemoteException e) { Log.e(TAG, "failed to getProfileConnectionState, error: ", e); } finally { mServiceLock.readLock().unlock(); } return BluetoothProfile.STATE_DISCONNECTED; } @Override public String queryToString(Integer query) { return String.format("getProfileConnectionState(profile=\"%d\")", query); } }; */ }}; /** @hide */ /* private static final String PROFILE_API = "getProfileConnectionState"; private final PropertyInvalidatedCache<Integer, Integer> mGetProfileConnectionStateCache = new BluetoothCache<Integer, Integer>(PROFILE_API, mBluetoothProfileQuery); /** * @hide */ @RequiresNoPermission public void disableGetProfileConnectionStateCache() { mGetProfileConnectionStateCache.disableLocal(); mGetProfileConnectionStateCache.disableForCurrentProcess(); } */ /** @hide */ /* /** * @hide */ public static void invalidateGetProfileConnectionStateCache() { PropertyInvalidatedCache.invalidateCache(BLUETOOTH_PROFILE_CACHE_PROPERTY); invalidateCache(PROFILE_API); } */ /** * Get the current connection state of a profile. Loading @@ -2956,22 +2923,7 @@ public final class BluetoothAdapter { if (getState() != STATE_ON) { return BluetoothProfile.STATE_DISCONNECTED; } try { mServiceLock.readLock().lock(); if (mService != null) { final SynchronousResultReceiver<Integer> recv = new SynchronousResultReceiver(); mService.getProfileConnectionState(profile, recv); return recv.awaitResultNoInterrupt(getSyncTimeout()).getValue(STATE_DISCONNECTED); } //return mGetProfileConnectionStateCache.query(new Integer(profile)); } catch (TimeoutException e) { Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable())); } catch (RemoteException e) { Log.e(TAG, "failed to getProfileConnectionState, error: ", e); } finally { mServiceLock.readLock().unlock(); } return BluetoothProfile.STATE_DISCONNECTED; return mGetProfileConnectionStateCache.query(profile); } /** Loading framework/java/android/bluetooth/BluetoothDevice.java +57 −45 File changed.Preview size limit exceeded, changes collapsed. Show changes Loading
android/app/src/com/android/bluetooth/btservice/AdapterProperties.java +9 −10 Original line number Diff line number Diff line Loading @@ -200,7 +200,7 @@ class AdapterProperties { AdapterProperties(AdapterService service) { mService = service; mAdapter = BluetoothAdapter.getDefaultAdapter(); //invalidateBluetoothCaches(); invalidateBluetoothCaches(); } public void init(RemoteDevices remoteDevices) { Loading Loading @@ -242,7 +242,7 @@ class AdapterProperties { filter.addAction(BluetoothPbapClient.ACTION_CONNECTION_STATE_CHANGED); mService.registerReceiver(mReceiver, filter); mReceiverRegistered = true; //invalidateBluetoothCaches(); invalidateBluetoothCaches(); } public void cleanup() { Loading @@ -254,9 +254,9 @@ class AdapterProperties { } mService = null; mBondedDevices.clear(); //invalidateBluetoothCaches(); invalidateBluetoothCaches(); } /* private static void invalidateGetProfileConnectionStateCache() { BluetoothAdapter.invalidateGetProfileConnectionStateCache(); } Loading @@ -275,7 +275,6 @@ class AdapterProperties { invalidateGetConnectionStateCache(); invalidateGetBondStateCache(); } */ @Override public Object clone() throws CloneNotSupportedException { Loading Loading @@ -413,7 +412,7 @@ class AdapterProperties { */ void setConnectionState(int connectionState) { mConnectionState = connectionState; //invalidateGetConnectionStateCache(); invalidateGetConnectionStateCache(); } /** Loading Loading @@ -647,7 +646,7 @@ class AdapterProperties { debugLog("Failed to remove device: " + device); } } //invalidateGetBondStateCache(); invalidateGetBondStateCache(); } catch (Exception ee) { Log.w(TAG, "onBondStateChanged: Exception ", ee); } Loading Loading @@ -876,7 +875,7 @@ class AdapterProperties { if (update) { mProfileConnectionState.put(profile, new Pair<Integer, Integer>(newHashState, numDev)); //invalidateGetProfileConnectionStateCache(); invalidateGetProfileConnectionStateCache(); } } Loading Loading @@ -1028,7 +1027,7 @@ class AdapterProperties { + mIsLeIsochronousBroadcasterSupported + " mIsLePeriodicAdvertisingSyncTransferRecipientSupported = " + mIsLePeriodicAdvertisingSyncTransferRecipientSupported); //invalidateIsOffloadedFilteringSupportedCache(); invalidateIsOffloadedFilteringSupportedCache(); } private void updateDynamicAudioBufferSupport(byte[] val) { Loading Loading @@ -1061,7 +1060,7 @@ class AdapterProperties { // Reset adapter and profile connection states setConnectionState(BluetoothAdapter.STATE_DISCONNECTED); mProfileConnectionState.clear(); //invalidateGetProfileConnectionStateCache(); invalidateGetProfileConnectionStateCache(); mProfilesConnected = 0; mProfilesConnecting = 0; mProfilesDisconnecting = 0; Loading
android/app/src/com/android/bluetooth/btservice/AdapterService.java +5 −9 Original line number Diff line number Diff line Loading @@ -539,7 +539,7 @@ public class AdapterService extends Service { setAdapterService(this); //invalidateBluetoothCaches(); invalidateBluetoothCaches(); // First call to getSharedPreferences will result in a file read into // memory cache. Call it here asynchronously to avoid potential ANR Loading Loading @@ -729,11 +729,9 @@ public class AdapterService extends Service { setProfileServiceState(GattService.class, BluetoothAdapter.STATE_OFF); } /* private void invalidateBluetoothGetStateCache() { BluetoothAdapter.invalidateBluetoothGetStateCache(); } */ void updateLeAudioProfileServiceState(boolean isCisCentralSupported) { if (isCisCentralSupported) { Loading @@ -754,7 +752,7 @@ public class AdapterService extends Service { void updateAdapterState(int prevState, int newState) { mAdapterProperties.setState(newState); //invalidateBluetoothGetStateCache(); invalidateBluetoothGetStateCache(); if (mCallbacks != null) { int n = mCallbacks.beginBroadcast(); debugLog("updateAdapterState() - Broadcasting state " + BluetoothAdapter.nameForState( Loading Loading @@ -916,7 +914,7 @@ public class AdapterService extends Service { clearAdapterService(this); mCleaningUp = true; //invalidateBluetoothCaches(); invalidateBluetoothCaches(); unregisterReceiver(mAlarmBroadcastReceiver); Loading Loading @@ -1013,7 +1011,6 @@ public class AdapterService extends Service { } } /* private void invalidateBluetoothCaches() { BluetoothAdapter.invalidateGetProfileConnectionStateCache(); BluetoothAdapter.invalidateIsOffloadedFilteringSupportedCache(); Loading @@ -1021,7 +1018,6 @@ public class AdapterService extends Service { BluetoothAdapter.invalidateBluetoothGetStateCache(); BluetoothAdapter.invalidateGetAdapterConnectionStateCache(); } */ private void setProfileServiceState(Class service, int state) { if (state == BluetoothAdapter.STATE_ON) { Loading Loading @@ -1573,8 +1569,8 @@ public class AdapterService extends Service { AdapterServiceBinder(AdapterService svc) { mService = svc; //mService.invalidateBluetoothGetStateCache(); //BluetoothAdapter.getDefaultAdapter().disableBluetoothGetStateCache(); mService.invalidateBluetoothGetStateCache(); BluetoothAdapter.getDefaultAdapter().disableBluetoothGetStateCache(); } public void cleanup() { Loading
framework/java/android/bluetooth/BluetoothAdapter.java +146 −194 Original line number Diff line number Diff line Loading @@ -30,8 +30,9 @@ 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.PendingIntent; import android.app.PropertyInvalidatedCache; import android.bluetooth.BluetoothDevice.AddressType; import android.bluetooth.BluetoothDevice.Transport; import android.bluetooth.BluetoothProfile.ConnectionPolicy; Loading Loading @@ -1123,45 +1124,69 @@ public final class BluetoothAdapter { return false; } /* private static final String BLUETOOTH_GET_STATE_CACHE_PROPERTY = "cache_key.bluetooth.get_state"; /** * 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); }}; private final PropertyInvalidatedCache<Void, Integer> mBluetoothGetStateCache = new PropertyInvalidatedCache<Void, Integer>( 8, BLUETOOTH_GET_STATE_CACHE_PROPERTY) { /** * 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); } /** * The binder cache for getState(). */ private static final String GET_STATE_API = "getState"; private final PropertyInvalidatedCache.QueryHandler<Void, Integer> mBluetoothGetStateQuery = new PropertyInvalidatedCache.QueryHandler<>() { @RequiresLegacyBluetoothPermission @RequiresNoPermission @AdapterState @Override @SuppressLint("AndroidFrameworkRequiresPermission") public Integer recompute(Void query) { public Integer apply(Void query) { int state = BluetoothAdapter.STATE_OFF; mServiceLock.readLock().lock(); try { if (mService != null) { final SynchronousResultReceiver<Integer> recv = new SynchronousResultReceiver(); mService.getState(recv); return recv.awaitResultNoInterrupt(getSyncTimeout()) .getValue(BluetoothAdapter.STATE_OFF); return recv.awaitResultNoInterrupt(getSyncTimeout()).getValue(state); } } catch (TimeoutException e) { Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable())); return BluetoothAdapter.STATE_OFF; } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } Log.e(TAG, "", e); e.rethrowFromSystemServer(); } finally { mServiceLock.readLock().unlock(); } }; */ return state; }}; private final PropertyInvalidatedCache<Void, Integer> mBluetoothGetStateCache = new BluetoothCache<Void, Integer>(GET_STATE_API, mBluetoothGetStateQuery); /** @hide */ /* @RequiresNoPermission public void disableBluetoothGetStateCache() { mBluetoothGetStateCache.disableLocal(); mBluetoothGetStateCache.disableForCurrentProcess(); } */ /** @hide */ /* public static void invalidateBluetoothGetStateCache() { PropertyInvalidatedCache.invalidateCache(BLUETOOTH_GET_STATE_CACHE_PROPERTY); invalidateCache(GET_STATE_API); } */ /** * Fetch the current bluetooth state. If the service is down, return Loading @@ -1169,22 +1194,7 @@ public final class BluetoothAdapter { */ @AdapterState private int getStateInternal() { int state = BluetoothAdapter.STATE_OFF; try { mServiceLock.readLock().lock(); if (mService != null) { //state = mBluetoothGetStateCache.query(null); final SynchronousResultReceiver<Integer> recv = new SynchronousResultReceiver(); //return mBluetoothBondCache.query(this); mService.getState(recv); return recv.awaitResultNoInterrupt(getSyncTimeout()).getValue(state); } } catch (RemoteException | TimeoutException e) { Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable())); } finally { mServiceLock.readLock().unlock(); } return state; return mBluetoothGetStateCache.query(null); } /** Loading Loading @@ -2257,20 +2267,16 @@ public final class BluetoothAdapter { } } /* private static final String BLUETOOTH_FILTERING_CACHE_PROPERTY = "cache_key.bluetooth.is_offloaded_filtering_supported"; private final PropertyInvalidatedCache<Void, Boolean> mBluetoothFilteringCache = new PropertyInvalidatedCache<Void, Boolean>( 8, BLUETOOTH_FILTERING_CACHE_PROPERTY) { private final PropertyInvalidatedCache.QueryHandler<Void, Boolean> mBluetoothFilteringQuery = new PropertyInvalidatedCache.QueryHandler<>() { @RequiresLegacyBluetoothPermission @RequiresNoPermission @Override @SuppressLint("AndroidFrameworkRequiresPermission") public Boolean recompute(Void query) { try { public Boolean apply(Void query) { mServiceLock.readLock().lock(); try { if (mService != null) { final SynchronousResultReceiver<Boolean> recv = new SynchronousResultReceiver(); final SynchronousResultReceiver<Boolean> recv = new SynchronousResultReceiver(); mService.isOffloadedFilteringSupported(recv); return recv.awaitResultNoInterrupt(getSyncTimeout()).getValue(false); } Loading @@ -2280,25 +2286,23 @@ public final class BluetoothAdapter { mServiceLock.readLock().unlock(); } return false; }}; } }; */ private static final String FILTERING_API = "isOffloadedFilteringSupported"; private final PropertyInvalidatedCache<Void, Boolean> mBluetoothFilteringCache = new BluetoothCache<Void, Boolean>(FILTERING_API, mBluetoothFilteringQuery); /** @hide */ /* @RequiresNoPermission public void disableIsOffloadedFilteringSupportedCache() { mBluetoothFilteringCache.disableLocal(); mBluetoothFilteringCache.disableForCurrentProcess(); } */ /** @hide */ /* public static void invalidateIsOffloadedFilteringSupportedCache() { PropertyInvalidatedCache.invalidateCache(BLUETOOTH_FILTERING_CACHE_PROPERTY); invalidateCache(FILTERING_API); } */ /** * Return true if offloaded filters are supported Loading @@ -2311,22 +2315,7 @@ public final class BluetoothAdapter { if (!getLeAccess()) { return false; } //return mBluetoothFilteringCache.query(null); try { mServiceLock.readLock().lock(); if (mService != null) { final SynchronousResultReceiver<Boolean> recv = new SynchronousResultReceiver(); mService.isOffloadedFilteringSupported(recv); return recv.awaitResultNoInterrupt(getSyncTimeout()).getValue(false); } } catch (TimeoutException e) { Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable())); } catch (RemoteException e) { Log.e(TAG, "failed to get isOffloadedFilteringSupported, error: ", e); } finally { mServiceLock.readLock().unlock(); } return false; return mBluetoothFilteringCache.query(null); } /** Loading Loading @@ -2809,47 +2798,46 @@ 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) { private final PropertyInvalidatedCache.QueryHandler<Void, Integer> mBluetoothGetAdapterQuery = new PropertyInvalidatedCache.QueryHandler<>() { @RequiresLegacyBluetoothPermission @RequiresNoPermission @Override @SuppressLint("AndroidFrameworkRequiresPermission") public Integer recompute(Void query) { public Integer apply(Void query) { mServiceLock.readLock().lock(); try { if (mService != null) { final SynchronousResultReceiver<Integer> recv = new SynchronousResultReceiver(); mService.getAdapterConnectionState(recv); return recv.awaitResultNoInterrupt(getSyncTimeout()) .getValue(BluetoothAdapter.STATE_DISCONNECTED); .getValue(STATE_DISCONNECTED); } } catch (TimeoutException e) { Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable())); } catch (RemoteException e) { throw e.rethrowAsRuntimeException(); Log.e(TAG, "failed to getConnectionState, error: ", e); } finally { mServiceLock.readLock().unlock(); } return BluetoothAdapter.STATE_DISCONNECTED; } }; */ }}; private static final String GET_CONNECTION_API = "getAdapterConnectionState"; private final PropertyInvalidatedCache<Void, Integer> mBluetoothGetAdapterConnectionStateCache = new BluetoothCache<Void, Integer>(GET_CONNECTION_API, mBluetoothGetAdapterQuery); /** @hide */ /* @RequiresNoPermission public void disableGetAdapterConnectionStateCache() { mBluetoothGetAdapterConnectionStateCache.disableLocal(); mBluetoothGetAdapterConnectionStateCache.disableForCurrentProcess(); } */ /** @hide */ /* public static void invalidateGetAdapterConnectionStateCache() { PropertyInvalidatedCache.invalidateCache( BLUETOOTH_GET_ADAPTER_CONNECTION_STATE_CACHE_PROPERTY); invalidateCache(GET_CONNECTION_API); } */ /** * Get the current connection state of the local Bluetooth adapter. Loading @@ -2869,72 +2857,51 @@ public final class BluetoothAdapter { if (getState() != STATE_ON) { return BluetoothAdapter.STATE_DISCONNECTED; } try { mServiceLock.readLock().lock(); if (mService != null) { final SynchronousResultReceiver<Integer> recv = new SynchronousResultReceiver(); mService.getAdapterConnectionState(recv); return recv.awaitResultNoInterrupt(getSyncTimeout()).getValue(STATE_DISCONNECTED); } //return mBluetoothGetAdapterConnectionStateCache.query(null); } catch (TimeoutException e) { Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable())); } catch (RemoteException e) { Log.e(TAG, "failed to getConnectionState, error: ", e); } finally { mServiceLock.readLock().unlock(); } return BluetoothAdapter.STATE_DISCONNECTED; return mBluetoothGetAdapterConnectionStateCache.query(null); } /* private static final String BLUETOOTH_PROFILE_CACHE_PROPERTY = "cache_key.bluetooth.get_profile_connection_state"; private final PropertyInvalidatedCache<Integer, Integer> mGetProfileConnectionStateCache = new PropertyInvalidatedCache<Integer, Integer>( 8, BLUETOOTH_PROFILE_CACHE_PROPERTY) { private final PropertyInvalidatedCache.QueryHandler<Integer, Integer> mBluetoothProfileQuery = new PropertyInvalidatedCache.QueryHandler<>() { @RequiresNoPermission @Override @SuppressLint("AndroidFrameworkRequiresPermission") public Integer recompute(Integer query) { public Integer apply(Integer query) { try { mServiceLock.readLock().lock(); if (mService != null) { final SynchronousResultReceiver<Integer> recv = new SynchronousResultReceiver(); final SynchronousResultReceiver<Integer> recv = new SynchronousResultReceiver(); mService.getProfileConnectionState(query, recv); return recv.awaitResultNoInterrupt(getSyncTimeout()) .getValue(BluetoothProfile.STATE_DISCONNECTED); } } catch (RemoteException | TimeoutException e) { } catch (TimeoutException e) { Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable())); } catch (RemoteException e) { Log.e(TAG, "failed to getProfileConnectionState, error: ", e); } finally { mServiceLock.readLock().unlock(); } return BluetoothProfile.STATE_DISCONNECTED; } @Override public String queryToString(Integer query) { return String.format("getProfileConnectionState(profile=\"%d\")", query); } }; */ }}; /** @hide */ /* private static final String PROFILE_API = "getProfileConnectionState"; private final PropertyInvalidatedCache<Integer, Integer> mGetProfileConnectionStateCache = new BluetoothCache<Integer, Integer>(PROFILE_API, mBluetoothProfileQuery); /** * @hide */ @RequiresNoPermission public void disableGetProfileConnectionStateCache() { mGetProfileConnectionStateCache.disableLocal(); mGetProfileConnectionStateCache.disableForCurrentProcess(); } */ /** @hide */ /* /** * @hide */ public static void invalidateGetProfileConnectionStateCache() { PropertyInvalidatedCache.invalidateCache(BLUETOOTH_PROFILE_CACHE_PROPERTY); invalidateCache(PROFILE_API); } */ /** * Get the current connection state of a profile. Loading @@ -2956,22 +2923,7 @@ public final class BluetoothAdapter { if (getState() != STATE_ON) { return BluetoothProfile.STATE_DISCONNECTED; } try { mServiceLock.readLock().lock(); if (mService != null) { final SynchronousResultReceiver<Integer> recv = new SynchronousResultReceiver(); mService.getProfileConnectionState(profile, recv); return recv.awaitResultNoInterrupt(getSyncTimeout()).getValue(STATE_DISCONNECTED); } //return mGetProfileConnectionStateCache.query(new Integer(profile)); } catch (TimeoutException e) { Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable())); } catch (RemoteException e) { Log.e(TAG, "failed to getProfileConnectionState, error: ", e); } finally { mServiceLock.readLock().unlock(); } return BluetoothProfile.STATE_DISCONNECTED; return mGetProfileConnectionStateCache.query(profile); } /** Loading
framework/java/android/bluetooth/BluetoothDevice.java +57 −45 File changed.Preview size limit exceeded, changes collapsed. Show changes