feat: Implement Pocket Detection for turning off the flashlight#474
Open
Mudit200408 wants to merge 2 commits into
Open
feat: Implement Pocket Detection for turning off the flashlight#474Mudit200408 wants to merge 2 commits into
Mudit200408 wants to merge 2 commits into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
How Pocket Detection Work:
Listen to Sensor:
• When app start accessibility service
(ScreenOffAccessibilityService.kt), it registers to listen to the
Proximity Sensor.
Detect Pocket Block:
• In onSensorChanged () , it reads distance from the sensor: val isBlocke
= distance < maxRange da distance < 5f
• If distance is less than 5cm, sensor is Blocked (phone is face down or insi
pocket).
Trigger Timer:
• If user has Pocket detection enabled, proximity sensor is Blocked, and
flashlight is currently ON:
• Service calls schedulePocketFlashlightTurn0ff() .
• This schedules a delay timer (1.5 seconds) to turn off the torch.
• If user pulls phone out of pocket before 1.5 seconds, timer is
cancelled so torch stays on!
Turn Off Torch:
• When 1.5-second timer fires, it double-checks if proximity is still blocked
and torch is still on.
• If yes, it calls flashlightHandler.toggleFlashlight() to turn it OFF!