Pass AttributionSource to bluetooth scanning methods.
This passes the AttributionSource to AdapterService and GattService methods that perform scanning or discovery. Bug: 183203469 Test: atest GattServiceTest Test: atest AdapterServiceTest Test: atest CtsPermissionTestCases:android.permission.cts.NearbyDevicesPermissionTest Change-Id: Id68558624fbae69eac3a8613b9536eb6e0df75bf
This commit is contained in:
@@ -38,12 +38,14 @@ import android.bluetooth.le.ScanRecord;
|
||||
import android.bluetooth.le.ScanResult;
|
||||
import android.bluetooth.le.ScanSettings;
|
||||
import android.compat.annotation.UnsupportedAppUsage;
|
||||
import android.content.AttributionSource;
|
||||
import android.content.Context;
|
||||
import android.os.BatteryStats;
|
||||
import android.os.Binder;
|
||||
import android.os.Build;
|
||||
import android.os.IBinder;
|
||||
import android.os.ParcelUuid;
|
||||
import android.os.Process;
|
||||
import android.os.RemoteException;
|
||||
import android.os.ResultReceiver;
|
||||
import android.os.ServiceManager;
|
||||
@@ -853,8 +855,8 @@ public final class BluetoothAdapter {
|
||||
}
|
||||
synchronized (mLock) {
|
||||
if (sBluetoothLeScanner == null) {
|
||||
sBluetoothLeScanner = new BluetoothLeScanner(mManagerService, getOpPackageName(),
|
||||
getAttributionTag());
|
||||
sBluetoothLeScanner =
|
||||
new BluetoothLeScanner(mManagerService, getAttributionSource());
|
||||
}
|
||||
}
|
||||
return sBluetoothLeScanner;
|
||||
@@ -1664,13 +1666,11 @@ public final class BluetoothAdapter {
|
||||
return ActivityThread.currentOpPackageName();
|
||||
}
|
||||
|
||||
private String getAttributionTag() {
|
||||
// Workaround for legacy API for getting a BluetoothAdapter not
|
||||
// passing a context
|
||||
private AttributionSource getAttributionSource() {
|
||||
if (mContext != null) {
|
||||
return mContext.getAttributionTag();
|
||||
return mContext.getAttributionSource();
|
||||
}
|
||||
return null;
|
||||
return new AttributionSource(Process.myUid(), ActivityThread.currentOpPackageName(), null);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1710,7 +1710,7 @@ public final class BluetoothAdapter {
|
||||
try {
|
||||
mServiceLock.readLock().lock();
|
||||
if (mService != null) {
|
||||
return mService.startDiscovery(getOpPackageName(), getAttributionTag());
|
||||
return mService.startDiscovery(getAttributionSource());
|
||||
}
|
||||
} catch (RemoteException e) {
|
||||
Log.e(TAG, "", e);
|
||||
|
||||
@@ -26,6 +26,7 @@ import android.bluetooth.BluetoothAdapter;
|
||||
import android.bluetooth.BluetoothGatt;
|
||||
import android.bluetooth.IBluetoothGatt;
|
||||
import android.bluetooth.IBluetoothManager;
|
||||
import android.content.AttributionSource;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.os.RemoteException;
|
||||
@@ -82,9 +83,7 @@ public final class BluetoothLeScanner {
|
||||
private final Handler mHandler;
|
||||
private BluetoothAdapter mBluetoothAdapter;
|
||||
private final Map<ScanCallback, BleScanCallbackWrapper> mLeScanClients;
|
||||
|
||||
private final String mOpPackageName;
|
||||
private final String mFeatureId;
|
||||
private final AttributionSource mAttributionSource;
|
||||
|
||||
/**
|
||||
* Use {@link BluetoothAdapter#getBluetoothLeScanner()} instead.
|
||||
@@ -95,13 +94,12 @@ public final class BluetoothLeScanner {
|
||||
* @hide
|
||||
*/
|
||||
public BluetoothLeScanner(IBluetoothManager bluetoothManager,
|
||||
@NonNull String opPackageName, @Nullable String featureId) {
|
||||
@NonNull AttributionSource attributionSource) {
|
||||
mBluetoothManager = bluetoothManager;
|
||||
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
|
||||
mHandler = new Handler(Looper.getMainLooper());
|
||||
mLeScanClients = new HashMap<ScanCallback, BleScanCallbackWrapper>();
|
||||
mOpPackageName = opPackageName;
|
||||
mFeatureId = featureId;
|
||||
mAttributionSource = attributionSource;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -256,8 +254,7 @@ public final class BluetoothLeScanner {
|
||||
wrapper.startRegistration();
|
||||
} else {
|
||||
try {
|
||||
gatt.startScanForIntent(callbackIntent, settings, filters, mOpPackageName,
|
||||
mFeatureId);
|
||||
gatt.startScanForIntent(callbackIntent, settings, filters, mAttributionSource);
|
||||
} catch (RemoteException e) {
|
||||
return ScanCallback.SCAN_FAILED_INTERNAL_ERROR;
|
||||
}
|
||||
@@ -298,7 +295,7 @@ public final class BluetoothLeScanner {
|
||||
IBluetoothGatt gatt;
|
||||
try {
|
||||
gatt = mBluetoothManager.getBluetoothGatt();
|
||||
gatt.stopScanForIntent(callbackIntent, mOpPackageName);
|
||||
gatt.stopScanForIntent(callbackIntent);
|
||||
} catch (RemoteException e) {
|
||||
}
|
||||
}
|
||||
@@ -458,7 +455,7 @@ public final class BluetoothLeScanner {
|
||||
} else {
|
||||
mScannerId = scannerId;
|
||||
mBluetoothGatt.startScan(mScannerId, mSettings, mFilters,
|
||||
mResultStorages, mOpPackageName, mFeatureId);
|
||||
mResultStorages, mAttributionSource);
|
||||
}
|
||||
} catch (RemoteException e) {
|
||||
Log.e(TAG, "fail to start le scan: " + e);
|
||||
|
||||
Reference in New Issue
Block a user