Merge "Adds per-user APIs required by the Settings app"
This commit is contained in:
committed by
Android (Google) Code Review
commit
1e1f2e8926
@@ -1926,8 +1926,17 @@ public abstract class ContentResolver {
|
||||
* @param sync true if the provider should be synced when tickles are received for it
|
||||
*/
|
||||
public static void setSyncAutomatically(Account account, String authority, boolean sync) {
|
||||
setSyncAutomaticallyAsUser(account, authority, sync, UserHandle.getCallingUserId());
|
||||
}
|
||||
|
||||
/**
|
||||
* @see #setSyncAutomatically(Account, String, boolean)
|
||||
* @hide
|
||||
*/
|
||||
public static void setSyncAutomaticallyAsUser(Account account, String authority, boolean sync,
|
||||
int userId) {
|
||||
try {
|
||||
getContentService().setSyncAutomatically(account, authority, sync);
|
||||
getContentService().setSyncAutomaticallyAsUser(account, authority, sync, userId);
|
||||
} catch (RemoteException e) {
|
||||
// exception ignored; if this is thrown then it means the runtime is in the midst of
|
||||
// being restarted
|
||||
@@ -2268,8 +2277,16 @@ public abstract class ContentResolver {
|
||||
* @return true if there is a pending sync with the matching account and authority
|
||||
*/
|
||||
public static boolean isSyncPending(Account account, String authority) {
|
||||
return isSyncPendingAsUser(account, authority, UserHandle.getCallingUserId());
|
||||
}
|
||||
|
||||
/**
|
||||
* @see #requestSync(Account, String, Bundle)
|
||||
* @hide
|
||||
*/
|
||||
public static boolean isSyncPendingAsUser(Account account, String authority, int userId) {
|
||||
try {
|
||||
return getContentService().isSyncPending(account, authority, null);
|
||||
return getContentService().isSyncPendingAsUser(account, authority, null, userId);
|
||||
} catch (RemoteException e) {
|
||||
throw new RuntimeException("the ContentService should always be reachable", e);
|
||||
}
|
||||
|
||||
@@ -82,6 +82,8 @@ interface IContentService {
|
||||
* @param sync true if the provider should be synced when tickles are received for it
|
||||
*/
|
||||
void setSyncAutomatically(in Account account, String providerName, boolean sync);
|
||||
void setSyncAutomaticallyAsUser(in Account account, String providerName, boolean sync,
|
||||
int userId);
|
||||
|
||||
/**
|
||||
* Get a list of periodic operations for a specified authority, or service.
|
||||
@@ -170,6 +172,8 @@ interface IContentService {
|
||||
* non-null.
|
||||
*/
|
||||
boolean isSyncPending(in Account account, String authority, in ComponentName cname);
|
||||
boolean isSyncPendingAsUser(in Account account, String authority, in ComponentName cname,
|
||||
int userId);
|
||||
|
||||
void addStatusChangeListener(int mask, ISyncStatusObserver callback);
|
||||
|
||||
|
||||
@@ -537,19 +537,26 @@ public final class ContentService extends IContentService.Stub {
|
||||
|
||||
@Override
|
||||
public void setSyncAutomatically(Account account, String providerName, boolean sync) {
|
||||
setSyncAutomaticallyAsUser(account, providerName, sync, UserHandle.getCallingUserId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSyncAutomaticallyAsUser(Account account, String providerName, boolean sync,
|
||||
int userId) {
|
||||
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");
|
||||
enforceCrossUserPermission(userId,
|
||||
"no permission to modify the sync settings for user " + userId);
|
||||
|
||||
int userId = UserHandle.getCallingUserId();
|
||||
long identityToken = clearCallingIdentity();
|
||||
try {
|
||||
SyncManager syncManager = getSyncManager();
|
||||
if (syncManager != null) {
|
||||
syncManager.getSyncStorageEngine()
|
||||
.setSyncAutomatically(account, userId, providerName, sync);
|
||||
syncManager.getSyncStorageEngine().setSyncAutomatically(account, userId,
|
||||
providerName, sync);
|
||||
}
|
||||
} finally {
|
||||
restoreCallingIdentity(identityToken);
|
||||
@@ -806,11 +813,17 @@ public final class ContentService extends IContentService.Stub {
|
||||
}
|
||||
|
||||
public boolean isSyncPending(Account account, String authority, ComponentName cname) {
|
||||
return isSyncPendingAsUser(account, authority, cname, UserHandle.getCallingUserId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSyncPendingAsUser(Account account, String authority, ComponentName cname,
|
||||
int userId) {
|
||||
mContext.enforceCallingOrSelfPermission(Manifest.permission.READ_SYNC_STATS,
|
||||
"no permission to read the sync stats");
|
||||
|
||||
enforceCrossUserPermission(userId,
|
||||
"no permission to retrieve the sync settings for user " + userId);
|
||||
int callerUid = Binder.getCallingUid();
|
||||
int userId = UserHandle.getCallingUserId();
|
||||
long identityToken = clearCallingIdentity();
|
||||
SyncManager syncManager = getSyncManager();
|
||||
if (syncManager == null) return false;
|
||||
|
||||
Reference in New Issue
Block a user