Search in sources :

Example 31 with SyncStatusInfo

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

the class SyncStorageEngine method getStatusByAuthority.

/**
     * Returns the status that matches the target.
     *
     * @param info the endpoint target we are querying status info for.
     * @return the SyncStatusInfo for the endpoint.
     */
public SyncStatusInfo getStatusByAuthority(EndPoint info) {
    if (info.account == null || info.provider == null) {
        return null;
    }
    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.target.matchesSpec(info)) {
                return cur;
            }
        }
        return null;
    }
}
Also used : SyncStatusInfo(android.content.SyncStatusInfo)

Example 32 with SyncStatusInfo

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

the class SyncStorageEngine method writeStatusLocked.

/**
     * Write all sync status to the sync status file.
     */
private void writeStatusLocked() {
    if (DEBUG_FILE)
        Log.v(TAG, "Writing new " + mStatusFile.getBaseFile());
    // The file is being written, so we don't need to have a scheduled
    // write until the next change.
    removeMessages(MSG_WRITE_STATUS);
    FileOutputStream fos = null;
    try {
        fos = mStatusFile.startWrite();
        Parcel out = Parcel.obtain();
        final int N = mSyncStatus.size();
        for (int i = 0; i < N; i++) {
            SyncStatusInfo status = mSyncStatus.valueAt(i);
            out.writeInt(STATUS_FILE_ITEM);
            status.writeToParcel(out, 0);
        }
        out.writeInt(STATUS_FILE_END);
        fos.write(out.marshall());
        out.recycle();
        mStatusFile.finishWrite(fos);
    } catch (java.io.IOException e1) {
        Log.w(TAG, "Error writing status", e1);
        if (fos != null) {
            mStatusFile.failWrite(fos);
        }
    }
}
Also used : Parcel(android.os.Parcel) FileOutputStream(java.io.FileOutputStream) SyncStatusInfo(android.content.SyncStatusInfo)

Example 33 with SyncStatusInfo

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

the class SyncStorageEngine method stopSyncEvent.

public void stopSyncEvent(long historyId, long elapsedTime, String resultMessage, long downstreamActivity, long upstreamActivity) {
    synchronized (mAuthorities) {
        if (DEBUG) {
            Log.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) {
            Log.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 34 with SyncStatusInfo

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

the class SyncStorageEngine method readStatusLocked.

/**
     * Read all sync status back in to the initial engine state.
     */
private void readStatusLocked() {
    if (DEBUG_FILE)
        Log.v(TAG, "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 (DEBUG_FILE)
                        Log.v(TAG, "Adding status for id " + status.authorityId);
                    mSyncStatus.put(status.authorityId, status);
                }
            } else {
                // Ooops.
                Log.w(TAG, "Unknown status token: " + token);
                break;
            }
        }
    } catch (java.io.IOException e) {
        Log.i(TAG, "No initial status");
    }
}
Also used : Parcel(android.os.Parcel) SyncStatusInfo(android.content.SyncStatusInfo)

Example 35 with SyncStatusInfo

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

the class SyncStorageEngine method deleteFromPending.

public boolean deleteFromPending(PendingOperation op) {
    boolean res = false;
    synchronized (mAuthorities) {
        if (DEBUG) {
            Log.v(TAG, "deleteFromPending: account=" + op.account + " user=" + op.userId + " auth=" + op.authority + " src=" + op.syncSource + " extras=" + op.extras);
        }
        if (mPendingOperations.remove(op)) {
            if (mPendingOperations.size() == 0 || mNumPendingFinished >= PENDING_FINISH_TO_WRITE) {
                writePendingOperationsLocked();
                mNumPendingFinished = 0;
            } else {
                mNumPendingFinished++;
            }
            AuthorityInfo authority = getAuthorityLocked(op.account, op.userId, op.authority, "deleteFromPending");
            if (authority != null) {
                if (DEBUG)
                    Log.v(TAG, "removing - " + authority);
                final int N = mPendingOperations.size();
                boolean morePending = false;
                for (int i = 0; i < N; i++) {
                    PendingOperation cur = mPendingOperations.get(i);
                    if (cur.account.equals(op.account) && cur.authority.equals(op.authority) && cur.userId == op.userId) {
                        morePending = true;
                        break;
                    }
                }
                if (!morePending) {
                    if (DEBUG)
                        Log.v(TAG, "no more pending!");
                    SyncStatusInfo status = getOrCreateSyncStatusLocked(authority.ident);
                    status.pending = false;
                }
            }
            res = true;
        }
    }
    reportChange(ContentResolver.SYNC_OBSERVER_TYPE_PENDING);
    return res;
}
Also used : 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