Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,14 @@ A clear and concise description of what you expected to happen.
**Screenshots**
If applicable, add screenshots to help explain your problem.

**Smartphone (please complete the following information):**
- Device: [e.g. Pixel 11 Pro]
**Device & App Info**
Please open **About (i) → Copy debug info** in Native Alpha and paste the output below (or fill in manually):
```
<!-- Paste debug info here -->
```
- Device (if not using Copy debug info): [e.g. Pixel 11 Pro]
- Android version: [e.g. Android 17]
- App version [In the About (i) screen, e.g. v1.6.3]
- App version [In the About (i) screen, e.g. v1.6.8]

**Additional context**
Add any other context about the problem here.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.cylonid.nativealpha.ui.about

import android.content.ClipData
import android.content.ClipboardManager
import android.content.Intent
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Box
Expand All @@ -20,7 +22,9 @@ import androidx.compose.material.icons.automirrored.rounded.ArrowBack
import androidx.compose.material.icons.automirrored.rounded.KeyboardArrowRight
import androidx.compose.material.icons.automirrored.rounded.OpenInNew
import androidx.compose.material.icons.rounded.AutoAwesome
import androidx.compose.material.icons.rounded.BugReport
import androidx.compose.material.icons.rounded.Code
import androidx.compose.material.icons.rounded.ContentCopy
import androidx.compose.material.icons.rounded.Description
import androidx.compose.material.icons.rounded.Extension
import androidx.compose.material.icons.rounded.Favorite
Expand All @@ -37,6 +41,8 @@ import androidx.compose.material3.IconButtonDefaults
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.MediumFlexibleTopAppBar
import androidx.compose.material3.Scaffold
import androidx.compose.material3.SnackbarHost
import androidx.compose.material3.SnackbarHostState
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
Expand All @@ -45,6 +51,7 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
Expand All @@ -64,6 +71,10 @@ import com.cylonid.nativealpha.ui.components.ReleaseNotesBottomSheet
import com.cylonid.nativealpha.ui.components.RoundedCardContainer
import com.cylonid.nativealpha.ui.components.SettingsActionItem
import com.cylonid.nativealpha.ui.components.SettingsSectionHeader
import com.cylonid.nativealpha.util.DebugInfoFormatter
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import timber.log.Timber

