Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2a2a8170 authored by Christopher Tate's avatar Christopher Tate
Browse files

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
parent f8e7cbff
Loading
Loading
Loading
Loading
+25 −6
Original line number Diff line number Diff line
@@ -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.
+2 −2
Original line number Diff line number Diff line
@@ -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()]);
        }
    }