Skip to content

feat: Implement Pocket Detection for turning off the flashlight#474

Open
Mudit200408 wants to merge 2 commits into
sameerasw:developfrom
Mudit200408:flashlight
Open

feat: Implement Pocket Detection for turning off the flashlight#474
Mudit200408 wants to merge 2 commits into
sameerasw:developfrom
Mudit200408:flashlight

Conversation

@Mudit200408
Copy link
Copy Markdown

How Pocket Detection Work:

  1. Listen to Sensor:
    • When app start accessibility service
    (ScreenOffAccessibilityService.kt), it registers to listen to the
    Proximity Sensor.

  2. 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).

  3. 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!

  4. 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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

2 participants