mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-20 21:35:59 +00:00
About 650 user-facing strings were written in Kotlin and Java, so no translation could reach them and the UI stayed half English in every language. They now live in values/strings.xml. - Dialogs, menus, status lines, toasts and errors shown to the user go through getString/stringResource. - Code that matched on English text now uses IDs: installer and loading stages, Decky stages, storage labels and the Back button's order labels. - Choice lists (upscalers, FPS limits, textures, themes, presets) carry @StringRes labels instead of English. - Robolectric tests read the app's resources (includeAndroidResources). - Six strings nothing used any more are dropped. Existing translations are untouched; the new strings show in English until they are translated.
This commit is contained in:
1 parent
1951d8bfde
commit
0b04678bdc
76 files changed
+2150
-919
No files matched your search
@@ -4,6 +4,7 @@ import android.content.Context
|
||||
import android.content.pm.PackageManager
|
||||
import android.os.Build
|
||||
import com.droiddeck.launcher.BuildConfig
|
||||
import com.droiddeck.launcher.R
|
||||
import org.json.JSONArray
|
||||
import org.json.JSONObject
|
||||
import java.io.IOException
|
||||
@@ -195,13 +196,17 @@ object AppUpdates {
|
||||
}
|
||||
|
||||
/** Why Android cannot install this published build over [me], before downloading anything. */
|
||||
fun installBlock(r: Release, me: Installed = installed()): String? = when {
|
||||
r.apk == null -> "This build has no download for this copy of DroidDeck."
|
||||
r.apk.versionCode < me.versionCode ->
|
||||
"Android won't install it over this build because its versionCode ${r.apk.versionCode} is below the installed ${me.versionCode}."
|
||||
fun installBlock(r: Release, me: Installed = installed()): InstallBlock? = when {
|
||||
r.apk == null -> InstallBlock(R.string.upd_block_no_apk)
|
||||
r.apk.versionCode < me.versionCode -> InstallBlock(R.string.upd_block_version_code, r.apk.versionCode, me.versionCode)
|
||||
else -> null
|
||||
}
|
||||
|
||||
/** Why Android would refuse a build, as a line for the user. */
|
||||
class InstallBlock(@androidx.annotation.StringRes val text: Int, private vararg val args: Any) {
|
||||
fun message(context: Context): String = context.getString(text, *args)
|
||||
}
|
||||
|
||||
fun follow(context: Context, catalog: Catalog?): Follow {
|
||||
stored(context)?.let { return it }
|
||||
val me = installed()
|
||||
@@ -243,11 +248,13 @@ object AppUpdates {
|
||||
/** One static request, rather than several unauthenticated GitHub API requests. */
|
||||
fun refresh(context: Context): Catalog {
|
||||
val checkedAt = System.currentTimeMillis()
|
||||
val catalog = readPublishedCatalog(
|
||||
JSONObject(get("$CATALOG_URL?checked=$checkedAt")),
|
||||
context.packageName,
|
||||
checkedAt,
|
||||
)
|
||||
val published = JSONObject(get(context, "$CATALOG_URL?checked=$checkedAt"))
|
||||
// Its checks say why in English; the user gets that inside a sentence in the app's language.
|
||||
val catalog = try {
|
||||
readPublishedCatalog(published, context.packageName, checkedAt)
|
||||
} catch (e: IOException) {
|
||||
throw IOException(context.getString(R.string.appupd_catalog_rejected, e.message), e)
|
||||
}
|
||||
prefs(context).edit().putString(KEY_CATALOG, writeCatalog(catalog).toString()).apply()
|
||||
return catalog
|
||||
}
|
||||
@@ -358,7 +365,7 @@ object AppUpdates {
|
||||
return 0
|
||||
}
|
||||
|
||||
private fun get(url: String): String {
|
||||
private fun get(context: Context, url: String): String {
|
||||
val c = URL(url).openConnection() as HttpURLConnection
|
||||
c.connectTimeout = 15_000
|
||||
c.readTimeout = 20_000
|
||||
@@ -367,7 +374,7 @@ object AppUpdates {
|
||||
c.setRequestProperty("Cache-Control", "no-cache")
|
||||
try {
|
||||
val code = c.responseCode
|
||||
if (code != 200) throw IOException("The update catalog answered HTTP $code")
|
||||
if (code != 200) throw IOException(context.getString(R.string.appupd_http, code))
|
||||
return c.inputStream.bufferedReader().use { it.readText() }
|
||||
} finally {
|
||||
c.disconnect()
|
||||
|
||||
@@ -9,6 +9,7 @@ import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.provider.Settings
|
||||
import com.droiddeck.launcher.BuildConfig
|
||||
import com.droiddeck.launcher.R
|
||||
import com.droiddeck.launcher.core.FileUtils
|
||||
import com.droiddeck.launcher.core.Hashes
|
||||
import java.io.File
|
||||
@@ -46,7 +47,7 @@ object SelfInstaller {
|
||||
c.setRequestProperty("User-Agent", "DroidDeck-app")
|
||||
c.instanceFollowRedirects = true
|
||||
try {
|
||||
if (c.responseCode != 200) throw IOException("The download answered HTTP ${c.responseCode}")
|
||||
if (c.responseCode != 200) throw IOException(context.getString(R.string.selfinst_http, c.responseCode))
|
||||
val total = c.contentLengthLong.takeIf { it > 0 } ?: apk.size
|
||||
c.inputStream.use { input ->
|
||||
FileOutputStream(target).use { out ->
|
||||
@@ -64,10 +65,10 @@ object SelfInstaller {
|
||||
}
|
||||
}
|
||||
if (apk.size > 0 && target.length() != apk.size) {
|
||||
throw IOException("The download size didn't match the published APK and was discarded - try again")
|
||||
throw IOException(context.getString(R.string.selfinst_size_mismatch))
|
||||
}
|
||||
if (!apk.sha256.equals(Hashes.sha256(target), ignoreCase = true)) {
|
||||
throw IOException("The download didn't match its checksum and was discarded - try again")
|
||||
throw IOException(context.getString(R.string.selfinst_checksum_mismatch))
|
||||
}
|
||||
validateDownloaded(context, target, apk)
|
||||
return target
|
||||
@@ -82,10 +83,10 @@ object SelfInstaller {
|
||||
/** Inspect the actual downloaded APK before giving it to Android's installer. */
|
||||
private fun validateDownloaded(context: Context, file: File, apk: AppUpdates.Apk) {
|
||||
if (apk.packageName != context.packageName) {
|
||||
throw IOException("The update is for Android package ${apk.packageName}, not ${context.packageName}")
|
||||
throw IOException(context.getString(R.string.selfinst_wrong_package, apk.packageName, context.packageName))
|
||||
}
|
||||
if (!apk.signerSha256.equals(BuildConfig.RELEASE_SIGNER, ignoreCase = true)) {
|
||||
throw IOException("The update metadata doesn't name DroidDeck's release signing key")
|
||||
throw IOException(context.getString(R.string.selfinst_metadata_signer))
|
||||
}
|
||||
@Suppress("DEPRECATION")
|
||||
val flags = if (Build.VERSION.SDK_INT >= 28) {
|
||||
@@ -94,29 +95,29 @@ object SelfInstaller {
|
||||
PackageManager.GET_SIGNATURES
|
||||
}
|
||||
val info = context.packageManager.getPackageArchiveInfo(file.absolutePath, flags)
|
||||
?: throw IOException("Android couldn't read the downloaded APK")
|
||||
?: throw IOException(context.getString(R.string.selfinst_unreadable))
|
||||
if (info.packageName != context.packageName) {
|
||||
throw IOException("The downloaded APK is for ${info.packageName}, not ${context.packageName}")
|
||||
throw IOException(context.getString(R.string.selfinst_apk_wrong_package, info.packageName, context.packageName))
|
||||
}
|
||||
@Suppress("DEPRECATION")
|
||||
val code = if (Build.VERSION.SDK_INT >= 28) info.longVersionCode else info.versionCode.toLong()
|
||||
if (code != apk.versionCode.toLong()) {
|
||||
throw IOException("The downloaded APK says versionCode $code, not the published ${apk.versionCode}")
|
||||
throw IOException(context.getString(R.string.selfinst_version_mismatch, code, apk.versionCode))
|
||||
}
|
||||
if (code < BuildConfig.VERSION_CODE.toLong()) {
|
||||
throw IOException("Android won't install versionCode $code over the installed ${BuildConfig.VERSION_CODE}")
|
||||
throw IOException(context.getString(R.string.selfinst_downgrade, code, BuildConfig.VERSION_CODE))
|
||||
}
|
||||
|
||||
// Before Android 9 this lineage intentionally presents the public legacy test key. Android
|
||||
// 9+ understands the v3 hand-over and must see DroidDeck's private release key as current.
|
||||
if (Build.VERSION.SDK_INT >= 28) {
|
||||
val signing = info.signingInfo ?: throw IOException("The downloaded APK has no signing information")
|
||||
val signing = info.signingInfo ?: throw IOException(context.getString(R.string.selfinst_no_signing))
|
||||
val digests = signing.apkContentsSigners.orEmpty().map { cert ->
|
||||
MessageDigest.getInstance("SHA-256").digest(cert.toByteArray())
|
||||
.joinToString("") { "%02x".format(it) }
|
||||
}
|
||||
if (digests.none { it.equals(BuildConfig.RELEASE_SIGNER, ignoreCase = true) }) {
|
||||
throw IOException("The downloaded APK isn't signed with DroidDeck's release key")
|
||||
throw IOException(context.getString(R.string.selfinst_wrong_signer))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -145,13 +146,12 @@ object SelfInstaller {
|
||||
}
|
||||
|
||||
/** What went wrong, in words for the user, from PackageInstaller's status and message. */
|
||||
fun describeFailure(status: Int, message: String?): String = when {
|
||||
message?.contains("VERSION_DOWNGRADE") == true ->
|
||||
"Android won't install an older version over a newer one. Stay on this build until the channel catches up."
|
||||
fun describeFailure(context: Context, status: Int, message: String?): String = when {
|
||||
message?.contains("VERSION_DOWNGRADE") == true -> context.getString(R.string.upd_fail_downgrade)
|
||||
status == PackageInstaller.STATUS_FAILURE_CONFLICT || message?.contains("UPDATE_INCOMPATIBLE") == true ->
|
||||
"This copy of DroidDeck is signed differently (a local build?), so Android won't update it in place."
|
||||
status == PackageInstaller.STATUS_FAILURE_STORAGE -> "There isn't enough free space for the update."
|
||||
status == PackageInstaller.STATUS_FAILURE_ABORTED -> "The update was cancelled."
|
||||
else -> "The update didn't install" + (message?.let { ": $it" } ?: ".")
|
||||
context.getString(R.string.upd_fail_signature)
|
||||
status == PackageInstaller.STATUS_FAILURE_STORAGE -> context.getString(R.string.upd_fail_storage)
|
||||
status == PackageInstaller.STATUS_FAILURE_ABORTED -> context.getString(R.string.upd_fail_aborted)
|
||||
else -> message?.let { context.getString(R.string.upd_fail_with_message, it) } ?: context.getString(R.string.upd_fail_generic)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user