use of com.vodafone360.people.service.io.Request in project 360-Engine-for-Android by 360.
the class LoginEngine method handleNewPublicKeyResponse.
/**
* Called when a response to the server fetch public key request is
* received. Validates the response and stores the new public key details.
*
* @param mDataTypes Response data from server.
*/
private void handleNewPublicKeyResponse(List<BaseDataType> mDataTypes) {
LogUtils.logD("LoginEngine.handleNewPublicKeyResponse()");
ServiceStatus errorStatus = getResponseStatus(BaseDataType.PUBLIC_KEY_DETAILS_DATA_TYPE, mDataTypes);
if (errorStatus == ServiceStatus.SUCCESS) {
LogUtils.logD("LoginEngine.handleNewPublicKeyResponse() - Succesfully retrieved");
// AA
// 1. save to DB; save the flag that we aren't using default and
// have to use one from DB
// 2. start registration again
mPublicKey = (PublicKeyDetails) mDataTypes.get(0);
// done in startRegistrationProcessCrypted already
// mDb.modifyCredentialsAndPublicKey(mLoginDetails, mPublicKey);
startRegistrationProcessCrypted(mRegistrationDetails);
} else {
completeUiRequest(errorStatus, null);
}
}
use of com.vodafone360.people.service.io.Request in project 360-Engine-for-Android by 360.
the class LoginEngine method onReset.
/**
* Called by the framework before a remove user data operation takes place.
* Initiates a suitable UI request which will kick the worker thread.
*/
@Override
public void onReset() {
// reset the engine as if it was just created
super.onReset();
setRegistrationComplete(false);
mState = State.NOT_REGISTERED;
mRegistrationDetails = new RegistrationDetails();
mActivationCode = null;
onLoginStateChanged(false);
}
use of com.vodafone360.people.service.io.Request in project 360-Engine-for-Android by 360.
the class TimeOutWatcherTest method createRequestWithTimeout.
// //////////////////
// HELPER METHODS //
// //////////////////
/**
* Creates a request for the "undefined" engine.
* @param timeout the timeout for the request in milliseconds
*/
private Request createRequestWithTimeout(long timeout) {
final Request request = new Request("", Type.PRESENCE_LIST, EngineId.UNDEFINED, false, timeout);
request.setActive(true);
return request;
}
use of com.vodafone360.people.service.io.Request in project 360-Engine-for-Android by 360.
the class TimeOutWatcherTest method testThrowingTimeout.
/**
* Tests that a timeout error is thrown if the response of the request has not been received after the timeout period.
*/
@Suppress
public void testThrowingTimeout() {
Log.i("testThrowingTimeout()", "-begin");
final Request request = createRequestWithTimeout(TIMEOUT_2000_MS);
// check that the response queue is empty for the engine with EngineId.UNDEFINED id (we use this one for the test)
DecodedResponse response = ResponseQueue.getInstance().getNextResponse(EngineId.UNDEFINED);
assertNull(response);
// adding the request to the queue should add it to the TimeOutWatcher
final int reqId = QueueManager.getInstance().addRequest(request);
// check that the response queue is still empty
response = ResponseQueue.getInstance().getNextResponse(EngineId.UNDEFINED);
assertNull(response);
// let's give at least 2 times the timeout to the system before checking
long stopTime = System.currentTimeMillis() + (TIMEOUT_2000_MS * 2);
while (System.currentTimeMillis() < stopTime) {
try {
Thread.sleep(TIMEOUT_2000_MS);
} catch (InterruptedException ie) {
Log.i("testThrowingTimeout()", "Error while sleeping: " + ie);
}
}
// check that the response is still empty
response = ResponseQueue.getInstance().getNextResponse(EngineId.UNDEFINED);
assertNotNull(response);
// check response request id is the same as the request id
assertEquals(reqId, response.mReqId.intValue());
// check the timeout error returned is as expected
assertNotNull(response.mDataTypes);
assertEquals(1, response.mDataTypes.size());
BaseDataType error = response.mDataTypes.get(0);
assertTrue(error instanceof ServerError);
ServerError srvError = (ServerError) error;
assertEquals(ServerError.ErrorType.REQUEST_TIMEOUT, srvError.getType());
Log.i("testThrowingTimeout()", "-end");
}
use of com.vodafone360.people.service.io.Request 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