Skip to content

Commit

Permalink
refactor: change package name and fix some check
Browse files Browse the repository at this point in the history
  • Loading branch information
RimuruChan committed Mar 17, 2024
1 parent 3adff64 commit 221e975
Show file tree
Hide file tree
Showing 54 changed files with 559 additions and 281 deletions.
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
# Kernel Flasher

_Forked from [Kernel Flasher](https://github.com/capntrips/KernelFlasher/) and modified
by [weiishu](https://github.com/tiann)._

Kernel Flasher is an Android app to flash, backup, and restore kernels.

## Usage

`View` a slot and choose to `Flash` an AK3 zip, `Backup` the kernel related partitions, or `Restore` a previous backup.
`View` a slot and choose to `Flash` an AK3 zip, `Backup` the kernel related partitions, or `Restore`
a previous backup.

There are also options to toggle the mount and map status of `vendor_dlkm` and to save `dmesg` and `logcat`.
There are also options to toggle the mount and map status of `vendor_dlkm` and to save `dmesg`
and `logcat`.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ android {
compileSdk 34

defaultConfig {
applicationId "com.github.capntrips.kernelflasher"
applicationId "com.github.rimuruchan.kernelflasher"
minSdk 29
targetSdk 34
versionCode 19
Expand Down Expand Up @@ -65,7 +65,7 @@ android {
useLegacyPackaging true
}
}
namespace 'com.github.capntrips.kernelflasher'
namespace 'com.github.rimuruchan.kernelflasher'
}

dependencies {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.github.capntrips.kernelflasher;
package com.github.rimuruchan.kernelflasher;

interface IFilesystemService {
IBinder getFileSystemService();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.github.capntrips.kernelflasher
package com.github.rimuruchan.kernelflasher

import android.content.Intent
import android.os.IBinder
Expand All @@ -11,6 +11,7 @@ class FilesystemService : RootService() {
return FileSystemManager.getService()
}
}

override fun onBind(intent: Intent): IBinder {
return FilesystemIPC()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.github.capntrips.kernelflasher
package com.github.rimuruchan.kernelflasher

import android.animation.ObjectAnimator
import android.animation.PropertyValuesHolder
Expand All @@ -11,6 +11,7 @@ import android.util.Log
import android.view.View
import android.view.ViewTreeObserver
import android.view.animation.AccelerateInterpolator
import android.widget.Toast
import androidx.activity.ComponentActivity
import androidx.activity.compose.BackHandler
import androidx.activity.compose.setContent
Expand All @@ -30,20 +31,20 @@ import androidx.navigation.NavBackStackEntry
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.rememberNavController
import com.github.capntrips.kernelflasher.ui.screens.RefreshableScreen
import com.github.capntrips.kernelflasher.ui.screens.backups.BackupsContent
import com.github.capntrips.kernelflasher.ui.screens.backups.SlotBackupsContent
import com.github.capntrips.kernelflasher.ui.screens.error.ErrorScreen
import com.github.capntrips.kernelflasher.ui.screens.main.MainContent
import com.github.capntrips.kernelflasher.ui.screens.main.MainViewModel
import com.github.capntrips.kernelflasher.ui.screens.reboot.RebootContent
import com.github.capntrips.kernelflasher.ui.screens.slot.SlotContent
import com.github.capntrips.kernelflasher.ui.screens.slot.SlotFlashContent
import com.github.capntrips.kernelflasher.ui.screens.updates.UpdatesAddContent
import com.github.capntrips.kernelflasher.ui.screens.updates.UpdatesChangelogContent
import com.github.capntrips.kernelflasher.ui.screens.updates.UpdatesContent
import com.github.capntrips.kernelflasher.ui.screens.updates.UpdatesViewContent
import com.github.capntrips.kernelflasher.ui.theme.KernelFlasherTheme
import com.github.rimuruchan.kernelflasher.ui.screens.RefreshableScreen
import com.github.rimuruchan.kernelflasher.ui.screens.backups.BackupsContent
import com.github.rimuruchan.kernelflasher.ui.screens.backups.SlotBackupsContent
import com.github.rimuruchan.kernelflasher.ui.screens.error.ErrorScreen
import com.github.rimuruchan.kernelflasher.ui.screens.main.MainContent
import com.github.rimuruchan.kernelflasher.ui.screens.main.MainViewModel
import com.github.rimuruchan.kernelflasher.ui.screens.reboot.RebootContent
import com.github.rimuruchan.kernelflasher.ui.screens.slot.SlotContent
import com.github.rimuruchan.kernelflasher.ui.screens.slot.SlotFlashContent
import com.github.rimuruchan.kernelflasher.ui.screens.updates.UpdatesAddContent
import com.github.rimuruchan.kernelflasher.ui.screens.updates.UpdatesChangelogContent
import com.github.rimuruchan.kernelflasher.ui.screens.updates.UpdatesContent
import com.github.rimuruchan.kernelflasher.ui.screens.updates.UpdatesViewContent
import com.github.rimuruchan.kernelflasher.ui.theme.KernelFlasherTheme
import com.topjohnwu.superuser.Shell
import com.topjohnwu.superuser.ipc.RootService
import com.topjohnwu.superuser.nio.FileSystemManager
Expand All @@ -59,6 +60,7 @@ import java.io.File
class MainActivity : ComponentActivity() {
companion object {
const val TAG: String = "MainActivity"

init {
Shell.setDefaultBuilder(Shell.Builder.create().setFlags(Shell.FLAG_MOUNT_MASTER))
}
Expand Down Expand Up @@ -136,6 +138,9 @@ class MainActivity : ComponentActivity() {
scale.start()
}

Toast.makeText(this, getString(R.string.loading_please_wait), Toast.LENGTH_LONG)
.show()

val content: View = findViewById(android.R.id.content)
content.viewTreeObserver.addOnPreDrawListener(
object : ViewTreeObserver.OnPreDrawListener {
Expand Down Expand Up @@ -181,7 +186,8 @@ class MainActivity : ComponentActivity() {
setContent {
val navController = rememberNavController()
viewModel = viewModel {
val application = checkNotNull(get(ViewModelProvider.AndroidViewModelFactory.APPLICATION_KEY))
val application =
checkNotNull(get(ViewModelProvider.AndroidViewModelFactory.APPLICATION_KEY))
MainViewModel(application, fileSystemManager, navController)
}
val mainViewModel = viewModel!!
Expand All @@ -196,25 +202,35 @@ class MainActivity : ComponentActivity() {
val updatesViewModel = mainViewModel.updates
val rebootViewModel = mainViewModel.reboot
BackHandler(enabled = mainViewModel.isRefreshing, onBack = {})
val slotFlashContent: @Composable AnimatedVisibilityScope.(NavBackStackEntry) -> Unit = { backStackEntry ->
val slotSuffix = backStackEntry.arguments?.getString("slotSuffix")!!
val slotViewModel = if (slotSuffix == "_a") slotViewModelA else slotViewModelB
RefreshableScreen(mainViewModel, navController) {
SlotFlashContent(slotViewModel, slotSuffix, navController)
}
}
val slotBackupsContent: @Composable AnimatedVisibilityScope.(NavBackStackEntry) -> Unit = { backStackEntry ->
val slotSuffix = backStackEntry.arguments?.getString("slotSuffix")!!
val slotViewModel = if (slotSuffix == "_a") slotViewModelA else slotViewModelB
if (backStackEntry.arguments?.getString("backupId") != null) {
backupsViewModel.currentBackup = backStackEntry.arguments?.getString("backupId")
} else {
backupsViewModel.clearCurrent()
val slotFlashContent: @Composable AnimatedVisibilityScope.(NavBackStackEntry) -> Unit =
{ backStackEntry ->
val slotSuffix = backStackEntry.arguments?.getString("slotSuffix")!!
val slotViewModel =
if (slotSuffix == "_a") slotViewModelA else slotViewModelB
RefreshableScreen(mainViewModel, navController) {
SlotFlashContent(slotViewModel, slotSuffix, navController)
}
}
RefreshableScreen(mainViewModel, navController) {
SlotBackupsContent(slotViewModel, backupsViewModel, slotSuffix, navController)
val slotBackupsContent: @Composable AnimatedVisibilityScope.(NavBackStackEntry) -> Unit =
{ backStackEntry ->
val slotSuffix = backStackEntry.arguments?.getString("slotSuffix")!!
val slotViewModel =
if (slotSuffix == "_a") slotViewModelA else slotViewModelB
if (backStackEntry.arguments?.getString("backupId") != null) {
backupsViewModel.currentBackup =
backStackEntry.arguments?.getString("backupId")
} else {
backupsViewModel.clearCurrent()
}
RefreshableScreen(mainViewModel, navController) {
SlotBackupsContent(
slotViewModel,
backupsViewModel,
slotSuffix,
navController
)
}
}
}
NavHost(navController = navController, startDestination = "main") {
composable("main") {
RefreshableScreen(mainViewModel, navController, swipeEnabled = true) {
Expand All @@ -223,8 +239,12 @@ class MainActivity : ComponentActivity() {
}
composable("slot{slotSuffix}") { backStackEntry ->
val slotSuffix = backStackEntry.arguments?.getString("slotSuffix")!!
val slotViewModel = if (slotSuffix == "_a") slotViewModelA else slotViewModelB
if (slotViewModel.wasFlashSuccess != null && navController.currentDestination!!.route.equals("slot{slotSuffix}")) {
val slotViewModel =
if (slotSuffix == "_a") slotViewModelA else slotViewModelB
if (slotViewModel.wasFlashSuccess != null && navController.currentDestination!!.route.equals(
"slot{slotSuffix}"
)
) {
slotViewModel.clearFlash(this@MainActivity)
}
RefreshableScreen(mainViewModel, navController, swipeEnabled = true) {
Expand All @@ -238,13 +258,24 @@ class MainActivity : ComponentActivity() {
composable("slot{slotSuffix}/backup", content = slotFlashContent)
composable("slot{slotSuffix}/backup/backup", content = slotFlashContent)
composable("slot{slotSuffix}/backups", content = slotBackupsContent)
composable("slot{slotSuffix}/backups/{backupId}", content = slotBackupsContent)
composable("slot{slotSuffix}/backups/{backupId}/restore", content = slotBackupsContent)
composable("slot{slotSuffix}/backups/{backupId}/restore/restore", content = slotBackupsContent)
composable(
"slot{slotSuffix}/backups/{backupId}",
content = slotBackupsContent
)
composable(
"slot{slotSuffix}/backups/{backupId}/restore",
content = slotBackupsContent
)
composable(
"slot{slotSuffix}/backups/{backupId}/restore/restore",
content = slotBackupsContent
)
composable("slot{slotSuffix}/backups/{backupId}/flash/ak3") { backStackEntry ->
val slotSuffix = backStackEntry.arguments?.getString("slotSuffix")!!
val slotViewModel = if (slotSuffix == "_a") slotViewModelA else slotViewModelB
backupsViewModel.currentBackup = backStackEntry.arguments?.getString("backupId")
val slotViewModel =
if (slotSuffix == "_a") slotViewModelA else slotViewModelB
backupsViewModel.currentBackup =
backStackEntry.arguments?.getString("backupId")
if (backupsViewModel.backups.containsKey(backupsViewModel.currentBackup)) {
RefreshableScreen(mainViewModel, navController) {
SlotFlashContent(slotViewModel, slotSuffix, navController)
Expand All @@ -258,7 +289,8 @@ class MainActivity : ComponentActivity() {
}
}
composable("backups/{backupId}") { backStackEntry ->
backupsViewModel.currentBackup = backStackEntry.arguments?.getString("backupId")
backupsViewModel.currentBackup =
backStackEntry.arguments?.getString("backupId")
if (backupsViewModel.backups.containsKey(backupsViewModel.currentBackup)) {
RefreshableScreen(mainViewModel, navController) {
BackupsContent(backupsViewModel, navController)
Expand All @@ -278,7 +310,8 @@ class MainActivity : ComponentActivity() {
}
composable("updates/view/{updateId}") { backStackEntry ->
val updateId = backStackEntry.arguments?.getString("updateId")!!.toInt()
val currentUpdate = updatesViewModel.updates.firstOrNull { it.id == updateId }
val currentUpdate =
updatesViewModel.updates.firstOrNull { it.id == updateId }
updatesViewModel.currentUpdate = currentUpdate
if (updatesViewModel.currentUpdate != null) {
// TODO: enable swipe refresh
Expand All @@ -289,7 +322,8 @@ class MainActivity : ComponentActivity() {
}
composable("updates/view/{updateId}/changelog") { backStackEntry ->
val updateId = backStackEntry.arguments?.getString("updateId")!!.toInt()
val currentUpdate = updatesViewModel.updates.firstOrNull { it.id == updateId }
val currentUpdate =
updatesViewModel.updates.firstOrNull { it.id == updateId }
updatesViewModel.currentUpdate = currentUpdate
if (updatesViewModel.currentUpdate != null) {
RefreshableScreen(mainViewModel, navController) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.github.capntrips.kernelflasher
package com.github.rimuruchan.kernelflasher

internal class MainListener(private val callback: () -> Unit) {
fun resume() {
Expand Down
Loading

0 comments on commit 221e975

Please sign in to comment.