com.vodafone360.people.engine.contactsync
Class ContactSyncEngine

java.lang.Object
  extended by com.vodafone360.people.engine.BaseEngine
      extended by com.vodafone360.people.engine.contactsync.ContactSyncEngine
All Implemented Interfaces:
IContactSyncCallback, NativeContactsApi.ContactsObserver

public class ContactSyncEngine
extends BaseEngine
implements IContactSyncCallback, NativeContactsApi.ContactsObserver

Implementation of engine handling Contact-sync. Contact sync is a multi-stage process, involving sync of contacts from the native database, sync of server contacts, fetching of groups and thumbnails. Each phase is handled by a separate processor created and managed by the Contact sync engine.


Nested Class Summary
static interface ContactSyncEngine.IContactSyncObserver
          Observer interface allowing interested parties to receive notification of changes in Contact sync state.
static class ContactSyncEngine.Mode
          Defines the contact sync mode.
static class ContactSyncEngine.State
          Definition of states for Contact sync.
private static class ContactSyncEngine.SyncParams
          Holds parameters for the UI sync request
 
Nested classes/interfaces inherited from class com.vodafone360.people.engine.BaseEngine
BaseEngine.IEngineEventCallback
 
Field Summary
private static long FULL_SYNC_RETRIES
          Number of retries when first time sync fails
private  BaseSyncProcessor mActiveProcessor
          Currently active processor (the processor which is running) or null
private  ServiceUiRequest mActiveUiRequestBackup
          Backup of the previous active request before processing the new one.
private  ApplicationCache mCache
           
private  boolean mCancelSync
          True if the current contact sync is being cancelled.
private  Context mContext
          The context of the People service
private  ContentResolver mCr
          The content resolver object mainly used for accessing the native database
private  int mCurrentProgressPercent
          Current progress value (used to check if the progress has changed)
private  boolean mDatabaseChanged
          Database changed flag.
private  DatabaseHelper mDb
          DatabaseHelper object used for accessing NowPlus database.
private  boolean mDbChangedByProcessor
          Flag which is set when the current processor changes the database
private  Handler mDbChangeHandler
          Used to listen for NowPlus database change events.
private  java.util.ArrayList<ContactSyncEngine.IContactSyncObserver> mEventCallbackList
          Maintains a list of contact sync observers
private  java.lang.String mFailureList
          A failure list (currently containing unlocalised English strings) of contacts which could not be sync'ed to the server.
private  java.lang.Long mFetchNativeSyncTimeout
          Specifies the time that a fetch native sync should be started relative to current time in milliseconds.
private  boolean mFirstTimeNativeSyncComplete
          Flag which matches the persisted equivalent in the NowPlus database state table.
private  boolean mFirstTimeSyncComplete
          Flag which matches the persisted equivalent in the NowPlus database state table.
private  boolean mFirstTimeSyncStarted
          Flag which matches the persisted equivalent in the NowPlus database state table.
private  boolean mFullSyncRequired
          True if a full sync should be started as soon as possible
private  int mFullSyncRetryCount
          Counter for first time sync failures
private  java.lang.Long mLastDbUpdateTime
          Last time the database was updated (in milliseconds)
private  java.lang.Long mLastServerSyncTime
          Keeps track of the last time a server sync happened.
private  ContactSyncEngine.Mode mMode
          Current mode (or stragegy) the contact sync engine is in.
private  java.lang.Object mMutex
          Mutex for thread synchronization
private  NativeContactsApi mNativeContactsApi
          Native Contacts API access.
private  boolean mNativeFetchSyncRequired
          True if a native fetch sync should be started as soon as possible
private  boolean mNativeUpdateSyncRequired
          True if a native update sync should be started as soon as possible
private  ProcessorFactory mProcessorFactory
          The factory class which is used for creating processors for a particular state.
private  boolean mRemoveUserData
          The following flag is set when the user initiates a remove user data.
private  boolean mServerSyncRequired
          True if a server sync should be started as soon as possible
