下面列出了android.content.ContentResolver#SYNC_EXEMPTION_NONE 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@SyncExemption
private int getSyncExemptionAndCleanUpExtrasForCaller(int callingUid, Bundle extras) {
if (extras != null) {
final int exemption =
extras.getInt(ContentResolver.SYNC_VIRTUAL_EXTRAS_EXEMPTION_FLAG, -1);
// Need to remove the virtual extra.
extras.remove(ContentResolver.SYNC_VIRTUAL_EXTRAS_EXEMPTION_FLAG);
if (exemption != -1) {
return exemption;
}
}
final ActivityManagerInternal ami =
LocalServices.getService(ActivityManagerInternal.class);
final int procState = (ami != null)
? ami.getUidProcessState(callingUid)
: ActivityManager.PROCESS_STATE_NONEXISTENT;
if (procState <= ActivityManager.PROCESS_STATE_TOP) {
return ContentResolver.SYNC_EXEMPTION_PROMOTE_BUCKET_WITH_TEMP;
}
if (procState <= ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND) {
return ContentResolver.SYNC_EXEMPTION_PROMOTE_BUCKET;
}
return ContentResolver.SYNC_EXEMPTION_NONE;
}
@SyncExemption
private int getSyncExemptionAndCleanUpExtrasForCaller(int callingUid, Bundle extras) {
if (extras != null) {
final int exemption =
extras.getInt(ContentResolver.SYNC_VIRTUAL_EXTRAS_EXEMPTION_FLAG, -1);
// Need to remove the virtual extra.
extras.remove(ContentResolver.SYNC_VIRTUAL_EXTRAS_EXEMPTION_FLAG);
if (exemption != -1) {
return exemption;
}
}
final ActivityManagerInternal ami =
LocalServices.getService(ActivityManagerInternal.class);
if (ami == null) {
return ContentResolver.SYNC_EXEMPTION_NONE;
}
final int procState = ami.getUidProcessState(callingUid);
final boolean isUidActive = ami.isUidActive(callingUid);
// Providers bound by a TOP app will get PROCESS_STATE_BOUND_TOP, so include those as well
if (procState <= ActivityManager.PROCESS_STATE_TOP
|| procState == ActivityManager.PROCESS_STATE_BOUND_TOP) {
return ContentResolver.SYNC_EXEMPTION_PROMOTE_BUCKET_WITH_TEMP;
}
if (procState <= ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND || isUidActive) {
return ContentResolver.SYNC_EXEMPTION_PROMOTE_BUCKET;
}
return ContentResolver.SYNC_EXEMPTION_NONE;
}
public SyncOperation createOneTimeSyncOperation() {
if (!isPeriodic) {
return null;
}
SyncOperation op = new SyncOperation(target, owningUid, owningPackage, reason, syncSource,
new Bundle(extras), allowParallelSyncs, false, jobId /* sourcePeriodicId */,
periodMillis, flexMillis, ContentResolver.SYNC_EXEMPTION_NONE);
return op;
}
public SyncOperation(SyncOperation op, long periodMillis, long flexMillis) {
this(op.target, op.owningUid, op.owningPackage, op.reason, op.syncSource,
new Bundle(op.extras), op.allowParallelSyncs, op.isPeriodic, op.sourcePeriodicId,
periodMillis, flexMillis, ContentResolver.SYNC_EXEMPTION_NONE);
}
String dump(PackageManager pm, boolean shorter, SyncAdapterStateFetcher appStates,
boolean logSafe) {
StringBuilder sb = new StringBuilder();
sb.append("JobId=").append(jobId)
.append(" ")
.append(logSafe ? "***" : target.account.name)
.append("/")
.append(target.account.type)
.append(" u")
.append(target.userId)
.append(" [")
.append(target.provider)
.append("] ");
sb.append(SyncStorageEngine.SOURCES[syncSource]);
if (expectedRuntime != 0) {
sb.append(" ExpectedIn=");
SyncManager.formatDurationHMS(sb,
(expectedRuntime - SystemClock.elapsedRealtime()));
}
if (extras.getBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, false)) {
sb.append(" EXPEDITED");
}
switch (syncExemptionFlag) {
case ContentResolver.SYNC_EXEMPTION_NONE:
break;
case ContentResolver.SYNC_EXEMPTION_PROMOTE_BUCKET:
sb.append(" STANDBY-EXEMPTED");
break;
case ContentResolver.SYNC_EXEMPTION_PROMOTE_BUCKET_WITH_TEMP:
sb.append(" STANDBY-EXEMPTED(TOP)");
break;
default:
sb.append(" ExemptionFlag=" + syncExemptionFlag);
break;
}
sb.append(" Reason=");
sb.append(reasonToString(pm, reason));
if (isPeriodic) {
sb.append(" (period=");
SyncManager.formatDurationHMS(sb, periodMillis);
sb.append(" flex=");
SyncManager.formatDurationHMS(sb, flexMillis);
sb.append(")");
}
if (retries > 0) {
sb.append(" Retries=");
sb.append(retries);
}
if (!shorter) {
sb.append(" Owner={");
UserHandle.formatUid(sb, owningUid);
sb.append(" ");
sb.append(owningPackage);
if (appStates != null) {
sb.append(" [");
sb.append(appStates.getStandbyBucket(
UserHandle.getUserId(owningUid), owningPackage));
sb.append("]");
if (appStates.isAppActive(owningUid)) {
sb.append(" [ACTIVE]");
}
}
sb.append("}");
if (!extras.keySet().isEmpty()) {
sb.append(" ");
extrasToStringBuilder(extras, sb);
}
}
return sb.toString();
}
boolean isAppStandbyExempted() {
return syncExemptionFlag != ContentResolver.SYNC_EXEMPTION_NONE;
}