-
Notifications
You must be signed in to change notification settings - Fork 1
Termux-Ausgabe: Wechsel von apply() zu commit() zur Vermeidung einer Race-Condition
#105
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: fix-termux-command-execution-issues
Are you sure you want to change the base?
Changes from all commits
b12b5d9
7efcfc0
b360c25
ab1b413
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,14 +11,20 @@ object TermuxOutputPreferences { | |
| val prefs = context.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE) | ||
| val existing = prefs.getString(KEY_PENDING_OUTPUT, "").orEmpty() | ||
| val merged = if (existing.isBlank()) output else "$existing\n\n$output" | ||
| prefs.edit().putString(KEY_PENDING_OUTPUT, merged).apply() | ||
| val committed = prefs.edit().putString(KEY_PENDING_OUTPUT, merged).commit() | ||
| if (!committed) { | ||
| throw IllegalStateException("Failed to persist pending Termux output") | ||
| } | ||
|
Comment on lines
+15
to
+17
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛑 Crash Risk: Throwing |
||
| } | ||
|
|
||
| fun consumeOutput(context: Context): String? { | ||
| val prefs = context.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE) | ||
| val value = prefs.getString(KEY_PENDING_OUTPUT, "").orEmpty().trim() | ||
| if (value.isBlank()) return null | ||
| prefs.edit().remove(KEY_PENDING_OUTPUT).apply() | ||
| val committed = prefs.edit().remove(KEY_PENDING_OUTPUT).commit() | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛑 Crash Risk: The synchronous |
||
| if (!committed) { | ||
| throw IllegalStateException("Failed to clear consumed Termux output") | ||
| } | ||
|
Comment on lines
+25
to
+27
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛑 Crash Risk: Throwing |
||
| return value | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛑 Crash Risk: The synchronous
commit()call performs blocking I/O on the calling thread. IfappendOutputis called from the main thread, this will freeze the UI and may trigger ANR (Application Not Responding) dialogs, degrading user experience. Consider using a background thread withcommit()or keepingapply()with proper synchronization mechanisms to avoid the race condition without blocking the UI thread.