From b27aaa2b0b85cc006587c7a99f1283d0591786fc Mon Sep 17 00:00:00 2001 From: zachisfine <131436334+zachisfine@users.noreply.github.com> Date: Fri, 6 Nov 2026 18:17:05 -0500 Subject: [PATCH] brighten the screen while a QR code is displayed 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 #290 --- .../auditor/AttestationActivity.java | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/app/src/main/java/app/attestation/auditor/AttestationActivity.java b/app/src/main/java/app/attestation/auditor/AttestationActivity.java index f7cd4c593..ffe57e89e 100644 --- a/app/src/main/java/app/attestation/auditor/AttestationActivity.java +++ b/app/src/main/java/app/attestation/auditor/AttestationActivity.java @@ -21,6 +21,7 @@ import android.view.View; import android.view.ViewGroup; import android.view.ViewTreeObserver; +import android.view.WindowManager; import android.widget.LinearLayout; import androidx.activity.EdgeToEdge; @@ -87,6 +88,7 @@ private enum Stage { } private Stage stage = Stage.None; + private boolean resumed; private boolean auditeePairing; private byte[] auditeeSerializedAttestation; private byte[] auditorChallenge; @@ -114,6 +116,7 @@ private enum Stage { } else if (stage == Stage.Auditor) { stage = Stage.Result; binding.content.imageview.setVisibility(View.GONE); + updateQrCodeBrightness(); handleAttestation(contentsBytes); } else if (stage == Stage.EnableRemoteVerify) { stage = Stage.None; @@ -268,6 +271,7 @@ public void handleOnBackPressed() { @Override protected void onResume() { super.onResume(); + resumed = true; final boolean isRemoteVerifyEnabled = RemoteVerifyJob.isEnabled(this); int visibility = View.VISIBLE; if (isRemoteVerifyEnabled) { @@ -282,6 +286,39 @@ protected void onResume() { stage = Stage.EnableRemoteVerify; startQrScanner(); }); + updateQrCodeBrightness(); + } + + @Override + protected void onPause() { + super.onPause(); + resumed = false; + setQrCodeBrightness(false); + } + + /** + * The QR code is the only thing on screen that another device's camera has to read, and it is + * noticeably hard to scan at a low brightness, so the screen is brightened for as long as the + * code is being shown and restored to the user's own setting afterwards. + * + * The resumed check matters because the attestation is generated on a background thread and + * shown from a posted UI callback, which can land after onPause: without it, a window that is + * no longer resumed could be brightened again after onPause restored the user's brightness. + */ + private void updateQrCodeBrightness() { + setQrCodeBrightness(resumed && (stage == Stage.AuditeeResults || stage == Stage.Auditor)); + } + + private void setQrCodeBrightness(final boolean bright) { + final WindowManager.LayoutParams attributes = getWindow().getAttributes(); + final float brightness = bright + ? WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_FULL + : WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_NONE; + if (attributes.screenBrightness == brightness) { + return; + } + attributes.screenBrightness = brightness; + getWindow().setAttributes(attributes); } @Override @@ -330,6 +367,7 @@ private void runAuditor() { binding.content.textview.setText(R.string.qr_code_scan_hint_auditor); chooseBestLayout(auditorChallenge); binding.content.imageview.setOnClickListener(view -> startQrScanner()); + updateQrCodeBrightness(); } private void handleAttestation(final byte[] serialized) { @@ -392,6 +430,7 @@ private void auditeeShowAttestation(final byte[] serialized) { binding.content.textview.setText(R.string.qr_code_scan_hint_auditee); } chooseBestLayout(serialized); + updateQrCodeBrightness(); } private Bitmap createQrCode(final byte[] contents) {