private  java.lang.Long mServerSyncTimeout
          Specifies the time that a server sync should be started relative to current time in milliseconds.
private  ContactSyncEngine.State mState
          Current state of the contact sync engine (determines which processor is currently active)
private  boolean mThumbnailSyncRequired
          True if a server thumbnail (avatar) sync should be started as soon as possible
private  UiAgent mUiAgent
           
private  java.lang.Long mUpdateNativeSyncTimeout
          Specifies the time that a update native sync should be started relative to current time in milliseconds.
private static long NATIVE_CONTACT_SYNC_TIMEOUT_MS
          Time to wait after the user modifies a contact before a contact sync with the native database will be initiated (in milliseconds).
private static long SERVER_CONTACT_SYNC_TIMEOUT_MS
          Time to wait after the user modifies a contact before a contact sync with the server will be initiated (in milliseconds).
private static long UI_REFRESH_WAIT_TIME_NANO
          Determines the time that should be waited between publishing database change events.
private static long USER_ACTIVITY_SERVER_SYNC_TIMEOUT_MS
          The time to wait before requesting a new server sync when the user is using the application.
 
Fields inherited from class com.vodafone360.people.engine.BaseEngine
mActiveUiRequest, mCurrentTimeout, mEngineId, mEventCallback
 
Constructor Summary
ContactSyncEngine(BaseEngine.IEngineEventCallback eventCallback, Context context, DatabaseHelper db, ProcessorFactory processorFactory)
          ContactSyncEngine constructor.
 
Method Summary
 void addEventCallback(ContactSyncEngine.IContactSyncObserver observer)
          Add observer of Contact-sync.
 void addUiStartFullSync()
          Triggers a full contact sync from the UI (via the service interface).
 void addUiStartServerSync(long delay)
          Triggers a server contact sync from the UI (via service interface).
private  void cancelSync()
          Called by the run function when the mCancelSync flag is set to true.
private  void clearCurrentSyncAndPatchBaseEngine()
          Clears the current sync and make sure that if we cancel a previous sync, it doesn't notify a wrong UI request.
private  void completeSync(ServiceStatus status)
          Called when the current mode has finished all the sync tasks.
private  void fireProgressEvent(ContactSyncEngine.State currentState, int percent)
          Notifies observers when the progress value changes for the current sync.
private  void fireStateChangeEvent(ContactSyncEngine.Mode mode, ContactSyncEngine.State previousState, ContactSyncEngine.State newState)
          Notifies observers when a state or mode change occurs.
private  void fireSyncCompleteEvent(ServiceStatus status)
          Notifies observers when a contact sync complete event occurs.
 BaseEngine getEngine()
          Used by processors to fetch this engine.
 long getNextRunTime()
          Framework function to determine when the contact sync engine next needs to run.
 boolean isFirstTimeSyncComplete()
          Determines if the first time contact sync has been completed.
private  void newState(ContactSyncEngine.State newState)
          Changes the state of the engine and informs the observers.
private  void nextTaskFetchNativeContacts()
          Moves to the next state for the fetch native contacts mode, and runs the appropriate processor.
private  void nextTaskFullSyncFirstTime()
          Moves to the next state for the full sync first time mode, and runs the appropriate processor.
private  void nextTaskFullSyncNormal()
          Moves to the next state for the full sync normal mode, and runs the appropriate processor.
private  void nextTaskServerSync()
          Moves to the next state for the server sync mode, and runs the appropriate processor.
private  void nextTaskThumbnailSync()
          Moves to the next state for the thumbnail sync mode, and runs the appropriate processor.
private  void nextTaskUpdateNativeContacts()
          Moves to the next state for the update native contacts mode, and runs the appropriate processor.
 void onChange()
          Call-back to notify that a change happened in the native address book.
 void onCreate()
          Called after the engine has been created to do some extra initialisation.
 void onDatabaseChanged()
          Called by the active processor to indicate that the NowPlus database has changed.
 void onDestroy()
          Called just before engine is about to be closed.
 void onProcessorComplete(ServiceStatus status, java.lang.String failureList, java.lang.Object data)
          Called by a processor when it has completed.
