use of com.vodafone360.people.service.transport.DecoderThread in project 360-Engine-for-Android by 360.
the class PollThread method startConnection.
/**
* Starts the connection.
*/
protected synchronized void startConnection(DecoderThread decoder) {
mDecoder = decoder;
setHttpClient();
mIsConnectionRunning = true;
try {
URL url = new URL(SettingsManager.getProperty(Settings.RPG_SERVER_KEY) + LoginEngine.getSession().userID);
mUrl = url.toURI();
mHeader = new RpgHeader();
mMode = ACTIVE_MODE;
Thread t = new Thread(this);
t.start();
} catch (Exception e) {
e.printStackTrace();
}
}
use of com.vodafone360.people.service.transport.DecoderThread in project 360-Engine-for-Android by 360.
the class RemoteService method onCreate.
/**
* Creation of RemoteService. Loads properties (i.e. supported features,
* server URLs etc) from SettingsManager. Creates IPeopleServiceImpl,
* NetworkAgent. Connects ConnectionManager creating Connection thread(s)
* and DecoderThread 'Kicks' worker thread.
*/
@Override
public void onCreate() {
LogUtils.logV("RemoteService.onCreate()");
SettingsManager.loadProperties(this);
mIPeopleServiceImpl = new PeopleServiceImpl(this, this);
mNetworkAgent = new NetworkAgent(this, this, this);
// Create NativeContactsApi here to access Application Context
NativeContactsApi.createInstance(getApplicationContext());
EngineManager.createEngineManager(this, mIPeopleServiceImpl);
mNetworkAgent.onCreate();
mIPeopleServiceImpl.setNetworkAgent(mNetworkAgent);
/**
* The service has now been fully initialised. *
*/
mIsStarted = true;
kickWorkerThread();
final MainApplication mainApp = (MainApplication) getApplication();
mainApp.setServiceInterface(mIPeopleServiceImpl);
if (VersionUtils.is2XPlatform()) {
mAccountsObjectsHolder = new NativeAccountObjectsHolder(((MainApplication) getApplication()));
}
final UserDataProtection userDataProtection = new UserDataProtection(this, mainApp.getDatabase());
userDataProtection.performStartupChecks();
}
use of com.vodafone360.people.service.transport.DecoderThread in project 360-Engine-for-Android by 360.
the class HeartbeatSenderThreadTest method testSendHeartbeat_valid.
@MediumTest
public void testSendHeartbeat_valid() {
byte[] header = { (byte) 0xFF, (byte) 0xFF, (byte) 0x64 };
ByteArrayOutputStream baos = new ByteArrayOutputStream();
MockTcpConnectionThread connThread = new MockTcpConnectionThread(new DecoderThread(), null);
MockHeartbeatSenderThread hbSender = new MockHeartbeatSenderThread(connThread, null, // QUICKFIX: Not sure about this value
null);
AuthSessionHolder authHolder = new AuthSessionHolder();
authHolder.userID = 007;
authHolder.sessionID = "SESS_ID";
authHolder.sessionSecret = "SESS_SECRET";
authHolder.userName = "James_Bond";
LoginEngine.setTestSession(authHolder);
hbSender.setOutputStream(baos);
try {
hbSender.sendHeartbeat();
} catch (Exception e) {
fail("sendHeartbeatTest() should not throw an Exception here " + e.toString());
}
try {
baos.flush();
baos.close();
} catch (IOException ioe) {
}
byte[] payload = baos.toByteArray();
if (null != payload) {
boolean isHeaderOk = false, isEndingOk = false, isPayloadLenOk = false;
if ((header[0] == payload[0]) && (header[1] == payload[1]) && (header[2] == payload[2])) {
isHeaderOk = true;
} else {
fail("RPG Header was malformed!");
}
if (payload[payload.length - 1] == ((byte) 0x7A)) {
isPayloadLenOk = true;
} else {
fail("Message End was malformed! Char was: " + payload[payload.length - 1]);
}
int payloadSize = byteArrayToInt(new byte[] { payload[11], payload[12], payload[13], payload[14] }, 0);
if (payloadSize == (payload.length - 16)) {
isEndingOk = true;
} else {
fail("Payload length is not okay: " + payloadSize + " vs. " + (payload.length - 16));
}
assertTrue((isHeaderOk && isEndingOk && isPayloadLenOk));
} else {
fail("HB-Payload was null!");
}
}
use of com.vodafone360.people.service.transport.DecoderThread in project 360-Engine-for-Android by 360.
the class HeartbeatSenderThreadTest method testSendHeartbeat_exception.
@MediumTest
public void testSendHeartbeat_exception() {
MockByteArrayOutputStream baos = new MockByteArrayOutputStream();
MockTcpConnectionThread connThread = new MockTcpConnectionThread(new DecoderThread(), null);
MockHeartbeatSenderThread hbSender = new MockHeartbeatSenderThread(connThread, null, // QUICKFIX: Not sure about this value
null);
AuthSessionHolder authHolder = new AuthSessionHolder();
authHolder.userID = 007;
authHolder.sessionID = "SESS_ID";
authHolder.sessionSecret = "SESS_SECRET";
authHolder.userName = "James_Bond";
LoginEngine.setTestSession(authHolder);
hbSender.setOutputStream(baos);
try {
baos.close();
} catch (IOException ioe) {
}
// IOException Test
try {
hbSender.sendHeartbeat();
} catch (IOException ioe) {
// we succeed because we expect an IOE to be thrown here!
assertTrue(true);
} catch (Exception e) {
fail("We should not have received a generic exception, but an IOException!");
}
baos = null;
// NullPointerException Test
hbSender.setOutputStream(null);
try {
hbSender.sendHeartbeat();
} catch (IOException ioe) {
fail("We should not have received an IOException, but a generic (NP-)Exception!");
} catch (Exception e) {
// we succeed because we expect an IOE to be thrown here!
assertTrue(true);
}
}
use of com.vodafone360.people.service.transport.DecoderThread in project 360-Engine-for-Android by 360.
the class HeartbeatSenderThreadTest method testStopConnection.
@Suppress
@MediumTest
public void testStopConnection() {
DataOutputStream dos = new DataOutputStream(new ByteArrayOutputStream());
MockTcpConnectionThread connThread = new MockTcpConnectionThread(new DecoderThread(), null);
MockHeartbeatSenderThread hbSender = new MockHeartbeatSenderThread(connThread, null, // QUICKFIX: Not sure about this value
null);
hbSender.setOutputStream(dos);
hbSender.startConnection();
try {
Thread.sleep(500);
} catch (Exception e) {
}
hbSender.stopConnection();
try {
Thread.sleep(1000);
} catch (Exception e) {
}
assertNotNull(hbSender.getConnectionThread());
if (null != hbSender.getConnectionThread()) {
assertFalse(hbSender.getConnectionThread().isAlive());
try {
dos.write(1);
fail("Should not be able to write here!");
} catch (IOException e) {
assertTrue(true);
}
}
}
Aggregations