From e715f2355b96b8885f5ee096299379c8d1bcfa94 Mon Sep 17 00:00:00 2001 From: Ahmed alaa Date: Mon, 26 Aug 2024 02:04:11 +0300 Subject: [PATCH 1/4] feat: allow enable automatic ndk crash report --- .../flutter/modules/CrashReportingApi.java | 5 +++++ .../flutter/CrashReportingApiTest.java | 18 ++++++++++++++++++ ios/Classes/Modules/CrashReportingApi.m | 5 +++++ lib/src/modules/crash_reporting.dart | 7 +++++++ pigeons/crash_reporting.api.dart | 2 ++ test/crash_reporting_test.dart | 10 ++++++++++ 6 files changed, 47 insertions(+) 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..9ad4ac84d 100644 --- a/lib/src/modules/crash_reporting.dart +++ b/lib/src/modules/crash_reporting.dart @@ -30,6 +30,13 @@ 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]; From bafd19e36411131a7adf6a2165b6808b8b06bcc1 Mon Sep 17 00:00:00 2001 From: Ahmed alaa Date: Tue, 27 Aug 2024 16:41:42 +0300 Subject: [PATCH 2/4] feat: Support enabling NDK crash capturing on Android --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d0b3bf7bc..cba707956 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 ([#501](https://github.com/Instabug/Instabug-React-Native/pull/501)). + ## [13.3.0](https://github.com/Instabug/Instabug-Flutter/compare/v13.2.0...v13.3.0) (August 5, 2024) ### Added From b42e3395ef4b670a552fe5523dcf47411e9b7985 Mon Sep 17 00:00:00 2001 From: ahmed alaa <154802748+ahmedAlaaInstabug@users.noreply.github.com> Date: Tue, 27 Aug 2024 16:45:18 +0300 Subject: [PATCH 3/4] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cba707956..f9aafe3db 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ ### Added -- Support enabling NDK crash capturing on Android ([#501](https://github.com/Instabug/Instabug-React-Native/pull/501)). +- 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) From e1e99f28509528e0d74ff7f219976fdbbc9c62e2 Mon Sep 17 00:00:00 2001 From: Ahmed alaa Date: Tue, 27 Aug 2024 17:01:42 +0300 Subject: [PATCH 4/4] feat: Support enabling NDK crash capturing on Android --- lib/src/modules/crash_reporting.dart | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/src/modules/crash_reporting.dart b/lib/src/modules/crash_reporting.dart index 9ad4ac84d..60cec6bcc 100644 --- a/lib/src/modules/crash_reporting.dart +++ b/lib/src/modules/crash_reporting.dart @@ -30,7 +30,6 @@ class CrashReporting { return _host.setEnabled(isEnabled); } - /// Enables and disables automatic NDK crash reporting on Android. /// [boolean] isEnabled static Future setNDKEnabled(bool isEnabled) async {