From cbd2adeb98d2e3a88acb8769df2a5a9071f6ad5e Mon Sep 17 00:00:00 2001 From: Chad Date: Mon, 24 Aug 2026 19:26:51 +0000 Subject: [PATCH] Stop overriding Adaptive Brightness on every screen wake applyBrightness() unconditionally forced Settings.System.SCREEN_BRIGHTNESS_MODE to MANUAL every time it ran -- including from reapplyBrightness(), which fires on every ACTION_SCREEN_ON broadcast and every accessibility-service reconnect, and from loadSavedBrightness(), which fires whenever the touch-strip service (re)starts. Neither of those is the user touching a brightness control; both are KompaktX passively restoring its last-known brightness. The net effect: once KompaktX had ever set a brightness (which happens the first time its overlay brightness control is used, and persists across restarts), turning Adaptive Brightness back on in system settings never stuck -- the very next screen wake silently flipped it back to manual. Add a forceManualMode parameter to applyBrightness(), defaulting to true so every direct user gesture (slider drag, sun-icon tap, front-light toggle) keeps forcing manual mode, matching stock Android's own behavior when you drag its brightness slider. The two passive-restore call sites now pass false, so they reapply the physical brightness (still correct) without silently overriding a system setting the user didn't just touch. Scope note: buildBrightnessSection() and buildBrightnessSubPanel() still force manual mode once each, at the top of the function, whenever KompaktX's own brightness UI is displayed (not only when it's touched). That's a smaller, separate quirk left out of this patch to keep it narrowly scoped to the dominant bug -- the continuous every-wake override -- rather than touching every place brightness mode is set. --- .../restore/overlay/OverlayPanelManager.kt | 31 +++++++++++++++---- 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/noti/restore/overlay/OverlayPanelManager.kt b/app/src/main/java/com/noti/restore/overlay/OverlayPanelManager.kt index 282c108..7656e29 100644 --- a/app/src/main/java/com/noti/restore/overlay/OverlayPanelManager.kt +++ b/app/src/main/java/com/noti/restore/overlay/OverlayPanelManager.kt @@ -856,9 +856,10 @@ object OverlayPanelManager { val sp = context.getSharedPreferences("kompaktx_brightness", Context.MODE_PRIVATE) lastManualBrightness = sp.getInt("last_manual_brightness", 128) currentBrightnessTarget = sp.getInt("current_brightness_target", -1) - // If we have a saved target, apply it immediately + // If we have a saved target, apply it immediately — passively, without forcing manual + // brightness mode, since this isn't a user gesture (see applyBrightness's kdoc). if (currentBrightnessTarget >= 0) { - applyBrightness(context.contentResolver, currentBrightnessTarget) + applyBrightness(context.contentResolver, currentBrightnessTarget, forceManualMode = false) } } @@ -2295,11 +2296,25 @@ object OverlayPanelManager { // ─── Helpers ──────────────────────────────────────────────────── - private fun applyBrightness(resolver: android.content.ContentResolver, brightness: Int) { + /** + * @param forceManualMode Whether to also flip the system into manual brightness mode. + * True for a direct user gesture (slider drag, sun-icon tap, front-light toggle) — matching + * stock Android's own "dragging the brightness slider disables Adaptive Brightness" behavior. + * False for a passive reapplication of an already-saved target (screen wake, service + * restart) — those aren't the user touching a brightness control, so they must not silently + * override an Adaptive Brightness setting the user may have turned back on since. + */ + private fun applyBrightness( + resolver: android.content.ContentResolver, + brightness: Int, + forceManualMode: Boolean = true + ) { currentBrightnessTarget = brightness try { - Settings.System.putInt(resolver, Settings.System.SCREEN_BRIGHTNESS_MODE, - Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL) + if (forceManualMode) { + Settings.System.putInt(resolver, Settings.System.SCREEN_BRIGHTNESS_MODE, + Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL) + } Settings.System.putInt(resolver, Settings.System.SCREEN_BRIGHTNESS, brightness) } catch (_: Exception) {} val screenVal = if (brightness <= 0) 0.001f else brightness / 255f @@ -2324,7 +2339,11 @@ object OverlayPanelManager { val ctx = stripContext ?: return val target = currentBrightnessTarget if (target < 0) return - handler.post { applyBrightness(ctx.contentResolver, target) } + // Fires on every screen wake and accessibility-service reconnect — not a user gesture, + // so don't force manual brightness mode here (see applyBrightness's kdoc). This was + // previously the main reason Adaptive Brightness appeared broken while KompaktX was + // installed: every wake silently flipped the system back to manual. + handler.post { applyBrightness(ctx.contentResolver, target, forceManualMode = false) } } /** Update the live brightness slider/icon UI if the panel is currently open. */