summaryrefslogtreecommitdiff
path: root/framework/java/android/bluetooth/le/PeriodicAdvertisingManager.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/le/PeriodicAdvertisingManager.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/le/PeriodicAdvertisingManager.java')
-rw-r--r--framework/java/android/bluetooth/le/PeriodicAdvertisingManager.java17
1 files changed, 11 insertions, 6 deletions
diff --git a/framework/java/android/bluetooth/le/PeriodicAdvertisingManager.java b/framework/java/android/bluetooth/le/PeriodicAdvertisingManager.java
index 26978e3980..47f47bb8e3 100644
--- a/framework/java/android/bluetooth/le/PeriodicAdvertisingManager.java
+++ b/framework/java/android/bluetooth/le/PeriodicAdvertisingManager.java
@@ -25,6 +25,7 @@ import android.bluetooth.IBluetoothManager;
import android.bluetooth.annotations.RequiresBluetoothLocationPermission;
import android.bluetooth.annotations.RequiresBluetoothScanPermission;
import android.bluetooth.annotations.RequiresLegacyBluetoothAdminPermission;
+import android.content.AttributionSource;
import android.os.Handler;
import android.os.Looper;
import android.os.RemoteException;
@@ -32,6 +33,7 @@ import android.util.Log;
import java.util.IdentityHashMap;
import java.util.Map;
+import java.util.Objects;
/**
* This class provides methods to perform periodic advertising related
@@ -54,8 +56,9 @@ public final class PeriodicAdvertisingManager {
private static final int SYNC_STARTING = -1;
+ private final BluetoothAdapter mBluetoothAdapter;
private final IBluetoothManager mBluetoothManager;
- private BluetoothAdapter mBluetoothAdapter;
+ private final AttributionSource mAttributionSource;
/* maps callback, to callback wrapper and sync handle */
Map<PeriodicAdvertisingCallback,
@@ -67,9 +70,10 @@ public final class PeriodicAdvertisingManager {
* @param bluetoothManager BluetoothManager that conducts overall Bluetooth Management.
* @hide
*/
- public PeriodicAdvertisingManager(IBluetoothManager bluetoothManager) {
- mBluetoothManager = bluetoothManager;
- mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
+ public PeriodicAdvertisingManager(BluetoothAdapter bluetoothAdapter) {
+ mBluetoothAdapter = Objects.requireNonNull(bluetoothAdapter);
+ mBluetoothManager = mBluetoothAdapter.getBluetoothManager();
+ mAttributionSource = mBluetoothAdapter.getAttributionSource();
mCallbackWrappers = new IdentityHashMap<>();
}
@@ -166,7 +170,8 @@ public final class PeriodicAdvertisingManager {
mCallbackWrappers.put(callback, wrapped);
try {
- gatt.registerSync(scanResult, skip, timeout, wrapped);
+ gatt.registerSync(
+ scanResult, skip, timeout, wrapped, mAttributionSource);
} catch (RemoteException e) {
Log.e(TAG, "Failed to register sync - ", e);
return;
@@ -202,7 +207,7 @@ public final class PeriodicAdvertisingManager {
}
try {
- gatt.unregisterSync(wrapper);
+ gatt.unregisterSync(wrapper, mAttributionSource);
} catch (RemoteException e) {
Log.e(TAG, "Failed to cancel sync creation - ", e);
return;