Skip to content

fix: screenshot and MediaProjection failures on Android 14+ - #2

Open
debugtalk wants to merge 1 commit into
dondetir:mainfrom
httprunner:main
Open

fix: screenshot and MediaProjection failures on Android 14+#2
debugtalk wants to merge 1 commit into
dondetir:mainfrom
httprunner:main

Conversation

@debugtalk

Copy link
Copy Markdown

Summary

Fix screenshot and MediaProjection failures on Android 14+ by restructuring the consent flow and adding the missing accessibility capability.

Type of Change

  • Bug fix

Changes

  • Add android:canTakeScreenshot="true" to accessibility service config, enabling AccessibilityService.takeScreenshot() fallback on API 30+ (capabilities bitmask was 41 instead of 169 due to missing CAPABILITY_CAN_TAKE_SCREENSHOT)
  • Move getMediaProjection() call into ScreenshotConsentActivity instead of deferring to Service, satisfying Android 15+ requirement that it must be called while a visible Activity exists
  • Defer foreground service MEDIA_PROJECTION type upgrade to after user consent, avoiding SecurityException on OEM ROMs (e.g. ColorOS) that add extra permission requirements
  • Add AtomicBoolean guard to prevent double FGS type upgrade (Activity-side and Service-side callback), with proper reset on MediaProjection session loss and service destroy

Testing

  • Verified on Android 16 Pixel: full MediaProjection path (fast screenshots ~60ms)
  • Verified on Android 14 Oplus: AccessibilityService.takeScreenshot() fallback works when OEM blocks FGS upgrade
  • Re-authorization works after MediaProjection session loss (guard resets correctly)
  • MCP tools (screenshot, get_ui_tree, tap, swipe) all functional via HTTP JSON-RPC on port 7474

Protobuf Changes

No .proto files modified.

Checklist

  • Code follows existing patterns in the codebase
  • No hardcoded device IDs, IP addresses, or personal paths
  • Error messages are actionable
  • Latency impact considered (<100ms target for fast path operations)

- Add canTakeScreenshot to accessibility_service_config.xml to enable
  AccessibilityService.takeScreenshot() fallback on API 30+
- Create MediaProjection inside ScreenshotConsentActivity (Android 15+
  requires getMediaProjection() called while Activity is visible)
- Upgrade foreground service type to MEDIA_PROJECTION after user consent
  instead of at startup (avoids SecurityException on OEM ROMs like ColorOS)
- Add AtomicBoolean guard to prevent double FGS type upgrade and reset
  it on MediaProjection session loss for re-authorization
- Add onMediaProjectionGranted callback for FGS upgrade notification

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant