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
}
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;
}
}
use of com.vodafone360.people.service.ServiceUiRequest in project 360-Engine-for-Android by 360.
the class PresenceEngine method processUiRequest.
@Override
protected void processUiRequest(ServiceUiRequest requestId, Object data) {
if (!isFirstTimeSyncComplete()) {
LogUtils.logE("PresenceEngine.processUIRequest():" + " Can't run PresenceEngine before the contact list is downloaded:1");
return;
}
LogUtils.logW("PresenceEngine.processUiRequest() requestId.name[" + requestId.name() + "]");
if (data == null && requestId != ServiceUiRequest.GET_PRESENCE_LIST) {
LogUtils.logW("PresenceEngine.processUiRequest() skipping processing for request with no data!");
return;
}
switch(requestId) {
case SET_MY_AVAILABILITY:
Hashtable<String, String> presenceHash = (Hashtable<String, String>) data;
notifyUiAgentOfRequest(Presence.setMyAvailability(presenceHash), presenceHash);
break;
case GET_PRESENCE_LIST:
Presence.getPresenceList(EngineId.PRESENCE_ENGINE, null);
break;
case CREATE_CONVERSATION:
List<String> tos = ((ChatMessage) data).getTos();
LogUtils.logW("PresenceEngine processUiRequest() CREATE_CONVERSATION with: " + tos);
Chat.startChat(tos);
break;
case SEND_CHAT_MESSAGE:
ChatMessage msg = (ChatMessage) data;
updateChatDatabase(msg, TimelineSummaryItem.Type.OUTGOING);
//cache the message (necessary for failed message sending failures)
mSendMessagesHash.put(msg.getTos().get(0), msg);
Chat.sendChatMessage(msg);
break;
default:
LogUtils.logE("PresenceEngine processUiRequest() Unhandled UI request [" + requestId.name() + "]");
// don't complete with success and schedule the next runtime
return;
}
completeUiRequest(ServiceStatus.SUCCESS, null);
setTimeout(CHECK_FREQUENCY);
}
use of com.vodafone360.people.service.ServiceUiRequest in project 360-Engine-for-Android by 360.
the class ContactSyncEngine method 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!
*/
private void clearCurrentSyncAndPatchBaseEngine() {
// Cancel background sync
if (mActiveProcessor != null) {
// the mActiveUiRequest is already the new one so if
// onCompleteUiRequest(Error) is called,
// this will reset it to null even if we didn't start to process it.
ServiceUiRequest newActiveUiRequest = mActiveUiRequest;
mActiveUiRequest = mActiveUiRequestBackup;
mActiveProcessor.cancel();
// cancelSync();
// restore the active UI request...
mActiveUiRequest = newActiveUiRequest;
mActiveProcessor = null;
}
newState(State.IDLE);
}
use of com.vodafone360.people.service.ServiceUiRequest in project 360-Engine-for-Android by 360.
the class ContactSyncEngineTest method testUiRequestCompleteEvent_fullSync.
/**
* Verifies that events are fired after UI requests.
*/
@Suppress
public // Breaks tests.
void testUiRequestCompleteEvent_fullSync() {
Log.i(LOG_TAG, "**** testUiRequestCompleteEvent_fullSync() begin ****");
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);
return new DummySyncProcessor(mContactSyncEngine, null);
}
};
minimalEngineSetup(engineEventCallback, factory);
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);
// set the connection to be fine
NetworkAgent.setAgentState(AgentState.CONNECTED);
// ask for a full sync
mContactSyncEngine.addUiStartFullSync();
nextRuntime = mContactSyncEngine.getNextRunTime();
assertEquals(0, nextRuntime);
mContactSyncEngine.run();
// check that first time sync is completed
assertEquals(ServiceUiRequest.UI_REQUEST_COMPLETE.ordinal(), uiEventCall.event);
assertEquals(uiEventCall.status, ServiceStatus.SUCCESS.ordinal());
Log.i(LOG_TAG, "**** testUiRequestCompleteEvent_fullSync() end ****");
}
Aggregations