Skip to content

Conversation

@Crustack
Copy link
Owner

@Crustack Crustack commented Nov 2, 2025

With this PR dis-/enabling biometric lock becomes much safer

  • Create backup before de-/encrypting database
  • Double check if the de-/encryption was succesful, if not do not overwrite original database/use backup db file
  • Show user that de-/encryption has failed with opportunity to report the error

Summary by CodeRabbit

Release Notes

  • New Features

    • Enhanced error reporting for biometric operations with standardized dialogs, "Report Bug" action, and copy-to-clipboard functionality.
  • Bug Fixes

    • Biometric lock enable/disable now runs asynchronously, preventing UI freezing.
    • Improved error handling and recovery during encryption/decryption failures.
  • Documentation

    • Updated help text and localization strings for error reporting terminology.

@coderabbitai
Copy link

coderabbitai bot commented Nov 2, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

This PR enhances biometric lock security by adding database backup and integrity verification during enable/disable operations. It introduces exception handling with user-facing error dialogs, converts key biometric functions to suspend functions, and updates string resources and localization for bug reporting functionality.

Changes

Cohort / File(s) Summary
Biometric Lock Core Logic
app/src/main/java/com/philkes/notallyx/presentation/viewmodel/BaseNoteModel.kt
Converts enableBiometricLock, disableBiometricLock, and resetPreferences to suspend functions. Adds database backup/copy operations, encryption/decryption validation within IO context, and throws EncryptionException/DecryptionException on validation failures.
Exception Classes
app/src/main/java/com/philkes/notallyx/utils/security/EncryptionException.kt, app/src/main/java/com/philkes/notallyx/utils/security/DecryptionException.kt
Introduces new exception types for database encryption/decryption failures with message and optional cause parameters.
Encryption Utilities
app/src/main/java/com/philkes/notallyx/utils/security/EncryptionUtils.kt
Updates encryptDatabase and decryptDatabase to accept explicit File parameters. Adds file-based state checks via new extension properties (isEncryptedDatabase, isUnencryptedDatabase). Wraps operations with try/catch to throw new exceptions.
Backup Utilities
app/src/main/java/com/philkes/notallyx/utils/backup/ExportExtensions.kt
Extends copyDatabase signature with optional decrypt and suffix parameters. Updates output file naming to use suffix.
Error Dialog Infrastructure
app/src/main/java/com/philkes/notallyx/utils/AndroidExtensions.kt
Adds showErrorDialog extension functions for Fragment and Activity to render standardized error dialogs with stack trace display, copy-to-clipboard, and bug report actions.
UI Layer — Activity
app/src/main/java/com/philkes/notallyx/presentation/activity/LockedActivity.kt
Wraps biometric disable flows in lifecycleScope.launch coroutines for error paths, updating dialog dismissal and async execution.
UI Layer — Fragment
app/src/main/java/com/philkes/notallyx/presentation/activity/main/fragment/settings/SettingsFragment.kt
Wraps resetSettings, biometric enable/disable operations in coroutine scopes with try/catch for EncryptionException/DecryptionException, showing error dialogs on failure.
Error Activity
app/src/main/java/com/philkes/notallyx/utils/ErrorActivity.kt
Removes inline error dialog logic and delegates to showErrorDialog extension, wiring localized strings.
String Resources — Default
app/src/main/res/values/strings.xml
Adds three new biometric setup failure strings (biometrics_setup_failure, biometrics_setup_failure_decrypt, biometrics_setup_failure_encrypt). Updates report_bug from "Report an issue/bug" to "Report Bug".
String Resources — Localization
app/src/main/res/values-{cs,de,es,fr,it,nl,pl,ro,ru,zh-rCN,zh-rTW}/strings.xml
Updates report_bug string value across 11 language files, removing slash-delimited alternatives and simplifying to "Report Bug" (or equivalent).
Documentation
documentation/docs/faq.md
Updates FAQ references from "Report an issue/bug" to "Report Bug" in Troubleshooting section.

