summaryrefslogtreecommitdiff
path: root/core/java/android
diff options
context:
space:
mode:
authorTreeHugger Robot <treehugger-gerrit@google.com>2018-01-25 22:47:54 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2018-01-25 22:47:54 +0000
commit5815664d4b39e6b59b7bbf92cb6900da26f340b6 (patch)
treed23fb0e8b74a171ce8d2ddbb2b54251588bf5074 /core/java/android
parent4b66fc6b1f9f92d96ea9a03b9a186a5510ebd253 (diff)
parent486b24179f25439be8e647ec22851bbe5b002bb3 (diff)
Merge "Add AbstractThreadedSyncAdapter#onUnsyncableAccount API"
Diffstat (limited to 'core/java/android')
-rw-r--r--core/java/android/content/AbstractThreadedSyncAdapter.java27
-rw-r--r--core/java/android/content/ISyncAdapter.aidl9
-rw-r--r--core/java/android/content/ISyncAdapterUnsyncableAccountCallback.aidl30
3 files changed, 66 insertions, 0 deletions
diff --git a/core/java/android/content/AbstractThreadedSyncAdapter.java b/core/java/android/content/AbstractThreadedSyncAdapter.java
index 2629929e91ce..5a1216b79b82 100644
--- a/core/java/android/content/AbstractThreadedSyncAdapter.java
+++ b/core/java/android/content/AbstractThreadedSyncAdapter.java
@@ -21,6 +21,7 @@ import android.os.Build;
import android.os.Bundle;
import android.os.IBinder;
import android.os.Process;
+import android.os.RemoteException;
import android.os.Trace;
import android.util.Log;
@@ -166,6 +167,12 @@ public abstract class AbstractThreadedSyncAdapter {
private class ISyncAdapterImpl extends ISyncAdapter.Stub {
@Override
+ public void onUnsyncableAccount(ISyncAdapterUnsyncableAccountCallback cb)
+ throws RemoteException {
+ cb.onUnsyncableAccountDone(AbstractThreadedSyncAdapter.this.onUnsyncableAccount());
+ }
+
+ @Override
public void startSync(ISyncContext syncContext, String authority, Account account,
Bundle extras) {
if (ENABLE_LOG) {
@@ -374,6 +381,26 @@ public abstract class AbstractThreadedSyncAdapter {
}
/**
+ * Allows to defer syncing until all accounts are properly set up.
+ *
+ * <p>Called when a account / authority pair
+ * <ul>
+ * <li>that can be handled by this adapter</li>
+ * <li>{@link ContentResolver#requestSync(SyncRequest) is synced}</li>
+ * <li>and the account/provider {@link ContentResolver#getIsSyncable(Account, String) has
+ * unknown state (<0)}.</li>
+ * </ul>
+ *
+ * <p>This might be called on a different service connection as {@link #onPerformSync}.
+ *
+ * @return If {@code false} syncing is deferred. Returns {@code true} by default, i.e. by
+ * default syncing starts immediately.
+ */
+ public boolean onUnsyncableAccount() {
+ return true;
+ }
+
+ /**
* Perform a sync for this account. SyncAdapter-specific parameters may
* be specified in extras, which is guaranteed to not be null. Invocations
* of this method are guaranteed to be serialized.
diff --git a/core/java/android/content/ISyncAdapter.aidl b/core/java/android/content/ISyncAdapter.aidl
index 4660527925c5..0eb581e6b585 100644
--- a/core/java/android/content/ISyncAdapter.aidl
+++ b/core/java/android/content/ISyncAdapter.aidl
@@ -19,6 +19,7 @@ package android.content;
import android.accounts.Account;
import android.os.Bundle;
import android.content.ISyncContext;
+import android.content.ISyncAdapterUnsyncableAccountCallback;
/**
* Interface used to control the sync activity on a SyncAdapter
@@ -26,6 +27,14 @@ import android.content.ISyncContext;
*/
oneway interface ISyncAdapter {
/**
+ * Called before {@link #startSync}. This allows the adapter to defer syncs until the
+ * adapter is ready for the account
+ *
+ * @param cb If called back with {@code false} accounts are not synced.
+ */
+ void onUnsyncableAccount(ISyncAdapterUnsyncableAccountCallback cb);
+
+ /**
* Initiate a sync for this account. SyncAdapter-specific parameters may
* be specified in extras, which is guaranteed to not be null.
*
diff --git a/core/java/android/content/ISyncAdapterUnsyncableAccountCallback.aidl b/core/java/android/content/ISyncAdapterUnsyncableAccountCallback.aidl
new file mode 100644
index 000000000000..a738ac2785c5
--- /dev/null
+++ b/core/java/android/content/ISyncAdapterUnsyncableAccountCallback.aidl
@@ -0,0 +1,30 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.content;
+
+/**
+ * Callback for {@link ISyncAdapter#onUnsyncableAccount}
+ * @hide
+ */
+oneway interface ISyncAdapterUnsyncableAccountCallback {
+ /**
+ * Deliver the result for {@link ISyncAdapter#onUnsyncableAccount}
+ *
+ * @param isReady Iff {@code false} account is not synced.
+ */
+ void onUnsyncableAccountDone(boolean isReady);
+}