summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Christopher Tate <ctate@google.com> 2011-10-03 18:13:44 -0700
committer Christopher Tate <ctate@google.com> 2011-10-04 15:35:00 -0700
commit240c7d2d1fb2944ee6a6f1dee41c7bbd766f8f0d (patch)
tree1e512dba224bc80c1eeb58411b7d508317699958
parentbe25ca2997ab98e1257d5625dd510e643dcead95 (diff)
Add -nosystem flag to adb backup
This makes it easy to back up everything that belongs to 3rd party apps, but nothing that comes with the system per se. If any system packages are explicitly named on the command line they will be included in the backup even if -nosystem was passed. So, for example, this will back up all 3rd party apps as well as system settings, but nothing else belonging to system-deployed apps: adb backup -all -nosystem com.android.provider.settings Bug 5361503 Change-Id: Iebe04b7d7027ca58b9f55e8eb7f219d6cca69269
-rw-r--r--cmds/bu/src/com/android/commands/bu/Backup.java7
-rw-r--r--core/java/android/app/backup/IBackupManager.aidl6
-rw-r--r--services/java/com/android/server/BackupManagerService.java39
3 files changed, 40 insertions, 12 deletions
diff --git a/cmds/bu/src/com/android/commands/bu/Backup.java b/cmds/bu/src/com/android/commands/bu/Backup.java
index 4c4bf9863aea..046ccca9b02a 100644
--- a/cmds/bu/src/com/android/commands/bu/Backup.java
+++ b/cmds/bu/src/com/android/commands/bu/Backup.java
@@ -66,6 +66,7 @@ public final class Backup {
boolean saveApks = false;
boolean saveShared = false;
boolean doEverything = false;
+ boolean allIncludesSystem = true;
String arg;
while ((arg = nextArg()) != null) {
@@ -78,6 +79,10 @@ public final class Backup {
saveShared = true;
} else if ("-noshared".equals(arg)) {
saveShared = false;
+ } else if ("-system".equals(arg)) {
+ allIncludesSystem = true;
+ } else if ("-nosystem".equals(arg)) {
+ allIncludesSystem = false;
} else if ("-all".equals(arg)) {
doEverything = true;
} else {
@@ -102,7 +107,7 @@ public final class Backup {
try {
ParcelFileDescriptor fd = ParcelFileDescriptor.adoptFd(socketFd);
String[] packArray = new String[packages.size()];
- mBackupManager.fullBackup(fd, saveApks, saveShared, doEverything,
+ mBackupManager.fullBackup(fd, saveApks, saveShared, doEverything, allIncludesSystem,
packages.toArray(packArray));
} catch (RemoteException e) {
Log.e(TAG, "Unable to invoke backup manager for backup");
diff --git a/core/java/android/app/backup/IBackupManager.aidl b/core/java/android/app/backup/IBackupManager.aidl
index c154296fbf03..acdd0b54559a 100644
--- a/core/java/android/app/backup/IBackupManager.aidl
+++ b/core/java/android/app/backup/IBackupManager.aidl
@@ -157,11 +157,15 @@ interface IBackupManager {
* @param allApps If <code>true</code>, the resulting tar stream will include all
* installed applications' data, not just those named in the <code>packageNames</code>
* parameter.
+ * @param allIncludesSystem If {@code true}, then {@code allApps} will be interpreted
+ * as including packages pre-installed as part of the system. If {@code false},
+ * then setting {@code allApps} to {@code true} will mean only that all 3rd-party
+ * applications will be included in the dataset.
* @param packageNames The package names of the apps whose data (and optionally .apk files)
* are to be backed up. The <code>allApps</code> parameter supersedes this.
*/
void fullBackup(in ParcelFileDescriptor fd, boolean includeApks, boolean includeShared,
- boolean allApps, in String[] packageNames);
+ boolean allApps, boolean allIncludesSystem, in String[] packageNames);
/**
* Restore device content from the data stream passed through the given socket. The
diff --git a/services/java/com/android/server/BackupManagerService.java b/services/java/com/android/server/BackupManagerService.java
index fe49cd2bd4c8..7b8657a03f26 100644
--- a/services/java/com/android/server/BackupManagerService.java
+++ b/services/java/com/android/server/BackupManagerService.java
@@ -325,14 +325,16 @@ class BackupManagerService extends IBackupManager.Stub {
public boolean includeApks;
public boolean includeShared;
public boolean allApps;
+ public boolean includeSystem;
public String[] packages;
FullBackupParams(ParcelFileDescriptor output, boolean saveApks, boolean saveShared,
- boolean doAllApps, String[] pkgList) {
+ boolean doAllApps, boolean doSystem, String[] pkgList) {
fd = output;
includeApks = saveApks;
includeShared = saveShared;
allApps = doAllApps;
+ includeSystem = doSystem;
packages = pkgList;
}
}
@@ -504,7 +506,7 @@ class BackupManagerService extends IBackupManager.Stub {
PerformFullBackupTask task = new PerformFullBackupTask(params.fd,
params.observer, params.includeApks,
params.includeShared, params.curPassword, params.encryptPassword,
- params.allApps, params.packages, params.latch);
+ params.allApps, params.includeSystem, params.packages, params.latch);
(new Thread(task)).start();
break;
}
@@ -2161,6 +2163,7 @@ class BackupManagerService extends IBackupManager.Stub {
boolean mIncludeApks;
boolean mIncludeShared;
boolean mAllApps;
+ final boolean mIncludeSystem;
String[] mPackages;
String mCurrentPassword;
String mEncryptPassword;
@@ -2219,13 +2222,14 @@ class BackupManagerService extends IBackupManager.Stub {
PerformFullBackupTask(ParcelFileDescriptor fd, IFullBackupRestoreObserver observer,
boolean includeApks, boolean includeShared, String curPassword,
- String encryptPassword, boolean doAllApps, String[] packages,
+ String encryptPassword, boolean doAllApps, boolean doSystem, String[] packages,
AtomicBoolean latch) {
mOutputFile = fd;
mObserver = observer;
mIncludeApks = includeApks;
mIncludeShared = includeShared;
mAllApps = doAllApps;
+ mIncludeSystem = doSystem;
mPackages = packages;
mCurrentPassword = curPassword;
// when backing up, if there is a current backup password, we require that
@@ -2245,7 +2249,7 @@ class BackupManagerService extends IBackupManager.Stub {
@Override
public void run() {
- final List<PackageInfo> packagesToBackup;
+ List<PackageInfo> packagesToBackup = new ArrayList<PackageInfo>();
Slog.i(TAG, "--- Performing full-dataset backup ---");
sendStartBackup();
@@ -2254,8 +2258,23 @@ class BackupManagerService extends IBackupManager.Stub {
if (mAllApps) {
packagesToBackup = mPackageManager.getInstalledPackages(
PackageManager.GET_SIGNATURES);
- } else {
- packagesToBackup = new ArrayList<PackageInfo>();
+ // Exclude system apps if we've been asked to do so
+ if (mIncludeSystem == false) {
+ for (int i = 0; i < packagesToBackup.size(); ) {
+ PackageInfo pkg = packagesToBackup.get(i);
+ if ((pkg.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
+ packagesToBackup.remove(i);
+ } else {
+ i++;
+ }
+ }
+ }
+ }
+
+ // Now process the command line argument packages, if any. Note that explicitly-
+ // named system-partition packages will be included even if includeSystem was
+ // set to false.
+ if (mPackages != null) {
for (String pkgName : mPackages) {
try {
packagesToBackup.add(mPackageManager.getPackageInfo(pkgName,
@@ -2268,8 +2287,8 @@ class BackupManagerService extends IBackupManager.Stub {
// Cull any packages that have indicated that backups are not permitted.
for (int i = 0; i < packagesToBackup.size(); ) {
- PackageInfo info = packagesToBackup.get(i);
- if ((info.applicationInfo.flags & ApplicationInfo.FLAG_ALLOW_BACKUP) == 0) {
+ PackageInfo pkg = packagesToBackup.get(i);
+ if ((pkg.applicationInfo.flags & ApplicationInfo.FLAG_ALLOW_BACKUP) == 0) {
packagesToBackup.remove(i);
} else {
i++;
@@ -4781,7 +4800,7 @@ class BackupManagerService extends IBackupManager.Stub {
// to the supplied file descriptor. This method is synchronous and does not return
// to the caller until the backup has been completed.
public void fullBackup(ParcelFileDescriptor fd, boolean includeApks, boolean includeShared,
- boolean doAllApps, String[] pkgList) {
+ boolean doAllApps, boolean includeSystem, String[] pkgList) {
mContext.enforceCallingPermission(android.Manifest.permission.BACKUP, "fullBackup");
// Validate
@@ -4811,7 +4830,7 @@ class BackupManagerService extends IBackupManager.Stub {
Slog.i(TAG, "Beginning full backup...");
FullBackupParams params = new FullBackupParams(fd, includeApks, includeShared,
- doAllApps, pkgList);
+ doAllApps, includeSystem, pkgList);
final int token = generateToken();
synchronized (mFullConfirmations) {
mFullConfirmations.put(token, params);