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

Commit c6b82720 authored by Jiakai Zhang's avatar Jiakai Zhang Committed by Android (Google) Code Review
Browse files

Merge changes from topic...

Merge changes from topic "revert-24993368-revert-24773688-dm-profile-validation-SONEGLGSYT-IFGCBNBBOH" into main

* changes:
  Revert^2 "Propagate external profile errors for `adb insta..."
  Revert^2 "Fail adb install on external profile errors."
parents 72c330e5 bd37d28b
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -293,6 +293,13 @@ java_aconfig_library {
    defaults: ["framework-minus-apex-aconfig-java-defaults"],
}

java_aconfig_library {
    name: "android.content.pm.flags-aconfig-java-host",
    aconfig_declarations: "android.content.pm.flags-aconfig",
    host_supported: true,
    defaults: ["framework-minus-apex-aconfig-java-defaults"],
}

// Media BetterTogether
aconfig_declarations {
    name: "com.android.media.flags.bettertogether-aconfig",
+7 −0
Original line number Diff line number Diff line
@@ -370,6 +370,13 @@ public class PackageInstaller {
    public static final String EXTRA_UNARCHIVE_ALL_USERS =
            "android.content.pm.extra.UNARCHIVE_ALL_USERS";

    /**
     * A list of warnings that occurred during installation.
     *
     * @hide
     */
    public static final String EXTRA_WARNINGS = "android.content.pm.extra.WARNINGS";

    /**
     * Streaming installation pending.
     * Caller should make sure DataLoader is able to prepare image and reinitiate the operation.
+7 −0
Original line number Diff line number Diff line
@@ -43,3 +43,10 @@ flag {
    description: "Feature flag to enable the feature to retrieve package info without installation."
    bug: "269149275"
}

flag {
    name: "use_art_service_v2"
    namespace: "package_manager_service"
    description: "Feature flag to enable the features that rely on new ART Service APIs that are in the VIC version of the ART module."
    bug: "304741685"
}
+44 −13
Original line number Diff line number Diff line
@@ -22,6 +22,8 @@ import static android.content.pm.PackageManager.INSTALL_SCENARIO_DEFAULT;
import static android.content.pm.PackageManager.INSTALL_SUCCEEDED;
import static android.os.Process.INVALID_UID;

import static com.android.server.art.model.DexoptResult.DexContainerFileDexoptResult;
import static com.android.server.art.model.DexoptResult.PackageDexoptResult;
import static com.android.server.pm.PackageManagerService.EMPTY_INT_ARRAY;
import static com.android.server.pm.PackageManagerService.SCAN_AS_INSTANT_APP;
import static com.android.server.pm.PackageManagerService.TAG;
@@ -32,6 +34,7 @@ import android.apex.ApexInfo;
import android.app.AppOpsManager;
import android.content.pm.ArchivedPackageParcel;
import android.content.pm.DataLoaderType;
import android.content.pm.Flags;
import android.content.pm.IPackageInstallObserver2;
import android.content.pm.PackageInstaller;
import android.content.pm.PackageManager;
@@ -56,6 +59,7 @@ import com.android.server.pm.pkg.parsing.ParsingPackageUtils;

import java.io.File;
import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;

final class InstallRequest {
@@ -147,6 +151,9 @@ final class InstallRequest {
    @NonNull
    private int[] mUpdateBroadcastInstantUserIds = EMPTY_INT_ARRAY;

    @NonNull
    private ArrayList<String> mWarnings = new ArrayList<>();

    // New install
    InstallRequest(InstallingSession params) {
        mUserId = params.getUser().getIdentifier();
@@ -658,6 +665,11 @@ final class InstallRequest {
        return mUpdateBroadcastInstantUserIds;
    }

    @NonNull
    public ArrayList<String> getWarnings() {
        return mWarnings;
    }

    public void setScanFlags(int scanFlags) {
        mScanFlags = scanFlags;
    }
@@ -855,6 +867,10 @@ final class InstallRequest {
        }
    }

    public void addWarning(@NonNull String warning) {
        mWarnings.add(warning);
    }

    public void onPrepareStarted() {
        if (mPackageMetrics != null) {
            mPackageMetrics.onStepStarted(PackageMetrics.STEP_PREPARE);
@@ -904,23 +920,38 @@ final class InstallRequest {
    }

    public void onDexoptFinished(DexoptResult dexoptResult) {
        if (mPackageMetrics == null) {
            return;
        // Only report external profile warnings when installing from adb. The goal is to warn app
        // developers if they have provided bad external profiles, so it's not beneficial to report
        // those warnings in the normal app install workflow.
        if (isInstallFromAdb() && Flags.useArtServiceV2()) {
            var externalProfileErrors = new LinkedHashSet<String>();
            for (PackageDexoptResult packageResult : dexoptResult.getPackageDexoptResults()) {
                for (DexContainerFileDexoptResult fileResult :
                        packageResult.getDexContainerFileDexoptResults()) {
                    externalProfileErrors.addAll(fileResult.getExternalProfileErrors());
                }
        mDexoptStatus = dexoptResult.getFinalStatus();
        if (mDexoptStatus != DexoptResult.DEXOPT_PERFORMED) {
            return;
            }
            if (!externalProfileErrors.isEmpty()) {
                addWarning("Error occurred during dexopt when processing external profiles:\n  "
                        + String.join("\n  ", externalProfileErrors));
            }
        }

        // Report dexopt metrics.
        if (mPackageMetrics != null) {
            mDexoptStatus = dexoptResult.getFinalStatus();
            if (mDexoptStatus == DexoptResult.DEXOPT_PERFORMED) {
                long durationMillis = 0;
        for (DexoptResult.PackageDexoptResult packageResult :
                dexoptResult.getPackageDexoptResults()) {
            for (DexoptResult.DexContainerFileDexoptResult fileResult :
                for (PackageDexoptResult packageResult : dexoptResult.getPackageDexoptResults()) {
                    for (DexContainerFileDexoptResult fileResult :
                            packageResult.getDexContainerFileDexoptResults()) {
                        durationMillis += fileResult.getDex2oatWallTimeMillis();
                    }
                }
                mPackageMetrics.onStepFinished(PackageMetrics.STEP_DEXOPT, durationMillis);
            }
        }
    }

    public void onInstallCompleted() {
        if (getReturnCode() == INSTALL_SUCCEEDED) {
+30 −1
Original line number Diff line number Diff line
@@ -2930,15 +2930,40 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub {
     * @return a future that will be completed when the whole process is completed.
     */
    private CompletableFuture<Void> install() {
        // `futures` either contains only one session (`this`) or contains one parent session
        // (`this`) and n-1 child sessions.
        List<CompletableFuture<InstallResult>> futures = installNonStaged();
        CompletableFuture<InstallResult>[] arr = new CompletableFuture[futures.size()];
        return CompletableFuture.allOf(futures.toArray(arr)).whenComplete((r, t) -> {
            if (t == null) {
                setSessionApplied();
                var multiPackageWarnings = new ArrayList<String>();
                if (isMultiPackage()) {
                    // This is a parent session. Collect warnings from children.
                    for (CompletableFuture<InstallResult> f : futures) {
                        InstallResult result = f.join();
                        if (result.session != this && result.extras != null) {
                            ArrayList<String> childWarnings = result.extras.getStringArrayList(
                                    PackageInstaller.EXTRA_WARNINGS);
                            if (!ArrayUtils.isEmpty(childWarnings)) {
                                multiPackageWarnings.addAll(childWarnings);
                            }
                        }
                    }
                }
                for (CompletableFuture<InstallResult> f : futures) {
                    InstallResult result = f.join();
                    Bundle extras = result.extras;
                    if (isMultiPackage() && result.session == this
                            && !multiPackageWarnings.isEmpty()) {
                        if (extras == null) {
                            extras = new Bundle();
                        }
                        extras.putStringArrayList(
                                PackageInstaller.EXTRA_WARNINGS, multiPackageWarnings);
                    }
                    result.session.dispatchSessionFinished(
                            INSTALL_SUCCEEDED, "Session installed", result.extras);
                            INSTALL_SUCCEEDED, "Session installed", extras);
                }
            } else {
                PackageManagerException e = (PackageManagerException) t.getCause();
@@ -5189,6 +5214,10 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub {
            if (!TextUtils.isEmpty(existing)) {
                fillIn.putExtra(PackageInstaller.EXTRA_OTHER_PACKAGE_NAME, existing);
            }
            ArrayList<String> warnings = extras.getStringArrayList(PackageInstaller.EXTRA_WARNINGS);
            if (!ArrayUtils.isEmpty(warnings)) {
                fillIn.putStringArrayListExtra(PackageInstaller.EXTRA_WARNINGS, warnings);
            }
        }
        try {
            final BroadcastOptions options = BroadcastOptions.makeBasic();
Loading