diff options
author | Matthew Williams <mjwilliams@google.com> | 2013-07-26 00:23:10 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2013-07-26 00:23:11 +0000 |
commit | 09d20f3bc24fb74d164ef8a0ef820840067d048c (patch) | |
tree | 173ee6f4d78495e2789227e3623333f83a9228c8 /core/java/android | |
parent | 5bd42924f291ef89cf32fd64d4c16aba2ad61c33 (diff) | |
parent | 68e39c3411d97ba2fe3ef5e33260b31fc73c934f (diff) | |
download | frameworks_base-09d20f3bc24fb74d164ef8a0ef820840067d048c.zip frameworks_base-09d20f3bc24fb74d164ef8a0ef820840067d048c.tar.gz frameworks_base-09d20f3bc24fb74d164ef8a0ef820840067d048c.tar.bz2 |
Merge "Fixed NPE in SyncRequest for Bundle.EMPTY"
Diffstat (limited to 'core/java/android')
-rw-r--r-- | core/java/android/content/SyncRequest.java | 64 |
1 files changed, 36 insertions, 28 deletions
diff --git a/core/java/android/content/SyncRequest.java b/core/java/android/content/SyncRequest.java index 819b1a8..4474c70 100644 --- a/core/java/android/content/SyncRequest.java +++ b/core/java/android/content/SyncRequest.java @@ -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; @@ -579,50 +582,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()); - } + ContentResolver.validateSyncExtrasBundle(mCustomExtras); 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()"); } @@ -633,5 +623,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"); + } + } } } |