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

Commit 1d99c391 authored by Christopher Tate's avatar Christopher Tate
Browse files

Cancel alarms & jobs when an app's data is cleared

In the same bit of code, fix a system restore issue:  in the
course of setup + restore, we reestablish permission grants and
notification state up front for the to-be-restored app, and
then bring in its data.  However, a data wipe is part of the
prologue for that data delivery -- so we were inadvertently
unwinding the permission grants and notification state restore
that we'd just performed.  Now, we distinguish the restore flow
from other clear-data operations so we don't unwind that operation.

Finally take the opportunity to elide a lot of copypasta code into
a single predicate-driven implementation.

Bug: 67508896
Bug: 69538432
Test: atest android.app.cts.AlarmManagerTest

Change-Id: I15c912c3c99645599ae9bd6fb7337fa86b4e5757
parent ab39cc57
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -2613,7 +2613,7 @@ public class ActivityManager {
            Manifest.permission.ACCESS_INSTANT_APPS})
    public boolean clearApplicationUserData(String packageName, IPackageDataObserver observer) {
        try {
            return getService().clearApplicationUserData(packageName,
            return getService().clearApplicationUserData(packageName, false,
                    observer, UserHandle.myUserId());
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
+1 −1
Original line number Diff line number Diff line
@@ -207,7 +207,7 @@ interface IActivityManager {
    boolean moveActivityTaskToBack(in IBinder token, boolean nonRoot);
    void getMemoryInfo(out ActivityManager.MemoryInfo outInfo);
    List<ActivityManager.ProcessErrorStateInfo> getProcessesInErrorState();
    boolean clearApplicationUserData(in String packageName,
    boolean clearApplicationUserData(in String packageName, boolean keepState,
            in IPackageDataObserver observer, int userId);
    void forceStopPackage(in String packageName, int userId);
    boolean killPids(in int[] pids, in String reason, boolean secure);
+6 −2
Original line number Diff line number Diff line
@@ -1520,7 +1520,11 @@ public class RefactoredBackupManagerService implements BackupManagerServiceInter
    }

    // clear an application's data, blocking until the operation completes or times out
    public void clearApplicationDataSynchronous(String packageName) {
    // if keepSystemState is true, we intentionally do not also clear system state that
    // would ordinarily also be cleared, because we aren't actually wiping the app back
    // to empty; we're bringing it into the actual expected state related to the already-
    // restored notification state etc.
    public void clearApplicationDataSynchronous(String packageName, boolean keepSystemState) {
        // Don't wipe packages marked allowClearUserData=false
        try {
            PackageInfo info = mPackageManager.getPackageInfo(packageName, 0);
@@ -1541,7 +1545,7 @@ public class RefactoredBackupManagerService implements BackupManagerServiceInter
        synchronized (mClearDataLock) {
            mClearingData = true;
            try {
                mActivityManager.clearApplicationUserData(packageName, observer, 0);
                mActivityManager.clearApplicationUserData(packageName, keepSystemState, observer, 0);
            } catch (RemoteException e) {
                // can't happen because the activity manager is in this process
            }
+1 −1
Original line number Diff line number Diff line
@@ -327,7 +327,7 @@ public class FullRestoreEngine extends RestoreEngine {
                                        Slog.d(TAG,
                                                "Clearing app data preparatory to full restore");
                                    }
                                    mBackupManagerService.clearApplicationDataSynchronous(pkg);
                                    mBackupManagerService.clearApplicationDataSynchronous(pkg, true);
                                } else {
                                    if (MORE_DEBUG) {
                                        Slog.d(TAG, "backup agent ("
+1 −1
Original line number Diff line number Diff line
@@ -591,7 +591,7 @@ public class PerformAdbRestoreTask implements Runnable {
                                        Slog.d(TAG,
                                                "Clearing app data preparatory to full restore");
                                    }
                                    mBackupManagerService.clearApplicationDataSynchronous(pkg);
                                    mBackupManagerService.clearApplicationDataSynchronous(pkg, true);
                                } else {
                                    if (DEBUG) {
                                        Slog.d(TAG, "backup agent ("
Loading