use of org.infobip.mobile.messaging.SystemData in project mobile-messaging-sdk-android by infobip.
the class AndroidBroadcasterTest method test_should_send_system_data.
@Test
public void test_should_send_system_data() throws Exception {
// Given
SystemData systemData = new SystemData("SomeSdkVersion", "SomeOsVersion", "SomeDeviceManufacturer", "SomeDeviceModel", "SomeAppVersion", false, true, true);
// When
broadcastSender.systemDataReported(systemData);
// Then
Mockito.verify(contextMock, Mockito.times(1)).sendBroadcast(intentArgumentCaptor.capture());
Intent intent = intentArgumentCaptor.getValue();
assertEquals(Event.SYSTEM_DATA_REPORTED.getKey(), intent.getAction());
SystemData systemDataAfter = SystemData.createFrom(intent.getExtras());
assertNotSame(systemData, systemDataAfter);
assertJEquals(systemData, systemDataAfter);
}
use of org.infobip.mobile.messaging.SystemData in project mobile-messaging-sdk-android by infobip.
the class SystemDataReporter method synchronize.
public void synchronize() {
SystemData systemData = mobileMessagingCore.getUnreportedSystemData();
if (systemData == null) {
return;
}
new MRetryableTask<SystemData, SystemData>() {
@Override
public SystemData run(SystemData[] systemDatas) {
if (systemDatas.length < 1 || systemDatas[0] == null) {
MobileMessagingLogger.e(InternalSdkError.ERROR_EMPTY_SYSTEM_DATA.get());
throw InternalSdkError.ERROR_EMPTY_SYSTEM_DATA.getException();
}
if (StringUtils.isBlank(mobileMessagingCore.getPushRegistrationId())) {
MobileMessagingLogger.w("Can't report system data without valid registration");
throw InternalSdkError.NO_VALID_REGISTRATION.getException();
}
SystemData data = systemDatas[0];
SystemDataReport report = from(data);
MobileMessagingLogger.v("SYSTEM DATA >>>", report);
mobileApiData.reportSystemData(report);
MobileMessagingLogger.v("SYSTEM DATA <<<");
return data;
}
@Override
public void after(SystemData systemData) {
mobileMessagingCore.setSystemDataReported();
broadcaster.systemDataReported(systemData);
}
@Override
public void error(Throwable error) {
MobileMessagingLogger.w("Error reporting system data: " + error);
mobileMessagingCore.setLastHttpException(error);
stats.reportError(MobileMessagingStatsError.SYSTEM_DATA_REPORT_ERROR);
if (!(error instanceof InternalSdkError.InternalSdkException)) {
broadcaster.error(MobileMessagingError.createFrom(error));
}
}
}.retryWith(policy).execute(executor, systemData);
}
Aggregations