Search in sources :

Example 36 with SyncStatusInfo

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

the class SyncStorageEngine method getStatusByAccountAndAuthority.

/**
     * Returns the status that matches the authority and account.
     *
     * @param account the account we want to check
     * @param authority the authority whose row should be selected
     * @return the SyncStatusInfo for the authority
     */
public SyncStatusInfo getStatusByAccountAndAuthority(Account account, int userId, String authority) {
    if (account == null || authority == null) {
        throw new IllegalArgumentException();
    }
    synchronized (mAuthorities) {
        final int N = mSyncStatus.size();
        for (int i = 0; i < N; i++) {
            SyncStatusInfo cur = mSyncStatus.valueAt(i);
            AuthorityInfo ainfo = mAuthorities.get(cur.authorityId);
            if (ainfo != null && ainfo.authority.equals(authority) && ainfo.userId == userId && account.equals(ainfo.account)) {
                return cur;
            }
        }
        return null;
    }
}
Also used : SyncStatusInfo(android.content.SyncStatusInfo)

Example 37 with SyncStatusInfo

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

the class SyncStorageEngine method insertIntoPending.

public PendingOperation insertIntoPending(PendingOperation op) {
    synchronized (mAuthorities) {
        if (DEBUG) {
            Log.v(TAG, "insertIntoPending: account=" + op.account + " user=" + op.userId + " auth=" + op.authority + " src=" + op.syncSource + " extras=" + op.extras);
        }
        AuthorityInfo authority = getOrCreateAuthorityLocked(op.account, op.userId, op.authority, -1, /* desired identifier */
        true);
        if (authority == null) {
            return null;
        }
        op = new PendingOperation(op);
        op.authorityId = authority.ident;
        mPendingOperations.add(op);
        appendPendingOperationLocked(op);
        SyncStatusInfo status = getOrCreateSyncStatusLocked(authority.ident);
        status.pending = true;
    }
    reportChange(ContentResolver.SYNC_OBSERVER_TYPE_PENDING);
    return op;
}
Also used : SyncStatusInfo(android.content.SyncStatusInfo)

Example 38 with SyncStatusInfo

use of android.content.SyncStatusInfo in project platform_frameworks_base by android.

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

use of android.content.SyncStatusInfo in project platform_frameworks_base by android.

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)

Example 40 with SyncStatusInfo

use of android.content.SyncStatusInfo in project platform_frameworks_base by android.

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)

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