From 27bec23a0f82e22f3b46198f56b6905b13ec5f33 Mon Sep 17 00:00:00 2001 From: Oli Lan Date: Tue, 17 Mar 2020 16:31:10 +0000 Subject: [PATCH] Delete expired CE snapshots of app data when user unlocks. This adds a call to the new destroyCeSnapshotsNotSpecified method of installd, to delete all expired CE snapshots when a user unlocks. See ag/10731882 for the installd side of this change. Bug: 147806409 Test: Manual - install app with rollback enabled, expire the rollback, check that snapshot is deleted. Change-Id: Ife88309d29963d30c27bfe47f20f6f42a9f59086 --- .../java/com/android/server/pm/Installer.java | 24 +++++++++++++++++++ .../rollback/RollbackManagerServiceImpl.java | 5 ++++ 2 files changed, 29 insertions(+) diff --git a/services/core/java/com/android/server/pm/Installer.java b/services/core/java/com/android/server/pm/Installer.java index f37af3aef6579..9fb468e8db6e3 100644 --- a/services/core/java/com/android/server/pm/Installer.java +++ b/services/core/java/com/android/server/pm/Installer.java @@ -723,6 +723,30 @@ public class Installer extends SystemService { } } + /** + * Deletes all snapshots of credential encrypted user data, where the snapshot id is not + * included in {@code retainSnapshotIds}. + * + * @param userId id of the user whose user data snapshots to delete. + * @param retainSnapshotIds ids of the snapshots that should not be deleted. + * + * @return {@code true} if the operation was successful, or {@code false} if a remote call + * shouldn't be continued. See {@link #checkBeforeRemote}. + * + * @throws InstallerException if failed to delete user data snapshot. + */ + public boolean destroyCeSnapshotsNotSpecified(@UserIdInt int userId, + int[] retainSnapshotIds) throws InstallerException { + if (!checkBeforeRemote()) return false; + + try { + mInstalld.destroyCeSnapshotsNotSpecified(null, userId, retainSnapshotIds); + return true; + } catch (Exception e) { + throw InstallerException.from(e); + } + } + /** * Migrates obb data from its legacy location {@code /data/media/obb} to * {@code /data/media/0/Android/obb}. This call is idempotent and a fast no-op if data has diff --git a/services/core/java/com/android/server/rollback/RollbackManagerServiceImpl.java b/services/core/java/com/android/server/rollback/RollbackManagerServiceImpl.java index b50c22ea09e31..5e2c030211e04 100644 --- a/services/core/java/com/android/server/rollback/RollbackManagerServiceImpl.java +++ b/services/core/java/com/android/server/rollback/RollbackManagerServiceImpl.java @@ -504,6 +504,11 @@ class RollbackManagerServiceImpl extends IRollbackManager.Stub { rollbackIds[i] = mRollbacks.get(i).info.getRollbackId(); } ApexManager.getInstance().destroyCeSnapshotsNotSpecified(userId, rollbackIds); + try { + mInstaller.destroyCeSnapshotsNotSpecified(userId, rollbackIds); + } catch (Installer.InstallerException ie) { + Slog.e(TAG, "Failed to delete snapshots for user: " + userId, ie); + } } @WorkerThread