-
Notifications
You must be signed in to change notification settings - Fork 180
fix: detect mAadhaar #1121
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: detect mAadhaar #1121
Conversation
WalkthroughAdded optional decode hints to QR detection workflow in QrCodeDetectorProcessor. Private methods now accept and propagate a hints map, merging defaults (TRY_HARDER, POSSIBLE_FORMATS: QR_CODE) with caller-provided entries (e.g., PURE_BARCODE: false). Detection attempts apply these hints across original and scaled bitmaps, including asynchronous paths. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor UI as UI
participant QRP as QrCodeDetectorProcessor
participant ZX as ZXing Decoder
UI->>QRP: detectQrCodeInImage(image)
activate QRP
Note over QRP: Build hints = {TRY_HARDER, POSSIBLE_FORMATS: QR_CODE, PURE_BARCODE: false}
QRP->>QRP: detectInImage(image, hints)
QRP->>QRP: tryDetectInBitmap(original, hints)
QRP->>ZX: decode(original, hints)
alt success
ZX-->>QRP: QR result
else fail
QRP->>QRP: tryDetectInBitmap(scaled, hints)
QRP->>ZX: decode(scaled, hints)
alt success
ZX-->>QRP: QR result
else fail
QRP->>QRP: tryDetectInBitmap(scaledDown, hints)
QRP->>ZX: decode(scaledDown, hints)
ZX-->>QRP: result or failure
end
end
QRP-->>UI: result or error
deactivate QRP
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (3)
app/android/app/src/main/java/com/proofofpassportapp/utils/QrCodeDetectorProcessor.kt (3)
160-167: Reset reader state between attempts and broaden hints for robustnessResetting avoids stale internal state. ALSO_INVERTED and UTF‑8 improve real‑world hit rate.
Apply:
try { val result = qRCodeDetectorReader.decode(binaryBitMap) println("QR Code detected successfully with ${binarizer.javaClass.simpleName}") return result } catch (e: Exception) { println("Detection failed with ${binarizer.javaClass.simpleName}: ${e.message}") + qRCodeDetectorReader.reset() } } @@ - val hints = buildMap { + val hints = buildMap { put(com.google.zxing.DecodeHintType.TRY_HARDER, true) put(com.google.zxing.DecodeHintType.POSSIBLE_FORMATS, listOf(com.google.zxing.BarcodeFormat.QR_CODE)) + put(com.google.zxing.DecodeHintType.ALSO_INVERTED, true) + put(com.google.zxing.DecodeHintType.CHARACTER_SET, "UTF-8") additionalHints?.forEach { (key, value) -> put(key, value) } } @@ try { val result = qRCodeDetectorReader.decode(binaryBitMap, hints) println("QR Code detected successfully with hints and ${binarizer.javaClass.simpleName}") return result } catch (e: Exception) { println("Detection with hints failed with ${binarizer.javaClass.simpleName}: ${e.message}") + qRCodeDetectorReader.reset() } }Also applies to: 170-175, 179-186
192-194: Shut down the executor to prevent thread leaksThe empty stop() leaks the thread. Shut it down.
Apply:
fun stop() { - } + try { + executor.shutdownNow() + } catch (_: Exception) { /* no-op */ } + }
100-118: Don't gate camera QR on URLs — pass ZXing hints and always reset throttledetectQrCodeInImage (camera flow) calls detectInImage(image) without hints and treats non‑URL payloads as failures (breaks mAadhaar). Wrap the executor body in try/finally to always clear shouldThrottle and pass the same DecodeHintType hints used in detectQrCodeInBitmap.
Location: app/android/app/src/main/java/com/proofofpassportapp/utils/QrCodeDetectorProcessor.kt — lines ~100–118
- executor.execute { - val result = detectInImage(image) - val timeRequired = System.currentTimeMillis() - start - println(result) - if (result != null) { - if (URLUtil.isValidUrl(result.text)) { - println("NICO HERE TOO " + result.text) - listener.onSuccess(result.text!!, metadata, timeRequired, originalBitmap) - } else { - listener.onFailure(Exception("Invalid URL"), timeRequired) - } - } - else { - listener.onCompletedFrame(timeRequired) - } - shouldThrottle.set(false) - } + executor.execute { + try { + val hints = mapOf( + com.google.zxing.DecodeHintType.PURE_BARCODE to false, + com.google.zxing.DecodeHintType.ALSO_INVERTED to true, + com.google.zxing.DecodeHintType.POSSIBLE_FORMATS to listOf(com.google.zxing.BarcodeFormat.QR_CODE), + com.google.zxing.DecodeHintType.TRY_HARDER to true, + ) + val result = detectInImage(image, hints) + val timeRequired = System.currentTimeMillis() - start + if (result != null) { + listener.onSuccess(result.text!!, metadata, timeRequired, originalBitmap) + } else { + listener.onCompletedFrame(timeRequired) + } + } catch (e: Exception) { + val timeRequired = System.currentTimeMillis() - start + listener.onFailure(e, timeRequired) + } finally { + shouldThrottle.set(false) + } + }
🧹 Nitpick comments (1)
app/android/app/src/main/java/com/proofofpassportapp/utils/QrCodeDetectorProcessor.kt (1)
122-140: Scale defensively to avoid OOM and invalid dimensionsScaling to 2x can explode memory on high‑res frames; dividing by 2 can reach 0. Add guards.
Apply:
- // If original fails, try with scaled up image (better for small QR codes) - val scaledBitmap = Bitmap.createScaledBitmap(bitmap, bitmap.width * 2, bitmap.height * 2, true) - result = tryDetectInBitmap(scaledBitmap, qRCodeDetectorReader, additionalHints) + // If original fails, try with scaled up image (better for small QR codes) + if (bitmap.width <= 1280 && bitmap.height <= 1280) { + val scaledBitmap = Bitmap.createScaledBitmap(bitmap, bitmap.width * 2, bitmap.height * 2, true) + result = tryDetectInBitmap(scaledBitmap, qRCodeDetectorReader, additionalHints) + if (result != null) return result + } - if (result != null) return result @@ - val scaledDownBitmap = Bitmap.createScaledBitmap(bitmap, bitmap.width / 2, bitmap.height / 2, true) - result = tryDetectInBitmap(scaledDownBitmap, qRCodeDetectorReader, additionalHints) + val downW = maxOf(1, bitmap.width / 2) + val downH = maxOf(1, bitmap.height / 2) + val scaledDownBitmap = Bitmap.createScaledBitmap(bitmap, downW, downH, true) + result = tryDetectInBitmap(scaledDownBitmap, qRCodeDetectorReader, additionalHints)
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
app/android/app/src/main/java/com/proofofpassportapp/utils/QrCodeDetectorProcessor.kt(3 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
app/android/**/*.{kt,java}
📄 CodeRabbit inference engine (app/AGENTS.md)
Document complex native Android module changes in the PR
Files:
app/android/app/src/main/java/com/proofofpassportapp/utils/QrCodeDetectorProcessor.kt
app/android/**/*
⚙️ CodeRabbit configuration file
app/android/**/*: Review Android-specific code for:
- Platform-specific implementations
- Performance considerations
- Security best practices for mobile
Files:
app/android/app/src/main/java/com/proofofpassportapp/utils/QrCodeDetectorProcessor.kt
⏰ Context from checks skipped due to timeout of 300000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
- GitHub Check: build-deps
- GitHub Check: android-build-test
- GitHub Check: e2e-ios
- GitHub Check: analyze-ios
- GitHub Check: analyze-android
🔇 Additional comments (1)
app/android/app/src/main/java/com/proofofpassportapp/utils/QrCodeDetectorProcessor.kt (1)
201-206: Good: explicit hints for mAadhaarPassing PURE_BARCODE=false is appropriate. Ensure parity by using the same hints in the camera path (see suggested patch above).
| val timeRequired = System.currentTimeMillis() - start | ||
| println(result) | ||
| if (result != null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid logging decoded payloads (PII risk)
Remove println of Result to prevent leaking Aadhaar data in logs.
Apply:
- println(result)🤖 Prompt for AI Agents
In
app/android/app/src/main/java/com/proofofpassportapp/utils/QrCodeDetectorProcessor.kt
around lines 206 to 208 you are printing the decoded Result which may contain
sensitive PII (Aadhaar data); remove the println(result) call and do not log the
decoded payload. If you need telemetry, replace it with a non-sensitive
indicator (e.g., log that a QR was detected or increment a metric) or log only
safe metadata (presence/length or masked value), ensuring no PII is written to
stdout or app logs.
Summary by CodeRabbit