Search in sources :

Example 51 with SyncStatusInfo

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

the class SyncStorageEngine method getOrCreateSyncStatusLocked.

private SyncStatusInfo getOrCreateSyncStatusLocked(int authorityId) {
    SyncStatusInfo status = mSyncStatus.get(authorityId);
    if (status == null) {
        status = new SyncStatusInfo(authorityId);
        mSyncStatus.put(authorityId, status);
    }
    return status;
}
Also used : SyncStatusInfo(android.content.SyncStatusInfo)

Example 52 with SyncStatusInfo

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

the class SyncStorageEngine method stopSyncEvent.

public void stopSyncEvent(long historyId, long elapsedTime, String resultMessage, long downstreamActivity, long upstreamActivity) {
    synchronized (mAuthorities) {
        if (Log.isLoggable(TAG, Log.VERBOSE)) {
            Slog.v(TAG, "stopSyncEvent: historyId=" + historyId);
        }
        SyncHistoryItem item = null;
        int i = mSyncHistory.size();
        while (i > 0) {
            i--;
            item = mSyncHistory.get(i);
            if (item.historyId == historyId) {
                break;
            }
            item = null;
        }
        if (item == null) {
            Slog.w(TAG, "stopSyncEvent: no history for id " + historyId);
            return;
        }
        item.elapsedTime = elapsedTime;
        item.event = EVENT_STOP;
        item.mesg = resultMessage;
        item.downstreamActivity = downstreamActivity;
        item.upstreamActivity = upstreamActivity;
        SyncStatusInfo status = getOrCreateSyncStatusLocked(item.authorityId);
        status.numSyncs++;
        status.totalElapsedTime += elapsedTime;
        switch(item.source) {
            case SOURCE_LOCAL:
                status.numSourceLocal++;
                break;
            case SOURCE_POLL:
                status.numSourcePoll++;
                break;
            case SOURCE_USER:
                status.numSourceUser++;
                break;
            case SOURCE_SERVER:
                status.numSourceServer++;
                break;
            case SOURCE_PERIODIC:
                status.numSourcePeriodic++;
                break;
        }
        boolean writeStatisticsNow = false;
        int day = getCurrentDayLocked();
        if (mDayStats[0] == null) {
            mDayStats[0] = new DayStats(day);
        } else if (day != mDayStats[0].day) {
            System.arraycopy(mDayStats, 0, mDayStats, 1, mDayStats.length - 1);
            mDayStats[0] = new DayStats(day);
            writeStatisticsNow = true;
        } else if (mDayStats[0] == null) {
        }
        final DayStats ds = mDayStats[0];
        final long lastSyncTime = (item.eventTime + elapsedTime);
        boolean writeStatusNow = false;
        if (MESG_SUCCESS.equals(resultMessage)) {
            // - if successful, update the successful columns
            if (status.lastSuccessTime == 0 || status.lastFailureTime != 0) {
                writeStatusNow = true;
            }
            status.lastSuccessTime = lastSyncTime;
            status.lastSuccessSource = item.source;
            status.lastFailureTime = 0;
            status.lastFailureSource = -1;
            status.lastFailureMesg = null;
            status.initialFailureTime = 0;
            ds.successCount++;
            ds.successTime += elapsedTime;
        } else if (!MESG_CANCELED.equals(resultMessage)) {
            if (status.lastFailureTime == 0) {
                writeStatusNow = true;
            }
            status.lastFailureTime = lastSyncTime;
            status.lastFailureSource = item.source;
            status.lastFailureMesg = resultMessage;
            if (status.initialFailureTime == 0) {
                status.initialFailureTime = lastSyncTime;
            }
            ds.failureCount++;
            ds.failureTime += elapsedTime;
        }
        if (writeStatusNow) {
            writeStatusLocked();
        } else if (!hasMessages(MSG_WRITE_STATUS)) {
            sendMessageDelayed(obtainMessage(MSG_WRITE_STATUS), WRITE_STATUS_DELAY);
        }
        if (writeStatisticsNow) {
            writeStatisticsLocked();
        } else if (!hasMessages(MSG_WRITE_STATISTICS)) {
            sendMessageDelayed(obtainMessage(MSG_WRITE_STATISTICS), WRITE_STATISTICS_DELAY);
        }
    }
    reportChange(ContentResolver.SYNC_OBSERVER_TYPE_STATUS);
}
Also used : SyncStatusInfo(android.content.SyncStatusInfo)

Example 53 with SyncStatusInfo

use of android.content.SyncStatusInfo 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)

Example 54 with SyncStatusInfo

use of android.content.SyncStatusInfo 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 55 with SyncStatusInfo

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

the class SyncStorageEngine method readStatusLocked.

/**
     * Read all sync status back in to the initial engine state.
     */
private void readStatusLocked() {
    if (Log.isLoggable(TAG_FILE, Log.VERBOSE)) {
        Slog.v(TAG_FILE, "Reading " + mStatusFile.getBaseFile());
    }
    try {
        byte[] data = mStatusFile.readFully();
        Parcel in = Parcel.obtain();
        in.unmarshall(data, 0, data.length);
        in.setDataPosition(0);
        int token;
        while ((token = in.readInt()) != STATUS_FILE_END) {
            if (token == STATUS_FILE_ITEM) {
                SyncStatusInfo status = new SyncStatusInfo(in);
                if (mAuthorities.indexOfKey(status.authorityId) >= 0) {
                    status.pending = false;
                    if (Log.isLoggable(TAG_FILE, Log.VERBOSE)) {
                        Slog.v(TAG_FILE, "Adding status for id " + status.authorityId);
                    }
                    mSyncStatus.put(status.authorityId, status);
                }
            } else {
                // Ooops.
                Slog.w(TAG, "Unknown status token: " + token);
                break;
            }
        }
    } catch (java.io.IOException e) {
        Slog.i(TAG, "No initial status");
    }
}
Also used : Parcel(android.os.Parcel) SyncStatusInfo(android.content.SyncStatusInfo)

Aggregations

SyncStatusInfo (android.content.SyncStatusInfo)58 Parcel (android.os.Parcel)12 Account (android.accounts.Account)8 SyncAdapterType (android.content.SyncAdapterType)7 AccountAndUser (android.accounts.AccountAndUser)6 PackageManager (android.content.pm.PackageManager)6 RegisteredServicesCache (android.content.pm.RegisteredServicesCache)6 UserInfo (android.content.pm.UserInfo)6 Cursor (android.database.Cursor)6 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)6 SQLiteException (android.database.sqlite.SQLiteException)6 SQLiteQueryBuilder (android.database.sqlite.SQLiteQueryBuilder)6 File (java.io.File)6 FileOutputStream (java.io.FileOutputStream)6 HashMap (java.util.HashMap)6 AuthorityInfo (com.android.server.content.SyncStorageEngine.AuthorityInfo)5 EndPoint (com.android.server.content.SyncStorageEngine.EndPoint)5 SyncInfo (android.content.SyncInfo)2 Bundle (android.os.Bundle)2 Preference (android.support.v7.preference.Preference)2