FileDocCategorySizeDatePackage
SyncCommon.javaAPI DocAndroid 1.5 API6513Wed May 06 22:41:08 BST 2009com.android.ddmuilib.log.event

SyncCommon

public abstract class SyncCommon extends EventDisplay

Fields Summary
private int
mLastState
private long
mLastStartTime
private long
mLastStopTime
private String
mLastDetails
private int
mLastSyncSource
protected static final int
CALENDAR
protected static final int
GMAIL
protected static final int
FEEDS
protected static final int
CONTACTS
protected static final int
ERRORS
protected static final int
NUM_AUTHS
protected static final String[]
AUTH_NAMES
protected static final Color[]
AUTH_COLORS
final int
EVENT_SYNC
final int
EVENT_TICKLE
final int
EVENT_SYNC_DETAILS
Constructors Summary
protected SyncCommon(String name)


       
        super(name);
    
Methods Summary
protected intgetAuth(java.lang.String authname)
Converts authority name to auth number.

param
authname "calendar", etc.
return
number series number associated with the authority

        if ("calendar".equals(authname) || "cl".equals(authname)) {
            return CALENDAR;
        } else if ("contacts".equals(authname) || "cp".equals(authname)) {
            return CONTACTS;
        } else if ("subscribedfeeds".equals(authname)) {
            return FEEDS;
        } else if ("gmail-ls".equals(authname) || "mail".equals(authname)) {
            return GMAIL;
        } else if ("gmail-live".equals(authname)) {
            return GMAIL;
        } else if ("unknown".equals(authname)) {
            return -1; // Unknown tickles; discard
        } else {
            throw new InvalidTypeException("Unknown authname " + authname);
        }
    
voidnewEvent(com.android.ddmlib.log.EventContainer event, com.android.ddmlib.log.EventLogParser logParser)
Updates the display with a new event. This is the main entry point for each event. This method has the logic to tie together the start event, stop event, and details event into one graph item. The combined sync event is handed to the subclass via processSycnEvent. Note that the details can happen before or after the stop event.

param
event The event
param
logParser The parser providing the event.

        try {
            if (event.mTag == EVENT_SYNC) {
                int state = Integer.parseInt(event.getValueAsString(1));
                if (state == 0) { // start
                    mLastStartTime = (long) event.sec * 1000L + (event.nsec / 1000000L);
                    mLastState = 0;
                    mLastSyncSource = Integer.parseInt(event.getValueAsString(2));                    
                    mLastDetails = "";
                } else if (state == 1) { // stop
                    if (mLastState == 0) {
                        mLastStopTime = (long) event.sec * 1000L + (event.nsec / 1000000L);
                        if (mLastStartTime == 0) {
                            // Log starts with a stop event
                            mLastStartTime = mLastStopTime;
                        }
                        int auth = getAuth(event.getValueAsString(0));
                        processSyncEvent(event, auth, mLastStartTime, mLastStopTime, mLastDetails,
                                true, mLastSyncSource);
                        mLastState = 1;
                    }
                }
            } else if (event.mTag == EVENT_SYNC_DETAILS) {
                mLastDetails = event.getValueAsString(3);
                if (mLastState != 0) { // Not inside event
                    long updateTime = (long) event.sec * 1000L + (event.nsec / 1000000L);
                    if (updateTime - mLastStopTime <= 250) {
                        // Got details within 250ms after event, so delete and re-insert
                        // Details later than 250ms (arbitrary) are discarded as probably
                        // unrelated.
                        int auth = getAuth(event.getValueAsString(0));
                        processSyncEvent(event, auth, mLastStartTime, mLastStopTime, mLastDetails,
                                false, mLastSyncSource);
                    }
                }
            }
        } catch (InvalidTypeException e) {
        }
    
abstract voidprocessSyncEvent(com.android.ddmlib.log.EventContainer event, int auth, long startTime, long stopTime, java.lang.String details, boolean newEvent, int syncSource)
Callback hook for subclass to process a sync event. newEvent has the logic to combine start and stop events and passes a processed event to the subclass.

param
event The sync event
param
auth The sync authority
param
startTime Start time (ms) of events
param
stopTime Stop time (ms) of events
param
details Details associated with the event.
param
newEvent True if this event is a new sync event. False if this event
param
syncSource Poll, user, server, etc.

voidresetUI()
Resets the display.

        mLastStartTime = 0;
        mLastStopTime = 0;
        mLastState = -1;
        mLastSyncSource = -1;
        mLastDetails = "";