aboutsummaryrefslogtreecommitdiff
path: root/framework/java/android/bluetooth/BluetoothDevice.java
diff options
context:
space:
mode:
authorOli Lan <olilan@google.com>2021-04-22 19:05:17 +0100
committerJeff Sharkey <jsharkey@android.com>2021-04-22 14:47:39 -0600
commit4dabcb764f1948823dcd74eefb3440afcab07db2 (patch)
tree32b0d4ad5c2e3f8d37a08b619d7d78bcd4e2a295 /framework/java/android/bluetooth/BluetoothDevice.java
parent4e4c9c4796c2c16d32e87417e084a1f724e9f258 (diff)
Pass attribution source to BT APIs.
This adds attribution source to BT method calls. This is now required to allow the app ops for the new BT permissions (BLUETOOTH_CONNECT, BLUETOOTH_ADVERTISE, and BLUETOOTH_SCAN) to be noted. Bug: 183626112 Test: atest BluetoothInstrumentationTests Change-Id: I81598553b762e491d6364064a2e1ef41dec89bf9
Diffstat (limited to 'framework/java/android/bluetooth/BluetoothDevice.java')
-rw-r--r--framework/java/android/bluetooth/BluetoothDevice.java53
1 files changed, 25 insertions, 28 deletions
diff --git a/framework/java/android/bluetooth/BluetoothDevice.java b/framework/java/android/bluetooth/BluetoothDevice.java
index cc2ba9b8ab..5eca947931 100644
--- a/framework/java/android/bluetooth/BluetoothDevice.java
+++ b/framework/java/android/bluetooth/BluetoothDevice.java
@@ -1167,17 +1167,13 @@ public final class BluetoothDevice implements Parcelable {
mAddress = address;
mAddressType = ADDRESS_TYPE_PUBLIC;
+ mAttributionSource = ActivityThread.currentAttributionSource();
}
void setAttributionSource(AttributionSource attributionSource) {
mAttributionSource = attributionSource;
}
- private AttributionSource resolveAttributionSource() {
- return (mAttributionSource != null) ? mAttributionSource
- : ActivityThread.currentAttributionSource();
- }
-
@Override
public boolean equals(@Nullable Object o) {
if (o instanceof BluetoothDevice) {
@@ -1268,7 +1264,7 @@ public final class BluetoothDevice implements Parcelable {
return null;
}
try {
- String name = service.getRemoteName(this, resolveAttributionSource());
+ String name = service.getRemoteName(this, mAttributionSource);
if (name != null) {
// remove whitespace characters from the name
return name
@@ -1299,7 +1295,7 @@ public final class BluetoothDevice implements Parcelable {
return DEVICE_TYPE_UNKNOWN;
}
try {
- return service.getRemoteType(this, resolveAttributionSource());
+ return service.getRemoteType(this, mAttributionSource);
} catch (RemoteException e) {
Log.e(TAG, "", e);
}
@@ -1323,7 +1319,7 @@ public final class BluetoothDevice implements Parcelable {
return null;
}
try {
- String alias = service.getRemoteAliasWithAttribution(this, resolveAttributionSource());
+ String alias = service.getRemoteAliasWithAttribution(this, mAttributionSource);
if (alias == null) {
return getName();
}
@@ -1365,8 +1361,8 @@ public final class BluetoothDevice implements Parcelable {
}
try {
return service.setRemoteAlias(this, alias,
- resolveAttributionSource().getPackageName(),
- resolveAttributionSource());
+ mAttributionSource.getPackageName(),
+ mAttributionSource);
} catch (RemoteException e) {
Log.e(TAG, "", e);
}
@@ -1392,7 +1388,7 @@ public final class BluetoothDevice implements Parcelable {
return BATTERY_LEVEL_BLUETOOTH_OFF;
}
try {
- return service.getBatteryLevel(this, resolveAttributionSource());
+ return service.getBatteryLevel(this, mAttributionSource);
} catch (RemoteException e) {
Log.e(TAG, "", e);
}
@@ -1483,7 +1479,7 @@ public final class BluetoothDevice implements Parcelable {
}
try {
return service.createBond(
- this, transport, remoteP192Data, remoteP256Data, resolveAttributionSource());
+ this, transport, remoteP192Data, remoteP256Data, mAttributionSource);
} catch (RemoteException e) {
Log.e(TAG, "", e);
}
@@ -1508,7 +1504,7 @@ public final class BluetoothDevice implements Parcelable {
return false;
}
try {
- return service.isBondingInitiatedLocally(this, resolveAttributionSource());
+ return service.isBondingInitiatedLocally(this, mAttributionSource);
} catch (RemoteException e) {
Log.e(TAG, "", e);
}
@@ -1533,7 +1529,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, resolveAttributionSource());
+ return service.cancelBondProcess(this, mAttributionSource);
} catch (RemoteException e) {
Log.e(TAG, "", e);
}
@@ -1561,7 +1557,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, resolveAttributionSource());
+ return service.removeBond(this, mAttributionSource);
} catch (RemoteException e) {
Log.e(TAG, "", e);
}
@@ -1577,7 +1573,7 @@ public final class BluetoothDevice implements Parcelable {
@SuppressLint("AndroidFrameworkRequiresPermission")
protected Integer recompute(BluetoothDevice query) {
try {
- return sService.getBondState(query, resolveAttributionSource());
+ return sService.getBondState(query, mAttributionSource);
} catch (RemoteException e) {
throw e.rethrowAsRuntimeException();
}
@@ -1667,7 +1663,7 @@ public final class BluetoothDevice implements Parcelable {
return false;
}
try {
- return service.getConnectionStateWithAttribution(this, resolveAttributionSource())
+ return service.getConnectionStateWithAttribution(this, mAttributionSource)
!= CONNECTION_STATE_DISCONNECTED;
} catch (RemoteException e) {
Log.e(TAG, "", e);
@@ -1693,7 +1689,7 @@ public final class BluetoothDevice implements Parcelable {
return false;
}
try {
- return service.getConnectionStateWithAttribution(this, resolveAttributionSource())
+ return service.getConnectionStateWithAttribution(this, mAttributionSource)
> CONNECTION_STATE_CONNECTED;
} catch (RemoteException e) {
Log.e(TAG, "", e);
@@ -1716,7 +1712,7 @@ public final class BluetoothDevice implements Parcelable {
return null;
}
try {
- int classInt = service.getRemoteClass(this, resolveAttributionSource());
+ int classInt = service.getRemoteClass(this, mAttributionSource);
if (classInt == BluetoothClass.ERROR) return null;
return new BluetoothClass(classInt);
} catch (RemoteException e) {
@@ -1745,7 +1741,7 @@ public final class BluetoothDevice implements Parcelable {
return null;
}
try {
- return service.getRemoteUuids(this, resolveAttributionSource());
+ return service.getRemoteUuids(this, mAttributionSource);
} catch (RemoteException e) {
Log.e(TAG, "", e);
}
@@ -1775,7 +1771,7 @@ public final class BluetoothDevice implements Parcelable {
return false;
}
try {
- return service.fetchRemoteUuidsWithAttribution(this, resolveAttributionSource());
+ return service.fetchRemoteUuidsWithAttribution(this, mAttributionSource);
} catch (RemoteException e) {
Log.e(TAG, "", e);
}
@@ -1812,7 +1808,7 @@ public final class BluetoothDevice implements Parcelable {
return false;
}
try {
- return service.sdpSearch(this, uuid, resolveAttributionSource());
+ return service.sdpSearch(this, uuid, mAttributionSource);
} catch (RemoteException e) {
Log.e(TAG, "", e);
}
@@ -1834,7 +1830,7 @@ public final class BluetoothDevice implements Parcelable {
return false;
}
try {
- return service.setPin(this, true, pin.length, pin, resolveAttributionSource());
+ return service.setPin(this, true, pin.length, pin, mAttributionSource);
} catch (RemoteException e) {
Log.e(TAG, "", e);
}
@@ -1897,7 +1893,7 @@ public final class BluetoothDevice implements Parcelable {
return false;
}
try {
- return service.cancelBondProcess(this, resolveAttributionSource());
+ return service.cancelBondProcess(this, mAttributionSource);
} catch (RemoteException e) {
Log.e(TAG, "", e);
}
@@ -1930,7 +1926,7 @@ public final class BluetoothDevice implements Parcelable {
return ACCESS_UNKNOWN;
}
try {
- return service.getPhonebookAccessPermission(this, resolveAttributionSource());
+ return service.getPhonebookAccessPermission(this, mAttributionSource);
} catch (RemoteException e) {
Log.e(TAG, "", e);
}
@@ -2036,7 +2032,7 @@ public final class BluetoothDevice implements Parcelable {
return ACCESS_UNKNOWN;
}
try {
- return service.getMessageAccessPermission(this, resolveAttributionSource());
+ return service.getMessageAccessPermission(this, mAttributionSource);
} catch (RemoteException e) {
Log.e(TAG, "", e);
}
@@ -2087,7 +2083,7 @@ public final class BluetoothDevice implements Parcelable {
return ACCESS_UNKNOWN;
}
try {
- return service.getSimAccessPermission(this, resolveAttributionSource());
+ return service.getSimAccessPermission(this, mAttributionSource);
} catch (RemoteException e) {
Log.e(TAG, "", e);
}
@@ -2516,7 +2512,8 @@ public final class BluetoothDevice implements Parcelable {
// BLE is not supported
return null;
}
- BluetoothGatt gatt = new BluetoothGatt(iGatt, this, transport, opportunistic, phy);
+ BluetoothGatt gatt = new BluetoothGatt(
+ iGatt, this, transport, opportunistic, phy, mAttributionSource);
gatt.connect(autoConnect, callback, handler);
return gatt;
} catch (RemoteException e) {