Skip to content
This repository was archived by the owner on Sep 12, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ package com.github.capntrips.kernelflasher.ui.screens.main

import android.annotation.SuppressLint
import android.content.Context
import android.content.res.Resources
import android.util.Log
import android.widget.Toast
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.mutableStateOf
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import androidx.navigation.NavController
import com.github.capntrips.kernelflasher.R
import com.github.capntrips.kernelflasher.common.PartitionUtil
import com.github.capntrips.kernelflasher.common.types.backups.Backup
import com.github.capntrips.kernelflasher.ui.screens.backups.BackupsViewModel
Expand Down Expand Up @@ -48,6 +50,7 @@ class MainViewModel(
private val _isRefreshing: MutableState<Boolean> = mutableStateOf(true)
private var _error: String? = null
private var _backups: MutableMap<String, Backup> = mutableMapOf()
private val resources: Resources = context.resources

val isRefreshing: Boolean
get() = _isRefreshing.value
Expand Down Expand Up @@ -142,9 +145,9 @@ class MainViewModel(
val ramoops = File("/sdcard/Download/console-ramoops--$now.log")
Shell.cmd("cp /sys/fs/pstore/console-ramoops-0 $ramoops").exec()
if (ramoops.exists()) {
log(context, "Saved ramoops to $ramoops")
log(context, resources.getString(R.string.save_ramoops_success, ramoops))
} else {
log(context, "Failed to save $ramoops", shouldThrow = true)
log(context,resources.getString(R.string.save_ramoops_fail, ramoops), shouldThrow = true)
}
}
}
Expand All @@ -156,9 +159,9 @@ class MainViewModel(
val dmesg = File("/sdcard/Download/dmesg--$now.log")
Shell.cmd("dmesg > $dmesg").exec()
if (dmesg.exists()) {
log(context, "Saved dmesg to $dmesg")
log(context, resources.getString(R.string.save_dmesg_success, dmesg))
} else {
log(context, "Failed to save $dmesg", shouldThrow = true)
log(context,resources.getString(R.string.save_dmesg_fail, dmesg), shouldThrow = true)
}
}
}
Expand All @@ -170,9 +173,9 @@ class MainViewModel(
val logcat = File("/sdcard/Download/logcat--$now.log")
Shell.cmd("logcat -d > $logcat").exec()
if (logcat.exists()) {
log(context, "Saved logcat to $logcat")
log(context, resources.getString(R.string.save_logcat_success, logcat))
} else {
log(context, "Failed to save $logcat", shouldThrow = true)
log(context,resources.getString(R.string.save_logcat_fail, logcat), shouldThrow = true)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.github.capntrips.kernelflasher.ui.screens.slot

import android.annotation.SuppressLint
import android.content.Context
import android.content.res.Resources
import android.net.Uri
import android.provider.OpenableColumns
import android.util.Log
Expand All @@ -15,6 +16,7 @@ import androidx.compose.runtime.snapshots.SnapshotStateMap
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import androidx.navigation.NavController
import com.github.capntrips.kernelflasher.R
import com.github.capntrips.kernelflasher.common.PartitionUtil
import com.github.capntrips.kernelflasher.common.extensions.ByteArray.toHex
import com.github.capntrips.kernelflasher.common.extensions.ExtendedFile.inputStream
Expand Down Expand Up @@ -65,6 +67,7 @@ class SlotViewModel(
private val hashAlgorithm: String = "SHA-256"
private var inInit = true
private var _error: String? = null
private val resources: Resources = context.resources

val sha1: String
get() = _sha1!!
Expand Down Expand Up @@ -120,12 +123,12 @@ class SlotViewModel(
when (Shell.cmd("$magiskboot cpio ramdisk.cpio test").exec().code) {
0 -> _sha1 = Shell.cmd("$magiskboot sha1 $boot").exec().out.firstOrNull()
1 -> _sha1 = Shell.cmd("$magiskboot cpio ramdisk.cpio sha1").exec().out.firstOrNull()
else -> log(context, "Invalid ramdisk in boot.img", shouldThrow = true)
else -> log(context, resources.getString(R.string.invalid_ramdisk), shouldThrow = true)
}
} else if (kernel.exists()) {
_sha1 = Shell.cmd("$magiskboot sha1 $boot").exec().out.firstOrNull()
} else {
log(context, "Invalid boot.img, no ramdisk or kernel found", shouldThrow = true)
log(context, resources.getString(R.string.invalid_boot), shouldThrow = true)
}
Shell.cmd("$magiskboot cleanup").exec()

Expand Down Expand Up @@ -218,11 +221,11 @@ class SlotViewModel(
launch {
val now = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd--HH-mm"))
val logName = if (navController.currentDestination!!.route!!.contains("ak3")) {
"ak3"
resources.getString(R.string.log_ak3)
} else if (navController.currentDestination!!.route!!.endsWith("/backup")) {
"backup"
resources.getString(R.string.log_backup)
} else {
"flash"
resources.getString(R.string.log_flash)
}
val log = File("/sdcard/Download/$logName-log--$now.log")
if (navController.currentDestination!!.route!!.contains("ak3")) {
Expand All @@ -231,9 +234,9 @@ class SlotViewModel(
log.writeText(flashOutput.joinToString("\n"))
}
if (log.exists()) {
log(context, "Saved $logName log to $log")
log(context, resources.getString(R.string.save_log_success, logName, log))
} else {
log(context, "Failed to save $log", shouldThrow = true)
log(context, resources.getString(R.string.save_log_fail, log), shouldThrow = true)
}
}
}
Expand Down Expand Up @@ -353,21 +356,21 @@ class SlotViewModel(
val externalDir = fileSystemManager.getFile("/sdcard/KernelFlasher")
if (!externalDir.exists()) {
if (!externalDir.mkdir()) {
log(context, "Failed to create KernelFlasher dir on /sdcard", shouldThrow = true)
log(context, resources.getString(R.string.create_kf_dir_fail), shouldThrow = true)
}
}
val backupsDir = externalDir.getChildFile("backups")
if (!backupsDir.exists()) {
if (!backupsDir.mkdir()) {
log(context, "Failed to create backups dir", shouldThrow = true)
log(context, resources.getString(R.string.create_backups_dir_fail), shouldThrow = true)
}
}
val backupDir = backupsDir.getChildFile(now)
if (backupDir.exists()) {
log(context, "Backup $now already exists", shouldThrow = true)
log(context, resources.getString(R.string.backup_exists, now), shouldThrow = true)
} else {
if (!backupDir.mkdir()) {
log(context, "Failed to create backup dir", shouldThrow = true)
log(context, resources.getString(R.string.create_backup_dir_fail), shouldThrow = true)
}
}
return backupDir
Expand All @@ -389,7 +392,7 @@ class SlotViewModel(
addMessage("Saving backup $now")
val hashes = backupPartitions(context, backupDir)
if (hashes == null) {
log(context, "No partitions saved", shouldThrow = true)
log(context, resources.getString(R.string.no_partitions_saved), shouldThrow = true)
}
val jsonFile = backupDir.getChildFile("backup.json")
val backup = Backup(now, "raw", currentKernelVersion!!, sha1, null, hashes, hashAlgorithm)
Expand Down Expand Up @@ -423,7 +426,7 @@ class SlotViewModel(
callback.invoke()
}
} else {
log(context, "AK3 zip is missing", shouldThrow = true)
log(context, resources.getString(R.string.ak3_zip_missing), shouldThrow = true)
}
}
}
Expand All @@ -443,7 +446,7 @@ class SlotViewModel(
val zipFile = ZipFile(zip)
zipFile.use { z ->
if (z.getEntry("anykernel.sh") == null) {
log(context, "Invalid AK3 zip", shouldThrow = true)
log(context, resources.getString(R.string.ak3_zip_invalid), shouldThrow = true)
}
withContext (Dispatchers.Main) {
callback?.invoke()
Expand All @@ -454,7 +457,7 @@ class SlotViewModel(
throw e
}
} else {
log(context, "Failed to save zip", shouldThrow = true)
log(context, resources.getString(R.string.save_zip_fail), shouldThrow = true)
}
}

Expand All @@ -467,7 +470,7 @@ class SlotViewModel(
val backupsDir = fileSystemManager.getFile("$externalDir/backups")
val backupDir = backupsDir.getChildFile(currentBackup)
if (!backupDir.exists()) {
log(context, "Backup $currentBackup does not exists", shouldThrow = true)
log(context, resources.getString(R.string.backup_not_exist, currentBackup), shouldThrow = true)
}
val source = backupDir.getChildFile(flashFilename!!)
val zip = File(context.filesDir, flashFilename!!)
Expand Down Expand Up @@ -509,14 +512,14 @@ class SlotViewModel(
val flashScript = File(files, "flash_ak3.sh")
val result = Shell.Builder.create().setFlags(Shell.FLAG_MOUNT_MASTER or Shell.FLAG_REDIRECT_STDERR).build().newJob().add("F=$files Z=\"$zip\" /system/bin/sh $flashScript").to(flashOutput).exec()
if (result.isSuccess) {
log(context, "Kernel flashed successfully")
log(context, resources.getString(R.string.flash_success))
_wasFlashSuccess.value = true
} else {
log(context, "Failed to flash zip", shouldThrow = false)
log(context, resources.getString(R.string.flash_fail), shouldThrow = false)
}
clearTmp(context)
} else {
log(context, "AK3 zip is missing", shouldThrow = true)
log(context, resources.getString(R.string.ak3_zip_missing), shouldThrow = true)
}
} catch (e: Exception) {
clearFlash(context)
Expand Down Expand Up @@ -569,15 +572,15 @@ class SlotViewModel(
PartitionUtil.flashBlockDevice(image, blockDevice, hashAlgorithm)
}
} else {
log(context, "Partition $partitionName was not found", shouldThrow = true)
log(context, resources.getString(R.string.partition_not_found, partitionName), shouldThrow = true)
}
addMessage("Flashed $flashFilename to $partitionName")
addMessage("Cleaning up ...")
clearTmp(context)
addMessage("Done.")
_wasFlashSuccess.value = true
} else {
log(context, "Partition image is missing", shouldThrow = true)
log(context, resources.getString(R.string.partition_image_missing), shouldThrow = true)
}
} catch (e: Exception) {
clearFlash(context)
Expand Down
89 changes: 89 additions & 0 deletions app/src/main/res/values-pl/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">Kernel Flasher</string>
<string name="root_required">Wymagane uprawnienia Superużytkownika</string>
<string name="root_service_disconnected">Usługa Superużytkownika została odłączona</string>
<string name="device">Urządzenie</string>
<string name="model">Model</string>
<string name="build_number">Kompilacja</string>
<string name="kernel_name">Nazwa jądra</string>
<string name="kernel_version">Wersja jądra</string>
<string name="slot_suffix">Przyrostek slotu</string>
<string name="slot">Slot</string>
<string name="slot_a">Slot A</string>
<string name="slot_b">Slot B</string>
<string name="boot_sha1">Boot SHA1</string>
<string name="vendor_dlkm">Vendor DLKM</string>
<string name="exists">Istnieje</string>
<string name="not_found">Nie znaleziono</string>
<string name="mounted">Zamontowany</string>
<string name="unmounted">Niezamontowany</string>
<string name="view">Wybierz</string>
<string name="backups">Kopie zapasowe</string>
<string name="save_ramoops">Zapisz ramoops</string>
<string name="save_dmesg">Zapisz dmesg</string>
<string name="save_logcat">Zapisz logcat</string>
<string name="back">Wstecz</string>
<string name="backup">Utwórz kopię zapasową</string>
<string name="updates">Aktualizacje</string>
<string name="flash">Sflashuj</string>
<string name="flash_ak3_zip">Sflashuj archiwum AK3</string>
<string name="flash_partition_image">Sflashuj obraz partycji</string>
<string name="restore">Przywróć</string>
<string name="check_kernel_version">Sprawdź wersję jądra</string>
<string name="mount_vendor_dlkm">Zamontuj Vendor DLKM</string>
<string name="unmount_vendor_dlkm">Odmontuj Vendor DLKM</string>
<string name="migrate">Migruj</string>
<string name="map_vendor_dlkm">Zmapuj Vendor DLKM</string>
<string name="unmap_vendor_dlkm">Odmapuj Vendor DLKM</string>
<string name="no_backups_found">Nie znaleziono kopii zapasowych</string>
<string name="delete">Usuń</string>
<string name="add">Dodaj</string>
<string name="url">Adres URL</string>
<string name="version">Wersja</string>
<string name="date_released">Data publikacji</string>
<string name="last_updated">Ostatnia aktualizacja</string>
<string name="changelog">Lista zmian</string>
<string name="check_for_updates">Sprawdź aktualizacje</string>
<string name="download">Pobierz</string>
<string name="reboot">Uruchom ponownie</string>
<string name="reboot_userspace">Miękki restart</string>
<string name="reboot_recovery">Uruchom ponownie do trybu Recovery</string>
<string name="reboot_bootloader">Uruchom ponownie do trybu Bootloader</string>
<string name="reboot_download">Uruchom ponownie do trybu Download</string>
<string name="reboot_edl">Uruchom ponownie do trybu EDL</string>
<string name="save_ak3_log">Zapisz dziennik AK3</string>
<string name="save_flash_log">Zapisz dziennik Flashowania</string>
<string name="save_backup_log">Zapisz dziennik kopii zapasowej</string>
<string name="save_restore_log">Zapisz dziennik przywracania</string>
<string name="save_ak3_zip_as_backup">Zapisz archiwum AK3 jako kopię zapasową</string>
<string name="backup_type">Typ kopii zapasowej</string>
<string name="hashes">Sumy kontrolne</string>
<string name="partition_selection_unavailable">Wybór partycji niedostępny dla kopii zapasowych starszego formatu</string>
<string name="flash_success">Sflashowano pomyślnie</string>
<string name="flash_fail">Błąd podczas flashowania</string>
<string name="invalid_ramdisk">Wadliwy ramdisk w boot.img</string>
<string name="invalid_boot">Wadliwy boot.img, nie znaleziono ramdisku lub jądra</string>
<string name="save_log_success">Zapisano dziennik %1$s do %2$s</string>
<string name="save_log_fail">Nie udało się zapisać dziennika %1$s</string>
<string name="log_ak3">AK3</string>
<string name="log_backup">Kopii zapasowej</string>
<string name="log_flash">Flashowania</string>
<string name="create_kf_dir_fail">Nie udało się utworzyć katalogu KernelFlasher w /sdcard</string>
<string name="create_backups_dir_fail">Nie udało się utworzyć katalogu kopii zapasowych</string>
<string name="create_backup_dir_fail">Nie udało się utworzyć katalogu kopii zapasowej</string>
<string name="backup_exists">Kopia zapasowa %1$s już istnieje</string>
<string name="no_partitions_saved">Brak zapisanych partycji</string>
<string name="ak3_zip_missing">Archiwum AK3 nie istnieje</string>
<string name="ak3_zip_invalid">Wadliwe archiwum AK3</string>
<string name="save_zip_fail">Nie udało się zapisać archiwum</string>
<string name="backup_not_exist">Kopia zpasowa %1$s nie istnieje</string>
<string name="partition_not_found">Nie znaleziono partycji %1$s</string>
<string name="partition_image_missing">Obraz partycji nie istnieje</string>
<string name="save_ramoops_success">Zapisano ramoops w %1$s</string>
<string name="save_ramoops_fail">Nie udało się zapisać pliku %1$s</string>
<string name="save_dmesg_success">Zapisano dmesg w %1$s</string>
<string name="save_dmesg_fail">Nie udało się zapisać pliku %1$s</string>
<string name="save_logcat_success">Zapisano logcat w %1$s</string>
<string name="save_logcat_fail">Nie udało się zapisać pliku %1$s</string>
</resources>
26 changes: 26 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,31 @@
<string name="backup_type">Backup Type</string>
<string name="hashes">Hashes</string>
<string name="partition_selection_unavailable">Partition selection unavailable for legacy backups</string>
<string name="flash_success">Kernel flashed successfully</string>
<string name="flash_fail">Failed to flash zip</string>
<string name="invalid_ramdisk">Invalid ramdisk in boot.img</string>
<string name="invalid_boot">Invalid boot.img, no ramdisk or kernel found</string>
<string name="save_log_success">Saved %1$s log to %2$s</string>
<string name="save_log_fail">Failed to save %1$s log</string>
<string name="log_ak3">AK3</string>
<string name="log_backup">backup</string>
<string name="log_flash">flash</string>
<string name="create_kf_dir_fail">Failed to create KernelFlasher dir on /sdcard</string>
<string name="create_backups_dir_fail">Failed to create backups dir</string>
<string name="create_backup_dir_fail">Failed to create backup dir</string>
<string name="backup_exists">Backup %1$s already exists</string>
<string name="no_partitions_saved">No partitions saved</string>
<string name="ak3_zip_missing">AK3 zip is missing</string>
<string name="ak3_zip_invalid">Invalid AK3 zip</string>
<string name="save_zip_fail">Failed to save zip</string>
<string name="backup_not_exist">Backup %1$s does not exists</string>
<string name="partition_not_found">Partition %1$s was not found</string>
<string name="partition_image_missing">Partition image is missing</string>
<string name="save_ramoops_success">Saved ramoops to %1$s</string>
<string name="save_ramoops_fail">Failed to save %1$s</string>
<string name="save_dmesg_success">Saved dmesg to %1$s</string>
<string name="save_dmesg_fail">Failed to save %1$s</string>
<string name="save_logcat_success">Saved logcat to %1$s</string>
<string name="save_logcat_fail">Failed to save %1$s</string>
<!-- TODO: Make error and success messages string resources -->
</resources>