Skip to content

feat: added native crash handler#2450

Open
RohitKushvaha01 wants to merge 8 commits into
Acode-Foundation:mainfrom
RohitKushvaha01:feature/crash-handler
Open

feat: added native crash handler#2450
RohitKushvaha01 wants to merge 8 commits into
Acode-Foundation:mainfrom
RohitKushvaha01:feature/crash-handler

Conversation

@RohitKushvaha01

@RohitKushvaha01 RohitKushvaha01 commented Jul 5, 2026

Copy link
Copy Markdown
Member

This will help debug issues like #2158

@greptile-apps

greptile-apps Bot commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR introduces a new Cordova plugin, cordova-plugin-crashhandler, that intercepts uncaught native Java exceptions in the main app process, captures the stack trace, and displays a custom CrashActivity in a separate :crash OS process with device metadata, the stack trace, and restart/copy/close buttons. The plugin is registered with onload: true so it installs the handler as early as possible.

  • CrashHandler.java registers a Thread.UncaughtExceptionHandler that catches Throwable (including Error subclasses), starts CrashActivity via explicit intent, and terminates the faulting process unconditionally in the finally block.
  • CrashActivity.java renders a self-contained crash report UI built entirely from Android SDK views, reads optional app theme colours from SharedPreferences, and offers restart, copy, and close actions.
  • package.json and package-lock.json register the local plugin as a dev dependency and list it in the cordova.plugins map; the existing ANDROIDBLACKLISTSECURESOCKETPROTOCOLS config for cordova-plugin-advanced-http is preserved.

Confidence Score: 5/5

The crash handler is correctly implemented and the faulting process is unconditionally terminated in the finally block.

The three blocking concerns from the previous review round (process not terminated, too-narrow exception catch, TLS protocol blacklist removal) are all resolved. No new logic bugs were found.

CrashActivity.java — null getLaunchIntentForPackage exits silently (previously discussed); System.java — duplicate imports should be deduplicated.

Important Files Changed

Filename Overview
src/plugins/cordova-plugin-crashhandler/src/android/CrashHandler.java Registers the uncaught exception handler; catches Throwable (including Error subclasses), serialises the stack trace, starts CrashActivity, and unconditionally kills the process in the finally block. Previously flagged issues resolved.
src/plugins/cordova-plugin-crashhandler/src/android/CrashActivity.java Self-contained crash screen Activity running in the :crash process. Reads theme colours from SharedPreferences with safe fallbacks, builds a programmatic UI, and offers restart/copy/close actions.
src/plugins/cordova-plugin-crashhandler/plugin.xml Declares the CrashHandler feature (onload=true) and registers CrashActivity in the :crash process with android:exported=false, singleInstance launch mode, and comprehensive configChanges.
package.json Adds cordova-plugin-crashhandler to cordova.plugins and devDependencies. The ANDROIDBLACKLISTSECURESOCKETPROTOCOLS setting for cordova-plugin-advanced-http is preserved.
src/plugins/system/android/com/foxdebug/system/System.java Import block reorganised, introducing duplicate import statements (previously noted). No logic changes detected.

Sequence Diagram

%%{init: {'theme': 'neutral'}}%%
sequenceDiagram
    participant Main as Main Process
    participant AMS as ActivityManagerService
    participant Crash as :crash Process
    Note over Main: App running normally
    Main->>Main: CrashHandler.initialize()
    Main->>Main: Thread.setDefaultUncaughtExceptionHandler()
    Note over Main: Uncaught exception thrown
    Main->>Main: uncaughtException(thread, throwable)
    Main->>AMS: context.startActivity(CrashActivity intent)
    Main->>Main: Process.killProcess() + System.exit(10)
    AMS->>Crash: Start CrashActivity
    Crash->>Crash: loadThemeColors() + build UI
    alt Restart
        Crash->>AMS: startActivity(launch intent)
        Crash->>Crash: System.exit(0)
    else Close
        Crash->>Crash: System.exit(0)
    end
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
sequenceDiagram
    participant Main as Main Process
    participant AMS as ActivityManagerService
    participant Crash as :crash Process
    Note over Main: App running normally
    Main->>Main: CrashHandler.initialize()
    Main->>Main: Thread.setDefaultUncaughtExceptionHandler()
    Note over Main: Uncaught exception thrown
    Main->>Main: uncaughtException(thread, throwable)
    Main->>AMS: context.startActivity(CrashActivity intent)
    Main->>Main: Process.killProcess() + System.exit(10)
    AMS->>Crash: Start CrashActivity
    Crash->>Crash: loadThemeColors() + build UI
    alt Restart
        Crash->>AMS: startActivity(launch intent)
        Crash->>Crash: System.exit(0)
    else Close
        Crash->>Crash: System.exit(0)
    end
Loading

Reviews (4): Last reviewed commit: "catch Throwable instead of Exception to ..." | Re-trigger Greptile

Comment thread src/plugins/cordova-plugin-crashhandler/src/android/CrashHandler.java Outdated
Comment thread package.json
RohitKushvaha01 and others added 3 commits July 5, 2026 14:41
…ity.java

Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
@RohitKushvaha01

This comment was marked as outdated.

@bajrangCoder

This comment was marked as outdated.

Comment thread src/plugins/cordova-plugin-crashhandler/src/android/CrashHandler.java Outdated
@bajrangCoder

This comment was marked as outdated.

@UnschooledGamer UnschooledGamer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, Do we need I18n strings for this PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

3 participants