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

Commit 312e10ad authored by Fyodor Kupolov's avatar Fyodor Kupolov
Browse files

Block results if location is disabled in Settings

Apps holding PEERS_MAC_ADDRESS permission can still access scan results.

Bug: 21852542
Change-Id: I75fc289e8965df64efb7ff84fe5a4204904724ab
parent fdb62835
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -309,6 +309,14 @@ final public class Utils {
        return false;
    }

    /**
     * Returns true if the caller holds PEERS_MAC_ADDRESS.
     */
    public static boolean checkCallerHasPeersMacAddressPermission(Context context) {
        return context.checkCallingOrSelfPermission(
                android.Manifest.permission.PEERS_MAC_ADDRESS) == PackageManager.PERMISSION_GRANTED;
    }

    /**
     * Return true if the specified package name is a foreground app.
     *
+13 −1
Original line number Diff line number Diff line
@@ -34,10 +34,13 @@ import android.bluetooth.le.ScanRecord;
import android.bluetooth.le.ScanResult;
import android.bluetooth.le.ScanSettings;
import android.content.Intent;
import android.os.Binder;
import android.os.IBinder;
import android.os.ParcelUuid;
import android.os.RemoteException;
import android.os.SystemClock;
import android.os.UserHandle;
import android.provider.Settings;
import android.util.Log;

import com.android.bluetooth.Utils;
@@ -579,6 +582,9 @@ public class GattService extends ProfileService {
    void onScanResult(String address, int rssi, byte[] adv_data) {
        if (VDBG) Log.d(TAG, "onScanResult() - address=" + address
                    + ", rssi=" + rssi);
        boolean locationEnabled = Settings.Secure.getInt(getContentResolver(),
                Settings.Secure.LOCATION_MODE, Settings.Secure.LOCATION_MODE_OFF)
                != Settings.Secure.LOCATION_MODE_OFF;
        List<UUID> remoteUuids = parseUuids(adv_data);
        for (ScanClient client : mScanManager.getRegularScanQueue()) {
            if (client.uuids.length > 0) {
@@ -602,7 +608,11 @@ public class GattService extends ProfileService {
                            .getRemoteDevice(address);
                    ScanResult result = new ScanResult(device, ScanRecord.parseFromBytes(adv_data),
                            rssi, SystemClock.elapsedRealtimeNanos());
                    if (client.hasLocationPermission && matchesFilters(client, result)) {
                    // Do no report if location mode is OFF or the client has no location permission
                    // PEERS_MAC_ADDRESS permission holders always get results
                    if ((client.hasPeersMacAddressPermission
                            || (locationEnabled && client.hasLocationPermission))
                            && matchesFilters(client, result)) {
                        try {
                            ScanSettings settings = client.settings;
                            if ((settings.getCallbackType() &
@@ -1364,6 +1374,8 @@ public class GattService extends ProfileService {
                mAppOps, callingPackage);
        final ScanClient scanClient = new ScanClient(appIf, isServer, settings, filters, storages);
        scanClient.hasLocationPermission = hasLocationPermission;
        scanClient.hasPeersMacAddressPermission = Utils.checkCallerHasPeersMacAddressPermission(
                this);
        mScanManager.startScan(scanClient);
    }

+1 −0
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@ import java.util.UUID;
    // App associated with the scan client died.
    boolean appDied;
    boolean hasLocationPermission;
    boolean hasPeersMacAddressPermission;

    private static final ScanSettings DEFAULT_SCAN_SETTINGS = new ScanSettings.Builder()
            .setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY).build();