protected  void onRequestComplete()
          Called by base class when a contact sync UI request has been completed.
 void onReset()
          Called by framework to warn the engine that a remove user data is about to start.
protected  void onTimeoutEvent()
          Called by base class when a timeout has been completed.
 void pingUserActivity()
          Tells the ContactSyncEngine that the user is actively using the service and adjust sync timeout accordingly.
protected  void processCommsResponse(ResponseQueue.Response resp)
          Called when a response to a request or a push message is received from the server.
private  void processDbMessage(Message message)
          Called when a database change event is received from the DatabaseHelper.
private  boolean processPushEvent(ResponseQueue.Response resp)
          Determines if a given response is a push message and processes in this case TODO: we need the check for Me Profile be migrated to he new engine
protected  void processUiRequest(ServiceUiRequest requestId, java.lang.Object data)
          Called by base class to process a NOWPLUSSYNC UI request.
private  boolean readyToStartFetchNativeSync()
          Checks if a fetch native sync can be started based on network conditions and engine state
private  boolean readyToStartServerSync()
          Checks if a server sync can be started based on network conditions and engine state
private  boolean readyToStartUpdateNativeSync()
          Checks if a update native sync can be started based on network conditions and engine state
 void run()
          Called by framework when getNextRunTime() reports that the engine needs to run, to carry out the next task.
 void setActiveRequestId(int reqId)
          Called by active processor when issuing a request to store the request id in the base engine class.
private  ServiceStatus setFirstTimeNativeSyncComplete(boolean value)
          Helper function to update the database when the state of the mFirstTimeNativeSyncComplete flag changes.
private  ServiceStatus setFirstTimeSyncComplete(boolean value)
          Helper function to update the database when the state of the mFirstTimeSyncComplete flag changes.
private  ServiceStatus setFirstTimeSyncStarted(boolean value)
          Helper function to update the database when the state of the mFirstTimeSyncStarted flag changes.
 void setSyncStatus(SyncStatus syncStatus)
          Used by active processor to set the current progress.
 void setTimeout(long timeout)
          Used by active processor to set a timeout.
private  void setTimeoutIfRequired()
          Sets the current timeout to the next pending timer and kicks the engine if necessary.
private  boolean startDownloadServerContacts()
          Helper function to start the download server contacts processor
private  boolean startDownloadServerThumbnails()
          Helper function to start the download thumbnails processor
private  boolean startFetchNativeContacts()
          Helper function to start the fetch native contacts processor
private  void startFetchNativeContactSyncTimer()
          Starts a timer to trigger a fetch native contact sync in a short while (normally around 30 seconds).
private  void startFetchNativeSync()
          Starts a background fetch native contacts sync
 void startFullSync()
          Starts a full sync.
private  void startProcessor(BaseSyncProcessor processor)
          Helper function to start a processor running.
private  void startServerContactSyncTimer(long delay)
          Starts a timer to trigger a server contact sync in a short while (normally around 30 seconds).
private  void startServerSync()
          Starts a server sync.
private  void startSyncIfRequired()
          Based on current timeout values schedules a new sync if required.
private  void startThumbnailSync()
          Starts a background thumbnail sync
private  boolean startUpdateNativeContacts()
          Helper function to start the update native contacts processor
private  void startUpdateNativeContactSyncTimer()
          Starts a timer to trigger a update native contact sync in a short while (normally around 30 seconds).
private  void startUpdateNativeSync()
          Starts a background update native contacts sync
private  boolean startUploadServerContacts()
          Helper function to start the upload server contacts processor
private  boolean startUploadServerThumbnails()
          Helper function to start the upload thumbnails processor
 
Methods inherited from class com.vodafone360.people.engine.BaseEngine
addUiRequestToQueue, clearTimeout, completeUiRequest, completeUiRequest, deactivateEngine, emptyUiRequestQueue, engineId, genericHandleResponseType, getCurrentTimeout, isCommsResponseOutstanding, isDeactivated, isUiRequestOutstanding, onCommsInMessage, processCommsInQueue, processTimeout, processUiQueue, setReqId
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

