diff --git a/CHANGELOG.md b/CHANGELOG.md index d0b3bf7bc..f9aafe3db 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## [Unreleased](https://github.com/Instabug/Instabug-Flutter/compare/v13.3.0...dev) + +### Added + +- Support enabling NDK crash capturing on Android ([#503](https://github.com/Instabug/Instabug-Flutter/pull/503)). + ## [13.3.0](https://github.com/Instabug/Instabug-Flutter/compare/v13.2.0...v13.3.0) (August 5, 2024) ### Added diff --git a/android/src/main/java/com/instabug/flutter/modules/CrashReportingApi.java b/android/src/main/java/com/instabug/flutter/modules/CrashReportingApi.java index 075d0da69..61e258ba8 100644 --- a/android/src/main/java/com/instabug/flutter/modules/CrashReportingApi.java +++ b/android/src/main/java/com/instabug/flutter/modules/CrashReportingApi.java @@ -50,6 +50,11 @@ public void send(@NonNull String jsonCrash, @NonNull Boolean isHandled) { } } + @Override + public void setNDKEnabled(@NonNull Boolean isEnabled) { + CrashReporting.setNDKCrashesState(isEnabled ? Feature.State.ENABLED : Feature.State.DISABLED); + } + @Override public void sendNonFatalError(@NonNull String jsonCrash, @Nullable Map userAttributes, @Nullable String fingerprint, @NonNull String nonFatalExceptionLevel) { try { diff --git a/android/src/test/java/com/instabug/flutter/CrashReportingApiTest.java b/android/src/test/java/com/instabug/flutter/CrashReportingApiTest.java index a538fc8b4..b33fed840 100644 --- a/android/src/test/java/com/instabug/flutter/CrashReportingApiTest.java +++ b/android/src/test/java/com/instabug/flutter/CrashReportingApiTest.java @@ -98,4 +98,22 @@ public void testSendNonFatalError() { reflected.verify(() -> MockReflected.crashReportException(any(JSONObject.class), eq(isHandled), eq(expectedUserAttributes), eq(expectedFingerprint), eq(expectedLevel))); } + + @Test + public void testSetNDKEnabledGivenTrue() { + boolean isEnabled = true; + + api.setNDKEnabled(isEnabled); + + mCrashReporting.verify(() -> CrashReporting.setNDKCrashesState(Feature.State.ENABLED)); + } + + @Test + public void testSetNDKEnabledGivenFalse() { + boolean isEnabled = false; + + api.setNDKEnabled(isEnabled); + + mCrashReporting.verify(() -> CrashReporting.setNDKCrashesState(Feature.State.DISABLED)); + } } diff --git a/ios/Classes/Modules/CrashReportingApi.m b/ios/Classes/Modules/CrashReportingApi.m index f36e821cf..d3df33039 100644 --- a/ios/Classes/Modules/CrashReportingApi.m +++ b/ios/Classes/Modules/CrashReportingApi.m @@ -46,4 +46,9 @@ - (void)sendNonFatalErrorJsonCrash:(nonnull NSString *)jsonCrash userAttributes: userAttributes:userAttributes]; } + +- (void)setNDKEnabledIsEnabled:(nonnull NSNumber *)isEnabled error:(FlutterError * _Nullable __autoreleasing * _Nonnull)error { + +} + @end diff --git a/lib/src/modules/crash_reporting.dart b/lib/src/modules/crash_reporting.dart index e5d0a0e3e..60cec6bcc 100644 --- a/lib/src/modules/crash_reporting.dart +++ b/lib/src/modules/crash_reporting.dart @@ -30,6 +30,12 @@ class CrashReporting { return _host.setEnabled(isEnabled); } + /// Enables and disables automatic NDK crash reporting on Android. + /// [boolean] isEnabled + static Future setNDKEnabled(bool isEnabled) async { + return _host.setNDKEnabled(isEnabled); + } + static Future reportCrash(Object exception, StackTrace stack) async { if (IBGBuildInfo.instance.isReleaseMode && enabled) { await _reportUnhandledCrash(exception, stack); diff --git a/pigeons/crash_reporting.api.dart b/pigeons/crash_reporting.api.dart index 45f4a9cdb..5c14ae53d 100644 --- a/pigeons/crash_reporting.api.dart +++ b/pigeons/crash_reporting.api.dart @@ -6,6 +6,8 @@ abstract class CrashReportingHostApi { void send(String jsonCrash, bool isHandled); + void setNDKEnabled(bool isEnabled); + void sendNonFatalError( String jsonCrash, Map? userAttributes, diff --git a/test/crash_reporting_test.dart b/test/crash_reporting_test.dart index a4ec87528..f712a6a07 100644 --- a/test/crash_reporting_test.dart +++ b/test/crash_reporting_test.dart @@ -37,6 +37,16 @@ void main() { ).called(1); }); + test('[setNDKEnabled] should call host method', () async { + const enabled = true; + + await CrashReporting.setNDKEnabled(enabled); + + verify( + mHost.setNDKEnabled(enabled), + ).called(1); + }); + test('[reportHandledCrash] should call host method', () async { try { final params = [1, 2];