Class CrashProtection
Crash protection: captures unhandled exceptions, scrubs PII, persists
each crash to Storage immediately, and uploads to the
Codename One cloud crash service when enabled.
Quick start:
// In your start() method, after Display has initialised:
CrashProtection.install();
// Once your app has obtained user consent (e.g. from a settings
// screen) flip this on. The default is off so no data leaves the
// device until the developer explicitly enables uploads.
CrashProtection.setEnabled(true);
Pluggable PII scrubbing: override PiiScrubber and register
your subclass via setScrubber(PiiScrubber) to extend the
default redaction rules. The default scrubber masks the local part
of email addresses (keeping the first three characters and the full
domain) and replaces runs of six or more digits with [num].
The endpoint URL is fixed and cannot be modified by the application. Crash uploads are accepted only for Pro-tier (or higher) accounts for builds produced by the Codename One cloud build server within the last 30 days; out-of-tier or stale builds are silently dropped by the server.
This runs in parallel with the legacy Log.bindCrashProtection
path; both can be installed in the same app without conflict.
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidManually report an exception.static PiiScrubberstatic voidinstall()Installs the crash protection hooks.static booleanstatic voidsetEnabled(boolean enabled) Enables or disables crash uploads.static voidReplaces the active PII scrubber.
-
Method Details
-
install
public static void install()Installs the crash protection hooks. Idempotent: calling more than once has no effect. Does nothing on the simulator (matches the legacy
Log.bindCrashProtectionbehaviour).Side effect: any crashes previously persisted to storage but not yet uploaded will be drained in the background if uploads are currently enabled.
-
isEnabled
public static boolean isEnabled()- Returns:
trueif crash uploads are enabled. Default isfalse.
-
setEnabled
public static void setEnabled(boolean enabled) Enables or disables crash uploads. When transitioning from off to on, any crashes buffered in storage are drained in the background. The toggle persists across launches. -
setScrubber
Replaces the active PII scrubber. SubclassPiiScrubberto extend or replace the default redaction rules. -
getScrubber
-
capture
Manually report an exception. The crash is persisted to storage first and then uploaded if uploads are enabled. Stack frames are captured from the throwable.
-