Java Code Examples for android.content.SyncRequest#getBundle()

The following examples show how to use android.content.SyncRequest#getBundle() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ContentService.java    From AndroidComponentPlugin with Apache License 2.0 5 votes vote down vote up
/**
 * If the user id supplied is different to the calling user, the caller must hold the
 * INTERACT_ACROSS_USERS_FULL permission.
 */
@Override
public void syncAsUser(SyncRequest request, int userId) {
    enforceCrossUserPermission(userId, "no permission to request sync as user: " + userId);
    int callerUid = Binder.getCallingUid();
    // 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();
    try {
        SyncManager syncManager = getSyncManager();
        if (syncManager == null) {
            return;
        }

        Bundle extras = request.getBundle();
        long flextime = request.getSyncFlexTime();
        long runAtTime = request.getSyncRunTime();
        if (request.isPeriodic()) {
            mContext.enforceCallingOrSelfPermission(
                    Manifest.permission.WRITE_SYNC_SETTINGS,
                    "no permission to write the sync settings");
            SyncStorageEngine.EndPoint info;
            info = new SyncStorageEngine.EndPoint(
                    request.getAccount(), request.getProvider(), userId);

            runAtTime = clampPeriod(runAtTime);
            // Schedule periodic sync.
            getSyncManager().updateOrAddPeriodicSync(info, runAtTime,
                    flextime, extras);
        } else {
            syncManager.scheduleSync(
                    request.getAccount(), userId, callerUid, request.getProvider(), extras,
                    SyncStorageEngine.AuthorityInfo.UNDEFINED);
        }
    } finally {
        restoreCallingIdentity(identityToken);
    }
}
 
Example 2
Source File: ContentService.java    From AndroidComponentPlugin with Apache License 2.0 5 votes vote down vote up
@Override
public void cancelRequest(SyncRequest request) {
    SyncManager syncManager = getSyncManager();
    if (syncManager == null) return;
    int userId = UserHandle.getCallingUserId();
    final int callingUid = Binder.getCallingUid();

    long identityToken = clearCallingIdentity();
    try {
        SyncStorageEngine.EndPoint info;
        Bundle extras = new Bundle(request.getBundle());
        Account account = request.getAccount();
        String provider = request.getProvider();
        info = new SyncStorageEngine.EndPoint(account, provider, userId);
        if (request.isPeriodic()) {
            // Remove periodic sync.
            mContext.enforceCallingOrSelfPermission(Manifest.permission.WRITE_SYNC_SETTINGS,
                    "no permission to write the sync settings");
            getSyncManager().removePeriodicSync(info, extras,
                    "cancelRequest() by uid=" + callingUid);
        }
        // Cancel active syncs and clear pending syncs from the queue.
        syncManager.cancelScheduledSyncOperation(info, extras);
        syncManager.cancelActiveSync(info, extras, "API");
    } finally {
        restoreCallingIdentity(identityToken);
    }
}
 
Example 3
Source File: ContentService.java    From AndroidComponentPlugin with Apache License 2.0 5 votes vote down vote up
@Override
public void cancelRequest(SyncRequest request) {
    SyncManager syncManager = getSyncManager();
    if (syncManager == null) return;
    int userId = UserHandle.getCallingUserId();
    final int callingUid = Binder.getCallingUid();

    if (request.isPeriodic()) {
        mContext.enforceCallingOrSelfPermission(Manifest.permission.WRITE_SYNC_SETTINGS,
                "no permission to write the sync settings");
    }

    Bundle extras = new Bundle(request.getBundle());
    validateExtras(callingUid, extras);

    long identityToken = clearCallingIdentity();
    try {
        SyncStorageEngine.EndPoint info;

        Account account = request.getAccount();
        String provider = request.getProvider();
        info = new SyncStorageEngine.EndPoint(account, provider, userId);
        if (request.isPeriodic()) {
            // Remove periodic sync.
            getSyncManager().removePeriodicSync(info, extras,
                    "cancelRequest() by uid=" + callingUid);
        }
        // Cancel active syncs and clear pending syncs from the queue.
        syncManager.cancelScheduledSyncOperation(info, extras);
        syncManager.cancelActiveSync(info, extras, "API");
    } finally {
        restoreCallingIdentity(identityToken);
    }
}
 
