Loading core/java/com/android/internal/backup/IBackupTransport.aidl +6 −3 Original line number Diff line number Diff line Loading @@ -42,11 +42,14 @@ interface IBackupTransport { */ /** * Verify that this is a suitable time for a backup pass. This should return zero * if a backup is reasonable right now, false otherwise. This method will be called * outside of the {@link #startSession}/{@link #endSession} pair. * if a backup is reasonable right now, some positive value otherwise. This method * will be called outside of the {@link #startSession}/{@link #endSession} pair. * * <p>If this is not a suitable time for a backup, the transport should suggest a * <p>If this is not a suitable time for a backup, the transport should return a * backoff delay, in milliseconds, after which the Backup Manager should try again. * * @return Zero if this is a suitable time for a backup pass, or a positive time delay * in milliseconds to suggest deferring the backup pass for a while. */ long requestBackupTime(); Loading services/java/com/android/server/BackupManagerService.java +26 −22 Original line number Diff line number Diff line Loading @@ -120,7 +120,9 @@ class BackupManagerService extends IBackupManager.Stub { private final Object mClearDataLock = new Object(); private volatile boolean mClearingData; // Current active transport & restore session private int mTransportId; private IBackupTransport mTransport; private RestoreSession mActiveRestoreSession; private File mStateDir; Loading @@ -144,14 +146,16 @@ class BackupManagerService extends IBackupManager.Stub { mJournalDir.mkdirs(); makeJournalLocked(); // okay because no other threads are running yet //!!! TODO: default to cloud transport, not local mTransportId = BackupManager.TRANSPORT_LOCAL; // Build our mapping of uid to backup client services synchronized (mBackupParticipants) { addPackageParticipantsLocked(null); } // Stand up our default transport //!!! TODO: default to cloud transport, not local mTransportId = BackupManager.TRANSPORT_LOCAL; mTransport = createTransport(mTransportId); // Now that we know about valid backup participants, parse any // leftover journal files and schedule a new backup pass parseLeftoverJournals(); Loading Loading @@ -284,7 +288,7 @@ class BackupManagerService extends IBackupManager.Stub { // deleted. If we crash prior to that, the old journal is parsed // at next boot and the journaled requests fulfilled. } (new PerformBackupThread(mTransportId, mBackupQueue, oldJournal)).run(); (new PerformBackupThread(mTransport, mBackupQueue, oldJournal)).run(); break; case MSG_RUN_FULL_BACKUP: Loading Loading @@ -505,13 +509,13 @@ class BackupManagerService extends IBackupManager.Stub { class PerformBackupThread extends Thread { private static final String TAG = "PerformBackupThread"; int mTransport; IBackupTransport mTransport; ArrayList<BackupRequest> mQueue; File mJournal; public PerformBackupThread(int transportId, ArrayList<BackupRequest> queue, public PerformBackupThread(IBackupTransport transport, ArrayList<BackupRequest> queue, File journal) { mTransport = transportId; mTransport = transport; mQueue = queue; mJournal = journal; } Loading @@ -520,15 +524,9 @@ class BackupManagerService extends IBackupManager.Stub { public void run() { if (DEBUG) Log.v(TAG, "Beginning backup of " + mQueue.size() + " targets"); // stand up the current transport IBackupTransport transport = createTransport(mTransport); if (transport == null) { return; } // start up the transport try { transport.startSession(); mTransport.startSession(); } catch (Exception e) { Log.e(TAG, "Error session transport"); e.printStackTrace(); Loading @@ -536,11 +534,11 @@ class BackupManagerService extends IBackupManager.Stub { } // The transport is up and running; now run all the backups in our queue doQueuedBackups(transport); doQueuedBackups(mTransport); // Finally, tear down the transport try { transport.endSession(); mTransport.endSession(); } catch (Exception e) { Log.e(TAG, "Error ending transport"); e.printStackTrace(); Loading Loading @@ -939,8 +937,14 @@ class BackupManagerService extends IBackupManager.Stub { public int selectBackupTransport(int transportId) { mContext.enforceCallingPermission("android.permission.BACKUP", "selectBackupTransport"); int prevTransport = mTransportId; int prevTransport = -1; IBackupTransport newTransport = createTransport(transportId); if (newTransport != null) { // !!! TODO: a method on the old transport that says it's being deactivated? mTransport = newTransport; prevTransport = mTransportId; mTransportId = transportId; } return prevTransport; } Loading Loading
core/java/com/android/internal/backup/IBackupTransport.aidl +6 −3 Original line number Diff line number Diff line Loading @@ -42,11 +42,14 @@ interface IBackupTransport { */ /** * Verify that this is a suitable time for a backup pass. This should return zero * if a backup is reasonable right now, false otherwise. This method will be called * outside of the {@link #startSession}/{@link #endSession} pair. * if a backup is reasonable right now, some positive value otherwise. This method * will be called outside of the {@link #startSession}/{@link #endSession} pair. * * <p>If this is not a suitable time for a backup, the transport should suggest a * <p>If this is not a suitable time for a backup, the transport should return a * backoff delay, in milliseconds, after which the Backup Manager should try again. * * @return Zero if this is a suitable time for a backup pass, or a positive time delay * in milliseconds to suggest deferring the backup pass for a while. */ long requestBackupTime(); Loading
services/java/com/android/server/BackupManagerService.java +26 −22 Original line number Diff line number Diff line Loading @@ -120,7 +120,9 @@ class BackupManagerService extends IBackupManager.Stub { private final Object mClearDataLock = new Object(); private volatile boolean mClearingData; // Current active transport & restore session private int mTransportId; private IBackupTransport mTransport; private RestoreSession mActiveRestoreSession; private File mStateDir; Loading @@ -144,14 +146,16 @@ class BackupManagerService extends IBackupManager.Stub { mJournalDir.mkdirs(); makeJournalLocked(); // okay because no other threads are running yet //!!! TODO: default to cloud transport, not local mTransportId = BackupManager.TRANSPORT_LOCAL; // Build our mapping of uid to backup client services synchronized (mBackupParticipants) { addPackageParticipantsLocked(null); } // Stand up our default transport //!!! TODO: default to cloud transport, not local mTransportId = BackupManager.TRANSPORT_LOCAL; mTransport = createTransport(mTransportId); // Now that we know about valid backup participants, parse any // leftover journal files and schedule a new backup pass parseLeftoverJournals(); Loading Loading @@ -284,7 +288,7 @@ class BackupManagerService extends IBackupManager.Stub { // deleted. If we crash prior to that, the old journal is parsed // at next boot and the journaled requests fulfilled. } (new PerformBackupThread(mTransportId, mBackupQueue, oldJournal)).run(); (new PerformBackupThread(mTransport, mBackupQueue, oldJournal)).run(); break; case MSG_RUN_FULL_BACKUP: Loading Loading @@ -505,13 +509,13 @@ class BackupManagerService extends IBackupManager.Stub { class PerformBackupThread extends Thread { private static final String TAG = "PerformBackupThread"; int mTransport; IBackupTransport mTransport; ArrayList<BackupRequest> mQueue; File mJournal; public PerformBackupThread(int transportId, ArrayList<BackupRequest> queue, public PerformBackupThread(IBackupTransport transport, ArrayList<BackupRequest> queue, File journal) { mTransport = transportId; mTransport = transport; mQueue = queue; mJournal = journal; } Loading @@ -520,15 +524,9 @@ class BackupManagerService extends IBackupManager.Stub { public void run() { if (DEBUG) Log.v(TAG, "Beginning backup of " + mQueue.size() + " targets"); // stand up the current transport IBackupTransport transport = createTransport(mTransport); if (transport == null) { return; } // start up the transport try { transport.startSession(); mTransport.startSession(); } catch (Exception e) { Log.e(TAG, "Error session transport"); e.printStackTrace(); Loading @@ -536,11 +534,11 @@ class BackupManagerService extends IBackupManager.Stub { } // The transport is up and running; now run all the backups in our queue doQueuedBackups(transport); doQueuedBackups(mTransport); // Finally, tear down the transport try { transport.endSession(); mTransport.endSession(); } catch (Exception e) { Log.e(TAG, "Error ending transport"); e.printStackTrace(); Loading Loading @@ -939,8 +937,14 @@ class BackupManagerService extends IBackupManager.Stub { public int selectBackupTransport(int transportId) { mContext.enforceCallingPermission("android.permission.BACKUP", "selectBackupTransport"); int prevTransport = mTransportId; int prevTransport = -1; IBackupTransport newTransport = createTransport(transportId); if (newTransport != null) { // !!! TODO: a method on the old transport that says it's being deactivated? mTransport = newTransport; prevTransport = mTransportId; mTransportId = transportId; } return prevTransport; } Loading