@@ -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