mMutex

private final java.lang.Object mMutex
Mutex for thread synchronization


mUiAgent

private final UiAgent mUiAgent

mCache

private final ApplicationCache mCache

FULL_SYNC_RETRIES

private static final long FULL_SYNC_RETRIES
Number of retries when first time sync fails

See Also:
Constant Field Values

mFullSyncRetryCount

private int mFullSyncRetryCount
Counter for first time sync failures


mState

private ContactSyncEngine.State mState
Current state of the contact sync engine (determines which processor is currently active)


mMode

private ContactSyncEngine.Mode mMode
Current mode (or stragegy) the contact sync engine is in. The mode determines the order which the processors are run.


mFailureList

private java.lang.String mFailureList
A failure list (currently containing unlocalised English strings) of contacts which could not be sync'ed to the server.


mDatabaseChanged

private boolean mDatabaseChanged
Database changed flag. Will be set to true if at any stage of the contact sync the NowPlus database is changed.


mLastDbUpdateTime

private java.lang.Long mLastDbUpdateTime
Last time the database was updated (in milliseconds)


mDb

private DatabaseHelper mDb
DatabaseHelper object used for accessing NowPlus database.


mActiveProcessor

private BaseSyncProcessor mActiveProcessor
Currently active processor (the processor which is running) or null


mProcessorFactory

private ProcessorFactory mProcessorFactory
The factory class which is used for creating processors for a particular state.


SERVER_CONTACT_SYNC_TIMEOUT_MS

private static final long SERVER_CONTACT_SYNC_TIMEOUT_MS
Time to wait after the user modifies a contact before a contact sync with the server will be initiated (in milliseconds). The timer will be reset each time a modification takes place.

See Also:
Constant Field Values

NATIVE_CONTACT_SYNC_TIMEOUT_MS

private static final long NATIVE_CONTACT_SYNC_TIMEOUT_MS
Time to wait after the user modifies a contact before a contact sync with the native database will be initiated (in milliseconds). The timer will be reset each time a modification takes place.

See Also:
Constant Field Values

USER_ACTIVITY_SERVER_SYNC_TIMEOUT_MS

private static final long USER_ACTIVITY_SERVER_SYNC_TIMEOUT_MS
The time to wait before requesting a new server sync when the user is using the application.

See Also:
Constant Field Values

UI_REFRESH_WAIT_TIME_NANO

private static final long UI_REFRESH_WAIT_TIME_NANO
Determines the time that should be waited between publishing database change events. This is to prevent the UI updating too frequently during a contact sync. The time is specified in nanoseconds.

See Also:
Constant Field Values

mServerSyncTimeout

private volatile java.lang.Long mServerSyncTimeout
Specifies the time that a server sync should be started relative to current time in milliseconds. Will be NULL when a server sync timeout is not required.


mFetchNativeSyncTimeout

private volatile java.lang.Long mFetchNativeSyncTimeout
Specifies the time that a fetch native sync should be started relative to current time in milliseconds. Will be NULL when a fetch native sync timeout is not required.


mUpdateNativeSyncTimeout

private volatile java.lang.Long mUpdateNativeSyncTimeout
Specifies the time that a update native sync should be started relative to current time in milliseconds. Will be NULL when a update native sync timeout is not required.


mLastServerSyncTime

private java.lang.Long mLastServerSyncTime
Keeps track of the last time a server sync happened.


mCr

private ContentResolver mCr
The content resolver object mainly used for accessing the native database


mContext

private Context mContext
The context of the People service


mFirstTimeSyncComplete

private boolean mFirstTimeSyncComplete
Flag which matches the persisted equivalent in the NowPlus database state table. Will be set to true when the first time sync is completed and will remain true until a remove user data is performed.


mFirstTimeSyncStarted

