Skip to content

Commit d912ec6

Browse files
fredquintanaAndroid (Google) Code Review
authored andcommitted
Merge "add a way for the sync adapter to specify the activity that should be invoked to reach a settings screen for that sync adapter"
2 parents 97c4618 + e6d60ec commit d912ec6

File tree

5 files changed

+76
-3
lines changed

5 files changed

+76
-3
lines changed

api/current.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5770,6 +5770,7 @@ package android.content {
57705770
ctor public SyncAdapterType(android.os.Parcel);
57715771
method public boolean allowParallelSyncs();
57725772
method public int describeContents();
5773+
method public java.lang.String getSettingsActivity();
57735774
method public boolean isAlwaysSyncable();
57745775
method public boolean isUserVisible();
57755776
method public static android.content.SyncAdapterType newKey(java.lang.String, java.lang.String);

core/java/android/content/AbstractThreadedSyncAdapter.java

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,51 @@
3434
* If a cancelSync() is received that matches an existing sync operation then the thread
3535
* that is running that sync operation will be interrupted, which will indicate to the thread
3636
* that the sync has been canceled.
37+
* <p>
38+
* In order to be a sync adapter one must extend this class, provide implementations for the
39+
* abstract methods and write a service that returns the result of {@link #getSyncAdapterBinder()}
40+
* in the service's {@link android.app.Service#onBind(android.content.Intent)} when invoked
41+
* with an intent with action <code>android.content.SyncAdapter</code>. This service
42+
* must specify the following intent filter and metadata tags in its AndroidManifest.xml file
43+
* <pre>
44+
* &lt;intent-filter&gt;
45+
* &lt;action android:name="android.content.SyncAdapter" /&gt;
46+
* &lt;/intent-filter&gt;
47+
* &lt;meta-data android:name="android.content.SyncAdapter"
48+
* android:resource="@xml/syncadapter" /&gt;
49+
* </pre>
50+
* The <code>android:resource</code> attribute must point to a resource that looks like:
51+
* <pre>
52+
* &lt;sync-adapter xmlns:android="http://schemas.android.com/apk/res/android"
53+
* android:contentAuthority="authority"
54+
* android:accountType="accountType"
55+
* android:userVisible="true|false"
56+
* android:supportsUploading="true|false"
57+
* android:allowParallelSyncs="true|false"
58+
* android:isAlwaysSyncable="true|false"
59+
* android:syncAdapterSettingsAction="ACTION_OF_SETTINGS_ACTIVITY"
60+
* /&gt;
61+
* </pre>
62+
* <ul>
63+
* <li>The <code>android:contentAuthority</code> and <code>android:accountType</code> attributes
64+
* indicate which content authority and for which account types this sync adapter serves.
65+
* <li><code>android:userVisible</code> defaults to true and controls whether or not this sync
66+
* adapter shows up in the Sync Settings screen.
67+
* <li><code>android:supportsUploading</code> defaults
68+
* to true and if true an upload-only sync will be requested for all syncadapters associated
69+
* with an authority whenever that authority's content provider does a
70+
* {@link ContentResolver#notifyChange(android.net.Uri, android.database.ContentObserver, boolean)}
71+
* with syncToNetwork set to true.
72+
* <li><code>android:allowParallelSyncs</code> defaults to false and if true indicates that
73+
* the sync adapter can handle syncs for multiple accounts at the same time. Otherwise
74+
* the SyncManager will wait until the sync adapter is not in use before requesting that
75+
* it sync an account's data.
76+
* <li><code>android:isAlwaysSyncable</code> defaults to false and if true tells the SyncManager
77+
* to intialize the isSyncable state to 1 for that sync adapter for each account that is added.
78+
* <li><code>android:syncAdapterSettingsAction</code> defaults to null and if supplied it
79+
* specifies an Intent action of an activity that can be used to adjust the sync adapter's
80+
* sync settings. The activity must live in the same package as the sync adapter.
81+
* </ul>
3782
*/
3883
public abstract class AbstractThreadedSyncAdapter {
3984
/**

core/java/android/content/SyncAdapterType.java

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public class SyncAdapterType implements Parcelable {
3232
private final boolean supportsUploading;
3333
private final boolean isAlwaysSyncable;
3434
private final boolean allowParallelSyncs;
35+
private final String settingsActivity;
3536

3637
public SyncAdapterType(String authority, String accountType, boolean userVisible,
3738
boolean supportsUploading) {
@@ -47,14 +48,16 @@ public SyncAdapterType(String authority, String accountType, boolean userVisible
4748
this.supportsUploading = supportsUploading;
4849
this.isAlwaysSyncable = false;
4950
this.allowParallelSyncs = false;
51+
this.settingsActivity = null;
5052
this.isKey = false;
5153
}
5254

5355
/** @hide */
5456
public SyncAdapterType(String authority, String accountType, boolean userVisible,
5557
boolean supportsUploading,
5658
boolean isAlwaysSyncable,
57-
boolean allowParallelSyncs) {
59+
boolean allowParallelSyncs,
60+
String settingsActivity) {
5861
if (TextUtils.isEmpty(authority)) {
5962
throw new IllegalArgumentException("the authority must not be empty: " + authority);
6063
}
@@ -67,6 +70,7 @@ public SyncAdapterType(String authority, String accountType, boolean userVisible
6770
this.supportsUploading = supportsUploading;
6871
this.isAlwaysSyncable = isAlwaysSyncable;
6972
this.allowParallelSyncs = allowParallelSyncs;
73+
this.settingsActivity = settingsActivity;
7074
this.isKey = false;
7175
}
7276

@@ -83,6 +87,7 @@ private SyncAdapterType(String authority, String accountType) {
8387
this.supportsUploading = true;
8488
this.isAlwaysSyncable = false;
8589
this.allowParallelSyncs = false;
90+
this.settingsActivity = null;
8691
this.isKey = true;
8792
}
8893

@@ -131,6 +136,18 @@ public boolean isAlwaysSyncable() {
131136
return isAlwaysSyncable;
132137
}
133138

139+
/**
140+
* @return The activity to use to invoke this SyncAdapter's settings activity.
141+
* May be null.
142+
*/
143+
public String getSettingsActivity() {
144+
if (isKey) {
145+
throw new IllegalStateException(
146+
"this method is not allowed to be called when this is a key");
147+
}
148+
return settingsActivity;
149+
}
150+
134151
public static SyncAdapterType newKey(String authority, String accountType) {
135152
return new SyncAdapterType(authority, accountType);
136153
}
@@ -163,6 +180,7 @@ public String toString() {
163180
+ ", supportsUploading=" + supportsUploading
164181
+ ", isAlwaysSyncable=" + isAlwaysSyncable
165182
+ ", allowParallelSyncs=" + allowParallelSyncs
183+
+ ", settingsActivity=" + settingsActivity
166184
+ "}";
167185
}
168186
}
@@ -182,6 +200,7 @@ public void writeToParcel(Parcel dest, int flags) {
182200
dest.writeInt(supportsUploading ? 1 : 0);
183201
dest.writeInt(isAlwaysSyncable ? 1 : 0);
184202
dest.writeInt(allowParallelSyncs ? 1 : 0);
203+
dest.writeString(settingsActivity);
185204
}
186205

187206
public SyncAdapterType(Parcel source) {
@@ -191,7 +210,8 @@ public SyncAdapterType(Parcel source) {
191210
source.readInt() != 0,
192211
source.readInt() != 0,
193212
source.readInt() != 0,
194-
source.readInt() != 0);
213+
source.readInt() != 0,
214+
source.readString());
195215
}
196216

197217
public static final Creator<SyncAdapterType> CREATOR = new Creator<SyncAdapterType>() {

core/java/android/content/SyncAdaptersCache.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,11 @@ public SyncAdapterType parseServiceAttributes(Resources res,
6666
final boolean allowParallelSyncs =
6767
sa.getBoolean(com.android.internal.R.styleable.SyncAdapter_allowParallelSyncs,
6868
false);
69+
final String settingsActivity =
70+
sa.getString(com.android.internal.R.styleable
71+
.SyncAdapter_settingsActivity);
6972
return new SyncAdapterType(authority, accountType, userVisible, supportsUploading,
70-
isAlwaysSyncable, allowParallelSyncs);
73+
isAlwaysSyncable, allowParallelSyncs, settingsActivity);
7174
} finally {
7275
sa.recycle();
7376
}

core/res/res/values/attrs.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5110,6 +5110,10 @@
51105110
Defaults to false.
51115111
-->
51125112
<attr name="isAlwaysSyncable" format="boolean"/>
5113+
<!-- If provided, specifies the action of the settings
5114+
activity for this SyncAdapter.
5115+
-->
5116+
<attr name="settingsActivity"/>
51135117
</declare-styleable>
51145118

51155119
<!-- =============================== -->

0 commit comments

Comments
 (0)