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

Commit 408e0893 authored by Hassan Ali's avatar Hassan Ali Committed by Android (Google) Code Review
Browse files

Merge changes from topics "revert-24773688-dm-profile-validation-SONEGLGSYT",...

Merge changes from topics "revert-24773688-dm-profile-validation-SONEGLGSYT", "revert-24811599-dm-profile-validation-multi-package-WNNOMIVWHU" into main

* changes:
  Revert "Fail adb install on external profile errors."
  Revert "Propagate external profile errors for `adb install-multi..."
parents baaa71a1 979e2b03
Loading
Loading
Loading
Loading
+0 −7
Original line number Original line Diff line number Diff line
@@ -370,13 +370,6 @@ public class PackageInstaller {
    public static final String EXTRA_UNARCHIVE_ALL_USERS =
    public static final String EXTRA_UNARCHIVE_ALL_USERS =
            "android.content.pm.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.
     * Streaming installation pending.
     * Caller should make sure DataLoader is able to prepare image and reinitiate the operation.
     * Caller should make sure DataLoader is able to prepare image and reinitiate the operation.
+13 −43
Original line number Original line Diff line number Diff line
@@ -22,8 +22,6 @@ import static android.content.pm.PackageManager.INSTALL_SCENARIO_DEFAULT;
import static android.content.pm.PackageManager.INSTALL_SUCCEEDED;
import static android.content.pm.PackageManager.INSTALL_SUCCEEDED;
import static android.os.Process.INVALID_UID;
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.EMPTY_INT_ARRAY;
import static com.android.server.pm.PackageManagerService.SCAN_AS_INSTANT_APP;
import static com.android.server.pm.PackageManagerService.SCAN_AS_INSTANT_APP;
import static com.android.server.pm.PackageManagerService.TAG;
import static com.android.server.pm.PackageManagerService.TAG;
@@ -58,7 +56,6 @@ import com.android.server.pm.pkg.parsing.ParsingPackageUtils;


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


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


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

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


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

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


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

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


    public void onDexoptFinished(DexoptResult dexoptResult) {
    public void onDexoptFinished(DexoptResult dexoptResult) {
        // Only report external profile warnings when installing from adb. The goal is to warn app
        if (mPackageMetrics == null) {
        // developers if they have provided bad external profiles, so it's not beneficial to report
            return;
        // those warnings in the normal app install workflow.
        if (isInstallFromAdb()) {
            var externalProfileErrors = new LinkedHashSet<String>();
            for (PackageDexoptResult packageResult : dexoptResult.getPackageDexoptResults()) {
                for (DexContainerFileDexoptResult fileResult :
                        packageResult.getDexContainerFileDexoptResults()) {
                    externalProfileErrors.addAll(fileResult.getExternalProfileErrors());
                }
            }
            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();
        mDexoptStatus = dexoptResult.getFinalStatus();
            if (mDexoptStatus == DexoptResult.DEXOPT_PERFORMED) {
        if (mDexoptStatus != DexoptResult.DEXOPT_PERFORMED) {
            return;
        }
        long durationMillis = 0;
        long durationMillis = 0;
                for (PackageDexoptResult packageResult : dexoptResult.getPackageDexoptResults()) {
        for (DexoptResult.PackageDexoptResult packageResult :
                    for (DexContainerFileDexoptResult fileResult :
                dexoptResult.getPackageDexoptResults()) {
            for (DexoptResult.DexContainerFileDexoptResult fileResult :
                    packageResult.getDexContainerFileDexoptResults()) {
                    packageResult.getDexContainerFileDexoptResults()) {
                durationMillis += fileResult.getDex2oatWallTimeMillis();
                durationMillis += fileResult.getDex2oatWallTimeMillis();
            }
            }
        }
        }
        mPackageMetrics.onStepFinished(PackageMetrics.STEP_DEXOPT, durationMillis);
        mPackageMetrics.onStepFinished(PackageMetrics.STEP_DEXOPT, durationMillis);
    }
    }
        }
    }


    public void onInstallCompleted() {
    public void onInstallCompleted() {
        if (getReturnCode() == INSTALL_SUCCEEDED) {
        if (getReturnCode() == INSTALL_SUCCEEDED) {
+1 −30
Original line number Original line Diff line number Diff line
@@ -2930,40 +2930,15 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub {
     * @return a future that will be completed when the whole process is completed.
     * @return a future that will be completed when the whole process is completed.
     */
     */
    private CompletableFuture<Void> install() {
    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();
        List<CompletableFuture<InstallResult>> futures = installNonStaged();
        CompletableFuture<InstallResult>[] arr = new CompletableFuture[futures.size()];
        CompletableFuture<InstallResult>[] arr = new CompletableFuture[futures.size()];
        return CompletableFuture.allOf(futures.toArray(arr)).whenComplete((r, t) -> {
        return CompletableFuture.allOf(futures.toArray(arr)).whenComplete((r, t) -> {
            if (t == null) {
            if (t == null) {
                setSessionApplied();
                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) {
                for (CompletableFuture<InstallResult> f : futures) {
                    InstallResult result = f.join();
                    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(
                    result.session.dispatchSessionFinished(
                            INSTALL_SUCCEEDED, "Session installed", extras);
                            INSTALL_SUCCEEDED, "Session installed", result.extras);
                }
                }
            } else {
            } else {
                PackageManagerException e = (PackageManagerException) t.getCause();
                PackageManagerException e = (PackageManagerException) t.getCause();
@@ -5214,10 +5189,6 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub {
            if (!TextUtils.isEmpty(existing)) {
            if (!TextUtils.isEmpty(existing)) {
                fillIn.putExtra(PackageInstaller.EXTRA_OTHER_PACKAGE_NAME, 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 {
        try {
            final BroadcastOptions options = BroadcastOptions.makeBasic();
            final BroadcastOptions options = BroadcastOptions.makeBasic();
+0 −3
Original line number Original line Diff line number Diff line
@@ -1434,9 +1434,6 @@ public class PackageManagerService implements PackageSender, TestUtilityService
                break;
                break;
            }
            }
        }
        }
        if (!request.getWarnings().isEmpty()) {
            extras.putStringArrayList(PackageInstaller.EXTRA_WARNINGS, request.getWarnings());
        }
        return extras;
        return extras;
    }
    }


+3 −14
Original line number Original line Diff line number Diff line
@@ -4397,21 +4397,10 @@ class PackageManagerShellCommand extends ShellCommand {
            session.commit(receiver.getIntentSender());
            session.commit(receiver.getIntentSender());
            if (!session.isStaged()) {
            if (!session.isStaged()) {
                final Intent result = receiver.getResult();
                final Intent result = receiver.getResult();
                int status = result.getIntExtra(
                final int status = result.getIntExtra(PackageInstaller.EXTRA_STATUS,
                        PackageInstaller.EXTRA_STATUS, PackageInstaller.STATUS_FAILURE);
                        PackageInstaller.STATUS_FAILURE);
                List<String> warnings =
                        result.getStringArrayListExtra(PackageInstaller.EXTRA_WARNINGS);
                if (status == PackageInstaller.STATUS_SUCCESS) {
                if (status == PackageInstaller.STATUS_SUCCESS) {
                    if (!ArrayUtils.isEmpty(warnings)) {
                    if (logSuccess) {
                        // Don't start the output string with "Success" because that will make adb
                        // treat this as a success.
                        for (String warning : warnings) {
                            pw.println("Warning: " + warning);
                        }
                        // Treat warnings as failure to draw app developers' attention.
                        status = PackageInstaller.STATUS_FAILURE;
                        pw.println("Completed with warning(s)");
                    } else if (logSuccess) {
                        pw.println("Success");
                        pw.println("Success");
                    }
                    }
                } else {
                } else {