Skip to content

Commit

Permalink
fixed boot_b
Browse files Browse the repository at this point in the history
lowered minSdk to 29
bumped dependencies
cleaned up warnings
  • Loading branch information
capntrips committed Oct 3, 2023
1 parent 02a2090 commit f5f270c
Show file tree
Hide file tree
Showing 29 changed files with 187 additions and 157 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
/local.properties
/.idea
.DS_Store
/app/release
/build
/captures
.externalNativeBuild
Expand Down
81 changes: 46 additions & 35 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,19 +1,28 @@
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id 'org.jetbrains.kotlin.kapt'
id 'org.jetbrains.kotlin.plugin.serialization'
alias(libs.plugins.android.application)
alias(libs.plugins.devtools.ksp)
alias(libs.plugins.kotlin.android)
alias(libs.plugins.kotlin.serialization)
}

android {
compileSdk 33
compileSdk 34

defaultConfig {
applicationId "com.github.capntrips.kernelflasher"
minSdk 30
targetSdk 33
versionCode 14
versionName "1.0.0-alpha14"
minSdk 29
targetSdk 34
versionCode 15
versionName "1.0.0-alpha15"

javaCompileOptions {
annotationProcessorOptions {
arguments += [
"room.schemaLocation": "$projectDir/schemas".toString(),
"room.incremental": "true"
]
}
}

vectorDrawables {
useSupportLibrary true
Expand All @@ -25,18 +34,21 @@ android {
minifyEnabled false
}
}
buildFeatures {
aidl true
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
kotlinOptions {
jvmTarget = '1.8'
jvmTarget = '17'
}
buildFeatures {
compose true
}
composeOptions {
kotlinCompilerExtensionVersion compiler_version
kotlinCompilerExtensionVersion libs.versions.compose.compiler.get()
}
packagingOptions {
resources {
Expand All @@ -47,26 +59,25 @@ android {
}

dependencies {
implementation "androidx.activity:activity-compose:$activity_version"
implementation "androidx.appcompat:appcompat:$appcompat_version"
implementation "androidx.compose.material3:material3:$material3_version"
implementation "androidx.compose.foundation:foundation:$compose_version"
implementation "androidx.compose.ui:ui:$compose_version"
implementation "androidx.core:core-ktx:$core_version"
implementation "androidx.core:core-splashscreen:$splashscreen_version"
implementation "androidx.lifecycle:lifecycle-runtime-ktx:$lifecycle_version"
implementation "androidx.lifecycle:lifecycle-viewmodel-compose:$lifecycle_version"
implementation "androidx.navigation:navigation-compose:$nav_version"
implementation "androidx.room:room-runtime:$room_version"
annotationProcessor "androidx.room:room-compiler:$room_version"
kapt "androidx.room:room-compiler:$room_version"
implementation "com.github.topjohnwu.libsu:core:$libsu_version"
implementation "com.github.topjohnwu.libsu:io:$libsu_version"
implementation "com.github.topjohnwu.libsu:nio:$libsu_version"
implementation "com.github.topjohnwu.libsu:service:$libsu_version"
implementation "com.google.accompanist:accompanist-navigation-animation:$accompanist_version"
implementation "com.google.accompanist:accompanist-swiperefresh:$accompanist_version"
implementation "com.google.android.material:material:$material_version"
implementation("com.squareup.okhttp3:okhttp:$okhttp_version")
implementation "org.jetbrains.kotlinx:kotlinx-serialization-json:$serialization_version"
implementation(libs.androidx.activity.compose)
implementation(libs.androidx.appcompat)
implementation(libs.androidx.compose.material)
implementation(libs.androidx.compose.material3)
implementation(libs.androidx.compose.foundation)
implementation(libs.androidx.compose.ui)
implementation(libs.androidx.core.ktx)
implementation(libs.androidx.core.splashscreen)
implementation(libs.androidx.lifecycle.runtime.ktx)
implementation(libs.androidx.lifecycle.viewmodel.compose)
implementation(libs.androidx.navigation.compose)
implementation(libs.androidx.room.runtime)
annotationProcessor(libs.androidx.room.compiler)
ksp(libs.androidx.room.compiler)
implementation(libs.libsu.core)
implementation(libs.libsu.io)
implementation(libs.libsu.nio)
implementation(libs.libsu.service)
implementation(libs.material)
implementation(libs.okhttp)
implementation(libs.kotlinx.serialization.json)
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import androidx.activity.compose.BackHandler
import androidx.activity.compose.setContent
import androidx.compose.animation.AnimatedVisibilityScope
import androidx.compose.animation.ExperimentalAnimationApi
import androidx.compose.material.ExperimentalMaterialApi
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.runtime.Composable
import androidx.compose.ui.res.stringResource
Expand All @@ -26,6 +27,9 @@ import androidx.core.view.WindowCompat
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.viewmodel.compose.viewModel
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
Expand All @@ -40,20 +44,18 @@ import com.github.capntrips.kernelflasher.ui.screens.updates.UpdatesChangelogCon
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.google.accompanist.navigation.animation.AnimatedNavHost
import com.google.accompanist.navigation.animation.composable
import com.google.accompanist.navigation.animation.rememberAnimatedNavController
import com.topjohnwu.superuser.Shell
import com.topjohnwu.superuser.ipc.RootService
import com.topjohnwu.superuser.nio.FileSystemManager
import kotlinx.serialization.ExperimentalSerializationApi
import java.io.File


@ExperimentalAnimationApi
@ExperimentalMaterialApi
@ExperimentalMaterial3Api
@ExperimentalSerializationApi
@ExperimentalUnitApi
@ExperimentalMaterial3Api
@ExperimentalAnimationApi
class MainActivity : ComponentActivity() {
companion object {
const val TAG: String = "MainActivity"
Expand Down Expand Up @@ -164,7 +166,7 @@ class MainActivity : ComponentActivity() {
}
}
setContent {
val navController = rememberAnimatedNavController()
val navController = rememberNavController()
viewModel = viewModel {
val application = checkNotNull(get(ViewModelProvider.AndroidViewModelFactory.APPLICATION_KEY))
MainViewModel(application, fileSystemManager, navController)
Expand Down Expand Up @@ -200,7 +202,7 @@ class MainActivity : ComponentActivity() {
SlotBackupsContent(slotViewModel, backupsViewModel, slotSuffix, navController)
}
}
AnimatedNavHost(navController = navController, startDestination = "main") {
NavHost(navController = navController, startDestination = "main") {
composable("main") {
RefreshableScreen(mainViewModel, navController, swipeEnabled = true) {
MainContent(mainViewModel, navController)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import com.github.capntrips.kernelflasher.common.types.partitions.FstabEntry
import com.topjohnwu.superuser.Shell
import com.topjohnwu.superuser.nio.ExtendedFile
import com.topjohnwu.superuser.nio.FileSystemManager
import kotlinx.serialization.decodeFromString
import kotlinx.serialization.json.Json
import java.io.File
import java.security.DigestOutputStream
Expand All @@ -27,13 +26,13 @@ object PartitionUtil {
val AvailablePartitions = mutableListOf<String>()

private var fileSystemManager: FileSystemManager? = null
private var bootDevice: File? = null
private var bootParent: File? = null

fun init(context: Context, fileSystemManager: FileSystemManager) {
this.fileSystemManager = fileSystemManager
val fstabEntry = findPartitionFstabEntry(context, "boot")
if (fstabEntry != null) {
bootDevice = File(fstabEntry.blkDevice).parentFile
bootParent = File(fstabEntry.blkDevice).parentFile
}
val activeSlotSuffix = Shell.cmd("getprop ro.boot.slot_suffix").exec().out[0]
for (partitionName in PartitionNames) {
Expand Down Expand Up @@ -67,10 +66,13 @@ object PartitionUtil {
}
} else {
blockDevice = fileSystemManager!!.getFile(fstabEntry.blkDevice)
if (blockDevice.name != "$partitionName$slotSuffix") {
blockDevice = fileSystemManager!!.getFile(blockDevice.parentFile, "$partitionName$slotSuffix")
}
}
}
if (blockDevice == null) {
val siblingDevice = if (bootDevice != null) fileSystemManager!!.getFile(bootDevice!!, partitionName) else null
if (blockDevice == null || !blockDevice.exists()) {
val siblingDevice = if (bootParent != null) fileSystemManager!!.getFile(bootParent!!, "$partitionName$slotSuffix") else null
val physicalDevice = fileSystemManager!!.getFile("/dev/block/by-name/$partitionName$slotSuffix")
val logicalDevice = fileSystemManager!!.getFile("/dev/block/mapper/$partitionName$slotSuffix")
if (siblingDevice?.exists() == true) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ object ExtendedFile {
@Suppress("unused")
fun ExtendedFile.writeText(text: String, charset: Charset = Charsets.UTF_8): Unit = writeBytes(text.toByteArray(charset))

@Suppress("MemberVisibilityCanBePrivate")
fun ExtendedFile.inputStream(): InputStream = newInputStream()

@Suppress("MemberVisibilityCanBePrivate")
fun ExtendedFile.outputStream(): OutputStream = newOutputStream()
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ data class Partitions(
val boot: String? = null,
val vbmeta: String? = null,
val dtbo: String? = null,
val vendor_boot: String? = null,
val vendor_kernel_boot: String? = null,
val vendor_dlkm: String? = null,
val init_boot: String? = null,
@Suppress("PropertyName") val vendor_boot: String? = null,
@Suppress("PropertyName") val vendor_kernel_boot: String? = null,
@Suppress("PropertyName") val vendor_dlkm: String? = null,
@Suppress("PropertyName") val init_boot: String? = null,
val recovery: String? = null
) {
companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import androidx.activity.result.contract.ActivityResultContracts
import androidx.compose.animation.ExperimentalAnimationApi
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.ExperimentalMaterialApi
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.OutlinedButton
import androidx.compose.material3.Text
Expand All @@ -18,9 +19,10 @@ import androidx.compose.ui.unit.ExperimentalUnitApi
import androidx.compose.ui.unit.dp
import com.github.capntrips.kernelflasher.MainActivity

@ExperimentalUnitApi
@ExperimentalAnimationApi
@ExperimentalMaterialApi
@ExperimentalMaterial3Api
@ExperimentalUnitApi
@Composable
fun FlashButton(
buttonText: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
Expand Down Expand Up @@ -85,10 +86,9 @@ fun Modifier.scrollbar(
width: Dp = 6.dp
): Modifier = composed {
var visibleItemsCountChanged = false
var visibleItemsCount by remember { mutableStateOf(state.layoutInfo.visibleItemsInfo.size) }
var visibleItemsCount by remember { mutableIntStateOf(state.layoutInfo.visibleItemsInfo.size) }
if (visibleItemsCount != state.layoutInfo.visibleItemsInfo.size) {
visibleItemsCountChanged = true
@Suppress("UNUSED_VALUE")
visibleItemsCount = state.layoutInfo.visibleItemsInfo.size
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import androidx.compose.animation.AnimatedVisibility
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontFamily
Expand Down Expand Up @@ -34,7 +34,7 @@ fun SlotCard(
}
}
) {
val cardWidth = remember { mutableStateOf(0) }
val cardWidth = remember { mutableIntStateOf(0) }
DataRow(
label = stringResource(R.string.boot_sha1),
value = viewModel.sha1.substring(0, 8),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.statusBars
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.ExperimentalMaterialApi
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ArrowBack
import androidx.compose.material.pullrefresh.PullRefreshIndicator
import androidx.compose.material.pullrefresh.pullRefresh
import androidx.compose.material.pullrefresh.rememberPullRefreshState
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
Expand All @@ -34,10 +38,8 @@ import androidx.compose.ui.unit.dp
import androidx.navigation.NavController
import com.github.capntrips.kernelflasher.R
import com.github.capntrips.kernelflasher.ui.screens.main.MainViewModel
import com.google.accompanist.swiperefresh.SwipeRefresh
import com.google.accompanist.swiperefresh.SwipeRefreshIndicator
import com.google.accompanist.swiperefresh.rememberSwipeRefreshState

@ExperimentalMaterialApi
@ExperimentalMaterial3Api
@Composable
fun RefreshableScreen(
Expand All @@ -48,6 +50,10 @@ fun RefreshableScreen(
) {
val statusBar = WindowInsets.statusBars.only(WindowInsetsSides.Top).asPaddingValues()
val navigationBars = WindowInsets.navigationBars.asPaddingValues()
val context = LocalContext.current
val state = rememberPullRefreshState(viewModel.isRefreshing, onRefresh = {
viewModel.refresh(context)
})
Scaffold(
topBar = {
Box(
Expand Down Expand Up @@ -85,24 +91,11 @@ fun RefreshableScreen(
}
}
) { paddingValues ->
val context = LocalContext.current
SwipeRefresh(
Box(
modifier = Modifier
.padding(paddingValues)
.pullRefresh(state, swipeEnabled)
.fillMaxSize(),
state = rememberSwipeRefreshState(viewModel.isRefreshing),
swipeEnabled = swipeEnabled,
// TODO: move onRefresh to signature?
onRefresh = { viewModel.refresh(context) },
indicator = { state, trigger ->
SwipeRefreshIndicator(
state = state,
refreshTriggerDistance = trigger,
backgroundColor = MaterialTheme.colorScheme.background,
contentColor = MaterialTheme.colorScheme.primaryContainer,
scale = true
)
}
) {
Column(
modifier = Modifier
Expand All @@ -111,6 +104,14 @@ fun RefreshableScreen(
.verticalScroll(rememberScrollState()),
content = content
)
PullRefreshIndicator(
viewModel.isRefreshing,
state = state,
modifier = Modifier.align(Alignment.TopCenter),
backgroundColor = MaterialTheme.colorScheme.background,
contentColor = MaterialTheme.colorScheme.primaryContainer,
scale = true
)
}
}
}
Loading

0 comments on commit f5f270c

Please sign in to comment.