Skip to content

Add JM21 Physical Key Event Logger Android app with MediaSession service and logging UI - #3

Open
mun5mun4 wants to merge 7 commits into
mainfrom
codex/develop-physical-key-event-logger-app-o76pp2
Open

Add JM21 Physical Key Event Logger Android app with MediaSession service and logging UI#3
mun5mun4 wants to merge 7 commits into
mainfrom
codex/develop-physical-key-event-logger-app-o76pp2

Conversation

@mun5mun4

Copy link
Copy Markdown
Owner

Motivation

  • Add a small Android test app to capture and analyze physical media/volume key delivery behavior for FiiO JM21 (Android 13) devices.
  • Provide multiple capture paths (MediaSessionService, BroadcastReceiver, and Activity.dispatchKeyEvent) and record environmental context to help reproduce delivery differences when screen/lock/app state changes.

Description

  • Introduce a new Android application module implementing a foreground MediaSessionService (KeyLoggerService) that plays a silent WAV in loop to keep the media session active and captures media key events via onMediaButtonEvent.
  • Add BroadcastReceiver (MediaButtonEventReceiver) and Activity-level capture (MainActivity.dispatchKeyEvent) so events from different delivery paths are recorded, and create DeviceStateProvider to snapshot environment state.
  • Add in-memory logging with KeyEventLogRepository, domain models in KeyEventModels, CSV export (exportToCsv), and a Compose UI in MainActivity to control service/logging and inspect/save logs; include MP3 open/play/seek helpers for manual tests.
  • Add project metadata: AndroidManifest.xml, Gradle config (build.gradle.kts, app/build.gradle.kts, settings.gradle.kts, gradle.properties), README.md, and detailed docs/TEST_PROCEDURE.md for manual test instructions.

Testing

  • No automated tests or unit/instrumentation tests were added or executed as part of this change.

Codex Task

@chatgpt-codex-connector

Copy link
Copy Markdown

💡 Codex Review

downTimestamps.putIfAbsent(event.keyCode, now)
null
}
KeyEvent.ACTION_UP -> {
downTimestamps.remove(event.keyCode)?.let { now - it }

P1 Badge Track hold timing by source/device, not only keycode

downTimestamps is keyed only by event.keyCode, but this app intentionally logs the same physical press via Activity, BroadcastReceiver, and MediaSession paths. When multiple paths record ACTION_DOWN for one key, the first ACTION_UP removes the shared timestamp and subsequent ACTION_UP entries from other paths get holdDurationMs as null (or an incorrect value), which corrupts per-path hold-duration analysis. Use a composite key (e.g., source + deviceId + keyCode) or derive duration from each event’s downTime/eventTime to keep measurements independent.


<receiver
android:name=".MediaButtonEventReceiver"
android:exported="true">

P2 Badge Make media-button receiver non-exported

The media-button receiver is exported and onReceive accepts any ACTION_MEDIA_BUTTON intent payload, then logs it as a key event. That lets any third-party app send an explicit broadcast with crafted EXTRA_KEY_EVENT values, polluting the experiment logs (and triggering service starts) without real hardware input. Restrict this receiver to trusted callers by setting it non-exported or guarding it with an appropriate permission/caller check.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

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