Search in sources :

Example 16 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 17 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)

Example 18 with SyncInfo

use of android.content.SyncInfo in project platform_packages_apps_Settings by BlissRoms.

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.DEBUG)) {
            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 19 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.DEBUG)) {
            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(getContext(), 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);
    }
    if (syncIsFailing) {
        mFooterPreferenceMixin.createFooterPreference().setTitle(R.string.sync_is_failing);
    }
}
Also used : Account(android.accounts.Account) Preference(androidx.preference.Preference) SyncInfo(android.content.SyncInfo) SyncStatusInfo(android.content.SyncStatusInfo) Date(java.util.Date)

Aggregations

SyncInfo (android.content.SyncInfo)19 Account (android.accounts.Account)8 SyncStatusInfo (android.content.SyncStatusInfo)8 Date (java.util.Date)8 Preference (android.support.v7.preference.Preference)6 ArrayList (java.util.ArrayList)5 Preference (androidx.preference.Preference)2 SyncAdapterType (android.content.SyncAdapterType)1 AccountPreference (com.android.settings.AccountPreference)1 FooterPreference (com.android.settingslib.widget.FooterPreference)1 HashSet (java.util.HashSet)1