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

Commit 96410a8a authored by Wei Wang's avatar Wei Wang Committed by Android (Google) Code Review
Browse files

Merge "Enforce permissions for BLE hidden APIs." into lmp-dev

parents 700ea968 d1eeae33
Loading
Loading
Loading
Loading
+20 −0
Original line number Diff line number Diff line
@@ -1274,6 +1274,9 @@ public class GattService extends ProfileService {
            List<ScanFilter> filters, List<List<ResultStorageDescriptor>> storages) {
        if (DBG) Log.d(TAG, "start scan with filters");
        enforceAdminPermission();
        if (needsPrivilegedPermissionForScan(settings)) {
            enforcePrivilegedPermission();
        }
        mScanManager.startScan(new ScanClient(appIf, isServer, settings, filters, storages));
    }

@@ -1953,6 +1956,23 @@ public class GattService extends ProfileService {
        enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM, "Need BLUETOOTH_ADMIN permission");
    }

    private boolean needsPrivilegedPermissionForScan(ScanSettings settings) {
        // Regular scan, no special permission.
        if (settings == null) {
            return false;
        }
        // Hidden API for onLost/onFound
        if (settings.getScanMode() != ScanSettings.CALLBACK_TYPE_ALL_MATCHES) {
            return true;
        }
        // Regular scan, no special permission.
        if (settings.getReportDelayMillis() == 0) {
            return false;
        }
        // Batch scan, truncated mode needs permission.
        return settings.getScanResultType() == ScanSettings.SCAN_RESULT_TYPE_ABBREVIATED;
    }

    // Enforce caller has BLUETOOTH_PRIVILEGED permission. A {@link SecurityException} will be
    // thrown if the caller app does not have BLUETOOTH_PRIVILEGED permission.
    private void enforcePrivilegedPermission() {