summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Christopher Tate <ctate@google.com> 2017-05-01 16:11:48 -0700
committer Christopher Tate <ctate@google.com> 2017-05-01 16:59:16 -0700
commit2a2a817024e0a19b7c7f700dc05c8e6af22e33c9 (patch)
tree989422c55f0657ff5b8eca9072f8b0a0d842e679
parentf8e7cbffb9de3f16d1ee4329190a0423c2319545 (diff)
Don't mix "current dataset" tokens for different backup transports
Previously, one could poison the current-dataset tracking by inopportunely-timed use of the local (aka development) transport. Now you can't: we reset the 'current dataset token?' tracking whenever the user changes the active transport. Also don't double-allocate return values sometimes. Bug 37694618 Test: manual Change-Id: I2cf5d42774522af830aecb99e65f43c4d0b5ce76
-rw-r--r--services/backup/java/com/android/server/backup/BackupManagerService.java31
-rw-r--r--services/backup/java/com/android/server/backup/TransportManager.java4
2 files changed, 27 insertions, 8 deletions
diff --git a/services/backup/java/com/android/server/backup/BackupManagerService.java b/services/backup/java/com/android/server/backup/BackupManagerService.java
index 1b970e5656bd..b0340ea63051 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");
}
@@ -10456,8 +10456,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;
@@ -10480,9 +10479,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);
@@ -10505,6 +10502,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 67f105e503d3..da1f32c9d203 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()]);
}
}