2023-04-15 04:12:28 +02:00
|
|
|
package eu.kanade.presentation.more.settings.screen.debug
|
|
|
|
|
2023-04-19 04:59:27 +02:00
|
|
|
import android.os.Build
|
2023-04-15 04:12:28 +02:00
|
|
|
import androidx.compose.runtime.Composable
|
|
|
|
import androidx.compose.runtime.ReadOnlyComposable
|
2023-04-19 04:59:27 +02:00
|
|
|
import androidx.compose.runtime.getValue
|
|
|
|
import androidx.compose.runtime.produceState
|
|
|
|
import androidx.compose.ui.platform.LocalContext
|
|
|
|
import androidx.profileinstaller.ProfileVerifier
|
2023-04-15 04:12:28 +02:00
|
|
|
import cafe.adriel.voyager.navigator.LocalNavigator
|
|
|
|
import cafe.adriel.voyager.navigator.currentOrThrow
|
|
|
|
import eu.kanade.presentation.more.settings.Preference
|
2023-04-19 04:59:27 +02:00
|
|
|
import eu.kanade.presentation.more.settings.PreferenceScaffold
|
2023-07-08 23:47:10 +02:00
|
|
|
import eu.kanade.presentation.more.settings.screen.about.AboutScreen
|
2023-05-13 20:22:02 +02:00
|
|
|
import eu.kanade.presentation.util.Screen
|
2023-04-19 04:59:27 +02:00
|
|
|
import eu.kanade.tachiyomi.util.system.DeviceUtil
|
2023-10-18 04:30:55 +02:00
|
|
|
import eu.kanade.tachiyomi.util.system.WebViewUtil
|
2023-12-26 00:11:22 +01:00
|
|
|
import kotlinx.collections.immutable.mutate
|
|
|
|
import kotlinx.collections.immutable.persistentListOf
|
2023-04-19 04:59:27 +02:00
|
|
|
import kotlinx.coroutines.guava.await
|
2023-11-18 19:54:56 +01:00
|
|
|
import tachiyomi.i18n.MR
|
2023-04-15 04:12:28 +02:00
|
|
|
|
2023-07-30 22:15:21 +02:00
|
|
|
class DebugInfoScreen : Screen() {
|
|
|
|
|
2023-04-15 04:12:28 +02:00
|
|
|
@Composable
|
2023-04-19 04:59:27 +02:00
|
|
|
override fun Content() {
|
|
|
|
val navigator = LocalNavigator.currentOrThrow
|
|
|
|
PreferenceScaffold(
|
2023-11-18 19:54:56 +01:00
|
|
|
titleRes = MR.strings.pref_debug_info,
|
2023-04-19 04:59:27 +02:00
|
|
|
onBackPressed = navigator::pop,
|
|
|
|
itemsProvider = {
|
|
|
|
listOf(
|
|
|
|
Preference.PreferenceItem.TextPreference(
|
|
|
|
title = WorkerInfoScreen.title,
|
2023-07-30 22:15:21 +02:00
|
|
|
onClick = { navigator.push(WorkerInfoScreen()) },
|
2023-04-19 04:59:27 +02:00
|
|
|
),
|
2023-05-28 00:53:11 +02:00
|
|
|
Preference.PreferenceItem.TextPreference(
|
|
|
|
title = BackupSchemaScreen.title,
|
2023-07-30 22:15:21 +02:00
|
|
|
onClick = { navigator.push(BackupSchemaScreen()) },
|
2023-05-28 00:53:11 +02:00
|
|
|
),
|
2023-04-19 04:59:27 +02:00
|
|
|
getAppInfoGroup(),
|
|
|
|
getDeviceInfoGroup(),
|
|
|
|
)
|
|
|
|
},
|
|
|
|
)
|
|
|
|
}
|
2023-04-15 04:12:28 +02:00
|
|
|
|
|
|
|
@Composable
|
2023-04-19 04:59:27 +02:00
|
|
|
private fun getAppInfoGroup(): Preference.PreferenceGroup {
|
|
|
|
return Preference.PreferenceGroup(
|
|
|
|
title = "App info",
|
2023-12-26 00:11:22 +01:00
|
|
|
preferenceItems = persistentListOf(
|
2023-04-19 04:59:27 +02:00
|
|
|
Preference.PreferenceItem.TextPreference(
|
|
|
|
title = "Version",
|
|
|
|
subtitle = AboutScreen.getVersionName(false),
|
|
|
|
),
|
|
|
|
Preference.PreferenceItem.TextPreference(
|
|
|
|
title = "Build time",
|
|
|
|
subtitle = AboutScreen.getFormattedBuildTime(),
|
|
|
|
),
|
|
|
|
getProfileVerifierPreference(),
|
|
|
|
Preference.PreferenceItem.TextPreference(
|
|
|
|
title = "WebView version",
|
|
|
|
subtitle = getWebViewVersion(),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
}
|
2023-04-15 04:12:28 +02:00
|
|
|
|
2023-04-19 04:59:27 +02:00
|
|
|
@Composable
|
|
|
|
@ReadOnlyComposable
|
|
|
|
private fun getWebViewVersion(): String {
|
2023-10-18 04:30:55 +02:00
|
|
|
return WebViewUtil.getVersion(LocalContext.current)
|
2023-04-19 04:59:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Composable
|
|
|
|
private fun getProfileVerifierPreference(): Preference.PreferenceItem.TextPreference {
|
|
|
|
val status by produceState(initialValue = "-") {
|
|
|
|
val result = ProfileVerifier.getCompilationStatusAsync().await().profileInstallResultCode
|
|
|
|
value = when (result) {
|
|
|
|
ProfileVerifier.CompilationStatus.RESULT_CODE_NO_PROFILE -> "No profile installed"
|
|
|
|
ProfileVerifier.CompilationStatus.RESULT_CODE_COMPILED_WITH_PROFILE -> "Compiled"
|
2023-11-05 15:14:57 +01:00
|
|
|
ProfileVerifier.CompilationStatus.RESULT_CODE_COMPILED_WITH_PROFILE_NON_MATCHING ->
|
|
|
|
"Compiled non-matching"
|
2023-04-19 04:59:27 +02:00
|
|
|
ProfileVerifier.CompilationStatus.RESULT_CODE_ERROR_CACHE_FILE_EXISTS_BUT_CANNOT_BE_READ,
|
|
|
|
ProfileVerifier.CompilationStatus.RESULT_CODE_ERROR_CANT_WRITE_PROFILE_VERIFICATION_RESULT_CACHE_FILE,
|
|
|
|
ProfileVerifier.CompilationStatus.RESULT_CODE_ERROR_PACKAGE_NAME_DOES_NOT_EXIST,
|
|
|
|
-> "Error $result"
|
|
|
|
ProfileVerifier.CompilationStatus.RESULT_CODE_ERROR_UNSUPPORTED_API_VERSION -> "Not supported"
|
|
|
|
ProfileVerifier.CompilationStatus.RESULT_CODE_PROFILE_ENQUEUED_FOR_COMPILATION -> "Pending compilation"
|
|
|
|
else -> "Unknown code $result"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Preference.PreferenceItem.TextPreference(
|
|
|
|
title = "Profile compilation status",
|
|
|
|
subtitle = status,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
private fun getDeviceInfoGroup(): Preference.PreferenceGroup {
|
2023-12-26 00:11:22 +01:00
|
|
|
val items = persistentListOf<Preference.PreferenceItem<out Any>>().mutate {
|
|
|
|
it.add(
|
2023-04-26 23:27:44 +02:00
|
|
|
Preference.PreferenceItem.TextPreference(
|
|
|
|
title = "Model",
|
|
|
|
subtitle = "${Build.MANUFACTURER} ${Build.MODEL} (${Build.DEVICE})",
|
|
|
|
),
|
2023-04-19 04:59:27 +02:00
|
|
|
)
|
|
|
|
|
2023-04-26 23:27:44 +02:00
|
|
|
if (DeviceUtil.oneUiVersion != null) {
|
2023-12-26 00:11:22 +01:00
|
|
|
it.add(
|
2023-04-26 23:27:44 +02:00
|
|
|
Preference.PreferenceItem.TextPreference(
|
|
|
|
title = "OneUI version",
|
|
|
|
subtitle = "${DeviceUtil.oneUiVersion}",
|
|
|
|
),
|
|
|
|
)
|
|
|
|
} else if (DeviceUtil.miuiMajorVersion != null) {
|
2023-12-26 00:11:22 +01:00
|
|
|
it.add(
|
2023-04-26 23:27:44 +02:00
|
|
|
Preference.PreferenceItem.TextPreference(
|
|
|
|
title = "MIUI version",
|
|
|
|
subtitle = "${DeviceUtil.miuiMajorVersion}",
|
|
|
|
),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
val androidVersion = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
|
|
|
Build.VERSION.RELEASE_OR_PREVIEW_DISPLAY
|
|
|
|
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
|
|
|
Build.VERSION.RELEASE_OR_CODENAME
|
|
|
|
} else {
|
|
|
|
Build.VERSION.RELEASE
|
|
|
|
}
|
2023-12-26 00:11:22 +01:00
|
|
|
it.add(
|
2023-04-26 23:27:44 +02:00
|
|
|
Preference.PreferenceItem.TextPreference(
|
|
|
|
title = "Android version",
|
|
|
|
subtitle = "$androidVersion (${Build.DISPLAY})",
|
|
|
|
),
|
|
|
|
)
|
2023-04-19 04:59:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return Preference.PreferenceGroup(
|
|
|
|
title = "Device info",
|
|
|
|
preferenceItems = items,
|
|
|
|
)
|
2023-04-15 04:12:28 +02:00
|
|
|
}
|
|
|
|
}
|