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

Commit 27f0a7d1 authored by Winson's avatar Winson
Browse files

Fix DomainVerificationShell user/allowed bugs

The USER_ALL was not being applied to the specific package name branch
and the set-app-links-allowed boolean parsing was incorrect.

Bug: 180753593

Test: manual, diagnosed when writing CTS

Change-Id: I3d62972218bca2b4c3b713e5eb7597977d7ce271
parent 7a95ff7a
Loading
Loading
Loading
Loading
+9 −2
Original line number Original line Diff line number Diff line
@@ -473,10 +473,17 @@ public class DomainVerificationService extends SystemService
                    throw DomainVerificationUtils.throwPackageUnavailable(packageName);
                    throw DomainVerificationUtils.throwPackageUnavailable(packageName);
                }
                }


                if (userId == UserHandle.USER_ALL) {
                    for (int aUserId : mConnection.getAllUserIds()) {
                        pkgState.getOrCreateUserState(aUserId)
                                .setLinkHandlingAllowed(allowed);
                    }
                } else {
                    pkgState.getOrCreateUserState(userId)
                    pkgState.getOrCreateUserState(userId)
                            .setLinkHandlingAllowed(allowed);
                            .setLinkHandlingAllowed(allowed);
                }
                }
            }
            }
        }


        mConnection.scheduleWriteSettings();
        mConnection.scheduleWriteSettings();
    }
    }
+46 −23
Original line number Original line Diff line number Diff line
@@ -38,6 +38,8 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Arrays;
import java.util.Collections;
import java.util.Collections;
import java.util.List;
import java.util.List;
import java.util.Locale;
import java.util.function.Function;


public class DomainVerificationShell {
public class DomainVerificationShell {


@@ -226,21 +228,18 @@ public class DomainVerificationShell {


        userId = translateUserId(userId, "runSetAppLinksUserState");
        userId = translateUserId(userId, "runSetAppLinksUserState");


        String enabledString = commandHandler.getNextArgRequired();
        String enabledArg = commandHandler.getNextArg();
        if (TextUtils.isEmpty(enabledArg)) {
            commandHandler.getErrPrintWriter().println("Error: enabled param not specified");
            return false;
        }


        // Manually ensure that "true" and "false" are the only options, to ensure a domain isn't
        // accidentally parsed as a boolean
        boolean enabled;
        boolean enabled;
        switch (enabledString) {
        try {
            case "true":
            enabled = parseEnabled(enabledArg);
                enabled = true;
        } catch (IllegalArgumentException e) {
                break;
            commandHandler.getErrPrintWriter()
            case "false":
                    .println("Error: invalid enabled param: " + e.getMessage());
                enabled = false;
                break;
            default:
                commandHandler.getErrPrintWriter().println(
                        "Invalid enabled param: " + enabledString);
            return false;
            return false;
        }
        }


@@ -255,8 +254,8 @@ public class DomainVerificationShell {
        }
        }


        try {
        try {
            mCallback.setDomainVerificationUserSelectionInternal(userId,
            mCallback.setDomainVerificationUserSelectionInternal(userId, packageName, enabled,
                    packageName, enabled, domains);
                    domains);
        } catch (NameNotFoundException e) {
        } catch (NameNotFoundException e) {
            commandHandler.getErrPrintWriter().println("Package not found: " + packageName);
            commandHandler.getErrPrintWriter().println("Package not found: " + packageName);
            return false;
            return false;
@@ -362,15 +361,12 @@ public class DomainVerificationShell {
    private boolean runSetAppLinksAllowed(@NonNull BasicShellCommandHandler commandHandler) {
    private boolean runSetAppLinksAllowed(@NonNull BasicShellCommandHandler commandHandler) {
        String packageName = null;
        String packageName = null;
        Integer userId = null;
        Integer userId = null;
        Boolean allowed = null;
        String option;
        String option;
        while ((option = commandHandler.getNextOption()) != null) {
        while ((option = commandHandler.getNextOption()) != null) {
            if (option.equals("--package")) {
            if (option.equals("--package")) {
                packageName = commandHandler.getNextArgRequired();
                packageName = commandHandler.getNextArg();
            } if (option.equals("--user")) {
            } else if (option.equals("--user")) {
                userId = UserHandle.parseUserArg(commandHandler.getNextArgRequired());
                userId = UserHandle.parseUserArg(commandHandler.getNextArgRequired());
            } else if (allowed == null) {
                allowed = Boolean.valueOf(option);
            } else {
            } else {
                commandHandler.getErrPrintWriter().println("Error: unexpected option: " + option);
                commandHandler.getErrPrintWriter().println("Error: unexpected option: " + option);
                return false;
                return false;
@@ -389,11 +385,21 @@ public class DomainVerificationShell {
            return false;
            return false;
        }
        }


        if (allowed == null) {
        String allowedArg = commandHandler.getNextArg();
        if (TextUtils.isEmpty(allowedArg)) {
            commandHandler.getErrPrintWriter().println("Error: allowed setting not specified");
            commandHandler.getErrPrintWriter().println("Error: allowed setting not specified");
            return false;
            return false;
        }
        }


        boolean allowed;
        try {
            allowed = parseEnabled(allowedArg);
        } catch (IllegalArgumentException e) {
            commandHandler.getErrPrintWriter()
                    .println("Error: invalid allowed setting: " + e.getMessage());
            return false;
        }

        userId = translateUserId(userId, "runSetAppLinksAllowed");
        userId = translateUserId(userId, "runSetAppLinksAllowed");


        try {
        try {
@@ -421,6 +427,22 @@ public class DomainVerificationShell {
                userId, true, true, logContext, "pm command");
                userId, true, true, logContext, "pm command");
    }
    }


    /**
     * Manually ensure that "true" and "false" are the only options, to ensure a domain isn't
     * accidentally parsed as a boolean.
     */
    @NonNull
    private boolean parseEnabled(@NonNull String arg) throws IllegalArgumentException {
        switch (arg.toLowerCase(Locale.US)) {
            case "true":
                return true;
            case "false":
                return false;
            default:
                throw new IllegalArgumentException(arg + " is not a valid boolean");
        }
    }

    /**
    /**
     * Separated interface from {@link DomainVerificationManagerInternal} to hide methods that are
     * Separated interface from {@link DomainVerificationManagerInternal} to hide methods that are
     * even more internal, and so that testing is easier.
     * even more internal, and so that testing is easier.
@@ -498,7 +520,8 @@ public class DomainVerificationShell {
        void verifyPackages(@Nullable List<String> packageNames, boolean reVerify);
        void verifyPackages(@Nullable List<String> packageNames, boolean reVerify);


        /**
        /**
         * @see DomainVerificationManagerInternal#printState(IndentingPrintWriter, String, Integer)
         * @see DomainVerificationManagerInternal#printState(IndentingPrintWriter, String, Integer,
         * Function)
         */
         */
        void printState(@NonNull IndentingPrintWriter writer, @Nullable String packageName,
        void printState(@NonNull IndentingPrintWriter writer, @Nullable String packageName,
                @Nullable @UserIdInt Integer userId) throws NameNotFoundException;
                @Nullable @UserIdInt Integer userId) throws NameNotFoundException;