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

Commit 57f8b1b5 authored by Song Chun Fan's avatar Song Chun Fan
Browse files

[ADI] allow clearing all experiments at once

If the package name is not specified in the
`clear-developer-verificationn-result` command, clear all experiments at
once.

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

Change-Id: Ie2e73d1815282b48cec8f81e85f10e7dccec5cc7
parent 875ba7d0
Loading
Loading
Loading
Loading
+5 −3
Original line number Diff line number Diff line
@@ -4755,7 +4755,7 @@ class PackageManagerShellCommand extends ShellCommand {
        final PrintWriter pw = getOutPrintWriter();
        try {
            final IPackageInstaller installer = mInterface.getPackageInstaller();
            final String packageName = getNextArgRequired();
            final String packageName = getNextArg();
            installer.clearDeveloperVerificationExperiment(packageName);
        } catch (Exception e) {
            pw.println("Failure [" + e.getMessage() + "]");
@@ -5225,9 +5225,11 @@ class PackageManagerShellCommand extends ShellCommand {
        pw.println("        6 [disconnect]: Verification service disconnected.");
        pw.println("        7 [infeasible]: Verification service was unavailable.");
        pw.println("");
        pw.println("  clear-developer-verification-result PACKAGE");
        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("    result for the given app using set-developer-verification-result.");
        pw.println("    If the package name is not specified, clear all previously set");
        pw.println("    developer verification enforcement policy and results of future sessions");
        pw.println("");
        pw.println("");
        printArtServiceHelp();
+3 −2
Original line number Diff line number Diff line
@@ -696,9 +696,10 @@ public class DeveloperVerifierController {
    }

    /**
     * Clear the experiment associated with a package name if it exists.
     * Clear the experiment associated with a package name if it exists. If the package name is
     * null, clear all experiments.
     */
    public void clearExperiment(String packageName) {
    public void clearExperiment(@Nullable String packageName) {
        mExperimentProvider.clearExperiment(packageName);
    }

+20 −6
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.server.pm.verify.developer;
import static android.content.pm.verify.developer.DeveloperVerificationSession.DEVELOPER_VERIFICATION_INCOMPLETE_NETWORK_UNAVAILABLE;
import static android.content.pm.verify.developer.DeveloperVerificationSession.DEVELOPER_VERIFICATION_INCOMPLETE_UNKNOWN;

import android.annotation.Nullable;
import android.content.pm.PackageInstaller;
import android.content.pm.verify.developer.DeveloperVerificationStatus;
import android.os.Handler;
@@ -29,6 +30,7 @@ import com.android.server.pm.PackageInstallerSession;
import java.time.Duration;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;

public class DeveloperVerifierExperimentProvider {
    @GuardedBy("mExperiments")
@@ -73,15 +75,27 @@ public class DeveloperVerifierExperimentProvider {
    }

    /**
     * Remove the experiment for a package.
     * Remove the experiment for a package. If the package name is null, clear all experiments.
     */
    public void clearExperiment(String packageName) {
    public void clearExperiment(@Nullable String packageName) {
        if (packageName == null) {
            Set<String> packages = mExperiments.keySet();
            synchronized (mExperiments) {
                mExperiments.clear();
            }
            // Remove all previously set cleaning tasks
            for (int i = 0; i < packages.size(); i++) {
                final String pkg = packages.iterator().next();
                mHandler.removeCallbacksAndEqualMessages(getExperimentToken(pkg));
            }
        } else {
            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;