Sequence Diagram(s)

sequenceDiagram
    participant UI as UI Layer<br/>(Activity/Fragment)
    participant Scope as lifecycleScope
    participant Model as BaseNoteModel
    participant IO as IO Context
    participant DB as Database
    participant Encrypt as Encryption Utils
    
    rect rgb(200, 220, 255)
    Note over UI,Encrypt: Biometric Enable Flow
    UI->>Scope: launch coroutine
    Scope->>Model: enableBiometricLock(cipher)
    Model->>IO: withContext(IO)
    IO->>DB: copyDatabase (backup)
    IO->>Encrypt: encryptDatabase(backup)
    IO->>DB: overwrite original with encrypted
    IO->>DB: validateEncrypted() check
    alt Validation Success
        IO->>Model: write lock state + key
        Model-->>Scope: return success
        Scope->>UI: update UI + show toast
    else Validation Fails
        IO->>Model: throw EncryptionException
        Model-->>Scope: propagate exception
        Scope->>UI: catch + showErrorDialog
    end
    end

    rect rgb(200, 255, 220)
    Note over UI,Encrypt: Biometric Disable Flow
    UI->>Scope: launch coroutine
    Scope->>Model: disableBiometricLock()
    Model->>IO: withContext(IO)
    IO->>DB: copyDatabase(decrypt=true)
    IO->>Encrypt: decryptDatabase(copy)
    IO->>DB: overwrite original with decrypted
    IO->>DB: validateUnencrypted() check
    alt Validation Success
        IO->>Model: disable lock + callback
        Model-->>Scope: return success
        Scope->>UI: show disable toast
    else Validation Fails
        IO->>Model: throw DecryptionException
        Model-->>Scope: propagate exception
        Scope->>UI: catch + showErrorDialog
    end
    end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

  • BaseNoteModel.kt: Database backup, encryption/decryption validation logic, and suspend function conversions require careful review of state transitions and error paths.
  • EncryptionUtils.kt: File-based state checks and new exception-throwing patterns need verification for correctness.
  • SettingsFragment.kt & LockedActivity.kt: Coroutine scope lifecycle, try/catch error handling, and UI callback ordering must be validated across both enable and disable flows.
  • Localization files: While homogeneous changes, the 11 language updates should be spot-checked for consistency in key string simplifications.

Possibly related PRs

Poem

🐰 With backup and cipher, we lock databases tight,
Encrypting with care, decrypting just right,
When errors arise, the dialogs appear—
Clear messages flowing to users so dear! 🔒✨

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 "Improve de-/encrypting db error handling" directly and accurately describes the main objective of this changeset. The PR's core focus is enhancing error handling for database encryption/decryption operations through the introduction of new exception classes (EncryptionException, DecryptionException), validation checks, backup mechanisms to prevent data loss, and user-facing error notification via enhanced error dialogs. The title is specific, clear, concise, and appropriately captures the primary change without being misleading or overly vague.

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f569244 and d0e8ac2.

