Skip to content

feat: power button in Button Remap - #1480

Open
jawzf wants to merge 1 commit into
sameerasw:developfrom
jawzf:feat/012-power-button-remap
Open

jawzf wants to merge 1 commit into
sameerasw:developfrom
jawzf:feat/012-power-button-remap

Conversation

@jawzf

@jawzf jawzf commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Description

Adds the Power button to Button Remap. The screen now starts with a button picker (Volume Up | Volume Down | Power) above the Screen Off | Screen On picker. The volume keys work as before.

Power has two sections:

  • Double press always opens the camera with Android's own gesture, which Essentials never changes. The one option is Flip camera with double press: while a camera app is open, a double press switches between the front and back cameras. From anywhere else, a double press just opens the camera.
  • Press and hold is set per screen state: Digital assistant (default), Power menu or Custom actions. The settings button on Digital assistant opens Android's default assistant picker.

How it works:

  • Hold. While both screen states keep the same Android choice (assistant or power menu), Essentials only sets power_button_long_press (5 assistant, 1 power menu) and Android does the rest. When the states differ or Custom actions is picked, it sets it to 0 and runs the hold itself. This needs WRITE_SECURE_SETTINGS; the permission sheet shows otherwise. Turning Button Remap off puts the assistant back, but only if Essentials changed it.
  • Detecting presses. Apps never get the power key, not even through accessibility, so Essentials reads it from the kernel input device through Shizuku or root. That's the same way "Use Shizuku" already works for the volume keys: getevent -pl finds every device with KEY_POWER. PowerPressDetector reports a double press (300 ms window) or a hold (500 ms). The listener only runs with the screen on when a hold is handled by Essentials or camera flip is on.
  • Running a hold. Assistant sends KEYCODE_ASSIST, which opens the default assistant like Android does (ACTION_ASSIST showed a chooser). Power menu opens the power dialog. Custom actions runs the list and puts the screen back the way it was, since Android still toggles the screen on the press.
  • Camera flip (best effort). Android's gesture reopens the camera on the lens it had and doesn't lock the phone. A CameraManager.AvailabilityCallback keeps the last few camera sessions (lens, opened, closed). If a camera was in use at the first press, Essentials waits for Android to reopen it. If it's still on the same lens, Essentials clicks the app's flip button through accessibility, found by view id (camera_switch, …) or description ("Switch camera", …). If no camera was open at the first press, it does nothing, and if no button is found, nothing happens. The toggle says it may not work in every camera app.

Limits:

  • Custom hold actions and camera flip need Shizuku or root, as the hint and toggle say.

Type of change

  • Bug fix
  • New feature
  • UI / visual update
  • Performance improvement
  • Refactoring / cleanup
  • Translations
  • Build / CI tooling

UI changes

1_power_tab

The button picker above the screen picker, and the Power tab: Double press with the flip toggle, Press and hold with its choices.

Checklist

  • The base branch is set to develop (not main).
  • The app builds cleanly locally with ./gradlew assembleDebug (and assembleRelease).
  • Unit tests pass with ./gradlew testDebugUnitTest (new: PowerButtonGesturesTest, PowerGestureTrackerTest, InputDeviceScannerTest, CameraFlipButtonTest).
  • Tested on the Android 17 emulator with Shizuku, using real kernel presses from a uinput power device. Hold: every choice in both screen states, with Android left in charge for matching defaults; restore on remap off. Camera flip with AOSP Camera2: alternated 1 → 10 → 1 → 10 → 1 on repeated double presses; from the home screen it only opens the camera.
  • Tested on a Pixel 11 Pro (Android 17) with Google Camera: from anywhere a double press only opens the camera; inside the camera it flips between back and front; hold choices work with Shizuku.
  • Preferences use SettingsRepository keys and getters/setters.
  • New settings registered in FeatureRegistry.kt: "Flip camera with double press" and the Power press and hold options are in search and open Button Remap on the Power tab.
  • Reuses RoundedCardContainer, SegmentedPicker, RemapActionItem, IconToggleItem, ActionSequenceEditor and the existing permission sheet.
  • New strings are in strings.xml (English only); icons are rounded_* drawables.
  • No new dependencies or manifest permissions. Release APK +12 KB (18,688 → 18,700 KB).

🤖 Generated with Claude Code

Button Remap now starts with a button picker (Volume up, Volume down,
Power) above the Screen off / Screen on picker.

Double press keeps Android's own camera gesture. An optional "Flip
camera with double press" switches between front and back cameras
while a camera app is open, using camera availability to tell whether
a camera was in use at the first press.

Press and hold is set per screen state: Digital assistant, Power menu
or Custom actions. Matching system choices stay with Android; otherwise
Essentials reads the power key through Shizuku or root and runs the
choice itself.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jawzf
jawzf force-pushed the feat/012-power-button-remap branch from ffac88d to 0fbdb95 Compare October 24, 2026 17:17
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.

1 participant