Verified Commit f20d966f authored by Marvin W.'s avatar Marvin W. 🐿

Mapbox: Add version stamp file to cached native library

Fixes #1321
parent 85e06675
......@@ -20,6 +20,7 @@ apply plugin: 'kotlin-android-extensions'
dependencies {
implementation project(':play-services-api')
implementation project(':play-services-base-core')
implementation("com.mapbox.mapboxsdk:mapbox-android-sdk:9.2.1") {
exclude group: 'com.mapbox.mapboxsdk', module: 'mapbox-android-accounts'
}
......
......@@ -21,6 +21,8 @@ import android.content.Context
import android.content.pm.ApplicationInfo
import android.util.Log
import com.mapbox.mapboxsdk.LibraryLoader
import org.microg.gms.common.Constants
import org.microg.gms.common.PackageUtils
import java.io.*
import java.util.zip.ZipFile
......@@ -36,9 +38,12 @@ class MultiArchLoader(private val mapContext: Context, private val appContext: C
if (primaryCpuAbi != null) {
val path = "lib/$primaryCpuAbi/lib$name.so"
val cacheFile = File("${appContext.cacheDir.absolutePath}/.gmscore/$path")
cacheFile.parentFile.mkdirs()
cacheFile.parentFile?.mkdirs()
val cacheFileStamp = File("${appContext.cacheDir.absolutePath}/.gmscore/$path.stamp")
val cacheVersion = kotlin.runCatching { cacheFileStamp.readText().toInt() }.getOrNull()
val mapVersion = PackageUtils.versionCode(mapContext, Constants.GMS_PACKAGE_NAME)
val apkFile = File(mapContext.packageCodePath)
if (!cacheFile.exists() || cacheFile.lastModified() < apkFile.lastModified()) {
if (!cacheFile.exists() || cacheVersion == null || cacheVersion != mapVersion) {
val zipFile = ZipFile(apkFile)
val entry = zipFile.getEntry(path)
if (entry != null) {
......@@ -46,6 +51,7 @@ class MultiArchLoader(private val mapContext: Context, private val appContext: C
} else {
Log.d(TAG, "Can't load native library: $path does not exist in $apkFile")
}
cacheFileStamp.writeText(mapVersion.toString())
}
Log.d(TAG, "Loading $name from ${cacheFile.getPath()}")
System.load(cacheFile.absolutePath)
......@@ -75,4 +81,4 @@ class MultiArchLoader(private val mapContext: Context, private val appContext: C
private val TAG = "GmsMultiArchLoader"
}
}
\ No newline at end of file
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment