Device information

master
Zakhar Timoshenko 2 years ago
parent e2b860c4da
commit 98451e55e2
Signed by: Xtimms
SSH Key Fingerprint: SHA256:wH6spYepK/A5erBh7ZyAnr1ru9H4eaMVBEuiw6DSpxI

@ -56,7 +56,8 @@ import javax.inject.Inject
@AndroidEntryPoint
class MainActivity : ComponentActivity() {
@Inject lateinit var coil: ImageLoader
@Inject
lateinit var coil: ImageLoader
override fun onCreate(savedInstanceState: Bundle?) {
enableEdgeToEdge()
@ -146,7 +147,7 @@ fun MainView(
BottomNavBar(
navController = navController,
bottomBarState = bottomBarState,
topBarOffsetY = topBarOffsetY
topBarOffsetY = topBarOffsetY,
)
}
},
@ -170,7 +171,6 @@ fun MainView(
bottom = systemBarsPadding.calculateBottomPadding()
),
topBarHeightPx = topBarHeightPx,
topBarOffsetY = topBarOffsetY,
listState = scroll
)
}
@ -188,7 +188,6 @@ fun MainView(
),
padding = padding,
topBarHeightPx = topBarHeightPx,
topBarOffsetY = topBarOffsetY,
listState = scroll
)
}

@ -65,7 +65,6 @@ fun Navigation(
modifier: Modifier,
padding: PaddingValues,
topBarHeightPx: Float,
topBarOffsetY: Animatable<Float, AnimationVector1D>,
listState: LazyGridState,
) {
@ -128,7 +127,6 @@ fun Navigation(
},
padding = padding,
topBarHeightPx = topBarHeightPx,
topBarOffsetY = topBarOffsetY,
listState = listState
)
}

@ -50,7 +50,6 @@ fun ExploreView(
coil: ImageLoader,
navigateToSource: (MangaSource) -> Unit,
topBarHeightPx: Float,
topBarOffsetY: Animatable<Float, AnimationVector1D>,
listState: LazyGridState,
padding: PaddingValues,
) {
@ -63,7 +62,6 @@ fun ExploreView(
uiState = uiState,
event = viewModel,
topBarHeightPx = topBarHeightPx,
topBarOffsetY = topBarOffsetY,
listState = listState,
padding = padding
)
@ -108,12 +106,7 @@ fun ExploreViewContent(
)
LazyVerticalGrid(
columns = GridCells.Adaptive(minSize = 90.dp),
modifier = listModifier
.collapsable(
state = listState,
topBarHeightPx = topBarHeightPx,
topBarOffsetY = topBarOffsetY,
),
modifier = listModifier,
state = listState,
contentPadding = PaddingValues(
start = padding.calculateStartPadding(layoutDirection) + 8.dp,

@ -1,5 +1,6 @@
package org.xtimms.tokusho.sections.settings.advanced
import android.os.Build
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.runtime.Composable
@ -16,6 +17,7 @@ import org.xtimms.tokusho.R
import org.xtimms.tokusho.core.components.PreferenceItem
import org.xtimms.tokusho.core.components.PreferenceSubtitle
import org.xtimms.tokusho.core.components.ScaffoldWithTopAppBar
import org.xtimms.tokusho.utils.DeviceUtil
import org.xtimms.tokusho.utils.WebViewUtil
import org.xtimms.tokusho.utils.lang.toDateTimestampString
import java.text.DateFormat
@ -62,6 +64,44 @@ fun AdvancedView(
description = getWebViewVersion()
)
}
item {
PreferenceSubtitle(text = stringResource(id = R.string.device_info))
}
item {
PreferenceItem(
title = "Model",
description = "${Build.MANUFACTURER} ${Build.MODEL} (${Build.DEVICE})"
)
}
if (DeviceUtil.oneUiVersion != null) {
item {
PreferenceItem(
title = "OneUI version",
description = "${DeviceUtil.oneUiVersion}"
)
}
}
if (DeviceUtil.miuiMajorVersion != null) {
item {
PreferenceItem(
title = "MIUI version",
description = "${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
}
item {
PreferenceItem(
title = "Android version",
description = "$androidVersion (${Build.DISPLAY})"
)
}
}
}
}

@ -0,0 +1,93 @@
package org.xtimms.tokusho.utils
import android.annotation.SuppressLint
import android.app.ActivityManager
import android.content.Context
import android.os.Build
import androidx.core.content.getSystemService
object DeviceUtil {
val isMiui: Boolean by lazy {
getSystemProperty("ro.miui.ui.version.name")?.isNotEmpty() ?: false
}
/**
* Extracts the MIUI major version code from a string like "V12.5.3.0.QFGMIXM".
*
* @return MIUI major version code (e.g., 13) or null if can't be parsed.
*/
val miuiMajorVersion: Int? by lazy {
if (!isMiui) return@lazy null
Build.VERSION.INCREMENTAL
.substringBefore('.')
.trimStart('V')
.toIntOrNull()
}
@SuppressLint("PrivateApi")
fun isMiuiOptimizationDisabled(): Boolean {
val sysProp = getSystemProperty("persist.sys.miui_optimization")
if (sysProp == "0" || sysProp == "false") {
return true
}
return try {
Class.forName("android.miui.AppOpsUtils")
.getDeclaredMethod("isXOptMode")
.invoke(null) as Boolean
} catch (e: Exception) {
false
}
}
val isSamsung: Boolean by lazy {
Build.MANUFACTURER.equals("samsung", ignoreCase = true)
}
val oneUiVersion: Double? by lazy {
try {
val semPlatformIntField = Build.VERSION::class.java.getDeclaredField("SEM_PLATFORM_INT")
val version = semPlatformIntField.getInt(null) - 90000
if (version < 0) {
1.0
} else {
((version / 10000).toString() + "." + version % 10000 / 100).toDouble()
}
} catch (e: Exception) {
null
}
}
val invalidDefaultBrowsers = listOf(
"android",
"com.huawei.android.internal.app",
"com.zui.resolver",
)
/**
* ActivityManager#isLowRamDevice is based on a system property, which isn't
* necessarily trustworthy. 1GB is supposedly the regular threshold.
*
* Instead, we consider anything with less than 3GB of RAM as low memory
* considering how heavy image processing can be.
*/
fun isLowRamDevice(context: Context): Boolean {
val memInfo = ActivityManager.MemoryInfo()
context.getSystemService<ActivityManager>()!!.getMemoryInfo(memInfo)
val totalMemBytes = memInfo.totalMem
return totalMemBytes < 3L * 1024 * 1024 * 1024
}
@SuppressLint("PrivateApi")
private fun getSystemProperty(key: String?): String? {
return try {
Class.forName("android.os.SystemProperties")
.getDeclaredMethod("get", String::class.java)
.invoke(null, key) as String
} catch (e: Exception) {
null
}
}
}

@ -79,4 +79,5 @@
<string name="build_time">Build time</string>
<string name="webview_version">WebView version</string>
<string name="advanced_page">Dump crash logs, debug info</string>
<string name="device_info">Device info</string>
</resources>
Loading…
Cancel
Save