⛔ Files ignored due to path filters (1)
  • app/translations.xlsx is excluded by !**/*.xlsx
📒 Files selected for processing (22)
  • app/src/main/java/com/philkes/notallyx/presentation/activity/LockedActivity.kt (4 hunks)
  • app/src/main/java/com/philkes/notallyx/presentation/activity/main/fragment/settings/SettingsFragment.kt (6 hunks)
  • app/src/main/java/com/philkes/notallyx/presentation/viewmodel/BaseNoteModel.kt (5 hunks)
  • app/src/main/java/com/philkes/notallyx/utils/AndroidExtensions.kt (2 hunks)
  • app/src/main/java/com/philkes/notallyx/utils/ErrorActivity.kt (2 hunks)
  • app/src/main/java/com/philkes/notallyx/utils/backup/ExportExtensions.kt (1 hunks)
  • app/src/main/java/com/philkes/notallyx/utils/security/DecryptionException.kt (1 hunks)
  • app/src/main/java/com/philkes/notallyx/utils/security/EncryptionException.kt (1 hunks)
  • app/src/main/java/com/philkes/notallyx/utils/security/EncryptionUtils.kt (1 hunks)
  • app/src/main/res/values-cs/strings.xml (1 hunks)
  • app/src/main/res/values-de/strings.xml (1 hunks)
  • app/src/main/res/values-es/strings.xml (1 hunks)
  • app/src/main/res/values-fr/strings.xml (1 hunks)
  • app/src/main/res/values-it/strings.xml (1 hunks)
  • app/src/main/res/values-nl/strings.xml (1 hunks)
  • app/src/main/res/values-pl/strings.xml (1 hunks)
  • app/src/main/res/values-ro/strings.xml (1 hunks)
  • app/src/main/res/values-ru/strings.xml (1 hunks)
  • app/src/main/res/values-zh-rCN/strings.xml (1 hunks)
  • app/src/main/res/values-zh-rTW/strings.xml (1 hunks)
  • app/src/main/res/values/strings.xml (2 hunks)
  • documentation/docs/faq.md (2 hunks)

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

@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: 3

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
app/src/main/java/com/philkes/notallyx/presentation/activity/LockedActivity.kt (1)

87-114: Catch failures from disableBiometricLock() before showing success toast.

disableBiometricLock() now performs IO and throws EncryptionException/DecryptionException when crypto fails. Launching it without a try/catch on lifecycleScope hands any failure to the default coroutine exception handler, crashing the activity and leaving the UI hidden. Wrap both calls in a try/catch (or runCatching) and route errors through the new showErrorDialog helper instead of unconditionally showing the success toast.

🧹 Nitpick comments (2)
app/src/main/java/com/philkes/notallyx/utils/security/DecryptionException.kt (1)

1-3: Remove the empty class body.

Detekt flags the trailing {} as an empty class block. Drop the braces so the declaration is a single line.

-class DecryptionException(msg: String, cause: Throwable? = null) : Exception(msg, cause) {}
+class DecryptionException(msg: String, cause: Throwable? = null) : Exception(msg, cause)
app/src/main/java/com/philkes/notallyx/utils/security/EncryptionException.kt (1)

1-3: Remove the empty class body.

For consistency with detekt, make the declaration a single line without {}.

-class EncryptionException(msg: String, cause: Throwable? = null) : Exception(msg, cause) {}
+class EncryptionException(msg: String, cause: Throwable? = null) : Exception(msg, cause)
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1384740 and f569244.

⛔ Files ignored due to path filters (1)
  • app/translations.xlsx is excluded by !**/*.xlsx
