From 3ddb598d4f663501e7d41050ed5b9cacaf20dcd7 Mon Sep 17 00:00:00 2001 From: frknkrc44 Date: Sun, 14 Jul 2024 18:22:00 +0300 Subject: [PATCH 1/3] fix: Try to fix compose crash and some RemoteRootServiceImpl issues --- .../main/kotlin/com/xayah/databackup/MainActivity.kt | 5 ++++- .../core/rootservice/impl/RemoteRootServiceImpl.kt | 10 +++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/source/app/src/main/kotlin/com/xayah/databackup/MainActivity.kt b/source/app/src/main/kotlin/com/xayah/databackup/MainActivity.kt index e0576a2bd4..f7778837e4 100644 --- a/source/app/src/main/kotlin/com/xayah/databackup/MainActivity.kt +++ b/source/app/src/main/kotlin/com/xayah/databackup/MainActivity.kt @@ -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, diff --git a/source/core/rootservice/src/main/kotlin/com/xayah/core/rootservice/impl/RemoteRootServiceImpl.kt b/source/core/rootservice/src/main/kotlin/com/xayah/core/rootservice/impl/RemoteRootServiceImpl.kt index 4bf6625c6d..c183ca81dd 100644 --- a/source/core/rootservice/src/main/kotlin/com/xayah/core/rootservice/impl/RemoteRootServiceImpl.kt +++ b/source/core/rootservice/src/main/kotlin/com/xayah/core/rootservice/impl/RemoteRootServiceImpl.kt @@ -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) + @@ -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, ) } From 35e6f0b4970739ba5441627e0a3d6e220d5c9a8f Mon Sep 17 00:00:00 2001 From: frknkrc44 Date: Mon, 15 Jul 2024 15:38:25 +0300 Subject: [PATCH 2/3] fix: Add compose lifecycle for setup screen --- .../src/main/kotlin/com/xayah/feature/setup/MainActivity.kt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/source/feature/setup/src/main/kotlin/com/xayah/feature/setup/MainActivity.kt b/source/feature/setup/src/main/kotlin/com/xayah/feature/setup/MainActivity.kt index 68d2efbeaf..547db6fa75 100644 --- a/source/feature/setup/src/main/kotlin/com/xayah/feature/setup/MainActivity.kt +++ b/source/feature/setup/src/main/kotlin/com/xayah/feature/setup/MainActivity.kt @@ -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() } } From 689d27e4a71031c1725ab3c72f1def7e155915b4 Mon Sep 17 00:00:00 2001 From: Xayah Date: Mon, 15 Jul 2024 22:01:55 +0800 Subject: [PATCH 3/3] fix: Add compose lifecycle for crash screen Change-Id: Icb6853fed02a6f1b19582126d1fc1358f1fd0f29 --- source/feature/crash/build.gradle.kts | 1 + .../com/xayah/feature/crash/MainActivity.kt | 60 ++++++++++--------- 2 files changed, 34 insertions(+), 27 deletions(-) diff --git a/source/feature/crash/build.gradle.kts b/source/feature/crash/build.gradle.kts index e245487ab0..8d27f4e7b8 100644 --- a/source/feature/crash/build.gradle.kts +++ b/source/feature/crash/build.gradle.kts @@ -12,6 +12,7 @@ dependencies { // Core implementation(project(":core:common")) implementation(project(":core:ui")) + implementation(project(":core:data")) implementation(project(":core:util")) // Compose Navigation diff --git a/source/feature/crash/src/main/kotlin/com/xayah/feature/crash/MainActivity.kt b/source/feature/crash/src/main/kotlin/com/xayah/feature/crash/MainActivity.kt index 149955e3f1..acad44397f 100644 --- a/source/feature/crash/src/main/kotlin/com/xayah/feature/crash/MainActivity.kt +++ b/source/feature/crash/src/main/kotlin/com/xayah/feature/crash/MainActivity.kt @@ -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 @@ -46,39 +47,44 @@ class MainActivity : AppCompatActivity() { setContent { DataBackupTheme { - val viewModel = hiltViewModel() - 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() + 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) + } } } }