private boolean mFirstTimeSyncStarted
Flag which matches the persisted equivalent in the NowPlus database state table. Will be set to true when the first time sync is started and will remain true until a remove user data is performed.


mFirstTimeNativeSyncComplete

private volatile boolean mFirstTimeNativeSyncComplete
Flag which matches the persisted equivalent in the NowPlus database state table. Will be set to true when the part of the first time sync to fetch native contacts is started and will remain true until a remove user data is performed. Once this flag has been set to true, the next time a full sync is started the full sync normal mode will be used instead of full sync first time.


mFullSyncRequired

private boolean mFullSyncRequired
True if a full sync should be started as soon as possible


mServerSyncRequired

private boolean mServerSyncRequired
True if a server sync should be started as soon as possible


mNativeFetchSyncRequired

private boolean mNativeFetchSyncRequired
True if a native fetch sync should be started as soon as possible


mNativeUpdateSyncRequired

private boolean mNativeUpdateSyncRequired
True if a native update sync should be started as soon as possible


mThumbnailSyncRequired

private boolean mThumbnailSyncRequired
True if a server thumbnail (avatar) sync should be started as soon as possible


mCancelSync

private boolean mCancelSync
True if the current contact sync is being cancelled. This can happen when the user performs a remove user data to prevent the database being updated by a contact sync during deletion.


mRemoveUserData

private boolean mRemoveUserData
The following flag is set when the user initiates a remove user data. The contact sync must be stopped.


mEventCallbackList

private final java.util.ArrayList<ContactSyncEngine.IContactSyncObserver> mEventCallbackList
Maintains a list of contact sync observers


mCurrentProgressPercent

private int mCurrentProgressPercent
Current progress value (used to check if the progress has changed)


mDbChangedByProcessor

private boolean mDbChangedByProcessor
Flag which is set when the current processor changes the database


mActiveUiRequestBackup

private ServiceUiRequest mActiveUiRequestBackup
Backup of the previous active request before processing the new one.


mNativeContactsApi

private final NativeContactsApi mNativeContactsApi
Native Contacts API access. The appropriate version should be used depending on the SDK.


mDbChangeHandler

private final Handler mDbChangeHandler
Used to listen for NowPlus database change events. Such events will be received when the user modifies a contact in the people application.

Constructor Detail

ContactSyncEngine

public ContactSyncEngine(BaseEngine.IEngineEventCallback eventCallback,
                         Context context,
                         DatabaseHelper db,
                         ProcessorFactory processorFactory)
ContactSyncEngine constructor.

Parameters:
eventCallback - Engine-event callback interface allowing engine to report back to client on request completion.
context - Context.
db - Handle to People database.
processorFactory - the processor factory
Method Detail

onCreate

public void onCreate()
Called after the engine has been created to do some extra initialisation.

Specified by:
onCreate in class BaseEngine

onDestroy

public void onDestroy()
Called just before engine is about to be closed. Cleans up resources.

Specified by:
onDestroy in class BaseEngine

addUiStartFullSync

public void addUiStartFullSync()
Triggers a full contact sync from the UI (via the service interface). Will start a first time sync if necessary, otherwise a normal full sync will be executed. A ServiceUiRequest.NOWPLUSSYNC event will be sent to notify the UI when the sync has completed.


addUiStartServerSync

public void addUiStartServerSync(long delay)
Triggers a server contact sync from the UI (via service interface). Only the contacts will be updated, not the me profile.

Parameters:
delay - the delay in milliseconds from now when the sync should start

pingUserActivity

public void pingUserActivity()
Tells the ContactSyncEngine that the user is actively using the service and adjust sync timeout accordingly. Note: A server sync should occur every 20 minutes during application intensive usage or immediately if the application is used again after sleeping more than 20 minutes.


isFirstTimeSyncComplete

public boolean isFirstTimeSyncComplete()
Determines if the first time contact sync has been completed.

Returns:
true if completed.

addEventCallback

public void addEventCallback(ContactSyncEngine.IContactSyncObserver observer)
Add observer of Contact-sync.

