Refactor accessibility command queue and utilities; add keyboard/media helpers and multimodal serialization#63
Merged
Android-PowerUser merged 4 commits intocodex/analyze-technical-debt-and-complexity-o6bm9pfrom Mar 29, 2026
Conversation
There was a problem hiding this comment.
This PR implements significant refactoring to improve accessibility command processing, lifecycle management, and code organization. However, critical thread-safety bugs have been identified in the new AccessibilityCommandQueue class that must be fixed before merge.
Critical Issues (Must Fix):
- 🛑 Thread-safety bugs in AccessibilityCommandQueue: The
clearAndUnlock,enqueue,peek,poll,size, andisEmptymethods lack synchronization, which can cause race conditions, lost commands, and ConcurrentModificationExceptions when accessed by multiple threads simultaneously.
Summary:
The refactoring successfully:
- Introduces dedicated abstractions for command queue, service state checking, keyboard visibility, and media projection starting
- Extracts Command sealed class and improves CommandParser with better pattern handling and deduplication
- Adds multimodal helpers for streaming JSON, bitmap serialization, and MainActivity bridge
- Refactors app mapping with structured definitions and string similarity matching
- Improves SharedPreferences handling across utility classes
Once the thread-safety issues are resolved with proper synchronization, this refactoring will significantly improve code maintainability and reliability.
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.
…ueue.kt Co-authored-by: amazon-q-developer[bot] <208079219+amazon-q-developer[bot]@users.noreply.github.com>
…ueue.kt Co-authored-by: amazon-q-developer[bot] <208079219+amazon-q-developer[bot]@users.noreply.github.com>
…ueue.kt Co-authored-by: amazon-q-developer[bot] <208079219+amazon-q-developer[bot]@users.noreply.github.com>
e0681f9
into
codex/analyze-technical-debt-and-complexity-o6bm9p
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
AccessibilityCommandQueueabstraction.MainActivityto simplify lifecycle management and reduce duplicated code.Description
AccessibilityCommandQueue,AccessibilityServiceStateChecker,KeyboardVisibilityObserver, andMediaProjectionServiceStarterto encapsulate queueing, state checks, keyboard detection, and service start logic respectively, and wired them intoMainActivityandScreenOperatorAccessibilityService.ScreenOperatorAccessibilityServiceto useAccessibilityCommandQueueandAccessibilityServiceStateCheckerand updated queue processing logic to use the new API (enqueue,tryAcquireProcessing,releaseProcessing, etc.).Commandsealed class inutil/Command.ktand substantially refactoredCommandParserto be more robust (pattern metadata, overlap handling, single-instance command deduplication and logs).PhotoReasoningSerializationfor streaming JSON and bitmap->Base64 conversion, andMainActivityBridgeto safely accessMainActivitycontext/API key from view models; updatedPhotoReasoningViewModelto use these utilities and to delegate AI calls to the foreground service.AppMappings+AppNamePackageMapper) to use structured definitions and string-similarity matching via a newStringSimilarityutil, improved normalization and caching behavior.ImageUtilscleanup,CoordinateParsersimplification,GenerationSettingsPreferences,ChatHistoryPreferences,SystemMessagePreferences,SystemMessageEntryPreferences, andUserInputPreferencesrefactored for safer SharedPreferences access, default population, and clearer keys/serializers.Testing
./gradlew assembleDebugto verify compilation with the refactor; build succeeded../gradlew test(project unit tests) and static checks; they completed successfully.Codex Task