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

Commit 66a23d05 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Add a way to record causePackages for rollbacks."

parents 7fc3aa0a bf5b5c44
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -1698,6 +1698,7 @@ package android.content.rollback {
  public final class RollbackInfo implements android.os.Parcelable {
    method public int describeContents();
    method public java.util.List<android.content.pm.VersionedPackage> getCausePackages();
    method public java.util.List<android.content.rollback.PackageRollbackInfo> getPackages();
    method public int getRollbackId();
    method public int getSessionId();
@@ -1707,7 +1708,7 @@ package android.content.rollback {
  }
  public final class RollbackManager {
    method @RequiresPermission(android.Manifest.permission.MANAGE_ROLLBACKS) public void commitRollback(int, @NonNull android.content.IntentSender);
    method @RequiresPermission(android.Manifest.permission.MANAGE_ROLLBACKS) public void commitRollback(int, @NonNull java.util.List<android.content.pm.VersionedPackage>, @NonNull android.content.IntentSender);
    method @RequiresPermission(android.Manifest.permission.MANAGE_ROLLBACKS) public void expireRollbackForPackage(@NonNull String);
    method @RequiresPermission(android.Manifest.permission.MANAGE_ROLLBACKS) public java.util.List<android.content.rollback.RollbackInfo> getAvailableRollbacks();
    method @RequiresPermission(android.Manifest.permission.MANAGE_ROLLBACKS) @NonNull public java.util.List<android.content.rollback.RollbackInfo> getRecentlyCommittedRollbacks();
+2 −2
Original line number Diff line number Diff line
@@ -26,8 +26,8 @@ interface IRollbackManager {
    ParceledListSlice getAvailableRollbacks();
    ParceledListSlice getRecentlyExecutedRollbacks();

    void commitRollback(int rollbackId, String callerPackageName,
            in IntentSender statusReceiver);
    void commitRollback(int rollbackId, in ParceledListSlice causePackages,
            String callerPackageName, in IntentSender statusReceiver);

    // Exposed for use from the system server only. Callback from the package
    // manager during the install flow when user data can be restored for a given
+17 −1
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package android.content.rollback;

import android.annotation.SystemApi;
import android.content.pm.PackageInstaller;
import android.content.pm.VersionedPackage;
import android.os.Parcel;
import android.os.Parcelable;

@@ -39,15 +40,20 @@ public final class RollbackInfo implements Parcelable {

    private final List<PackageRollbackInfo> mPackages;

    private final List<VersionedPackage> mCausePackages;

    /** @hide */
    public RollbackInfo(int rollbackId, List<PackageRollbackInfo> packages) {
    public RollbackInfo(int rollbackId, List<PackageRollbackInfo> packages,
            List<VersionedPackage> causePackages) {
        this.mRollbackId = rollbackId;
        this.mPackages = packages;
        this.mCausePackages = causePackages;
    }

    private RollbackInfo(Parcel in) {
        mRollbackId = in.readInt();
        mPackages = in.createTypedArrayList(PackageRollbackInfo.CREATOR);
        mCausePackages = in.createTypedArrayList(VersionedPackage.CREATOR);
    }

    /**
@@ -82,6 +88,15 @@ public final class RollbackInfo implements Parcelable {
        return PackageInstaller.SessionInfo.INVALID_ID;
    }

    /**
     * Gets the list of package versions that motivated this rollback.
     * As provided to {@link #commitRollback} when the rollback was committed.
     * This is only applicable for rollbacks that have been committed.
     */
    public List<VersionedPackage> getCausePackages() {
        return mCausePackages;
    }

    @Override
    public int describeContents() {
        return 0;
@@ -91,6 +106,7 @@ public final class RollbackInfo implements Parcelable {
    public void writeToParcel(Parcel out, int flags) {
        out.writeInt(mRollbackId);
        out.writeTypedList(mPackages);
        out.writeTypedList(mCausePackages);
    }

    public static final Parcelable.Creator<RollbackInfo> CREATOR =
+8 −2
Original line number Diff line number Diff line
@@ -22,6 +22,8 @@ import android.annotation.SystemApi;
import android.annotation.SystemService;
import android.content.Context;
import android.content.IntentSender;
import android.content.pm.ParceledListSlice;
import android.content.pm.VersionedPackage;
import android.os.RemoteException;

import java.util.List;
@@ -103,14 +105,18 @@ public final class RollbackManager {
     * TODO: Specify the returns status codes.
     *
     * @param rollbackId ID of the rollback to commit
     * @param causePackages package versions to record as the motivation for this
     *                      rollback.
     * @param statusReceiver where to deliver the results
     * @throws SecurityException if the caller does not have the
     *            MANAGE_ROLLBACKS permission.
     */
    @RequiresPermission(android.Manifest.permission.MANAGE_ROLLBACKS)
    public void commitRollback(int rollbackId, @NonNull IntentSender statusReceiver) {
    public void commitRollback(int rollbackId, @NonNull List<VersionedPackage> causePackages,
            @NonNull IntentSender statusReceiver) {
        try {
            mBinder.commitRollback(rollbackId, mCallerPackageName, statusReceiver);
            mBinder.commitRollback(rollbackId, new ParceledListSlice(causePackages),
                    mCallerPackageName, statusReceiver);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
+10 −7
Original line number Diff line number Diff line
@@ -54,6 +54,7 @@ import java.security.SecureRandom;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
@@ -207,7 +208,8 @@ class RollbackManagerServiceImpl extends IRollbackManager.Stub {
            List<RollbackInfo> rollbacks = new ArrayList<>();
            for (int i = 0; i < mAvailableRollbacks.size(); ++i) {
                RollbackData data = mAvailableRollbacks.get(i);
                rollbacks.add(new RollbackInfo(data.rollbackId, data.packages));
                rollbacks.add(new RollbackInfo(data.rollbackId, data.packages,
                            Collections.emptyList()));
            }
            return new ParceledListSlice<>(rollbacks);
        }
@@ -227,8 +229,8 @@ class RollbackManagerServiceImpl extends IRollbackManager.Stub {
    }

    @Override
    public void commitRollback(int rollbackId, String callerPackageName,
            IntentSender statusReceiver) {
    public void commitRollback(int rollbackId, ParceledListSlice causePackages,
            String callerPackageName, IntentSender statusReceiver) {
        mContext.enforceCallingOrSelfPermission(
                android.Manifest.permission.MANAGE_ROLLBACKS,
                "executeRollback");
@@ -238,7 +240,8 @@ class RollbackManagerServiceImpl extends IRollbackManager.Stub {
        appOps.checkPackage(callingUid, callerPackageName);

        getHandler().post(() ->
                commitRollbackInternal(rollbackId, callerPackageName, statusReceiver));
                commitRollbackInternal(rollbackId, causePackages.getList(),
                    callerPackageName, statusReceiver));
    }

    /**
@@ -246,7 +249,7 @@ class RollbackManagerServiceImpl extends IRollbackManager.Stub {
     * The work is done on the current thread. This may be a long running
     * operation.
     */
    private void commitRollbackInternal(int rollbackId,
    private void commitRollbackInternal(int rollbackId, List<VersionedPackage> causePackages,
            String callerPackageName, IntentSender statusReceiver) {
        Log.i(TAG, "Initiating rollback");

@@ -350,8 +353,8 @@ class RollbackManagerServiceImpl extends IRollbackManager.Stub {
                                return;
                            }

                            addRecentlyExecutedRollback(
                                    new RollbackInfo(data.rollbackId, data.packages));
                            addRecentlyExecutedRollback(new RollbackInfo(
                                        data.rollbackId, data.packages, causePackages));
                            sendSuccess(statusReceiver);

                            Intent broadcast = new Intent(Intent.ACTION_ROLLBACK_COMMITTED);
Loading