Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions app/src/main/java/app/attestation/auditor/AttestationActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -87,6 +88,7 @@
}

private Stage stage = Stage.None;
private boolean resumed;
private boolean auditeePairing;
private byte[] auditeeSerializedAttestation;
private byte[] auditorChallenge;
Expand Down Expand Up @@ -114,6 +116,7 @@
} 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;
Expand Down Expand Up @@ -268,6 +271,7 @@
@Override
protected void onResume() {
super.onResume();
resumed = true;
final boolean isRemoteVerifyEnabled = RemoteVerifyJob.isEnabled(this);
int visibility = View.VISIBLE;
if (isRemoteVerifyEnabled) {
Expand All @@ -282,6 +286,39 @@
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
Expand Down Expand Up @@ -330,6 +367,7 @@
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) {
Expand Down Expand Up @@ -392,6 +430,7 @@
binding.content.textview.setText(R.string.qr_code_scan_hint_auditee);
}
chooseBestLayout(serialized);
updateQrCodeBrightness();
}

private Bitmap createQrCode(final byte[] contents) {
Expand Down Expand Up @@ -567,6 +606,6 @@

private void launchQrScannerActivity() {
QRScannerActivityLauncher.launch(new Intent(this, QRScannerActivity.class));
overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);

Check warning on line 609 in app/src/main/java/app/attestation/auditor/AttestationActivity.java

View workflow job for this annotation

GitHub Actions / build

[deprecation] overridePendingTransition(int,int) in Activity has been deprecated

Check warning on line 609 in app/src/main/java/app/attestation/auditor/AttestationActivity.java

View workflow job for this annotation

GitHub Actions / build

[deprecation] overridePendingTransition(int,int) in Activity has been deprecated

Check warning on line 609 in app/src/main/java/app/attestation/auditor/AttestationActivity.java

View workflow job for this annotation

GitHub Actions / build

[deprecation] overridePendingTransition(int,int) in Activity has been deprecated
}
}
Loading