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

Commit 9ff28be4 authored by Oli Lan's avatar Oli Lan
Browse files

Allow permission renouncement without RENOUNCE permission in test mode.

This allows permission renouncement to be recognised when the caller
does not have the RENOUNCE_PERMISSIONS permission, when in test mode.

Without this, renouncement cannot be tested because a test apk cannot
be given RENOUNCE_PERMISSIONS, and the shell (whose permissions can be
adopted) does not have BLUETOOTH_SCAN.

Bug: 183625242
Test: atest NearbyDevicesRenouncePermissionTest
Change-Id: If4a7235b9141b9279016671b8745b8ba5afd8f41
parent 3f42f6f9
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -553,12 +553,13 @@ public final class Utils {
    // Suppressed since we're not actually enforcing here
    @SuppressLint("AndroidFrameworkRequiresPermission")
    public static boolean hasDisavowedLocationForScan(
            Context context, String packageName, AttributionSource attributionSource) {
            Context context, String packageName, AttributionSource attributionSource,
            boolean inTestMode) {

        // TODO(b/183625242): Handle multi-step attribution chains here.
        if (attributionSource.getRenouncedPermissions().contains(ACCESS_FINE_LOCATION)
                && context.checkCallingPermission(RENOUNCE_PERMISSIONS)
                == PackageManager.PERMISSION_GRANTED) {
                && (inTestMode || context.checkCallingPermission(RENOUNCE_PERMISSIONS)
                        == PackageManager.PERMISSION_GRANTED)) {
            return true;
        }

+5 −1
Original line number Diff line number Diff line
@@ -284,6 +284,8 @@ public class AdapterService extends Service {
    private HearingAidService mHearingAidService;
    private SapService mSapService;

    private boolean mTestModeEnabled;

    /**
     * Register a {@link ProfileService} with AdapterService.
     *
@@ -2470,7 +2472,8 @@ public class AdapterService extends Service {
        mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
        boolean isQApp = Utils.isQApp(this, callingPackage);
        boolean hasDisavowedLocation =
                Utils.hasDisavowedLocationForScan(this, callingPackage, attributionSource);
                Utils.hasDisavowedLocationForScan(this, callingPackage, attributionSource,
                        mTestModeEnabled);
        String permission = null;
        if (Utils.checkCallerHasNetworkSettingsPermission(this)) {
            permission = android.Manifest.permission.NETWORK_SETTINGS;
@@ -3402,6 +3405,7 @@ public class AdapterService extends Service {
            for (ProfileService profile : mRunningProfiles) {
                profile.setTestModeEnabled(testModeEnabled);
            }
            mTestModeEnabled = true;
            return;
        }

+4 −3
Original line number Diff line number Diff line
@@ -20,7 +20,6 @@ import static android.content.pm.PackageManager.PERMISSION_GRANTED;

import android.annotation.RequiresPermission;
import android.annotation.SuppressLint;
import android.app.ActivityThread;
import android.app.AppOpsManager;
import android.app.PendingIntent;
import android.app.Service;
@@ -2270,7 +2269,8 @@ public class GattService extends ProfileService {
                callingPackage.equals(mExposureNotificationPackage);

        scanClient.hasDisavowedLocation =
                Utils.hasDisavowedLocationForScan(this, callingPackage, attributionSource);
                Utils.hasDisavowedLocationForScan(this, callingPackage, attributionSource,
                        isTestModeEnabled());

        scanClient.isQApp = Utils.isQApp(this, callingPackage);
        if (!scanClient.hasDisavowedLocation) {
@@ -2343,7 +2343,8 @@ public class GattService extends ProfileService {
                callingPackage.equals(mExposureNotificationPackage);

        app.mHasDisavowedLocation =
                Utils.hasDisavowedLocationForScan(this, callingPackage, attributionSource);
                Utils.hasDisavowedLocationForScan(this, callingPackage, attributionSource,
                        isTestModeEnabled());

        app.mIsQApp = Utils.isQApp(this, callingPackage);
        if (!app.mHasDisavowedLocation) {