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

Commit cde1eec0 authored by Song Chun Fan's avatar Song Chun Fan
Browse files

[ADI] add a command to clear previously set local experiments

Adding this command so that the user can clear the previously set
experiment for a package. Otherwise the user will have to wait for the
timeout which is inconvenient. This command can also be used in
automated testing for improving test robustness.

BUG: 399436145
Test: manually
FLAG: android.content.pm.verification_service

Change-Id: I5bb0a6570e50efd9e47286c025da23734e94a06f
parent 410d4350
Loading
Loading
Loading
Loading
+1 −0
Original line number Original line Diff line number Diff line
@@ -110,4 +110,5 @@ interface IPackageInstaller {
    DeveloperVerificationUserConfirmationInfo getDeveloperVerificationUserConfirmationInfo(int sessionId);
    DeveloperVerificationUserConfirmationInfo getDeveloperVerificationUserConfirmationInfo(int sessionId);


    void addDeveloperVerificationExperiment(String packageName, int verificationPolicy, in int[] results);
    void addDeveloperVerificationExperiment(String packageName, int verificationPolicy, in int[] results);
    void clearDeveloperVerificationExperiment(String packagename);
}
}
+5 −0
Original line number Original line Diff line number Diff line
@@ -2142,6 +2142,11 @@ public class PackageInstallerService extends IPackageInstaller.Stub implements
        mDeveloperVerifierController.addExperiment(packageName, verificationPolicy, resultsList);
        mDeveloperVerifierController.addExperiment(packageName, verificationPolicy, resultsList);
    }
    }


    @Override
    public void clearDeveloperVerificationExperiment(String packageName) {
        mDeveloperVerifierController.clearExperiment(packageName);
    }

    void onUserAdded(int userId) {
    void onUserAdded(int userId) {
        synchronized (mDeveloperVerificationPolicyPerUser) {
        synchronized (mDeveloperVerificationPolicyPerUser) {
            mDeveloperVerificationPolicyPerUser.put(userId, DEFAULT_VERIFICATION_POLICY);
            mDeveloperVerificationPolicyPerUser.put(userId, DEFAULT_VERIFICATION_POLICY);
+24 −0
Original line number Original line Diff line number Diff line
@@ -406,6 +406,8 @@ class PackageManagerShellCommand extends ShellCommand {
                    return runGetDeveloperVerificationServiceProvider();
                    return runGetDeveloperVerificationServiceProvider();
                case "set-developer-verification-result":
                case "set-developer-verification-result":
                    return runSetDeveloperVerificationResult();
                    return runSetDeveloperVerificationResult();
                case "clear-developer-verification-result":
                    return runClearDeveloperVerificationResult();
                default: {
                default: {
                    if (ART_SERVICE_COMMANDS.contains(cmd)) {
                    if (ART_SERVICE_COMMANDS.contains(cmd)) {
                        return runArtServiceCommand();
                        return runArtServiceCommand();
@@ -4749,6 +4751,19 @@ class PackageManagerShellCommand extends ShellCommand {
        return 0;
        return 0;
    }
    }


    private int runClearDeveloperVerificationResult() {
        final PrintWriter pw = getOutPrintWriter();
        try {
            final IPackageInstaller installer = mInterface.getPackageInstaller();
            final String packageName = getNextArgRequired();
            installer.clearDeveloperVerificationExperiment(packageName);
        } catch (Exception e) {
            pw.println("Failure [" + e.getMessage() + "]");
            return 1;
        }
        return 0;
    }

    @Override
    @Override
    public void onHelp() {
    public void onHelp() {
        final PrintWriter pw = getOutPrintWriter();
        final PrintWriter pw = getOutPrintWriter();
@@ -5151,6 +5166,7 @@ class PackageManagerShellCommand extends ShellCommand {
        pw.println("");
        pw.println("");
        pw.println("  clear-package-preferred-activities <PACKAGE>");
        pw.println("  clear-package-preferred-activities <PACKAGE>");
        pw.println("    Remove the preferred activity mappings for the given package.");
        pw.println("    Remove the preferred activity mappings for the given package.");
        pw.println("");
        pw.println("  wait-for-handler --timeout <MILLIS>");
        pw.println("  wait-for-handler --timeout <MILLIS>");
        pw.println("    Wait for a given amount of time till the package manager handler finishes");
        pw.println("    Wait for a given amount of time till the package manager handler finishes");
        pw.println("    handling all pending messages.");
        pw.println("    handling all pending messages.");
@@ -5177,15 +5193,19 @@ class PackageManagerShellCommand extends ShellCommand {
        pw.println("    Displays the component name of the domain verification agent on device.");
        pw.println("    Displays the component name of the domain verification agent on device.");
        pw.println("    If the component isn't enabled, an error message will be displayed.");
        pw.println("    If the component isn't enabled, an error message will be displayed.");
        pw.println("      --user: return the agent of the given user (SYSTEM_USER if unspecified)");
        pw.println("      --user: return the agent of the given user (SYSTEM_USER if unspecified)");
        pw.println("");
        pw.println("  get-package-storage-stats [--user <USER_ID>] <PACKAGE>");
        pw.println("  get-package-storage-stats [--user <USER_ID>] <PACKAGE>");
        pw.println("    Return the storage stats for the given app, if present");
        pw.println("    Return the storage stats for the given app, if present");
        pw.println("");
        pw.println("  get-developer-verification-policy [--user USER_ID]");
        pw.println("  get-developer-verification-policy [--user USER_ID]");
        pw.println("    Display current verification enforcement policy which will be applied to");
        pw.println("    Display current verification enforcement policy which will be applied to");
        pw.println("    all the future installation sessions");
        pw.println("    all the future installation sessions");
        pw.println("      --user: show the policy of the given user (SYSTEM_USER if unspecified)");
        pw.println("      --user: show the policy of the given user (SYSTEM_USER if unspecified)");
        pw.println("");
        pw.println("  get-developer-verification-service-provider");
        pw.println("  get-developer-verification-service-provider");
        pw.println("    Displays component name of developer verification service provider.");
        pw.println("    Displays component name of developer verification service provider.");
        pw.println("      --user: show the policy of the given user (SYSTEM_USER if unspecified)");
        pw.println("      --user: show the policy of the given user (SYSTEM_USER if unspecified)");
        pw.println("");
        pw.println("  set-developer-verification-result PACKAGE POLICY RESULT [RESULT...]");
        pw.println("  set-developer-verification-result PACKAGE POLICY RESULT [RESULT...]");
        pw.println("    Set the developer verification enforcement policy and the result(s)");
        pw.println("    Set the developer verification enforcement policy and the result(s)");
        pw.println("    in sequence for the next N verification sessions for the given app where");
        pw.println("    in sequence for the next N verification sessions for the given app where");
@@ -5205,6 +5225,10 @@ class PackageManagerShellCommand extends ShellCommand {
        pw.println("        6 [disconnect]: Verification service disconnected.");
        pw.println("        6 [disconnect]: Verification service disconnected.");
        pw.println("        7 [infeasible]: Verification service was unavailable.");
        pw.println("        7 [infeasible]: Verification service was unavailable.");
        pw.println("");
        pw.println("");
        pw.println("  clear-developer-verification-result PACKAGE");
        pw.println("    Clear any previously set developer verification enforcement policy and");
        pw.println("    result for the given app using set-developer-verification-result");
        pw.println("");
        pw.println("");
        pw.println("");
        printArtServiceHelp();
        printArtServiceHelp();
        pw.println("");
        pw.println("");
+7 −0
Original line number Original line Diff line number Diff line
@@ -695,6 +695,13 @@ public class DeveloperVerifierController {
        mExperimentProvider.addExperiment(packageName, verificationPolicy, status);
        mExperimentProvider.addExperiment(packageName, verificationPolicy, status);
    }
    }


    /**
     * Clear the experiment associated with a package name if it exists.
     */
    public void clearExperiment(String packageName) {
        mExperimentProvider.clearExperiment(packageName);
    }

    /**
    /**
     * Check if there is an experiment for the given package.
     * Check if there is an experiment for the given package.
     */
     */
+16 −1
Original line number Original line Diff line number Diff line
@@ -61,7 +61,8 @@ public class DeveloperVerifierExperimentProvider {
            mExperiments.put(packageName,
            mExperiments.put(packageName,
                    new ExperimentConfiguration(verificationPolicy, validStatuses));
                    new ExperimentConfiguration(verificationPolicy, validStatuses));
        }
        }
        final String token = "addExperiment:" + packageName;
        final String token = getExperimentToken(packageName);
        // Remove any previously set cleaning task for this package
        mHandler.removeCallbacksAndEqualMessages(token);
        mHandler.removeCallbacksAndEqualMessages(token);
        // Automatically remove the experiment after timeout
        // Automatically remove the experiment after timeout
        mHandler.postDelayed(() -> {
        mHandler.postDelayed(() -> {
@@ -71,6 +72,20 @@ public class DeveloperVerifierExperimentProvider {
        }, token, EXPERIMENT_TIMEOUT_MILLIS);
        }, token, EXPERIMENT_TIMEOUT_MILLIS);
    }
    }


    /**
     * Remove the experiment for a package.
     */
    public void clearExperiment(String packageName) {
        synchronized (mExperiments) {
            mExperiments.remove(packageName);
        }
        // Remove any previously set cleaning task for this package
        mHandler.removeCallbacksAndEqualMessages(getExperimentToken(packageName));
    }

    private String getExperimentToken(String packageName) {
        return "addExperiment:" + packageName;
    }
    /**
    /**
     * Check if the provider has an experiment for the given package.
     * Check if the provider has an experiment for the given package.
     */
     */