Skip to content

feat(android): add Oniimai controller, lighting and external-display support - #331

Draft
kyarameru0 wants to merge 4 commits into
TeamMajdata:devfrom
kyarameru0:oniimai-android
Draft

kyarameru0 wants to merge 4 commits into
TeamMajdata:devfrom
kyarameru0:oniimai-android

Conversation

@kyarameru0

Copy link
Copy Markdown

Summary

This adds native Oniimai controller support to the Android game. USB touch and IO4 button input feed the existing game input path, game lighting drives the controller's RGB outputs, and an external display can show the game while the phone displays statistics and controller status.

The implementation runs inside MajdataPlay and does not require root, LSPosed, or NPatch. Settings are available in-game.

Included behavior

  • Controller input: 34 raw touch zones, eight IO4 HID buttons and P1, automatic/saved port selection, and touch-sensitivity settings. Short press edges are retained between game samples; stale input expires and controls must be released after closing settings or regaining focus.
  • Lighting: button/ring LEDs and upper-speaker RGB. Dedicated workers send the latest light state and retry failed LED connections independently of touch input. Speaker color is derived from the button colors because this base has no separate ceiling RGB signal.
  • External display: portrait game output rotated by 90° or 270°, a separate native phone dashboard, and a draggable shortcut for returning to external output. This uses a display exposed by Android, rather than capturing and retransmitting the phone screen.
  • Dashboard and setup: configurable widgets, game statistics, touch/button status, Korean and Simplified Chinese setup, and saved preferences. Final song statistics remain visible through the result screen and reset when leaving results or starting another run.

Implementation

flowchart LR
    USB[Oniimai controller] <--> Bridge[Android USB bridge]
    Bridge <--> Game[Unity input and lighting]
    Game --> Display[External game surface]
    Game --> Stats[Native phone dashboard]
Loading

Java owns USB communication, Android lifecycle, settings and display surfaces. Unity reads atomic input snapshots through JNI and merges them with the existing input path, including the existing C1/C2 center-zone handling. Diagnostics read a separate snapshot so they do not consume gameplay press edges.

Lighting work stays off the UI thread. External surface teardown detaches Unity before releasing the surface. Dashboard updates are throttled, and final statistics are captured before gameplay objects are destroyed.

The main review entry points are OniimaiController.cs, OniimaiFrame.cs, InputSnapshot.java, LedOutput.java, OniimaiDisplay.java, and OniimaiStatsRetention.cs. The developer guide includes source paths, sequence diagrams and build instructions.

Why the frame-rate option is included

Without a fixed rendering target, frame drops and uneven motion were observed on the external display in the tested setup, even when the phone display appeared smooth. This integration defaults to 60fps and offers 120fps for a compatible setup.

The render target and actual display refresh rate are reported separately. A requested 120Hz display mode can fall back to 60Hz when it cannot be applied. Working 120Hz output has not been verified. The setting is a workaround for the observed hardware setup, not a guarantee of uniform frame timing on every device. Unity's Android optimized frame pacing remains disabled in the Oniimai build configuration.

Validation

Validation applies to Oniimai 0.2.18, based on upstream Nightly commit 5e9c2aa9d0aec133c5dcfca9e0dbcc228d39416b.

Check Result
Java regression and HID transport checks 9,060 assertions passed
C# input merge and result retention 186 + 225 checks passed
Upstream renderer validation RawSpriteDrawModeValidation passed; no rendered-image comparison
Android build Unity 6000.3.17f1, ARM64, IL2CPP, OpenGL ES 3; build passed
APK verification Signature and ZIP integrity passed; 42 exported Java sources matched
Physical device The maintainer reported normal operation of the exact released APK on their setup

The 0.2.18 APK and checksum are available for reproduction. The APK uses a separate application ID, net.majdata.majdataplay.oniimai, and retains the test build's debug signing certificate.

Limits and areas for maintainer review

The current implementation is primarily tailored to Oniimai controller setups and is not yet sufficiently isolated for general Android users. Oniimai-specific features and defaults may also take effect for users who do not use an Oniimai controller. Additional changes are needed before upstream integration to make activation explicit, gate controller-specific behavior appropriately, and preserve the existing experience for users without the controller.

  • This integration does not implement Aime/NFC login.
  • Desktop/iOS behavior, working 120Hz output, and a complete USB/display reconnect and lifecycle matrix have not been validated for this snapshot.
  • Android currently uses the native panel's saved 60/120fps choice instead of the profile FPS limit. First-run defaults enable input, automatic connection, LED output and external output. These defaults and the frame-rate setting's ownership need upstream review.
  • Static review identified two USB recovery issues to address: the detach receiver disconnects active controller input/lighting without checking which USB device was removed, and an input transport failure closes the inputs without scheduling a reconnect while the device remains attached. These paths have not been exercised in the reported device test.
  • The current fork includes its own application identity, build configuration and README/download presentation. Those should be adapted to upstream's preferred packaging and documentation before merging.

License and authorship

The upstream GPL-3.0 license and existing dependency and asset notices are retained. The native UI uses artwork and fonts from the MajdataPlay source tree, documented in the asset provenance note.

The Oniimai additions were generated and iterated with OpenAI Codex (AI-generated code) under human direction, with automated checks and maintainer device testing. This disclosure does not describe the authorship of upstream MajdataPlay or third-party dependencies.

Add Oniimai 0.2.18 to the published MajdataPlay Nightly 20260925 base.
Integrate USB touch and IO4 input, button/ring/speaker lighting, rotated
external output, configurable 60/120fps rendering, and the phone dashboard.
Include in-game setup, saved settings, result retention, Android build tools,
and regression checks. Android version: 2.0.3-oniimai.22 (version code 22).

Validation: Android ARM64 IL2CPP APK build, 9,060 Java/HID checks,
186 frame-merge checks, 225 statistics-retention checks, upstream renderer
validation, APK signature and ZIP integrity. Physical-device testing of
this updated snapshot remains pending.
Document the build setup, core implementation paths, input and LED flows,
external-display lifecycle, dashboard statistics, and 60/120fps rationale.
Include architecture and sequence diagrams, code examples, validation
evidence, and a checklist for transferring the change to an upstream PR.
@LeZi9916 LeZi9916 added enhancement New feature or request android Issues specific to Android io Indicates issues related to I/O devices or functionality labels Sep 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

android Issues specific to Android enhancement New feature or request io Indicates issues related to I/O devices or functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants