Skip to content

BGF: Minor code fixit on callbacks/controllers/command names - #127

Merged
natetrost merged 1 commit into
android:mainfrom
natetrost:main
Nov 15, 2026
Merged

natetrost merged 1 commit into
android:mainfrom
natetrost:main

Conversation

@natetrost

Copy link
Copy Markdown
Contributor

Fix event callback user data, controller status/motion, command names

Fix callback and controller bugs in base_game_framework's system event and game controller managers, and the app command names used in the lifecycle debug log:

  • SystemEventManager::SetMemoryWarningEventCallback stored its user_data into lifecycle_event_user_data_, so the memory callback got a stale pointer and registering it clobbered the lifecycle callback's user_data.
  • GameControllerManager integrated (handset) motion:
    • Report support from Paddleboat_getIntegratedMotionSensorFlags(). integrated_motion_data_ was never set, so GetIntegratedMotionDataSupport() always returned false and SetIntegratedMotionDataCallback() was a no-op.
    • Integrated sensor reporting was enabled unconditionally at init, so the accelerometer and gyroscope were sampled continuously in every app (even agdktunnel idle on its menu). Reporting is now enabled only while an integrated motion callback is registered and disabled when it is cleared.
  • GameControllerManager controller status:
    • Map Paddleboat's JUST_CONNECTED / JUST_DISCONNECTED status callback values. JUST_CONNECTED was treated as inactive, so a newly connected controller was reported to the app as kInactive.
    • Fire status_callback_ for status changes detected in Update(), and only on real changes. If a different controller takes an already active slot (device_id changed, e.g. swapped while stopped), report a disconnect then a connect so its info is refreshed. Clear a slot's data and info on disconnect so held buttons/sticks don't stay stuck.
    • Implement SetConsumeBackButton(), which was declared but never defined (link error if called), via Paddleboat_setBackButtonConsumed.
    • static_assert kMaxControllers <= PADDLEBOAT_MAX_CONTROLLERS, and make GetIntegratedMotionDataSupport() const.
  • PlatformEventAndroid: replace the kGlueCommandStrings array with a switch on NativeAppGlueAppCmd. The array was missing APP_CMD_SOFTWARE_KB_VIS_CHANGED, so every name for commands 6-16 was off by one and command 17 read past the end of the array. The switch names every command and has no default case, so -Wswitch fails the build if a GameActivity update adds one. Out-of-range values log UNKNOWN_APP_CMD.

…names

Fix callback and controller bugs in base_game_framework's system event
and game controller managers, and the app command names used in the
lifecycle debug log:

- SystemEventManager::SetMemoryWarningEventCallback stored its
  user_data into lifecycle_event_user_data_, so the memory callback got
  a stale pointer and registering it clobbered the lifecycle
  callback's user_data.
- GameControllerManager integrated (handset) motion:
  - Report support from Paddleboat_getIntegratedMotionSensorFlags().
    integrated_motion_data_ was never set, so
    GetIntegratedMotionDataSupport() always returned false and
    SetIntegratedMotionDataCallback() was a no-op.
  - Integrated sensor reporting was enabled unconditionally at init, so
    the accelerometer and gyroscope were sampled continuously in every
    app (even agdktunnel idle on its menu). Reporting is now enabled
    only while an integrated motion callback is registered and disabled
    when it is cleared.
- GameControllerManager controller status:
  - Map Paddleboat's JUST_CONNECTED / JUST_DISCONNECTED status callback
    values. JUST_CONNECTED was treated as inactive, so a newly connected
    controller was reported to the app as kInactive.
  - Fire status_callback_ for status changes detected in Update(), and
    only on real changes. If a different controller takes an already
    active slot (device_id changed, e.g. swapped while stopped), report
    a disconnect then a connect so its info is refreshed. Clear a
    slot's data and info on disconnect so held buttons/sticks don't
    stay stuck.
  - Implement SetConsumeBackButton(), which was declared but never
    defined (link error if called), via Paddleboat_setBackButtonConsumed.
  - static_assert kMaxControllers <= PADDLEBOAT_MAX_CONTROLLERS, and
    make GetIntegratedMotionDataSupport() const.
- PlatformEventAndroid: replace the kGlueCommandStrings array with a
  switch on NativeAppGlueAppCmd. The array was missing
  APP_CMD_SOFTWARE_KB_VIS_CHANGED, so every name for commands 6-16 was
  off by one and command 17 read past the end of the array. The switch
  names every command and has no default case, so -Wswitch fails the
  build if a GameActivity update adds one. Out-of-range values log
  UNKNOWN_APP_CMD.

Tested on a Pixel 10 Pro with agdktunnel and temporary test hooks:
- Lifecycle and memory callbacks receive their own user_data (memory
  event from am send-trim-memory RUNNING_CRITICAL).
- dumpsys sensorservice: before this change the idle app held the
  accelerometer and gyroscope; now it holds neither until an integrated
  motion callback is registered. Integrated events arrive with their
  user_data while registered, and stop (and the sensors are released)
  when it is cleared.
- SetConsumeBackButton(false/true) round-trips via
  Paddleboat_getBackButtonConsumed().
- Logcat shows correct names for all lifecycle commands. Removing a
  case from the switch fails the build with -Wswitch.
Controller connect, disconnect and swap paths were not tested (no
physical controller available).
@natetrost
natetrost merged commit fbb898d into android:main Nov 15, 2026
7 checks passed
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