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

Commit 40a7bd0d authored by Matthew Williams's avatar Matthew Williams Committed by The Android Automerger
Browse files

Fixed NPE in SyncRequest for Bundle.EMPTY

Writing to bundle caller provides causes app to crash if bundle
is Bundle.EMPTY, which is backed by an unmodifiable map.

Change-Id: Ia9bdf12cddea9673bb84e0458cce8bc8027fbba5
parent 2e2141b7
Loading
Loading
Loading
Loading
+36 −28
Original line number Diff line number Diff line
@@ -204,6 +204,9 @@ public class SyncRequest implements Parcelable {
        mIsAuthority = (b.mSyncTarget == Builder.SYNC_TARGET_ADAPTER);
        mIsExpedited = b.mExpedited;
        mExtras = new Bundle(b.mCustomExtras);
        // For now we merge the sync config extras & the custom extras into one bundle.
        // TODO: pass the configuration extras through separately.
        mExtras.putAll(b.mSyncConfigExtras);
        mAllowMetered = b.mAllowMetered;
        mTxBytes = b.mTxBytes;
        mRxBytes = b.mRxBytes;
@@ -567,50 +570,37 @@ public class SyncRequest implements Parcelable {
         */
        public SyncRequest build() {
            // Validate the extras bundle
            try {
            ContentResolver.validateSyncExtrasBundle(mCustomExtras);
            } catch (IllegalArgumentException e) {
                throw new IllegalArgumentException(e.getMessage());
            }
            if (mCustomExtras == null) {
                mCustomExtras = new Bundle();
            }
            // Combine the builder extra flags into the copy of the bundle.
            // Combine builder extra flags into the config bundle.
            mSyncConfigExtras = new Bundle();
            if (mIgnoreBackoff) {
                mCustomExtras.putBoolean(ContentResolver.SYNC_EXTRAS_IGNORE_BACKOFF, true);
                mSyncConfigExtras.putBoolean(ContentResolver.SYNC_EXTRAS_IGNORE_BACKOFF, true);
            }
            if (mAllowMetered) {
                mCustomExtras.putBoolean(ContentResolver.SYNC_EXTRAS_ALLOW_METERED, true);
                mSyncConfigExtras.putBoolean(ContentResolver.SYNC_EXTRAS_ALLOW_METERED, true);
            }
            if (mIgnoreSettings) {
                mCustomExtras.putBoolean(ContentResolver.SYNC_EXTRAS_IGNORE_SETTINGS, true);
                mSyncConfigExtras.putBoolean(ContentResolver.SYNC_EXTRAS_IGNORE_SETTINGS, true);
            }
            if (mNoRetry) {
                mCustomExtras.putBoolean(ContentResolver.SYNC_EXTRAS_DO_NOT_RETRY, true);
                mSyncConfigExtras.putBoolean(ContentResolver.SYNC_EXTRAS_DO_NOT_RETRY, true);
            }
            if (mExpedited) {
                mCustomExtras.putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, true);
                mSyncConfigExtras.putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, true);
            }
            if (mIsManual) {
                mCustomExtras.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);
                mSyncConfigExtras.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);
            }
            // Upload/download expectations.
            mCustomExtras.putLong(ContentResolver.SYNC_EXTRAS_EXPECTED_UPLOAD, mTxBytes);
            mCustomExtras.putLong(ContentResolver.SYNC_EXTRAS_EXPECTED_DOWNLOAD, mRxBytes);
            // Priority.
            mCustomExtras.putInt(ContentResolver.SYNC_EXTRAS_PRIORITY, mPriority);
            mSyncConfigExtras.putLong(ContentResolver.SYNC_EXTRAS_EXPECTED_UPLOAD, mTxBytes);
            mSyncConfigExtras.putLong(ContentResolver.SYNC_EXTRAS_EXPECTED_DOWNLOAD, mRxBytes);
            mSyncConfigExtras.putInt(ContentResolver.SYNC_EXTRAS_PRIORITY, mPriority);
            if (mSyncType == SYNC_TYPE_PERIODIC) {
                // If this is a periodic sync ensure than invalid extras were
                // not set.
                if (mCustomExtras.getBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, false)
                        || mCustomExtras.getBoolean(ContentResolver.SYNC_EXTRAS_DO_NOT_RETRY, false)
                        || mCustomExtras.getBoolean(ContentResolver.SYNC_EXTRAS_IGNORE_BACKOFF, false)
                        || mCustomExtras.getBoolean(ContentResolver.SYNC_EXTRAS_IGNORE_SETTINGS, false)
                        || mCustomExtras.getBoolean(ContentResolver.SYNC_EXTRAS_INITIALIZE, false)
                        || mCustomExtras.getBoolean(ContentResolver.SYNC_EXTRAS_FORCE, false)
                        || mCustomExtras.getBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, false)) {
                    throw new IllegalArgumentException("Illegal extras were set");
                }
                // If this is a periodic sync ensure than invalid extras were not set.
                validatePeriodicExtras(mCustomExtras);
                validatePeriodicExtras(mSyncConfigExtras);
            } else if (mSyncType == SYNC_TYPE_UNKNOWN) {
                throw new IllegalArgumentException("Must call either syncOnce() or syncPeriodic()");
            }
@@ -621,5 +611,23 @@ public class SyncRequest implements Parcelable {
            }
            return new SyncRequest(this);
        }

        /**
         * Helper function to throw an <code>IllegalArgumentException</code> if any illegal
         * extras were set for a periodic sync.
         *
         * @param extras bundle to validate.
         */
        private void validatePeriodicExtras(Bundle extras) {
            if (extras.getBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, false)
                    || extras.getBoolean(ContentResolver.SYNC_EXTRAS_DO_NOT_RETRY, false)
                    || extras.getBoolean(ContentResolver.SYNC_EXTRAS_IGNORE_BACKOFF, false)
                    || extras.getBoolean(ContentResolver.SYNC_EXTRAS_IGNORE_SETTINGS, false)
                    || extras.getBoolean(ContentResolver.SYNC_EXTRAS_INITIALIZE, false)
                    || extras.getBoolean(ContentResolver.SYNC_EXTRAS_FORCE, false)
                    || extras.getBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, false)) {
                throw new IllegalArgumentException("Illegal extras were set");
            }
        }
    }
}
+1 −1
Original line number Diff line number Diff line
@@ -97,7 +97,7 @@ public class SyncOperation implements Comparable {
        this.delayUntil = delayUntil;
        this.backoff = backoff;
        final long now = SystemClock.elapsedRealtime();
        // Check the extras bundle. Must occur after we set the internal bundle.
        // Checks the extras bundle. Must occur after we set the internal bundle.
        if (runTimeFromNow < 0 || isExpedited()) {
            this.expedited = true;
            this.latestRunTime = now;