Search in sources :

Example 6 with SyncInfo

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

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 7 with SyncInfo

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

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 (DEBUG) {
            Log.v(TAG, "setActiveSync: account=" + activeSyncContext.mSyncOperation.account + " auth=" + activeSyncContext.mSyncOperation.authority + " src=" + activeSyncContext.mSyncOperation.syncSource + " extras=" + activeSyncContext.mSyncOperation.extras);
        }
        AuthorityInfo authority = getOrCreateAuthorityLocked(activeSyncContext.mSyncOperation.account, activeSyncContext.mSyncOperation.userId, activeSyncContext.mSyncOperation.authority, -1, /* assign a new identifier if creating a new authority */
        true);
        syncInfo = new SyncInfo(authority.ident, authority.account, authority.authority, activeSyncContext.mStartTime);
        getCurrentSyncs(authority.userId).add(syncInfo);
    }
    reportActiveChange();
    return syncInfo;
}
Also used : SyncInfo(android.content.SyncInfo)

Example 8 with SyncInfo

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

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 9 with SyncInfo

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

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 10 with SyncInfo

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

the class ManageAccountsSettings method showSyncState.

/**
     * Shows the sync state of the accounts. Note: it must be called after the accounts have been
     * loaded, @see #showAccountsIfNeeded().
     */
private void showSyncState() {
    // Catch any delayed delivery of update messages
    if (getActivity() == null || getActivity().isFinishing())
        return;
    final int userId = mUserHandle.getIdentifier();
    // iterate over all the preferences, setting the state properly for each
    List<SyncInfo> currentSyncs = ContentResolver.getCurrentSyncsAsUser(userId);
    // true if sync on any account failed
    boolean anySyncFailed = false;
    Date date = new Date();
    // only track userfacing sync adapters when deciding if account is synced or not
    final SyncAdapterType[] syncAdapters = ContentResolver.getSyncAdapterTypesAsUser(userId);
    HashSet<String> userFacing = new HashSet<String>();
    for (int k = 0, n = syncAdapters.length; k < n; k++) {
        final SyncAdapterType sa = syncAdapters[k];
        if (sa.isUserVisible()) {
            userFacing.add(sa.authority);
        }
    }
    for (int i = 0, count = getPreferenceScreen().getPreferenceCount(); i < count; i++) {
        Preference pref = getPreferenceScreen().getPreference(i);
        if (!(pref instanceof AccountPreference)) {
            continue;
        }
        AccountPreference accountPref = (AccountPreference) pref;
        Account account = accountPref.getAccount();
        int syncCount = 0;
        long lastSuccessTime = 0;
        boolean syncIsFailing = false;
        final ArrayList<String> authorities = accountPref.getAuthorities();
        boolean syncingNow = false;
        if (authorities != null) {
            for (String authority : authorities) {
                SyncStatusInfo status = ContentResolver.getSyncStatusAsUser(account, authority, userId);
                boolean syncEnabled = isSyncEnabled(userId, account, authority);
                boolean authorityIsPending = ContentResolver.isSyncPending(account, authority);
                boolean activelySyncing = isSyncing(currentSyncs, account, authority);
                boolean lastSyncFailed = status != null && syncEnabled && status.lastFailureTime != 0 && status.getLastFailureMesgAsInt(0) != ContentResolver.SYNC_ERROR_SYNC_ALREADY_IN_PROGRESS;
                if (lastSyncFailed && !activelySyncing && !authorityIsPending) {
                    syncIsFailing = true;
                    anySyncFailed = true;
                }
                syncingNow |= activelySyncing;
                if (status != null && lastSuccessTime < status.lastSuccessTime) {
                    lastSuccessTime = status.lastSuccessTime;
                }
                syncCount += syncEnabled && userFacing.contains(authority) ? 1 : 0;
            }
        } else {
            if (Log.isLoggable(TAG, Log.VERBOSE)) {
                Log.v(TAG, "no syncadapters found for " + account);
            }
        }
        if (syncIsFailing) {
            accountPref.setSyncStatus(AccountPreference.SYNC_ERROR, true);
        } else if (syncCount == 0) {
            accountPref.setSyncStatus(AccountPreference.SYNC_DISABLED, true);
        } else if (syncCount > 0) {
            if (syncingNow) {
                accountPref.setSyncStatus(AccountPreference.SYNC_IN_PROGRESS, true);
            } else {
                accountPref.setSyncStatus(AccountPreference.SYNC_ENABLED, true);
                if (lastSuccessTime > 0) {
                    accountPref.setSyncStatus(AccountPreference.SYNC_ENABLED, false);
                    date.setTime(lastSuccessTime);
                    final String timeString = formatSyncDate(date);
                    accountPref.setSummary(getResources().getString(R.string.last_synced, timeString));
                }
            }
        } else {
            accountPref.setSyncStatus(AccountPreference.SYNC_DISABLED, true);
        }
    }
    mErrorInfoView.setVisibility(anySyncFailed ? View.VISIBLE : View.GONE);
}
Also used : Account(android.accounts.Account) SyncStatusInfo(android.content.SyncStatusInfo) SyncAdapterType(android.content.SyncAdapterType) Date(java.util.Date) AccountPreference(com.android.settings.AccountPreference) Preference(android.support.v7.preference.Preference) SyncInfo(android.content.SyncInfo) AccountPreference(com.android.settings.AccountPreference) HashSet(java.util.HashSet)

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