Skip to content

fix(haptics): expire stale audio output - #84

Merged
qiin2333 merged 2 commits into
masterfrom
codex/harmony-music-transients
Jul 26, 2026
Merged

fix(haptics): expire stale audio output#84
qiin2333 merged 2 commits into
masterfrom
codex/harmony-music-transients

Conversation

@qiin2333

@qiin2333 qiin2333 commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

改了啥呀

  • 为连续音频振动增加 1200 ms 输出安全 watchdog,每次有效输出都会重新续租
  • 到期后统一清理机身与 USB 手柄的音频振动来源
  • 使用 epoch 隔离旧定时器,避免旧 watchdog 误停新一轮振动
  • 只清理音频来源,游戏本身的 rumble 继续参与混合,不会被顺手停掉

为啥要改

游戏模式静音或信号中断时,USB 手柄可能一直保持最后一次电机值,部分机身马达也可能没有按预期自然结束;此前只能等下一帧信号触发重算。现在给这种赖着不走的杂鱼残留状态加一道输出层兜底,不改 SDK 节拍、强度或场景算法。

验证

  • npm run check
  • node hvigorw.js assembleHap --mode module -p module=entry@default -p product=default --no-daemon
  • HAP 构建成功;现有 ArkTS 警告不涉及本次修改

Summary by CodeRabbit

  • 问题修复
    • 增加持续振动输出保护机制,在设备或 USB 振动未按预期停止时自动清理,避免振动持续输出。
    • 停止所有振动时同步取消相关保护计时,防止延迟操作重复触发。

@coderabbitai

coderabbitai Bot commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@qiin2333, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 51 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: adf03194-be6f-4270-adc0-191be8427165

📥 Commits

Reviewing files that changed from the base of the PR and between ffe1033 and c2a85e7.

📒 Files selected for processing (1)
  • entry/src/main/ets/service/AudioVibrationService.ets
📝 Walkthrough

Walkthrough

AudioVibrationService 新增持续振动输出看门狗,在满足持续输出条件时启动超时定时器,并通过 epoch 校验和停止流程取消过期回调。

Changes

持续输出看门狗

Layer / File(s) Summary
看门狗状态与触发
entry/src/main/ets/service/AudioVibrationService.ets
新增看门狗超时常量、定时器状态和 epoch,并在持续输出达到最低强度阈值时启动看门狗。
看门狗取消与停止清理
entry/src/main/ets/service/AudioVibrationService.ets
新增看门狗启停逻辑,通过 epoch 校验避免旧回调误触发,并在 stopAll() 中取消待执行定时器。

Estimated code review effort: 2 (Simple) | ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 标题准确概括了本次为音频触觉输出增加过期清理机制的主要改动。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/harmony-music-transients

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@qiin2333
qiin2333 marked this pull request as ready for review July 26, 2026 06:30

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@entry/src/main/ets/service/AudioVibrationService.ets`:
- Around line 219-222: 在 renderFrame 的所有提前返回路径(包括幅度去抖和节流判断)之前,针对 continuous 达到
AudioVibrationService.MINIMUM_INTENSITY 且 isDeviceSourceActive 或
isUsbSourceActive 为真的有效持续帧调用
armContinuousOutputWatchdog();保留现有提交路径中的调用,以覆盖首次输出场景。
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 47473993-8c41-4a4a-b8f6-2b80d201defa

📥 Commits

Reviewing files that changed from the base of the PR and between 7e81fde and ffe1033.

📒 Files selected for processing (1)
  • entry/src/main/ets/service/AudioVibrationService.ets

Comment on lines +219 to +222
if (continuous >= AudioVibrationService.MINIMUM_INTENSITY &&
(this.isDeviceSourceActive || this.isUsbSourceActive)) {
this.armContinuousOutputWatchdog();
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

稳定持续输出会在 1200 ms 后被误停。

renderFrame 在 Line 166-170 的幅度去抖、Line 162-165 或 Line 179 的节流路径中会提前返回,因此稳定的持续输出帧不会执行这里的 armContinuousOutputWatchdog()。结果是看门狗只在首次提交后启动,约 1200 ms 后便调用 stopAll(),即使有效持续帧仍在到达也会清除振动。

请在这些提前返回之前,针对强度达到最低阈值且已有活动来源的有效持续帧刷新看门狗;保留此处调用以覆盖首次提交输出的场景。

建议修复
     if (!hasTransient &&
         selected < AudioVibrationService.MINIMUM_INTENSITY) {
       if (continuousChanged || hasStop) this.stopAll();
       return;
     }

+    if (continuous >= AudioVibrationService.MINIMUM_INTENSITY &&
+        (this.isDeviceSourceActive || this.isUsbSourceActive)) {
+      this.armContinuousOutputWatchdog();
+    }
+
     const now = Date.now();
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (continuous >= AudioVibrationService.MINIMUM_INTENSITY &&
(this.isDeviceSourceActive || this.isUsbSourceActive)) {
this.armContinuousOutputWatchdog();
}
if (!hasTransient &&
selected < AudioVibrationService.MINIMUM_INTENSITY) {
if (continuousChanged || hasStop) this.stopAll();
return;
}
if (continuous >= AudioVibrationService.MINIMUM_INTENSITY &&
(this.isDeviceSourceActive || this.isUsbSourceActive)) {
this.armContinuousOutputWatchdog();
}
const now = Date.now();
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@entry/src/main/ets/service/AudioVibrationService.ets` around lines 219 - 222,
在 renderFrame 的所有提前返回路径(包括幅度去抖和节流判断)之前,针对 continuous 达到
AudioVibrationService.MINIMUM_INTENSITY 且 isDeviceSourceActive 或
isUsbSourceActive 为真的有效持续帧调用
armContinuousOutputWatchdog();保留现有提交路径中的调用,以覆盖首次输出场景。

@qiin2333
qiin2333 merged commit 9f30692 into master Jul 26, 2026
2 checks passed
@qiin2333
qiin2333 deleted the codex/harmony-music-transients branch July 26, 2026 06:50
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