Loading framework/java/android/bluetooth/BluetoothAdapter.java +20 −20 Original line number Diff line number Diff line Loading @@ -31,12 +31,12 @@ import android.app.ActivityThread; import android.app.PropertyInvalidatedCache; import android.bluetooth.BluetoothDevice.Transport; import android.bluetooth.BluetoothProfile.ConnectionPolicy; import android.bluetooth.annotations.RequiresLegacyBluetoothAdminPermission; import android.bluetooth.annotations.RequiresBluetoothAdvertisePermission; import android.bluetooth.annotations.RequiresBluetoothConnectPermission; import android.bluetooth.annotations.RequiresBluetoothLocationPermission; import android.bluetooth.annotations.RequiresLegacyBluetoothPermission; import android.bluetooth.annotations.RequiresBluetoothScanPermission; import android.bluetooth.annotations.RequiresLegacyBluetoothAdminPermission; import android.bluetooth.annotations.RequiresLegacyBluetoothPermission; import android.bluetooth.le.BluetoothLeAdvertiser; import android.bluetooth.le.BluetoothLeScanner; import android.bluetooth.le.PeriodicAdvertisingManager; Loading Loading @@ -807,7 +807,7 @@ public final class BluetoothAdapter { */ @RequiresNoPermission public BluetoothDevice getRemoteDevice(String address) { return new BluetoothDevice(address); return new BluetoothDevice(address, getAttributionSource()); } /** Loading @@ -828,7 +828,7 @@ public final class BluetoothAdapter { } return new BluetoothDevice( String.format(Locale.US, "%02X:%02X:%02X:%02X:%02X:%02X", address[0], address[1], address[2], address[3], address[4], address[5])); address[2], address[3], address[4], address[5]), getAttributionSource()); } /** Loading Loading @@ -1330,7 +1330,7 @@ public final class BluetoothAdapter { try { mServiceLock.readLock().lock(); if (mService != null) { return mService.getUuids(); return mService.getUuids(getAttributionSource()); } } catch (RemoteException e) { Log.e(TAG, "", e); Loading Loading @@ -1364,7 +1364,7 @@ public final class BluetoothAdapter { try { mServiceLock.readLock().lock(); if (mService != null) { return mService.setName(name); return mService.setName(name, getAttributionSource()); } } catch (RemoteException e) { Log.e(TAG, "", e); Loading Loading @@ -1392,7 +1392,7 @@ public final class BluetoothAdapter { try { mServiceLock.readLock().lock(); if (mService != null) { return mService.getBluetoothClass(); return mService.getBluetoothClass(getAttributionSource()); } } catch (RemoteException e) { Log.e(TAG, "", e); Loading Loading @@ -1448,7 +1448,7 @@ public final class BluetoothAdapter { if (getState() != STATE_ON) return BluetoothAdapter.IO_CAPABILITY_UNKNOWN; try { mServiceLock.readLock().lock(); if (mService != null) return mService.getIoCapability(); if (mService != null) return mService.getIoCapability(getAttributionSource()); } catch (RemoteException e) { Log.e(TAG, e.getMessage(), e); } finally { Loading Loading @@ -1501,7 +1501,7 @@ public final class BluetoothAdapter { if (getState() != STATE_ON) return BluetoothAdapter.IO_CAPABILITY_UNKNOWN; try { mServiceLock.readLock().lock(); if (mService != null) return mService.getLeIoCapability(); if (mService != null) return mService.getLeIoCapability(getAttributionSource()); } catch (RemoteException e) { Log.e(TAG, e.getMessage(), e); } finally { Loading Loading @@ -1563,7 +1563,7 @@ public final class BluetoothAdapter { try { mServiceLock.readLock().lock(); if (mService != null) { return mService.getScanMode(); return mService.getScanMode(getAttributionSource()); } } catch (RemoteException e) { Log.e(TAG, "", e); Loading Loading @@ -1612,7 +1612,7 @@ public final class BluetoothAdapter { mServiceLock.readLock().lock(); if (mService != null) { int durationSeconds = Math.toIntExact(durationMillis / 1000); return mService.setScanMode(mode, durationSeconds); return mService.setScanMode(mode, durationSeconds, getAttributionSource()); } } catch (RemoteException e) { Log.e(TAG, "", e); Loading Loading @@ -1662,7 +1662,7 @@ public final class BluetoothAdapter { try { mServiceLock.readLock().lock(); if (mService != null) { return mService.setScanMode(mode, getDiscoverableTimeout()); return mService.setScanMode(mode, getDiscoverableTimeout(), getAttributionSource()); } } catch (RemoteException e) { Log.e(TAG, "", e); Loading @@ -1683,7 +1683,7 @@ public final class BluetoothAdapter { try { mServiceLock.readLock().lock(); if (mService != null) { return mService.getDiscoverableTimeout(); return mService.getDiscoverableTimeout(getAttributionSource()); } } catch (RemoteException e) { Log.e(TAG, "", e); Loading @@ -1704,7 +1704,7 @@ public final class BluetoothAdapter { try { mServiceLock.readLock().lock(); if (mService != null) { mService.setDiscoverableTimeout(timeout); mService.setDiscoverableTimeout(timeout, getAttributionSource()); } } catch (RemoteException e) { Log.e(TAG, "", e); Loading Loading @@ -1755,7 +1755,7 @@ public final class BluetoothAdapter { return ActivityThread.currentOpPackageName(); } private AttributionSource getAttributionSource() { AttributionSource getAttributionSource() { if (mContext != null) { return mContext.getAttributionSource(); } Loading Loading @@ -1838,7 +1838,7 @@ public final class BluetoothAdapter { try { mServiceLock.readLock().lock(); if (mService != null) { return mService.cancelDiscovery(); return mService.cancelDiscovery(getAttributionSource()); } } catch (RemoteException e) { Log.e(TAG, "", e); Loading Loading @@ -1876,7 +1876,7 @@ public final class BluetoothAdapter { try { mServiceLock.readLock().lock(); if (mService != null) { return mService.isDiscovering(); return mService.isDiscovering(getAttributionSource()); } } catch (RemoteException e) { Log.e(TAG, "", e); Loading Loading @@ -2313,7 +2313,7 @@ public final class BluetoothAdapter { try { mServiceLock.readLock().lock(); if (mService != null) { return mService.getMaxConnectedAudioDevices(); return mService.getMaxConnectedAudioDevices(getAttributionSource()); } } catch (RemoteException e) { Log.e(TAG, "failed to get getMaxConnectedAudioDevices, error: ", e); Loading Loading @@ -2425,7 +2425,7 @@ public final class BluetoothAdapter { try { mServiceLock.readLock().lock(); if (mService != null) { return mService.getMostRecentlyConnectedDevices(); return mService.getMostRecentlyConnectedDevices(getAttributionSource()); } } catch (RemoteException e) { Log.e(TAG, "", e); Loading Loading @@ -2455,7 +2455,7 @@ public final class BluetoothAdapter { try { mServiceLock.readLock().lock(); if (mService != null) { return toDeviceSet(mService.getBondedDevices()); return toDeviceSet(mService.getBondedDevices(getAttributionSource())); } return toDeviceSet(new BluetoothDevice[0]); } catch (RemoteException e) { Loading framework/java/android/bluetooth/BluetoothDevice.java +39 −25 Original line number Diff line number Diff line Loading @@ -32,6 +32,7 @@ import android.bluetooth.annotations.RequiresLegacyBluetoothAdminPermission; import android.bluetooth.annotations.RequiresLegacyBluetoothPermission; import android.companion.AssociationRequest; import android.compat.annotation.UnsupportedAppUsage; import android.content.AttributionSource; import android.content.Context; import android.os.Build; import android.os.Handler; Loading Loading @@ -1101,6 +1102,8 @@ public final class BluetoothDevice implements Parcelable { */ private static volatile IBluetooth sService; private final AttributionSource mAttributionSource; private final String mAddress; @AddressType private final int mAddressType; Loading Loading @@ -1149,12 +1152,12 @@ public final class BluetoothDevice implements Parcelable { * and is validated in this constructor. * * @param address valid Bluetooth MAC address * @param attributionSource attribution for permission-protected calls * @throws RuntimeException Bluetooth is not available on this platform * @throws IllegalArgumentException address is invalid * @hide */ @UnsupportedAppUsage /*package*/ BluetoothDevice(String address) { public BluetoothDevice(String address, AttributionSource attributionSource) { getService(); // ensures sService is initialized if (!BluetoothAdapter.checkBluetoothAddress(address)) { throw new IllegalArgumentException(address + " is not a valid Bluetooth address"); Loading @@ -1162,6 +1165,12 @@ public final class BluetoothDevice implements Parcelable { mAddress = address; mAddressType = ADDRESS_TYPE_PUBLIC; mAttributionSource = attributionSource; } @UnsupportedAppUsage /*package*/ BluetoothDevice(String address) { this(address, BluetoothAdapter.getDefaultAdapter().getAttributionSource()); } @Override Loading Loading @@ -1199,7 +1208,8 @@ public final class BluetoothDevice implements Parcelable { public static final @android.annotation.NonNull Parcelable.Creator<BluetoothDevice> CREATOR = new Parcelable.Creator<BluetoothDevice>() { public BluetoothDevice createFromParcel(Parcel in) { return new BluetoothDevice(in.readString()); return new BluetoothDevice( in.readString(), in.readParcelable(getClass().getClassLoader())); } public BluetoothDevice[] newArray(int size) { Loading @@ -1210,6 +1220,7 @@ public final class BluetoothDevice implements Parcelable { @Override public void writeToParcel(Parcel out, int flags) { out.writeString(mAddress); out.writeParcelable(mAttributionSource, 0); } /** Loading Loading @@ -1254,7 +1265,7 @@ public final class BluetoothDevice implements Parcelable { return null; } try { String name = service.getRemoteName(this); String name = service.getRemoteName(this, mAttributionSource); if (name != null) { // remove whitespace characters from the name return name Loading Loading @@ -1285,7 +1296,7 @@ public final class BluetoothDevice implements Parcelable { return DEVICE_TYPE_UNKNOWN; } try { return service.getRemoteType(this); return service.getRemoteType(this, mAttributionSource); } catch (RemoteException e) { Log.e(TAG, "", e); } Loading @@ -1309,7 +1320,7 @@ public final class BluetoothDevice implements Parcelable { return null; } try { String alias = service.getRemoteAlias(this); String alias = service.getRemoteAliasWithAttribution(this, mAttributionSource); if (alias == null) { return getName(); } Loading Loading @@ -1351,7 +1362,8 @@ public final class BluetoothDevice implements Parcelable { } try { BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); return service.setRemoteAlias(this, alias, adapter.getOpPackageName()); return service.setRemoteAlias( this, alias, adapter.getOpPackageName(), mAttributionSource); } catch (RemoteException e) { Log.e(TAG, "", e); } Loading @@ -1377,7 +1389,7 @@ public final class BluetoothDevice implements Parcelable { return BATTERY_LEVEL_BLUETOOTH_OFF; } try { return service.getBatteryLevel(this); return service.getBatteryLevel(this, mAttributionSource); } catch (RemoteException e) { Log.e(TAG, "", e); } Loading Loading @@ -1467,8 +1479,8 @@ public final class BluetoothDevice implements Parcelable { return false; } try { return service.createBond(this, transport, remoteP192Data, remoteP256Data, BluetoothAdapter.getDefaultAdapter().getOpPackageName()); return service.createBond( this, transport, remoteP192Data, remoteP256Data, mAttributionSource); } catch (RemoteException e) { Log.e(TAG, "", e); } Loading @@ -1493,7 +1505,7 @@ public final class BluetoothDevice implements Parcelable { return false; } try { return service.isBondingInitiatedLocally(this); return service.isBondingInitiatedLocally(this, mAttributionSource); } catch (RemoteException e) { Log.e(TAG, "", e); } Loading @@ -1518,7 +1530,7 @@ public final class BluetoothDevice implements Parcelable { Log.i(TAG, "cancelBondProcess() for device " + getAddress() + " called by pid: " + Process.myPid() + " tid: " + Process.myTid()); return service.cancelBondProcess(this); return service.cancelBondProcess(this, mAttributionSource); } catch (RemoteException e) { Log.e(TAG, "", e); } Loading Loading @@ -1546,7 +1558,7 @@ public final class BluetoothDevice implements Parcelable { Log.i(TAG, "removeBond() for device " + getAddress() + " called by pid: " + Process.myPid() + " tid: " + Process.myTid()); return service.removeBond(this); return service.removeBond(this, mAttributionSource); } catch (RemoteException e) { Log.e(TAG, "", e); } Loading @@ -1562,7 +1574,7 @@ public final class BluetoothDevice implements Parcelable { @SuppressLint("AndroidFrameworkRequiresPermission") protected Integer recompute(BluetoothDevice query) { try { return sService.getBondState(query); return sService.getBondState(query, mAttributionSource); } catch (RemoteException e) { throw e.rethrowAsRuntimeException(); } Loading Loading @@ -1652,7 +1664,8 @@ public final class BluetoothDevice implements Parcelable { return false; } try { return service.getConnectionState(this) != CONNECTION_STATE_DISCONNECTED; return service.getConnectionStateWithAttribution(this, mAttributionSource) != CONNECTION_STATE_DISCONNECTED; } catch (RemoteException e) { Log.e(TAG, "", e); return false; Loading @@ -1677,7 +1690,8 @@ public final class BluetoothDevice implements Parcelable { return false; } try { return service.getConnectionState(this) > CONNECTION_STATE_CONNECTED; return service.getConnectionStateWithAttribution(this, mAttributionSource) > CONNECTION_STATE_CONNECTED; } catch (RemoteException e) { Log.e(TAG, "", e); return false; Loading @@ -1699,7 +1713,7 @@ public final class BluetoothDevice implements Parcelable { return null; } try { int classInt = service.getRemoteClass(this); int classInt = service.getRemoteClass(this, mAttributionSource); if (classInt == BluetoothClass.ERROR) return null; return new BluetoothClass(classInt); } catch (RemoteException e) { Loading Loading @@ -1728,7 +1742,7 @@ public final class BluetoothDevice implements Parcelable { return null; } try { return service.getRemoteUuids(this); return service.getRemoteUuids(this, mAttributionSource); } catch (RemoteException e) { Log.e(TAG, "", e); } Loading Loading @@ -1758,7 +1772,7 @@ public final class BluetoothDevice implements Parcelable { return false; } try { return service.fetchRemoteUuids(this); return service.fetchRemoteUuidsWithAttribution(this, mAttributionSource); } catch (RemoteException e) { Log.e(TAG, "", e); } Loading Loading @@ -1795,7 +1809,7 @@ public final class BluetoothDevice implements Parcelable { return false; } try { return service.sdpSearch(this, uuid); return service.sdpSearch(this, uuid, mAttributionSource); } catch (RemoteException e) { Log.e(TAG, "", e); } Loading @@ -1817,7 +1831,7 @@ public final class BluetoothDevice implements Parcelable { return false; } try { return service.setPin(this, true, pin.length, pin); return service.setPin(this, true, pin.length, pin, mAttributionSource); } catch (RemoteException e) { Log.e(TAG, "", e); } Loading Loading @@ -1880,7 +1894,7 @@ public final class BluetoothDevice implements Parcelable { return false; } try { return service.cancelBondProcess(this); return service.cancelBondProcess(this, mAttributionSource); } catch (RemoteException e) { Log.e(TAG, "", e); } Loading Loading @@ -1913,7 +1927,7 @@ public final class BluetoothDevice implements Parcelable { return ACCESS_UNKNOWN; } try { return service.getPhonebookAccessPermission(this); return service.getPhonebookAccessPermission(this, mAttributionSource); } catch (RemoteException e) { Log.e(TAG, "", e); } Loading Loading @@ -2019,7 +2033,7 @@ public final class BluetoothDevice implements Parcelable { return ACCESS_UNKNOWN; } try { return service.getMessageAccessPermission(this); return service.getMessageAccessPermission(this, mAttributionSource); } catch (RemoteException e) { Log.e(TAG, "", e); } Loading Loading @@ -2070,7 +2084,7 @@ public final class BluetoothDevice implements Parcelable { return ACCESS_UNKNOWN; } try { return service.getSimAccessPermission(this); return service.getSimAccessPermission(this, mAttributionSource); } catch (RemoteException e) { Log.e(TAG, "", e); } Loading service/java/com/android/server/bluetooth/BluetoothManagerService.java +10 −7 Original line number Diff line number Diff line Loading @@ -347,7 +347,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub { addActiveLog( BluetoothProtoEnums.ENABLE_DISABLE_REASON_FACTORY_RESET, mContext.getPackageName(), false); mBluetooth.disable(); mBluetooth.disable(mContext.getAttributionSource()); return true; } } catch (RemoteException e) { Loading Loading @@ -1714,7 +1714,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub { try { mBluetoothLock.readLock().lock(); if (mBluetooth != null) { return mBluetooth.getAddress(); return mBluetooth.getAddressWithAttribution(mContext.getAttributionSource()); } } catch (RemoteException e) { Slog.e(TAG, Loading Loading @@ -1743,7 +1743,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub { try { mBluetoothLock.readLock().lock(); if (mBluetooth != null) { return mBluetooth.getName(); return mBluetooth.getName(mContext.getAttributionSource()); } } catch (RemoteException e) { Slog.e(TAG, "getName(): Unable to retrieve name remotely. Returning cached name", e); Loading Loading @@ -1830,7 +1830,10 @@ class BluetoothManagerService extends IBluetoothManager.Stub { } } else if (mBluetooth != null) { try { storeNameAndAddress(mBluetooth.getName(), mBluetooth.getAddress()); storeNameAndAddress( mBluetooth.getName(mContext.getAttributionSource()), mBluetooth.getAddressWithAttribution( mContext.getAttributionSource())); } catch (RemoteException re) { Slog.e(TAG, "Unable to grab names", re); } Loading Loading @@ -2096,7 +2099,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub { //Do enable request try { if (!mBluetooth.enable(mQuietEnable)) { if (!mBluetooth.enable(mQuietEnable, mContext.getAttributionSource())) { Slog.e(TAG, "IBluetooth.enable() returned false"); } } catch (RemoteException e) { Loading Loading @@ -2417,7 +2420,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub { } else if (mBluetooth != null) { //Enable bluetooth try { if (!mBluetooth.enable(mQuietEnable)) { if (!mBluetooth.enable(mQuietEnable, mContext.getAttributionSource())) { Slog.e(TAG, "IBluetooth.enable() returned false"); } } catch (RemoteException e) { Loading Loading @@ -2447,7 +2450,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub { if (DBG) { Slog.d(TAG, "Sending off request."); } if (!mBluetooth.disable()) { if (!mBluetooth.disable(mContext.getAttributionSource())) { Slog.e(TAG, "IBluetooth.disable() returned false"); } } Loading Loading
framework/java/android/bluetooth/BluetoothAdapter.java +20 −20 Original line number Diff line number Diff line Loading @@ -31,12 +31,12 @@ import android.app.ActivityThread; import android.app.PropertyInvalidatedCache; import android.bluetooth.BluetoothDevice.Transport; import android.bluetooth.BluetoothProfile.ConnectionPolicy; import android.bluetooth.annotations.RequiresLegacyBluetoothAdminPermission; import android.bluetooth.annotations.RequiresBluetoothAdvertisePermission; import android.bluetooth.annotations.RequiresBluetoothConnectPermission; import android.bluetooth.annotations.RequiresBluetoothLocationPermission; import android.bluetooth.annotations.RequiresLegacyBluetoothPermission; import android.bluetooth.annotations.RequiresBluetoothScanPermission; import android.bluetooth.annotations.RequiresLegacyBluetoothAdminPermission; import android.bluetooth.annotations.RequiresLegacyBluetoothPermission; import android.bluetooth.le.BluetoothLeAdvertiser; import android.bluetooth.le.BluetoothLeScanner; import android.bluetooth.le.PeriodicAdvertisingManager; Loading Loading @@ -807,7 +807,7 @@ public final class BluetoothAdapter { */ @RequiresNoPermission public BluetoothDevice getRemoteDevice(String address) { return new BluetoothDevice(address); return new BluetoothDevice(address, getAttributionSource()); } /** Loading @@ -828,7 +828,7 @@ public final class BluetoothAdapter { } return new BluetoothDevice( String.format(Locale.US, "%02X:%02X:%02X:%02X:%02X:%02X", address[0], address[1], address[2], address[3], address[4], address[5])); address[2], address[3], address[4], address[5]), getAttributionSource()); } /** Loading Loading @@ -1330,7 +1330,7 @@ public final class BluetoothAdapter { try { mServiceLock.readLock().lock(); if (mService != null) { return mService.getUuids(); return mService.getUuids(getAttributionSource()); } } catch (RemoteException e) { Log.e(TAG, "", e); Loading Loading @@ -1364,7 +1364,7 @@ public final class BluetoothAdapter { try { mServiceLock.readLock().lock(); if (mService != null) { return mService.setName(name); return mService.setName(name, getAttributionSource()); } } catch (RemoteException e) { Log.e(TAG, "", e); Loading Loading @@ -1392,7 +1392,7 @@ public final class BluetoothAdapter { try { mServiceLock.readLock().lock(); if (mService != null) { return mService.getBluetoothClass(); return mService.getBluetoothClass(getAttributionSource()); } } catch (RemoteException e) { Log.e(TAG, "", e); Loading Loading @@ -1448,7 +1448,7 @@ public final class BluetoothAdapter { if (getState() != STATE_ON) return BluetoothAdapter.IO_CAPABILITY_UNKNOWN; try { mServiceLock.readLock().lock(); if (mService != null) return mService.getIoCapability(); if (mService != null) return mService.getIoCapability(getAttributionSource()); } catch (RemoteException e) { Log.e(TAG, e.getMessage(), e); } finally { Loading Loading @@ -1501,7 +1501,7 @@ public final class BluetoothAdapter { if (getState() != STATE_ON) return BluetoothAdapter.IO_CAPABILITY_UNKNOWN; try { mServiceLock.readLock().lock(); if (mService != null) return mService.getLeIoCapability(); if (mService != null) return mService.getLeIoCapability(getAttributionSource()); } catch (RemoteException e) { Log.e(TAG, e.getMessage(), e); } finally { Loading Loading @@ -1563,7 +1563,7 @@ public final class BluetoothAdapter { try { mServiceLock.readLock().lock(); if (mService != null) { return mService.getScanMode(); return mService.getScanMode(getAttributionSource()); } } catch (RemoteException e) { Log.e(TAG, "", e); Loading Loading @@ -1612,7 +1612,7 @@ public final class BluetoothAdapter { mServiceLock.readLock().lock(); if (mService != null) { int durationSeconds = Math.toIntExact(durationMillis / 1000); return mService.setScanMode(mode, durationSeconds); return mService.setScanMode(mode, durationSeconds, getAttributionSource()); } } catch (RemoteException e) { Log.e(TAG, "", e); Loading Loading @@ -1662,7 +1662,7 @@ public final class BluetoothAdapter { try { mServiceLock.readLock().lock(); if (mService != null) { return mService.setScanMode(mode, getDiscoverableTimeout()); return mService.setScanMode(mode, getDiscoverableTimeout(), getAttributionSource()); } } catch (RemoteException e) { Log.e(TAG, "", e); Loading @@ -1683,7 +1683,7 @@ public final class BluetoothAdapter { try { mServiceLock.readLock().lock(); if (mService != null) { return mService.getDiscoverableTimeout(); return mService.getDiscoverableTimeout(getAttributionSource()); } } catch (RemoteException e) { Log.e(TAG, "", e); Loading @@ -1704,7 +1704,7 @@ public final class BluetoothAdapter { try { mServiceLock.readLock().lock(); if (mService != null) { mService.setDiscoverableTimeout(timeout); mService.setDiscoverableTimeout(timeout, getAttributionSource()); } } catch (RemoteException e) { Log.e(TAG, "", e); Loading Loading @@ -1755,7 +1755,7 @@ public final class BluetoothAdapter { return ActivityThread.currentOpPackageName(); } private AttributionSource getAttributionSource() { AttributionSource getAttributionSource() { if (mContext != null) { return mContext.getAttributionSource(); } Loading Loading @@ -1838,7 +1838,7 @@ public final class BluetoothAdapter { try { mServiceLock.readLock().lock(); if (mService != null) { return mService.cancelDiscovery(); return mService.cancelDiscovery(getAttributionSource()); } } catch (RemoteException e) { Log.e(TAG, "", e); Loading Loading @@ -1876,7 +1876,7 @@ public final class BluetoothAdapter { try { mServiceLock.readLock().lock(); if (mService != null) { return mService.isDiscovering(); return mService.isDiscovering(getAttributionSource()); } } catch (RemoteException e) { Log.e(TAG, "", e); Loading Loading @@ -2313,7 +2313,7 @@ public final class BluetoothAdapter { try { mServiceLock.readLock().lock(); if (mService != null) { return mService.getMaxConnectedAudioDevices(); return mService.getMaxConnectedAudioDevices(getAttributionSource()); } } catch (RemoteException e) { Log.e(TAG, "failed to get getMaxConnectedAudioDevices, error: ", e); Loading Loading @@ -2425,7 +2425,7 @@ public final class BluetoothAdapter { try { mServiceLock.readLock().lock(); if (mService != null) { return mService.getMostRecentlyConnectedDevices(); return mService.getMostRecentlyConnectedDevices(getAttributionSource()); } } catch (RemoteException e) { Log.e(TAG, "", e); Loading Loading @@ -2455,7 +2455,7 @@ public final class BluetoothAdapter { try { mServiceLock.readLock().lock(); if (mService != null) { return toDeviceSet(mService.getBondedDevices()); return toDeviceSet(mService.getBondedDevices(getAttributionSource())); } return toDeviceSet(new BluetoothDevice[0]); } catch (RemoteException e) { Loading
framework/java/android/bluetooth/BluetoothDevice.java +39 −25 Original line number Diff line number Diff line Loading @@ -32,6 +32,7 @@ import android.bluetooth.annotations.RequiresLegacyBluetoothAdminPermission; import android.bluetooth.annotations.RequiresLegacyBluetoothPermission; import android.companion.AssociationRequest; import android.compat.annotation.UnsupportedAppUsage; import android.content.AttributionSource; import android.content.Context; import android.os.Build; import android.os.Handler; Loading Loading @@ -1101,6 +1102,8 @@ public final class BluetoothDevice implements Parcelable { */ private static volatile IBluetooth sService; private final AttributionSource mAttributionSource; private final String mAddress; @AddressType private final int mAddressType; Loading Loading @@ -1149,12 +1152,12 @@ public final class BluetoothDevice implements Parcelable { * and is validated in this constructor. * * @param address valid Bluetooth MAC address * @param attributionSource attribution for permission-protected calls * @throws RuntimeException Bluetooth is not available on this platform * @throws IllegalArgumentException address is invalid * @hide */ @UnsupportedAppUsage /*package*/ BluetoothDevice(String address) { public BluetoothDevice(String address, AttributionSource attributionSource) { getService(); // ensures sService is initialized if (!BluetoothAdapter.checkBluetoothAddress(address)) { throw new IllegalArgumentException(address + " is not a valid Bluetooth address"); Loading @@ -1162,6 +1165,12 @@ public final class BluetoothDevice implements Parcelable { mAddress = address; mAddressType = ADDRESS_TYPE_PUBLIC; mAttributionSource = attributionSource; } @UnsupportedAppUsage /*package*/ BluetoothDevice(String address) { this(address, BluetoothAdapter.getDefaultAdapter().getAttributionSource()); } @Override Loading Loading @@ -1199,7 +1208,8 @@ public final class BluetoothDevice implements Parcelable { public static final @android.annotation.NonNull Parcelable.Creator<BluetoothDevice> CREATOR = new Parcelable.Creator<BluetoothDevice>() { public BluetoothDevice createFromParcel(Parcel in) { return new BluetoothDevice(in.readString()); return new BluetoothDevice( in.readString(), in.readParcelable(getClass().getClassLoader())); } public BluetoothDevice[] newArray(int size) { Loading @@ -1210,6 +1220,7 @@ public final class BluetoothDevice implements Parcelable { @Override public void writeToParcel(Parcel out, int flags) { out.writeString(mAddress); out.writeParcelable(mAttributionSource, 0); } /** Loading Loading @@ -1254,7 +1265,7 @@ public final class BluetoothDevice implements Parcelable { return null; } try { String name = service.getRemoteName(this); String name = service.getRemoteName(this, mAttributionSource); if (name != null) { // remove whitespace characters from the name return name Loading Loading @@ -1285,7 +1296,7 @@ public final class BluetoothDevice implements Parcelable { return DEVICE_TYPE_UNKNOWN; } try { return service.getRemoteType(this); return service.getRemoteType(this, mAttributionSource); } catch (RemoteException e) { Log.e(TAG, "", e); } Loading @@ -1309,7 +1320,7 @@ public final class BluetoothDevice implements Parcelable { return null; } try { String alias = service.getRemoteAlias(this); String alias = service.getRemoteAliasWithAttribution(this, mAttributionSource); if (alias == null) { return getName(); } Loading Loading @@ -1351,7 +1362,8 @@ public final class BluetoothDevice implements Parcelable { } try { BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); return service.setRemoteAlias(this, alias, adapter.getOpPackageName()); return service.setRemoteAlias( this, alias, adapter.getOpPackageName(), mAttributionSource); } catch (RemoteException e) { Log.e(TAG, "", e); } Loading @@ -1377,7 +1389,7 @@ public final class BluetoothDevice implements Parcelable { return BATTERY_LEVEL_BLUETOOTH_OFF; } try { return service.getBatteryLevel(this); return service.getBatteryLevel(this, mAttributionSource); } catch (RemoteException e) { Log.e(TAG, "", e); } Loading Loading @@ -1467,8 +1479,8 @@ public final class BluetoothDevice implements Parcelable { return false; } try { return service.createBond(this, transport, remoteP192Data, remoteP256Data, BluetoothAdapter.getDefaultAdapter().getOpPackageName()); return service.createBond( this, transport, remoteP192Data, remoteP256Data, mAttributionSource); } catch (RemoteException e) { Log.e(TAG, "", e); } Loading @@ -1493,7 +1505,7 @@ public final class BluetoothDevice implements Parcelable { return false; } try { return service.isBondingInitiatedLocally(this); return service.isBondingInitiatedLocally(this, mAttributionSource); } catch (RemoteException e) { Log.e(TAG, "", e); } Loading @@ -1518,7 +1530,7 @@ public final class BluetoothDevice implements Parcelable { Log.i(TAG, "cancelBondProcess() for device " + getAddress() + " called by pid: " + Process.myPid() + " tid: " + Process.myTid()); return service.cancelBondProcess(this); return service.cancelBondProcess(this, mAttributionSource); } catch (RemoteException e) { Log.e(TAG, "", e); } Loading Loading @@ -1546,7 +1558,7 @@ public final class BluetoothDevice implements Parcelable { Log.i(TAG, "removeBond() for device " + getAddress() + " called by pid: " + Process.myPid() + " tid: " + Process.myTid()); return service.removeBond(this); return service.removeBond(this, mAttributionSource); } catch (RemoteException e) { Log.e(TAG, "", e); } Loading @@ -1562,7 +1574,7 @@ public final class BluetoothDevice implements Parcelable { @SuppressLint("AndroidFrameworkRequiresPermission") protected Integer recompute(BluetoothDevice query) { try { return sService.getBondState(query); return sService.getBondState(query, mAttributionSource); } catch (RemoteException e) { throw e.rethrowAsRuntimeException(); } Loading Loading @@ -1652,7 +1664,8 @@ public final class BluetoothDevice implements Parcelable { return false; } try { return service.getConnectionState(this) != CONNECTION_STATE_DISCONNECTED; return service.getConnectionStateWithAttribution(this, mAttributionSource) != CONNECTION_STATE_DISCONNECTED; } catch (RemoteException e) { Log.e(TAG, "", e); return false; Loading @@ -1677,7 +1690,8 @@ public final class BluetoothDevice implements Parcelable { return false; } try { return service.getConnectionState(this) > CONNECTION_STATE_CONNECTED; return service.getConnectionStateWithAttribution(this, mAttributionSource) > CONNECTION_STATE_CONNECTED; } catch (RemoteException e) { Log.e(TAG, "", e); return false; Loading @@ -1699,7 +1713,7 @@ public final class BluetoothDevice implements Parcelable { return null; } try { int classInt = service.getRemoteClass(this); int classInt = service.getRemoteClass(this, mAttributionSource); if (classInt == BluetoothClass.ERROR) return null; return new BluetoothClass(classInt); } catch (RemoteException e) { Loading Loading @@ -1728,7 +1742,7 @@ public final class BluetoothDevice implements Parcelable { return null; } try { return service.getRemoteUuids(this); return service.getRemoteUuids(this, mAttributionSource); } catch (RemoteException e) { Log.e(TAG, "", e); } Loading Loading @@ -1758,7 +1772,7 @@ public final class BluetoothDevice implements Parcelable { return false; } try { return service.fetchRemoteUuids(this); return service.fetchRemoteUuidsWithAttribution(this, mAttributionSource); } catch (RemoteException e) { Log.e(TAG, "", e); } Loading Loading @@ -1795,7 +1809,7 @@ public final class BluetoothDevice implements Parcelable { return false; } try { return service.sdpSearch(this, uuid); return service.sdpSearch(this, uuid, mAttributionSource); } catch (RemoteException e) { Log.e(TAG, "", e); } Loading @@ -1817,7 +1831,7 @@ public final class BluetoothDevice implements Parcelable { return false; } try { return service.setPin(this, true, pin.length, pin); return service.setPin(this, true, pin.length, pin, mAttributionSource); } catch (RemoteException e) { Log.e(TAG, "", e); } Loading Loading @@ -1880,7 +1894,7 @@ public final class BluetoothDevice implements Parcelable { return false; } try { return service.cancelBondProcess(this); return service.cancelBondProcess(this, mAttributionSource); } catch (RemoteException e) { Log.e(TAG, "", e); } Loading Loading @@ -1913,7 +1927,7 @@ public final class BluetoothDevice implements Parcelable { return ACCESS_UNKNOWN; } try { return service.getPhonebookAccessPermission(this); return service.getPhonebookAccessPermission(this, mAttributionSource); } catch (RemoteException e) { Log.e(TAG, "", e); } Loading Loading @@ -2019,7 +2033,7 @@ public final class BluetoothDevice implements Parcelable { return ACCESS_UNKNOWN; } try { return service.getMessageAccessPermission(this); return service.getMessageAccessPermission(this, mAttributionSource); } catch (RemoteException e) { Log.e(TAG, "", e); } Loading Loading @@ -2070,7 +2084,7 @@ public final class BluetoothDevice implements Parcelable { return ACCESS_UNKNOWN; } try { return service.getSimAccessPermission(this); return service.getSimAccessPermission(this, mAttributionSource); } catch (RemoteException e) { Log.e(TAG, "", e); } Loading
service/java/com/android/server/bluetooth/BluetoothManagerService.java +10 −7 Original line number Diff line number Diff line Loading @@ -347,7 +347,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub { addActiveLog( BluetoothProtoEnums.ENABLE_DISABLE_REASON_FACTORY_RESET, mContext.getPackageName(), false); mBluetooth.disable(); mBluetooth.disable(mContext.getAttributionSource()); return true; } } catch (RemoteException e) { Loading Loading @@ -1714,7 +1714,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub { try { mBluetoothLock.readLock().lock(); if (mBluetooth != null) { return mBluetooth.getAddress(); return mBluetooth.getAddressWithAttribution(mContext.getAttributionSource()); } } catch (RemoteException e) { Slog.e(TAG, Loading Loading @@ -1743,7 +1743,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub { try { mBluetoothLock.readLock().lock(); if (mBluetooth != null) { return mBluetooth.getName(); return mBluetooth.getName(mContext.getAttributionSource()); } } catch (RemoteException e) { Slog.e(TAG, "getName(): Unable to retrieve name remotely. Returning cached name", e); Loading Loading @@ -1830,7 +1830,10 @@ class BluetoothManagerService extends IBluetoothManager.Stub { } } else if (mBluetooth != null) { try { storeNameAndAddress(mBluetooth.getName(), mBluetooth.getAddress()); storeNameAndAddress( mBluetooth.getName(mContext.getAttributionSource()), mBluetooth.getAddressWithAttribution( mContext.getAttributionSource())); } catch (RemoteException re) { Slog.e(TAG, "Unable to grab names", re); } Loading Loading @@ -2096,7 +2099,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub { //Do enable request try { if (!mBluetooth.enable(mQuietEnable)) { if (!mBluetooth.enable(mQuietEnable, mContext.getAttributionSource())) { Slog.e(TAG, "IBluetooth.enable() returned false"); } } catch (RemoteException e) { Loading Loading @@ -2417,7 +2420,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub { } else if (mBluetooth != null) { //Enable bluetooth try { if (!mBluetooth.enable(mQuietEnable)) { if (!mBluetooth.enable(mQuietEnable, mContext.getAttributionSource())) { Slog.e(TAG, "IBluetooth.enable() returned false"); } } catch (RemoteException e) { Loading Loading @@ -2447,7 +2450,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub { if (DBG) { Slog.d(TAG, "Sending off request."); } if (!mBluetooth.disable()) { if (!mBluetooth.disable(mContext.getAttributionSource())) { Slog.e(TAG, "IBluetooth.disable() returned false"); } } Loading