Search in sources :

Example 1 with LatestReleaseResponse

use of org.infobip.mobile.messaging.api.version.LatestReleaseResponse in project mobile-messaging-sdk-android by infobip.

the class VersionChecker method sync.

public void sync() {
    if (!SoftwareInformation.isDebuggableApplicationBuild(context)) {
        return;
    }
    Long lastCheckTime = PreferenceHelper.findLong(context, MobileMessagingProperty.VERSION_CHECK_LAST_TIME);
    Integer minimumInterval = PreferenceHelper.findInt(context, MobileMessagingProperty.VERSION_CHECK_INTERVAL_DAYS);
    if (TimeUnit.MILLISECONDS.toDays(Time.now() - lastCheckTime) < minimumInterval) {
        return;
    }
    new MRetryableTask<Void, VersionCheckResult>() {

        @Override
        public VersionCheckResult run(Void[] voids) {
            MobileMessagingLogger.v("VERSION >>>");
            LatestReleaseResponse response = mobileApiVersion.getLatestRelease();
            MobileMessagingLogger.v("VERSION <<<", response);
            return new VersionCheckResult(response);
        }

        @Override
        public void after(VersionCheckResult versionCheckResult) {
            if (versionCheckResult.hasError()) {
                MobileMessagingLogger.e("MobileMessaging API returned error (version check)!");
                stats.reportError(MobileMessagingStatsError.VERSION_CHECK_ERROR);
                return;
            }
            String current = SoftwareInformation.getSDKVersion();
            if (shouldUpdate(versionCheckResult.getVersion(), current)) {
                MobileMessagingLogger.w(TAG, "Your library version is outdated, find latest release " + versionCheckResult.getVersion() + " here: " + versionCheckResult.getUpdateUrl());
            }
            PreferenceHelper.saveLong(context, MobileMessagingProperty.VERSION_CHECK_LAST_TIME, Time.now());
        }

        @Override
        public void error(Throwable error) {
            mobileMessagingCore.setLastHttpException(error);
            MobileMessagingLogger.e("Error while checking version!");
            stats.reportError(MobileMessagingStatsError.VERSION_CHECK_ERROR);
        }
    }.retryWith(retryPolicyProvider.ONE_RETRY()).execute();
}
Also used : LatestReleaseResponse(org.infobip.mobile.messaging.api.version.LatestReleaseResponse) MRetryableTask(org.infobip.mobile.messaging.mobile.common.MRetryableTask)

Example 2 with LatestReleaseResponse

use of org.infobip.mobile.messaging.api.version.LatestReleaseResponse in project mobile-messaging-sdk-android by infobip.

the class MobileApiVersionTest method create_success.

@Test
public void create_success() throws Exception {
    debugServer.respondWith(NanoHTTPD.Response.Status.OK, DefaultApiClient.JSON_SERIALIZER.serialize(new LatestReleaseResponse("GCM", "3.2.1", "www")));
    LatestReleaseResponse response = mobileApiVersion.getLatestRelease();
    // inspect http context
    assertEquals("/mobile/3/version", debugServer.getUri());
    assertEquals(1, debugServer.getRequestCount());
    assertEquals(NanoHTTPD.Method.GET, debugServer.getRequestMethod());
    assertEquals("App my_API_key", debugServer.getHeader("Authorization"));
    assertNull(debugServer.getBody());
    // inspect response
    assertEquals("GCM", response.getPlatformType());
    assertEquals("3.2.1", response.getLibraryVersion());
    assertEquals("www", response.getUpdateUrl());
}
Also used : LatestReleaseResponse(org.infobip.mobile.messaging.api.version.LatestReleaseResponse) Test(org.junit.Test)

Aggregations

LatestReleaseResponse (org.infobip.mobile.messaging.api.version.LatestReleaseResponse)2 MRetryableTask (org.infobip.mobile.messaging.mobile.common.MRetryableTask)1 Test (org.junit.Test)1