diff options
| author | Varun Shah <varunshah@google.com> | 2021-02-16 19:10:58 -0800 |
|---|---|---|
| committer | Varun Shah <varunshah@google.com> | 2021-02-23 12:15:53 -0800 |
| commit | c516abcf46229c27d2f8bcad9d39e8f95a603ab0 (patch) | |
| tree | a5074ff0ffcafa79c0b4921910eac2427e1fd84f /core/java/android/content/SyncRequest.java | |
| parent | 8963b30f44c562cb63bc439f12ff21ae69814019 (diff) | |
Allow syncs to be scheduled as EJs.
Bug: 178852366
Test: atest SyncRequestTest
Test: atest SyncOperationTest
Test: atest SyncManagerTest
Test: atest CtsSyncManagerTest
Test: atest ContentResolverTest [all]
Change-Id: I4a78abdc1f2f5313ac18f739209b76fdf49388e5
Diffstat (limited to 'core/java/android/content/SyncRequest.java')
| -rw-r--r-- | core/java/android/content/SyncRequest.java | 63 |
1 files changed, 56 insertions, 7 deletions
diff --git a/core/java/android/content/SyncRequest.java b/core/java/android/content/SyncRequest.java index 9e568a40e0ee..e1e6f75d152f 100644 --- a/core/java/android/content/SyncRequest.java +++ b/core/java/android/content/SyncRequest.java @@ -17,6 +17,7 @@ package android.content; import android.accounts.Account; +import android.annotation.NonNull; import android.compat.annotation.UnsupportedAppUsage; import android.os.Build; import android.os.Bundle; @@ -58,6 +59,8 @@ public class SyncRequest implements Parcelable { private final boolean mIsAuthority; /** Sync should be run in lieu of other syncs. */ private final boolean mIsExpedited; + /** Sync sound be ran as an expedited job. */ + private final boolean mIsScheduledAsExpeditedJob; /** * {@hide} @@ -79,6 +82,14 @@ public class SyncRequest implements Parcelable { /** * {@hide} + * @return whether this sync is scheduled as an expedited job. + */ + public boolean isScheduledAsExpeditedJob() { + return mIsScheduledAsExpeditedJob; + } + + /** + * {@hide} * * @return account object for this sync. * @throws IllegalArgumentException if this function is called for a request that targets a @@ -149,6 +160,7 @@ public class SyncRequest implements Parcelable { parcel.writeInt((mDisallowMetered ? 1 : 0)); parcel.writeInt((mIsAuthority ? 1 : 0)); parcel.writeInt((mIsExpedited? 1 : 0)); + parcel.writeInt(mIsScheduledAsExpeditedJob ? 1 : 0); parcel.writeParcelable(mAccountToSync, flags); parcel.writeString(mAuthority); } @@ -161,6 +173,7 @@ public class SyncRequest implements Parcelable { mDisallowMetered = (in.readInt() != 0); mIsAuthority = (in.readInt() != 0); mIsExpedited = (in.readInt() != 0); + mIsScheduledAsExpeditedJob = (in.readInt() != 0); mAccountToSync = in.readParcelable(null); mAuthority = in.readString(); } @@ -174,6 +187,7 @@ public class SyncRequest implements Parcelable { mIsPeriodic = (b.mSyncType == Builder.SYNC_TYPE_PERIODIC); mIsAuthority = (b.mSyncTarget == Builder.SYNC_TARGET_ADAPTER); mIsExpedited = b.mExpedited; + mIsScheduledAsExpeditedJob = b.mScheduleAsExpeditedJob; 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. @@ -258,6 +272,11 @@ public class SyncRequest implements Parcelable { */ private boolean mRequiresCharging; + /** + * Whether the sync should be scheduled as an expedited job. + */ + private boolean mScheduleAsExpeditedJob; + public Builder() { } @@ -309,7 +328,8 @@ public class SyncRequest implements Parcelable { * {@link ContentResolver#SYNC_EXTRAS_INITIALIZE}, * {@link ContentResolver#SYNC_EXTRAS_FORCE}, * {@link ContentResolver#SYNC_EXTRAS_EXPEDITED}, - * {@link ContentResolver#SYNC_EXTRAS_MANUAL} + * {@link ContentResolver#SYNC_EXTRAS_MANUAL}, + * {@link ContentResolver#SYNC_EXTRAS_SCHEDULE_AS_EXPEDITED_JOB} * set to true. If any are supplied then an <code>IllegalArgumentException</code> will * be thrown. * @@ -500,6 +520,22 @@ public class SyncRequest implements Parcelable { } /** + * Convenience function for setting + * {@link ContentResolver#SYNC_EXTRAS_SCHEDULE_AS_EXPEDITED_JOB}. + * + * <p> Not to be confused with {@link ContentResolver#SYNC_EXTRAS_EXPEDITED}. + * + * <p> Not valid for periodic syncs, expedited syncs, and syncs that require charging - an + * <code>IllegalArgumentException</code> will be thrown in {@link #build()}. + * + * @param scheduleAsExpeditedJob whether to schedule as an expedited job. Default false. + */ + public @NonNull Builder setScheduleAsExpeditedJob(boolean scheduleAsExpeditedJob) { + mScheduleAsExpeditedJob = scheduleAsExpeditedJob; + return this; + } + + /** * Performs validation over the request and throws the runtime exception * <code>IllegalArgumentException</code> if this validation fails. * @@ -507,11 +543,6 @@ public class SyncRequest implements Parcelable { * builder. */ public SyncRequest build() { - // Validate the extras bundle - ContentResolver.validateSyncExtrasBundle(mCustomExtras); - if (mCustomExtras == null) { - mCustomExtras = new Bundle(); - } // Combine builder extra flags into the config bundle. mSyncConfigExtras = new Bundle(); if (mIgnoreBackoff) { @@ -532,17 +563,35 @@ public class SyncRequest implements Parcelable { if (mExpedited) { mSyncConfigExtras.putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, true); } + if (mScheduleAsExpeditedJob) { + mSyncConfigExtras.putBoolean( + ContentResolver.SYNC_EXTRAS_SCHEDULE_AS_EXPEDITED_JOB, true); + } if (mIsManual) { mSyncConfigExtras.putBoolean(ContentResolver.SYNC_EXTRAS_IGNORE_BACKOFF, true); mSyncConfigExtras.putBoolean(ContentResolver.SYNC_EXTRAS_IGNORE_SETTINGS, true); } + + if (mCustomExtras == null) { + mCustomExtras = new Bundle(); + } + // Validate the extras bundles + ContentResolver.validateSyncExtrasBundle(mCustomExtras); + // If this is a periodic sync ensure than invalid extras were not set. if (mSyncType == SYNC_TYPE_PERIODIC) { - // If this is a periodic sync ensure than invalid extras were not set. if (ContentResolver.invalidPeriodicExtras(mCustomExtras) || ContentResolver.invalidPeriodicExtras(mSyncConfigExtras)) { throw new IllegalArgumentException("Illegal extras were set"); } } + // If this sync is scheduled as an EJ, ensure that invalid extras were not set. + if (mCustomExtras.getBoolean(ContentResolver.SYNC_EXTRAS_SCHEDULE_AS_EXPEDITED_JOB) + || mScheduleAsExpeditedJob) { + if (ContentResolver.hasInvalidScheduleAsEjExtras(mCustomExtras) + || ContentResolver.hasInvalidScheduleAsEjExtras(mSyncConfigExtras)) { + throw new IllegalArgumentException("Illegal extras were set"); + } + } // Ensure that a target for the sync has been set. if (mSyncTarget == SYNC_TARGET_UNKNOWN) { throw new IllegalArgumentException("Must specify an adapter with" + |
