Skip to content

Commit

Permalink
Hash Check
Browse files Browse the repository at this point in the history
  • Loading branch information
AkosPaha01 committed Mar 26, 2023
1 parent e91a4cd commit 4405b59
Show file tree
Hide file tree
Showing 13 changed files with 44 additions and 1,802 deletions.
2 changes: 1 addition & 1 deletion .idea/kotlinc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 9 additions & 9 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ plugins {
id("com.google.gms.google-services")
kotlin("android")
kotlin("kapt")
id("com.google.devtools.ksp") version("1.8.20-RC-1.0.9")
id("com.google.devtools.ksp") version("1.8.20-RC2-1.0.9")
}

val libsuVersion = "5.0.4"
Expand All @@ -24,7 +24,7 @@ android {
applicationId = "de.dertyp7214.rboardthememanager"
minSdk = 23
targetSdk = 33
versionCode = 376400
versionCode = 376500
versionName = "3.7.6"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
Expand Down Expand Up @@ -80,14 +80,13 @@ dependencies {
implementation(project(":mathc"))
implementation(project(":rboardcomponents"))

implementation(platform("com.google.firebase:firebase-bom:31.2.3"))
implementation(platform("com.google.firebase:firebase-bom:31.3.0"))
implementation("com.google.firebase:firebase-messaging-ktx:23.1.2")
implementation("com.google.firebase:firebase-analytics-ktx:21.2.0")
implementation("com.google.firebase:firebase-analytics-ktx:21.2.1")

implementation("com.github.DerTyp7214:PreferencesPlus:1.0")

implementation("com.google.protobuf:protobuf-kotlin:3.22.0")
implementation("com.google.protobuf:protobuf-java:3.22.0")
implementation("com.github.os72:protobuf-dynamic:1.0.1")

implementation("androidx.legacy:legacy-support-v4:1.0.0")
implementation("androidx.navigation:navigation-fragment-ktx:2.6.0-alpha08")
Expand All @@ -100,17 +99,18 @@ dependencies {
implementation("dev.chrisbanes.insetter:insetter:0.6.1")
implementation("androidx.core:core-ktx:1.12.0-alpha01")
//noinspection DifferentStdlibGradleVersion
implementation("org.jetbrains.kotlin:kotlin-stdlib:1.8.20-RC")
implementation("org.jetbrains.kotlin:kotlin-stdlib:1.8.20-RC2")
implementation("androidx.core:core:1.12.0-alpha01")
implementation("com.google.android.material:material:1.9.0-beta01")
implementation("androidx.constraintlayout:constraintlayout:2.2.0-alpha09")
implementation("androidx.preference:preference-ktx:1.2.0")
implementation("androidx.activity:activity-ktx:1.8.0-alpha02")
implementation("androidx.fragment:fragment-ktx:1.6.0-alpha08")
implementation("com.jaredrummler:android-shell:1.0.0")
implementation("com.google.firebase:firebase-analytics:21.2.0")
implementation("com.google.firebase:firebase-analytics:21.2.1")
implementation("com.google.firebase:firebase-messaging:23.1.2")
implementation("com.google.code.gson:gson:2.10.1")
implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.1")
implementation("com.bignerdranch.android:simple-item-decoration:1.0.0")
implementation("de.dertyp7214:PRDownloader:v0.6.0")
implementation("com.github.skydoves:balloon:1.5.3-SNAPSHOT")
Expand All @@ -125,5 +125,5 @@ dependencies {
implementation(fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar", "*.aar"))))

debugImplementation("androidx.compose.ui:ui-tooling:1.5.0-alpha01")
implementation("org.jetbrains.kotlin:kotlin-reflect:1.8.20-RC")
implementation("org.jetbrains.kotlin:kotlin-reflect:1.8.20-RC2")
}
2 changes: 2 additions & 0 deletions app/src/main/java/de/dertyp7214/rboardthememanager/Config.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ object Config {
var GITLAB_RAW_PREFIX = "https://gitlab.com/dertyp7214/RboardMirror/-/raw/main/PackRepoBeta"
var GITHUB_RAW_PREFIX = "https://github.com/GboardThemes/PackRepoBeta/raw/main"

var PROTO_FILE = "https://raw.githubusercontent.com/GboardThemes/PackRepoBeta/main/proto/list.proto"

var REPO_PREFIX = GITHUB_REPO_PREFIX
var RAW_PREFIX = GITHUB_RAW_PREFIX

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class NewsFeedAdapter(
holder.author.text = "by ${item.author}"

holder.card.setOnClickListener {
onCardClicked(ThemePack(item.author, item.url, item.title, listOf()))
onCardClicked(ThemePack(item.author, "", item.url, item.title, listOf()))
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package de.dertyp7214.rboardthememanager.adapter

import android.annotation.SuppressLint
import android.app.Activity
import androidx.fragment.app.FragmentActivity
import android.content.Intent
import android.text.TextUtils
import android.view.LayoutInflater
Expand All @@ -20,7 +20,7 @@ import de.dertyp7214.rboardthememanager.Config

class ThemePackAdapter(
private val list: List<ThemePack>,
private val activity: Activity,
private val activity: FragmentActivity,
private val resultLauncher: ActivityResultLauncher<Intent>
) :
RecyclerView.Adapter<RecyclerView.ViewHolder>() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import de.dertyp7214.rboardthememanager.data.ModuleMeta
import java.io.File
import java.io.InputStream
import kotlin.text.Charsets.UTF_8
import java.security.MessageDigest

fun File.parseModuleMeta(): ModuleMeta {
val text = SuFileInputStream.open(this).readBytes().toString(UTF_8)
Expand Down Expand Up @@ -69,4 +70,6 @@ fun File.share(
)
)
}
}
}
fun File.hash(): String = MessageDigest.getInstance("SHA-256").digest(readBytes())
.joinToString("") { "%02x".format(it) }
17 changes: 0 additions & 17 deletions app/src/main/java/de/dertyp7214/rboardthememanager/core/List.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package de.dertyp7214.rboardthememanager.core

import de.dertyp7214.rboardthememanager.data.ThemePack
import de.dertyp7214.rboardthememanager.proto.ThemePackList

operator fun <E> List<E>.times(times: Int): ArrayList<E> {
val list = ArrayList(this)
for (i in 0..times) list.addAll(this)
Expand All @@ -25,18 +22,4 @@ fun List<String>.toMap(): Map<String, Boolean> {
val str = it.removePrefix("true:").removePrefix("false:")
Pair(str, bool)
}
}

fun List<ThemePackList.Object>.toPackList() = map { pack ->
ThemePack(
pack.getAuthor(),
pack.getUrl(),
pack.getName(),
pack.getTagsList() ?: listOf(),
pack.getThemesList(),
pack.getSize(),
pack.getDescription(),
false,
pack.getDate()
)
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package de.dertyp7214.rboardthememanager.core

import android.app.Activity
import androidx.fragment.app.FragmentActivity
import com.downloader.Error
import com.downloader.OnDownloadListener
import com.downloader.PRDownloader
Expand All @@ -13,7 +13,7 @@ import de.dertyp7214.rboardthememanager.data.ThemePack
import de.dertyp7214.rboardthememanager.utils.ZipHelper
import java.io.File

fun ThemePack.download(activity: Activity, result: (themes: List<String>) -> Unit) {
fun ThemePack.download(activity: FragmentActivity, result: (themes: List<String>) -> Unit) {
val dialog = activity.openLoadingDialog(R.string.downloading_pack)
val name = name.replace(" ", "_")
Logger.log(Logger.Companion.Type.DEBUG, "Download", "Downloading $url ${url.let {
Expand All @@ -28,6 +28,17 @@ fun ThemePack.download(activity: Activity, result: (themes: List<String>) -> Uni
.start(object : OnDownloadListener {
override fun onDownloadComplete() {
val pack = File(activity.cacheDir, "$name.pack")
if (this@download.hash != null && pack.hash() != this@download.hash) {
dialog.dismiss()
result(listOf())

activity.openDialog(R.string.error, R.string.hash_mismatch, negative = null) {
it.dismiss()
}

return
}

val destination = SuFile(activity.cacheDir, name)
dialog.dismiss()
if (ZipHelper().unpackZip(destination.absolutePath, pack.absolutePath)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import de.dertyp7214.rboardthememanager.core.RepoUrl
data class ThemePack(
val author: String,
val url: String,
val hash: String? = null,
@SerializedName(value = "title", alternate = ["name"])
val name: String,
val tags: List<String>,
Expand All @@ -30,6 +31,7 @@ data class ThemePack(

if (author != other.author) return false
if (url != other.url) return false
if (hash != other.hash) return false
if (name != other.name) return false
if (tags != other.tags) return false
if (themes != other.themes) return false
Expand All @@ -42,6 +44,6 @@ data class ThemePack(
}

companion object {
val NONE = ThemePack("", "", "", listOf(), listOf(), 0, null, true)
val NONE = ThemePack("", "", "", "", listOf(), listOf(), 0, null, true)
}
}
Loading

0 comments on commit 4405b59

Please sign in to comment.