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

Commit 962a5e72 authored by Christine Hallstrom's avatar Christine Hallstrom Committed by Automerger Merge Worker
Browse files

Merge "Revert "Apply uid of original caller when starting LE scan by...

Merge "Revert "Apply uid of original caller when starting LE scan by PendingIntent"" into main am: f0c7602d

Original change: https://android-review.googlesource.com/c/platform/packages/modules/Bluetooth/+/2755325



Change-Id: I8ff9f551f7bc263f8927238cca6ea9e46dc35d88
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 688eb133 f0c7602d
Loading
Loading
Loading
Loading
+7 −17
Original line number Diff line number Diff line
@@ -209,22 +209,12 @@ public class ContextMap<C, T> {
    private Set<Connection> mConnections = new HashSet<Connection>();
    private final Object mConnectionsLock = new Object();

    /** Add an entry to the application context list. */
    App add(
            UUID uuid,
            WorkSource workSource,
            C callback,
            GattService.PendingIntentInfo piInfo,
            GattService service) {
        int appUid;
        String appName = null;
        if (piInfo != null) {
            appUid = piInfo.callingUid;
            appName = piInfo.callingPackage;
        } else {
            appUid = Binder.getCallingUid();
            appName = service.getPackageManager().getNameForUid(appUid);
        }
    /**
     * Add an entry to the application context list.
     */
    App add(UUID uuid, WorkSource workSource, C callback, T info, GattService service) {
        int appUid = Binder.getCallingUid();
        String appName = service.getPackageManager().getNameForUid(appUid);
        if (appName == null) {
            // Assign an app name if one isn't found
            appName = "Unknown App (UID: " + appUid + ")";
@@ -235,7 +225,7 @@ public class ContextMap<C, T> {
                appScanStats = new AppScanStats(appName, workSource, this, service);
                mAppScanStats.put(appUid, appScanStats);
            }
            App app = new App(uuid, callback, (T) piInfo, appName, appScanStats);
            App app = new App(uuid, callback, info, appName, appScanStats);
            mApps.add(app);
            appScanStats.isRegistered = true;
            return app;
+3 −11
Original line number Diff line number Diff line
@@ -208,7 +208,6 @@ public class GattService extends ProfileService {
        public ScanSettings settings;
        public List<ScanFilter> filters;
        public String callingPackage;
        public int callingUid;

        @Override
        public boolean equals(Object other) {
@@ -3258,22 +3257,15 @@ public class GattService extends ProfileService {
        settings = enforceReportDelayFloor(settings);
        enforcePrivilegedPermissionIfNeeded(filters);
        UUID uuid = UUID.randomUUID();
        String callingPackage = attributionSource.getPackageName();
        int callingUid = attributionSource.getUid();
        if (DBG) {
            Log.d(
                    TAG,
                    "startScan(PI) -"
                            + (" UUID=" + uuid)
                            + (" Package=" + callingPackage)
                            + (" UID=" + callingUid));
            Log.d(TAG, "startScan(PI) - UUID=" + uuid);
        }
        String callingPackage = attributionSource.getPackageName();
        PendingIntentInfo piInfo = new PendingIntentInfo();
        piInfo.intent = pendingIntent;
        piInfo.settings = settings;
        piInfo.filters = filters;
        piInfo.callingPackage = callingPackage;
        piInfo.callingUid = callingUid;

        // Don't start scan if the Pi scan already in mScannerMap.
        if (mScannerMap.getByContextInfo(piInfo) != null) {
@@ -3324,7 +3316,7 @@ public class GattService extends ProfileService {
    void continuePiStartScan(int scannerId, ScannerMap.App app) {
        final PendingIntentInfo piInfo = app.info;
        final ScanClient scanClient =
                new ScanClient(scannerId, piInfo.settings, piInfo.filters, piInfo.callingUid);
                new ScanClient(scannerId, piInfo.settings, piInfo.filters);
        scanClient.hasLocationPermission = app.hasLocationPermission;
        scanClient.userHandle = app.mUserHandle;
        scanClient.isQApp = checkCallerTargetSdk(this, app.name, Build.VERSION_CODES.Q);
+1 −5
Original line number Diff line number Diff line
@@ -58,15 +58,11 @@ import java.util.Objects;
    }

    ScanClient(int scannerId, ScanSettings settings, List<ScanFilter> filters) {
        this(scannerId, settings, filters, Binder.getCallingUid());
    }

    ScanClient(int scannerId, ScanSettings settings, List<ScanFilter> filters, int appUid) {
        this.scannerId = scannerId;
        this.settings = settings;
        this.scanModeApp = settings.getScanMode();
        this.filters = filters;
        this.appUid = appUid;
        this.appUid = Binder.getCallingUid();
    }

    @Override
+0 −13
Original line number Diff line number Diff line
@@ -387,8 +387,6 @@ public class ScanManager {
                Log.d(TAG, "handling starting scan");
            }

            fetchAppForegroundState(client);

            if (!isScanSupported(client)) {
                Log.e(TAG, "Scan settings not supported");
                return;
@@ -734,17 +732,6 @@ public class ScanManager {
            return mIsUidForegroundMap.get(client.appUid, DEFAULT_UID_IS_FOREGROUND);
        }

        private void fetchAppForegroundState(ScanClient client) {
            if (mActivityManager == null) {
                return;
            }
            int importance = mActivityManager.getUidImportance(client.appUid);
            boolean isForeground =
                    importance
                            <= ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND_SERVICE;
            mIsUidForegroundMap.put(client.appUid, isForeground);
        }

        private boolean updateScanModeBeforeStart(ScanClient client) {
            if (upgradeScanModeBeforeStart(client)) {
                return true;
+0 −27
Original line number Diff line number Diff line
@@ -61,7 +61,6 @@ import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentMatcher;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;

@@ -263,32 +262,6 @@ public class GattServiceTest {
        verify(mScanManager).startScan(any());
    }

    @Test
    public void continuePiStartScanCheckUid() {
        int scannerId = 1;

        mPiInfo.settings = new ScanSettings.Builder().build();
        mPiInfo.callingUid = 123;
        mApp.info = mPiInfo;

        AppScanStats appScanStats = mock(AppScanStats.class);
        doReturn(appScanStats).when(mScannerMap).getAppScanStatsById(scannerId);

        mService.continuePiStartScan(scannerId, mApp);

        verify(appScanStats)
                .recordScanStart(mPiInfo.settings, mPiInfo.filters, false, false, scannerId);
        verify(mScanManager)
                .startScan(
                        argThat(
                                new ArgumentMatcher<ScanClient>() {
                                    @Override
                                    public boolean matches(ScanClient client) {
                                        return mPiInfo.callingUid == client.appUid;
                                    }
                                }));
    }

    @Test
    public void onBatchScanReportsInternal_deliverBatchScan() throws RemoteException {
        int status = 1;