Example 4
Source File: ContentService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public void cancelRequest(SyncRequest request) {
    SyncManager syncManager = getSyncManager();
    if (syncManager == null) return;
    int userId = UserHandle.getCallingUserId();
    final int callingUid = Binder.getCallingUid();

    if (request.isPeriodic()) {
        mContext.enforceCallingOrSelfPermission(Manifest.permission.WRITE_SYNC_SETTINGS,
                "no permission to write the sync settings");
    }

    Bundle extras = new Bundle(request.getBundle());
    validateExtras(callingUid, extras);

    long identityToken = clearCallingIdentity();
    try {
        SyncStorageEngine.EndPoint info;

        Account account = request.getAccount();
        String provider = request.getProvider();
        info = new SyncStorageEngine.EndPoint(account, provider, userId);
        if (request.isPeriodic()) {
            // Remove periodic sync.
            getSyncManager().removePeriodicSync(info, extras,
                    "cancelRequest() by uid=" + callingUid);
        }
        // Cancel active syncs and clear pending syncs from the queue.
        syncManager.cancelScheduledSyncOperation(info, extras);
        syncManager.cancelActiveSync(info, extras, "API");
    } finally {
        restoreCallingIdentity(identityToken);
    }
}
 
Example 5
Source File: ContentService.java    From AndroidComponentPlugin with Apache License 2.0 4 votes vote down vote up
/**
 * If the user id supplied is different to the calling user, the caller must hold the
 * INTERACT_ACROSS_USERS_FULL permission.
 */
@Override
public void syncAsUser(SyncRequest request, int userId, String callingPackage) {
    enforceCrossUserPermission(userId, "no permission to request sync as user: " + userId);
    final int callingUid = Binder.getCallingUid();
    final int callingPid = Binder.getCallingPid();

    final Bundle extras = request.getBundle();

    validateExtras(callingUid, extras);
    final int syncExemption = getSyncExemptionAndCleanUpExtrasForCaller(callingUid, extras);

    // 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();
    try {
        SyncManager syncManager = getSyncManager();
        if (syncManager == null) {
            return;
        }
        long flextime = request.getSyncFlexTime();
        long runAtTime = request.getSyncRunTime();
        if (request.isPeriodic()) {
            mContext.enforceCallingOrSelfPermission(
                    Manifest.permission.WRITE_SYNC_SETTINGS,
                    "no permission to write the sync settings");
            SyncStorageEngine.EndPoint info;
            info = new SyncStorageEngine.EndPoint(
                    request.getAccount(), request.getProvider(), userId);

            runAtTime = clampPeriod(runAtTime);
            // Schedule periodic sync.
            getSyncManager().updateOrAddPeriodicSync(info, runAtTime,
                    flextime, extras);
        } else {
            syncManager.scheduleSync(
                    request.getAccount(), userId, callingUid, request.getProvider(), extras,
                    SyncStorageEngine.AuthorityInfo.UNDEFINED,
                    syncExemption, callingUid, callingPid, callingPackage);
        }
    } finally {
        restoreCallingIdentity(identityToken);
    }
}
 
Example 6
Source File: ContentService.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
/**
 * If the user id supplied is different to the calling user, the caller must hold the
 * INTERACT_ACROSS_USERS_FULL permission.
 */
@Override
public void syncAsUser(SyncRequest request, int userId) {
    enforceCrossUserPermission(userId, "no permission to request sync as user: " + userId);
    int callerUid = Binder.getCallingUid();

    final Bundle extras = request.getBundle();

    validateExtras(callerUid, extras);
    final int syncExemption = getSyncExemptionAndCleanUpExtrasForCaller(callerUid, extras);

    // 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();
    try {
        SyncManager syncManager = getSyncManager();
        if (syncManager == null) {
            return;
        }
        long flextime = request.getSyncFlexTime();
        long runAtTime = request.getSyncRunTime();
        if (request.isPeriodic()) {
            mContext.enforceCallingOrSelfPermission(
                    Manifest.permission.WRITE_SYNC_SETTINGS,
                    "no permission to write the sync settings");
            SyncStorageEngine.EndPoint info;
            info = new SyncStorageEngine.EndPoint(
                    request.getAccount(), request.getProvider(), userId);

            runAtTime = clampPeriod(runAtTime);
            // Schedule periodic sync.
            getSyncManager().updateOrAddPeriodicSync(info, runAtTime,
                    flextime, extras);
        } else {
            syncManager.scheduleSync(
                    request.getAccount(), userId, callerUid, request.getProvider(), extras,
                    SyncStorageEngine.AuthorityInfo.UNDEFINED,
                    syncExemption);
        }
    } finally {
        restoreCallingIdentity(identityToken);
    }
}