Parameters:
observer - IContactSyncObserver handle.

startServerContactSyncTimer

private void startServerContactSyncTimer(long delay)
Starts a timer to trigger a server contact sync in a short while (normally around 30 seconds).


startFetchNativeContactSyncTimer

private void startFetchNativeContactSyncTimer()
Starts a timer to trigger a fetch native contact sync in a short while (normally around 30 seconds).


startUpdateNativeContactSyncTimer

private void startUpdateNativeContactSyncTimer()
Starts a timer to trigger a update native contact sync in a short while (normally around 30 seconds).


startProcessor

private void startProcessor(BaseSyncProcessor processor)
Helper function to start a processor running.

Parameters:
processor - Processor which was created by processor factory.

getNextRunTime

public long getNextRunTime()
Framework function to determine when the contact sync engine next needs to run.

Specified by:
getNextRunTime in class BaseEngine
Returns:
-1 if the engine does not need to run 0 if the engine needs to run as soon as possible x where x > 0, the engine needs to run when current time in milliseconds >= x

run

public void run()
Called by framework when getNextRunTime() reports that the engine needs to run, to carry out the next task. Each task should not take longer than a second to complete.

Specified by:
run in class BaseEngine

onRequestComplete

protected void onRequestComplete()
Called by base class when a contact sync UI request has been completed. Not currently used.

Specified by:
onRequestComplete in class BaseEngine

onTimeoutEvent

protected void onTimeoutEvent()
Called by base class when a timeout has been completed. If there is an active processor the timeout event will be passed to it, otherwise the engine will check if it needs to schedule a new sync and set the next pending timeout.

Specified by:
onTimeoutEvent in class BaseEngine

startSyncIfRequired

private void startSyncIfRequired()
Based on current timeout values schedules a new sync if required.


processCommsResponse

protected void processCommsResponse(ResponseQueue.Response resp)
Called when a response to a request or a push message is received from the server. Push messages are processed by the engine, responses are passed to the active processor.

Specified by:
processCommsResponse in class BaseEngine
Parameters:
resp - Response or push message received

processPushEvent

private boolean processPushEvent(ResponseQueue.Response resp)
Determines if a given response is a push message and processes in this case TODO: we need the check for Me Profile be migrated to he new engine

Parameters:
resp - Response to check and process
Returns:
true if the response was processed

processUiRequest

protected void processUiRequest(ServiceUiRequest requestId,
                                java.lang.Object data)
Called by base class to process a NOWPLUSSYNC UI request. This will be called to process a full sync or server sync UI request.

Specified by:
processUiRequest in class BaseEngine
Parameters:
requestId - ID of the request to process, only ServiceUiRequest.NOWPLUSSYNC is currently supported.
data - Type is determined by request ID, in case of NOWPLUSSYNC this is a flag which determines if a full sync is required (true = full sync, false = server sync).

cancelSync

private void cancelSync()
Called by the run function when the mCancelSync flag is set to true. Cancels the active processor and completes the current UI request.


clearCurrentSyncAndPatchBaseEngine

private void clearCurrentSyncAndPatchBaseEngine()
Clears the current sync and make sure that if we cancel a previous sync, it doesn't notify a wrong UI request. TODO: Find another way to not have to hack the BaseEngine!


readyToStartServerSync

private boolean readyToStartServerSync()
Checks if a server sync can be started based on network conditions and engine state

Returns:
true if a sync can be started, false otherwise.

readyToStartFetchNativeSync

private boolean readyToStartFetchNativeSync()
Checks if a fetch native sync can be started based on network conditions and engine state

Returns:
true if a sync can be started, false otherwise.

readyToStartUpdateNativeSync

private boolean readyToStartUpdateNativeSync()
Checks if a update native sync can be started based on network conditions and engine state

Returns:
true if a sync can be started, false otherwise.

startFullSync

public void startFullSync()
Starts a full sync. If the native contacts haven't yet been fetched then a first time sync will be started, otherwise will start a normal full sync. Full syncs are always initiated from the UI (via UI request).


