Termux RUN_COMMAND direkt anfragen und Senden bis Genehmigung verzögern#111
Conversation
There was a problem hiding this comment.
Summary
This PR refactors the Termux RUN_COMMAND permission handling to skip the checkSelfPermission pre-check and always call requestPermissions directly, aligning with MiXplorer's approach to avoid false GRANTED results on some devices.
Critical Issue Found
Logic Error in PhotoReasoningScreen (Line 458-461): The code incorrectly treats a null MainActivity reference as a permission denial, incrementing the denial counter when it's actually a lifecycle issue. This can cause users to be redirected to app settings prematurely without ever denying the permission.
Changes Review
MainActivity.kt: The new requestTermuxRunCommandPermission function correctly implements the direct permission request flow using the deprecated but necessary onRequestPermissionsResult for this use case. The callback handling is clean.
PhotoReasoningScreen.kt: The removal of the local permission checking logic simplifies the code. The addition of isTermuxPermissionRequestPending properly prevents double-sends during permission requests. The button enable/disable logic correctly includes this state.
Please address the critical issue before merging to prevent incorrect denial count increments that could frustrate users.
You can now have the agent implement changes and create commits directly on your pull request's source branch. Simply comment with /q followed by your request in natural language to ask the agent to make changes.
| if (mainActivity == null) { | ||
| handleTermuxRunCommandPermissionDenied() | ||
| return@IconButton | ||
| } |
There was a problem hiding this comment.
🛑 Logic Error: Calling handleTermuxRunCommandPermissionDenied() when mainActivity is null incorrectly increments the permission denial count. This happens when the activity reference is unavailable (lifecycle issue), not when the user denies the permission. This causes the denial counter to increment incorrectly, potentially leading to premature redirection to app settings after 3 failed send attempts even though the user never denied the permission.
| if (mainActivity == null) { | |
| handleTermuxRunCommandPermissionDenied() | |
| return@IconButton | |
| } | |
| if (mainActivity == null) { | |
| Toast.makeText(context, "Activity not available. Please try again.", Toast.LENGTH_SHORT).show() | |
| return@IconButton | |
| } |
Motivation
checkSelfPermission-Vorcheck und ruftrequestPermissionsdirekt auf, weil der Vorcheck auf manchen Geräten fälschlicherweiseGRANTEDzurückgeben kann und dadurch der Systemdialog nie erscheint; dieser PR richtet Screen Operator nach diesem Verhalten aus.Description
MainActivitydie neue FunktionrequestTermuxRunCommandPermission(onResult: (Boolean) -> Unit)dieActivityCompat.requestPermissions(...)verwendet und das Ergebnis überonRequestPermissionsResultan den Callback weiterreicht.TERMUX_RUN_COMMAND_PERMISSIONundREQUEST_CODE_TERMUX_RUN_COMMAND_PERMISSIONinMainActivityhinzu und behandelt das Ergebnis zentral (kein Vorcheck mehr vor dem Request).PhotoReasoningScreenan, sodass das Senden jetzt immer die direkte Request-API ausMainActivityverwendet und das eigentliche Senden erst dann ausführt, wenn die Permission gewährt wurde (sendCurrentQuestion()); bei Ablehnung bleibt die bestehende Denial-/Settings-Logik erhalten.isTermuxPermissionRequestPending) um doppelte Sends zu vermeiden und entfernt den vorherigencheckSelfPermission-Pfad/Launcher-basierten Vorcheck.Testing
./gradlew :app:compileDebugKotlinwurde ausgeführt und lief erfolgreich (BUILD SUCCESSFUL) mit nur Compiler-Warnungen; keine Fehler gefunden.Codex Task