@OptIn(ExperimentalMaterial3Api::class, ExperimentalMaterial3ExpressiveApi::class)
Expand All @@ -77,16 +88,20 @@ fun AboutScreen(

val scrollBehavior = TopAppBarDefaults.exitUntilCollapsedScrollBehavior()
val context = LocalContext.current
val snackbarHostState = remember { SnackbarHostState() }
val coroutineScope = rememberCoroutineScope()
val copiedMessage = stringResource(R.string.about_debug_info_copied)
var releaseNotes by remember { mutableStateOf<com.cylonid.nativealpha.model.ReleaseNotes?>(null) }
androidx.compose.runtime.LaunchedEffect(Unit) {
releaseNotes =
kotlinx.coroutines.withContext(kotlinx.coroutines.Dispatchers.IO) {
withContext(Dispatchers.IO) {
ReleaseNotesRepository.load(context)
}
}

Scaffold(
modifier = modifier.nestedScroll(scrollBehavior.nestedScrollConnection),
snackbarHost = { SnackbarHost(hostState = snackbarHostState) },
topBar = {
MediumFlexibleTopAppBar(
title = {
Expand Down Expand Up @@ -267,6 +282,24 @@ fun AboutScreen(
)
},
)

SettingsActionItem(
title = stringResource(R.string.about_debug_info_title),
description = stringResource(R.string.about_debug_info_desc),
icon = Icons.Rounded.BugReport,
trailingIcon = Icons.Rounded.ContentCopy,
onClick = {
coroutineScope.launch {
val debugText =
withContext(Dispatchers.IO) {
DebugInfoFormatter.format(DebugInfoFormatter.collect(context))
}
val clipboard = context.getSystemService(ClipboardManager::class.java)
clipboard?.setPrimaryClip(ClipData.newPlainText("Native Alpha Debug Info", debugText))
snackbarHostState.showSnackbar(copiedMessage)
}
},
)
}

if (BuildConfig.FLAVOR == "extendedGithub") {
Expand Down
204 changes: 204 additions & 0 deletions app/src/main/kotlin/com/cylonid/nativealpha/util/DebugInfoFormatter.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
package com.cylonid.nativealpha.util

import android.app.LocaleManager
import android.content.Context
import android.os.Build
import android.os.PowerManager
import androidx.webkit.WebViewCompat
import com.cylonid.nativealpha.BuildConfig
import com.cylonid.nativealpha.model.DataManager
import java.io.IOException

/**
* Sanitized diagnostic snapshot of the app, device, OS, WebView, and aggregate settings for bug reports.
*/
data class DebugInfo(
val appVersionName: String,
val appVersionCode: Int,
val buildFlavor: String,
val buildType: String,
val androidRelease: String,
val sdkInt: Int,
val securityPatch: String,
val manufacturer: String,
val brand: String,
val model: String,
val device: String,
val buildDisplay: String,
val romVersion: String?,
val webViewPackage: String?,
val webViewVersion: String?,
val appLocale: String,
val themeMode: String,
val dynamicColor: Boolean,
val ignoringBatteryOptimizations: Boolean?,
val activeWebAppCount: Int,
val sandboxedWebAppCount: Int,
val globalAdblockEnabled: Boolean,
val globalBiometricEnabled: Boolean,
)

/**
* Collects and formats non-PII diagnostic device, WebView, and app information for clipboard sharing.
*/
object DebugInfoFormatter {
/**
* Collects live diagnostic metadata from [context], [Build], [WebViewCompat], and [DataManager].
* Safe to invoke off the main thread because it may query `getprop` for OEM ROM version.
*/
fun collect(
context: Context,
getProperty: (String) -> String? = ::readSystemProperty,
): DebugInfo {
val localeTag = resolveLocaleTag(context)
val webViewPkg = runCatching { WebViewCompat.getCurrentWebViewPackage(context) }.getOrNull()
val powerManager = context.getSystemService(PowerManager::class.java)
val ignoringBattery =
runCatching {
powerManager?.isIgnoringBatteryOptimizations(context.packageName)
}.getOrNull()

val dataManager = DataManager.getInstance()
val settings = runCatching { dataManager.settings }.getOrNull()
val activeApps = runCatching { dataManager.activeWebsites }.getOrDefault(emptyList())
val themeMode =
when (settings?.themeId) {
0 -> "System"
1 -> "Dark"
2 -> "Light"
null -> "Unknown"
else -> "Custom(${settings.themeId})"
}

return DebugInfo(
appVersionName = BuildConfig.VERSION_NAME,
appVersionCode = BuildConfig.VERSION_CODE,
buildFlavor = BuildConfig.FLAVOR,
buildType = BuildConfig.BUILD_TYPE,
androidRelease = Build.VERSION.RELEASE.orEmpty(),
sdkInt = Build.VERSION.SDK_INT,
securityPatch = Build.VERSION.SECURITY_PATCH.orEmpty(),
manufacturer = Build.MANUFACTURER.orEmpty(),
brand = Build.BRAND.orEmpty(),
model = Build.MODEL.orEmpty(),
device = Build.DEVICE.orEmpty(),
buildDisplay = Build.DISPLAY.orEmpty(),
romVersion = detectRomVersion(Build.MANUFACTURER.orEmpty(), getProperty),
webViewPackage = webViewPkg?.packageName,
webViewVersion = webViewPkg?.versionName,
appLocale = localeTag,
themeMode = themeMode,
dynamicColor = settings?.isDynamicColor ?: false,
ignoringBatteryOptimizations = ignoringBattery,
activeWebAppCount = activeApps.size,
sandboxedWebAppCount = activeApps.count { it.isUseContainer },
globalAdblockEnabled = settings?.globalWebApp?.isUseAdblock ?: false,
globalBiometricEnabled = settings?.globalWebApp?.isBiometricProtection ?: false,
)
}

/**
* Formats [info] as a clean multi-line plain-text block suitable for pasting into issue trackers.
*/
fun format(info: DebugInfo): String =
buildString {
appendLine("App: Native Alpha ${info.appVersionName} (${info.appVersionCode}, ${info.buildFlavor}/${info.buildType})")
appendLine("Android: ${info.androidRelease} (API ${info.sdkInt})")
if (info.securityPatch.isNotBlank()) {
appendLine("Security Patch: ${info.securityPatch}")
}
appendLine("Device: ${info.manufacturer} ${info.model} (${info.brand}/${info.device})")
if (!info.romVersion.isNullOrBlank()) {
appendLine("ROM: ${info.romVersion}")
}
if (info.buildDisplay.isNotBlank()) {
appendLine("Build: ${info.buildDisplay}")
}
if (!info.webViewPackage.isNullOrBlank()) {
val versionSuffix =
info.webViewVersion
?.takeIf { it.isNotBlank() }
?.let { " ($it)" }
.orEmpty()
appendLine("WebView: ${info.webViewPackage}$versionSuffix")
}
appendLine("Locale: ${info.appLocale} | Theme: ${info.themeMode} (DynamicColor=${info.dynamicColor})")
if (info.ignoringBatteryOptimizations != null) {
appendLine("Battery Optimization Ignored: ${info.ignoringBatteryOptimizations}")
}
append(
"WebApps: ${info.activeWebAppCount} active (${info.sandboxedWebAppCount} sandboxed) | " +
"Global Adblock=${info.globalAdblockEnabled}, Biometric=${info.globalBiometricEnabled}",
)
}

/**
* Detects common OEM skin / custom ROM version strings from standard system properties.
*/
internal fun detectRomVersion(
manufacturer: String,
getProperty: (String) -> String?,
): String? {
val mfr = manufacturer.trim().lowercase()

val oneUi = formatOneUiVersion(getProperty("ro.build.version.oneui"))
if (oneUi != null) return oneUi
if (mfr == "samsung") {
getProperty("ro.build.PDA")?.takeIf { it.isNotBlank() }?.let { return "One UI ($it)" }
}

getProperty("ro.mi.os.version.name")?.takeIf { it.isNotBlank() }?.let { return "HyperOS $it" }
getProperty("ro.miui.ui.version.name")?.takeIf { it.isNotBlank() }?.let { return "MIUI $it" }

getProperty("ro.build.version.oplusrom")?.takeIf { it.isNotBlank() }?.let {
val label = if (mfr == "oneplus") "OxygenOS" else "ColorOS"
return "$label $it"
}

getProperty("ro.nothing.version.id")?.takeIf { it.isNotBlank() }?.let { return "Nothing OS $it" }
getProperty("ro.lineage.version")?.takeIf { it.isNotBlank() }?.let { return "LineageOS $it" }

return null
}

/**
* Converts Samsung's integer `ro.build.version.oneui` property (e.g. `"80000"`, `"60101"`)
* into a human-readable string (e.g. `"One UI 8.0"`, `"One UI 6.1.1"`).
*/
internal fun formatOneUiVersion(rawVersion: String?): String? {
val code = rawVersion?.trim()?.toIntOrNull() ?: return null
if (code < 10000) return null
val major = code / 10000
val minor = (code % 10000) / 100
val patch = code % 100
return if (patch > 0) "One UI $major.$minor.$patch" else "One UI $major.$minor"
}

private fun resolveLocaleTag(context: Context): String {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
val appLocales = context.getSystemService(LocaleManager::class.java)?.applicationLocales
if (appLocales != null && !appLocales.isEmpty) {
return appLocales.toLanguageTags()
}
}
val locales = context.resources.configuration.locales
return if (!locales.isEmpty) locales[0].toLanguageTag() else "default"
}

private fun readSystemProperty(key: String): String? =
try {
val process =
ProcessBuilder("getprop", key)
.redirectErrorStream(true)
.start()
val output = process.inputStream.bufferedReader().use { it.readText().trim() }
if (process.waitFor() == 0 && output.isNotEmpty()) output else null
} catch (_: IOException) {
null
} catch (_: SecurityException) {
null
} catch (_: InterruptedException) {
Thread.currentThread().interrupt()
null
}
}
3 changes: 3 additions & 0 deletions app/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -187,4 +187,7 @@
<string name="pdf_viewer_loading">PDF wird geladen…</string>
<string name="pdf_viewer_retry">Wiederholen</string>
<string name="press_back_again_to_exit">Erneut „Zurück“ drücken zum Beenden</string>
<string name="about_debug_info_title">Debug-Infos kopieren</string>
<string name="about_debug_info_desc">Geräte-, WebView- und App-Diagnosedaten für Fehlerberichte kopieren</string>
<string name="about_debug_info_copied">Debug-Infos in die Zwischenablage kopiert</string>
</resources>
3 changes: 3 additions & 0 deletions app/src/main/res/values-es/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -188,4 +188,7 @@
<string name="pdf_viewer_loading">Cargando PDF…</string>
<string name="pdf_viewer_retry">Reintentar</string>
<string name="press_back_again_to_exit">Pulsa atrás de nuevo para salir</string>
<string name="about_debug_info_title">Copiar info de depuración</string>
<string name="about_debug_info_desc">Copia el diagnóstico del dispositivo, WebView y la app para informes de error</string>
<string name="about_debug_info_copied">Info de depuración copiada al portapapeles</string>
</resources>
3 changes: 3 additions & 0 deletions app/src/main/res/values-it/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -187,4 +187,7 @@
<string name="pdf_viewer_loading">Caricamento PDF…</string>
<string name="pdf_viewer_retry">Riprova</string>
<string name="press_back_again_to_exit">Premi di nuovo indietro per uscire</string>
<string name="about_debug_info_title">Copia info di debug</string>
<string name="about_debug_info_desc">Copia la diagnostica di dispositivo, WebView e app per le segnalazioni</string>
<string name="about_debug_info_copied">Info di debug copiate negli appunti</string>
</resources>
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -191,4 +191,7 @@
<string name="pdf_viewer_loading">Loading PDF…</string>
<string name="pdf_viewer_retry">Retry</string>
<string name="press_back_again_to_exit">Press back again to exit</string>
<string name="about_debug_info_title">Copy debug info</string>
<string name="about_debug_info_desc">Copy device, WebView, and app diagnostics for bug reports</string>
<string name="about_debug_info_copied">Debug info copied to clipboard</string>
</resources>
Loading