startServerSync

private void startServerSync()
Starts a server sync. This will only sync contacts with the server and will not include the me profile. Thumbnails are not fetched as part of this sync, but will be fetched as part of a background sync afterwards.


startThumbnailSync

private void startThumbnailSync()
Starts a background thumbnail sync


startFetchNativeSync

private void startFetchNativeSync()
Starts a background fetch native contacts sync


startUpdateNativeSync

private void startUpdateNativeSync()
Starts a background update native contacts sync


startFetchNativeContacts

private boolean startFetchNativeContacts()
Helper function to start the fetch native contacts processor

Returns:
if this type of sync is enabled in the settings, false otherwise.

startUpdateNativeContacts

private boolean startUpdateNativeContacts()
Helper function to start the update native contacts processor

Returns:
if this type of sync is enabled in the settings, false otherwise.

startDownloadServerContacts

private boolean startDownloadServerContacts()
Helper function to start the download server contacts processor

Returns:
if this type of sync is enabled in the settings, false otherwise.

startUploadServerContacts

private boolean startUploadServerContacts()
Helper function to start the upload server contacts processor

Returns:
if this type of sync is enabled in the settings, false otherwise.

startDownloadServerThumbnails

private boolean startDownloadServerThumbnails()
Helper function to start the download thumbnails processor

Returns:
if this type of sync is enabled in the settings, false otherwise.

startUploadServerThumbnails

private boolean startUploadServerThumbnails()
Helper function to start the upload thumbnails processor

Returns:
if this type of sync is enabled in the settings, false otherwise.

onProcessorComplete

public void onProcessorComplete(ServiceStatus status,
                                java.lang.String failureList,
                                java.lang.Object data)
Called by a processor when it has completed. Will move to the next task. When the active contact sync has totally finished, will complete any pending UI request.

Specified by:
onProcessorComplete in interface IContactSyncCallback
Parameters:
status - Status of the sync from the processor, any error codes will stop the sync.
failureList - Contains a list of sync failure information which can be used as a summary at the end. Otherwise should be an empty string.
data - Any processor specific data to pass back to the engine. Not currently used.

nextTaskFullSyncFirstTime

private void nextTaskFullSyncFirstTime()
Moves to the next state for the full sync first time mode, and runs the appropriate processor. Completes the UI request when the sync is complete (if one is pending).


nextTaskFullSyncNormal

private void nextTaskFullSyncNormal()
Moves to the next state for the full sync normal mode, and runs the appropriate processor. Completes the UI request when the sync is complete (if one is pending).


nextTaskFetchNativeContacts

private void nextTaskFetchNativeContacts()
Moves to the next state for the fetch native contacts mode, and runs the appropriate processor. Completes the UI request when the sync is complete (if one is pending).


nextTaskUpdateNativeContacts

private void nextTaskUpdateNativeContacts()
Moves to the next state for the update native contacts mode, and runs the appropriate processor. Completes the UI request when the sync is complete (if one is pending).


nextTaskServerSync

private void nextTaskServerSync()
Moves to the next state for the server sync mode, and runs the appropriate processor. Completes the UI request when the sync is complete (if one is pending).


nextTaskThumbnailSync

private void nextTaskThumbnailSync()
Moves to the next state for the thumbnail sync mode, and runs the appropriate processor. Completes the UI request when the sync is complete (if one is pending).


newState

private void newState(ContactSyncEngine.State newState)
Changes the state of the engine and informs the observers.

Parameters:
newState - The new state

completeSync

private void completeSync(ServiceStatus status)
Called when the current mode has finished all the sync tasks. Completes the UI request if one is pending, sends an event to the observer and a database change event if necessary.

Parameters:
status - The overall status of the contact sync.

setTimeoutIfRequired

private void setTimeoutIfRequired()
Sets the current timeout to the next pending timer and kicks the engine if necessary.


onDatabaseChanged

public void onDatabaseChanged()
Called by the active processor to indicate that the NowPlus database has changed.

