From a20efab567578f697f938db7666d21648a5011a9 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Thu, 16 May 2019 19:54:35 +0200 Subject: [PATCH 1/4] remove deprecated calls --- .../versionChecker/VersionCheckerUtils.kt | 27 ++++++------------- .../VersionCheckerUtilsKtTest.kt | 10 +++---- 2 files changed, 13 insertions(+), 24 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/versionChecker/VersionCheckerUtils.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/versionChecker/VersionCheckerUtils.kt index 8791030abb..daebb5deb6 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/versionChecker/VersionCheckerUtils.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/versionChecker/VersionCheckerUtils.kt @@ -9,29 +9,21 @@ import info.nightscout.androidaps.logging.L import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification import info.nightscout.androidaps.plugins.general.overview.notifications.Notification import info.nightscout.androidaps.utils.SP -import org.apache.http.HttpResponse -import org.apache.http.client.methods.HttpGet -import org.apache.http.impl.client.DefaultHttpClient import org.slf4j.LoggerFactory import java.io.IOException -import java.io.InputStream +import java.net.URL import java.util.concurrent.TimeUnit + // check network connection fun isConnected(): Boolean { val connMgr = MainApp.instance().applicationContext.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager return connMgr.activeNetworkInfo?.isConnected ?: false } -// convert inputstream to String -@Throws(IOException::class) -inline fun InputStream.findVersion(): String? { +fun findVersion(file :String?): String? { val regex = "(.*)version(.*)\"(((\\d+)\\.)+(\\d+))\"(.*)".toRegex() - return bufferedReader() - .readLines() - .filter { regex.matches(it) } - .mapNotNull { regex.matchEntire(it)?.groupValues?.getOrNull(3) } - .firstOrNull() + return file?.lines()?.filter { regex.matches(it) }?.mapNotNull { regex.matchEntire(it)?.groupValues?.getOrNull(3) }?.firstOrNull() } private val log = LoggerFactory.getLogger(L.CORE) @@ -39,24 +31,21 @@ private val log = LoggerFactory.getLogger(L.CORE) fun triggerCheckVersion() { - if(!SP.contains(R.string.key_last_time_this_version_detected)) { + if (!SP.contains(R.string.key_last_time_this_version_detected)) { // On a new installation, set it as 30 days old in order to warn that there is a new version. SP.putLong(R.string.key_last_time_this_version_detected, System.currentTimeMillis() - TimeUnit.DAYS.toMillis(30)) } // If we are good, only check once every day. - if(System.currentTimeMillis() > SP.getLong(R.string.key_last_time_this_version_detected, 0) + CHECK_EVERY){ + if (System.currentTimeMillis() > SP.getLong(R.string.key_last_time_this_version_detected, 0) + CHECK_EVERY) { checkVersion() } } -@Suppress("DEPRECATION") private fun checkVersion() = if (isConnected()) { Thread { try { - val request = HttpGet("https://raw.githubusercontent.com/MilosKozak/AndroidAPS/master/app/build.gradle") - val response: HttpResponse = DefaultHttpClient().execute(request) - val version: String? = response.entity.content?.findVersion() + val version: String? = findVersion(URL("https://raw.githubusercontent.com/MilosKozak/AndroidAPS/master/app/build.gradle").readText()) compareWithCurrentVersion(version, BuildConfig.VERSION_NAME) } catch (e: IOException) { log.debug("Github master version check error: $e") @@ -90,7 +79,7 @@ fun onVersionNotDetectable() { fun onNewVersionDetected(currentVersion: String, newVersion: String?) { val now = System.currentTimeMillis() - if(now > SP.getLong(R.string.key_last_versionchecker_warning, 0) + WARN_EVERY) { + if (now > SP.getLong(R.string.key_last_versionchecker_warning, 0) + WARN_EVERY) { log.debug("Version ${currentVersion} outdated. Found $newVersion") val notification = Notification(Notification.NEWVERSIONDETECTED, String.format(MainApp.gs(R.string.versionavailable), newVersion.toString()), Notification.LOW) MainApp.bus().post(EventNewNotification(notification)) diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/general/versionChecker/VersionCheckerUtilsKtTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/general/versionChecker/VersionCheckerUtilsKtTest.kt index 2d07e40c1d..1e67bb2d4f 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/general/versionChecker/VersionCheckerUtilsKtTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/general/versionChecker/VersionCheckerUtilsKtTest.kt @@ -26,7 +26,7 @@ class VersionCheckerUtilsKtTest { | version = "2.2.2" | appName = "Aaoeu" """.trimMargin() - val detectedVersion: String? = buildGradle.byteInputStream().findVersion() + val detectedVersion: String? = findVersion(buildGradle) assertEquals("2.2.2", detectedVersion) } @@ -41,14 +41,14 @@ class VersionCheckerUtilsKtTest { | version = "2.2.2-nefarious-underground-mod" | appName = "Aaoeu" """.trimMargin() - val detectedVersion: String? = buildGradle.byteInputStream().findVersion() + val detectedVersion: String? = findVersion(buildGradle) assertEquals(null, detectedVersion) } @Test fun findVersionMatchesDoesNotMatchErrorResponse() { val buildGradle = """Balls! No build.gradle here. Move along""" - val detectedVersion: String? = buildGradle.byteInputStream().findVersion() + val detectedVersion: String? = findVersion(buildGradle) assertEquals(null, detectedVersion) } @@ -166,7 +166,7 @@ class VersionCheckerUtilsKtTest { | appName = "Aaoeu" """.trimMargin() val bus = prepareBus() - compareWithCurrentVersion(buildGradle.byteInputStream().findVersion(), currentVersion = "2.2.2") + compareWithCurrentVersion(findVersion(buildGradle), currentVersion = "2.2.2") verify(bus, times(0)).post(any()) @@ -186,7 +186,7 @@ class VersionCheckerUtilsKtTest { | appName = "Aaoeu" """.trimMargin() val bus = prepareBus() - compareWithCurrentVersion(buildGradle.byteInputStream().findVersion(), currentVersion = "2.2.2") + compareWithCurrentVersion(findVersion(buildGradle), currentVersion = "2.2.2") verify(bus, times(1)).post(any()) From 2d39d0be950d7a6db2ac5cc601df1e479189c3e3 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Thu, 16 May 2019 23:07:08 +0200 Subject: [PATCH 2/4] travis tools 28 --- .travis.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 5c6309f817..ec1632958e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,19 +2,19 @@ language: android jdk: oraclejdk8 env: matrix: - - ANDROID_TARGET=android-23 ANDROID_ABI=x86 org.gradle.jvmargs=-XX:-OmitStackTraceInFastThrow + - ANDROID_TARGET=android-28 ANDROID_ABI=x86 org.gradle.jvmargs=-XX:-OmitStackTraceInFastThrow android: components: - platform-tools - tools - - build-tools-27.0.2 - - android-23 + - build-tools-28.0.3 + - android-28 - extra-google-m2repository - extra-android-m2repository - extra-google-google_play_services before_install: -- yes | sdkmanager "platforms;android-27" +- yes | sdkmanager "platforms;android-28" script: # Unit Test From 0089c2ad9cfbd0d592ab38dc469dd29da4580167 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Fri, 17 May 2019 00:17:25 +0200 Subject: [PATCH 3/4] travis memory --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index ec1632958e..31d571fde4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,7 +2,7 @@ language: android jdk: oraclejdk8 env: matrix: - - ANDROID_TARGET=android-28 ANDROID_ABI=x86 org.gradle.jvmargs=-XX:-OmitStackTraceInFastThrow + - ANDROID_TARGET=android-28 ANDROID_ABI=x86 org.gradle.jvmargs=-Xmx2g -XX:-OmitStackTraceInFastThrow android: components: - platform-tools From 767276ebbb3052fddc6ee07959e417c339538ac5 Mon Sep 17 00:00:00 2001 From: triplem <160079+triplem@users.noreply.github.com> Date: Sat, 18 May 2019 09:40:06 +0200 Subject: [PATCH 4/4] fork tests --- .travis.yml | 2 +- app/build.gradle | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 31d571fde4..ec1632958e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,7 +2,7 @@ language: android jdk: oraclejdk8 env: matrix: - - ANDROID_TARGET=android-28 ANDROID_ABI=x86 org.gradle.jvmargs=-Xmx2g -XX:-OmitStackTraceInFastThrow + - ANDROID_TARGET=android-28 ANDROID_ABI=x86 org.gradle.jvmargs=-XX:-OmitStackTraceInFastThrow android: components: - platform-tools diff --git a/app/build.gradle b/app/build.gradle index 4facf2fa78..d5487c62c2 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -195,8 +195,15 @@ android { } testOptions { - unitTests.returnDefaultValues = true - unitTests.includeAndroidResources = true + unitTests { + returnDefaultValues = true + includeAndroidResources = true + + all { + maxParallelForks = 10 + forkEvery = 20 + } + } } useLibrary "org.apache.http.legacy"