Search in sources :

Example 1 with ServiceUiRequest

use of com.vodafone360.people.service.ServiceUiRequest in project 360-Engine-for-Android by 360.

the class ContactSyncEngine method processDbMessage.

/**
 * 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.
 *
 * @param msg The message indicating the type of event
 */
private void processDbMessage(Message message) {
    final ServiceUiRequest event = ServiceUiRequest.getUiEvent(message.what);
    switch(event) {
        case DATABASE_CHANGED_EVENT:
            if (message.arg1 == DatabaseHelper.DatabaseChangeType.CONTACTS.ordinal() && message.arg2 == 0) {
                LogUtils.logV("ContactSyncEngine.processDbMessage - Contacts have changed");
                // startMeProfileSyncTimer();
                startServerContactSyncTimer(SERVER_CONTACT_SYNC_TIMEOUT_MS);
                startUpdateNativeContactSyncTimer();
            }
            break;
        default:
            // Do nothing.
            break;
    }
}
Also used : ServiceUiRequest(com.vodafone360.people.service.ServiceUiRequest)

Example 2 with ServiceUiRequest

use of com.vodafone360.people.service.ServiceUiRequest in project 360-Engine-for-Android by 360.

the class IdentityEngine method pushIdentitiesToUi.

/**
 * Pushes the identities retrieved by get my identities or by get available identities
 * to the ui.
 *
 * @param request The request type: either get my identities, or get available identities.
 */
private void pushIdentitiesToUi(ServiceUiRequest request) {
    String requestKey = null;
    ArrayList<Identity> idBundle = null;
    if (request == ServiceUiRequest.GET_AVAILABLE_IDENTITIES) {
        requestKey = KEY_AVAILABLE_IDS;
        synchronized (mAvailableIdentityList) {
            // provide a shallow copy
            idBundle = new ArrayList<Identity>(mAvailableIdentityList);
        }
    } else {
        requestKey = KEY_MY_IDS;
        synchronized (mMyIdentityList) {
            // provide a shallow copy
            idBundle = new ArrayList<Identity>(mMyIdentityList);
        }
    }
    // send update to 3rd party identities ui if it is up
    Bundle b = new Bundle();
    b.putParcelableArrayList(requestKey, idBundle);
    UiAgent uiAgent = mEventCallback.getUiAgent();
    if (uiAgent != null && uiAgent.isSubscribed()) {
        uiAgent.sendUnsolicitedUiEvent(request, b);
    }
// end: send update to 3rd party identities ui if it is up
}
Also used : UiAgent(com.vodafone360.people.service.agent.UiAgent) Bundle(android.os.Bundle) Identity(com.vodafone360.people.datatypes.Identity)

Example 3 with ServiceUiRequest

use of com.vodafone360.people.service.ServiceUiRequest in project 360-Engine-for-Android by 360.

the class ContactSyncEngineTest method testCancelSync.

/**
 * Tests the sync is cancelled in case we remove user data.
 */
@Suppress
public // Breaks tests.
void testCancelSync() {
    Log.i(LOG_TAG, "**** testNativeSync_newEngineInstantiation() begin ****");
    final ArrayList<ProcessorLog> processorLogs = new ArrayList<ProcessorLog>();
    final UiEventCall uiEventCall = new UiEventCall();
    final ProcessorLog processorLog = new ProcessorLog();
    final IEngineEventCallback engineEventCallback = new HelperClasses.EngineCallbackBase() {

        @Override
        public void onUiEvent(ServiceUiRequest event, int request, int status, Object data) {
            Log.i(LOG_TAG, "onUiEvent: " + event + ", " + request + ", " + status + ", " + data);
            uiEventCall.event = event.ordinal();
            uiEventCall.request = request;
            uiEventCall.status = status;
            uiEventCall.data = data;
        }
    };
    final ProcessorFactory factory = new ProcessorFactory() {

        @Override
        public BaseSyncProcessor create(int type, IContactSyncCallback callback, DatabaseHelper dbHelper) {
            Log.i(LOG_TAG, "create(), type=" + type);
            ProcessorLog log = new ProcessorLog();
            log.type = type;
            log.time = System.currentTimeMillis();
            processorLogs.add(log);
            return new BaseSyncProcessor(mContactSyncEngine, null) {

                @Override
                protected void doCancel() {
                    // cancel the job
                    processorLog.type = 1;
                }

                @Override
                protected void doStart() {
                    // set a "timeout" to be called back immediately
                    setTimeout(0);
                    processorLog.type = 2;
                }

                @Override
                public void onTimeoutEvent() {
                    // set the job as completed
                    Log.i(LOG_TAG, "onTimeoutEvent()");
                    complete(ServiceStatus.SUCCESS);
                    processorLog.type = 3;
                }

                @Override
                public void processCommsResponse(DecodedResponse resp) {
                    // we don't need this case in this test
                    processorLog.type = 4;
                }
            };
        }
    };
    minimalEngineSetup(engineEventCallback, factory);
    // set the connection to be fine
    NetworkAgent.setAgentState(NetworkAgent.AgentState.CONNECTED);
    long nextRuntime = mContactSyncEngine.getNextRunTime();
    // should be equal to -1 because first time sync has not been yet
    // started
    assertEquals(-1, nextRuntime);
    // force a first time sync
    mContactSyncEngine.addUiStartFullSync();
    processorLog.type = 0;
    // start performing the sync
    mContactSyncEngine.run();
    // the first processor should have started
    assertTrue(processorLog.type == 2);
    // this will cancel any sync
    mContactSyncEngine.onReset();
    // get the engine to perform a cancel on the current processor
    mContactSyncEngine.run();
    assertTrue(processorLog.type == 1);
    // check that the engine cancelled the sync
    assertEquals(ServiceUiRequest.UI_REQUEST_COMPLETE.ordinal(), uiEventCall.event);
    assertEquals(uiEventCall.status, ServiceStatus.USER_CANCELLED.ordinal());
}
Also used : DecodedResponse(com.vodafone360.people.service.io.ResponseQueue.DecodedResponse) ArrayList(java.util.ArrayList) ServiceUiRequest(com.vodafone360.people.service.ServiceUiRequest) DatabaseHelper(com.vodafone360.people.database.DatabaseHelper) BaseSyncProcessor(com.vodafone360.people.engine.contactsync.BaseSyncProcessor) ProcessorFactory(com.vodafone360.people.engine.contactsync.ProcessorFactory) IContactSyncCallback(com.vodafone360.people.engine.contactsync.IContactSyncCallback) IEngineEventCallback(com.vodafone360.people.engine.IEngineEventCallback) Suppress(android.test.suitebuilder.annotation.Suppress)

Example 4 with ServiceUiRequest

use of com.vodafone360.people.service.ServiceUiRequest in project 360-Engine-for-Android by 360.

the class ContactSyncEngineTest method testAutoSyncTimer.

/**
 * Checks that nothing is scheduled before the first time sync has been
 * completed.
 */
