Skip to content

Migrate hinge angle injection to sensors simulator#2643

Open
dimorinny wants to merge 1 commit into
google:mainfrom
dimorinny:main
Open

Migrate hinge angle injection to sensors simulator#2643
dimorinny wants to merge 1 commit into
google:mainfrom
dimorinny:main

Conversation

@dimorinny
Copy link
Copy Markdown
Contributor

The cuttlefish_sensor_injection tool does not work with goldfish multihal sensors, meaning hinge angle changes currently have no effect

To fix this, redirect WebRTC hinge angle updates to the sensors simulator instead.

Test: hinge angle is updated from web ui
Bug: 517370262

@dimorinny dimorinny added the kokoro:run Run e2e tests. label Jun 2, 2026
@GoogleCuttlefishTesterBot GoogleCuttlefishTesterBot removed the kokoro:run Run e2e tests. label Jun 2, 2026
@dimorinny dimorinny added the kokoro:force-run Trigger a presubmit build unconditionally. label Jun 2, 2026
@GoogleCuttlefishTesterBot GoogleCuttlefishTesterBot removed the kokoro:force-run Trigger a presubmit build unconditionally. label Jun 2, 2026
Comment on lines +216 to +218
auto sensors_data = sensors_simulator_.GetSensorsData(mask);
std::lock_guard<std::mutex> lock(report_mtx_);
auto result = UpdateSensorsHal(sensors_data, data_channel_, mask);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I see that this was moved from data_reporter_thread_, but note abseil.io/tips/232

Use type deduction only if it makes the code clearer to readers who aren’t familiar with the project, or if it makes the code safer. Do not use it merely to avoid the inconvenience of writing an explicit type.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Agreed with making sensors_data explicit (std::string) above, the type isn't obvious from GetSensorsData, but I kept result as auto since auto result = …; if (!result.ok()) for Result<void> is the idiom used throughout this file and the wider codebase. Happy to spell it out too if you'd rather go the other way.

Comment thread base/cvd/cuttlefish/host/commands/sensors_simulator/sensors_hal_proxy.cpp Outdated
Comment on lines +148 to +150
if (on_change_callback_) {
on_change_callback_(1 << kHingeAngle0Id);
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is there anything else that should also invoke this new callback? SetMotion also affects state and seems relevant to something called "on change callback".

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch, you're right it's odd for a "changed" callback to fire only from SetHingeAngle.

Context: the HAL proxy splits sensors into continuous (kContinuousModeSensors, streamed to the guest every cycle) and on-change (kOnChangeSensors, currently just the hinge angle). Motion sensors are continuous, so the polling loop already reports them regularly; there's nothing to push when SetMotion runs.

The catch is that answering "no, SetMotion shouldn't fire it" means teaching the simulator which sensors are continuous vs on-change. But that's the proxy's concept, and leaking it into the simulator is exactly what made this confusing in the first place.

So I made the callback generic instead: both SetMotion and SetHingeAngle just report whatever they changed, and the subscriber passes a mask of what it cares about. The proxy subscribes with kOnChangeSensors, so motion updates get filtered out there and the continuous/on-change policy stays entirely in the proxy where it belongs.

Do you think it looks cleaner now?

Comment thread base/cvd/cuttlefish/host/frontend/webrtc/sensors_handler.cpp Outdated
element.dataset.adb = true;
}
}
element.dataset.adb = true;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should this still be here? If I understand correctly, the code before amounted to something like "if the device state includes hinge_angle, make sure adb is connected."

As written this commit changes it to "always connect to adb," but I would expect "the hinge angle is not sent via adb" to imply "adb no longer matters for sensors, don't set or unset the adb connection requirement."

I may be misunderstanding what the .adb variable is for. FYI @jemoreira

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

From the change perspective this makes sense, I'm agree.

However, after checking the getCustomDeviceStateButtonCb implementation, it looks to me like any action on that panel triggers adbShell('cmd device_state state reset'), meaning ADB is executed regardless of whether we change the hinge angle, the lid, or anything else, so I assume the entire panel should be disabled if ADB isn't available.

Do you think I'm missing something?

The cuttlefish_sensor_injection tool does not work with goldfish
multihal sensors, meaning hinge angle changes currently have no
effect

To fix this, redirect WebRTC hinge angle updates to the sensors
simulator instead.

Test: hinge angle is updated from web ui
Bug: 517370262
Signed-off-by: Dmitrii Merkurev <dimorinny@google.com>
@dimorinny dimorinny added the kokoro:run Run e2e tests. label Jun 3, 2026
@GoogleCuttlefishTesterBot GoogleCuttlefishTesterBot removed the kokoro:run Run e2e tests. label Jun 3, 2026
@dimorinny dimorinny requested a review from Databean June 3, 2026 09:51
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.

3 participants