下面列出了怎么用android.content.SyncInfo的API类实例代码及写法,或者点击链接到github查看源代码。
/**
* If the user id supplied is different to the calling user, the caller must hold the
* INTERACT_ACROSS_USERS_FULL permission.
*/
@Override
public List<SyncInfo> getCurrentSyncsAsUser(int userId) {
enforceCrossUserPermission(userId,
"no permission to read the sync settings for user " + userId);
mContext.enforceCallingOrSelfPermission(Manifest.permission.READ_SYNC_STATS,
"no permission to read the sync stats");
final boolean canAccessAccounts =
mContext.checkCallingOrSelfPermission(Manifest.permission.GET_ACCOUNTS)
== PackageManager.PERMISSION_GRANTED;
long identityToken = clearCallingIdentity();
try {
return getSyncManager().getSyncStorageEngine()
.getCurrentSyncsCopy(userId, canAccessAccounts);
} finally {
restoreCallingIdentity(identityToken);
}
}
/**
* If the user id supplied is different to the calling user, the caller must hold the
* INTERACT_ACROSS_USERS_FULL permission.
*/
@Override
public List<SyncInfo> getCurrentSyncsAsUser(int userId) {
enforceCrossUserPermission(userId,
"no permission to read the sync settings for user " + userId);
mContext.enforceCallingOrSelfPermission(Manifest.permission.READ_SYNC_STATS,
"no permission to read the sync stats");
final boolean canAccessAccounts =
mContext.checkCallingOrSelfPermission(Manifest.permission.GET_ACCOUNTS)
== PackageManager.PERMISSION_GRANTED;
long identityToken = clearCallingIdentity();
try {
return getSyncManager().getSyncStorageEngine()
.getCurrentSyncsCopy(userId, canAccessAccounts);
} finally {
restoreCallingIdentity(identityToken);
}
}
/**
* If the user id supplied is different to the calling user, the caller must hold the
* INTERACT_ACROSS_USERS_FULL permission.
*/
@Override
public List<SyncInfo> getCurrentSyncsAsUser(int userId) {
enforceCrossUserPermission(userId,
"no permission to read the sync settings for user " + userId);
mContext.enforceCallingOrSelfPermission(Manifest.permission.READ_SYNC_STATS,
"no permission to read the sync stats");
final boolean canAccessAccounts =
mContext.checkCallingOrSelfPermission(Manifest.permission.GET_ACCOUNTS)
== PackageManager.PERMISSION_GRANTED;
long identityToken = clearCallingIdentity();
try {
return getSyncManager().getSyncStorageEngine()
.getCurrentSyncsCopy(userId, canAccessAccounts);
} finally {
restoreCallingIdentity(identityToken);
}
}
/**
* Returns true if there is currently a sync operation being actively processed for the given
* target.
*/
public boolean isSyncActive(EndPoint info) {
synchronized (mAuthorities) {
for (SyncInfo syncInfo : getCurrentSyncs(info.userId)) {
AuthorityInfo ainfo = getAuthority(syncInfo.authorityId);
if (ainfo != null && ainfo.target.matchesSpec(info)) {
return true;
}
}
}
return false;
}
/**
* Called to indicate that a previously active sync is no longer active.
*/
public void removeActiveSync(SyncInfo syncInfo, int userId) {
synchronized (mAuthorities) {
if (Log.isLoggable(TAG, Log.VERBOSE)) {
Slog.v(TAG, "removeActiveSync: account=" + syncInfo.account
+ " user=" + userId
+ " auth=" + syncInfo.authority);
}
getCurrentSyncs(userId).remove(syncInfo);
}
reportActiveChange();
}
private List<SyncInfo> getCurrentSyncsLocked(int userId) {
ArrayList<SyncInfo> syncs = mCurrentSyncs.get(userId);
if (syncs == null) {
syncs = new ArrayList<SyncInfo>();
mCurrentSyncs.put(userId, syncs);
}
return syncs;
}
public static boolean isSyncActiveHoneycomb(Account account, String authority) {
for (SyncInfo syncInfo : ContentResolver.getCurrentSyncs()) {
if (syncInfo.account.equals(account) && syncInfo.authority.equals(authority)) {
return true;
}
}
return false;
}
@Override
public List<SyncInfo> getCurrentSyncs() {
return getCurrentSyncsAsUser(UserHandle.getCallingUserId());
}
@Override
public List<SyncInfo> getCurrentSyncs() {
return getCurrentSyncsAsUser(UserHandle.getCallingUserId());
}
@Override
public List<SyncInfo> getCurrentSyncs() {
return getCurrentSyncsAsUser(UserHandle.getCallingUserId());
}
/**
* Return a list of the currently active syncs. Note that the returned
* items are the real, live active sync objects, so be careful what you do
* with it.
*/
private List<SyncInfo> getCurrentSyncs(int userId) {
synchronized (mAuthorities) {
return getCurrentSyncsLocked(userId);
}
}
@Override
protected void after(XParam param) throws Throwable {
switch (mMethod) {
case getCurrentSync:
if (isRestricted(param))
param.setResult(null);
break;
case getCurrentSyncs:
if (isRestricted(param))
param.setResult(new ArrayList<SyncInfo>());
break;
case getSyncAdapterTypes:
if (isRestricted(param))
param.setResult(new SyncAdapterType[0]);
break;
case openAssetFileDescriptor:
case openFileDescriptor:
case openInputStream:
case openOutputStream:
case openTypedAssetFileDescriptor:
case openAssetFile:
case openFile:
if (param.args.length > 0 && param.args[0] instanceof Uri) {
String uri = ((Uri) param.args[0]).toString();
if (isRestrictedExtra(param, uri))
param.setThrowable(new FileNotFoundException("XPrivacy"));
}
break;
case Srv_call:
handleCallAfter(param);
break;
case query:
case Srv_query:
handleUriAfter(param);
break;
case Srv_getCurrentSyncs:
case Srv_getCurrentSyncsAsUser:
if (param.getResult() != null)
if (isRestricted(param)) {
int uid = Binder.getCallingUid();
@SuppressWarnings("unchecked")
List<SyncInfo> listSync = (List<SyncInfo>) param.getResult();
List<SyncInfo> listFiltered = new ArrayList<SyncInfo>();
for (SyncInfo sync : listSync)
if (XAccountManager.isAccountAllowed(sync.account, uid))
listFiltered.add(sync);
param.setResult(listFiltered);
}
break;
}
}