Skip to content

Commit

Permalink
Merge pull request #271 from frknkrc44/fix-compose
Browse files Browse the repository at this point in the history
fix: Try to fix compose crash and some RemoteRootServiceImpl issues
  • Loading branch information
XayahSuSuSu authored Jul 15, 2024
2 parents 24c44ea + 689d27e commit 6c30087
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,10 @@ class MainActivity : AppCompatActivity() {
setContent {
DataBackupTheme {
val navController = rememberNavController()
CompositionLocalProvider(LocalNavController provides navController) {
CompositionLocalProvider(
LocalNavController provides navController,
androidx.lifecycle.compose.LocalLifecycleOwner provides androidx.compose.ui.platform.LocalLifecycleOwner.current,
) {
AnimatedNavHost(
navController = navController,
startDestination = MainRoutes.Dashboard.route,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,16 +311,16 @@ internal class RemoteRootServiceImpl : IRemoteRootService.Stub() {
// https://cs.android.com/android/platform/superproject/+/android-8.0.0_r51:frameworks/base/core/java/android/app/usage/StorageStats.java;l=31
val userDir = "${PathUtil.getPackageUserDir(userHandle.identifier)}/${packageInfo.packageName}"
val userCacheDir = "$userDir/cache"
val userCodeCacheDir = "$userDir}/code_cache"
val userCodeCacheDir = "$userDir/code_cache"
val dataDir = "${PathUtil.getPackageDataDir(userHandle.identifier)}/${packageInfo.packageName}"
val dataCacheDir = "$dataDir/cache"
val dataCodeCacheDir = "$dataDir}/code_cache"
val dataCodeCacheDir = "$dataDir/code_cache"
val obbDir = "${PathUtil.getPackageObbDir(userHandle.identifier)}/${packageInfo.packageName}"
val obbCacheDir = "$obbDir/cache"
val obbCodeCacheDir = "$obbDir}/code_cache"
val obbCodeCacheDir = "$obbDir/code_cache"
val mediaDir = "${PathUtil.getPackageMediaDir(userHandle.identifier)}/${packageInfo.packageName}"
val mediaCacheDir = "$mediaDir/cache"
val mediaCodeCacheDir = "$mediaDir}/code_cache"
val mediaCodeCacheDir = "$mediaDir/code_cache"

val cacheDirSize = FileUtil.calculateSize(userCacheDir) + FileUtil.calculateSize(userCodeCacheDir) +
FileUtil.calculateSize(dataCacheDir) + FileUtil.calculateSize(dataCodeCacheDir) +
Expand All @@ -343,7 +343,7 @@ internal class RemoteRootServiceImpl : IRemoteRootService.Stub() {
stats.appBytes,
stats.cacheBytes,
stats.dataBytes,
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { stats.externalCacheBytes } else { 0 },
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) stats.externalCacheBytes else 0,
)
}

Expand Down
1 change: 1 addition & 0 deletions source/feature/crash/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ dependencies {
// Core
implementation(project(":core:common"))
implementation(project(":core:ui"))
implementation(project(":core:data"))
implementation(project(":core:util"))

// Compose Navigation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import androidx.compose.material.icons.rounded.Warning
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.Scaffold
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment
Expand Down Expand Up @@ -46,39 +47,44 @@ class MainActivity : AppCompatActivity() {

setContent {
DataBackupTheme {
val viewModel = hiltViewModel<IndexViewModel>()
val uiState by viewModel.uiState.collectAsStateWithLifecycle()
CompositionLocalProvider(
androidx.lifecycle.compose.LocalLifecycleOwner provides androidx.compose.ui.platform.LocalLifecycleOwner.current,
) {

LaunchedEffect(null) {
viewModel.emitState(uiState.copy(text = crashInfo))
}
val viewModel = hiltViewModel<IndexViewModel>()
val uiState by viewModel.uiState.collectAsStateWithLifecycle()

Scaffold { innerPadding ->
Column(
modifier = Modifier
.fillMaxWidth()
.paddingHorizontal(PaddingTokens.Level4)
.verticalScroll(rememberScrollState()),
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.spacedBy(PaddingTokens.Level4)
) {
InnerTopSpacer(innerPadding = innerPadding)
LaunchedEffect(null) {
viewModel.emitState(uiState.copy(text = crashInfo))
}

// TopBar
Icon(
imageVector = Icons.Rounded.Warning,
contentDescription = null,
tint = ColorSchemeKeyTokens.OnSurfaceVariant.toColor(),
Scaffold { innerPadding ->
Column(
modifier = Modifier
.size(PaddingTokens.Level7)
.paddingBottom(PaddingTokens.Level2)
)
TopBarTitle(text = stringResource(id = R.string.app_crashed))
.fillMaxWidth()
.paddingHorizontal(PaddingTokens.Level4)
.verticalScroll(rememberScrollState()),
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.spacedBy(PaddingTokens.Level4)
) {
InnerTopSpacer(innerPadding = innerPadding)

// TopBar
Icon(
imageVector = Icons.Rounded.Warning,
contentDescription = null,
tint = ColorSchemeKeyTokens.OnSurfaceVariant.toColor(),
modifier = Modifier
.size(PaddingTokens.Level7)
.paddingBottom(PaddingTokens.Level2)
)
TopBarTitle(text = stringResource(id = R.string.app_crashed))

// Content
LabelSmallText(text = uiState.text, fontFamily = JetbrainsMonoFamily)
// Content
LabelSmallText(text = uiState.text, fontFamily = JetbrainsMonoFamily)

InnerBottomSpacer(innerPadding = innerPadding)
InnerBottomSpacer(innerPadding = innerPadding)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ class MainActivity : AppCompatActivity() {
setContent {
DataBackupTheme {
val navController = rememberNavController()
CompositionLocalProvider(LocalNavController provides navController) {
CompositionLocalProvider(
LocalNavController provides navController,
androidx.lifecycle.compose.LocalLifecycleOwner provides androidx.compose.ui.platform.LocalLifecycleOwner.current,
) {
SetupGraph()
}
}
Expand Down

0 comments on commit 6c30087

Please sign in to comment.