Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2b4476ce authored by Oli Lan's avatar Oli Lan Committed by Automerger Merge Worker
Browse files

Pass attribution source to BT APIs. am: 4dabcb76

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/14283252

Change-Id: Ib7f3696994517f921588d030cc41b0a48b2cc1f7
parents fc93b37e 4dabcb76
Loading
Loading
Loading
Loading
+49 −51
Original line number Diff line number Diff line
@@ -706,11 +706,13 @@ public final class BluetoothAdapter {
     */
    private static BluetoothAdapter sAdapter;

    private static BluetoothLeScanner sBluetoothLeScanner;
    private static BluetoothLeAdvertiser sBluetoothLeAdvertiser;
    private static PeriodicAdvertisingManager sPeriodicAdvertisingManager;
    private BluetoothLeScanner mBluetoothLeScanner;
    private BluetoothLeAdvertiser mBluetoothLeAdvertiser;
    private PeriodicAdvertisingManager mPeriodicAdvertisingManager;

    private final IBluetoothManager mManagerService;
    private final AttributionSource mAttributionSource;

    @UnsupportedAppUsage
    private IBluetooth mService;
    private final ReentrantReadWriteLock mServiceLock = new ReentrantReadWriteLock();
@@ -722,8 +724,6 @@ public final class BluetoothAdapter {
    private final Map<BluetoothConnectionCallback, Executor>
            mBluetoothConnectionCallbackExecutorMap = new HashMap<>();

    private AttributionSource mAttributionSource;

    /**
     * Bluetooth metadata listener. Overrides the default BluetoothMetadataListener
     * implementation.
@@ -763,16 +763,17 @@ public final class BluetoothAdapter {
    @RequiresNoPermission
    public static synchronized BluetoothAdapter getDefaultAdapter() {
        if (sAdapter == null) {
            sAdapter = createAdapter();
            sAdapter = createAdapter(ActivityThread.currentAttributionSource());
        }
        return sAdapter;
    }

    /** {@hide} */
    public static BluetoothAdapter createAdapter() {
    public static BluetoothAdapter createAdapter(AttributionSource attributionSource) {
        IBinder binder = ServiceManager.getService(BLUETOOTH_MANAGER_SERVICE);
        if (binder != null) {
            return new BluetoothAdapter(IBluetoothManager.Stub.asInterface(binder));
            return new BluetoothAdapter(IBluetoothManager.Stub.asInterface(binder),
                    attributionSource);
        } else {
            Log.e(TAG, "Bluetooth binder is null");
            return null;
@@ -782,7 +783,7 @@ public final class BluetoothAdapter {
    /**
     * Use {@link #getDefaultAdapter} to get the BluetoothAdapter instance.
     */
    BluetoothAdapter(IBluetoothManager managerService) {
    BluetoothAdapter(IBluetoothManager managerService, AttributionSource attributionSource) {
        if (managerService == null) {
            throw new IllegalArgumentException("bluetooth manager service is null");
        }
@@ -794,20 +795,12 @@ public final class BluetoothAdapter {
        } finally {
            mServiceLock.writeLock().unlock();
        }
        mManagerService = managerService;
        mManagerService = Objects.requireNonNull(managerService);
        mAttributionSource = Objects.requireNonNull(attributionSource);
        mLeScanClients = new HashMap<LeScanCallback, ScanCallback>();
        mToken = new Binder();
    }

    void setAttributionSource(AttributionSource attributionSource) {
        mAttributionSource = attributionSource;
    }

    private AttributionSource resolveAttributionSource() {
        return (mAttributionSource != null) ? mAttributionSource
                : ActivityThread.currentAttributionSource();
    }

    /**
     * Get a {@link BluetoothDevice} object for the given Bluetooth hardware
     * address.
@@ -864,11 +857,11 @@ public final class BluetoothAdapter {
            return null;
        }
        synchronized (mLock) {
            if (sBluetoothLeAdvertiser == null) {
                sBluetoothLeAdvertiser = new BluetoothLeAdvertiser(mManagerService);
            if (mBluetoothLeAdvertiser == null) {
                mBluetoothLeAdvertiser = new BluetoothLeAdvertiser(this);
            }
            return mBluetoothLeAdvertiser;
        }
        return sBluetoothLeAdvertiser;
    }

    /**
@@ -892,11 +885,11 @@ public final class BluetoothAdapter {
        }

        synchronized (mLock) {
            if (sPeriodicAdvertisingManager == null) {
                sPeriodicAdvertisingManager = new PeriodicAdvertisingManager(mManagerService);
            if (mPeriodicAdvertisingManager == null) {
                mPeriodicAdvertisingManager = new PeriodicAdvertisingManager(this);
            }
            return mPeriodicAdvertisingManager;
        }
        return sPeriodicAdvertisingManager;
    }

    /**
@@ -908,12 +901,11 @@ public final class BluetoothAdapter {
            return null;
        }
        synchronized (mLock) {
            if (sBluetoothLeScanner == null) {
                sBluetoothLeScanner =
                        new BluetoothLeScanner(mManagerService, resolveAttributionSource());
            if (mBluetoothLeScanner == null) {
                mBluetoothLeScanner = new BluetoothLeScanner(this);
            }
            return mBluetoothLeScanner;
        }
        return sBluetoothLeScanner;
    }

    /**
@@ -1349,7 +1341,7 @@ public final class BluetoothAdapter {
        try {
            mServiceLock.readLock().lock();
            if (mService != null) {
                return mService.getUuids(resolveAttributionSource());
                return mService.getUuids(mAttributionSource);
            }
        } catch (RemoteException e) {
            Log.e(TAG, "", e);
@@ -1383,7 +1375,7 @@ public final class BluetoothAdapter {
        try {
            mServiceLock.readLock().lock();
            if (mService != null) {
                return mService.setName(name, resolveAttributionSource());
                return mService.setName(name, mAttributionSource);
            }
        } catch (RemoteException e) {
            Log.e(TAG, "", e);
@@ -1411,7 +1403,7 @@ public final class BluetoothAdapter {
        try {
            mServiceLock.readLock().lock();
            if (mService != null) {
                return mService.getBluetoothClass(resolveAttributionSource());
                return mService.getBluetoothClass(mAttributionSource);
            }
        } catch (RemoteException e) {
            Log.e(TAG, "", e);
@@ -1467,7 +1459,7 @@ public final class BluetoothAdapter {
        if (getState() != STATE_ON) return BluetoothAdapter.IO_CAPABILITY_UNKNOWN;
        try {
            mServiceLock.readLock().lock();
            if (mService != null) return mService.getIoCapability(resolveAttributionSource());
            if (mService != null) return mService.getIoCapability(mAttributionSource);
        } catch (RemoteException e) {
            Log.e(TAG, e.getMessage(), e);
        } finally {
@@ -1520,7 +1512,7 @@ public final class BluetoothAdapter {
        if (getState() != STATE_ON) return BluetoothAdapter.IO_CAPABILITY_UNKNOWN;
        try {
            mServiceLock.readLock().lock();
            if (mService != null) return mService.getLeIoCapability(resolveAttributionSource());
            if (mService != null) return mService.getLeIoCapability(mAttributionSource);
        } catch (RemoteException e) {
            Log.e(TAG, e.getMessage(), e);
        } finally {
@@ -1582,7 +1574,7 @@ public final class BluetoothAdapter {
        try {
            mServiceLock.readLock().lock();
            if (mService != null) {
                return mService.getScanMode(resolveAttributionSource());
                return mService.getScanMode(mAttributionSource);
            }
        } catch (RemoteException e) {
            Log.e(TAG, "", e);
@@ -1631,7 +1623,7 @@ public final class BluetoothAdapter {
            mServiceLock.readLock().lock();
            if (mService != null) {
                int durationSeconds = Math.toIntExact(durationMillis / 1000);
                return mService.setScanMode(mode, durationSeconds, resolveAttributionSource());
                return mService.setScanMode(mode, durationSeconds, mAttributionSource);
            }
        } catch (RemoteException e) {
            Log.e(TAG, "", e);
@@ -1681,7 +1673,7 @@ public final class BluetoothAdapter {
        try {
            mServiceLock.readLock().lock();
            if (mService != null) {
                return mService.setScanMode(mode, getDiscoverableTimeout(), resolveAttributionSource());
                return mService.setScanMode(mode, getDiscoverableTimeout(), mAttributionSource);
            }
        } catch (RemoteException e) {
            Log.e(TAG, "", e);
@@ -1702,7 +1694,7 @@ public final class BluetoothAdapter {
        try {
            mServiceLock.readLock().lock();
            if (mService != null) {
                return mService.getDiscoverableTimeout(resolveAttributionSource());
                return mService.getDiscoverableTimeout(mAttributionSource);
            }
        } catch (RemoteException e) {
            Log.e(TAG, "", e);
@@ -1723,7 +1715,7 @@ public final class BluetoothAdapter {
        try {
            mServiceLock.readLock().lock();
            if (mService != null) {
                mService.setDiscoverableTimeout(timeout, resolveAttributionSource());
                mService.setDiscoverableTimeout(timeout, mAttributionSource);
            }
        } catch (RemoteException e) {
            Log.e(TAG, "", e);
@@ -1796,7 +1788,7 @@ public final class BluetoothAdapter {
        try {
            mServiceLock.readLock().lock();
            if (mService != null) {
                return mService.startDiscovery(resolveAttributionSource());
                return mService.startDiscovery(mAttributionSource);
            }
        } catch (RemoteException e) {
            Log.e(TAG, "", e);
@@ -1832,7 +1824,7 @@ public final class BluetoothAdapter {
        try {
            mServiceLock.readLock().lock();
            if (mService != null) {
                return mService.cancelDiscovery(resolveAttributionSource());
                return mService.cancelDiscovery(mAttributionSource);
            }
        } catch (RemoteException e) {
            Log.e(TAG, "", e);
@@ -1870,7 +1862,7 @@ public final class BluetoothAdapter {
        try {
            mServiceLock.readLock().lock();
            if (mService != null) {
                return mService.isDiscovering(resolveAttributionSource());
                return mService.isDiscovering(mAttributionSource);
            }
        } catch (RemoteException e) {
            Log.e(TAG, "", e);
@@ -2307,7 +2299,7 @@ public final class BluetoothAdapter {
        try {
            mServiceLock.readLock().lock();
            if (mService != null) {
                return mService.getMaxConnectedAudioDevices(resolveAttributionSource());
                return mService.getMaxConnectedAudioDevices(mAttributionSource);
            }
        } catch (RemoteException e) {
            Log.e(TAG, "failed to get getMaxConnectedAudioDevices, error: ", e);
@@ -2335,7 +2327,7 @@ public final class BluetoothAdapter {
                // BLE is not supported
                return false;
            }
            return (iGatt.numHwTrackFiltersAvailable() != 0);
            return (iGatt.numHwTrackFiltersAvailable(mAttributionSource) != 0);
        } catch (RemoteException e) {
            Log.e(TAG, "", e);
        }
@@ -2419,7 +2411,7 @@ public final class BluetoothAdapter {
        try {
            mServiceLock.readLock().lock();
            if (mService != null) {
                return mService.getMostRecentlyConnectedDevices(resolveAttributionSource());
                return mService.getMostRecentlyConnectedDevices(mAttributionSource);
            }
        } catch (RemoteException e) {
            Log.e(TAG, "", e);
@@ -2449,7 +2441,7 @@ public final class BluetoothAdapter {
        try {
            mServiceLock.readLock().lock();
            if (mService != null) {
                return toDeviceSet(mService.getBondedDevices(resolveAttributionSource()));
                return toDeviceSet(mService.getBondedDevices(mAttributionSource));
            }
            return toDeviceSet(new BluetoothDevice[0]);
        } catch (RemoteException e) {
@@ -3171,11 +3163,11 @@ public final class BluetoothAdapter {
                        if (mLeScanClients != null) {
                            mLeScanClients.clear();
                        }
                        if (sBluetoothLeAdvertiser != null) {
                            sBluetoothLeAdvertiser.cleanup();
                        if (mBluetoothLeAdvertiser != null) {
                            mBluetoothLeAdvertiser.cleanup();
                        }
                        if (sBluetoothLeScanner != null) {
                            sBluetoothLeScanner.cleanup();
                        if (mBluetoothLeScanner != null) {
                            mBluetoothLeScanner.cleanup();
                        }
                    } finally {
                        mServiceLock.writeLock().unlock();
@@ -3514,11 +3506,17 @@ public final class BluetoothAdapter {
                && (Integer.parseInt(address.split(":")[5], 16) & 0b11) == 0b11;
    }

    /** {@hide} */
    @UnsupportedAppUsage
    /*package*/ IBluetoothManager getBluetoothManager() {
    public IBluetoothManager getBluetoothManager() {
        return mManagerService;
    }

    /** {@hide} */
    public AttributionSource getAttributionSource() {
        return mAttributionSource;
    }

    private final ArrayList<IBluetoothManagerCallback> mProxyServiceStateCallbacks =
            new ArrayList<IBluetoothManagerCallback>();

+25 −28
Original line number Diff line number Diff line
@@ -1167,17 +1167,13 @@ public final class BluetoothDevice implements Parcelable {

        mAddress = address;
        mAddressType = ADDRESS_TYPE_PUBLIC;
        mAttributionSource = ActivityThread.currentAttributionSource();
    }

    void setAttributionSource(AttributionSource attributionSource) {
        mAttributionSource = attributionSource;
    }

    private AttributionSource resolveAttributionSource() {
        return (mAttributionSource != null) ? mAttributionSource
                : ActivityThread.currentAttributionSource();
    }

    @Override
    public boolean equals(@Nullable Object o) {
        if (o instanceof BluetoothDevice) {
@@ -1268,7 +1264,7 @@ public final class BluetoothDevice implements Parcelable {
            return null;
        }
        try {
            String name = service.getRemoteName(this, resolveAttributionSource());
            String name = service.getRemoteName(this, mAttributionSource);
            if (name != null) {
                // remove whitespace characters from the name
                return name
@@ -1299,7 +1295,7 @@ public final class BluetoothDevice implements Parcelable {
            return DEVICE_TYPE_UNKNOWN;
        }
        try {
            return service.getRemoteType(this, resolveAttributionSource());
            return service.getRemoteType(this, mAttributionSource);
        } catch (RemoteException e) {
            Log.e(TAG, "", e);
        }
@@ -1323,7 +1319,7 @@ public final class BluetoothDevice implements Parcelable {
            return null;
        }
        try {
            String alias = service.getRemoteAliasWithAttribution(this, resolveAttributionSource());
            String alias = service.getRemoteAliasWithAttribution(this, mAttributionSource);
            if (alias == null) {
                return getName();
            }
@@ -1365,8 +1361,8 @@ public final class BluetoothDevice implements Parcelable {
        }
        try {
            return service.setRemoteAlias(this, alias,
                    resolveAttributionSource().getPackageName(),
                    resolveAttributionSource());
                    mAttributionSource.getPackageName(),
                    mAttributionSource);
        } catch (RemoteException e) {
            Log.e(TAG, "", e);
        }
@@ -1392,7 +1388,7 @@ public final class BluetoothDevice implements Parcelable {
            return BATTERY_LEVEL_BLUETOOTH_OFF;
        }
        try {
            return service.getBatteryLevel(this, resolveAttributionSource());
            return service.getBatteryLevel(this, mAttributionSource);
        } catch (RemoteException e) {
            Log.e(TAG, "", e);
        }
@@ -1483,7 +1479,7 @@ public final class BluetoothDevice implements Parcelable {
        }
        try {
            return service.createBond(
                    this, transport, remoteP192Data, remoteP256Data, resolveAttributionSource());
                    this, transport, remoteP192Data, remoteP256Data, mAttributionSource);
        } catch (RemoteException e) {
            Log.e(TAG, "", e);
        }
@@ -1508,7 +1504,7 @@ public final class BluetoothDevice implements Parcelable {
            return false;
        }
        try {
            return service.isBondingInitiatedLocally(this, resolveAttributionSource());
            return service.isBondingInitiatedLocally(this, mAttributionSource);
        } catch (RemoteException e) {
            Log.e(TAG, "", e);
        }
@@ -1533,7 +1529,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, resolveAttributionSource());
            return service.cancelBondProcess(this, mAttributionSource);
        } catch (RemoteException e) {
            Log.e(TAG, "", e);
        }
@@ -1561,7 +1557,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, resolveAttributionSource());
            return service.removeBond(this, mAttributionSource);
        } catch (RemoteException e) {
            Log.e(TAG, "", e);
        }
@@ -1577,7 +1573,7 @@ public final class BluetoothDevice implements Parcelable {
                @SuppressLint("AndroidFrameworkRequiresPermission")
                protected Integer recompute(BluetoothDevice query) {
                    try {
                        return sService.getBondState(query, resolveAttributionSource());
                        return sService.getBondState(query, mAttributionSource);
                    } catch (RemoteException e) {
                        throw e.rethrowAsRuntimeException();
                    }
@@ -1667,7 +1663,7 @@ public final class BluetoothDevice implements Parcelable {
            return false;
        }
        try {
            return service.getConnectionStateWithAttribution(this, resolveAttributionSource())
            return service.getConnectionStateWithAttribution(this, mAttributionSource)
                    != CONNECTION_STATE_DISCONNECTED;
        } catch (RemoteException e) {
            Log.e(TAG, "", e);
@@ -1693,7 +1689,7 @@ public final class BluetoothDevice implements Parcelable {
            return false;
        }
        try {
            return service.getConnectionStateWithAttribution(this, resolveAttributionSource())
            return service.getConnectionStateWithAttribution(this, mAttributionSource)
                    > CONNECTION_STATE_CONNECTED;
        } catch (RemoteException e) {
            Log.e(TAG, "", e);
@@ -1716,7 +1712,7 @@ public final class BluetoothDevice implements Parcelable {
            return null;
        }
        try {
            int classInt = service.getRemoteClass(this, resolveAttributionSource());
            int classInt = service.getRemoteClass(this, mAttributionSource);
            if (classInt == BluetoothClass.ERROR) return null;
            return new BluetoothClass(classInt);
        } catch (RemoteException e) {
@@ -1745,7 +1741,7 @@ public final class BluetoothDevice implements Parcelable {
            return null;
        }
        try {
            return service.getRemoteUuids(this, resolveAttributionSource());
            return service.getRemoteUuids(this, mAttributionSource);
        } catch (RemoteException e) {
            Log.e(TAG, "", e);
        }
@@ -1775,7 +1771,7 @@ public final class BluetoothDevice implements Parcelable {
            return false;
        }
        try {
            return service.fetchRemoteUuidsWithAttribution(this, resolveAttributionSource());
            return service.fetchRemoteUuidsWithAttribution(this, mAttributionSource);
        } catch (RemoteException e) {
            Log.e(TAG, "", e);
        }
@@ -1812,7 +1808,7 @@ public final class BluetoothDevice implements Parcelable {
            return false;
        }
        try {
            return service.sdpSearch(this, uuid, resolveAttributionSource());
            return service.sdpSearch(this, uuid, mAttributionSource);
        } catch (RemoteException e) {
            Log.e(TAG, "", e);
        }
@@ -1834,7 +1830,7 @@ public final class BluetoothDevice implements Parcelable {
            return false;
        }
        try {
            return service.setPin(this, true, pin.length, pin, resolveAttributionSource());
            return service.setPin(this, true, pin.length, pin, mAttributionSource);
        } catch (RemoteException e) {
            Log.e(TAG, "", e);
        }
@@ -1897,7 +1893,7 @@ public final class BluetoothDevice implements Parcelable {
            return false;
        }
        try {
            return service.cancelBondProcess(this, resolveAttributionSource());
            return service.cancelBondProcess(this, mAttributionSource);
        } catch (RemoteException e) {
            Log.e(TAG, "", e);
        }
@@ -1930,7 +1926,7 @@ public final class BluetoothDevice implements Parcelable {
            return ACCESS_UNKNOWN;
        }
        try {
            return service.getPhonebookAccessPermission(this, resolveAttributionSource());
            return service.getPhonebookAccessPermission(this, mAttributionSource);
        } catch (RemoteException e) {
            Log.e(TAG, "", e);
        }
@@ -2036,7 +2032,7 @@ public final class BluetoothDevice implements Parcelable {
            return ACCESS_UNKNOWN;
        }
        try {
            return service.getMessageAccessPermission(this, resolveAttributionSource());
            return service.getMessageAccessPermission(this, mAttributionSource);
        } catch (RemoteException e) {
            Log.e(TAG, "", e);
        }
@@ -2087,7 +2083,7 @@ public final class BluetoothDevice implements Parcelable {
            return ACCESS_UNKNOWN;
        }
        try {
            return service.getSimAccessPermission(this, resolveAttributionSource());
            return service.getSimAccessPermission(this, mAttributionSource);
        } catch (RemoteException e) {
            Log.e(TAG, "", e);
        }
@@ -2516,7 +2512,8 @@ public final class BluetoothDevice implements Parcelable {
                // BLE is not supported
                return null;
            }
            BluetoothGatt gatt = new BluetoothGatt(iGatt, this, transport, opportunistic, phy);
            BluetoothGatt gatt = new BluetoothGatt(
                    iGatt, this, transport, opportunistic, phy, mAttributionSource);
            gatt.connect(autoConnect, callback, handler);
            return gatt;
        } catch (RemoteException e) {
+42 −31

File changed.

Preview size limit exceeded, changes collapsed.

+18 −12
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import android.annotation.RequiresPermission;
import android.annotation.SuppressLint;
import android.bluetooth.annotations.RequiresBluetoothConnectPermission;
import android.bluetooth.annotations.RequiresLegacyBluetoothPermission;
import android.content.AttributionSource;
import android.os.ParcelUuid;
import android.os.RemoteException;
import android.util.Log;
@@ -48,6 +49,7 @@ public final class BluetoothGattServer implements BluetoothProfile {
    private BluetoothAdapter mAdapter;
    private IBluetoothGatt mService;
    private BluetoothGattServerCallback mCallback;
    private final AttributionSource mAttributionSource;

    private Object mServerIfLock = new Object();
    private int mServerIf;
@@ -382,13 +384,15 @@ public final class BluetoothGattServer implements BluetoothProfile {
    /**
     * Create a BluetoothGattServer proxy object.
     */
    /*package*/ BluetoothGattServer(IBluetoothGatt iGatt, int transport) {
    /*package*/ BluetoothGattServer(
            IBluetoothGatt iGatt, int transport, AttributionSource attributionSource) {
        mService = iGatt;
        mAdapter = BluetoothAdapter.getDefaultAdapter();
        mCallback = null;
        mServerIf = 0;
        mTransport = transport;
        mServices = new ArrayList<BluetoothGattService>();
        mAttributionSource = attributionSource;
    }

    /**
@@ -488,7 +492,8 @@ public final class BluetoothGattServer implements BluetoothProfile {

            mCallback = callback;
            try {
                mService.registerServer(new ParcelUuid(uuid), mBluetoothGattServerCallback, eatt_support);
                mService.registerServer(new ParcelUuid(uuid), mBluetoothGattServerCallback,
                        eatt_support, mAttributionSource);
            } catch (RemoteException e) {
                Log.e(TAG, "", e);
                mCallback = null;
@@ -522,7 +527,7 @@ public final class BluetoothGattServer implements BluetoothProfile {

        try {
            mCallback = null;
            mService.unregisterServer(mServerIf);
            mService.unregisterServer(mServerIf, mAttributionSource);
            mServerIf = 0;
        } catch (RemoteException e) {
            Log.e(TAG, "", e);
@@ -576,7 +581,8 @@ public final class BluetoothGattServer implements BluetoothProfile {

        try {
            // autoConnect is inverse of "isDirect"
            mService.serverConnect(mServerIf, device.getAddress(), !autoConnect, mTransport);
            mService.serverConnect(
                    mServerIf, device.getAddress(), !autoConnect, mTransport, mAttributionSource);
        } catch (RemoteException e) {
            Log.e(TAG, "", e);
            return false;
@@ -599,7 +605,7 @@ public final class BluetoothGattServer implements BluetoothProfile {
        if (mService == null || mServerIf == 0) return;

        try {
            mService.serverDisconnect(mServerIf, device.getAddress());
            mService.serverDisconnect(mServerIf, device.getAddress(), mAttributionSource);
        } catch (RemoteException e) {
            Log.e(TAG, "", e);
        }
@@ -628,7 +634,7 @@ public final class BluetoothGattServer implements BluetoothProfile {
    public void setPreferredPhy(BluetoothDevice device, int txPhy, int rxPhy, int phyOptions) {
        try {
            mService.serverSetPreferredPhy(mServerIf, device.getAddress(), txPhy, rxPhy,
                    phyOptions);
                    phyOptions, mAttributionSource);
        } catch (RemoteException e) {
            Log.e(TAG, "", e);
        }
@@ -644,7 +650,7 @@ public final class BluetoothGattServer implements BluetoothProfile {
    @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)
    public void readPhy(BluetoothDevice device) {
        try {
            mService.serverReadPhy(mServerIf, device.getAddress());
            mService.serverReadPhy(mServerIf, device.getAddress(), mAttributionSource);
        } catch (RemoteException e) {
            Log.e(TAG, "", e);
        }
@@ -679,7 +685,7 @@ public final class BluetoothGattServer implements BluetoothProfile {

        try {
            mService.sendResponse(mServerIf, device.getAddress(), requestId,
                    status, offset, value);
                    status, offset, value, mAttributionSource);
        } catch (RemoteException e) {
            Log.e(TAG, "", e);
            return false;
@@ -722,7 +728,7 @@ public final class BluetoothGattServer implements BluetoothProfile {
        try {
            mService.sendNotification(mServerIf, device.getAddress(),
                    characteristic.getInstanceId(), confirm,
                    characteristic.getValue());
                    characteristic.getValue(), mAttributionSource);
        } catch (RemoteException e) {
            Log.e(TAG, "", e);
            return false;
@@ -757,7 +763,7 @@ public final class BluetoothGattServer implements BluetoothProfile {
        mPendingService = service;

        try {
            mService.addService(mServerIf, service);
            mService.addService(mServerIf, service, mAttributionSource);
        } catch (RemoteException e) {
            Log.e(TAG, "", e);
            return false;
@@ -784,7 +790,7 @@ public final class BluetoothGattServer implements BluetoothProfile {
        if (intService == null) return false;

        try {
            mService.removeService(mServerIf, service.getInstanceId());
            mService.removeService(mServerIf, service.getInstanceId(), mAttributionSource);
            mServices.remove(intService);
        } catch (RemoteException e) {
            Log.e(TAG, "", e);
@@ -805,7 +811,7 @@ public final class BluetoothGattServer implements BluetoothProfile {
        if (mService == null || mServerIf == 0) return;

        try {
            mService.clearServices(mServerIf);
            mService.clearServices(mServerIf, mAttributionSource);
            mServices.clear();
        } catch (RemoteException e) {
            Log.e(TAG, "", e);
+12 −7
Original line number Diff line number Diff line
@@ -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) {
Loading