Loading services/backup/java/com/android/server/backup/UserBackupManagerService.java +16 −1 Original line number Diff line number Diff line Loading @@ -441,6 +441,7 @@ public class UserBackupManagerService { private long mAncestralToken = 0; private long mCurrentToken = 0; @Nullable private File mAncestralSerialNumberFile; @OperationType private volatile long mAncestralOperationType; private final ContentObserver mSetupObserver; private final BroadcastReceiver mRunInitReceiver; Loading Loading @@ -881,6 +882,10 @@ public class UserBackupManagerService { mAncestralToken = ancestralToken; } public void setAncestralOperationType(@OperationType int operationType) { mAncestralOperationType = operationType; } public long getCurrentToken() { return mCurrentToken; } Loading Loading @@ -1808,6 +1813,16 @@ public class UserBackupManagerService { } } private BackupEligibilityRules getEligibilityRulesForRestoreAtInstall(long restoreToken) { if (mAncestralOperationType == OperationType.MIGRATION && restoreToken == mAncestralToken) { return getEligibilityRulesForOperation(OperationType.MIGRATION); } else { // If we're not using the ancestral data set, it means we're restoring from a backup // that happened on this device. return mScheduledBackupEligibility; } } /** * Get the restore-set token for the best-available restore set for this {@code packageName}: * the active set if possible, else the ancestral one. Returns zero if none available. Loading Loading @@ -3976,7 +3991,7 @@ public class UserBackupManagerService { packageName, token, listener, mScheduledBackupEligibility); getEligibilityRulesForRestoreAtInstall(restoreSet)); mBackupHandler.sendMessage(msg); } catch (Exception e) { // Calling into the transport broke; back off and proceed with the installation. Loading services/backup/java/com/android/server/backup/restore/FullRestoreEngine.java +6 −1 Original line number Diff line number Diff line Loading @@ -27,6 +27,7 @@ import static com.android.server.backup.internal.BackupHandler.MSG_RESTORE_OPERA import android.app.ApplicationThreadConstants; import android.app.IBackupAgent; import android.app.backup.BackupManager; import android.app.backup.FullBackup; import android.app.backup.IBackupManagerMonitor; import android.app.backup.IFullBackupRestoreObserver; Loading Loading @@ -633,7 +634,11 @@ public class FullRestoreEngine extends RestoreEngine { setRunning(false); } private static boolean isRestorableFile(FileMetadata info) { private boolean isRestorableFile(FileMetadata info) { if (mBackupEligibilityRules.getOperationType() == BackupManager.OperationType.MIGRATION) { // Everything is eligible for device-to-device migration. return true; } if (FullBackup.CACHE_TREE_TOKEN.equals(info.domain)) { if (MORE_DEBUG) { Slog.i(TAG, "Dropping cache file path " + info.path); Loading services/backup/java/com/android/server/backup/restore/PerformUnifiedRestoreTask.java +2 −0 Original line number Diff line number Diff line Loading @@ -1136,6 +1136,8 @@ public class PerformUnifiedRestoreTask implements BackupRestoreTask { if (mIsSystemRestore && mPmAgent != null) { backupManagerService.setAncestralPackages(mPmAgent.getRestoredPackages()); backupManagerService.setAncestralToken(mToken); backupManagerService.setAncestralOperationType( mBackupEligibilityRules.getOperationType()); backupManagerService.writeRestoreTokens(); } Loading services/backup/java/com/android/server/backup/utils/BackupEligibilityRules.java +23 −3 Original line number Diff line number Diff line Loading @@ -85,12 +85,15 @@ public class BackupEligibilityRules { * <li>they run as a system-level uid but do not supply their own backup agent * <li>it is the special shared-storage backup package used for 'adb backup' * </ol> * * However, the above eligibility rules are ignored for non-system apps in in case of * device-to-device migration, see {@link OperationType}. */ @VisibleForTesting public boolean appIsEligibleForBackup(ApplicationInfo app) { // 1. their manifest states android:allowBackup="false" boolean appAllowsBackup = (app.flags & ApplicationInfo.FLAG_ALLOW_BACKUP) != 0; if (!appAllowsBackup && !forceFullBackup(app.uid, mOperationType)) { // 1. their manifest states android:allowBackup="false" and this is not a device-to-device // migration if (!isAppBackupAllowed(app)) { return false; } Loading Loading @@ -122,6 +125,23 @@ public class BackupEligibilityRules { return !appIsDisabled(app); } /** * Check if this app allows backup. Apps can opt out of backup by stating * android:allowBackup="false" in their manifest. However, this flag is ignored for non-system * apps during device-to-device migrations, see {@link OperationType}. * * @param app The app under check. * @return boolean indicating whether backup is allowed. */ public boolean isAppBackupAllowed(ApplicationInfo app) { if (mOperationType == OperationType.MIGRATION && !UserHandle.isCore(app.uid)) { // Backup / restore of all apps is force allowed during device-to-device migration. return true; } return (app.flags & ApplicationInfo.FLAG_ALLOW_BACKUP) != 0; } /** * Returns whether an app is eligible for backup at runtime. That is, the app has to: * <ol> Loading services/backup/java/com/android/server/backup/utils/TarBackupReader.java +1 −1 Original line number Diff line number Diff line Loading @@ -402,7 +402,7 @@ public class TarBackupReader { info.packageName, PackageManager.GET_SIGNING_CERTIFICATES, userId); // Fall through to IGNORE if the app explicitly disallows backup final int flags = pkgInfo.applicationInfo.flags; if ((flags & ApplicationInfo.FLAG_ALLOW_BACKUP) != 0) { if (eligibilityRules.isAppBackupAllowed(pkgInfo.applicationInfo)) { // Restore system-uid-space packages only if they have // defined a custom backup agent if (!UserHandle.isCore(pkgInfo.applicationInfo.uid) Loading Loading
services/backup/java/com/android/server/backup/UserBackupManagerService.java +16 −1 Original line number Diff line number Diff line Loading @@ -441,6 +441,7 @@ public class UserBackupManagerService { private long mAncestralToken = 0; private long mCurrentToken = 0; @Nullable private File mAncestralSerialNumberFile; @OperationType private volatile long mAncestralOperationType; private final ContentObserver mSetupObserver; private final BroadcastReceiver mRunInitReceiver; Loading Loading @@ -881,6 +882,10 @@ public class UserBackupManagerService { mAncestralToken = ancestralToken; } public void setAncestralOperationType(@OperationType int operationType) { mAncestralOperationType = operationType; } public long getCurrentToken() { return mCurrentToken; } Loading Loading @@ -1808,6 +1813,16 @@ public class UserBackupManagerService { } } private BackupEligibilityRules getEligibilityRulesForRestoreAtInstall(long restoreToken) { if (mAncestralOperationType == OperationType.MIGRATION && restoreToken == mAncestralToken) { return getEligibilityRulesForOperation(OperationType.MIGRATION); } else { // If we're not using the ancestral data set, it means we're restoring from a backup // that happened on this device. return mScheduledBackupEligibility; } } /** * Get the restore-set token for the best-available restore set for this {@code packageName}: * the active set if possible, else the ancestral one. Returns zero if none available. Loading Loading @@ -3976,7 +3991,7 @@ public class UserBackupManagerService { packageName, token, listener, mScheduledBackupEligibility); getEligibilityRulesForRestoreAtInstall(restoreSet)); mBackupHandler.sendMessage(msg); } catch (Exception e) { // Calling into the transport broke; back off and proceed with the installation. Loading
services/backup/java/com/android/server/backup/restore/FullRestoreEngine.java +6 −1 Original line number Diff line number Diff line Loading @@ -27,6 +27,7 @@ import static com.android.server.backup.internal.BackupHandler.MSG_RESTORE_OPERA import android.app.ApplicationThreadConstants; import android.app.IBackupAgent; import android.app.backup.BackupManager; import android.app.backup.FullBackup; import android.app.backup.IBackupManagerMonitor; import android.app.backup.IFullBackupRestoreObserver; Loading Loading @@ -633,7 +634,11 @@ public class FullRestoreEngine extends RestoreEngine { setRunning(false); } private static boolean isRestorableFile(FileMetadata info) { private boolean isRestorableFile(FileMetadata info) { if (mBackupEligibilityRules.getOperationType() == BackupManager.OperationType.MIGRATION) { // Everything is eligible for device-to-device migration. return true; } if (FullBackup.CACHE_TREE_TOKEN.equals(info.domain)) { if (MORE_DEBUG) { Slog.i(TAG, "Dropping cache file path " + info.path); Loading
services/backup/java/com/android/server/backup/restore/PerformUnifiedRestoreTask.java +2 −0 Original line number Diff line number Diff line Loading @@ -1136,6 +1136,8 @@ public class PerformUnifiedRestoreTask implements BackupRestoreTask { if (mIsSystemRestore && mPmAgent != null) { backupManagerService.setAncestralPackages(mPmAgent.getRestoredPackages()); backupManagerService.setAncestralToken(mToken); backupManagerService.setAncestralOperationType( mBackupEligibilityRules.getOperationType()); backupManagerService.writeRestoreTokens(); } Loading
services/backup/java/com/android/server/backup/utils/BackupEligibilityRules.java +23 −3 Original line number Diff line number Diff line Loading @@ -85,12 +85,15 @@ public class BackupEligibilityRules { * <li>they run as a system-level uid but do not supply their own backup agent * <li>it is the special shared-storage backup package used for 'adb backup' * </ol> * * However, the above eligibility rules are ignored for non-system apps in in case of * device-to-device migration, see {@link OperationType}. */ @VisibleForTesting public boolean appIsEligibleForBackup(ApplicationInfo app) { // 1. their manifest states android:allowBackup="false" boolean appAllowsBackup = (app.flags & ApplicationInfo.FLAG_ALLOW_BACKUP) != 0; if (!appAllowsBackup && !forceFullBackup(app.uid, mOperationType)) { // 1. their manifest states android:allowBackup="false" and this is not a device-to-device // migration if (!isAppBackupAllowed(app)) { return false; } Loading Loading @@ -122,6 +125,23 @@ public class BackupEligibilityRules { return !appIsDisabled(app); } /** * Check if this app allows backup. Apps can opt out of backup by stating * android:allowBackup="false" in their manifest. However, this flag is ignored for non-system * apps during device-to-device migrations, see {@link OperationType}. * * @param app The app under check. * @return boolean indicating whether backup is allowed. */ public boolean isAppBackupAllowed(ApplicationInfo app) { if (mOperationType == OperationType.MIGRATION && !UserHandle.isCore(app.uid)) { // Backup / restore of all apps is force allowed during device-to-device migration. return true; } return (app.flags & ApplicationInfo.FLAG_ALLOW_BACKUP) != 0; } /** * Returns whether an app is eligible for backup at runtime. That is, the app has to: * <ol> Loading
services/backup/java/com/android/server/backup/utils/TarBackupReader.java +1 −1 Original line number Diff line number Diff line Loading @@ -402,7 +402,7 @@ public class TarBackupReader { info.packageName, PackageManager.GET_SIGNING_CERTIFICATES, userId); // Fall through to IGNORE if the app explicitly disallows backup final int flags = pkgInfo.applicationInfo.flags; if ((flags & ApplicationInfo.FLAG_ALLOW_BACKUP) != 0) { if (eligibilityRules.isAppBackupAllowed(pkgInfo.applicationInfo)) { // Restore system-uid-space packages only if they have // defined a custom backup agent if (!UserHandle.isCore(pkgInfo.applicationInfo.uid) Loading