summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/java/android/bluetooth/BluetoothAdapter.java16
-rw-r--r--core/java/android/bluetooth/le/BluetoothLeScanner.java17
2 files changed, 15 insertions, 18 deletions
diff --git a/core/java/android/bluetooth/BluetoothAdapter.java b/core/java/android/bluetooth/BluetoothAdapter.java
index 0be7b732b4bd..5446deb5605a 100644
--- a/core/java/android/bluetooth/BluetoothAdapter.java
+++ b/core/java/android/bluetooth/BluetoothAdapter.java
@@ -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);
diff --git a/core/java/android/bluetooth/le/BluetoothLeScanner.java b/core/java/android/bluetooth/le/BluetoothLeScanner.java
index 2888fbd8a363..2601cd4300ea 100644
--- a/core/java/android/bluetooth/le/BluetoothLeScanner.java
+++ b/core/java/android/bluetooth/le/BluetoothLeScanner.java
@@ -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);