summaryrefslogtreecommitdiff
path: root/core/java/android/bluetooth/BluetoothDevice.java
diff options
context:
space:
mode:
authorOli Lan <olilan@google.com>2021-04-20 09:56:45 +0100
committerOli Lan <olilan@google.com>2021-04-21 17:59:06 +0100
commit141edf9ef644c05ff6bd39c51f837abc2a5c9320 (patch)
tree0d9be01fd9efe39180d47874d4e45d759bc4be38 /core/java/android/bluetooth/BluetoothDevice.java
parenta2be0990e29b452dade901bdd9ac5ef74d7acf2f (diff)
Pass AttributionSource to AdapterService methods.
This adds attribution source to AdapterService bluetooth method calls. This is now required to allow the app ops for the new bluetooth permissions (BLUETOOTH_CONNECT, BLUETOOTH_ADVERTISE, and BLUETOOTH_SCAN) to be noted. Bug: 183626112 Test: atest AdapterServiceTest Test: atest CtsPermissionTestCases:android.permission.cts.NearbyDevicesPermissionTest Change-Id: I8d1fe41ca9945a3baab584f248a17b3a1eb255f7
Diffstat (limited to 'core/java/android/bluetooth/BluetoothDevice.java')
-rw-r--r--core/java/android/bluetooth/BluetoothDevice.java64
1 files changed, 39 insertions, 25 deletions
diff --git a/core/java/android/bluetooth/BluetoothDevice.java b/core/java/android/bluetooth/BluetoothDevice.java
index 1201663d1d10..701a2cc33b74 100644
--- a/core/java/android/bluetooth/BluetoothDevice.java
+++ b/core/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;
@@ -1087,6 +1088,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;
@@ -1135,12 +1138,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");
@@ -1148,6 +1151,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
@@ -1185,7 +1194,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) {
@@ -1196,6 +1206,7 @@ public final class BluetoothDevice implements Parcelable {
@Override
public void writeToParcel(Parcel out, int flags) {
out.writeString(mAddress);
+ out.writeParcelable(mAttributionSource, 0);
}
/**
@@ -1240,7 +1251,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
@@ -1271,7 +1282,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);
}
@@ -1295,7 +1306,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();
}
@@ -1337,7 +1348,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);
}
@@ -1363,7 +1375,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);
}
@@ -1453,8 +1465,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);
}
@@ -1479,7 +1491,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);
}
@@ -1504,7 +1516,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);
}
@@ -1532,7 +1544,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);
}
@@ -1548,7 +1560,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();
}
@@ -1638,7 +1650,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;
@@ -1663,7 +1676,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;
@@ -1685,7 +1699,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) {
@@ -1714,7 +1728,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);
}
@@ -1744,7 +1758,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);
}
@@ -1781,7 +1795,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);
}
@@ -1803,7 +1817,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);
}
@@ -1866,7 +1880,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);
}
@@ -1899,7 +1913,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);
}
@@ -2005,7 +2019,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);
}
@@ -2056,7 +2070,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);
}