Search in sources :

Example 11 with SyncInfo

use of android.content.SyncInfo in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class AccountSyncSettings method setFeedsState.

private void setFeedsState() {
    // iterate over all the preferences, setting the state properly for each
    Date date = new Date();
    final int userId = mUserHandle.getIdentifier();
    List<SyncInfo> currentSyncs = ContentResolver.getCurrentSyncsAsUser(userId);
    boolean syncIsFailing = false;
    // Refresh the sync status switches - some syncs may have become active.
    updateAccountSwitches();
    for (int i = 0, count = getPreferenceScreen().getPreferenceCount(); i < count; i++) {
        Preference pref = getPreferenceScreen().getPreference(i);
        if (!(pref instanceof SyncStateSwitchPreference)) {
            continue;
        }
        SyncStateSwitchPreference syncPref = (SyncStateSwitchPreference) pref;
        String authority = syncPref.getAuthority();
        Account account = syncPref.getAccount();
        SyncStatusInfo status = ContentResolver.getSyncStatusAsUser(account, authority, userId);
        boolean syncEnabled = ContentResolver.getSyncAutomaticallyAsUser(account, authority, userId);
        boolean authorityIsPending = status == null ? false : status.pending;
        boolean initialSync = status == null ? false : status.initialize;
        boolean activelySyncing = isSyncing(currentSyncs, account, authority);
        boolean lastSyncFailed = status != null && status.lastFailureTime != 0 && status.getLastFailureMesgAsInt(0) != ContentResolver.SYNC_ERROR_SYNC_ALREADY_IN_PROGRESS;
        if (!syncEnabled)
            lastSyncFailed = false;
        if (lastSyncFailed && !activelySyncing && !authorityIsPending) {
            syncIsFailing = true;
        }
        if (Log.isLoggable(TAG, Log.VERBOSE)) {
            Log.d(TAG, "Update sync status: " + account + " " + authority + " active = " + activelySyncing + " pend =" + authorityIsPending);
        }
        final long successEndTime = (status == null) ? 0 : status.lastSuccessTime;
        if (!syncEnabled) {
            syncPref.setSummary(R.string.sync_disabled);
        } else if (activelySyncing) {
            syncPref.setSummary(R.string.sync_in_progress);
        } else if (successEndTime != 0) {
            date.setTime(successEndTime);
            final String timeString = formatSyncDate(date);
            syncPref.setSummary(getResources().getString(R.string.last_synced, timeString));
        } else {
            syncPref.setSummary("");
        }
        int syncState = ContentResolver.getIsSyncableAsUser(account, authority, userId);
        syncPref.setActive(activelySyncing && (syncState >= 0) && !initialSync);
        syncPref.setPending(authorityIsPending && (syncState >= 0) && !initialSync);
        syncPref.setFailed(lastSyncFailed);
        final boolean oneTimeSyncMode = !ContentResolver.getMasterSyncAutomaticallyAsUser(userId);
        syncPref.setOneTimeSyncMode(oneTimeSyncMode);
        syncPref.setChecked(oneTimeSyncMode || syncEnabled);
    }
    mErrorInfoView.setVisibility(syncIsFailing ? View.VISIBLE : View.GONE);
}
Also used : Account(android.accounts.Account) Preference(android.support.v7.preference.Preference) SyncInfo(android.content.SyncInfo) SyncStatusInfo(android.content.SyncStatusInfo) Date(java.util.Date)

Example 12 with SyncInfo

use of android.content.SyncInfo in project android_frameworks_base by crdroidandroid.

the class SyncStorageEngine method addActiveSync.

/**
     * Called when a sync is starting. Supply a valid ActiveSyncContext with information
     * about the sync.
     */
public SyncInfo addActiveSync(SyncManager.ActiveSyncContext activeSyncContext) {
    final SyncInfo syncInfo;
    synchronized (mAuthorities) {
        if (Log.isLoggable(TAG, Log.VERBOSE)) {
            Slog.v(TAG, "setActiveSync: account=" + " auth=" + activeSyncContext.mSyncOperation.target + " src=" + activeSyncContext.mSyncOperation.syncSource + " extras=" + activeSyncContext.mSyncOperation.extras);
        }
        final EndPoint info = activeSyncContext.mSyncOperation.target;
        AuthorityInfo authorityInfo = getOrCreateAuthorityLocked(info, -1, /* assign a new identifier if creating a new target */
        true);
        syncInfo = new SyncInfo(authorityInfo.ident, authorityInfo.target.account, authorityInfo.target.provider, activeSyncContext.mStartTime);
        getCurrentSyncs(authorityInfo.target.userId).add(syncInfo);
    }
    reportActiveChange();
    return syncInfo;
}
Also used : SyncInfo(android.content.SyncInfo)

Example 13 with SyncInfo

use of android.content.SyncInfo in project android_frameworks_base by crdroidandroid.

the class SyncStorageEngine method getCurrentSyncsCopy.

/**
     * @param userId Id of user to return current sync info.
     * @param canAccessAccounts Determines whether to redact Account information from the result.
     * @return a copy of the current syncs data structure. Will not return null.
     */
public List<SyncInfo> getCurrentSyncsCopy(int userId, boolean canAccessAccounts) {
    synchronized (mAuthorities) {
        final List<SyncInfo> syncs = getCurrentSyncsLocked(userId);
        final List<SyncInfo> syncsCopy = new ArrayList<SyncInfo>();
        for (SyncInfo sync : syncs) {
            SyncInfo copy;
            if (!canAccessAccounts) {
                copy = SyncInfo.createAccountRedacted(sync.authorityId, sync.authority, sync.startTime);
            } else {
                copy = new SyncInfo(sync);
            }
            syncsCopy.add(copy);
        }
        return syncsCopy;
    }
}
Also used : SyncInfo(android.content.SyncInfo) ArrayList(java.util.ArrayList)

Aggregations

SyncInfo (android.content.SyncInfo)13 ArrayList (java.util.ArrayList)5 Account (android.accounts.Account)2 SyncStatusInfo (android.content.SyncStatusInfo)2 Preference (android.support.v7.preference.Preference)2 Date (java.util.Date)2 SyncAdapterType (android.content.SyncAdapterType)1 AccountPreference (com.android.settings.AccountPreference)1 HashSet (java.util.HashSet)1