Skip to content

Conversation

@Dan8Oren
Copy link
Owner

@Dan8Oren Dan8Oren commented Oct 9, 2025

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 = true on 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

Copilot AI review requested due to automatic review settings October 9, 2025 17:51
Copy link

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

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.

Comment on lines +66 to +67
// Check if this delay operation is still valid (not superseded by newer screen events)
if (isActivationPending.get() && delayStartTime.get() == currentTime) {
Copy link

Copilot AI Oct 9, 2025

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.

Copilot uses AI. Check for mistakes.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings October 10, 2025 13:51
Copy link

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

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() {
Copy link

Copilot AI Oct 10, 2025

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.

Suggested change
open class MainActivity : ComponentActivity() {
class MainActivity : ComponentActivity() {

Copilot uses AI. Check for mistakes.
* Manages delayed activation of microphone functionality when screen turns on.
* Handles race conditions, state validation, and proper cleanup of delay operations.
*/
open class DelayedActivationManager(
Copy link

Copilot AI Oct 10, 2025

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.

Suggested change
open class DelayedActivationManager(
class DelayedActivationManager(

Copilot uses AI. Check for mistakes.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings October 10, 2025 13:54
Copy link

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

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() {
Copy link

Copilot AI Oct 10, 2025

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.

Suggested change
open class MainActivity : ComponentActivity() {
class MainActivity : ComponentActivity() {

Copilot uses AI. Check for mistakes.
}

private fun updateAllUi() {
protected open fun updateAllUi() {
Copy link

Copilot AI Oct 10, 2025

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.

Suggested change
protected open fun updateAllUi() {
private fun updateAllUi() {

Copilot uses AI. Check for mistakes.
* Manages delayed activation of microphone functionality when screen turns on.
* Handles race conditions, state validation, and proper cleanup of delay operations.
*/
open class DelayedActivationManager(
Copy link

Copilot AI Oct 10, 2025

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.

Suggested change
open class DelayedActivationManager(
class DelayedActivationManager(

Copilot uses AI. Check for mistakes.
Dan8Oren and others added 2 commits October 12, 2025 12:17
* implement hybrid solution for stuck isPausedBySilence state

* removed pausedBySilenceTimestamp

* modified log

* Fixes issue where service would remain stuck in silenced state
Copilot AI review requested due to automatic review settings October 12, 2025 19:07
Copy link

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

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.

@Dan8Oren Dan8Oren changed the base branch from main to new-version-release October 13, 2025 06:26
@Dan8Oren Dan8Oren deleted the branch new-version-release October 13, 2025 06:34
@Dan8Oren Dan8Oren closed this Oct 13, 2025
@Dan8Oren Dan8Oren deleted the Dan8Oren-patch-1 branch October 13, 2025 06:39
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