diff options
author | Oli Lan <olilan@google.com> | 2021-04-22 19:05:17 +0100 |
---|---|---|
committer | Jeff Sharkey <jsharkey@android.com> | 2021-04-22 14:47:39 -0600 |
commit | 4dabcb764f1948823dcd74eefb3440afcab07db2 (patch) | |
tree | 32b0d4ad5c2e3f8d37a08b619d7d78bcd4e2a295 /framework/java/android/bluetooth/BluetoothManager.java | |
parent | 4e4c9c4796c2c16d32e87417e084a1f724e9f258 (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/BluetoothManager.java')
-rw-r--r-- | framework/java/android/bluetooth/BluetoothManager.java | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/framework/java/android/bluetooth/BluetoothManager.java b/framework/java/android/bluetooth/BluetoothManager.java index 69f9a79c73..07af8dbd23 100644 --- a/framework/java/android/bluetooth/BluetoothManager.java +++ b/framework/java/android/bluetooth/BluetoothManager.java @@ -20,8 +20,10 @@ import android.annotation.RequiresFeature; import android.annotation.RequiresNoPermission; import android.annotation.RequiresPermission; import android.annotation.SystemService; +import android.app.ActivityThread; import android.bluetooth.annotations.RequiresBluetoothConnectPermission; import android.bluetooth.annotations.RequiresLegacyBluetoothPermission; +import android.content.AttributionSource; import android.content.Context; import android.content.pm.PackageManager; import android.os.RemoteException; @@ -29,6 +31,7 @@ import android.util.Log; import java.util.ArrayList; import java.util.List; +import java.util.function.Supplier; /** * High level manager used to obtain an instance of an {@link BluetoothAdapter} @@ -56,16 +59,16 @@ public final class BluetoothManager { private static final String TAG = "BluetoothManager"; private static final boolean DBG = false; + private final AttributionSource mAttributionSource; private final BluetoothAdapter mAdapter; /** * @hide */ public BluetoothManager(Context context) { - mAdapter = BluetoothAdapter.createAdapter(); - if (context != null) { - mAdapter.setAttributionSource(context.getAttributionSource()); - } + mAttributionSource = (context != null) ? context.getAttributionSource() + : ActivityThread.currentAttributionSource(); + mAdapter = BluetoothAdapter.createAdapter(mAttributionSource); } /** @@ -138,7 +141,7 @@ public final class BluetoothManager { if (iGatt == null) return connectedDevices; connectedDevices = iGatt.getDevicesMatchingConnectionStates( - new int[]{BluetoothProfile.STATE_CONNECTED}); + new int[]{BluetoothProfile.STATE_CONNECTED}, mAttributionSource); } catch (RemoteException e) { Log.e(TAG, "", e); } @@ -180,7 +183,8 @@ public final class BluetoothManager { IBluetoothManager managerService = mAdapter.getBluetoothManager(); IBluetoothGatt iGatt = managerService.getBluetoothGatt(); if (iGatt == null) return devices; - devices = iGatt.getDevicesMatchingConnectionStates(states); + devices = iGatt.getDevicesMatchingConnectionStates( + states, mAttributionSource); } catch (RemoteException e) { Log.e(TAG, "", e); } @@ -283,7 +287,8 @@ public final class BluetoothManager { Log.e(TAG, "Fail to get GATT Server connection"); return null; } - BluetoothGattServer mGattServer = new BluetoothGattServer(iGatt, transport); + BluetoothGattServer mGattServer = + new BluetoothGattServer(iGatt, transport, mAttributionSource); Boolean regStatus = mGattServer.registerCallback(callback, eatt_support); return regStatus ? mGattServer : null; } catch (RemoteException e) { |