diff --git a/services/backup/java/com/android/server/backup/BackupManagerService.java b/services/backup/java/com/android/server/backup/BackupManagerService.java index dc2dfa8ff2891..a68a7ddd6f9cf 100644 --- a/services/backup/java/com/android/server/backup/BackupManagerService.java +++ b/services/backup/java/com/android/server/backup/BackupManagerService.java @@ -2387,7 +2387,7 @@ public class BackupManagerService { long token = mAncestralToken; synchronized (mQueueLock) { - if (mEverStoredApps.contains(packageName)) { + if (mCurrentToken != 0 && mEverStoredApps.contains(packageName)) { if (MORE_DEBUG) { Slog.i(TAG, "App in ever-stored, so using current token"); } @@ -10464,8 +10464,7 @@ if (MORE_DEBUG) Slog.v(TAG, " + got " + nRead + "; now wanting " + (size - soF final long oldId = Binder.clearCallingIdentity(); try { String prevTransport = mTransportManager.selectTransport(transport); - Settings.Secure.putString(mContext.getContentResolver(), - Settings.Secure.BACKUP_TRANSPORT, transport); + updateStateForTransport(transport); Slog.v(TAG, "selectBackupTransport() set " + mTransportManager.getCurrentTransportName() + " returning " + prevTransport); return prevTransport; @@ -10488,9 +10487,7 @@ if (MORE_DEBUG) Slog.v(TAG, " + got " + nRead + "; now wanting " + (size - soF @Override public void onSuccess(String transportName) { mTransportManager.selectTransport(transportName); - Settings.Secure.putString(mContext.getContentResolver(), - Settings.Secure.BACKUP_TRANSPORT, - mTransportManager.getCurrentTransportName()); + updateStateForTransport(mTransportManager.getCurrentTransportName()); Slog.v(TAG, "Transport successfully selected: " + transport.flattenToShortString()); try { listener.onSuccess(transportName); @@ -10513,6 +10510,28 @@ if (MORE_DEBUG) Slog.v(TAG, " + got " + nRead + "; now wanting " + (size - soF Binder.restoreCallingIdentity(oldId); } + private void updateStateForTransport(String newTransportName) { + // Publish the name change + Settings.Secure.putString(mContext.getContentResolver(), + Settings.Secure.BACKUP_TRANSPORT, newTransportName); + + // And update our current-dataset bookkeeping + IBackupTransport transport = mTransportManager.getTransportBinder(newTransportName); + if (transport != null) { + try { + mCurrentToken = transport.getCurrentRestoreSet(); + } catch (Exception e) { + // Oops. We can't know the current dataset token, so reset and figure it out + // when we do the next k/v backup operation on this transport. + mCurrentToken = 0; + } + } else { + // The named transport isn't bound at this particular moment, so we can't + // know yet what its current dataset token is. Reset as above. + mCurrentToken = 0; + } + } + // Supply the configuration Intent for the given transport. If the name is not one // of the available transports, or if the transport does not supply any configuration // UI, the method returns null. diff --git a/services/backup/java/com/android/server/backup/TransportManager.java b/services/backup/java/com/android/server/backup/TransportManager.java index 67f105e503d3b..da1f32c9d2035 100644 --- a/services/backup/java/com/android/server/backup/TransportManager.java +++ b/services/backup/java/com/android/server/backup/TransportManager.java @@ -182,13 +182,13 @@ class TransportManager { String[] getBoundTransportNames() { synchronized (mTransportLock) { - return mBoundTransports.keySet().toArray(new String[0]); + return mBoundTransports.keySet().toArray(new String[mBoundTransports.size()]); } } ComponentName[] getAllTransportCompenents() { synchronized (mTransportLock) { - return mValidTransports.keySet().toArray(new ComponentName[0]); + return mValidTransports.keySet().toArray(new ComponentName[mValidTransports.size()]); } }