Skip to content

Conversation

@seshanthS
Copy link
Collaborator

@seshanthS seshanthS commented Sep 23, 2025

Summary by CodeRabbit

  • New Features
    • Enhanced QR code scanning with smarter detection, improving recognition of complex and mAadhaar QR codes.
  • Improvements
    • Increased reliability in low-quality or non-standard QR images, reducing scan retries and time to detect.
  • Bug Fixes
    • Addressed cases where certain QR codes were previously not detected or inconsistently recognized.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 23, 2025

Walkthrough

Added 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

Cohort / File(s) Summary
QR detection hints propagation
app/android/app/src/main/java/com/proofofpassportapp/utils/QrCodeDetectorProcessor.kt
Added optional additionalHints to detectInImage/tryDetectInBitmap; merged dynamic ZXing hints (TRY_HARDER, POSSIBLE_FORMATS: QR_CODE, plus provided); updated all detection attempts (original/scaled/scaled-down and async) to pass hints; invoked with PURE_BARCODE: false for mAadhar variant; public API unchanged.

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
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Poem

Hints in the wires, a whisper to scan,
TRY_HARDER marches, a disciplined plan.
PURE_BARCODE off, for corners askew,
Bitmaps resize, taking one more view.
ZXing listens, secrets to decode—
One QR found on the winding road.

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title "fix: detect mAadhaar" is concise and accurately reflects the primary change in the diff, which updates QR detection logic to add and propagate decode hints (including PURE_BARCODE: false) to better detect mAadhaar QR codes; it follows conventional commit style and is specific enough for history scanning. It is not vague or misleading and ties directly to the modified QR detection code paths shown in the summary. This makes the title appropriate for the changeset.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch hotfix/aadhar-qr

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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 robustness

Resetting 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 leaks

The 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 throttle

detectQrCodeInImage (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 dimensions

Scaling 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

📥 Commits

Reviewing files that changed from the base of the PR and between e852005 and 48ba015.

📒 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 mAadhaar

Passing PURE_BARCODE=false is appropriate. Ensure parity by using the same hints in the camera path (see suggested patch above).

Comment on lines 206 to 208
val timeRequired = System.currentTimeMillis() - start
println(result)
if (result != null) {
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

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.

@transphorm transphorm merged commit cbf62fe into dev Sep 23, 2025
22 checks passed
@transphorm transphorm deleted the hotfix/aadhar-qr branch September 23, 2025 19:52
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.

3 participants