Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Support enabling NDK crash capturing on Android #503

Open
wants to merge 5 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String> userAttributes, @Nullable String fingerprint, @NonNull String nonFatalExceptionLevel) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
5 changes: 5 additions & 0 deletions ios/Classes/Modules/CrashReportingApi.m
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,9 @@ - (void)sendNonFatalErrorJsonCrash:(nonnull NSString *)jsonCrash userAttributes:
userAttributes:userAttributes];

}

- (void)setNDKEnabledIsEnabled:(nonnull NSNumber *)isEnabled error:(FlutterError * _Nullable __autoreleasing * _Nonnull)error {

}

@end
6 changes: 6 additions & 0 deletions lib/src/modules/crash_reporting.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ class CrashReporting {
return _host.setEnabled(isEnabled);
}

/// Enables and disables automatic NDK crash reporting on Android.
/// [boolean] isEnabled
static Future<void> setNDKEnabled(bool isEnabled) async {
return _host.setNDKEnabled(isEnabled);
}

static Future<void> reportCrash(Object exception, StackTrace stack) async {
if (IBGBuildInfo.instance.isReleaseMode && enabled) {
await _reportUnhandledCrash(exception, stack);
Expand Down
2 changes: 2 additions & 0 deletions pigeons/crash_reporting.api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ abstract class CrashReportingHostApi {

void send(String jsonCrash, bool isHandled);

void setNDKEnabled(bool isEnabled);

void sendNonFatalError(
String jsonCrash,
Map<String, String>? userAttributes,
Expand Down
10 changes: 10 additions & 0 deletions test/crash_reporting_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 = <dynamic>[1, 2];
Expand Down