resolved conflicts for merge of 94b51810 to master
Change-Id: Ida818f066b66c356a84c80e5eab0a4e2cf4ebd49
diff --git a/services/java/com/android/server/content/ContentService.java b/services/java/com/android/server/content/ContentService.java
index 48b3259..11c3fa0 100644
--- a/services/java/com/android/server/content/ContentService.java
+++ b/services/java/com/android/server/content/ContentService.java
@@ -42,6 +42,7 @@
import android.os.ServiceManager;
import android.os.SystemProperties;
import android.os.UserHandle;
+import android.text.TextUtils;
import android.util.Log;
import android.util.Pair;
import android.util.Slog;
@@ -344,12 +345,9 @@
* and
* anonymous OR provider sync.
* Depending on the request, we enqueue to suit in the SyncManager.
- * @param request
+ * @param request The request object. Validation of this object is done by its builder.
*/
public void sync(SyncRequest request) {
- Bundle extras = request.getBundle();
- ContentResolver.validateSyncExtrasBundle(extras);
-
int userId = UserHandle.getCallingUserId();
int callerUid = Binder.getCallingUid();
// This makes it so that future permission checks will be in the context of this
@@ -357,8 +355,11 @@
long identityToken = clearCallingIdentity();
try {
SyncManager syncManager = getSyncManager();
- if (syncManager == null) return;
+ if (syncManager == null) {
+ return;
+ }
+ Bundle extras = request.getBundle();
long flextime = request.getSyncFlexTime();
long runAtTime = request.getSyncRunTime();
if (request.isPeriodic()) {
@@ -412,9 +413,13 @@
* null.
* @param cname cancel syncs running on this service, or null for provider/account.
*/
+ @Override
public void cancelSync(Account account, String authority, ComponentName cname) {
- int userId = UserHandle.getCallingUserId();
+ if (authority != null && authority.length() == 0) {
+ throw new IllegalArgumentException("Authority must be non-empty");
+ }
+ int userId = UserHandle.getCallingUserId();
// This makes it so that future permission checks will be in the context of this
// process rather than the caller's process. We will restore this before returning.
long identityToken = clearCallingIdentity();
@@ -491,8 +496,8 @@
public boolean getSyncAutomatically(Account account, String providerName) {
mContext.enforceCallingOrSelfPermission(Manifest.permission.READ_SYNC_SETTINGS,
"no permission to read the sync settings");
- int userId = UserHandle.getCallingUserId();
+ int userId = UserHandle.getCallingUserId();
long identityToken = clearCallingIdentity();
try {
SyncManager syncManager = getSyncManager();
@@ -508,10 +513,13 @@
@Override
public void setSyncAutomatically(Account account, String providerName, boolean sync) {
+ if (TextUtils.isEmpty(providerName)) {
+ throw new IllegalArgumentException("Authority must be non-empty");
+ }
mContext.enforceCallingOrSelfPermission(Manifest.permission.WRITE_SYNC_SETTINGS,
"no permission to write the sync settings");
- int userId = UserHandle.getCallingUserId();
+ int userId = UserHandle.getCallingUserId();
long identityToken = clearCallingIdentity();
try {
SyncManager syncManager = getSyncManager();
@@ -525,12 +533,19 @@
}
/** Old API. Schedule periodic sync with default flex time. */
+ @Override
public void addPeriodicSync(Account account, String authority, Bundle extras,
long pollFrequency) {
+ if (account == null) {
+ throw new IllegalArgumentException("Account must not be null");
+ }
+ if (TextUtils.isEmpty(authority)) {
+ throw new IllegalArgumentException("Authority must not be empty.");
+ }
mContext.enforceCallingOrSelfPermission(Manifest.permission.WRITE_SYNC_SETTINGS,
"no permission to write the sync settings");
- int userId = UserHandle.getCallingUserId();
+ int userId = UserHandle.getCallingUserId();
if (pollFrequency < 60) {
Slog.w(TAG, "Requested poll frequency of " + pollFrequency
+ " seconds being rounded up to 60 seconds.");
@@ -553,10 +568,16 @@
}
public void removePeriodicSync(Account account, String authority, Bundle extras) {
+ if (account == null) {
+ throw new IllegalArgumentException("Account must not be null");
+ }
+ if (TextUtils.isEmpty(authority)) {
+ throw new IllegalArgumentException("Authority must not be empty");
+ }
mContext.enforceCallingOrSelfPermission(Manifest.permission.WRITE_SYNC_SETTINGS,
"no permission to write the sync settings");
- int userId = UserHandle.getCallingUserId();
+ int userId = UserHandle.getCallingUserId();
long identityToken = clearCallingIdentity();
try {
getSyncManager().getSyncStorageEngine()
@@ -568,13 +589,20 @@
}
}
+
public List<PeriodicSync> getPeriodicSyncs(Account account, String providerName,
ComponentName cname) {
+ if (account == null) {
+ throw new IllegalArgumentException("Account must not be null");
+ }
+ if (TextUtils.isEmpty(providerName)) {
+ throw new IllegalArgumentException("Authority must not be empty");
+ }
mContext.enforceCallingOrSelfPermission(Manifest.permission.READ_SYNC_SETTINGS,
"no permission to read the sync settings");
- int userId = UserHandle.getCallingUserId();
- int callerUid = Binder.getCallingUid();
+ int callerUid = Binder.getCallingUid();
+ int userId = UserHandle.getCallingUserId();
long identityToken = clearCallingIdentity();
try {
if (cname == null) {
@@ -611,10 +639,13 @@
}
public void setIsSyncable(Account account, String providerName, int syncable) {
+ if (TextUtils.isEmpty(providerName)) {
+ throw new IllegalArgumentException("Authority must not be empty");
+ }
mContext.enforceCallingOrSelfPermission(Manifest.permission.WRITE_SYNC_SETTINGS,
"no permission to write the sync settings");
- int userId = UserHandle.getCallingUserId();
+ int userId = UserHandle.getCallingUserId();
long identityToken = clearCallingIdentity();
try {
SyncManager syncManager = getSyncManager();
@@ -670,8 +701,8 @@
public boolean getMasterSyncAutomatically() {
mContext.enforceCallingOrSelfPermission(Manifest.permission.READ_SYNC_SETTINGS,
"no permission to read the sync settings");
- int userId = UserHandle.getCallingUserId();
+ int userId = UserHandle.getCallingUserId();
long identityToken = clearCallingIdentity();
try {
SyncManager syncManager = getSyncManager();
@@ -688,8 +719,8 @@
public void setMasterSyncAutomatically(boolean flag) {
mContext.enforceCallingOrSelfPermission(Manifest.permission.WRITE_SYNC_SETTINGS,
"no permission to write the sync settings");
- int userId = UserHandle.getCallingUserId();
+ int userId = UserHandle.getCallingUserId();
long identityToken = clearCallingIdentity();
try {
SyncManager syncManager = getSyncManager();
@@ -729,8 +760,8 @@
public List<SyncInfo> getCurrentSyncs() {
mContext.enforceCallingOrSelfPermission(Manifest.permission.READ_SYNC_STATS,
"no permission to read the sync stats");
- int userId = UserHandle.getCallingUserId();
+ int userId = UserHandle.getCallingUserId();
long identityToken = clearCallingIdentity();
try {
return getSyncManager().getSyncStorageEngine().getCurrentSyncs(userId);
@@ -740,8 +771,12 @@
}
public SyncStatusInfo getSyncStatus(Account account, String authority, ComponentName cname) {
+ if (TextUtils.isEmpty(authority)) {
+ throw new IllegalArgumentException("Authority must not be empty");
+ }
mContext.enforceCallingOrSelfPermission(Manifest.permission.READ_SYNC_STATS,
"no permission to read the sync stats");
+
int userId = UserHandle.getCallingUserId();
int callerUid = Binder.getCallingUid();
long identityToken = clearCallingIdentity();
@@ -768,8 +803,9 @@
public boolean isSyncPending(Account account, String authority, ComponentName cname) {
mContext.enforceCallingOrSelfPermission(Manifest.permission.READ_SYNC_STATS,
"no permission to read the sync stats");
- int userId = UserHandle.getCallingUserId();
+
int callerUid = Binder.getCallingUid();
+ int userId = UserHandle.getCallingUserId();
long identityToken = clearCallingIdentity();
SyncManager syncManager = getSyncManager();
if (syncManager == null) return false;
diff --git a/services/java/com/android/server/content/SyncManager.java b/services/java/com/android/server/content/SyncManager.java
index 5c0f902..18bf115 100644
--- a/services/java/com/android/server/content/SyncManager.java
+++ b/services/java/com/android/server/content/SyncManager.java
@@ -68,6 +68,7 @@
import android.provider.Settings;
import android.text.format.DateUtils;
import android.text.format.Time;
+import android.text.TextUtils;
import android.util.EventLog;
import android.util.Log;
import android.util.Pair;
@@ -2149,6 +2150,13 @@
for (Pair<AuthorityInfo, SyncStatusInfo> info : infos) {
final AuthorityInfo authorityInfo = info.first;
final SyncStatusInfo status = info.second;
+
+ if (TextUtils.isEmpty(authorityInfo.target.provider)) {
+ Log.e(TAG, "Got an empty provider string. Skipping: "
+ + authorityInfo.target.provider);
+ continue;
+ }
+
if (!isDispatchable(authorityInfo.target)) {
continue;
}
diff --git a/services/java/com/android/server/content/SyncStorageEngine.java b/services/java/com/android/server/content/SyncStorageEngine.java
index 1d8ca5a..1227374 100644
--- a/services/java/com/android/server/content/SyncStorageEngine.java
+++ b/services/java/com/android/server/content/SyncStorageEngine.java
@@ -1486,9 +1486,9 @@
*/
public SyncStatusInfo getStatusByAuthority(EndPoint info) {
if (info.target_provider && (info.account == null || info.provider == null)) {
- throw new IllegalArgumentException();
+ return null;
} else if (info.target_service && info.service == null) {
- throw new IllegalArgumentException();
+ return null;
}
synchronized (mAuthorities) {
final int N = mSyncStatus.size();