Merge branch 'sdk28' of https://github.com/MilosKozak/AndroidAPS into sdk28
This commit is contained in:
commit
256e73dab4
4 changed files with 26 additions and 30 deletions
|
@ -2,19 +2,19 @@ language: android
|
||||||
jdk: oraclejdk8
|
jdk: oraclejdk8
|
||||||
env:
|
env:
|
||||||
matrix:
|
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:
|
android:
|
||||||
components:
|
components:
|
||||||
- platform-tools
|
- platform-tools
|
||||||
- tools
|
- tools
|
||||||
- build-tools-27.0.2
|
- build-tools-28.0.3
|
||||||
- android-23
|
- android-28
|
||||||
- extra-google-m2repository
|
- extra-google-m2repository
|
||||||
- extra-android-m2repository
|
- extra-android-m2repository
|
||||||
- extra-google-google_play_services
|
- extra-google-google_play_services
|
||||||
|
|
||||||
before_install:
|
before_install:
|
||||||
- yes | sdkmanager "platforms;android-27"
|
- yes | sdkmanager "platforms;android-28"
|
||||||
|
|
||||||
script:
|
script:
|
||||||
# Unit Test
|
# Unit Test
|
||||||
|
|
|
@ -195,8 +195,15 @@ android {
|
||||||
}
|
}
|
||||||
|
|
||||||
testOptions {
|
testOptions {
|
||||||
unitTests.returnDefaultValues = true
|
unitTests {
|
||||||
unitTests.includeAndroidResources = true
|
returnDefaultValues = true
|
||||||
|
includeAndroidResources = true
|
||||||
|
|
||||||
|
all {
|
||||||
|
maxParallelForks = 10
|
||||||
|
forkEvery = 20
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
useLibrary "org.apache.http.legacy"
|
useLibrary "org.apache.http.legacy"
|
||||||
|
|
|
@ -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.events.EventNewNotification
|
||||||
import info.nightscout.androidaps.plugins.general.overview.notifications.Notification
|
import info.nightscout.androidaps.plugins.general.overview.notifications.Notification
|
||||||
import info.nightscout.androidaps.utils.SP
|
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 org.slf4j.LoggerFactory
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
import java.io.InputStream
|
import java.net.URL
|
||||||
import java.util.concurrent.TimeUnit
|
import java.util.concurrent.TimeUnit
|
||||||
|
|
||||||
|
|
||||||
// check network connection
|
// check network connection
|
||||||
fun isConnected(): Boolean {
|
fun isConnected(): Boolean {
|
||||||
val connMgr = MainApp.instance().applicationContext.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
|
val connMgr = MainApp.instance().applicationContext.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
|
||||||
return connMgr.activeNetworkInfo?.isConnected ?: false
|
return connMgr.activeNetworkInfo?.isConnected ?: false
|
||||||
}
|
}
|
||||||
|
|
||||||
// convert inputstream to String
|
fun findVersion(file :String?): String? {
|
||||||
@Throws(IOException::class)
|
|
||||||
inline fun InputStream.findVersion(): String? {
|
|
||||||
val regex = "(.*)version(.*)\"(((\\d+)\\.)+(\\d+))\"(.*)".toRegex()
|
val regex = "(.*)version(.*)\"(((\\d+)\\.)+(\\d+))\"(.*)".toRegex()
|
||||||
return bufferedReader()
|
return file?.lines()?.filter { regex.matches(it) }?.mapNotNull { regex.matchEntire(it)?.groupValues?.getOrNull(3) }?.firstOrNull()
|
||||||
.readLines()
|
|
||||||
.filter { regex.matches(it) }
|
|
||||||
.mapNotNull { regex.matchEntire(it)?.groupValues?.getOrNull(3) }
|
|
||||||
.firstOrNull()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private val log = LoggerFactory.getLogger(L.CORE)
|
private val log = LoggerFactory.getLogger(L.CORE)
|
||||||
|
@ -39,24 +31,21 @@ private val log = LoggerFactory.getLogger(L.CORE)
|
||||||
|
|
||||||
fun triggerCheckVersion() {
|
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.
|
// 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))
|
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 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()
|
checkVersion()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("DEPRECATION")
|
|
||||||
private fun checkVersion() = if (isConnected()) {
|
private fun checkVersion() = if (isConnected()) {
|
||||||
Thread {
|
Thread {
|
||||||
try {
|
try {
|
||||||
val request = HttpGet("https://raw.githubusercontent.com/MilosKozak/AndroidAPS/master/app/build.gradle")
|
val version: String? = findVersion(URL("https://raw.githubusercontent.com/MilosKozak/AndroidAPS/master/app/build.gradle").readText())
|
||||||
val response: HttpResponse = DefaultHttpClient().execute(request)
|
|
||||||
val version: String? = response.entity.content?.findVersion()
|
|
||||||
compareWithCurrentVersion(version, BuildConfig.VERSION_NAME)
|
compareWithCurrentVersion(version, BuildConfig.VERSION_NAME)
|
||||||
} catch (e: IOException) {
|
} catch (e: IOException) {
|
||||||
log.debug("Github master version check error: $e")
|
log.debug("Github master version check error: $e")
|
||||||
|
@ -90,7 +79,7 @@ fun onVersionNotDetectable() {
|
||||||
|
|
||||||
fun onNewVersionDetected(currentVersion: String, newVersion: String?) {
|
fun onNewVersionDetected(currentVersion: String, newVersion: String?) {
|
||||||
val now = System.currentTimeMillis()
|
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")
|
log.debug("Version ${currentVersion} outdated. Found $newVersion")
|
||||||
val notification = Notification(Notification.NEWVERSIONDETECTED, String.format(MainApp.gs(R.string.versionavailable), newVersion.toString()), Notification.LOW)
|
val notification = Notification(Notification.NEWVERSIONDETECTED, String.format(MainApp.gs(R.string.versionavailable), newVersion.toString()), Notification.LOW)
|
||||||
MainApp.bus().post(EventNewNotification(notification))
|
MainApp.bus().post(EventNewNotification(notification))
|
||||||
|
|
|
@ -26,7 +26,7 @@ class VersionCheckerUtilsKtTest {
|
||||||
| version = "2.2.2"
|
| version = "2.2.2"
|
||||||
| appName = "Aaoeu"
|
| appName = "Aaoeu"
|
||||||
""".trimMargin()
|
""".trimMargin()
|
||||||
val detectedVersion: String? = buildGradle.byteInputStream().findVersion()
|
val detectedVersion: String? = findVersion(buildGradle)
|
||||||
assertEquals("2.2.2", detectedVersion)
|
assertEquals("2.2.2", detectedVersion)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,14 +41,14 @@ class VersionCheckerUtilsKtTest {
|
||||||
| version = "2.2.2-nefarious-underground-mod"
|
| version = "2.2.2-nefarious-underground-mod"
|
||||||
| appName = "Aaoeu"
|
| appName = "Aaoeu"
|
||||||
""".trimMargin()
|
""".trimMargin()
|
||||||
val detectedVersion: String? = buildGradle.byteInputStream().findVersion()
|
val detectedVersion: String? = findVersion(buildGradle)
|
||||||
assertEquals(null, detectedVersion)
|
assertEquals(null, detectedVersion)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun findVersionMatchesDoesNotMatchErrorResponse() {
|
fun findVersionMatchesDoesNotMatchErrorResponse() {
|
||||||
val buildGradle = """<html><body>Balls! No build.gradle here. Move along</body><html>"""
|
val buildGradle = """<html><body>Balls! No build.gradle here. Move along</body><html>"""
|
||||||
val detectedVersion: String? = buildGradle.byteInputStream().findVersion()
|
val detectedVersion: String? = findVersion(buildGradle)
|
||||||
assertEquals(null, detectedVersion)
|
assertEquals(null, detectedVersion)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -166,7 +166,7 @@ class VersionCheckerUtilsKtTest {
|
||||||
| appName = "Aaoeu"
|
| appName = "Aaoeu"
|
||||||
""".trimMargin()
|
""".trimMargin()
|
||||||
val bus = prepareBus()
|
val bus = prepareBus()
|
||||||
compareWithCurrentVersion(buildGradle.byteInputStream().findVersion(), currentVersion = "2.2.2")
|
compareWithCurrentVersion(findVersion(buildGradle), currentVersion = "2.2.2")
|
||||||
|
|
||||||
verify(bus, times(0)).post(any())
|
verify(bus, times(0)).post(any())
|
||||||
|
|
||||||
|
@ -186,7 +186,7 @@ class VersionCheckerUtilsKtTest {
|
||||||
| appName = "Aaoeu"
|
| appName = "Aaoeu"
|
||||||
""".trimMargin()
|
""".trimMargin()
|
||||||
val bus = prepareBus()
|
val bus = prepareBus()
|
||||||
compareWithCurrentVersion(buildGradle.byteInputStream().findVersion(), currentVersion = "2.2.2")
|
compareWithCurrentVersion(findVersion(buildGradle), currentVersion = "2.2.2")
|
||||||
|
|
||||||
verify(bus, times(1)).post(any())
|
verify(bus, times(1)).post(any())
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue