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

Commit a05ba8ee authored by Oli Lan's avatar Oli Lan
Browse files

Delete expired CE APEX snapshots when user unlocks.

This adds a call to the new destroyCeSnapshotsNotSpecified method
of ApexService, to delete all expired CE snapshots when a user
unlocks.

See ag/10552991 for the apexd side of this change.

Cherry-pick and manual merge of ag/10564717 (from rvc-dev) to avoid
conflict.

Bug: 147806409
Test: Manual - install APEX with rollback enabled, expire the rollback,
check that snapshot is deleted.
Change-Id: Icf31d1dd67449edc22d530798a0d67d329e30b62
parent 1a736377
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