-
Notifications
You must be signed in to change notification settings - Fork 2
added Screen-Off behavior configuration #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…ver configuration
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR implements configurable screen-on delay behavior to optimize battery usage during brief screen interactions while maintaining responsive microphone activation for legitimate usage. The implementation provides three behavior modes: Always-On, Delayed Reactivation (default 1.3s), and Stays-Off, with a user-friendly slider interface for configuration.
- Intelligent delay system with configurable delays (0-5000ms) that prevents unnecessary microphone activation during brief screen interactions
- Coroutine-based DelayedActivationManager for robust race condition handling and proper cleanup
- Enhanced UI configuration with visual slider interface showing behavioral zones and immediate preference updates
Reviewed Changes
Copilot reviewed 23 out of 26 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| app/src/main/java/io/github/miclock/service/DelayedActivationManager.kt | Core delay management component with coroutine-based scheduling and state validation |
| app/src/main/java/io/github/miclock/service/MicLockService.kt | Updated service to integrate delayed activation with proper foreground service lifecycle |
| app/src/main/java/io/github/miclock/ui/MainActivity.kt | Enhanced UI with slider configuration and improved start button handling |
| app/src/main/java/io/github/miclock/data/Prefs.kt | Added preference management with slider mapping and validation logic |
| app/src/main/res/layout/activity_main.xml | New slider UI with visual zones for different behavior modes |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| // Check if this delay operation is still valid (not superseded by newer screen events) | ||
| if (isActivationPending.get() && delayStartTime.get() == currentTime) { |
Copilot
AI
Oct 9, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Race condition potential in delay validation check. Between lines 67 and subsequent operations, another thread could modify these atomic values, making the validation unreliable. Consider using a single atomic operation or proper synchronization.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 23 out of 26 changed files in this pull request and generated 4 comments.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| * service state changes via StateFlow to update the UI accordingly. | ||
| */ | ||
| class MainActivity : ComponentActivity() { | ||
| open class MainActivity : ComponentActivity() { |
Copilot
AI
Oct 10, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Making MainActivity open is unusual and could indicate a design issue. If this is for testing purposes, consider using dependency injection or other testing strategies instead of inheritance.
| open class MainActivity : ComponentActivity() { | |
| class MainActivity : ComponentActivity() { |
| * Manages delayed activation of microphone functionality when screen turns on. | ||
| * Handles race conditions, state validation, and proper cleanup of delay operations. | ||
| */ | ||
| open class DelayedActivationManager( |
Copilot
AI
Oct 10, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The class is marked as open but there's no clear indication this is intended for inheritance. If this is solely for testing purposes (as suggested by TestableDelayedActivationManager), consider making it final and using composition or dependency injection for testability.
| open class DelayedActivationManager( | |
| class DelayedActivationManager( |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 23 out of 26 changed files in this pull request and generated 4 comments.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| * service state changes via StateFlow to update the UI accordingly. | ||
| */ | ||
| class MainActivity : ComponentActivity() { | ||
| open class MainActivity : ComponentActivity() { |
Copilot
AI
Oct 10, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Making MainActivity an open class suggests it's designed for inheritance, but there's no clear indication this is intentional. If inheritance is not needed, the class should remain final for better encapsulation.
| open class MainActivity : ComponentActivity() { | |
| class MainActivity : ComponentActivity() { |
| } | ||
|
|
||
| private fun updateAllUi() { | ||
| protected open fun updateAllUi() { |
Copilot
AI
Oct 10, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] The updateAllUi() method is marked as protected and open, but there's no clear inheritance pattern or subclass usage visible in the codebase. This should be private unless there's a documented need for inheritance.
| protected open fun updateAllUi() { | |
| private fun updateAllUi() { |
| * Manages delayed activation of microphone functionality when screen turns on. | ||
| * Handles race conditions, state validation, and proper cleanup of delay operations. | ||
| */ | ||
| open class DelayedActivationManager( |
Copilot
AI
Oct 10, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] The DelayedActivationManager is marked as open class but there's no evidence of inheritance in the codebase. Unless designed for extension, this should be a final class for better encapsulation.
| open class DelayedActivationManager( | |
| class DelayedActivationManager( |
* implement hybrid solution for stuck isPausedBySilence state * removed pausedBySilenceTimestamp * modified log * Fixes issue where service would remain stuck in silenced state
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 29 out of 32 changed files in this pull request and generated 3 comments.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
MicLock v1.1.1: Screen-On Delay & Battery Optimization
Key Changes
• Configurable screen-on delay (0-5000ms, default 1.3s) prevents unnecessary mic activation during brief screen interactions
• Smart cancellation - delay cancels if screen turns off, restarts if screen turns on again during delay
• Battery optimization - reduces power consumption for quick notification/battery checks
• User control - adjustable delay slider with immediate effect, no service restart needed
Critical Bug Fixes
• App Stuck In Paused & Tile unavailable - fixed a bug where the app become stuck in paused state when recording and turning off the screen while recording happens
• Fixed screen-off state management - removed incorrect
isPausedBySilence = trueon screen-off• Corrected service state validation - distinguishes between service running vs mic actively held
• Android 14+ FGS timing - starts foreground service immediately when delay scheduled
• Race condition handling - latest-event-wins strategy for rapid screen state changes
Technical Implementation
• DelayedActivationManager - new coroutine-based component with proper job cancellation
• Enhanced state tracking - separates screen-off pause from silence pause from other-app pause
• Quick Settings tile - shows "Activating..." state during delay, tap to override
• Thread-safe operations - atomic state updates and synchronized access
Version & Documentation
• Version: 1.1.0 → 1.1.1 (versionCode: 1 → 4 - to count past releases)
• Updated docs: README.md, architecture.md, DEV_SPECS.md, CHANGELOG.md
• No breaking changes - existing users get 1.3s default, fully backward compatible
• Comprehensive testing - unit tests for delay logic, race conditions, state validation