Fix QR code size limits and add better error logging

- Correct QR code capacity limits for Error Correction Level M (15%)
- Update limit from 2900 to 2300 characters (actual M level capacity is ~2334)
- Add detailed error logging to show bundle length when QR generation fails
- Fix FileProvider authority to use dynamic string resource instead of hardcoded value
- Ensure consistent limits across both PolycentricBackupActivity and QRCodeFullscreenActivity

The previous limit was based on Error Correction Level L (7%) but we use Level M (15%),
which has a lower capacity but better error recovery.
This commit is contained in:
Trevor 2025-08-19 11:13:45 -05:00
commit 79f478e421
2 changed files with 20 additions and 12 deletions

View file

@ -115,7 +115,7 @@ class PolycentricBackupActivity : AppCompatActivity() {
startActivity(intent) startActivity(intent)
} }
} catch (e: Exception) { } catch (e: Exception) {
Logger.e(TAG, getString(R.string.failed_to_generate_qr_code), e) Logger.e(TAG, "QR code generation failed. Bundle length: ${_exportBundle.length}, Error: ${e.message}", e)
// Show the export bundle text even if QR code generation fails // Show the export bundle text even if QR code generation fails
_exportBundle = withContext(Dispatchers.IO) { createExportBundle() } _exportBundle = withContext(Dispatchers.IO) { createExportBundle() }
@ -157,9 +157,13 @@ class PolycentricBackupActivity : AppCompatActivity() {
} }
private fun isContentSuitableForQRCode(content: String): Boolean { private fun isContentSuitableForQRCode(content: String): Boolean {
// QR Code Version 40 (177x177) with L error correction can hold ~2953 characters // QR Code Version 40 (177x177) capacity limits:
// We use a conservative limit of 2900 characters to ensure reliable generation // - Error Correction Level L (7%): ~2953 characters
return content.length <= 2900 // - Error Correction Level M (15%): ~2334 characters
// - Error Correction Level Q (25%): ~1666 characters
// - Error Correction Level H (30%): ~1276 characters
// We use Error Correction Level M, so limit to 2300 characters for reliability
return content.length <= 2300
} }
private fun generateQRCode(content: String, width: Int, height: Int): Bitmap { private fun generateQRCode(content: String, width: Int, height: Int): Bitmap {
@ -277,11 +281,11 @@ class PolycentricBackupActivity : AppCompatActivity() {
writer.write(_exportBundle) writer.write(_exportBundle)
} }
val uri = FileProvider.getUriForFile( val uri = FileProvider.getUriForFile(
this, this,
"${packageName}.fileprovider", getString(R.string.authority),
file file
) )
val shareIntent = Intent(Intent.ACTION_SEND).apply { val shareIntent = Intent(Intent.ACTION_SEND).apply {
type = "text/plain" type = "text/plain"

View file

@ -79,9 +79,13 @@ class QRCodeFullscreenActivity : AppCompatActivity() {
} }
private fun isContentSuitableForQRCode(content: String): Boolean { private fun isContentSuitableForQRCode(content: String): Boolean {
// QR Code Version 40 (177x177) with L error correction can hold ~2953 characters // QR Code Version 40 (177x177) capacity limits:
// We use a conservative limit of 2900 characters to ensure reliable generation // - Error Correction Level L (7%): ~2953 characters
return content.length <= 2900 // - Error Correction Level M (15%): ~2334 characters
// - Error Correction Level Q (25%): ~1666 characters
// - Error Correction Level H (30%): ~1276 characters
// We use Error Correction Level M, so limit to 2300 characters for reliability
return content.length <= 2300
} }
private fun generateQRCode(content: String, width: Int, height: Int): Bitmap { private fun generateQRCode(content: String, width: Int, height: Int): Bitmap {