summaryrefslogtreecommitdiffstats
path: root/services/java/com/android/server/content
diff options
context:
space:
mode:
authorMatthew Williams <mjwilliams@google.com>2013-08-20 15:32:20 -0700
committerMatthew Williams <mjwilliams@google.com>2013-08-30 21:28:53 +0000
commit6222288bfbae46550b4914ef1eb12c69dc1f716c (patch)
treeaaba6a3c0cf4ad8fee6b6e19522520dcf8b01ae6 /services/java/com/android/server/content
parent4b2993123bf9a1c56d0a16b032612834dd418520 (diff)
downloadframeworks_base-6222288bfbae46550b4914ef1eb12c69dc1f716c.zip
frameworks_base-6222288bfbae46550b4914ef1eb12c69dc1f716c.tar.gz
frameworks_base-6222288bfbae46550b4914ef1eb12c69dc1f716c.tar.bz2
DO NOT MERGE. Remove service component for KLP.
1) As discussed, lack of internal clients -> remove SyncService component from KLP. This CL reverts that addition. 2) Also includes javadoc cleanup of existing API. 3) Fix naming of allowMetered() -> disallowMetered() in API 4) Removed one-off sync in the future, as it doesn't make sense for sync adapters. Change-Id: I1b17094e6edafb2955cdfb99f39b44274fbe86f9
Diffstat (limited to 'services/java/com/android/server/content')
-rw-r--r--services/java/com/android/server/content/ContentService.java20
-rw-r--r--services/java/com/android/server/content/SyncManager.java189
-rw-r--r--services/java/com/android/server/content/SyncOperation.java40
-rw-r--r--services/java/com/android/server/content/SyncStorageEngine.java2
4 files changed, 19 insertions, 232 deletions
diff --git a/services/java/com/android/server/content/ContentService.java b/services/java/com/android/server/content/ContentService.java
index a56af08..7c82821 100644
--- a/services/java/com/android/server/content/ContentService.java
+++ b/services/java/com/android/server/content/ContentService.java
@@ -19,7 +19,6 @@ package com.android.server.content;
import android.Manifest;
import android.accounts.Account;
import android.app.ActivityManager;
-import android.content.ComponentName;
import android.content.ContentResolver;
import android.content.Context;
import android.content.IContentService;
@@ -363,8 +362,8 @@ public final class ContentService extends IContentService.Stub {
if (syncManager != null) {
if (request.hasAuthority()) {
// Sync Adapter registered with the system - old API.
- final Account account = request.getProviderInfo().first;
- final String provider = request.getProviderInfo().second;
+ final Account account = request.getAccount();
+ final String provider = request.getProvider();
if (request.isPeriodic()) {
mContext.enforceCallingOrSelfPermission(
Manifest.permission.WRITE_SYNC_SETTINGS,
@@ -386,20 +385,7 @@ public final class ContentService extends IContentService.Stub {
false /* onlyThoseWithUnknownSyncableState */);
}
} else {
- // Anonymous sync - new API.
- final ComponentName syncService = request.getService();
- if (request.isPeriodic()) {
- throw new RuntimeException("Periodic anonymous syncs not implemented yet.");
- } else {
- long beforeRuntimeMillis = (flextime) * 1000;
- long runtimeMillis = runAtTime * 1000;
- syncManager.scheduleSync(
- syncService, userId, uId, extras,
- beforeRuntimeMillis,
- runtimeMillis,
- false /* onlyThoseWithUnknownSyncableState */); // Empty function.
- throw new RuntimeException("One-off anonymous syncs not implemented yet.");
- }
+ Log.w(TAG, "Unrecognised sync parameters, doing nothing.");
}
}
} finally {
diff --git a/services/java/com/android/server/content/SyncManager.java b/services/java/com/android/server/content/SyncManager.java
index a6b69a2..9a41166 100644
--- a/services/java/com/android/server/content/SyncManager.java
+++ b/services/java/com/android/server/content/SyncManager.java
@@ -87,6 +87,7 @@ import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
@@ -539,177 +540,6 @@ public class SyncManager {
}
/**
- * Initiate a sync using the new anonymous service API.
- * TODO: Implement.
- * @param cname SyncService component bound to in order to perform the sync.
- * @param userId the id of the user whose accounts are to be synced. If userId is USER_ALL,
- * then all users' accounts are considered.
- * @param uid Linux uid of the application that is performing the sync.
- * @param extras a Map of SyncAdapter-specific information to control
- * syncs of a specific provider. Can be null.
- * @param beforeRunTimeMillis
- * @param runtimeMillis
- */
- public void scheduleSync(ComponentName cname, int userId, int uid, Bundle extras,
- long beforeRunTimeMillis, long runtimeMillis,
- boolean onlyThoseWithUnknownSyncableState) {
-/**
- boolean isLoggable = Log.isLoggable(TAG, Log.VERBOSE);
-
- final boolean backgroundDataUsageAllowed = !mBootCompleted ||
- getConnectivityManager().getBackgroundDataSetting();
-
- if (extras == null) {
- extras = new Bundle();
- }
- if (isLoggable) {
- Log.e(TAG, requestedAccount + " " + extras.toString() + " " + requestedAuthority);
- }
- Boolean expedited = extras.getBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, false);
- if (expedited) {
- runtimeMillis = -1; // this means schedule at the front of the queue
- }
-
- AccountAndUser[] accounts;
- if (requestedAccount != null && userId != UserHandle.USER_ALL) {
- accounts = new AccountAndUser[] { new AccountAndUser(requestedAccount, userId) };
- } else {
- // if the accounts aren't configured yet then we can't support an account-less
- // sync request
- accounts = mRunningAccounts;
- if (accounts.length == 0) {
- if (isLoggable) {
- Log.v(TAG, "scheduleSync: no accounts configured, dropping");
- }
- return;
- }
- }
-
- final boolean uploadOnly = extras.getBoolean(ContentResolver.SYNC_EXTRAS_UPLOAD, false);
- final boolean manualSync = extras.getBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, false);
- if (manualSync) {
- extras.putBoolean(ContentResolver.SYNC_EXTRAS_IGNORE_BACKOFF, true);
- extras.putBoolean(ContentResolver.SYNC_EXTRAS_IGNORE_SETTINGS, true);
- }
- final boolean ignoreSettings =
- extras.getBoolean(ContentResolver.SYNC_EXTRAS_IGNORE_SETTINGS, false);
-
- int source;
- if (uploadOnly) {
- source = SyncStorageEngine.SOURCE_LOCAL;
- } else if (manualSync) {
- source = SyncStorageEngine.SOURCE_USER;
- } else if (requestedAuthority == null) {
- source = SyncStorageEngine.SOURCE_POLL;
- } else {
- // this isn't strictly server, since arbitrary callers can (and do) request
- // a non-forced two-way sync on a specific url
- source = SyncStorageEngine.SOURCE_SERVER;
- }
-
- for (AccountAndUser account : accounts) {
- // Compile a list of authorities that have sync adapters.
- // For each authority sync each account that matches a sync adapter.
- final HashSet<String> syncableAuthorities = new HashSet<String>();
- for (RegisteredServicesCache.ServiceInfo<SyncAdapterType> syncAdapter :
- mSyncAdapters.getAllServices(account.userId)) {
- syncableAuthorities.add(syncAdapter.type.authority);
- }
-
- // 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 (requestedAuthority != null) {
- final boolean hasSyncAdapter = syncableAuthorities.contains(requestedAuthority);
- syncableAuthorities.clear();
- if (hasSyncAdapter) syncableAuthorities.add(requestedAuthority);
- }
-
- for (String authority : syncableAuthorities) {
- int isSyncable = getIsSyncable(account.account, account.userId,
- authority);
- if (isSyncable == 0) {
- continue;
- }
- final RegisteredServicesCache.ServiceInfo<SyncAdapterType> syncAdapterInfo;
- syncAdapterInfo = mSyncAdapters.getServiceInfo(
- SyncAdapterType.newKey(authority, account.account.type), account.userId);
- if (syncAdapterInfo == null) {
- continue;
- }
- final boolean allowParallelSyncs = syncAdapterInfo.type.allowParallelSyncs();
- final boolean isAlwaysSyncable = syncAdapterInfo.type.isAlwaysSyncable();
- if (isSyncable < 0 && isAlwaysSyncable) {
- mSyncStorageEngine.setIsSyncable(account.account, account.userId, authority, 1);
- isSyncable = 1;
- }
- if (onlyThoseWithUnkownSyncableState && isSyncable >= 0) {
- continue;
- }
- if (!syncAdapterInfo.type.supportsUploading() && uploadOnly) {
- continue;
- }
-
- // always allow if the isSyncable state is unknown
- boolean syncAllowed =
- (isSyncable < 0)
- || ignoreSettings
- || (backgroundDataUsageAllowed
- && mSyncStorageEngine.getMasterSyncAutomatically(account.userId)
- && mSyncStorageEngine.getSyncAutomatically(account.account,
- account.userId, authority));
- if (!syncAllowed) {
- if (isLoggable) {
- Log.d(TAG, "scheduleSync: sync of " + account + ", " + authority
- + " is not allowed, dropping request");
- }
- continue;
- }
-
- Pair<Long, Long> backoff = mSyncStorageEngine
- .getBackoff(account.account, account.userId, authority);
- long delayUntil = mSyncStorageEngine.getDelayUntilTime(account.account,
- account.userId, authority);
- final long backoffTime = backoff != null ? backoff.first : 0;
- if (isSyncable < 0) {
- // Initialisation sync.
- Bundle newExtras = new Bundle();
- newExtras.putBoolean(ContentResolver.SYNC_EXTRAS_INITIALIZE, true);
- if (isLoggable) {
- Log.v(TAG, "schedule initialisation Sync:"
- + ", delay until " + delayUntil
- + ", run by " + 0
- + ", source " + source
- + ", account " + account
- + ", authority " + authority
- + ", extras " + newExtras);
- }
- scheduleSyncOperation(
- new SyncOperation(account.account, account.userId, reason, source,
- authority, newExtras, 0 /* immediate , 0 /* No flex time,
- backoffTime, delayUntil, allowParallelSyncs));
- }
- if (!onlyThoseWithUnkownSyncableState) {
- if (isLoggable) {
- Log.v(TAG, "scheduleSync:"
- + " delay until " + delayUntil
- + " run by " + runtimeMillis
- + " flex " + beforeRuntimeMillis
- + ", source " + source
- + ", account " + account
- + ", authority " + authority
- + ", extras " + extras);
- }
- scheduleSyncOperation(
- new SyncOperation(account.account, account.userId, reason, source,
- authority, extras, runtimeMillis, beforeRuntimeMillis,
- backoffTime, delayUntil, allowParallelSyncs));
- }
- }
- }*/
- }
-
- /**
* Initiate a sync. This can start a sync for all providers
* (pass null to url, set onlyTicklable to false), only those
* providers that are marked as ticklable (pass null to url,
@@ -2190,17 +2020,14 @@ public class SyncManager {
for (int i = 0, N = authorityInfo.periodicSyncs.size(); i < N; i++) {
final PeriodicSync sync = authorityInfo.periodicSyncs.get(i);
final Bundle extras = sync.extras;
- final Long periodInMillis = sync.period * 1000;
- final Long flexInMillis = sync.flexTime * 1000;
+ final long periodInMillis = sync.period * 1000;
+ final long flexInMillis = sync.flexTime * 1000;
// Skip if the period is invalid.
if (periodInMillis <= 0) {
continue;
}
// Find when this periodic sync was last scheduled to run.
final long lastPollTimeAbsolute = status.getPeriodicSyncTime(i);
- final long shiftedLastPollTimeAbsolute =
- (0 < lastPollTimeAbsolute - mSyncRandomOffsetMillis) ?
- (lastPollTimeAbsolute - mSyncRandomOffsetMillis) : 0;
long remainingMillis
= periodInMillis - (shiftedNowAbsolute % periodInMillis);
long timeSinceLastRunMillis
@@ -2217,7 +2044,6 @@ public class SyncManager {
+ " remaining: " + (remainingMillis)
+ " time_since_last: " + timeSinceLastRunMillis
+ " last poll absol: " + lastPollTimeAbsolute
- + " last poll shifed: " + shiftedLastPollTimeAbsolute
+ " shifted now: " + shiftedNowAbsolute
+ " run_early: " + runEarly);
}
@@ -2392,6 +2218,15 @@ public class SyncManager {
}
continue;
}
+
+ // If the op isn't allowed on metered networks and we're on one, drop it.
+ if (getConnectivityManager().isActiveNetworkMetered()
+ && op.isMeteredDisallowed()) {
+ operationIterator.remove();
+ mSyncStorageEngine.deleteFromPending(op.pendingOperation);
+ continue;
+ }
+
// TODO: change this behaviour for non-registered syncs.
final RegisteredServicesCache.ServiceInfo<SyncAdapterType> syncAdapterInfo;
syncAdapterInfo = mSyncAdapters.getServiceInfo(
diff --git a/services/java/com/android/server/content/SyncOperation.java b/services/java/com/android/server/content/SyncOperation.java
index ce1dde4..4856747 100644
--- a/services/java/com/android/server/content/SyncOperation.java
+++ b/services/java/com/android/server/content/SyncOperation.java
@@ -111,40 +111,6 @@ public class SyncOperation implements Comparable {
this.key = toKey();
}
- public SyncOperation(SyncRequest request, int userId, int reason, int source, long backoff,
- long delayUntil, boolean allowParallelSyncs) {
- if (request.hasAuthority()) {
- Pair<Account, String> providerInfo = request.getProviderInfo();
- this.account = providerInfo.first;
- this.authority = providerInfo.second;
- this.service = null;
- } else {
- this.service = request.getService();
- this.account = null;
- this.authority = null;
- }
- this.userId = userId;
- this.reason = reason;
- this.syncSource = source;
- this.allowParallelSyncs = allowParallelSyncs;
- this.extras = new Bundle(extras);
- cleanBundle(this.extras);
- this.delayUntil = delayUntil;
- this.backoff = backoff;
- final long now = SystemClock.elapsedRealtime();
- if (request.isExpedited()) {
- this.expedited = true;
- this.latestRunTime = now;
- this.flexTime = 0;
- } else {
- this.expedited = false;
- this.latestRunTime = now + (request.getSyncRunTime() * 1000);
- this.flexTime = request.getSyncFlexTime() * 1000;
- }
- updateEffectiveRunTime();
- this.key = toKey();
- }
-
/**
* Make sure the bundle attached to this SyncOperation doesn't have unnecessary
* flags set.
@@ -159,7 +125,7 @@ public class SyncOperation implements Comparable {
removeFalseExtra(bundle, ContentResolver.SYNC_EXTRAS_DISCARD_LOCAL_DELETIONS);
removeFalseExtra(bundle, ContentResolver.SYNC_EXTRAS_EXPEDITED);
removeFalseExtra(bundle, ContentResolver.SYNC_EXTRAS_OVERRIDE_TOO_MANY_DELETIONS);
- removeFalseExtra(bundle, ContentResolver.SYNC_EXTRAS_ALLOW_METERED);
+ removeFalseExtra(bundle, ContentResolver.SYNC_EXTRAS_DISALLOW_METERED);
// Remove Config data.
bundle.remove(ContentResolver.SYNC_EXTRAS_EXPECTED_UPLOAD);
@@ -245,8 +211,8 @@ public class SyncOperation implements Comparable {
}
}
- public boolean isMetered() {
- return extras.getBoolean(ContentResolver.SYNC_EXTRAS_ALLOW_METERED, false);
+ public boolean isMeteredDisallowed() {
+ return extras.getBoolean(ContentResolver.SYNC_EXTRAS_DISALLOW_METERED, false);
}
public boolean isInitialization() {
diff --git a/services/java/com/android/server/content/SyncStorageEngine.java b/services/java/com/android/server/content/SyncStorageEngine.java
index e3693f8..1b9ed98 100644
--- a/services/java/com/android/server/content/SyncStorageEngine.java
+++ b/services/java/com/android/server/content/SyncStorageEngine.java
@@ -71,7 +71,7 @@ import java.util.TimeZone;
public class SyncStorageEngine extends Handler {
private static final String TAG = "SyncManager";
- private static final boolean DEBUG = true;
+ private static final boolean DEBUG = false;
private static final String TAG_FILE = "SyncManagerFile";
private static final String XML_ATTR_NEXT_AUTHORITY_ID = "nextAuthorityId";