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

Commit 709e6435 authored by Piyush Mehrotra's avatar Piyush Mehrotra
Browse files

Adds intent extra to package data clear broadcast during restore operation.

During full restore of a package, Backup service asks AM service to clear app data for the package (to ensure clean state for restore). AM broadcasts ACTION_PACKAGE_DATA_CLEARED intent, which Blockstore receives and it clears associated Blockstore data. This results in Blockstore data not being restored.

Adding an intent extra to the broadcast enabled Blockstore to know that it happened because of a restore, and won't clear it's data. See go/br-blockstore-framework-fix for details.

Note: This change adds intent extra as @hide. b/298012653 tracks the work to add it as a system api for V.

Bug: 243464090
Test: Verified through BroadcastReceiver
Change-Id: I3e90279a3dd2e6753b76527cbdb3f70ecce4db0f
parent 977b0cb1
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@ import android.content.ServiceConnection;
import android.content.pm.ActivityInfo;
import android.content.pm.ActivityPresentationInfo;
import android.content.pm.ApplicationInfo;
import android.content.pm.IPackageDataObserver;
import android.content.pm.UserInfo;
import android.net.Uri;
import android.os.Bundle;
@@ -1224,4 +1225,13 @@ public abstract class ActivityManagerInternal {
     */
    @NonNull
    public abstract StatsEvent getCachedAppsHighWatermarkStats(int atomTag, boolean resetAfterPull);

    /**
     * Internal method for clearing app data, with the extra param that is used to indicate restore.
     * Used by Backup service during restore operation.
     *
     * @hide
     */
    public abstract boolean clearApplicationUserData(String packageName, boolean keepState,
            boolean isRestore, IPackageDataObserver observer, int userId);
}
+9 −0
Original line number Diff line number Diff line
@@ -6685,6 +6685,15 @@ public class Intent implements Parcelable, Cloneable {
    public static final String EXTRA_VISIBILITY_ALLOW_LIST =
            "android.intent.extra.VISIBILITY_ALLOW_LIST";
    /**
     * A boolean extra used with {@link #ACTION_PACKAGE_DATA_CLEARED} which indicates if the intent
     * is broadcast as part of a restore operation.
     *
     * @hide
     */
    public static final String EXTRA_IS_RESTORE =
            "android.intent.extra.IS_RESTORE";
    // ---------------------------------------------------------------------
    // ---------------------------------------------------------------------
    // Intent flags (see mFlags variable).
+2 −6
Original line number Diff line number Diff line
@@ -1742,12 +1742,8 @@ public class UserBackupManagerService {

        synchronized (mClearDataLock) {
            mClearingData = true;
            try {
                mActivityManager.clearApplicationUserData(packageName, keepSystemState, observer,
                        mUserId);
            } catch (RemoteException e) {
                // can't happen because the activity manager is in this process
            }
            mActivityManagerInternal.clearApplicationUserData(packageName, keepSystemState,
                    /*isRestore=*/ true, observer, mUserId);

            // Only wait 30 seconds for the clear data to happen.
            long timeoutMark = System.currentTimeMillis() + CLEAR_DATA_TIMEOUT_INTERVAL;
+16 −0
Original line number Diff line number Diff line
@@ -3449,6 +3449,12 @@ public class ActivityManagerService extends IActivityManager.Stub
    @Override
    public boolean clearApplicationUserData(final String packageName, boolean keepState,
            final IPackageDataObserver observer, int userId) {
        return clearApplicationUserData(packageName, keepState, /*isRestore=*/ false, observer,
                userId);
    }
    private boolean clearApplicationUserData(final String packageName, boolean keepState,
            boolean isRestore, final IPackageDataObserver observer, int userId) {
        enforceNotIsolatedCaller("clearApplicationUserData");
        int uid = Binder.getCallingUid();
        int pid = Binder.getCallingPid();
@@ -3543,6 +3549,9 @@ public class ActivityManagerService extends IActivityManager.Stub
                        intent.putExtra(Intent.EXTRA_UID,
                                (appInfo != null) ? appInfo.uid : INVALID_UID);
                        intent.putExtra(Intent.EXTRA_USER_HANDLE, resolvedUserId);
                        if (isRestore) {
                            intent.putExtra(Intent.EXTRA_IS_RESTORE, true);
                        }
                        if (isInstantApp) {
                            intent.putExtra(Intent.EXTRA_PACKAGE_NAME, packageName);
                        }
@@ -18758,6 +18767,13 @@ public class ActivityManagerService extends IActivityManager.Stub
            return mAppProfiler.mCachedAppsWatermarkData.getCachedAppsHighWatermarkStats(
                    atomTag, resetAfterPull);
        }
        @Override
        public boolean clearApplicationUserData(final String packageName, boolean keepState,
                boolean isRestore, final IPackageDataObserver observer, int userId) {
            return ActivityManagerService.this.clearApplicationUserData(packageName, keepState,
                    isRestore, observer, userId);
        }
    }
    long inputDispatchingTimedOut(int pid, final boolean aboveSystem, TimeoutRecord timeoutRecord) {