Skip to content

Commit

Permalink
Change updater support check on Android to verify app signature
Browse files Browse the repository at this point in the history
  • Loading branch information
zacharee committed Aug 13, 2024
1 parent 5c80259 commit dbd5ab6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
3 changes: 3 additions & 0 deletions android/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,7 @@ android {
isMinifyEnabled = false
}
}
buildFeatures {
buildConfig = true
}
}
3 changes: 3 additions & 0 deletions common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,9 @@ android {
lint {
abortOnError = false
}
buildFeatures {
buildConfig = true
}

dependencies {
coreLibraryDesugaring(libs.desugar.jdk.libs)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package dev.zwander.common.util

import android.content.Intent
import android.os.Build
import android.content.pm.PackageManager
import androidx.core.content.FileProvider
import dev.zwander.common.App
import dev.zwander.common.GradleConfig
Expand All @@ -14,6 +14,7 @@ import io.ktor.http.HttpMethod
import io.ktor.util.cio.use
import io.ktor.util.cio.writeChannel
import io.ktor.utils.io.copyTo
import korlibs.crypto.sha256
import org.kohsuke.github.GitHub
import java.io.File

Expand Down Expand Up @@ -75,11 +76,15 @@ actual object UpdateUtil {
}
}

@Suppress("DEPRECATION")
actual fun supported(): Boolean {
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
App.instance.packageManager.getInstallSourceInfo(App.instance.packageName).installingPackageName
} else {
App.instance.packageManager.getInstallerPackageName(App.instance.packageName)
} != "com.android.vending"
val githubSha256 = "58997A7C334D76DCD57FAA918DDA90DA27EDA2E768AED4EB7F110D90C3196D67"
val signatures = App.instance.packageManager
.getPackageInfo(App.instance.packageName, PackageManager.GET_SIGNATURES).signatures
val matchesSignature = signatures.any { signature ->
signature.toByteArray().sha256().hexUpper == githubSha256
}

return matchesSignature || dev.zwander.common.BuildConfig.DEBUG
}
}

0 comments on commit dbd5ab6

Please sign in to comment.