@Suppress
public void testAutoSyncTimer() {
    Log.i(LOG_TAG, "**** testAutoSyncTimer() begin ****");
    final IEngineEventCallback engineEventCallback = new HelperClasses.EngineCallbackBase() {

        @Override
        public void onUiEvent(ServiceUiRequest event, int request, int status, Object data) {
            Log.i(LOG_TAG, "onUiEvent: " + event + ", " + request + ", " + status + ", " + data);
        }
    };
    final ProcessorFactory factory = new ProcessorFactory() {

        @Override
        public BaseSyncProcessor create(int type, IContactSyncCallback callback, DatabaseHelper dbHelper) {
            Log.i(LOG_TAG, "create(), type=" + type);
            return new DummySyncProcessor(mContactSyncEngine, null);
        }
    };
    minimalEngineSetup(engineEventCallback, factory);
    // set the connection to be fine
    NetworkAgent.setAgentState(NetworkAgent.AgentState.CONNECTED);
    // should be equal to -1 because first time sync has not been yet
    // started
    assertEquals(-1, mContactSyncEngine.getNextRunTime());
    mContactSyncEngine.run();
    assertEquals(-1, mContactSyncEngine.getNextRunTime());
    mContactSyncEngine.run();
    assertEquals(-1, mContactSyncEngine.getNextRunTime());
    Log.i(LOG_TAG, "**** testAutoSyncTimer() end ****");
}
Also used : DatabaseHelper(com.vodafone360.people.database.DatabaseHelper) ServiceUiRequest(com.vodafone360.people.service.ServiceUiRequest) ProcessorFactory(com.vodafone360.people.engine.contactsync.ProcessorFactory) IContactSyncCallback(com.vodafone360.people.engine.contactsync.IContactSyncCallback) IEngineEventCallback(com.vodafone360.people.engine.IEngineEventCallback) Suppress(android.test.suitebuilder.annotation.Suppress)

Example 5 with ServiceUiRequest

use of com.vodafone360.people.service.ServiceUiRequest in project 360-Engine-for-Android by 360.

the class ContactSyncEngineTest method testBackgroundSync.

/**
 * Checks that background sync is performed after the first time sync.
 */
@Suppress
public // Breaks tests.
void testBackgroundSync() {
    Log.i(LOG_TAG, "**** testBackgroundSync() begin ****");
    final ArrayList<ProcessorLog> processorLogs = new ArrayList<ProcessorLog>();
    final UiEventCall uiEventCall = new UiEventCall();
    final IEngineEventCallback engineEventCallback = new HelperClasses.EngineCallbackBase() {

        @Override
        public void onUiEvent(ServiceUiRequest event, int request, int status, Object data) {
            Log.i(LOG_TAG, "onUiEvent: " + event + ", " + request + ", " + status + ", " + data);
            uiEventCall.event = event.ordinal();
            uiEventCall.request = request;
            uiEventCall.status = status;
            uiEventCall.data = data;
        }
    };
    final ProcessorFactory factory = new ProcessorFactory() {

        @Override
        public BaseSyncProcessor create(int type, IContactSyncCallback callback, DatabaseHelper dbHelper) {
            Log.i(LOG_TAG, "create(), type=" + type);
            ProcessorLog log = new ProcessorLog();
            log.type = type;
            log.time = System.currentTimeMillis();
            processorLogs.add(log);
            return new DummySyncProcessor(mContactSyncEngine, null);
        }
    };
    minimalEngineSetup(engineEventCallback, factory);
    // set the connection to be fine
    NetworkAgent.setAgentState(NetworkAgent.AgentState.CONNECTED);
    long nextRuntime = mContactSyncEngine.getNextRunTime();
    // should be equal to -1 because first time sync has not been yet
    // started
    assertEquals(-1, mContactSyncEngine.getNextRunTime());
    // force a first time sync
    mContactSyncEngine.addUiStartFullSync();
    nextRuntime = mContactSyncEngine.getNextRunTime();
    // next runtime should be now
    assertEquals(0, nextRuntime);
    // perform the first time sync
    mContactSyncEngine.run();
    // check that first time sync is completed
    assertEquals(ServiceUiRequest.UI_REQUEST_COMPLETE.ordinal(), uiEventCall.event);
    assertEquals(uiEventCall.status, ServiceStatus.SUCCESS.ordinal());
    // check that a thumbnail sync is scheduled for now
    nextRuntime = mContactSyncEngine.getNextRunTime();
    assertEquals(0, nextRuntime);
    // reset the processor logs
    processorLogs.clear();
    // get the thumbnail sync to be run
    mContactSyncEngine.run();
    // check processor calls
    ProcessorLog log;
    assertEquals(2, processorLogs.size());
    log = processorLogs.get(0);
    assertEquals(ProcessorFactory.DOWNLOAD_SERVER_THUMBNAILS, log.type);
    log = processorLogs.get(1);
    assertEquals(ProcessorFactory.UPLOAD_SERVER_THUMBNAILS, log.type);
    // check that native sync is scheduled for now
    nextRuntime = mContactSyncEngine.getNextRunTime();
    assertEquals(0, nextRuntime);
    // reset the processor logs
    processorLogs.clear();
    // get the native sync to be run
    mContactSyncEngine.run();
    // check processor calls
    assertEquals(1, processorLogs.size());
    log = processorLogs.get(0);
    assertEquals(ProcessorFactory.UPDATE_NATIVE_CONTACTS, log.type);
    // check that nothing else is scheduled
    nextRuntime = mContactSyncEngine.getNextRunTime();
    assertEquals(-1, nextRuntime);
    /*
         * long startingTime = System.currentTimeMillis(); long duration =
         * 60000; long currentTime, timeToWait; while( (currentTime =
         * System.currentTimeMillis()) < (startingTime + duration) ) {
         * nextRuntime = mContactSyncEngine.getNextRunTime(); timeToWait =
         * nextRuntime > currentTime ? (nextRuntime-currentTime) : 0;
         * Log.e(LOG_TAG,
         * "testBackgroundSyncAfterFirstTimeSync(), timeToWait ="+timeToWait);
         * if (timeToWait > 0) { try { synchronized (this) { wait(timeToWait); }
         * } catch(Exception e) { Log.e(LOG_TAG,
         * "testBackgroundSyncAfterFirstTimeSync(), error while waiting: "+e); }
         * } Log.e(LOG_TAG,
         * "testBackgroundSyncAfterFirstTimeSync(), calling run()");
         * mContactSyncEngine.run(); }
         */
    Log.i(LOG_TAG, "**** testBackgroundSync() end ****");
}
Also used : ArrayList(java.util.ArrayList) ServiceUiRequest(com.vodafone360.people.service.ServiceUiRequest) DatabaseHelper(com.vodafone360.people.database.DatabaseHelper) ProcessorFactory(com.vodafone360.people.engine.contactsync.ProcessorFactory) IContactSyncCallback(com.vodafone360.people.engine.contactsync.IContactSyncCallback) IEngineEventCallback(com.vodafone360.people.engine.IEngineEventCallback) Suppress(android.test.suitebuilder.annotation.Suppress)

Aggregations

ServiceUiRequest (com.vodafone360.people.service.ServiceUiRequest)11 Suppress (android.test.suitebuilder.annotation.Suppress)9 DatabaseHelper (com.vodafone360.people.database.DatabaseHelper)9 IEngineEventCallback (com.vodafone360.people.engine.IEngineEventCallback)9 IContactSyncCallback (com.vodafone360.people.engine.contactsync.IContactSyncCallback)9 ProcessorFactory (com.vodafone360.people.engine.contactsync.ProcessorFactory)9 ArrayList (java.util.ArrayList)5 Bundle (android.os.Bundle)1 Handler (android.os.Handler)1 Looper (android.os.Looper)1 Message (android.os.Message)1 MessageQueue (android.os.MessageQueue)1 ChatMessage (com.vodafone360.people.datatypes.ChatMessage)1 Identity (com.vodafone360.people.datatypes.Identity)1 BaseSyncProcessor (com.vodafone360.people.engine.contactsync.BaseSyncProcessor)1 IContactSyncObserver (com.vodafone360.people.engine.contactsync.ContactSyncEngine.IContactSyncObserver)1 UiAgent (com.vodafone360.people.service.agent.UiAgent)1 DecodedResponse (com.vodafone360.people.service.io.ResponseQueue.DecodedResponse)1 Hashtable (java.util.Hashtable)1