diff options
Diffstat (limited to 'framework/java/android/bluetooth/BluetoothDevice.java')
-rw-r--r-- | framework/java/android/bluetooth/BluetoothDevice.java | 64 |
1 files changed, 39 insertions, 25 deletions
diff --git a/framework/java/android/bluetooth/BluetoothDevice.java b/framework/java/android/bluetooth/BluetoothDevice.java index 46ca500823..befb1ca4e5 100644 --- a/framework/java/android/bluetooth/BluetoothDevice.java +++ b/framework/java/android/bluetooth/BluetoothDevice.java @@ -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; @@ -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; @@ -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"); @@ -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 @@ -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) { @@ -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); } /** @@ -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 @@ -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); } @@ -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(); } @@ -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); } @@ -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); } @@ -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); } @@ -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); } @@ -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); } @@ -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); } @@ -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(); } @@ -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; @@ -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; @@ -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) { @@ -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); } @@ -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); } @@ -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); } @@ -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); } @@ -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); } @@ -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); } @@ -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); } @@ -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); } |