Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ data class TemplatePack(
val templates: List<Template>,
val defaults: ExportDefaults = ExportDefaults(),
// Legacy field for backward compatibility - prefer defaults.defaultTemplateId
@Deprecated("Use defaults.defaultTemplateId instead")
@Deprecated("Use defaults.defaultTemplateId instead", ReplaceWith("defaults.defaultTemplateId"))
val defaultTemplateId: String? = null
) {
init {
Expand All @@ -66,6 +66,7 @@ data class TemplatePack(
* Get the effective default template ID, checking both new and legacy locations.
*/
fun getEffectiveDefaultTemplateId(): String? {
@Suppress("DEPRECATION")
return defaults.defaultTemplateId ?: defaultTemplateId
}

Expand Down Expand Up @@ -161,7 +162,7 @@ data class FullBackup(
val defaults: ExportDefaults = ExportDefaults(),
val settings: ExportedSettings? = null,
// Legacy field for backward compatibility - prefer defaults.defaultTemplateId
@Deprecated("Use defaults.defaultTemplateId instead")
@Deprecated("Use defaults.defaultTemplateId instead", ReplaceWith("defaults.defaultTemplateId"))
val defaultTemplateId: String? = null
) {
init {
Expand All @@ -173,7 +174,9 @@ data class FullBackup(
/**
* Get the effective default template ID, checking both new and legacy locations.
*/
@Suppress("DEPRECATION")
fun getEffectiveDefaultTemplateId(): String? {
@Suppress("DEPRECATION")
return defaults.defaultTemplateId ?: defaultTemplateId
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ class GitHubAppUpdater(
"${appContext.packageName}.provider",
file
)
return Intent(Intent.ACTION_INSTALL_PACKAGE).apply {
return Intent(Intent.ACTION_VIEW).apply {
setDataAndType(uri, APK_MIME_TYPE)
addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ import androidx.compose.material3.rememberModalBottomSheetState
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalClipboardManager
import kotlinx.coroutines.launch
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.platform.LocalClipboard
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.text.font.FontFamily
Expand All @@ -45,7 +47,8 @@ fun TemplateVariablesSheet(
onDismiss: () -> Unit
) {
val sheetState = rememberModalBottomSheetState(skipPartiallyExpanded = true)
val clipboardManager = LocalClipboardManager.current
val clipboardManager = LocalClipboard.current
val scope = rememberCoroutineScope()

ModalBottomSheet(
onDismissRequest = onDismiss,
Expand Down Expand Up @@ -93,7 +96,13 @@ fun TemplateVariablesSheet(
placeholder = key,
description = description,
onCopy = {
clipboardManager.setText(AnnotatedString(key))
scope.launch {
clipboardManager.setClipEntry(
androidx.compose.ui.platform.ClipEntry(
android.content.ClipData.newPlainText("Template Variable", key)
)
)
}
}
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.platform.LocalClipboardManager
import kotlinx.coroutines.launch
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.platform.LocalClipboard
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
Expand Down Expand Up @@ -83,7 +85,8 @@ fun ImportScreen(
val vm = LocalImportViewModel.current
val soundPlayer = LocalSoundPlayer.current
val context = LocalContext.current
val clipboardManager = LocalClipboardManager.current
val clipboardManager = LocalClipboard.current
val scope = rememberCoroutineScope()
val maxImportSizeLabel = remember { formatBytesAsMb(MAX_IMPORT_SIZE_BYTES.toLong()) }
val uiState by vm.uiState.collectAsStateWithLifecycle()

Expand Down Expand Up @@ -196,17 +199,19 @@ fun ImportScreen(
error = uiState.error,
onOpenFile = { vm.onOpenFileRequest() },
onPaste = {
scope.launch {
try {
clipboardManager.getText()?.let {
if (exceedsImportLimit(it.text, MAX_IMPORT_SIZE_BYTES)) {
clipboardManager.getClipEntry()?.let {
val text = it.clipData.getItemAt(0).text.toString()

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Handle non-text clipboard items before importing

ClipData.Item.text may be null for URI/intent clipboard entries, and calling toString() here turns that into the literal string "null". That value is then passed to vm.onPasteContent(...), causing a misleading JSON import error path instead of treating the clipboard as non-text/empty. This regression is user-visible when pasting content copied from apps that publish URI-only clip data.

Useful? React with 👍 / 👎.

if (exceedsImportLimit(text, MAX_IMPORT_SIZE_BYTES)) {
soundPlayer.playBeep()
Toast.makeText(
context,
context.getString(R.string.toast_import_too_large, maxImportSizeLabel),
Toast.LENGTH_LONG
).show()
} else {
vm.onPasteContent(it.text)
vm.onPasteContent(text)
}
} ?: Toast.makeText(context, R.string.toast_clipboard_empty, Toast.LENGTH_SHORT).show()
Comment on lines +202 to 216

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🌐 Web query:

In Android official docs, can ClipData.Item represent Uri/Intent clipboard content, and is ClipData.Item.coerceToText(Context) the recommended way to convert arbitrary clipboard content into text?

💡 Result:

Yes, according to the official Android documentation, ClipData.Item can represent Uri and Intent clipboard content. Constructors exist for Item(Uri uri) and Item(Intent intent), and items can combine text, Intent, and/or URI. The types an individual item can contain explicitly include Text (CharSequence), Intent (arbitrary Intent object), and Uri (URI reference, often content: URI). Yes, ClipData.Item.coerceToText(Context) is the recommended way to convert arbitrary clipboard content into text. The API reference describes it as turning the item into text regardless of its type, with a fallback algorithm: prioritize getText if available; for Uri, attempt to retrieve text stream from content provider or return URI string; for Intent, convert to intent: URI string; otherwise empty string. The Copy and Paste guide explicitly states: "Even if your application only handles text, you can copy non-text data from the clipboard by converting it with the ClipData.Item.coerceToText(android.content.Context) method." The ClipData reference also notes: "If all you want is the textual representation of the clipped data, you can use the convenience method Item.coerceToText." This is presented as the standard convenience approach for text conversion without needing to handle specific MIME types manually.

Citations:


Use coerceToText(context) for arbitrary clipboard content.

  • Issue: ClipData.Item can carry Uri/Intent content, not just text. Reading .text.toString() directly skips the Android-recommended conversion path and assumes raw text exists.
  • Impact: Non-text clipboard entries bypass proper coercion logic; paste feedback becomes inconsistent and valid text conversions are missed.
  • Fix: Read the first item defensively, convert with coerceToText(context) (official Android clipboard API), and treat blank results as empty clipboard.
  • Test: Paste a Uri/image/file-backed clipboard item from another app; confirm it rejects cleanly without attempting raw import.
Suggested fix
-                                        clipboardManager.getClipEntry()?.let {
-                                            val text = it.clipData.getItemAt(0).text.toString()
-                                            if (exceedsImportLimit(text, MAX_IMPORT_SIZE_BYTES)) {
+                                        clipboardManager.getClipEntry()?.let { entry ->
+                                            val item = entry.clipData
+                                                .takeIf { it.itemCount > 0 }
+                                                ?.getItemAt(0)
+                                            val text = item?.coerceToText(context)?.toString().orEmpty()
+
+                                            if (text.isBlank()) {
+                                                Toast.makeText(
+                                                    context,
+                                                    R.string.toast_clipboard_empty,
+                                                    Toast.LENGTH_SHORT
+                                                ).show()
+                                            } else if (exceedsImportLimit(text, MAX_IMPORT_SIZE_BYTES)) {
                                                 soundPlayer.playBeep()
                                                 Toast.makeText(
                                                     context,
                                                     context.getString(R.string.toast_import_too_large, maxImportSizeLabel),
                                                     Toast.LENGTH_LONG
                                                 ).show()
                                             } else {
                                                 vm.onPasteContent(text)
                                             }
                                         } ?: Toast.makeText(context, R.string.toast_clipboard_empty, Toast.LENGTH_SHORT).show()
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@app/src/main/java/com/kingpaging/qwelcome/ui/import_pkg/ImportScreen.kt`
around lines 202 - 216, The clipboard handling currently calls
item.clipData.getItemAt(0).text.toString(), which assumes plain text; instead
obtain the first ClipData.Item from clipboardManager.getClipEntry(), call its
coerceToText(context) and treat null/blank as empty/invalid content, then use
that String for exceedsImportLimit(MAX_IMPORT_SIZE_BYTES) and vm.onPasteContent;
if coerceToText yields null/blank, show the R.string.toast_clipboard_empty toast
(and play soundPlayer.playBeep/Toast for oversized content as before) so
Uri/Intent-backed clipboard entries are safely coerced and rejected when not
convertible.

} catch (e: SecurityException) {
Expand All @@ -215,6 +220,7 @@ fun ImportScreen(
Toast.makeText(context, R.string.toast_cannot_access_clipboard, Toast.LENGTH_SHORT).show()
}
}
}
)
}
is ImportStep.Validated -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -892,7 +892,7 @@ private fun ContentEditorField(
Text(
text = stringResource(
R.string.error_template_missing_placeholders,
contentError ?: ""
contentError
),
color = MaterialTheme.colorScheme.error
)
Expand Down
20 changes: 10 additions & 10 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
[versions]
agp = "9.1.0"
coreKtx = "1.17.0"
agp = "9.1.1"
coreKtx = "1.18.0"
appcompat = "1.7.1"
junit = "4.13.2"
junitVersion = "1.3.0"
espressoCore = "3.7.0"
# Lifecycle versions updated to 2.10.0 stable (Jan 2026)
# Includes collectAsStateWithLifecycle and other improvements
lifecycle = "2.10.0"
activityCompose = "1.12.2"
kotlin = "2.2.10"
composeBom = "2026.01.00"
datastorePreferences = "1.2.0"
activityCompose = "1.13.0"
kotlin = "2.3.20"
composeBom = "2026.03.01"
datastorePreferences = "1.2.1"
splashscreen = "1.2.0"
qrose = "1.1.0"
kotlinxSerializationJson = "1.10.0"
protobuf = "3.25.5"
kotlinxSerializationJson = "1.11.0"
protobuf = "4.34.1"
protobufPlugin = "0.9.5"
coroutinesTest = "1.10.2"
turbine = "1.2.1"
mockk = "1.14.7"
# Navigation Compose
navigationCompose = "2.9.0"
navigationCompose = "2.9.7"
# Firebase
firebaseBom = "34.8.0"
firebaseBom = "34.12.0"
googleServices = "4.4.4"
firebaseCrashlytics = "3.0.3"

Expand Down
Loading