Skip to content

Fix volume shortcut with stale preferred flashlight levels - #148

Merged
cyb3rko merged 2 commits into
cyb3rko:mainfrom
isaacweber613:agent/fix-stale-preferred-level
Aug 11, 2026
Merged

cyb3rko merged 2 commits into
cyb3rko:mainfrom
isaacweber613:agent/fix-stale-preferred-level

Conversation

@isaacweber613

@isaacweber613 isaacweber613 commented Aug 2, 2026 •

Copy link
Copy Markdown
Contributor

Problem

FlashDim can keep a preferred flashlight level that the current device no longer supports. This can happen in two common ways:

  • An Android update lowers the number of flashlight strength levels, such as a Pixel changing from 45 supported levels to 21 while FlashDim still has 45 selected.
  • Android restores FlashDim's settings onto a new phone whose flashlight has a lower maximum than the previous phone.

This creates a particularly confusing failure in the volume-button shortcut:

  • The FlashDim app can still turn the flashlight on and off.
  • Pressing both volume buttons while the flashlight is off does not turn it on.
  • Pressing both volume buttons while the flashlight is on still turns it off.

The shortcut's on-path passes the stale preferred level to turnOnTorchWithStrengthLevel(), which rejects a level above the device's current maximum. The off-path does not pass a strength level, so it continues to work.

What changed

  • Clamp a requested preferred level to the camera's current Camera2 maximum before turning the flashlight on.
  • Apply the same validation to the volume-button service and the linked Quick Settings tile.
  • Normalize the saved preferred level when the app discovers that the device's maximum has changed.
  • Fall back to regular torch mode when strength levels are unavailable.

This preserves the user's linked-level setting while preventing an old or restored value from breaking flashlight activation.

Related issue

Addresses the stale 45 versus new 21 level failure reported in #146.

Validation

Tested with the upstream app on an Android 17 / API 37 Pixel 10 Pro XL emulator profile using simultaneous kernel-level volume-up and volume-down events.

Baseline reproduction with preferred level 45 and current maximum 10:

  1. App controls turned the flashlight on and off normally.
  2. With the flashlight off, the service logged Both volume buttons pressed, but the flashlight stayed off.
  3. With the flashlight on, the same volume-button chord turned it off.

Patched behavior with the same stale 45 preference:

  1. The volume-button chord turned the flashlight on at the valid maximum level 10.
  2. The next identical chord turned it off.
  3. Opening the app normalized the saved preferred level from 45 to 10.
  4. :app:assembleDebug completed successfully.

@isaacweber613 isaacweber613 changed the title Fix volume shortcut when Android lowers flashlight levels Fix volume shortcut with stale preferred flashlight levels Aug 2, 2026
@isaacweber613
isaacweber613 marked this pull request as ready for review August 2, 2026 16:15
@cyb3rko
cyb3rko force-pushed the agent/fix-stale-preferred-level branch from acb44be to 0d0ee14 Compare August 11, 2026 21:16
@cyb3rko
cyb3rko merged commit 917863b into cyb3rko:main Aug 11, 2026
2 checks passed
@cyb3rko

cyb3rko commented Aug 11, 2026

Copy link
Copy Markdown
Owner

@isaacweber613 Thank you!

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