Search in sources :

Example 61 with SyncStatusInfo

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

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 62 with SyncStatusInfo

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

the class SyncManager method dumpSyncState.

protected void dumpSyncState(PrintWriter pw) {
    pw.print("data connected: ");
    pw.println(mDataConnectionIsConnected);
    pw.print("auto sync: ");
    List<UserInfo> users = getAllUsers();
    if (users != null) {
        for (UserInfo user : users) {
            pw.print("u" + user.id + "=" + mSyncStorageEngine.getMasterSyncAutomatically(user.id) + " ");
        }
        pw.println();
    }
    pw.print("memory low: ");
    pw.println(mStorageIsLow);
    pw.print("device idle: ");
    pw.println(mDeviceIsIdle);
    pw.print("reported active: ");
    pw.println(mReportedSyncActive);
    final AccountAndUser[] accounts = AccountManagerService.getSingleton().getAllAccounts();
    pw.print("accounts: ");
    if (accounts != INITIAL_ACCOUNTS_ARRAY) {
        pw.println(accounts.length);
    } else {
        pw.println("not known yet");
    }
    final long now = SystemClock.elapsedRealtime();
    pw.print("now: ");
    pw.print(now);
    pw.println(" (" + formatTime(System.currentTimeMillis()) + ")");
    pw.println(" (HH:MM:SS)");
    pw.print("uptime: ");
    pw.print(DateUtils.formatElapsedTime(now / 1000));
    pw.println(" (HH:MM:SS)");
    pw.print("time spent syncing: ");
    pw.print(DateUtils.formatElapsedTime(mSyncHandler.mSyncTimeTracker.timeSpentSyncing() / 1000));
    pw.print(" (HH:MM:SS), sync ");
    pw.print(mSyncHandler.mSyncTimeTracker.mLastWasSyncing ? "" : "not ");
    pw.println("in progress");
    pw.println();
    pw.println("Active Syncs: " + mActiveSyncContexts.size());
    final PackageManager pm = mContext.getPackageManager();
    for (SyncManager.ActiveSyncContext activeSyncContext : mActiveSyncContexts) {
        final long durationInSeconds = (now - activeSyncContext.mStartTime) / 1000;
        pw.print("  ");
        pw.print(DateUtils.formatElapsedTime(durationInSeconds));
        pw.print(" - ");
        pw.print(activeSyncContext.mSyncOperation.dump(pm, false));
        pw.println();
    }
    // Join the installed sync adapter with the accounts list and emit for everything.
    pw.println();
    pw.println("Sync Status");
    for (AccountAndUser account : accounts) {
        pw.printf("Account %s u%d %s\n", account.account.name, account.userId, account.account.type);
        pw.println("=======================================================================");
        final PrintTable table = new PrintTable(12);
        table.set(0, 0, // 0
        "Authority", // 1
        "Syncable", // 2
        "Enabled", // 3
        "Delay", // 4
        "Loc", // 5
        "Poll", // 6
        "Per", // 7
        "Serv", // 8
        "User", // 9
        "Tot", // 10
        "Time", // 11
        "Last Sync");
        final List<RegisteredServicesCache.ServiceInfo<SyncAdapterType>> sorted = Lists.newArrayList();
        sorted.addAll(mSyncAdapters.getAllServices(account.userId));
        Collections.sort(sorted, new Comparator<RegisteredServicesCache.ServiceInfo<SyncAdapterType>>() {

            @Override
            public int compare(RegisteredServicesCache.ServiceInfo<SyncAdapterType> lhs, RegisteredServicesCache.ServiceInfo<SyncAdapterType> rhs) {
                return lhs.type.authority.compareTo(rhs.type.authority);
            }
        });
        for (RegisteredServicesCache.ServiceInfo<SyncAdapterType> syncAdapterType : sorted) {
            if (!syncAdapterType.type.accountType.equals(account.account.type)) {
                continue;
            }
            int row = table.getNumRows();
            Pair<AuthorityInfo, SyncStatusInfo> syncAuthoritySyncStatus = mSyncStorageEngine.getCopyOfAuthorityWithSyncStatus(new SyncStorageEngine.EndPoint(account.account, syncAdapterType.type.authority, account.userId));
            SyncStorageEngine.AuthorityInfo settings = syncAuthoritySyncStatus.first;
            SyncStatusInfo status = syncAuthoritySyncStatus.second;
            String authority = settings.target.provider;
            if (authority.length() > 50) {
                authority = authority.substring(authority.length() - 50);
            }
            table.set(row, 0, authority, settings.syncable, settings.enabled);
            table.set(row, 4, status.numSourceLocal, status.numSourcePoll, status.numSourcePeriodic, status.numSourceServer, status.numSourceUser, status.numSyncs, DateUtils.formatElapsedTime(status.totalElapsedTime / 1000));
            int row1 = row;
            if (settings.delayUntil > now) {
                table.set(row1++, 12, "D: " + (settings.delayUntil - now) / 1000);
                if (settings.backoffTime > now) {
                    table.set(row1++, 12, "B: " + (settings.backoffTime - now) / 1000);
                    table.set(row1++, 12, settings.backoffDelay / 1000);
                }
            }
            if (status.lastSuccessTime != 0) {
                table.set(row1++, 11, SyncStorageEngine.SOURCES[status.lastSuccessSource] + " " + "SUCCESS");
                table.set(row1++, 11, formatTime(status.lastSuccessTime));
            }
            if (status.lastFailureTime != 0) {
                table.set(row1++, 11, SyncStorageEngine.SOURCES[status.lastFailureSource] + " " + "FAILURE");
                table.set(row1++, 11, formatTime(status.lastFailureTime));
                //noinspection UnusedAssignment
                table.set(row1++, 11, status.lastFailureMesg);
            }
        }
        table.writeTo(pw);
    }
}
Also used : AuthorityInfo(com.android.server.content.SyncStorageEngine.AuthorityInfo) UserInfo(android.content.pm.UserInfo) SyncStatusInfo(android.content.SyncStatusInfo) SyncAdapterType(android.content.SyncAdapterType) EndPoint(com.android.server.content.SyncStorageEngine.EndPoint) EndPoint(com.android.server.content.SyncStorageEngine.EndPoint) PackageManager(android.content.pm.PackageManager) AccountAndUser(android.accounts.AccountAndUser) AuthorityInfo(com.android.server.content.SyncStorageEngine.AuthorityInfo) RegisteredServicesCache(android.content.pm.RegisteredServicesCache)

Example 63 with SyncStatusInfo

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

SyncStatusInfo (android.content.SyncStatusInfo)64 Account (android.accounts.Account)14 Parcel (android.os.Parcel)12 SyncInfo (android.content.SyncInfo)8 Date (java.util.Date)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 Preference (android.support.v7.preference.Preference)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