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

Commit 53bdb4b8 authored by Oli Lan's avatar Oli Lan Committed by Android (Google) Code Review
Browse files

Merge "Pass AttributionSource to bluetooth scanning methods." into sc-dev

parents 11ce311d ec2ca2d8
Loading
Loading
Loading
Loading
+8 −8
Original line number Diff line number Diff line
@@ -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);
+7 −10
Original line number Diff line number Diff line
@@ -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);