() {
+ public SyncAdapterType createFromParcel(Parcel source) {
+ return new SyncAdapterType(source);
+ }
+
+ public SyncAdapterType[] newArray(int size) {
+ return new SyncAdapterType[size];
+ }
+ };
}
\ No newline at end of file
diff --git a/core/java/android/content/SyncManager.java b/core/java/android/content/SyncManager.java
index c7954a51a1899..f73b394383076 100644
--- a/core/java/android/content/SyncManager.java
+++ b/core/java/android/content/SyncManager.java
@@ -35,7 +35,6 @@ import android.content.pm.ResolveInfo;
import android.content.pm.RegisteredServicesCache;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
-import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.HandlerThread;
@@ -72,7 +71,7 @@ import java.util.List;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Random;
-import java.util.Set;
+import java.util.Collection;
/**
* @hide
@@ -160,7 +159,7 @@ class SyncManager implements OnAccountsUpdatedListener {
Log.v(TAG, "Internal storage is low.");
}
mStorageIsLow = true;
- cancelActiveSync(null /* no url */);
+ cancelActiveSync(null /* any account */, null /* any authority */);
} else if (Intent.ACTION_DEVICE_STORAGE_OK.equals(action)) {
if (Log.isLoggable(TAG, Log.VERBOSE)) {
Log.v(TAG, "Internal storage is ok.");
@@ -204,7 +203,7 @@ class SyncManager implements OnAccountsUpdatedListener {
if (hadAccountsAlready && accounts.length > 0) {
// request a sync so that if the password was changed we will
// retry any sync that failed when it was wrong
- startSync(null /* all providers */, null /* no extras */);
+ scheduleSync(null, null, null, 0 /* no delay */);
}
}
@@ -327,7 +326,7 @@ class SyncManager implements OnAccountsUpdatedListener {
mHandleAlarmWakeLock.setReferenceCounted(false);
mSyncStorageEngine.addStatusChangeListener(
- SyncStorageEngine.CHANGE_SETTINGS, new ISyncStatusObserver.Stub() {
+ ContentResolver.SYNC_OBSERVER_TYPE_SETTINGS, new ISyncStatusObserver.Stub() {
public void onStatusChanged(int which) {
// force the sync loop to run if the settings change
sendCheckAlarmsMessage();
@@ -406,7 +405,8 @@ class SyncManager implements OnAccountsUpdatedListener {
scheduleSyncPollAlarm(nextRelativePollTimeMs);
// perform a poll
- scheduleSync(null /* sync all syncable providers */, new Bundle(), 0 /* no delay */);
+ scheduleSync(null /* sync all syncable accounts */, null /* sync all syncable providers */,
+ new Bundle(), 0 /* no delay */);
}
private void writeSyncPollTime(long when) {
@@ -502,20 +502,21 @@ class SyncManager implements OnAccountsUpdatedListener {
*
* You'll start getting callbacks after this.
*
- * @param url The Uri of a specific provider to be synced, or
- * null to sync all providers.
+ * @param requestedAccount the account to sync, may be null to signify all accounts
+ * @param requestedAuthority the authority to sync, may be null to indicate all authorities
* @param extras a Map of SyncAdapter-specific information to control
* syncs of a specific provider. Can be null. Is ignored
* if the url is null.
* @param delay how many milliseconds in the future to wait before performing this
- * sync. -1 means to make this the next sync to perform.
*/
- public void scheduleSync(Uri url, Bundle extras, long delay) {
+ public void scheduleSync(Account requestedAccount, String requestedAuthority,
+ Bundle extras, long delay) {
boolean isLoggable = Log.isLoggable(TAG, Log.VERBOSE);
if (isLoggable) {
Log.v(TAG, "scheduleSync:"
+ " delay " + delay
- + ", url " + ((url == null) ? "(null)" : url)
+ + ", account " + requestedAccount
+ + ", authority " + requestedAuthority
+ ", extras " + ((extras == null) ? "(null)" : extras));
}
@@ -539,9 +540,8 @@ class SyncManager implements OnAccountsUpdatedListener {
}
Account[] accounts;
- Account accountFromExtras = extras.getParcelable(ContentResolver.SYNC_EXTRAS_ACCOUNT);
- if (accountFromExtras != null) {
- accounts = new Account[]{accountFromExtras};
+ if (requestedAccount != null) {
+ accounts = new Account[]{requestedAccount};
} else {
// if the accounts aren't configured yet then we can't support an account-less
// sync request
@@ -563,14 +563,14 @@ class SyncManager implements OnAccountsUpdatedListener {
}
final boolean uploadOnly = extras.getBoolean(ContentResolver.SYNC_EXTRAS_UPLOAD, false);
- final boolean force = extras.getBoolean(ContentResolver.SYNC_EXTRAS_FORCE, false);
+ final boolean manualSync = extras.getBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, false);
int source;
if (uploadOnly) {
source = SyncStorageEngine.SOURCE_LOCAL;
- } else if (force) {
+ } else if (manualSync) {
source = SyncStorageEngine.SOURCE_USER;
- } else if (url == null) {
+ } else if (requestedAuthority == null) {
source = SyncStorageEngine.SOURCE_POLL;
} else {
// this isn't strictly server, since arbitrary callers can (and do) request
@@ -578,9 +578,9 @@ class SyncManager implements OnAccountsUpdatedListener {
source = SyncStorageEngine.SOURCE_SERVER;
}
- // compile a list of authorities that have sync adapters
- // for each authority sync each account that matches a sync adapter
- Set syncableAuthorities = new HashSet();
+ // Compile a list of authorities that have sync adapters.
+ // For each authority sync each account that matches a sync adapter.
+ final HashSet syncableAuthorities = new HashSet();
for (RegisteredServicesCache.ServiceInfo syncAdapter :
mSyncAdapters.getAllServices()) {
syncableAuthorities.add(syncAdapter.type.authority);
@@ -588,10 +588,10 @@ class SyncManager implements OnAccountsUpdatedListener {
// if the url was specified then replace the list of authorities with just this authority
// or clear it if this authority isn't syncable
- if (url != null) {
- boolean isSyncable = syncableAuthorities.contains(url.getAuthority());
+ if (requestedAuthority != null) {
+ final boolean isSyncable = syncableAuthorities.contains(requestedAuthority);
syncableAuthorities.clear();
- if (isSyncable) syncableAuthorities.add(url.getAuthority());
+ if (isSyncable) syncableAuthorities.add(requestedAuthority);
}
for (String authority : syncableAuthorities) {
@@ -614,10 +614,10 @@ class SyncManager implements OnAccountsUpdatedListener {
mStatusText = message;
}
- public void scheduleLocalSync(Uri url) {
+ public void scheduleLocalSync(Account account, String authority) {
final Bundle extras = new Bundle();
extras.putBoolean(ContentResolver.SYNC_EXTRAS_UPLOAD, true);
- scheduleSync(url, extras, LOCAL_SYNC_DELAY);
+ scheduleSync(account, authority, extras, LOCAL_SYNC_DELAY);
}
private IPackageManager getPackageManager() {
@@ -631,18 +631,16 @@ class SyncManager implements OnAccountsUpdatedListener {
return mPackageManager;
}
- /**
- * Initiate a sync for this given URL, or pass null for a full sync.
- *
- * You'll start getting callbacks after this.
- *
- * @param url The Uri of a specific provider to be synced, or
- * null to sync all providers.
- * @param extras a Map of SyncAdapter specific information to control
- * syncs of a specific provider. Can be null. Is ignored
- */
- public void startSync(Uri url, Bundle extras) {
- scheduleSync(url, extras, 0 /* no delay */);
+ public SyncAdapterType[] getSyncAdapterTypes() {
+ final Collection> serviceInfos =
+ mSyncAdapters.getAllServices();
+ SyncAdapterType[] types = new SyncAdapterType[serviceInfos.size()];
+ int i = 0;
+ for (RegisteredServicesCache.ServiceInfo serviceInfo : serviceInfos) {
+ types[i] = serviceInfo.type;
+ ++i;
+ }
+ return types;
}
public void updateHeartbeatTime() {
@@ -725,17 +723,22 @@ class SyncManager implements OnAccountsUpdatedListener {
}
/**
- * Cancel the active sync if it matches the uri. The uri corresponds to the one passed
- * in to startSync().
- * @param uri If non-null, the active sync is only canceled if it matches the uri.
- * If null, any active sync is canceled.
+ * Cancel the active sync if it matches the authority and account.
+ * @param account limit the cancelations to syncs with this account, if non-null
+ * @param authority limit the cancelations to syncs with this authority, if non-null
*/
- public void cancelActiveSync(Uri uri) {
+ public void cancelActiveSync(Account account, String authority) {
ActiveSyncContext activeSyncContext = mActiveSyncContext;
if (activeSyncContext != null) {
- // if a Uri was specified then only cancel the sync if it matches the the uri
- if (uri != null) {
- if (!uri.getAuthority().equals(activeSyncContext.mSyncOperation.authority)) {
+ // if an authority was specified then only cancel the sync if it matches
+ if (account != null) {
+ if (!account.equals(activeSyncContext.mSyncOperation.account)) {
+ return;
+ }
+ }
+ // if an account was specified then only cancel the sync if it matches
+ if (authority != null) {
+ if (!authority.equals(activeSyncContext.mSyncOperation.authority)) {
return;
}
}
@@ -787,14 +790,13 @@ class SyncManager implements OnAccountsUpdatedListener {
}
/**
- * Remove any scheduled sync operations that match uri. The uri corresponds to the one passed
- * in to startSync().
- * @param uri If non-null, only operations that match the uri are cleared.
- * If null, all operations are cleared.
+ * Remove scheduled sync operations.
+ * @param account limit the removals to operations with this account, if non-null
+ * @param authority limit the removals to operations with this authority, if non-null
*/
- public void clearScheduledSyncOperations(Uri uri) {
+ public void clearScheduledSyncOperations(Account account, String authority) {
synchronized (mSyncQueue) {
- mSyncQueue.clear(null, uri != null ? uri.getAuthority() : null);
+ mSyncQueue.clear(account, authority);
}
}
@@ -1558,14 +1560,14 @@ class SyncManager implements OnAccountsUpdatedListener {
// Otherwise consume SyncOperations from the head of the SyncQueue until one is
// found that is runnable (not disabled, etc). If that one is ready to run then
// start it, otherwise just get out.
- SyncOperation syncOperation;
+ SyncOperation op;
final ConnectivityManager connManager = (ConnectivityManager)
mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
- final boolean backgroundDataSetting = connManager.getBackgroundDataSetting();
+ final boolean backgroundDataUsageAllowed = connManager.getBackgroundDataSetting();
synchronized (mSyncQueue) {
while (true) {
- syncOperation = mSyncQueue.head();
- if (syncOperation == null) {
+ op = mSyncQueue.head();
+ if (op == null) {
if (isLoggable) {
Log.v(TAG, "runStateIdle: no more sync operations, returning");
}
@@ -1575,39 +1577,40 @@ class SyncManager implements OnAccountsUpdatedListener {
// Sync is disabled, drop this operation.
if (!isSyncEnabled()) {
if (isLoggable) {
- Log.v(TAG, "runStateIdle: sync disabled, dropping " + syncOperation);
+ Log.v(TAG, "runStateIdle: sync disabled, dropping " + op);
}
mSyncQueue.popHead();
continue;
}
- // skip the sync if it isn't a force and the settings are off for this provider
- final boolean force = syncOperation.extras.getBoolean(
- ContentResolver.SYNC_EXTRAS_FORCE, false);
- if (!force && (!backgroundDataSetting
- || !mSyncStorageEngine.getListenForNetworkTickles()
- || !mSyncStorageEngine.getSyncProviderAutomatically(
- null, syncOperation.authority))) {
+ // skip the sync if it isn't manual and auto sync is disabled
+ final boolean manualSync = op.extras.getBoolean(
+ ContentResolver.SYNC_EXTRAS_MANUAL, false);
+ final boolean syncAutomatically =
+ mSyncStorageEngine.getSyncAutomatically(op.account, op.authority)
+ || mSyncStorageEngine.getMasterSyncAutomatically();
+ boolean syncAllowed =
+ manualSync || (backgroundDataUsageAllowed && syncAutomatically);
+ if (!syncAllowed) {
if (isLoggable) {
- Log.v(TAG, "runStateIdle: sync off, dropping " + syncOperation);
+ Log.v(TAG, "runStateIdle: sync off, dropping " + op);
}
mSyncQueue.popHead();
continue;
}
// skip the sync if the account of this operation no longer exists
- if (!ArrayUtils.contains(accounts, syncOperation.account)) {
+ if (!ArrayUtils.contains(accounts, op.account)) {
mSyncQueue.popHead();
if (isLoggable) {
- Log.v(TAG, "runStateIdle: account not present, dropping "
- + syncOperation);
+ Log.v(TAG, "runStateIdle: account not present, dropping " + op);
}
continue;
}
// go ahead and try to sync this syncOperation
if (isLoggable) {
- Log.v(TAG, "runStateIdle: found sync candidate: " + syncOperation);
+ Log.v(TAG, "runStateIdle: found sync candidate: " + op);
}
break;
}
@@ -1615,11 +1618,10 @@ class SyncManager implements OnAccountsUpdatedListener {
// If the first SyncOperation isn't ready to run schedule a wakeup and
// get out.
final long now = SystemClock.elapsedRealtime();
- if (syncOperation.earliestRunTime > now) {
+ if (op.earliestRunTime > now) {
if (Log.isLoggable(TAG, Log.DEBUG)) {
Log.d(TAG, "runStateIdle: the time is " + now + " yet the next "
- + "sync operation is for " + syncOperation.earliestRunTime
- + ": " + syncOperation);
+ + "sync operation is for " + op.earliestRunTime + ": " + op);
}
return;
}
@@ -1627,14 +1629,14 @@ class SyncManager implements OnAccountsUpdatedListener {
// We will do this sync. Remove it from the queue and run it outside of the
// synchronized block.
if (isLoggable) {
- Log.v(TAG, "runStateIdle: we are going to sync " + syncOperation);
+ Log.v(TAG, "runStateIdle: we are going to sync " + op);
}
mSyncQueue.popHead();
}
// connect to the sync adapter
- SyncAdapterType syncAdapterType = new SyncAdapterType(syncOperation.authority,
- syncOperation.account.mType);
+ SyncAdapterType syncAdapterType = new SyncAdapterType(op.authority,
+ op.account.mType);
RegisteredServicesCache.ServiceInfo syncAdapterInfo =
mSyncAdapters.getServiceInfo(syncAdapterType);
if (syncAdapterInfo == null) {
@@ -1646,7 +1648,7 @@ class SyncManager implements OnAccountsUpdatedListener {
}
ActiveSyncContext activeSyncContext =
- new ActiveSyncContext(syncOperation, insertStartSyncEvent(syncOperation));
+ new ActiveSyncContext(op, insertStartSyncEvent(op));
mActiveSyncContext = activeSyncContext;
if (Log.isLoggable(TAG, Log.VERBOSE)) {
Log.v(TAG, "runStateIdle: setting mActiveSyncContext to " + mActiveSyncContext);
@@ -1776,21 +1778,21 @@ class SyncManager implements OnAccountsUpdatedListener {
*/
private int syncResultToErrorNumber(SyncResult syncResult) {
if (syncResult.syncAlreadyInProgress)
- return SyncStorageEngine.ERROR_SYNC_ALREADY_IN_PROGRESS;
+ return ContentResolver.SYNC_ERROR_SYNC_ALREADY_IN_PROGRESS;
if (syncResult.stats.numAuthExceptions > 0)
- return SyncStorageEngine.ERROR_AUTHENTICATION;
+ return ContentResolver.SYNC_ERROR_AUTHENTICATION;
if (syncResult.stats.numIoExceptions > 0)
- return SyncStorageEngine.ERROR_IO;
+ return ContentResolver.SYNC_ERROR_IO;
if (syncResult.stats.numParseExceptions > 0)
- return SyncStorageEngine.ERROR_PARSE;
+ return ContentResolver.SYNC_ERROR_PARSE;
if (syncResult.stats.numConflictDetectedExceptions > 0)
- return SyncStorageEngine.ERROR_CONFLICT;
+ return ContentResolver.SYNC_ERROR_CONFLICT;
if (syncResult.tooManyDeletions)
- return SyncStorageEngine.ERROR_TOO_MANY_DELETIONS;
+ return ContentResolver.SYNC_ERROR_TOO_MANY_DELETIONS;
if (syncResult.tooManyRetries)
- return SyncStorageEngine.ERROR_TOO_MANY_RETRIES;
+ return ContentResolver.SYNC_ERROR_TOO_MANY_RETRIES;
if (syncResult.databaseError)
- return SyncStorageEngine.ERROR_INTERNAL;
+ return ContentResolver.SYNC_ERROR_INTERNAL;
throw new IllegalStateException("we are not in an error state, " + syncResult);
}
@@ -1831,9 +1833,10 @@ class SyncManager implements OnAccountsUpdatedListener {
} else {
final boolean timeToShowNotification =
now > mSyncNotificationInfo.startTime + SYNC_NOTIFICATION_DELAY;
- final boolean syncIsForced = syncOperation.extras
- .getBoolean(ContentResolver.SYNC_EXTRAS_FORCE, false);
- shouldInstall = timeToShowNotification || syncIsForced;
+ // show the notification immediately if this is a manual sync
+ final boolean manualSync = syncOperation.extras
+ .getBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, false);
+ shouldInstall = timeToShowNotification || manualSync;
}
}
@@ -2088,9 +2091,9 @@ class SyncManager implements OnAccountsUpdatedListener {
SyncOperation existingOperation = mOpsByKey.get(operationKey);
// if this operation matches an existing operation that is being retried (delay > 0)
- // and this operation isn't forced, ignore this operation
+ // and this isn't a manual sync operation, ignore this operation
if (existingOperation != null && existingOperation.delay > 0) {
- if (!operation.extras.getBoolean(ContentResolver.SYNC_EXTRAS_FORCE, false)) {
+ if (!operation.extras.getBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, false)) {
return false;
}
}
diff --git a/core/java/android/content/SyncStatusObserver.java b/core/java/android/content/SyncStatusObserver.java
new file mode 100644
index 0000000000000..663378a7bedef
--- /dev/null
+++ b/core/java/android/content/SyncStatusObserver.java
@@ -0,0 +1,21 @@
+/*
+ * Copyright (C) 2009 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;
+
+public interface SyncStatusObserver {
+ void onStatusChanged(int which);
+}
diff --git a/core/java/android/content/SyncStorageEngine.java b/core/java/android/content/SyncStorageEngine.java
index aaa763dd155aa..aaba7c7c1891d 100644
--- a/core/java/android/content/SyncStorageEngine.java
+++ b/core/java/android/content/SyncStorageEngine.java
@@ -49,8 +49,6 @@ import java.util.HashMap;
import java.util.Iterator;
import java.util.TimeZone;
-import com.google.android.collect.Sets;
-
/**
* Singleton that tracks the sync data and overall sync
* history on the device.
@@ -89,6 +87,9 @@ public class SyncStorageEngine extends Handler {
/** Enum value for a user-initiated sync. */
public static final int SOURCE_USER = 3;
+ private static final Intent SYNC_CONNECTION_SETTING_CHANGED_INTENT =
+ new Intent("com.android.sync.SYNC_CONN_STATUS_CHANGED");
+
// TODO: i18n -- grab these out of resources.
/** String names for the sync source types. */
public static final String[] SOURCES = { "SERVER",
@@ -96,26 +97,10 @@ public class SyncStorageEngine extends Handler {
"POLL",
"USER" };
- // Error types
- public static final int ERROR_SYNC_ALREADY_IN_PROGRESS = 1;
- public static final int ERROR_AUTHENTICATION = 2;
- public static final int ERROR_IO = 3;
- public static final int ERROR_PARSE = 4;
- public static final int ERROR_CONFLICT = 5;
- public static final int ERROR_TOO_MANY_DELETIONS = 6;
- public static final int ERROR_TOO_MANY_RETRIES = 7;
- public static final int ERROR_INTERNAL = 8;
-
// The MESG column will contain one of these or one of the Error types.
public static final String MESG_SUCCESS = "success";
public static final String MESG_CANCELED = "canceled";
- public static final int CHANGE_SETTINGS = 1<<0;
- public static final int CHANGE_PENDING = 1<<1;
- public static final int CHANGE_ACTIVE = 1<<2;
- public static final int CHANGE_STATUS = 1<<3;
- public static final int CHANGE_ALL = 0x7fffffff;
-
public static final int MAX_HISTORY = 15;
private static final int MSG_WRITE_STATUS = 1;
@@ -166,7 +151,7 @@ public class SyncStorageEngine extends Handler {
final String authority;
final int ident;
boolean enabled;
-
+
AuthorityInfo(Account account, String authority, int ident) {
this.account = account;
this.authority = authority;
@@ -259,7 +244,7 @@ public class SyncStorageEngine extends Handler {
private int mNumPendingFinished = 0;
private int mNextHistoryId = 0;
- private boolean mListenForTickles = true;
+ private boolean mMasterSyncAutomatically = true;
private SyncStorageEngine(Context context) {
mContext = context;
@@ -356,14 +341,14 @@ public class SyncStorageEngine extends Handler {
}
}
- public boolean getSyncProviderAutomatically(Account account, String providerName) {
+ public boolean getSyncAutomatically(Account account, String providerName) {
synchronized (mAuthorities) {
if (account != null) {
AuthorityInfo authority = getAuthorityLocked(account, providerName,
- "getSyncProviderAutomatically");
- return authority != null ? authority.enabled : false;
+ "getSyncAutomatically");
+ return authority != null && authority.enabled;
}
-
+
int i = mAuthorities.size();
while (i > 0) {
i--;
@@ -377,42 +362,31 @@ public class SyncStorageEngine extends Handler {
}
}
- public void setSyncProviderAutomatically(Account account, String providerName,
- boolean sync) {
+ public void setSyncAutomatically(Account account, String providerName, boolean sync) {
synchronized (mAuthorities) {
- if (account != null) {
- AuthorityInfo authority = getAuthorityLocked(account, providerName,
- "setSyncProviderAutomatically");
- if (authority != null) {
- authority.enabled = sync;
- }
- } else {
- int i = mAuthorities.size();
- while (i > 0) {
- i--;
- AuthorityInfo authority = mAuthorities.get(i);
- if (authority.authority.equals(providerName)) {
- authority.enabled = sync;
- }
- }
+ AuthorityInfo authority = getAuthorityLocked(account, providerName,
+ "setSyncAutomatically");
+ if (authority != null) {
+ authority.enabled = sync;
}
writeAccountInfoLocked();
}
- reportChange(CHANGE_SETTINGS);
+ reportChange(ContentResolver.SYNC_OBSERVER_TYPE_SETTINGS);
}
- public void setListenForNetworkTickles(boolean flag) {
+ public void setMasterSyncAutomatically(boolean flag) {
synchronized (mAuthorities) {
- mListenForTickles = flag;
+ mMasterSyncAutomatically = flag;
writeAccountInfoLocked();
}
- reportChange(CHANGE_SETTINGS);
+ reportChange(ContentResolver.SYNC_OBSERVER_TYPE_SETTINGS);
+ mContext.sendBroadcast(SYNC_CONNECTION_SETTING_CHANGED_INTENT);
}
- public boolean getListenForNetworkTickles() {
+ public boolean getMasterSyncAutomatically() {
synchronized (mAuthorities) {
- return mListenForTickles;
+ return mMasterSyncAutomatically;
}
}
@@ -481,7 +455,7 @@ public class SyncStorageEngine extends Handler {
status.pending = true;
}
- reportChange(CHANGE_PENDING);
+ reportChange(ContentResolver.SYNC_OBSERVER_TYPE_PENDING);
return op;
}
@@ -527,7 +501,7 @@ public class SyncStorageEngine extends Handler {
}
}
- reportChange(CHANGE_PENDING);
+ reportChange(ContentResolver.SYNC_OBSERVER_TYPE_PENDING);
return res;
}
@@ -543,7 +517,7 @@ public class SyncStorageEngine extends Handler {
}
writePendingOperationsLocked();
}
- reportChange(CHANGE_PENDING);
+ reportChange(ContentResolver.SYNC_OBSERVER_TYPE_PENDING);
return num;
}
@@ -650,14 +624,14 @@ public class SyncStorageEngine extends Handler {
}
}
- reportChange(CHANGE_ACTIVE);
+ reportChange(ContentResolver.SYNC_OBSERVER_TYPE_ACTIVE);
}
/**
* To allow others to send active change reports, to poke clients.
*/
public void reportActiveChange() {
- reportChange(CHANGE_ACTIVE);
+ reportChange(ContentResolver.SYNC_OBSERVER_TYPE_ACTIVE);
}
/**
@@ -689,7 +663,7 @@ public class SyncStorageEngine extends Handler {
if (DEBUG) Log.v(TAG, "returning historyId " + id);
}
- reportChange(CHANGE_STATUS);
+ reportChange(ContentResolver.SYNC_OBSERVER_TYPE_STATUS);
return id;
}
@@ -793,7 +767,7 @@ public class SyncStorageEngine extends Handler {
}
}
- reportChange(CHANGE_STATUS);
+ reportChange(ContentResolver.SYNC_OBSERVER_TYPE_STATUS);
}
/**
@@ -851,7 +825,7 @@ public class SyncStorageEngine extends Handler {
/**
* Return true if the pending status is true of any matching authorities.
*/
- public boolean isAuthorityPending(Account account, String authority) {
+ public boolean isSyncPending(Account account, String authority) {
synchronized (mAuthorities) {
final int N = mSyncStatus.size();
for (int i=0; i 0) {
+ i--;
+ AuthorityInfo authority = mAuthorities.get(i);
+ if (authority.authority.equals(provider)) {
+ authority.enabled = value == null || Boolean.parseBoolean(value);
+ }
+ }
}
}
diff --git a/core/java/android/content/TempProviderSyncAdapter.java b/core/java/android/content/TempProviderSyncAdapter.java
index 0cbe01e7e3949..fb05fe7807a54 100644
--- a/core/java/android/content/TempProviderSyncAdapter.java
+++ b/core/java/android/content/TempProviderSyncAdapter.java
@@ -63,12 +63,10 @@ public abstract class TempProviderSyncAdapter extends SyncAdapter {
*
* @param context allows you to publish status and interact with the
* @param account the account to sync
- * @param forced if true then the sync was forced
+ * @param manualSync true if this sync was requested manually by the user
* @param result information to track what happened during this sync attempt
- * @return true, if the sync was successfully started. One reason it can
- * fail to start is if there is no user configured on the device.
*/
- public abstract void onSyncStarting(SyncContext context, Account account, boolean forced,
+ public abstract void onSyncStarting(SyncContext context, Account account, boolean manualSync,
SyncResult result);
/**
@@ -229,12 +227,12 @@ public abstract class TempProviderSyncAdapter extends SyncAdapter {
mAdapterSyncStarted = false;
String message = null;
- boolean syncForced = extras.getBoolean(ContentResolver.SYNC_EXTRAS_FORCE, false);
+ boolean manualSync = extras.getBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, false);
try {
mProvider.onSyncStart(syncContext, account);
mProviderSyncStarted = true;
- onSyncStarting(syncContext, account, syncForced, mResult);
+ onSyncStarting(syncContext, account, manualSync, mResult);
if (mResult.hasError()) {
message = "SyncAdapter failed while trying to start sync";
return;
diff --git a/core/java/android/provider/Sync.java b/core/java/android/provider/Sync.java
deleted file mode 100644
index c9bde0e4a1f93..0000000000000
--- a/core/java/android/provider/Sync.java
+++ /dev/null
@@ -1,649 +0,0 @@
-/*
- * Copyright (C) 2007 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.provider;
-
-import android.content.ContentQueryMap;
-import android.content.ContentResolver;
-import android.content.ContentValues;
-import android.database.Cursor;
-import android.net.Uri;
-import android.os.Handler;
-import android.accounts.Account;
-import android.text.TextUtils;
-
-import java.util.Map;
-
-/**
- * The Sync provider stores information used in managing the syncing of the device,
- * including the history and pending syncs.
- *
- * @hide
- */
-public final class Sync {
- // utility class
- private Sync() {}
-
- /**
- * The content url for this provider.
- */
- public static final Uri CONTENT_URI = Uri.parse("content://sync");
-
- /**
- * Columns from the stats table.
- */
- public interface StatsColumns {
- /**
- * The sync account.
- * Type: TEXT
- */
- public static final String ACCOUNT = "account";
-
- /**
- * The sync account type.
- * Type: TEXT
- */
- public static final String ACCOUNT_TYPE = "account_type";
-
- /**
- * The content authority (contacts, calendar, etc.).
- * Type: TEXT
- */
- public static final String AUTHORITY = "authority";
- }
-
- /**
- * Provides constants and utility methods to access and use the stats table.
- */
- public static final class Stats implements BaseColumns, StatsColumns {
-
- // utility class
- private Stats() {}
-
- /**
- * The content url for this table.
- */
- public static final Uri CONTENT_URI =
- Uri.parse("content://sync/stats");
-
- /** Projection for the _id column in the stats table. */
- public static final String[] SYNC_STATS_PROJECTION = {_ID};
- }
-
- /**
- * Columns from the history table.
- */
- public interface HistoryColumns {
- /**
- * The ID of the stats row corresponding to this event.
- * Type: INTEGER
- */
- public static final String STATS_ID = "stats_id";
-
- /**
- * The source of the sync event (LOCAL, POLL, USER, SERVER).
- * Type: INTEGER
- */
- public static final String SOURCE = "source";
-
- /**
- * The type of sync event (START, STOP).
- * Type: INTEGER
- */
- public static final String EVENT = "event";
-
- /**
- * The time of the event.
- * Type: INTEGER
- */
- public static final String EVENT_TIME = "eventTime";
-
- /**
- * How long this event took. This is only valid if the EVENT is EVENT_STOP.
- * Type: INTEGER
- */
- public static final String ELAPSED_TIME = "elapsedTime";
-
- /**
- * Any additional message associated with this event.
- * Type: TEXT
- */
- public static final String MESG = "mesg";
-
- /**
- * How much activity was performed sending data to the server. This is sync adapter
- * specific, but usually is something like how many record update/insert/delete attempts
- * were carried out. This is only valid if the EVENT is EVENT_STOP.
- * Type: INTEGER
- */
- public static final String UPSTREAM_ACTIVITY = "upstreamActivity";
-
- /**
- * How much activity was performed while receiving data from the server.
- * This is sync adapter specific, but usually is something like how many
- * records were received from the server. This is only valid if the
- * EVENT is EVENT_STOP.
- * Type: INTEGER
- */
- public static final String DOWNSTREAM_ACTIVITY = "downstreamActivity";
- }
-
- /**
- * Columns from the history table.
- */
- public interface StatusColumns {
- /**
- * How many syncs were completed for this account and authority.
- * Type: INTEGER
- */
- public static final String NUM_SYNCS = "numSyncs";
-
- /**
- * How long all the events for this account and authority took.
- * Type: INTEGER
- */
- public static final String TOTAL_ELAPSED_TIME = "totalElapsedTime";
-
- /**
- * The number of syncs with SOURCE_POLL.
- * Type: INTEGER
- */
- public static final String NUM_SOURCE_POLL = "numSourcePoll";
-
- /**
- * The number of syncs with SOURCE_SERVER.
- * Type: INTEGER
- */
- public static final String NUM_SOURCE_SERVER = "numSourceServer";
-
- /**
- * The number of syncs with SOURCE_LOCAL.
- * Type: INTEGER
- */
- public static final String NUM_SOURCE_LOCAL = "numSourceLocal";
-
- /**
- * The number of syncs with SOURCE_USER.
- * Type: INTEGER
- */
- public static final String NUM_SOURCE_USER = "numSourceUser";
-
- /**
- * The time in ms that the last successful sync ended. Will be null if
- * there are no successful syncs. A successful sync is defined as one having
- * MESG=MESG_SUCCESS.
- * Type: INTEGER
- */
- public static final String LAST_SUCCESS_TIME = "lastSuccessTime";
-
- /**
- * The SOURCE of the last successful sync. Will be null if
- * there are no successful syncs. A successful sync is defined
- * as one having MESG=MESG_SUCCESS.
- * Type: INTEGER
- */
- public static final String LAST_SUCCESS_SOURCE = "lastSuccessSource";
-
- /**
- * The end time in ms of the last sync that failed since the last successful sync.
- * Will be null if there are no syncs or if the last one succeeded. A failed
- * sync is defined as one where MESG isn't MESG_SUCCESS or MESG_CANCELED.
- * Type: INTEGER
- */
- public static final String LAST_FAILURE_TIME = "lastFailureTime";
-
- /**
- * The SOURCE of the last sync that failed since the last successful sync.
- * Will be null if there are no syncs or if the last one succeeded. A failed
- * sync is defined as one where MESG isn't MESG_SUCCESS or MESG_CANCELED.
- * Type: INTEGER
- */
- public static final String LAST_FAILURE_SOURCE = "lastFailureSource";
-
- /**
- * The MESG of the last sync that failed since the last successful sync.
- * Will be null if there are no syncs or if the last one succeeded. A failed
- * sync is defined as one where MESG isn't MESG_SUCCESS or MESG_CANCELED.
- * Type: STRING
- */
- public static final String LAST_FAILURE_MESG = "lastFailureMesg";
-
- /**
- * Is set to 1 if a sync is pending, 0 if not.
- * Type: INTEGER
- */
- public static final String PENDING = "pending";
- }
-
- /**
- * Provides constants and utility methods to access and use the history
- * table.
- */
- public static class History implements BaseColumns,
- StatsColumns,
- HistoryColumns {
-
- /**
- * The content url for this table.
- */
- public static final Uri CONTENT_URI =
- Uri.parse("content://sync/history");
-
- /** Enum value for a sync start event. */
- public static final int EVENT_START = 0;
-
- /** Enum value for a sync stop event. */
- public static final int EVENT_STOP = 1;
-
- // TODO: i18n -- grab these out of resources.
- /** String names for the sync event types. */
- public static final String[] EVENTS = { "START", "STOP" };
-
- /** Enum value for a server-initiated sync. */
- public static final int SOURCE_SERVER = 0;
-
- /** Enum value for a local-initiated sync. */
- public static final int SOURCE_LOCAL = 1;
- /**
- * Enum value for a poll-based sync (e.g., upon connection to
- * network)
- */
- public static final int SOURCE_POLL = 2;
-
- /** Enum value for a user-initiated sync. */
- public static final int SOURCE_USER = 3;
-
- // TODO: i18n -- grab these out of resources.
- /** String names for the sync source types. */
- public static final String[] SOURCES = { "SERVER",
- "LOCAL",
- "POLL",
- "USER" };
-
- // Error types
- public static final int ERROR_SYNC_ALREADY_IN_PROGRESS = 1;
- public static final int ERROR_AUTHENTICATION = 2;
- public static final int ERROR_IO = 3;
- public static final int ERROR_PARSE = 4;
- public static final int ERROR_CONFLICT = 5;
- public static final int ERROR_TOO_MANY_DELETIONS = 6;
- public static final int ERROR_TOO_MANY_RETRIES = 7;
- public static final int ERROR_INTERNAL = 8;
-
- // The MESG column will contain one of these or one of the Error types.
- public static final String MESG_SUCCESS = "success";
- public static final String MESG_CANCELED = "canceled";
-
- private static final String FINISHED_SINCE_WHERE_CLAUSE = EVENT + "=" + EVENT_STOP
- + " AND " + EVENT_TIME + ">? AND " + ACCOUNT + "=? AND " + ACCOUNT_TYPE + "=?"
- + " AND " + AUTHORITY + "=?";
-
- public static String mesgToString(String mesg) {
- if (MESG_SUCCESS.equals(mesg)) return mesg;
- if (MESG_CANCELED.equals(mesg)) return mesg;
- switch (Integer.parseInt(mesg)) {
- case ERROR_SYNC_ALREADY_IN_PROGRESS: return "already in progress";
- case ERROR_AUTHENTICATION: return "bad authentication";
- case ERROR_IO: return "network error";
- case ERROR_PARSE: return "parse error";
- case ERROR_CONFLICT: return "conflict detected";
- case ERROR_TOO_MANY_DELETIONS: return "too many deletions";
- case ERROR_TOO_MANY_RETRIES: return "too many retries";
- case ERROR_INTERNAL: return "internal error";
- default: return "unknown error";
- }
- }
-
- // utility class
- private History() {}
-
- /**
- * returns a cursor that queries the sync history in descending event time order
- * @param contentResolver the ContentResolver to use for the query
- * @return the cursor on the History table
- */
- public static Cursor query(ContentResolver contentResolver) {
- return contentResolver.query(CONTENT_URI, null, null, null, EVENT_TIME + " desc");
- }
-
- public static boolean hasNewerSyncFinished(ContentResolver contentResolver,
- Account account, String authority, long when) {
- Cursor c = contentResolver.query(CONTENT_URI, new String[]{_ID},
- FINISHED_SINCE_WHERE_CLAUSE,
- new String[]{Long.toString(when), account.mName, account.mType, authority},
- null);
- try {
- return c.getCount() > 0;
- } finally {
- c.close();
- }
- }
- }
-
- /**
- * Provides constants and utility methods to access and use the authority history
- * table, which contains information about syncs aggregated by account and authority.
- * All the HistoryColumns except for EVENT are present, plus the AuthorityHistoryColumns.
- */
- public static class Status extends History implements StatusColumns {
-
- /**
- * The content url for this table.
- */
- public static final Uri CONTENT_URI = Uri.parse("content://sync/status");
-
- // utility class
- private Status() {}
-
- /**
- * returns a cursor that queries the authority sync history in descending event order of
- * ACCOUNT, AUTHORITY
- * @param contentResolver the ContentResolver to use for the query
- * @return the cursor on the AuthorityHistory table
- */
- public static Cursor query(ContentResolver contentResolver) {
- return contentResolver.query(CONTENT_URI, null, null, null,
- ACCOUNT_TYPE + "," + ACCOUNT + "," + AUTHORITY);
- }
-
- public static class QueryMap extends ContentQueryMap {
- public QueryMap(ContentResolver contentResolver,
- boolean keepUpdated,
- Handler handlerForUpdateNotifications) {
- super(contentResolver.query(CONTENT_URI, null, null, null, null),
- _ID, keepUpdated, handlerForUpdateNotifications);
- }
-
- public ContentValues get(Account account, String authority) {
- Map rows = getRows();
- for (ContentValues values : rows.values()) {
- if (values.getAsString(ACCOUNT).equals(account.mName)
- && values.getAsString(ACCOUNT_TYPE).equals(account.mType)
- && values.getAsString(AUTHORITY).equals(authority)) {
- return values;
- }
- }
- return null;
- }
- }
- }
-
- /**
- * Provides constants and utility methods to access and use the pending syncs table
- */
- public static final class Pending implements BaseColumns,
- StatsColumns {
-
- /**
- * The content url for this table.
- */
- public static final Uri CONTENT_URI = Uri.parse("content://sync/pending");
-
- // utility class
- private Pending() {}
-
- public static class QueryMap extends ContentQueryMap {
- public QueryMap(ContentResolver contentResolver, boolean keepUpdated,
- Handler handlerForUpdateNotifications) {
- super(contentResolver.query(CONTENT_URI, null, null, null, null), _ID, keepUpdated,
- handlerForUpdateNotifications);
- }
-
- public boolean isPending(Account account, String authority) {
- Map rows = getRows();
- for (ContentValues values : rows.values()) {
- if (values.getAsString(ACCOUNT).equals(account.mName)
- && values.getAsString(ACCOUNT_TYPE).equals(account.mType)
- && values.getAsString(AUTHORITY).equals(authority)) {
- return true;
- }
- }
- return false;
- }
- }
- }
-
- /**
- * Columns from the history table.
- */
- public interface ActiveColumns {
- /**
- * The wallclock time of when the active sync started.
- * Type: INTEGER
- */
- public static final String START_TIME = "startTime";
- }
-
- /**
- * Provides constants and utility methods to access and use the pending syncs table
- */
- public static final class Active implements BaseColumns,
- StatsColumns,
- ActiveColumns {
-
- /**
- * The content url for this table.
- */
- public static final Uri CONTENT_URI = Uri.parse("content://sync/active");
-
- // utility class
- private Active() {}
-
- public static class QueryMap extends ContentQueryMap {
- public QueryMap(ContentResolver contentResolver, boolean keepUpdated,
- Handler handlerForUpdateNotifications) {
- super(contentResolver.query(CONTENT_URI, null, null, null, null), _ID, keepUpdated,
- handlerForUpdateNotifications);
- }
-
- public ContentValues getActiveSyncInfo() {
- Map rows = getRows();
- for (ContentValues values : rows.values()) {
- return values;
- }
- return null;
- }
-
- public Account getSyncingAccount() {
- ContentValues values = getActiveSyncInfo();
- if (values == null || TextUtils.isEmpty(values.getAsString(ACCOUNT))) {
- return null;
- }
- return new Account(values.getAsString(ACCOUNT), values.getAsString(ACCOUNT_TYPE));
- }
-
- public String getSyncingAuthority() {
- ContentValues values = getActiveSyncInfo();
- return (values == null) ? null : values.getAsString(AUTHORITY);
- }
-
- public long getSyncStartTime() {
- ContentValues values = getActiveSyncInfo();
- return (values == null) ? -1 : values.getAsLong(START_TIME);
- }
- }
- }
-
- /**
- * Columns in the settings table, which holds key/value pairs of settings.
- */
- public interface SettingsColumns {
- /**
- * The key of the setting
- * Type: TEXT
- */
- public static final String KEY = "name";
-
- /**
- * The value of the settings
- * Type: TEXT
- */
- public static final String VALUE = "value";
- }
-
- /**
- * Provides constants and utility methods to access and use the settings
- * table.
- */
- public static final class Settings implements BaseColumns, SettingsColumns {
- /**
- * The Uri of the settings table. This table behaves a little differently than
- * normal tables. Updates are not allowed, only inserts, and inserts cause a replace
- * to be performed, which first deletes the row if it is already present.
- */
- public static final Uri CONTENT_URI = Uri.parse("content://sync/settings");
-
- /** controls whether or not the device listens for sync tickles */
- public static final String SETTING_LISTEN_FOR_TICKLES = "listen_for_tickles";
-
- /** controls whether or not the individual provider is synced when tickles are received */
- public static final String SETTING_SYNC_PROVIDER_PREFIX = "sync_provider_";
-
- /** query column project */
- private static final String[] PROJECTION = { KEY, VALUE };
-
- /**
- * Convenience function for updating a single settings value as a
- * boolean. This will either create a new entry in the table if the
- * given name does not exist, or modify the value of the existing row
- * with that name. Note that internally setting values are always
- * stored as strings, so this function converts the given value to a
- * string before storing it.
- *
- * @param contentResolver the ContentResolver to use to access the settings table
- * @param name The name of the setting to modify.
- * @param val The new value for the setting.
- */
- static private void putBoolean(ContentResolver contentResolver, String name, boolean val) {
- ContentValues values = new ContentValues();
- values.put(KEY, name);
- values.put(VALUE, Boolean.toString(val));
- // this insert is translated into an update by the underlying Sync provider
- contentResolver.insert(CONTENT_URI, values);
- }
-
- /**
- * Convenience function for getting a setting value as a boolean without using the
- * QueryMap for light-weight setting querying.
- * @param contentResolver The ContentResolver for querying the setting.
- * @param name The name of the setting to query
- * @param def The default value for the setting.
- * @return The value of the setting.
- */
- static public boolean getBoolean(ContentResolver contentResolver,
- String name, boolean def) {
- Cursor cursor = contentResolver.query(
- CONTENT_URI,
- PROJECTION,
- KEY + "=?",
- new String[] { name },
- null);
- try {
- if (cursor != null && cursor.moveToFirst()) {
- return Boolean.parseBoolean(cursor.getString(1));
- }
- } finally {
- if (cursor != null) cursor.close();
- }
- return def;
- }
-
- /**
- * A convenience method to set whether or not the provider is synced when
- * it receives a network tickle.
- *
- * @param contentResolver the ContentResolver to use to access the settings table
- * @param providerName the provider whose behavior is being controlled
- * @param sync true if the provider should be synced when tickles are received for it
- */
- static public void setSyncProviderAutomatically(ContentResolver contentResolver,
- String providerName, boolean sync) {
- putBoolean(contentResolver, SETTING_SYNC_PROVIDER_PREFIX + providerName, sync);
- }
-
- /**
- * A convenience method to set whether or not the device should listen to tickles.
- *
- * @param contentResolver the ContentResolver to use to access the settings table
- * @param flag true if it should listen.
- */
- static public void setListenForNetworkTickles(ContentResolver contentResolver,
- boolean flag) {
- putBoolean(contentResolver, SETTING_LISTEN_FOR_TICKLES, flag);
- }
-
- public static class QueryMap extends ContentQueryMap {
- private ContentResolver mContentResolver;
-
- public QueryMap(ContentResolver contentResolver, boolean keepUpdated,
- Handler handlerForUpdateNotifications) {
- super(contentResolver.query(CONTENT_URI, null, null, null, null), KEY, keepUpdated,
- handlerForUpdateNotifications);
- mContentResolver = contentResolver;
- }
-
- /**
- * Check if the provider should be synced when a network tickle is received
- * @param providerName the provider whose setting we are querying
- * @return true of the provider should be synced when a network tickle is received
- */
- public boolean getSyncProviderAutomatically(String providerName) {
- return getBoolean(SETTING_SYNC_PROVIDER_PREFIX + providerName, true);
- }
-
- /**
- * Set whether or not the provider is synced when it receives a network tickle.
- *
- * @param providerName the provider whose behavior is being controlled
- * @param sync true if the provider should be synced when tickles are received for it
- */
- public void setSyncProviderAutomatically(String providerName, boolean sync) {
- Settings.setSyncProviderAutomatically(mContentResolver, providerName, sync);
- }
-
- /**
- * Set whether or not the device should listen for tickles.
- *
- * @param flag true if it should listen.
- */
- public void setListenForNetworkTickles(boolean flag) {
- Settings.setListenForNetworkTickles(mContentResolver, flag);
- }
-
- /**
- * Check if the device should listen to tickles.
-
- * @return true if it should
- */
- public boolean getListenForNetworkTickles() {
- return getBoolean(SETTING_LISTEN_FOR_TICKLES, true);
- }
-
- /**
- * Convenience function for retrieving a single settings value
- * as a boolean.
- *
- * @param name The name of the setting to retrieve.
- * @param def Value to return if the setting is not defined.
- * @return The setting's current value, or 'def' if it is not defined.
- */
- private boolean getBoolean(String name, boolean def) {
- ContentValues values = getValues(name);
- return values != null ? values.getAsBoolean(VALUE) : def;
- }
- }
- }
-}
diff --git a/packages/SubscribedFeedsProvider/src/com/android/providers/subscribedfeeds/SubscribedFeedsIntentService.java b/packages/SubscribedFeedsProvider/src/com/android/providers/subscribedfeeds/SubscribedFeedsIntentService.java
index 99924209cd47c..3cd2cc4a00cc4 100644
--- a/packages/SubscribedFeedsProvider/src/com/android/providers/subscribedfeeds/SubscribedFeedsIntentService.java
+++ b/packages/SubscribedFeedsProvider/src/com/android/providers/subscribedfeeds/SubscribedFeedsIntentService.java
@@ -16,9 +16,7 @@ import android.database.sqlite.SQLiteFullException;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.os.Bundle;
-import android.os.RemoteException;
import android.text.TextUtils;
-import android.net.Uri;
import android.accounts.Account;
import java.util.ArrayList;
@@ -113,8 +111,9 @@ public class SubscribedFeedsIntentService extends IntentService {
+ "and " + SubscribedFeeds.Feeds.FEED + "= ?";
try {
// TODO(fredq) fix the hardcoded type
+ final Account account = new Account(accountName, "com.google.GAIA");
c = context.getContentResolver().query(SubscribedFeeds.Feeds.CONTENT_URI,
- null, where, new String[]{accountName, "com.google.GAIA", feed}, null);
+ null, where, new String[]{account.mName, account.mType, feed}, null);
if (c.getCount() == 0) {
Log.w(TAG, "received tickle for non-existent feed: "
+ "account " + accountName + ", feed " + feed);
@@ -125,22 +124,14 @@ public class SubscribedFeedsIntentService extends IntentService {
String authority = c.getString(c.getColumnIndexOrThrow(
SubscribedFeeds.Feeds.AUTHORITY));
EventLog.writeEvent(LOG_TICKLE, authority);
- try {
- if (!ContentResolver.getContentService()
- .getSyncProviderAutomatically(authority)) {
- Log.d(TAG, "supressing tickle since provider " + authority
- + " is configured to not sync automatically");
- continue;
- }
- } catch (RemoteException e) {
+ if (!ContentResolver.getSyncAutomatically(account, authority)) {
+ Log.d(TAG, "supressing tickle since provider " + authority
+ + " is configured to not sync automatically");
continue;
}
- Uri uri = Uri.parse("content://" + authority);
Bundle extras = new Bundle();
- extras.putParcelable(ContentResolver.SYNC_EXTRAS_ACCOUNT,
- new Account(accountName, "com.google.GAIA"));
extras.putString("feed", feed);
- context.getContentResolver().startSync(uri, extras);
+ ContentResolver.requestSync(account, authority, extras);
}
} finally {
if (c != null) c.deactivate();
diff --git a/test-runner/android/test/SyncBaseInstrumentation.java b/test-runner/android/test/SyncBaseInstrumentation.java
index bf9e7832019dd..a860bb393f0c1 100644
--- a/test-runner/android/test/SyncBaseInstrumentation.java
+++ b/test-runner/android/test/SyncBaseInstrumentation.java
@@ -19,7 +19,6 @@ package android.test;
import android.content.ContentResolver;
import android.content.Context;
import android.os.Bundle;
-import android.os.RemoteException;
import android.os.SystemClock;
import android.net.Uri;
import android.accounts.Account;
@@ -45,13 +44,12 @@ public class SyncBaseInstrumentation extends InstrumentationTestCase {
* Syncs the specified provider.
* @throws Exception
*/
- protected void syncProvider(Uri uri, String account, String authority) throws Exception {
+ protected void syncProvider(Uri uri, String accountName, String authority) throws Exception {
Bundle extras = new Bundle();
- extras.putBoolean(ContentResolver.SYNC_EXTRAS_FORCE, true);
- Account account1 = new Account(account, "com.google.GAIA");
- extras.putParcelable(ContentResolver.SYNC_EXTRAS_ACCOUNT, account1);
+ extras.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);
+ Account account = new Account(accountName, "com.google.GAIA");
- mContentResolver.startSync(uri, extras);
+ ContentResolver.requestSync(account, authority, extras);
long startTimeInMillis = SystemClock.elapsedRealtime();
long endTimeInMillis = startTimeInMillis + MAX_TIME_FOR_SYNC_IN_MINS * 60000;
@@ -66,7 +64,7 @@ public class SyncBaseInstrumentation extends InstrumentationTestCase {
break;
}
- if (isSyncActive(account1, authority)) {
+ if (ContentResolver.isSyncActive(account, authority)) {
counter = 0;
continue;
}
@@ -75,24 +73,7 @@ public class SyncBaseInstrumentation extends InstrumentationTestCase {
}
protected void cancelSyncsandDisableAutoSync() {
- try {
- ContentResolver.getContentService().setListenForNetworkTickles(false);
- } catch (RemoteException e) {
- }
- mContentResolver.cancelSync(null);
- }
-
- /**
- * This method tests if any sync is active or not. Sync is considered to be active if the
- * entry is in either the Pending or Active tables.
- * @return
- */
- private boolean isSyncActive(Account account, String authority) {
- try {
- return ContentResolver.getContentService().isSyncActive(account,
- authority);
- } catch (RemoteException e) {
- return false;
- }
+ ContentResolver.setMasterSyncAutomatically(false);
+ ContentResolver.cancelSync(null /* all accounts */, null /* all authorities */);
}
}