📒 Files selected for processing (23)
  • TRANSLATIONS.md (1 hunks)
  • app/src/main/java/com/philkes/notallyx/presentation/activity/LockedActivity.kt (4 hunks)
  • app/src/main/java/com/philkes/notallyx/presentation/activity/main/fragment/settings/SettingsFragment.kt (6 hunks)
  • app/src/main/java/com/philkes/notallyx/presentation/viewmodel/BaseNoteModel.kt (4 hunks)
  • app/src/main/java/com/philkes/notallyx/utils/AndroidExtensions.kt (2 hunks)
  • app/src/main/java/com/philkes/notallyx/utils/ErrorActivity.kt (2 hunks)
  • app/src/main/java/com/philkes/notallyx/utils/backup/ExportExtensions.kt (1 hunks)
  • app/src/main/java/com/philkes/notallyx/utils/security/DecryptionException.kt (1 hunks)
  • app/src/main/java/com/philkes/notallyx/utils/security/EncryptionException.kt (1 hunks)
  • app/src/main/java/com/philkes/notallyx/utils/security/EncryptionUtils.kt (1 hunks)
  • app/src/main/res/values-cs/strings.xml (1 hunks)
  • app/src/main/res/values-de/strings.xml (1 hunks)
  • app/src/main/res/values-es/strings.xml (1 hunks)
  • app/src/main/res/values-fr/strings.xml (1 hunks)
  • app/src/main/res/values-it/strings.xml (1 hunks)
  • app/src/main/res/values-nl/strings.xml (1 hunks)
  • app/src/main/res/values-pl/strings.xml (1 hunks)
  • app/src/main/res/values-ro/strings.xml (1 hunks)
  • app/src/main/res/values-ru/strings.xml (1 hunks)
  • app/src/main/res/values-zh-rCN/strings.xml (1 hunks)
  • app/src/main/res/values-zh-rTW/strings.xml (1 hunks)
  • app/src/main/res/values/strings.xml (2 hunks)
  • documentation/docs/faq.md (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (5)
app/src/main/java/com/philkes/notallyx/utils/ErrorActivity.kt (1)
app/src/main/java/com/philkes/notallyx/utils/AndroidExtensions.kt (2)
  • showErrorDialog (186-208)
  • showErrorDialog (210-232)
app/src/main/java/com/philkes/notallyx/presentation/activity/LockedActivity.kt (2)
app/src/main/java/com/philkes/notallyx/presentation/UiExtensions.kt (3)
  • showToast (918-918)
  • showToast (920-923)
  • showToast (925-928)
app/src/main/java/com/philkes/notallyx/presentation/view/note/action/ActionBottomSheet.kt (1)
  • hide (139-141)
app/src/main/java/com/philkes/notallyx/presentation/viewmodel/BaseNoteModel.kt (1)
app/src/main/java/com/philkes/notallyx/utils/security/EncryptionUtils.kt (3)
  • encryptDatabase (20-33)
  • decryptDatabase (35-48)
  • decryptDatabase (56-66)
app/src/main/java/com/philkes/notallyx/utils/backup/ExportExtensions.kt (1)
app/src/main/java/com/philkes/notallyx/utils/security/EncryptionUtils.kt (3)
  • getInitializedCipherForDecryption (112-120)
  • decryptDatabase (35-48)
  • decryptDatabase (56-66)
app/src/main/java/com/philkes/notallyx/presentation/activity/main/fragment/settings/SettingsFragment.kt (2)
app/src/main/java/com/philkes/notallyx/presentation/UiExtensions.kt (3)
  • showToast (918-918)
  • showToast (920-923)
  • showToast (925-928)
app/src/main/java/com/philkes/notallyx/utils/AndroidExtensions.kt (2)
  • showErrorDialog (186-208)
  • showErrorDialog (210-232)
🪛 detekt (1.23.8)
app/src/main/java/com/philkes/notallyx/utils/security/DecryptionException.kt

[warning] 3-3: The class or object DecryptionException is empty.

(detekt.empty-blocks.EmptyClassBlock)

app/src/main/java/com/philkes/notallyx/utils/security/EncryptionException.kt

[warning] 3-3: The class or object EncryptionException is empty.

(detekt.empty-blocks.EmptyClassBlock)

🔇 Additional comments (15)
app/src/main/res/values-es/strings.xml (1)

258-258: ✓ Localization update looks good.

The string update shortens the "report_bug" text from "Informar de incidente/error" to "Informar error" for consistency with the English "Report Bug" update. This is a straightforward localization improvement with no functional impact.

app/src/main/res/values-zh-rCN/strings.xml (1)

264-264: ✓ Localization update looks good.

The string update simplifies the Chinese (Simplified) translation from "报告问题/错误" to "报告错误", maintaining clarity while improving consistency across the localization suite.

app/src/main/res/values-pl/strings.xml (1)

269-269: ✓ Localization update looks good.

The Polish translation is shortened from "Zgłoś problem/błąd" to "Zgłoś błąd", maintaining meaning while aligning with the global UI text update.

app/src/main/res/values-it/strings.xml (1)

249-249: ✓ Localization update looks good.

The Italian translation is updated from "Segnala un problema/bug" to "Segnala bug", providing a more concise and consistent phrasing.

app/src/main/res/values-zh-rTW/strings.xml (1)

251-251: ✓ Localization update looks good.

The Chinese (Traditional) translation is simplified from "報告問題/錯誤" to "報告錯誤", maintaining semantic clarity while improving brevity.

app/src/main/res/values-nl/strings.xml (1)

187-187: ✓ Localization update looks good.

The Dutch translation is updated from "Rapporteer een probleem/fout" to "Bug melden", providing a cleaner, more direct phrasing consistent with the global update.

app/src/main/res/values-ru/strings.xml (1)

264-264: ✓ Localization update looks good.

The Russian translation is trimmed from "Сообщить об ошибке/баге" to "Сообщить об ошибке", removing redundancy while maintaining clarity.

app/src/main/res/values-fr/strings.xml (1)

258-258: ✓ Localization update looks good.

The French translation is shortened from "Signaler un problème/un bug" to "Signaler bug", providing more concise UI text while maintaining the intended meaning.

app/src/main/res/values-cs/strings.xml (1)

264-264: LGTM!

Translation update is consistent and properly formatted.

app/src/main/res/values-de/strings.xml (1)

265-265: LGTM!

Translation update is consistent and properly formatted.

app/src/main/res/values-ro/strings.xml (1)

258-258: LGTM!

Translation update is consistent and properly formatted.

app/src/main/res/values/strings.xml (2)

49-51: Well‑structured error strings with actionable messaging.

The new strings provide clear error feedback with proper format placeholders for inserting the report action label. String naming convention is clear and consistent.

Please verify these new error strings are used in the encryption/decryption failure handling code paths mentioned in the PR description.


273-273: LGTM!

Label simplification is clear and consistent with locale-specific updates.

TRANSLATIONS.md (1)

22-51: Verify translation coverage reflects new strings across all locales.

The table shows total increased from 312 to 315 strings. However, spot-checking the Czech row: if previously at 301/312 (~96%), adding 3 strings should yield approximately 304/315 (~96%), but it shows 301/315 (~95%). This suggests the new biometric error strings may not yet be translated in all locales.

Confirm whether this is intentional (new strings marked as untranslated) or if translations are still pending.

documentation/docs/faq.md (1)

97-97: LGTM!

Documentation wording updates are consistent with the simplified "Report Bug" label across the app. User instructions remain clear and actionable.

Also applies to: 146-146

Comment on lines +97 to 103
showErrorDialog(
throwable,
auto_backup_failed,
getString(crash_export_backup_failed, this.getString(report_bug)),
originalStacktrace = stacktrace,
)
}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

Import showErrorDialog to fix the unresolved reference.

showErrorDialog(...) lives in com.philkes.notallyx.presentation. Without the import this file won’t compile.

 import com.philkes.notallyx.presentation.setupProgressDialog
 import com.philkes.notallyx.presentation.showToast
+import com.philkes.notallyx.presentation.showErrorDialog

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In app/src/main/java/com/philkes/notallyx/utils/ErrorActivity.kt around lines 97
to 103, the call to showErrorDialog is an unresolved reference because the
function is defined in com.philkes.notallyx.presentation; add the missing import
by adding import com.philkes.notallyx.presentation.showErrorDialog near the
other imports at the top of the file so the call compiles, then re-run build to
confirm resolution.

@Crustack Crustack force-pushed the fix/decrypt-encrypt-errors branch from f569244 to d0e8ac2 Compare November 2, 2025 15:42
@Crustack Crustack merged commit ac520d3 into main Nov 2, 2025
1 check passed
@Crustack Crustack deleted the fix/decrypt-encrypt-errors branch November 2, 2025 15:42
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.

2 participants