Loading core/api/current.txt +1 −1 Original line number Diff line number Diff line Loading @@ -8633,7 +8633,7 @@ package android.bluetooth { method public android.bluetooth.le.BluetoothLeAdvertiser getBluetoothLeAdvertiser(); method public android.bluetooth.le.BluetoothLeScanner getBluetoothLeScanner(); method @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) public java.util.Set<android.bluetooth.BluetoothDevice> getBondedDevices(); method public static android.bluetooth.BluetoothAdapter getDefaultAdapter(); method @Deprecated public static android.bluetooth.BluetoothAdapter getDefaultAdapter(); method public int getLeMaximumAdvertisingDataLength(); method @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) public String getName(); method @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) public int getProfileConnectionState(int); core/java/android/bluetooth/BluetoothA2dp.java +12 −7 Original line number Diff line number Diff line Loading @@ -23,13 +23,13 @@ import android.annotation.Nullable; import android.annotation.RequiresNoPermission; import android.annotation.RequiresPermission; import android.annotation.SdkConstant; import android.annotation.SuppressLint; import android.annotation.SdkConstant.SdkConstantType; import android.annotation.SystemApi; import android.bluetooth.annotations.RequiresBluetoothConnectPermission; import android.bluetooth.annotations.RequiresLegacyBluetoothAdminPermission; import android.bluetooth.annotations.RequiresLegacyBluetoothPermission; import android.annotation.SystemApi; import android.compat.annotation.UnsupportedAppUsage; import android.content.AttributionSource; import android.content.Context; import android.os.Binder; import android.os.Build; Loading Loading @@ -265,7 +265,8 @@ public final class BluetoothA2dp implements BluetoothProfile { @SystemApi public static final int DYNAMIC_BUFFER_SUPPORT_A2DP_SOFTWARE_ENCODING = 2; private BluetoothAdapter mAdapter; private final BluetoothAdapter mAdapter; private final AttributionSource mAttributionSource; private final BluetoothProfileConnector<IBluetoothA2dp> mProfileConnector = new BluetoothProfileConnector(this, BluetoothProfile.A2DP, "BluetoothA2dp", IBluetoothA2dp.class.getName()) { Loading @@ -279,8 +280,10 @@ public final class BluetoothA2dp implements BluetoothProfile { * Create a BluetoothA2dp proxy object for interacting with the local * Bluetooth A2DP service. */ /*package*/ BluetoothA2dp(Context context, ServiceListener listener) { mAdapter = BluetoothAdapter.getDefaultAdapter(); /* package */ BluetoothA2dp(Context context, ServiceListener listener, BluetoothAdapter adapter) { mAdapter = adapter; mAttributionSource = adapter.getAttributionSource(); mProfileConnector.connect(context, listener); } Loading Loading @@ -386,7 +389,8 @@ public final class BluetoothA2dp implements BluetoothProfile { try { final IBluetoothA2dp service = getService(); if (service != null && isEnabled()) { return service.getConnectedDevices(); return BluetoothDevice.setAttributionSource( service.getConnectedDevices(), mAttributionSource); } if (service == null) Log.w(TAG, "Proxy not attached to service"); return new ArrayList<BluetoothDevice>(); Loading @@ -407,7 +411,8 @@ public final class BluetoothA2dp implements BluetoothProfile { try { final IBluetoothA2dp service = getService(); if (service != null && isEnabled()) { return service.getDevicesMatchingConnectionStates(states); return BluetoothDevice.setAttributionSource( service.getDevicesMatchingConnectionStates(states), mAttributionSource); } if (service == null) Log.w(TAG, "Proxy not attached to service"); return new ArrayList<BluetoothDevice>(); Loading core/java/android/bluetooth/BluetoothA2dpSink.java +11 −5 Original line number Diff line number Diff line Loading @@ -27,6 +27,7 @@ import android.bluetooth.annotations.RequiresBluetoothConnectPermission; import android.bluetooth.annotations.RequiresLegacyBluetoothAdminPermission; import android.bluetooth.annotations.RequiresLegacyBluetoothPermission; import android.compat.annotation.UnsupportedAppUsage; import android.content.AttributionSource; import android.content.Context; import android.os.Binder; import android.os.Build; Loading Loading @@ -78,7 +79,8 @@ public final class BluetoothA2dpSink implements BluetoothProfile { public static final String ACTION_CONNECTION_STATE_CHANGED = "android.bluetooth.a2dp-sink.profile.action.CONNECTION_STATE_CHANGED"; private BluetoothAdapter mAdapter; private final BluetoothAdapter mAdapter; private final AttributionSource mAttributionSource; private final BluetoothProfileConnector<IBluetoothA2dpSink> mProfileConnector = new BluetoothProfileConnector(this, BluetoothProfile.A2DP_SINK, "BluetoothA2dpSink", IBluetoothA2dpSink.class.getName()) { Loading @@ -92,8 +94,10 @@ public final class BluetoothA2dpSink implements BluetoothProfile { * Create a BluetoothA2dp proxy object for interacting with the local * Bluetooth A2DP service. */ /*package*/ BluetoothA2dpSink(Context context, ServiceListener listener) { mAdapter = BluetoothAdapter.getDefaultAdapter(); /* package */ BluetoothA2dpSink(Context context, ServiceListener listener, BluetoothAdapter adapter) { mAdapter = adapter; mAttributionSource = adapter.getAttributionSource(); mProfileConnector.connect(context, listener); } Loading Loading @@ -198,7 +202,8 @@ public final class BluetoothA2dpSink implements BluetoothProfile { final IBluetoothA2dpSink service = getService(); if (service != null && isEnabled()) { try { return service.getConnectedDevices(); return BluetoothDevice.setAttributionSource( service.getConnectedDevices(), mAttributionSource); } catch (RemoteException e) { Log.e(TAG, "Stack:" + Log.getStackTraceString(new Throwable())); return new ArrayList<BluetoothDevice>(); Loading @@ -221,7 +226,8 @@ public final class BluetoothA2dpSink implements BluetoothProfile { final IBluetoothA2dpSink service = getService(); if (service != null && isEnabled()) { try { return service.getDevicesMatchingConnectionStates(states); return BluetoothDevice.setAttributionSource( service.getDevicesMatchingConnectionStates(states), mAttributionSource); } catch (RemoteException e) { Log.e(TAG, "Stack:" + Log.getStackTraceString(new Throwable())); return new ArrayList<BluetoothDevice>(); Loading core/java/android/bluetooth/BluetoothAdapter.java +74 −70 Original line number Diff line number Diff line Loading @@ -706,11 +706,13 @@ public final class BluetoothAdapter { */ private static BluetoothAdapter sAdapter; private static BluetoothLeScanner sBluetoothLeScanner; private static BluetoothLeAdvertiser sBluetoothLeAdvertiser; private static PeriodicAdvertisingManager sPeriodicAdvertisingManager; private BluetoothLeScanner mBluetoothLeScanner; private BluetoothLeAdvertiser mBluetoothLeAdvertiser; private PeriodicAdvertisingManager mPeriodicAdvertisingManager; private final IBluetoothManager mManagerService; private final AttributionSource mAttributionSource; @UnsupportedAppUsage private IBluetooth mService; private final ReentrantReadWriteLock mServiceLock = new ReentrantReadWriteLock(); Loading @@ -722,8 +724,6 @@ public final class BluetoothAdapter { private final Map<BluetoothConnectionCallback, Executor> mBluetoothConnectionCallbackExecutorMap = new HashMap<>(); private AttributionSource mAttributionSource; /** * Bluetooth metadata listener. Overrides the default BluetoothMetadataListener * implementation. Loading Loading @@ -752,27 +752,33 @@ public final class BluetoothAdapter { /** * Get a handle to the default local Bluetooth adapter. * <p>Currently Android only supports one Bluetooth adapter, but the API * could be extended to support more. This will always return the default * adapter. * <p> * Currently Android only supports one Bluetooth adapter, but the API could * be extended to support more. This will always return the default adapter. * </p> * * @return the default local adapter, or null if Bluetooth is not supported on this hardware * platform * @return the default local adapter, or null if Bluetooth is not supported * on this hardware platform * @deprecated this method will continue to work, but developers are * strongly encouraged to migrate to using * {@link BluetoothManager#getAdapter()}, since that approach * enables support for {@link Context#createAttributionContext}. */ @Deprecated @RequiresNoPermission public static synchronized BluetoothAdapter getDefaultAdapter() { if (sAdapter == null) { sAdapter = createAdapter(); sAdapter = createAdapter(BluetoothManager.resolveAttributionSource(null)); } return sAdapter; } /** {@hide} */ public static BluetoothAdapter createAdapter() { public static BluetoothAdapter createAdapter(AttributionSource attributionSource) { IBinder binder = ServiceManager.getService(BLUETOOTH_MANAGER_SERVICE); if (binder != null) { return new BluetoothAdapter(IBluetoothManager.Stub.asInterface(binder)); return new BluetoothAdapter(IBluetoothManager.Stub.asInterface(binder), attributionSource); } else { Log.e(TAG, "Bluetooth binder is null"); return null; Loading @@ -782,7 +788,7 @@ public final class BluetoothAdapter { /** * Use {@link #getDefaultAdapter} to get the BluetoothAdapter instance. */ BluetoothAdapter(IBluetoothManager managerService) { BluetoothAdapter(IBluetoothManager managerService, AttributionSource attributionSource) { if (managerService == null) { throw new IllegalArgumentException("bluetooth manager service is null"); } Loading @@ -794,20 +800,12 @@ public final class BluetoothAdapter { } finally { mServiceLock.writeLock().unlock(); } mManagerService = managerService; mManagerService = Objects.requireNonNull(managerService); mAttributionSource = Objects.requireNonNull(attributionSource); mLeScanClients = new HashMap<LeScanCallback, ScanCallback>(); mToken = new Binder(); } void setAttributionSource(AttributionSource attributionSource) { mAttributionSource = attributionSource; } private AttributionSource resolveAttributionSource() { return (mAttributionSource != null) ? mAttributionSource : ActivityThread.currentAttributionSource(); } /** * Get a {@link BluetoothDevice} object for the given Bluetooth hardware * address. Loading Loading @@ -864,11 +862,11 @@ public final class BluetoothAdapter { return null; } synchronized (mLock) { if (sBluetoothLeAdvertiser == null) { sBluetoothLeAdvertiser = new BluetoothLeAdvertiser(mManagerService); if (mBluetoothLeAdvertiser == null) { mBluetoothLeAdvertiser = new BluetoothLeAdvertiser(this); } return mBluetoothLeAdvertiser; } return sBluetoothLeAdvertiser; } /** Loading @@ -892,11 +890,11 @@ public final class BluetoothAdapter { } synchronized (mLock) { if (sPeriodicAdvertisingManager == null) { sPeriodicAdvertisingManager = new PeriodicAdvertisingManager(mManagerService); if (mPeriodicAdvertisingManager == null) { mPeriodicAdvertisingManager = new PeriodicAdvertisingManager(this); } return mPeriodicAdvertisingManager; } return sPeriodicAdvertisingManager; } /** Loading @@ -908,12 +906,11 @@ public final class BluetoothAdapter { return null; } synchronized (mLock) { if (sBluetoothLeScanner == null) { sBluetoothLeScanner = new BluetoothLeScanner(mManagerService, resolveAttributionSource()); if (mBluetoothLeScanner == null) { mBluetoothLeScanner = new BluetoothLeScanner(this); } return mBluetoothLeScanner; } return sBluetoothLeScanner; } /** Loading Loading @@ -1349,7 +1346,7 @@ public final class BluetoothAdapter { try { mServiceLock.readLock().lock(); if (mService != null) { return mService.getUuids(resolveAttributionSource()); return mService.getUuids(mAttributionSource); } } catch (RemoteException e) { Log.e(TAG, "", e); Loading Loading @@ -1383,7 +1380,7 @@ public final class BluetoothAdapter { try { mServiceLock.readLock().lock(); if (mService != null) { return mService.setName(name, resolveAttributionSource()); return mService.setName(name, mAttributionSource); } } catch (RemoteException e) { Log.e(TAG, "", e); Loading Loading @@ -1411,7 +1408,7 @@ public final class BluetoothAdapter { try { mServiceLock.readLock().lock(); if (mService != null) { return mService.getBluetoothClass(resolveAttributionSource()); return mService.getBluetoothClass(mAttributionSource); } } catch (RemoteException e) { Log.e(TAG, "", e); Loading Loading @@ -1467,7 +1464,7 @@ public final class BluetoothAdapter { if (getState() != STATE_ON) return BluetoothAdapter.IO_CAPABILITY_UNKNOWN; try { mServiceLock.readLock().lock(); if (mService != null) return mService.getIoCapability(resolveAttributionSource()); if (mService != null) return mService.getIoCapability(mAttributionSource); } catch (RemoteException e) { Log.e(TAG, e.getMessage(), e); } finally { Loading Loading @@ -1520,7 +1517,7 @@ public final class BluetoothAdapter { if (getState() != STATE_ON) return BluetoothAdapter.IO_CAPABILITY_UNKNOWN; try { mServiceLock.readLock().lock(); if (mService != null) return mService.getLeIoCapability(resolveAttributionSource()); if (mService != null) return mService.getLeIoCapability(mAttributionSource); } catch (RemoteException e) { Log.e(TAG, e.getMessage(), e); } finally { Loading Loading @@ -1582,7 +1579,7 @@ public final class BluetoothAdapter { try { mServiceLock.readLock().lock(); if (mService != null) { return mService.getScanMode(resolveAttributionSource()); return mService.getScanMode(mAttributionSource); } } catch (RemoteException e) { Log.e(TAG, "", e); Loading Loading @@ -1631,7 +1628,7 @@ public final class BluetoothAdapter { mServiceLock.readLock().lock(); if (mService != null) { int durationSeconds = Math.toIntExact(durationMillis / 1000); return mService.setScanMode(mode, durationSeconds, resolveAttributionSource()); return mService.setScanMode(mode, durationSeconds, mAttributionSource); } } catch (RemoteException e) { Log.e(TAG, "", e); Loading Loading @@ -1681,7 +1678,7 @@ public final class BluetoothAdapter { try { mServiceLock.readLock().lock(); if (mService != null) { return mService.setScanMode(mode, getDiscoverableTimeout(), resolveAttributionSource()); return mService.setScanMode(mode, getDiscoverableTimeout(), mAttributionSource); } } catch (RemoteException e) { Log.e(TAG, "", e); Loading @@ -1702,7 +1699,7 @@ public final class BluetoothAdapter { try { mServiceLock.readLock().lock(); if (mService != null) { return mService.getDiscoverableTimeout(resolveAttributionSource()); return mService.getDiscoverableTimeout(mAttributionSource); } } catch (RemoteException e) { Log.e(TAG, "", e); Loading @@ -1723,7 +1720,7 @@ public final class BluetoothAdapter { try { mServiceLock.readLock().lock(); if (mService != null) { mService.setDiscoverableTimeout(timeout, resolveAttributionSource()); mService.setDiscoverableTimeout(timeout, mAttributionSource); } } catch (RemoteException e) { Log.e(TAG, "", e); Loading Loading @@ -1796,7 +1793,7 @@ public final class BluetoothAdapter { try { mServiceLock.readLock().lock(); if (mService != null) { return mService.startDiscovery(resolveAttributionSource()); return mService.startDiscovery(mAttributionSource); } } catch (RemoteException e) { Log.e(TAG, "", e); Loading Loading @@ -1832,7 +1829,7 @@ public final class BluetoothAdapter { try { mServiceLock.readLock().lock(); if (mService != null) { return mService.cancelDiscovery(resolveAttributionSource()); return mService.cancelDiscovery(mAttributionSource); } } catch (RemoteException e) { Log.e(TAG, "", e); Loading Loading @@ -1870,7 +1867,7 @@ public final class BluetoothAdapter { try { mServiceLock.readLock().lock(); if (mService != null) { return mService.isDiscovering(resolveAttributionSource()); return mService.isDiscovering(mAttributionSource); } } catch (RemoteException e) { Log.e(TAG, "", e); Loading Loading @@ -2307,7 +2304,7 @@ public final class BluetoothAdapter { try { mServiceLock.readLock().lock(); if (mService != null) { return mService.getMaxConnectedAudioDevices(resolveAttributionSource()); return mService.getMaxConnectedAudioDevices(mAttributionSource); } } catch (RemoteException e) { Log.e(TAG, "failed to get getMaxConnectedAudioDevices, error: ", e); Loading Loading @@ -2335,7 +2332,7 @@ public final class BluetoothAdapter { // BLE is not supported return false; } return (iGatt.numHwTrackFiltersAvailable() != 0); return (iGatt.numHwTrackFiltersAvailable(mAttributionSource) != 0); } catch (RemoteException e) { Log.e(TAG, "", e); } Loading Loading @@ -2419,7 +2416,7 @@ public final class BluetoothAdapter { try { mServiceLock.readLock().lock(); if (mService != null) { return mService.getMostRecentlyConnectedDevices(resolveAttributionSource()); return mService.getMostRecentlyConnectedDevices(mAttributionSource); } } catch (RemoteException e) { Log.e(TAG, "", e); Loading Loading @@ -2449,7 +2446,7 @@ public final class BluetoothAdapter { try { mServiceLock.readLock().lock(); if (mService != null) { return toDeviceSet(mService.getBondedDevices(resolveAttributionSource())); return toDeviceSet(mService.getBondedDevices(mAttributionSource)); } return toDeviceSet(new BluetoothDevice[0]); } catch (RemoteException e) { Loading Loading @@ -2974,50 +2971,51 @@ public final class BluetoothAdapter { } if (profile == BluetoothProfile.HEADSET) { BluetoothHeadset headset = new BluetoothHeadset(context, listener); BluetoothHeadset headset = new BluetoothHeadset(context, listener, this); return true; } else if (profile == BluetoothProfile.A2DP) { BluetoothA2dp a2dp = new BluetoothA2dp(context, listener); BluetoothA2dp a2dp = new BluetoothA2dp(context, listener, this); return true; } else if (profile == BluetoothProfile.A2DP_SINK) { BluetoothA2dpSink a2dpSink = new BluetoothA2dpSink(context, listener); BluetoothA2dpSink a2dpSink = new BluetoothA2dpSink(context, listener, this); return true; } else if (profile == BluetoothProfile.AVRCP_CONTROLLER) { BluetoothAvrcpController avrcp = new BluetoothAvrcpController(context, listener); BluetoothAvrcpController avrcp = new BluetoothAvrcpController(context, listener, this); return true; } else if (profile == BluetoothProfile.HID_HOST) { BluetoothHidHost iDev = new BluetoothHidHost(context, listener); BluetoothHidHost iDev = new BluetoothHidHost(context, listener, this); return true; } else if (profile == BluetoothProfile.PAN) { BluetoothPan pan = new BluetoothPan(context, listener); BluetoothPan pan = new BluetoothPan(context, listener, this); return true; } else if (profile == BluetoothProfile.PBAP) { BluetoothPbap pbap = new BluetoothPbap(context, listener); BluetoothPbap pbap = new BluetoothPbap(context, listener, this); return true; } else if (profile == BluetoothProfile.HEALTH) { Log.e(TAG, "getProfileProxy(): BluetoothHealth is deprecated"); return false; } else if (profile == BluetoothProfile.MAP) { BluetoothMap map = new BluetoothMap(context, listener); BluetoothMap map = new BluetoothMap(context, listener, this); return true; } else if (profile == BluetoothProfile.HEADSET_CLIENT) { BluetoothHeadsetClient headsetClient = new BluetoothHeadsetClient(context, listener); BluetoothHeadsetClient headsetClient = new BluetoothHeadsetClient(context, listener, this); return true; } else if (profile == BluetoothProfile.SAP) { BluetoothSap sap = new BluetoothSap(context, listener); BluetoothSap sap = new BluetoothSap(context, listener, this); return true; } else if (profile == BluetoothProfile.PBAP_CLIENT) { BluetoothPbapClient pbapClient = new BluetoothPbapClient(context, listener); BluetoothPbapClient pbapClient = new BluetoothPbapClient(context, listener, this); return true; } else if (profile == BluetoothProfile.MAP_CLIENT) { BluetoothMapClient mapClient = new BluetoothMapClient(context, listener); BluetoothMapClient mapClient = new BluetoothMapClient(context, listener, this); return true; } else if (profile == BluetoothProfile.HID_DEVICE) { BluetoothHidDevice hidDevice = new BluetoothHidDevice(context, listener); BluetoothHidDevice hidDevice = new BluetoothHidDevice(context, listener, this); return true; } else if (profile == BluetoothProfile.HEARING_AID) { if (isHearingAidProfileSupported()) { BluetoothHearingAid hearingAid = new BluetoothHearingAid(context, listener); BluetoothHearingAid hearingAid = new BluetoothHearingAid(context, listener, this); return true; } return false; Loading Loading @@ -3171,11 +3169,11 @@ public final class BluetoothAdapter { if (mLeScanClients != null) { mLeScanClients.clear(); } if (sBluetoothLeAdvertiser != null) { sBluetoothLeAdvertiser.cleanup(); if (mBluetoothLeAdvertiser != null) { mBluetoothLeAdvertiser.cleanup(); } if (sBluetoothLeScanner != null) { sBluetoothLeScanner.cleanup(); if (mBluetoothLeScanner != null) { mBluetoothLeScanner.cleanup(); } } finally { mServiceLock.writeLock().unlock(); Loading Loading @@ -3514,11 +3512,17 @@ public final class BluetoothAdapter { && (Integer.parseInt(address.split(":")[5], 16) & 0b11) == 0b11; } /** {@hide} */ @UnsupportedAppUsage /*package*/ IBluetoothManager getBluetoothManager() { public IBluetoothManager getBluetoothManager() { return mManagerService; } /** {@hide} */ public AttributionSource getAttributionSource() { return mAttributionSource; } private final ArrayList<IBluetoothManagerCallback> mProxyServiceStateCallbacks = new ArrayList<IBluetoothManagerCallback>(); Loading core/java/android/bluetooth/BluetoothAvrcpController.java +11 −5 Original line number Diff line number Diff line Loading @@ -22,6 +22,7 @@ import android.annotation.SuppressLint; import android.annotation.SdkConstant.SdkConstantType; import android.bluetooth.annotations.RequiresBluetoothConnectPermission; import android.bluetooth.annotations.RequiresLegacyBluetoothPermission; import android.content.AttributionSource; import android.content.Context; import android.os.Binder; import android.os.IBinder; Loading Loading @@ -86,7 +87,8 @@ public final class BluetoothAvrcpController implements BluetoothProfile { public static final String EXTRA_PLAYER_SETTING = "android.bluetooth.avrcp-controller.profile.extra.PLAYER_SETTING"; private BluetoothAdapter mAdapter; private final BluetoothAdapter mAdapter; private final AttributionSource mAttributionSource; private final BluetoothProfileConnector<IBluetoothAvrcpController> mProfileConnector = new BluetoothProfileConnector(this, BluetoothProfile.AVRCP_CONTROLLER, "BluetoothAvrcpController", IBluetoothAvrcpController.class.getName()) { Loading @@ -101,8 +103,10 @@ public final class BluetoothAvrcpController implements BluetoothProfile { * Create a BluetoothAvrcpController proxy object for interacting with the local * Bluetooth AVRCP service. */ /*package*/ BluetoothAvrcpController(Context context, ServiceListener listener) { mAdapter = BluetoothAdapter.getDefaultAdapter(); /* package */ BluetoothAvrcpController(Context context, ServiceListener listener, BluetoothAdapter adapter) { mAdapter = adapter; mAttributionSource = adapter.getAttributionSource(); mProfileConnector.connect(context, listener); } Loading Loading @@ -131,7 +135,8 @@ public final class BluetoothAvrcpController implements BluetoothProfile { getService(); if (service != null && isEnabled()) { try { return service.getConnectedDevices(); return BluetoothDevice.setAttributionSource( service.getConnectedDevices(), mAttributionSource); } catch (RemoteException e) { Log.e(TAG, "Stack:" + Log.getStackTraceString(new Throwable())); return new ArrayList<BluetoothDevice>(); Loading @@ -153,7 +158,8 @@ public final class BluetoothAvrcpController implements BluetoothProfile { getService(); if (service != null && isEnabled()) { try { return service.getDevicesMatchingConnectionStates(states); return BluetoothDevice.setAttributionSource( service.getDevicesMatchingConnectionStates(states), mAttributionSource); } catch (RemoteException e) { Log.e(TAG, "Stack:" + Log.getStackTraceString(new Throwable())); return new ArrayList<BluetoothDevice>(); Loading Loading
core/api/current.txt +1 −1 Original line number Diff line number Diff line Loading @@ -8633,7 +8633,7 @@ package android.bluetooth { method public android.bluetooth.le.BluetoothLeAdvertiser getBluetoothLeAdvertiser(); method public android.bluetooth.le.BluetoothLeScanner getBluetoothLeScanner(); method @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) public java.util.Set<android.bluetooth.BluetoothDevice> getBondedDevices(); method public static android.bluetooth.BluetoothAdapter getDefaultAdapter(); method @Deprecated public static android.bluetooth.BluetoothAdapter getDefaultAdapter(); method public int getLeMaximumAdvertisingDataLength(); method @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) public String getName(); method @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) public int getProfileConnectionState(int);
core/java/android/bluetooth/BluetoothA2dp.java +12 −7 Original line number Diff line number Diff line Loading @@ -23,13 +23,13 @@ import android.annotation.Nullable; import android.annotation.RequiresNoPermission; import android.annotation.RequiresPermission; import android.annotation.SdkConstant; import android.annotation.SuppressLint; import android.annotation.SdkConstant.SdkConstantType; import android.annotation.SystemApi; import android.bluetooth.annotations.RequiresBluetoothConnectPermission; import android.bluetooth.annotations.RequiresLegacyBluetoothAdminPermission; import android.bluetooth.annotations.RequiresLegacyBluetoothPermission; import android.annotation.SystemApi; import android.compat.annotation.UnsupportedAppUsage; import android.content.AttributionSource; import android.content.Context; import android.os.Binder; import android.os.Build; Loading Loading @@ -265,7 +265,8 @@ public final class BluetoothA2dp implements BluetoothProfile { @SystemApi public static final int DYNAMIC_BUFFER_SUPPORT_A2DP_SOFTWARE_ENCODING = 2; private BluetoothAdapter mAdapter; private final BluetoothAdapter mAdapter; private final AttributionSource mAttributionSource; private final BluetoothProfileConnector<IBluetoothA2dp> mProfileConnector = new BluetoothProfileConnector(this, BluetoothProfile.A2DP, "BluetoothA2dp", IBluetoothA2dp.class.getName()) { Loading @@ -279,8 +280,10 @@ public final class BluetoothA2dp implements BluetoothProfile { * Create a BluetoothA2dp proxy object for interacting with the local * Bluetooth A2DP service. */ /*package*/ BluetoothA2dp(Context context, ServiceListener listener) { mAdapter = BluetoothAdapter.getDefaultAdapter(); /* package */ BluetoothA2dp(Context context, ServiceListener listener, BluetoothAdapter adapter) { mAdapter = adapter; mAttributionSource = adapter.getAttributionSource(); mProfileConnector.connect(context, listener); } Loading Loading @@ -386,7 +389,8 @@ public final class BluetoothA2dp implements BluetoothProfile { try { final IBluetoothA2dp service = getService(); if (service != null && isEnabled()) { return service.getConnectedDevices(); return BluetoothDevice.setAttributionSource( service.getConnectedDevices(), mAttributionSource); } if (service == null) Log.w(TAG, "Proxy not attached to service"); return new ArrayList<BluetoothDevice>(); Loading @@ -407,7 +411,8 @@ public final class BluetoothA2dp implements BluetoothProfile { try { final IBluetoothA2dp service = getService(); if (service != null && isEnabled()) { return service.getDevicesMatchingConnectionStates(states); return BluetoothDevice.setAttributionSource( service.getDevicesMatchingConnectionStates(states), mAttributionSource); } if (service == null) Log.w(TAG, "Proxy not attached to service"); return new ArrayList<BluetoothDevice>(); Loading
core/java/android/bluetooth/BluetoothA2dpSink.java +11 −5 Original line number Diff line number Diff line Loading @@ -27,6 +27,7 @@ import android.bluetooth.annotations.RequiresBluetoothConnectPermission; import android.bluetooth.annotations.RequiresLegacyBluetoothAdminPermission; import android.bluetooth.annotations.RequiresLegacyBluetoothPermission; import android.compat.annotation.UnsupportedAppUsage; import android.content.AttributionSource; import android.content.Context; import android.os.Binder; import android.os.Build; Loading Loading @@ -78,7 +79,8 @@ public final class BluetoothA2dpSink implements BluetoothProfile { public static final String ACTION_CONNECTION_STATE_CHANGED = "android.bluetooth.a2dp-sink.profile.action.CONNECTION_STATE_CHANGED"; private BluetoothAdapter mAdapter; private final BluetoothAdapter mAdapter; private final AttributionSource mAttributionSource; private final BluetoothProfileConnector<IBluetoothA2dpSink> mProfileConnector = new BluetoothProfileConnector(this, BluetoothProfile.A2DP_SINK, "BluetoothA2dpSink", IBluetoothA2dpSink.class.getName()) { Loading @@ -92,8 +94,10 @@ public final class BluetoothA2dpSink implements BluetoothProfile { * Create a BluetoothA2dp proxy object for interacting with the local * Bluetooth A2DP service. */ /*package*/ BluetoothA2dpSink(Context context, ServiceListener listener) { mAdapter = BluetoothAdapter.getDefaultAdapter(); /* package */ BluetoothA2dpSink(Context context, ServiceListener listener, BluetoothAdapter adapter) { mAdapter = adapter; mAttributionSource = adapter.getAttributionSource(); mProfileConnector.connect(context, listener); } Loading Loading @@ -198,7 +202,8 @@ public final class BluetoothA2dpSink implements BluetoothProfile { final IBluetoothA2dpSink service = getService(); if (service != null && isEnabled()) { try { return service.getConnectedDevices(); return BluetoothDevice.setAttributionSource( service.getConnectedDevices(), mAttributionSource); } catch (RemoteException e) { Log.e(TAG, "Stack:" + Log.getStackTraceString(new Throwable())); return new ArrayList<BluetoothDevice>(); Loading @@ -221,7 +226,8 @@ public final class BluetoothA2dpSink implements BluetoothProfile { final IBluetoothA2dpSink service = getService(); if (service != null && isEnabled()) { try { return service.getDevicesMatchingConnectionStates(states); return BluetoothDevice.setAttributionSource( service.getDevicesMatchingConnectionStates(states), mAttributionSource); } catch (RemoteException e) { Log.e(TAG, "Stack:" + Log.getStackTraceString(new Throwable())); return new ArrayList<BluetoothDevice>(); Loading
core/java/android/bluetooth/BluetoothAdapter.java +74 −70 Original line number Diff line number Diff line Loading @@ -706,11 +706,13 @@ public final class BluetoothAdapter { */ private static BluetoothAdapter sAdapter; private static BluetoothLeScanner sBluetoothLeScanner; private static BluetoothLeAdvertiser sBluetoothLeAdvertiser; private static PeriodicAdvertisingManager sPeriodicAdvertisingManager; private BluetoothLeScanner mBluetoothLeScanner; private BluetoothLeAdvertiser mBluetoothLeAdvertiser; private PeriodicAdvertisingManager mPeriodicAdvertisingManager; private final IBluetoothManager mManagerService; private final AttributionSource mAttributionSource; @UnsupportedAppUsage private IBluetooth mService; private final ReentrantReadWriteLock mServiceLock = new ReentrantReadWriteLock(); Loading @@ -722,8 +724,6 @@ public final class BluetoothAdapter { private final Map<BluetoothConnectionCallback, Executor> mBluetoothConnectionCallbackExecutorMap = new HashMap<>(); private AttributionSource mAttributionSource; /** * Bluetooth metadata listener. Overrides the default BluetoothMetadataListener * implementation. Loading Loading @@ -752,27 +752,33 @@ public final class BluetoothAdapter { /** * Get a handle to the default local Bluetooth adapter. * <p>Currently Android only supports one Bluetooth adapter, but the API * could be extended to support more. This will always return the default * adapter. * <p> * Currently Android only supports one Bluetooth adapter, but the API could * be extended to support more. This will always return the default adapter. * </p> * * @return the default local adapter, or null if Bluetooth is not supported on this hardware * platform * @return the default local adapter, or null if Bluetooth is not supported * on this hardware platform * @deprecated this method will continue to work, but developers are * strongly encouraged to migrate to using * {@link BluetoothManager#getAdapter()}, since that approach * enables support for {@link Context#createAttributionContext}. */ @Deprecated @RequiresNoPermission public static synchronized BluetoothAdapter getDefaultAdapter() { if (sAdapter == null) { sAdapter = createAdapter(); sAdapter = createAdapter(BluetoothManager.resolveAttributionSource(null)); } return sAdapter; } /** {@hide} */ public static BluetoothAdapter createAdapter() { public static BluetoothAdapter createAdapter(AttributionSource attributionSource) { IBinder binder = ServiceManager.getService(BLUETOOTH_MANAGER_SERVICE); if (binder != null) { return new BluetoothAdapter(IBluetoothManager.Stub.asInterface(binder)); return new BluetoothAdapter(IBluetoothManager.Stub.asInterface(binder), attributionSource); } else { Log.e(TAG, "Bluetooth binder is null"); return null; Loading @@ -782,7 +788,7 @@ public final class BluetoothAdapter { /** * Use {@link #getDefaultAdapter} to get the BluetoothAdapter instance. */ BluetoothAdapter(IBluetoothManager managerService) { BluetoothAdapter(IBluetoothManager managerService, AttributionSource attributionSource) { if (managerService == null) { throw new IllegalArgumentException("bluetooth manager service is null"); } Loading @@ -794,20 +800,12 @@ public final class BluetoothAdapter { } finally { mServiceLock.writeLock().unlock(); } mManagerService = managerService; mManagerService = Objects.requireNonNull(managerService); mAttributionSource = Objects.requireNonNull(attributionSource); mLeScanClients = new HashMap<LeScanCallback, ScanCallback>(); mToken = new Binder(); } void setAttributionSource(AttributionSource attributionSource) { mAttributionSource = attributionSource; } private AttributionSource resolveAttributionSource() { return (mAttributionSource != null) ? mAttributionSource : ActivityThread.currentAttributionSource(); } /** * Get a {@link BluetoothDevice} object for the given Bluetooth hardware * address. Loading Loading @@ -864,11 +862,11 @@ public final class BluetoothAdapter { return null; } synchronized (mLock) { if (sBluetoothLeAdvertiser == null) { sBluetoothLeAdvertiser = new BluetoothLeAdvertiser(mManagerService); if (mBluetoothLeAdvertiser == null) { mBluetoothLeAdvertiser = new BluetoothLeAdvertiser(this); } return mBluetoothLeAdvertiser; } return sBluetoothLeAdvertiser; } /** Loading @@ -892,11 +890,11 @@ public final class BluetoothAdapter { } synchronized (mLock) { if (sPeriodicAdvertisingManager == null) { sPeriodicAdvertisingManager = new PeriodicAdvertisingManager(mManagerService); if (mPeriodicAdvertisingManager == null) { mPeriodicAdvertisingManager = new PeriodicAdvertisingManager(this); } return mPeriodicAdvertisingManager; } return sPeriodicAdvertisingManager; } /** Loading @@ -908,12 +906,11 @@ public final class BluetoothAdapter { return null; } synchronized (mLock) { if (sBluetoothLeScanner == null) { sBluetoothLeScanner = new BluetoothLeScanner(mManagerService, resolveAttributionSource()); if (mBluetoothLeScanner == null) { mBluetoothLeScanner = new BluetoothLeScanner(this); } return mBluetoothLeScanner; } return sBluetoothLeScanner; } /** Loading Loading @@ -1349,7 +1346,7 @@ public final class BluetoothAdapter { try { mServiceLock.readLock().lock(); if (mService != null) { return mService.getUuids(resolveAttributionSource()); return mService.getUuids(mAttributionSource); } } catch (RemoteException e) { Log.e(TAG, "", e); Loading Loading @@ -1383,7 +1380,7 @@ public final class BluetoothAdapter { try { mServiceLock.readLock().lock(); if (mService != null) { return mService.setName(name, resolveAttributionSource()); return mService.setName(name, mAttributionSource); } } catch (RemoteException e) { Log.e(TAG, "", e); Loading Loading @@ -1411,7 +1408,7 @@ public final class BluetoothAdapter { try { mServiceLock.readLock().lock(); if (mService != null) { return mService.getBluetoothClass(resolveAttributionSource()); return mService.getBluetoothClass(mAttributionSource); } } catch (RemoteException e) { Log.e(TAG, "", e); Loading Loading @@ -1467,7 +1464,7 @@ public final class BluetoothAdapter { if (getState() != STATE_ON) return BluetoothAdapter.IO_CAPABILITY_UNKNOWN; try { mServiceLock.readLock().lock(); if (mService != null) return mService.getIoCapability(resolveAttributionSource()); if (mService != null) return mService.getIoCapability(mAttributionSource); } catch (RemoteException e) { Log.e(TAG, e.getMessage(), e); } finally { Loading Loading @@ -1520,7 +1517,7 @@ public final class BluetoothAdapter { if (getState() != STATE_ON) return BluetoothAdapter.IO_CAPABILITY_UNKNOWN; try { mServiceLock.readLock().lock(); if (mService != null) return mService.getLeIoCapability(resolveAttributionSource()); if (mService != null) return mService.getLeIoCapability(mAttributionSource); } catch (RemoteException e) { Log.e(TAG, e.getMessage(), e); } finally { Loading Loading @@ -1582,7 +1579,7 @@ public final class BluetoothAdapter { try { mServiceLock.readLock().lock(); if (mService != null) { return mService.getScanMode(resolveAttributionSource()); return mService.getScanMode(mAttributionSource); } } catch (RemoteException e) { Log.e(TAG, "", e); Loading Loading @@ -1631,7 +1628,7 @@ public final class BluetoothAdapter { mServiceLock.readLock().lock(); if (mService != null) { int durationSeconds = Math.toIntExact(durationMillis / 1000); return mService.setScanMode(mode, durationSeconds, resolveAttributionSource()); return mService.setScanMode(mode, durationSeconds, mAttributionSource); } } catch (RemoteException e) { Log.e(TAG, "", e); Loading Loading @@ -1681,7 +1678,7 @@ public final class BluetoothAdapter { try { mServiceLock.readLock().lock(); if (mService != null) { return mService.setScanMode(mode, getDiscoverableTimeout(), resolveAttributionSource()); return mService.setScanMode(mode, getDiscoverableTimeout(), mAttributionSource); } } catch (RemoteException e) { Log.e(TAG, "", e); Loading @@ -1702,7 +1699,7 @@ public final class BluetoothAdapter { try { mServiceLock.readLock().lock(); if (mService != null) { return mService.getDiscoverableTimeout(resolveAttributionSource()); return mService.getDiscoverableTimeout(mAttributionSource); } } catch (RemoteException e) { Log.e(TAG, "", e); Loading @@ -1723,7 +1720,7 @@ public final class BluetoothAdapter { try { mServiceLock.readLock().lock(); if (mService != null) { mService.setDiscoverableTimeout(timeout, resolveAttributionSource()); mService.setDiscoverableTimeout(timeout, mAttributionSource); } } catch (RemoteException e) { Log.e(TAG, "", e); Loading Loading @@ -1796,7 +1793,7 @@ public final class BluetoothAdapter { try { mServiceLock.readLock().lock(); if (mService != null) { return mService.startDiscovery(resolveAttributionSource()); return mService.startDiscovery(mAttributionSource); } } catch (RemoteException e) { Log.e(TAG, "", e); Loading Loading @@ -1832,7 +1829,7 @@ public final class BluetoothAdapter { try { mServiceLock.readLock().lock(); if (mService != null) { return mService.cancelDiscovery(resolveAttributionSource()); return mService.cancelDiscovery(mAttributionSource); } } catch (RemoteException e) { Log.e(TAG, "", e); Loading Loading @@ -1870,7 +1867,7 @@ public final class BluetoothAdapter { try { mServiceLock.readLock().lock(); if (mService != null) { return mService.isDiscovering(resolveAttributionSource()); return mService.isDiscovering(mAttributionSource); } } catch (RemoteException e) { Log.e(TAG, "", e); Loading Loading @@ -2307,7 +2304,7 @@ public final class BluetoothAdapter { try { mServiceLock.readLock().lock(); if (mService != null) { return mService.getMaxConnectedAudioDevices(resolveAttributionSource()); return mService.getMaxConnectedAudioDevices(mAttributionSource); } } catch (RemoteException e) { Log.e(TAG, "failed to get getMaxConnectedAudioDevices, error: ", e); Loading Loading @@ -2335,7 +2332,7 @@ public final class BluetoothAdapter { // BLE is not supported return false; } return (iGatt.numHwTrackFiltersAvailable() != 0); return (iGatt.numHwTrackFiltersAvailable(mAttributionSource) != 0); } catch (RemoteException e) { Log.e(TAG, "", e); } Loading Loading @@ -2419,7 +2416,7 @@ public final class BluetoothAdapter { try { mServiceLock.readLock().lock(); if (mService != null) { return mService.getMostRecentlyConnectedDevices(resolveAttributionSource()); return mService.getMostRecentlyConnectedDevices(mAttributionSource); } } catch (RemoteException e) { Log.e(TAG, "", e); Loading Loading @@ -2449,7 +2446,7 @@ public final class BluetoothAdapter { try { mServiceLock.readLock().lock(); if (mService != null) { return toDeviceSet(mService.getBondedDevices(resolveAttributionSource())); return toDeviceSet(mService.getBondedDevices(mAttributionSource)); } return toDeviceSet(new BluetoothDevice[0]); } catch (RemoteException e) { Loading Loading @@ -2974,50 +2971,51 @@ public final class BluetoothAdapter { } if (profile == BluetoothProfile.HEADSET) { BluetoothHeadset headset = new BluetoothHeadset(context, listener); BluetoothHeadset headset = new BluetoothHeadset(context, listener, this); return true; } else if (profile == BluetoothProfile.A2DP) { BluetoothA2dp a2dp = new BluetoothA2dp(context, listener); BluetoothA2dp a2dp = new BluetoothA2dp(context, listener, this); return true; } else if (profile == BluetoothProfile.A2DP_SINK) { BluetoothA2dpSink a2dpSink = new BluetoothA2dpSink(context, listener); BluetoothA2dpSink a2dpSink = new BluetoothA2dpSink(context, listener, this); return true; } else if (profile == BluetoothProfile.AVRCP_CONTROLLER) { BluetoothAvrcpController avrcp = new BluetoothAvrcpController(context, listener); BluetoothAvrcpController avrcp = new BluetoothAvrcpController(context, listener, this); return true; } else if (profile == BluetoothProfile.HID_HOST) { BluetoothHidHost iDev = new BluetoothHidHost(context, listener); BluetoothHidHost iDev = new BluetoothHidHost(context, listener, this); return true; } else if (profile == BluetoothProfile.PAN) { BluetoothPan pan = new BluetoothPan(context, listener); BluetoothPan pan = new BluetoothPan(context, listener, this); return true; } else if (profile == BluetoothProfile.PBAP) { BluetoothPbap pbap = new BluetoothPbap(context, listener); BluetoothPbap pbap = new BluetoothPbap(context, listener, this); return true; } else if (profile == BluetoothProfile.HEALTH) { Log.e(TAG, "getProfileProxy(): BluetoothHealth is deprecated"); return false; } else if (profile == BluetoothProfile.MAP) { BluetoothMap map = new BluetoothMap(context, listener); BluetoothMap map = new BluetoothMap(context, listener, this); return true; } else if (profile == BluetoothProfile.HEADSET_CLIENT) { BluetoothHeadsetClient headsetClient = new BluetoothHeadsetClient(context, listener); BluetoothHeadsetClient headsetClient = new BluetoothHeadsetClient(context, listener, this); return true; } else if (profile == BluetoothProfile.SAP) { BluetoothSap sap = new BluetoothSap(context, listener); BluetoothSap sap = new BluetoothSap(context, listener, this); return true; } else if (profile == BluetoothProfile.PBAP_CLIENT) { BluetoothPbapClient pbapClient = new BluetoothPbapClient(context, listener); BluetoothPbapClient pbapClient = new BluetoothPbapClient(context, listener, this); return true; } else if (profile == BluetoothProfile.MAP_CLIENT) { BluetoothMapClient mapClient = new BluetoothMapClient(context, listener); BluetoothMapClient mapClient = new BluetoothMapClient(context, listener, this); return true; } else if (profile == BluetoothProfile.HID_DEVICE) { BluetoothHidDevice hidDevice = new BluetoothHidDevice(context, listener); BluetoothHidDevice hidDevice = new BluetoothHidDevice(context, listener, this); return true; } else if (profile == BluetoothProfile.HEARING_AID) { if (isHearingAidProfileSupported()) { BluetoothHearingAid hearingAid = new BluetoothHearingAid(context, listener); BluetoothHearingAid hearingAid = new BluetoothHearingAid(context, listener, this); return true; } return false; Loading Loading @@ -3171,11 +3169,11 @@ public final class BluetoothAdapter { if (mLeScanClients != null) { mLeScanClients.clear(); } if (sBluetoothLeAdvertiser != null) { sBluetoothLeAdvertiser.cleanup(); if (mBluetoothLeAdvertiser != null) { mBluetoothLeAdvertiser.cleanup(); } if (sBluetoothLeScanner != null) { sBluetoothLeScanner.cleanup(); if (mBluetoothLeScanner != null) { mBluetoothLeScanner.cleanup(); } } finally { mServiceLock.writeLock().unlock(); Loading Loading @@ -3514,11 +3512,17 @@ public final class BluetoothAdapter { && (Integer.parseInt(address.split(":")[5], 16) & 0b11) == 0b11; } /** {@hide} */ @UnsupportedAppUsage /*package*/ IBluetoothManager getBluetoothManager() { public IBluetoothManager getBluetoothManager() { return mManagerService; } /** {@hide} */ public AttributionSource getAttributionSource() { return mAttributionSource; } private final ArrayList<IBluetoothManagerCallback> mProxyServiceStateCallbacks = new ArrayList<IBluetoothManagerCallback>(); Loading
core/java/android/bluetooth/BluetoothAvrcpController.java +11 −5 Original line number Diff line number Diff line Loading @@ -22,6 +22,7 @@ import android.annotation.SuppressLint; import android.annotation.SdkConstant.SdkConstantType; import android.bluetooth.annotations.RequiresBluetoothConnectPermission; import android.bluetooth.annotations.RequiresLegacyBluetoothPermission; import android.content.AttributionSource; import android.content.Context; import android.os.Binder; import android.os.IBinder; Loading Loading @@ -86,7 +87,8 @@ public final class BluetoothAvrcpController implements BluetoothProfile { public static final String EXTRA_PLAYER_SETTING = "android.bluetooth.avrcp-controller.profile.extra.PLAYER_SETTING"; private BluetoothAdapter mAdapter; private final BluetoothAdapter mAdapter; private final AttributionSource mAttributionSource; private final BluetoothProfileConnector<IBluetoothAvrcpController> mProfileConnector = new BluetoothProfileConnector(this, BluetoothProfile.AVRCP_CONTROLLER, "BluetoothAvrcpController", IBluetoothAvrcpController.class.getName()) { Loading @@ -101,8 +103,10 @@ public final class BluetoothAvrcpController implements BluetoothProfile { * Create a BluetoothAvrcpController proxy object for interacting with the local * Bluetooth AVRCP service. */ /*package*/ BluetoothAvrcpController(Context context, ServiceListener listener) { mAdapter = BluetoothAdapter.getDefaultAdapter(); /* package */ BluetoothAvrcpController(Context context, ServiceListener listener, BluetoothAdapter adapter) { mAdapter = adapter; mAttributionSource = adapter.getAttributionSource(); mProfileConnector.connect(context, listener); } Loading Loading @@ -131,7 +135,8 @@ public final class BluetoothAvrcpController implements BluetoothProfile { getService(); if (service != null && isEnabled()) { try { return service.getConnectedDevices(); return BluetoothDevice.setAttributionSource( service.getConnectedDevices(), mAttributionSource); } catch (RemoteException e) { Log.e(TAG, "Stack:" + Log.getStackTraceString(new Throwable())); return new ArrayList<BluetoothDevice>(); Loading @@ -153,7 +158,8 @@ public final class BluetoothAvrcpController implements BluetoothProfile { getService(); if (service != null && isEnabled()) { try { return service.getDevicesMatchingConnectionStates(states); return BluetoothDevice.setAttributionSource( service.getDevicesMatchingConnectionStates(states), mAttributionSource); } catch (RemoteException e) { Log.e(TAG, "Stack:" + Log.getStackTraceString(new Throwable())); return new ArrayList<BluetoothDevice>(); Loading