summaryrefslogtreecommitdiff
path: root/framework/java
diff options
context:
space:
mode:
authorJeff Sharkey <jsharkey@google.com>2021-04-21 22:40:20 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2021-04-21 22:40:20 +0000
commitd4e014e265ca543ad8d6d277cacbfafdb799db6f (patch)
tree180a58757a3f9e9a5724e51671596da100b154f2 /framework/java
parentf8c54a14e89477fd7809275a0920a0481367f04b (diff)
parentf0a1cae1d658c6915f9d663f1eca70f02c8c3581 (diff)
Merge "Pass AttributionSource to AdapterService methods." into sc-dev
Diffstat (limited to 'framework/java')
-rw-r--r--framework/java/android/bluetooth/BluetoothAdapter.java40
-rw-r--r--framework/java/android/bluetooth/BluetoothDevice.java64
2 files changed, 59 insertions, 45 deletions
diff --git a/framework/java/android/bluetooth/BluetoothAdapter.java b/framework/java/android/bluetooth/BluetoothAdapter.java
index 0442514d9c..5704c6513e 100644
--- a/framework/java/android/bluetooth/BluetoothAdapter.java
+++ b/framework/java/android/bluetooth/BluetoothAdapter.java
@@ -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;
@@ -807,7 +807,7 @@ public final class BluetoothAdapter {
*/
@RequiresNoPermission
public BluetoothDevice getRemoteDevice(String address) {
- return new BluetoothDevice(address);
+ return new BluetoothDevice(address, getAttributionSource());
}
/**
@@ -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());
}
/**
@@ -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);
@@ -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);
@@ -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);
@@ -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 {
@@ -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 {
@@ -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);
@@ -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);
@@ -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);
@@ -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);
@@ -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);
@@ -1755,7 +1755,7 @@ public final class BluetoothAdapter {
return ActivityThread.currentOpPackageName();
}
- private AttributionSource getAttributionSource() {
+ AttributionSource getAttributionSource() {
if (mContext != null) {
return mContext.getAttributionSource();
}
@@ -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);
@@ -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);
@@ -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);
@@ -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);
@@ -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) {
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);
}