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

Commit e6747b9b authored by Oli Lan's avatar Oli Lan Committed by Android (Google) Code Review
Browse files

Merge "Delete expired CE APEX snapshots when user unlocks."

parents 5d768671 a05ba8ee
Loading
Loading
Loading
Loading
+24 −0
Original line number Diff line number Diff line
@@ -300,6 +300,14 @@ public abstract class ApexManager {
     */
    public abstract boolean destroyDeSnapshots(int rollbackId);

    /**
     * Deletes snapshots of the credential encrypted apex data directories for the specified user,
     * where the rollback id is not included in {@code retainRollbackIds}.
     *
     * @return boolean true if the delete was successful
     */
    public abstract boolean destroyCeSnapshotsNotSpecified(int userId, int[] retainRollbackIds);

    /**
     * Dumps various state information to the provided {@link PrintWriter} object.
     *
@@ -745,6 +753,17 @@ public abstract class ApexManager {
            }
        }

        @Override
        public boolean destroyCeSnapshotsNotSpecified(int userId, int[] retainRollbackIds) {
            try {
                mApexService.destroyCeSnapshotsNotSpecified(userId, retainRollbackIds);
                return true;
            } catch (Exception e) {
                Slog.e(TAG, e.getMessage(), e);
                return false;
            }
        }

        /**
         * Dump information about the packages contained in a particular cache
         * @param packagesCache the cache to print information about.
@@ -962,6 +981,11 @@ public abstract class ApexManager {
            throw new UnsupportedOperationException();
        }

        @Override
        public boolean destroyCeSnapshotsNotSpecified(int userId, int[] retainRollbackIds) {
            return true;
        }

        @Override
        void dump(PrintWriter pw, String packageName) {
            // No-op
+14 −0
Original line number Diff line number Diff line
@@ -64,6 +64,7 @@ import com.android.server.LocalServices;
import com.android.server.PackageWatchdog;
import com.android.server.SystemConfig;
import com.android.server.Watchdog;
import com.android.server.pm.ApexManager;
import com.android.server.pm.Installer;

import java.io.File;
@@ -547,6 +548,19 @@ class RollbackManagerServiceImpl extends IRollbackManager.Stub {
                rollback.commitPendingBackupAndRestoreForUser(userId, mAppDataRollbackHelper);
            }
        });

        getHandler().post(() -> {
            destroyCeSnapshotsForExpiredRollbacks(userId);
        });
    }

    @WorkerThread
    private void destroyCeSnapshotsForExpiredRollbacks(int userId) {
        int[] rollbackIds = new int[mRollbacks.size()];
        for (int i = 0; i < rollbackIds.length; i++) {
            rollbackIds[i] = mRollbacks.get(i).info.getRollbackId();
        }
        ApexManager.getInstance().destroyCeSnapshotsNotSpecified(userId, rollbackIds);
    }

    @WorkerThread