Skip to content

Commit b5de598

Browse files
Christopher TateAndroid (Google) Code Review
authored andcommitted
Merge "Add -nosystem flag to adb backup"
2 parents 3c1951c + 240c7d2 commit b5de598

File tree

3 files changed

+40
-12
lines changed

3 files changed

+40
-12
lines changed

cmds/bu/src/com/android/commands/bu/Backup.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ private void doFullBackup(int socketFd) {
6666
boolean saveApks = false;
6767
boolean saveShared = false;
6868
boolean doEverything = false;
69+
boolean allIncludesSystem = true;
6970

7071
String arg;
7172
while ((arg = nextArg()) != null) {
@@ -78,6 +79,10 @@ private void doFullBackup(int socketFd) {
7879
saveShared = true;
7980
} else if ("-noshared".equals(arg)) {
8081
saveShared = false;
82+
} else if ("-system".equals(arg)) {
83+
allIncludesSystem = true;
84+
} else if ("-nosystem".equals(arg)) {
85+
allIncludesSystem = false;
8186
} else if ("-all".equals(arg)) {
8287
doEverything = true;
8388
} else {
@@ -102,7 +107,7 @@ private void doFullBackup(int socketFd) {
102107
try {
103108
ParcelFileDescriptor fd = ParcelFileDescriptor.adoptFd(socketFd);
104109
String[] packArray = new String[packages.size()];
105-
mBackupManager.fullBackup(fd, saveApks, saveShared, doEverything,
110+
mBackupManager.fullBackup(fd, saveApks, saveShared, doEverything, allIncludesSystem,
106111
packages.toArray(packArray));
107112
} catch (RemoteException e) {
108113
Log.e(TAG, "Unable to invoke backup manager for backup");

core/java/android/app/backup/IBackupManager.aidl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,11 +157,15 @@ interface IBackupManager {
157157
* @param allApps If <code>true</code>, the resulting tar stream will include all
158158
* installed applications' data, not just those named in the <code>packageNames</code>
159159
* parameter.
160+
* @param allIncludesSystem If {@code true}, then {@code allApps} will be interpreted
161+
* as including packages pre-installed as part of the system. If {@code false},
162+
* then setting {@code allApps} to {@code true} will mean only that all 3rd-party
163+
* applications will be included in the dataset.
160164
* @param packageNames The package names of the apps whose data (and optionally .apk files)
161165
* are to be backed up. The <code>allApps</code> parameter supersedes this.
162166
*/
163167
void fullBackup(in ParcelFileDescriptor fd, boolean includeApks, boolean includeShared,
164-
boolean allApps, in String[] packageNames);
168+
boolean allApps, boolean allIncludesSystem, in String[] packageNames);
165169

166170
/**
167171
* Restore device content from the data stream passed through the given socket. The

services/java/com/android/server/BackupManagerService.java

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -325,14 +325,16 @@ class FullBackupParams extends FullParams {
325325
public boolean includeApks;
326326
public boolean includeShared;
327327
public boolean allApps;
328+
public boolean includeSystem;
328329
public String[] packages;
329330

330331
FullBackupParams(ParcelFileDescriptor output, boolean saveApks, boolean saveShared,
331-
boolean doAllApps, String[] pkgList) {
332+
boolean doAllApps, boolean doSystem, String[] pkgList) {
332333
fd = output;
333334
includeApks = saveApks;
334335
includeShared = saveShared;
335336
allApps = doAllApps;
337+
includeSystem = doSystem;
336338
packages = pkgList;
337339
}
338340
}
@@ -504,7 +506,7 @@ public void handleMessage(Message msg) {
504506
PerformFullBackupTask task = new PerformFullBackupTask(params.fd,
505507
params.observer, params.includeApks,
506508
params.includeShared, params.curPassword, params.encryptPassword,
507-
params.allApps, params.packages, params.latch);
509+
params.allApps, params.includeSystem, params.packages, params.latch);
508510
(new Thread(task)).start();
509511
break;
510512
}
@@ -2161,6 +2163,7 @@ class PerformFullBackupTask implements Runnable {
21612163
boolean mIncludeApks;
21622164
boolean mIncludeShared;
21632165
boolean mAllApps;
2166+
final boolean mIncludeSystem;
21642167
String[] mPackages;
21652168
String mCurrentPassword;
21662169
String mEncryptPassword;
@@ -2219,13 +2222,14 @@ public void run() {
22192222

22202223
PerformFullBackupTask(ParcelFileDescriptor fd, IFullBackupRestoreObserver observer,
22212224
boolean includeApks, boolean includeShared, String curPassword,
2222-
String encryptPassword, boolean doAllApps, String[] packages,
2225+
String encryptPassword, boolean doAllApps, boolean doSystem, String[] packages,
22232226
AtomicBoolean latch) {
22242227
mOutputFile = fd;
22252228
mObserver = observer;
22262229
mIncludeApks = includeApks;
22272230
mIncludeShared = includeShared;
22282231
mAllApps = doAllApps;
2232+
mIncludeSystem = doSystem;
22292233
mPackages = packages;
22302234
mCurrentPassword = curPassword;
22312235
// when backing up, if there is a current backup password, we require that
@@ -2245,7 +2249,7 @@ public void run() {
22452249

22462250
@Override
22472251
public void run() {
2248-
final List<PackageInfo> packagesToBackup;
2252+
List<PackageInfo> packagesToBackup = new ArrayList<PackageInfo>();
22492253

22502254
Slog.i(TAG, "--- Performing full-dataset backup ---");
22512255
sendStartBackup();
@@ -2254,8 +2258,23 @@ public void run() {
22542258
if (mAllApps) {
22552259
packagesToBackup = mPackageManager.getInstalledPackages(
22562260
PackageManager.GET_SIGNATURES);
2257-
} else {
2258-
packagesToBackup = new ArrayList<PackageInfo>();
2261+
// Exclude system apps if we've been asked to do so
2262+
if (mIncludeSystem == false) {
2263+
for (int i = 0; i < packagesToBackup.size(); ) {
2264+
PackageInfo pkg = packagesToBackup.get(i);
2265+
if ((pkg.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
2266+
packagesToBackup.remove(i);
2267+
} else {
2268+
i++;
2269+
}
2270+
}
2271+
}
2272+
}
2273+
2274+
// Now process the command line argument packages, if any. Note that explicitly-
2275+
// named system-partition packages will be included even if includeSystem was
2276+
// set to false.
2277+
if (mPackages != null) {
22592278
for (String pkgName : mPackages) {
22602279
try {
22612280
packagesToBackup.add(mPackageManager.getPackageInfo(pkgName,
@@ -2268,8 +2287,8 @@ public void run() {
22682287

22692288
// Cull any packages that have indicated that backups are not permitted.
22702289
for (int i = 0; i < packagesToBackup.size(); ) {
2271-
PackageInfo info = packagesToBackup.get(i);
2272-
if ((info.applicationInfo.flags & ApplicationInfo.FLAG_ALLOW_BACKUP) == 0) {
2290+
PackageInfo pkg = packagesToBackup.get(i);
2291+
if ((pkg.applicationInfo.flags & ApplicationInfo.FLAG_ALLOW_BACKUP) == 0) {
22732292
packagesToBackup.remove(i);
22742293
} else {
22752294
i++;
@@ -4781,7 +4800,7 @@ boolean deviceIsProvisioned() {
47814800
// to the supplied file descriptor. This method is synchronous and does not return
47824801
// to the caller until the backup has been completed.
47834802
public void fullBackup(ParcelFileDescriptor fd, boolean includeApks, boolean includeShared,
4784-
boolean doAllApps, String[] pkgList) {
4803+
boolean doAllApps, boolean includeSystem, String[] pkgList) {
47854804
mContext.enforceCallingPermission(android.Manifest.permission.BACKUP, "fullBackup");
47864805

47874806
// Validate
@@ -4811,7 +4830,7 @@ public void fullBackup(ParcelFileDescriptor fd, boolean includeApks, boolean inc
48114830
Slog.i(TAG, "Beginning full backup...");
48124831

48134832
FullBackupParams params = new FullBackupParams(fd, includeApks, includeShared,
4814-
doAllApps, pkgList);
4833+
doAllApps, includeSystem, pkgList);
48154834
final int token = generateToken();
48164835
synchronized (mFullConfirmations) {
48174836
mFullConfirmations.put(token, params);

0 commit comments

Comments
 (0)