Skip to content

Precise screen off record#56

Merged
ItosEO merged 3 commits intomainfrom
PreciseScreenOffRecord
Apr 17, 2026
Merged

Precise screen off record#56
ItosEO merged 3 commits intomainfrom
PreciseScreenOffRecord

Conversation

@ItosEO
Copy link
Copy Markdown
Member

@ItosEO ItosEO commented Apr 16, 2026

No description provided.

ItosEO added 2 commits April 16, 2026 19:48
- 在 `Monitor` 中实现精确息屏记录逻辑,通过 `PARTIAL_WAKE_LOCK` 确保息屏下的采样精度。
- 新增 `preciseScreenOffRecordEnabled` 配置项及其对应的 UI 设置界面与中英文描述。
- 优化唤醒锁管理逻辑,支持按需申请与释放,并处理 `FakeContext` 初始化时的线程安全问题。
- 在 `AndroidManifest.xml` 中添加 `WAKE_LOCK` 权限。
- 更新配置编解码及各组件的日志打印,支持新配置项。
- 调整 `preparePreciseScreenOffWakeLock` 的触发时机,仅在功能启用时进行预加载。
- 引入 `preciseScreenOffWakeLockDisabledForCurrentServer` 标志位,在初始化失败时静默禁用该功能,避免在 Binder 回调线程中产生异常。
- 优化唤醒锁状态更新逻辑,增加对初始化状态的校验并完善日志记录。
- 修复 `requirePreciseScreenOffWakeLock` 的异常处理,防止因系统服务不可用导致的潜在崩溃。
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds an optional “Precise screen-off recording” mode that improves sampling interval accuracy during screen-off recording by holding a partial wake lock while the device is non-interactive.

Changes:

  • Introduces a new server setting (preciseScreenOffRecordEnabled) with persistence/codec support and logging.
  • Implements wake-lock lifecycle management in Monitor to hold/release a PARTIAL_WAKE_LOCK only during screen-off recording.
  • Exposes the setting in the app UI (EN + zh-CN) and adds the WAKE_LOCK manifest permission.

Reviewed changes

Copilot reviewed 15 out of 15 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
shared/src/main/java/yangfentuozi/batteryrecorder/shared/config/dataclass/ServerSettings.kt Adds the new preciseScreenOffRecordEnabled field to the server settings model.
shared/src/main/java/yangfentuozi/batteryrecorder/shared/config/SettingsConstants.kt Defines the new boolean config item and preference key.
shared/src/main/java/yangfentuozi/batteryrecorder/shared/config/ServerSettingsCodec.kt Persists/loads the new setting via SharedPreferences and map decoding.
shared/src/main/java/yangfentuozi/batteryrecorder/shared/config/ConfigUtil.kt Includes the new field in server settings logging.
server/src/main/java/yangfentuozi/batteryrecorder/server/recorder/Monitor.kt Adds wake-lock creation + state synchronization logic tied to screen-off recording conditions.
server/src/main/java/yangfentuozi/batteryrecorder/server/Server.kt Wires the new setting into Monitor during config updates.
app/src/main/res/values/strings.xml Adds EN strings for the new toggle and summary.
app/src/main/res/values-zh-rCN/strings.xml Adds zh-CN strings for the new toggle and summary.
app/src/main/java/yangfentuozi/batteryrecorder/ui/viewmodel/SettingsViewModel.kt Adds setter to update/push the new server setting.
app/src/main/java/yangfentuozi/batteryrecorder/ui/screens/settings/SettingsScreen.kt Threads the new setting/state/action through the settings screen.
app/src/main/java/yangfentuozi/batteryrecorder/ui/model/SettingsUiState.kt Adds UI state field for the new toggle.
app/src/main/java/yangfentuozi/batteryrecorder/ui/model/SettingsActions.kt Adds UI action callback for the new toggle.
app/src/main/java/yangfentuozi/batteryrecorder/ui/components/settings/sections/ServerSection.kt Adds the switch UI element in the Server settings section.
app/src/main/java/yangfentuozi/batteryrecorder/App.kt Logs the new setting at app startup.
app/src/main/AndroidManifest.xml Adds android.permission.WAKE_LOCK required for partial wake locks.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +132 to +135
private var preciseScreenOffWakeLock: PowerManager.WakeLock? = null
@Volatile
private var preciseScreenOffWakeLockDisabledForCurrentServer = false
private var lastPreciseScreenOffWakeLockDecisionReason: String? = null
Copy link

Copilot AI Apr 16, 2026

Choose a reason for hiding this comment

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

preciseScreenOffWakeLock is written in requirePreciseScreenOffWakeLock() without synchronization/@Volatile, but read from multiple threads inside @Synchronized methods (and from updatePreciseScreenOffWakeLockState() called by Binder callbacks). Without a happens-before edge, other threads may keep seeing null (or stale state) and skip acquiring/releasing, making the feature unreliable. Consider either marking preciseScreenOffWakeLock as @Volatile or synchronizing all reads/writes on the same monitor (e.g., make requirePreciseScreenOffWakeLock() @Synchronized and only access the field under that lock).

Copilot uses AI. Check for mistakes.
- 提取 `applyConfigInternal` 私有方法,统一管理服务端配置的应用逻辑。
- 优化 `init` 流程,在初始化时直接调用内部方法应用配置,避免不必要的线程切换。
- 在配置应用日志中增加 `source` 参数,便于追踪配置来源。
@ItosEO ItosEO merged commit eea814f into main Apr 17, 2026
1 check 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.

2 participants