Skip to content

Refactor media-projection & screenshot handling, improve accessibility and command parsing, add app mappings and tests#61

Merged
Android-PowerUser merged 1 commit intocodex/analyze-technical-debt-and-complexity-o6bm9pfrom
codex/identify-technical-debt-in-app
Mar 26, 2026
Merged

Refactor media-projection & screenshot handling, improve accessibility and command parsing, add app mappings and tests#61
Android-PowerUser merged 1 commit intocodex/analyze-technical-debt-and-complexity-o6bm9pfrom
codex/identify-technical-debt-in-app

Conversation

@Android-PowerUser
Copy link
Copy Markdown
Owner

Motivation

  • Make the MediaProjection / screenshot flow more robust and testable by centralizing launchers, result handling, receivers, and permission logic in MainActivity and ScreenCaptureService.
  • Improve accessibility service stability by guarding against null root nodes and scheduling failures to prevent crashes during command execution.
  • Harden multimodal reasoning logic and UI wiring to avoid duplicate ViewModel initialization, stale error states, and fragile image processing.
  • Provide deterministic app name <-> package mapping and add unit tests for the command parser to prevent regressions.

Description

  • Reworked MainActivity to encapsulate MediaProjection initialization and result handling via initializeMediaProjection, handleMediaProjectionResult, handleWebRtcMediaProjectionResult, handleScreenshotRequest, and handleScreenshotResult, and to register permission/screenshot receivers via registerPermissionLaunchers and registerScreenshotReceivers.
  • Replaced ad-hoc UI dialog conditionals with composable helpers TrialStateDialogs, PaymentMethodDialog, and ApiKeyDialogSection, added keyboard visibility listener setup, and exposed media-projection/accessibility state flows (_isMediaProjectionPermissionGranted, _isAccessibilityServiceEnabled) with improved logging.
  • Tightened ScreenOperatorAccessibilityService by centralizing root-node null checks into currentRootNodeOrHandleMissing, avoiding NPEs and ensuring command queue processing is scheduled safely.
  • Hardened PhotoReasoningScreen and PhotoReasoningViewModel to avoid duplicate initialization, added helper functions (appendUserAndPendingModelMessages, appendErrorMessage, clearStaleErrorState, routeProviderSpecificReasoning, reasonInLiveMode, reasonInRegularMode, buildPromptWithScreenInfo), improved offline/live reasoning checks, safer image loading, and more robust error handling and logging.
  • Refactored AppNamePackageMapper to use a new internal AppMappings object for variations/manual mappings and added normalization/query helpers to improve accuracy and caching.
  • Cleaned and modernized CommandParser buffer handling with synchronized methods, better logging via logCommandDetails, and added a unit test file CommandParserTest.kt to validate parsing and buffer semantics.
  • Minor resource tweak in data_extraction_rules.xml to include/exclude common backup domains and small cleanups/organizing imports across changed files.

Testing

  • Ran unit tests with ./gradlew test and the new CommandParserTest suite passed successfully.
  • Verified the project builds with ./gradlew assembleDebug and reported successful build artifacts creation.

Codex Task

Copy link
Copy Markdown

@amazon-q-developer amazon-q-developer bot left a comment

Choose a reason for hiding this comment

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

This PR implements code refactoring and cleanup focused on improving code organization and readability. The changes extract helper methods, improve null safety checks, and remove unnecessary comments. The refactoring maintains the existing functionality while making the code more maintainable. No blocking defects were found - the code has proper error handling, state management, and follows good practices.


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.

@Android-PowerUser Android-PowerUser merged commit d9bd498 into codex/analyze-technical-debt-and-complexity-o6bm9p Mar 26, 2026
1 check passed
@Android-PowerUser Android-PowerUser deleted the codex/identify-technical-debt-in-app branch March 26, 2026 10:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant