From 4e8ce9ec4ee383f4767b10cfbe5a53439e31117a Mon Sep 17 00:00:00 2001 From: Fyodor Kupolov Date: Thu, 30 Jun 2016 14:20:02 -0700 Subject: [PATCH] Schedule backup of a package on a background thread Scheduling involves writing to journal file. This part can be done on the background thread in order to speed up the unlocking. Deferring writes to journal file should be safe, because the system will reschedule backups in case of a crash. Bug: 29619732 Bug: 29645167 Change-Id: I0667ac2bf159e0f40b7a5066f41ea0841df98437 --- .../server/backup/BackupManagerService.java | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/services/backup/java/com/android/server/backup/BackupManagerService.java b/services/backup/java/com/android/server/backup/BackupManagerService.java index e6f99c15ab661..0b85198d1c2a0 100644 --- a/services/backup/java/com/android/server/backup/BackupManagerService.java +++ b/services/backup/java/com/android/server/backup/BackupManagerService.java @@ -234,6 +234,7 @@ public class BackupManagerService { private static final int MSG_WIDGET_BROADCAST = 13; private static final int MSG_RUN_FULL_TRANSPORT_BACKUP = 14; private static final int MSG_REQUEST_BACKUP = 15; + private static final int MSG_SCHEDULE_BACKUP_PACKAGE = 16; // backup task state machine tick static final int MSG_BACKUP_RESTORE_STEP = 20; @@ -1037,6 +1038,16 @@ public class BackupManagerService { sendMessage(pbtMessage); break; } + + case MSG_SCHEDULE_BACKUP_PACKAGE: + { + String pkgName = (String)msg.obj; + if (MORE_DEBUG) { + Slog.d(TAG, "MSG_SCHEDULE_BACKUP_PACKAGE " + pkgName); + } + dataChangedImpl(pkgName); + break; + } } } } @@ -1216,7 +1227,7 @@ public class BackupManagerService { // Now that we know about valid backup participants, parse any // leftover journal files into the pending backup set - parseLeftoverJournals(); + mBackupHandler.post(() -> parseLeftoverJournals()); // Power management mWakelock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "*backup*"); @@ -2161,7 +2172,7 @@ public class BackupManagerService { int uid = pkg.applicationInfo.uid; HashSet set = mBackupParticipants.get(uid); if (set == null) { - set = new HashSet(); + set = new HashSet<>(); mBackupParticipants.put(uid, set); } set.add(pkg.packageName); @@ -2169,7 +2180,9 @@ public class BackupManagerService { // Schedule a backup for it on general principles if (MORE_DEBUG) Slog.i(TAG, "Scheduling backup for new app " + pkg.packageName); - dataChangedImpl(pkg.packageName); + Message msg = mBackupHandler + .obtainMessage(MSG_SCHEDULE_BACKUP_PACKAGE, pkg.packageName); + mBackupHandler.sendMessage(msg); } } }