Skip to content

Brighten the screen while a QR code is displayed - #387

Open
zachisfine wants to merge 1 commit into
GrapheneOS:mainfrom
zachisfine:increase-qr-code-brightness
Open

zachisfine wants to merge 1 commit into
GrapheneOS:mainfrom
zachisfine:increase-qr-code-brightness

Conversation

@zachisfine

Copy link
Copy Markdown

Problem

The QR code is hard to scan, especially on older devices such as the Pixel 6 and 7 (#290). The reporter's workaround is to raise the screen brightness manually before showing the code and lower it again afterwards.

This matters for both directions of the exchange, since either device can be showing the code:

  • Stage.Auditor — the Auditor shows its challenge QR for the Auditee to scan (runAuditor()).
  • Stage.AuditeeResults — the Auditee shows its attestation QR for the Auditor to scan (auditeeShowAttestation()).

Fix

Brighten the screen for as long as a QR code is being displayed, then restore the user's own brightness.

  • setQrCodeBrightness(true) sets WindowManager.LayoutParams.screenBrightness to BRIGHTNESS_OVERRIDE_FULL for the current window only. This overrides the system brightness while the window is visible without persisting anything or changing the global setting, and it needs no permission.
  • setQrCodeBrightness(false) sets it back to BRIGHTNESS_OVERRIDE_NONE (-1), which returns control to the system setting.

The state is derived from stage rather than tracked separately, so it cannot get out of sync:

  • onResume() calls updateQrCodeBrightness(), which covers entering the activity and returning to it from the scanner. stage is restored from savedInstanceState, so a configuration change or process death re-applies the right brightness.
  • Both QR-producing paths call it directly, because both run after onResume() has already fired: runAuditor() synchronously from the click handler, and auditeeShowAttestation() from the async attestation-generation callback.
  • The Auditor's transition to Stage.Result after a successful scan calls it too, so the screen dims as soon as the code is gone.
  • onPause() restores the brightness unconditionally, so the camera activity, another app, or the lock screen never inherits the override.

Testing

Compiles and ./gradlew build passes. There is no automated test for this: the repo has no instrumentation tests, and window brightness is not observable from a unit test.

Copilot AI balanced review requested due to automatic review settings November 6, 2026 01:18

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

A pending attestation callback can re-enable full brightness after onPause() resets it, so the override needs a resumed-state check in addition to the QR-stage check.

1 open issue
What changed in this PR

This PR improves QR-code scanning in both exchange directions by temporarily increasing the activity window’s brightness without changing the system setting.

Changes:

  • Adds a window-scoped brightness override for Auditor and Auditee QR-code stages.
  • Updates brightness when QR codes appear, after a successful scan, and during activity resume and pause.
File Description
app/​src/​main/​java/​app/​attestation/​auditor/​AttestationActivity.java Adds brightness helpers and connects them to QR-display transitions and activity lifecycle callbacks.

Review effort: Balanced

The QR code is hard to scan at a low screen brightness, especially on older
devices. Brighten the window while the code is on screen and restore the
user's own brightness afterwards.

The brightness follows the stage rather than a separate flag: it is applied
in onResume so it covers entering the activity and returning from the
scanner, and both QR-producing paths apply it directly because they run
after onResume. onPause restores it unconditionally so the camera activity
or another app never inherits the override.

Only a resumed window may be brightened. The attestation is generated on a
background executor and shown from a posted UI callback, which can land
after onPause: onPause restores the user's brightness, and the callback
would then re-apply the override to a window that is no longer resumed. So
updateQrCodeBrightness() also requires an active onResume, tracked by a
resumed flag cleared before onPause's unconditional reset.

Fixes GrapheneOS#290
@zachisfine
zachisfine force-pushed the increase-qr-code-brightness branch from cea47fa to b27aaa2 Compare November 6, 2026 23:17
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