2 * Copyright (C) 2009 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package android.content;
19 import android.text.TextUtils;
20 import android.os.Parcelable;
21 import android.os.Parcel;
24 * Value type that represents a SyncAdapterType. This object overrides {@link #equals} and
25 * {@link #hashCode}, making it suitable for use as the key of a {@link java.util.Map}
27 public class SyncAdapterType implements Parcelable {
28 public final String authority;
29 public final String accountType;
30 public final boolean isKey;
31 private final boolean userVisible;
32 private final boolean supportsUploading;
33 private final boolean isAlwaysSyncable;
34 private final boolean allowParallelSyncs;
35 private final String settingsActivity;
37 public SyncAdapterType(String authority, String accountType, boolean userVisible,
38 boolean supportsUploading) {
39 if (TextUtils.isEmpty(authority)) {
40 throw new IllegalArgumentException("the authority must not be empty: " + authority);
42 if (TextUtils.isEmpty(accountType)) {
43 throw new IllegalArgumentException("the accountType must not be empty: " + accountType);
45 this.authority = authority;
46 this.accountType = accountType;
47 this.userVisible = userVisible;
48 this.supportsUploading = supportsUploading;
49 this.isAlwaysSyncable = false;
50 this.allowParallelSyncs = false;
51 this.settingsActivity = null;
56 public SyncAdapterType(String authority, String accountType, boolean userVisible,
57 boolean supportsUploading,
58 boolean isAlwaysSyncable,
59 boolean allowParallelSyncs,
60 String settingsActivity) {
61 if (TextUtils.isEmpty(authority)) {
62 throw new IllegalArgumentException("the authority must not be empty: " + authority);
64 if (TextUtils.isEmpty(accountType)) {
65 throw new IllegalArgumentException("the accountType must not be empty: " + accountType);
67 this.authority = authority;
68 this.accountType = accountType;
69 this.userVisible = userVisible;
70 this.supportsUploading = supportsUploading;
71 this.isAlwaysSyncable = isAlwaysSyncable;
72 this.allowParallelSyncs = allowParallelSyncs;
73 this.settingsActivity = settingsActivity;
77 private SyncAdapterType(String authority, String accountType) {
78 if (TextUtils.isEmpty(authority)) {
79 throw new IllegalArgumentException("the authority must not be empty: " + authority);
81 if (TextUtils.isEmpty(accountType)) {
82 throw new IllegalArgumentException("the accountType must not be empty: " + accountType);
84 this.authority = authority;
85 this.accountType = accountType;
86 this.userVisible = true;
87 this.supportsUploading = true;
88 this.isAlwaysSyncable = false;
89 this.allowParallelSyncs = false;
90 this.settingsActivity = null;
94 public boolean supportsUploading() {
96 throw new IllegalStateException(
97 "this method is not allowed to be called when this is a key");
99 return supportsUploading;
102 public boolean isUserVisible() {
104 throw new IllegalStateException(
105 "this method is not allowed to be called when this is a key");
111 * @return True if this SyncAdapter supports syncing multiple accounts simultaneously.
112 * If false then the SyncManager will take care to only start one sync at a time
113 * using this SyncAdapter.
115 public boolean allowParallelSyncs() {
117 throw new IllegalStateException(
118 "this method is not allowed to be called when this is a key");
120 return allowParallelSyncs;
124 * If true then the SyncManager will never issue an initialization sync to the SyncAdapter
125 * and will instead automatically call
126 * {@link ContentResolver#setIsSyncable(android.accounts.Account, String, int)} with a
127 * value of 1 for each account and provider that this sync adapter supports.
128 * @return true if the SyncAdapter does not require initialization and if it is ok for the
129 * SyncAdapter to treat it as syncable automatically.
131 public boolean isAlwaysSyncable() {
133 throw new IllegalStateException(
134 "this method is not allowed to be called when this is a key");
136 return isAlwaysSyncable;
140 * @return The activity to use to invoke this SyncAdapter's settings activity.
143 public String getSettingsActivity() {
145 throw new IllegalStateException(
146 "this method is not allowed to be called when this is a key");
148 return settingsActivity;
151 public static SyncAdapterType newKey(String authority, String accountType) {
152 return new SyncAdapterType(authority, accountType);
155 public boolean equals(Object o) {
156 if (o == this) return true;
157 if (!(o instanceof SyncAdapterType)) return false;
158 final SyncAdapterType other = (SyncAdapterType)o;
159 // don't include userVisible or supportsUploading in the equality check
160 return authority.equals(other.authority) && accountType.equals(other.accountType);
163 public int hashCode() {
165 result = 31 * result + authority.hashCode();
166 result = 31 * result + accountType.hashCode();
167 // don't include userVisible or supportsUploading the hash
171 public String toString() {
173 return "SyncAdapterType Key {name=" + authority
174 + ", type=" + accountType
177 return "SyncAdapterType {name=" + authority
178 + ", type=" + accountType
179 + ", userVisible=" + userVisible
180 + ", supportsUploading=" + supportsUploading
181 + ", isAlwaysSyncable=" + isAlwaysSyncable
182 + ", allowParallelSyncs=" + allowParallelSyncs
183 + ", settingsActivity=" + settingsActivity
188 public int describeContents() {
192 public void writeToParcel(Parcel dest, int flags) {
194 throw new IllegalStateException("keys aren't parcelable");
197 dest.writeString(authority);
198 dest.writeString(accountType);
199 dest.writeInt(userVisible ? 1 : 0);
200 dest.writeInt(supportsUploading ? 1 : 0);
201 dest.writeInt(isAlwaysSyncable ? 1 : 0);
202 dest.writeInt(allowParallelSyncs ? 1 : 0);
203 dest.writeString(settingsActivity);
206 public SyncAdapterType(Parcel source) {
210 source.readInt() != 0,
211 source.readInt() != 0,
212 source.readInt() != 0,
213 source.readInt() != 0,
214 source.readString());
217 public static final Creator<SyncAdapterType> CREATOR = new Creator<SyncAdapterType>() {
218 public SyncAdapterType createFromParcel(Parcel source) {
219 return new SyncAdapterType(source);
222 public SyncAdapterType[] newArray(int size) {
223 return new SyncAdapterType[size];