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

Commit b16d9905 authored by Jiakai Zhang's avatar Jiakai Zhang Committed by Automerger Merge Worker
Browse files

Merge changes from topic "dm-profile-validation" into main am: 7e72104d am: f0643a6b

parents af206077 f0643a6b
Loading
Loading
Loading
Loading
+26 −1
Original line number Diff line number Diff line
@@ -2739,15 +2739,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();