Specified by:
onDatabaseChanged in interface IContactSyncCallback

getEngine

public BaseEngine getEngine()
Used by processors to fetch this engine. The BaseEngine reference is needed to send requests to the server.

Specified by:
getEngine in interface IContactSyncCallback
Returns:
The BaseEngine reference of this engine.

setTimeout

public void setTimeout(long timeout)
Used by active processor to set a timeout.

Specified by:
setTimeout in interface IContactSyncCallback
Overrides:
setTimeout in class BaseEngine
Parameters:
timeout - Timeout value based on current time in milliseconds

setSyncStatus

public void setSyncStatus(SyncStatus syncStatus)
Used by active processor to set the current progress.

Specified by:
setSyncStatus in interface IContactSyncCallback
Parameters:
SyncStatus - Status of the processor, must not be NULL.
Throws:
java.security.InvalidParameterException - when SyncStatus is NULL.

setActiveRequestId

public void setActiveRequestId(int reqId)
Called by active processor when issuing a request to store the request id in the base engine class.

Specified by:
setActiveRequestId in interface IContactSyncCallback
Parameters:
reqId - Request ID received from one of the API functions.

setFirstTimeSyncStarted

private ServiceStatus setFirstTimeSyncStarted(boolean value)
Helper function to update the database when the state of the mFirstTimeSyncStarted flag changes.

Parameters:
value - New value to the flag. True indicates that first time sync has been started. The flag is never set to false again by the engine, it will be only set to false when a remove user data is done (and the database is deleted).
Returns:
SUCCESS or a suitable error code if the database could not be updated.

setFirstTimeSyncComplete

private ServiceStatus setFirstTimeSyncComplete(boolean value)
Helper function to update the database when the state of the mFirstTimeSyncComplete flag changes.

Parameters:
value - New value to the flag. True indicates that first time sync has been completed. The flag is never set to false again by the engine, it will be only set to false when a remove user data is done (and the database is deleted).
Returns:
SUCCESS or a suitable error code if the database could not be updated.

setFirstTimeNativeSyncComplete

private ServiceStatus setFirstTimeNativeSyncComplete(boolean value)
Helper function to update the database when the state of the mFirstTimeNativeSyncComplete flag changes.

Parameters:
value - New value to the flag. True indicates that the native fetch part of the first time sync has been completed. The flag is never set to false again by the engine, it will be only set to false when a remove user data is done (and the database is deleted).
Returns:
SUCCESS or a suitable error code if the database could not be updated.

processDbMessage

private void processDbMessage(Message message)
Called when a database change event is received from the DatabaseHelper. Only internal database change events are processed, external change events are generated by the contact sync engine.

Parameters:
msg - The message indicating the type of event

fireStateChangeEvent

private void fireStateChangeEvent(ContactSyncEngine.Mode mode,
                                  ContactSyncEngine.State previousState,
                                  ContactSyncEngine.State newState)
Notifies observers when a state or mode change occurs.

Parameters:
mode - Current mode
previousState - State before the change
newState - State after the change.

fireSyncCompleteEvent

private void fireSyncCompleteEvent(ServiceStatus status)
Notifies observers when a contact sync complete event occurs.

Parameters:
status - SUCCESS or a suitable error code

fireProgressEvent

private void fireProgressEvent(ContactSyncEngine.State currentState,
                               int percent)
Notifies observers when the progress value changes for the current sync.

Parameters:
currentState - Current sync task being processed
percent - Progress of task (between 0 and 100 percent)

onReset

public void onReset()
Called by framework to warn the engine that a remove user data is about to start. Sets flags and kicks the engine.

Overrides:
onReset in class BaseEngine

onChange

public void onChange()
Description copied from interface: NativeContactsApi.ContactsObserver
Call-back to notify that a change happened in the native address book.

Specified by:
onChange in interface NativeContactsApi.ContactsObserver
See Also:
NativeContactsApi.ContactsObserver.onChange()


JavaDoc