Skip to content

Commit 3d305b9

Browse files
github-actions[bot]web-flowkrystofwoldrichbuenaflor
authored
chore(deps): update Android SDK to v7.11.0 (#2144)
* chore: update flutter/scripts/update-android.sh to 7.11.0 * Fix capture envelope in SentryFlutterPlugin.kt * Revert SentryFlutterPlugin.kt to previous commit * Add info for unhandled exception * Update * Update * Update * Update mocks * Update * Format * Add test cases * naming * formatting --------- Co-authored-by: GitHub <[email protected]> Co-authored-by: Krystof Woldrich <[email protected]> Co-authored-by: GIancarlo Buenaflor <[email protected]>
1 parent df36ae7 commit 3d305b9

11 files changed

+102
-15
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@
3232
- Bump Cocoa SDK from v8.29.0 to v8.30.0 ([#2132](https://github.com/getsentry/sentry-dart/pull/2132))
3333
- [changelog](https://github.com/getsentry/sentry-cocoa/blob/main/CHANGELOG.md#8300)
3434
- [diff](https://github.com/getsentry/sentry-cocoa/compare/8.29.0...8.30.0)
35+
- Bump Android SDK from v7.10.0 to v7.11.0 ([#2144](https://github.com/getsentry/sentry-dart/pull/2144))
36+
- [changelog](https://github.com/getsentry/sentry-java/blob/main/CHANGELOG.md#7110)
37+
- [diff](https://github.com/getsentry/sentry-java/compare/7.10.0...7.11.0)
3538

3639
## 8.3.0
3740

dart/lib/src/sentry_envelope.dart

+16-1
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,19 @@ import 'sentry_user_feedback.dart';
1313

1414
/// Class representation of `Envelope` file.
1515
class SentryEnvelope {
16-
SentryEnvelope(this.header, this.items);
16+
SentryEnvelope(this.header, this.items,
17+
{this.containsUnhandledException = false});
1718

1819
/// Header describing envelope content.
1920
final SentryEnvelopeHeader header;
2021

2122
/// All items contained in the envelope.
2223
final List<SentryEnvelopeItem> items;
2324

25+
/// Whether the envelope contains an unhandled exception.
26+
/// This is used to determine if the native SDK should start a new session.
27+
final bool containsUnhandledException;
28+
2429
/// Create a [SentryEnvelope] containing one [SentryEnvelopeItem] which holds the [SentryEvent] data.
2530
factory SentryEnvelope.fromEvent(
2631
SentryEvent event,
@@ -29,6 +34,15 @@ class SentryEnvelope {
2934
SentryTraceContextHeader? traceContext,
3035
List<SentryAttachment>? attachments,
3136
}) {
37+
bool containsUnhandledException = false;
38+
39+
if (event.exceptions != null && event.exceptions!.isNotEmpty) {
40+
// Check all exceptions for any unhandled ones
41+
containsUnhandledException = event.exceptions!.any((exception) {
42+
return exception.mechanism?.handled == false;
43+
});
44+
}
45+
3246
return SentryEnvelope(
3347
SentryEnvelopeHeader(
3448
event.eventId,
@@ -41,6 +55,7 @@ class SentryEnvelope {
4155
if (attachments != null)
4256
...attachments.map((e) => SentryEnvelopeItem.fromAttachment(e))
4357
],
58+
containsUnhandledException: containsUnhandledException,
4459
);
4560
}
4661

dart/test/mocks/mock_envelope.dart

+3
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,7 @@ class MockEnvelope implements SentryEnvelope {
2323

2424
@override
2525
List<SentryEnvelopeItem> items = [];
26+
27+
@override
28+
bool get containsUnhandledException => false;
2629
}

flutter/android/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ android {
6060
}
6161

6262
dependencies {
63-
api 'io.sentry:sentry-android:7.10.0'
63+
api 'io.sentry:sentry-android:7.11.0'
6464
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
6565

6666
// Required -- JUnit 4 framework

flutter/android/src/main/kotlin/io/sentry/flutter/SentryFlutterPlugin.kt

+3-2
Original file line numberDiff line numberDiff line change
@@ -355,8 +355,9 @@ class SentryFlutterPlugin : FlutterPlugin, MethodCallHandler, ActivityAware {
355355
val args = call.arguments() as List<Any>? ?: listOf()
356356
if (args.isNotEmpty()) {
357357
val event = args.first() as ByteArray?
358-
if (event != null && event.isNotEmpty()) {
359-
val id = InternalSentrySdk.captureEnvelope(event)
358+
val containsUnhandledException = args[1] as Boolean
359+
if (event != null && event.isNotEmpty() && containsUnhandledException != null) {
360+
val id = InternalSentrySdk.captureEnvelope(event, containsUnhandledException)
360361
if (id != null) {
361362
result.success("")
362363
} else {

flutter/lib/src/file_system_transport.dart

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ class FileSystemTransport implements Transport {
1919
await envelope.envelopeStream(_options).forEach(envelopeData.addAll);
2020
try {
2121
// TODO avoid copy
22-
await _native.captureEnvelope(Uint8List.fromList(envelopeData));
22+
await _native.captureEnvelope(Uint8List.fromList(envelopeData),
23+
envelope.containsUnhandledException);
2324
} catch (exception, stackTrace) {
2425
_options.logger(
2526
SentryLevel.error,

flutter/lib/src/native/sentry_native_binding.dart

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ abstract class SentryNativeBinding {
1616

1717
Future<NativeAppStart?> fetchNativeAppStart();
1818

19-
Future<void> captureEnvelope(Uint8List envelopeData);
19+
Future<void> captureEnvelope(
20+
Uint8List envelopeData, bool containsUnhandledException);
2021

2122
Future<void> beginNativeFrames();
2223

flutter/lib/src/native/sentry_native_channel.dart

+5-2
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,11 @@ class SentryNativeChannel
8080
}
8181

8282
@override
83-
Future<void> captureEnvelope(Uint8List envelopeData) =>
84-
_channel.invokeMethod('captureEnvelope', [envelopeData]);
83+
Future<void> captureEnvelope(
84+
Uint8List envelopeData, bool containsUnhandledException) {
85+
return _channel.invokeMethod(
86+
'captureEnvelope', [envelopeData, containsUnhandledException]);
87+
}
8588

8689
@override
8790
Future<Map<String, dynamic>?> loadContexts() =>

flutter/test/file_system_transport_test.dart

+58-4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
library flutter_test;
33

44
import 'dart:convert';
5+
56
// backcompatibility for Flutter < 3.3
67
// ignore: unnecessary_import
78
import 'dart:typed_data';
@@ -39,7 +40,7 @@ void main() {
3940
});
4041

4142
test('$FileSystemTransport returns emptyId if channel throws', () async {
42-
when(fixture.binding.captureEnvelope(any)).thenThrow(Exception());
43+
when(fixture.binding.captureEnvelope(any, false)).thenThrow(Exception());
4344

4445
final transport = fixture.getSut();
4546
final event = SentryEvent();
@@ -56,6 +57,58 @@ void main() {
5657
expect(SentryId.empty(), sentryId);
5758
});
5859

60+
test(
61+
'sets unhandled exception flag in captureEnvelope to true for unhandled exception',
62+
() async {
63+
final transport = fixture.getSut();
64+
65+
final unhandledException = SentryException(
66+
mechanism: Mechanism(type: 'UnhandledException', handled: false),
67+
threadId: 99,
68+
type: 'Exception',
69+
value: 'Unhandled exception',
70+
);
71+
final event = SentryEvent(exceptions: [unhandledException]);
72+
final sdkVersion =
73+
SdkVersion(name: 'fixture-sdkName', version: 'fixture-sdkVersion');
74+
final envelope = SentryEnvelope.fromEvent(
75+
event,
76+
sdkVersion,
77+
dsn: fixture.options.dsn,
78+
);
79+
80+
await transport.send(envelope);
81+
82+
verify(fixture.binding.captureEnvelope(captureAny, true)).captured.single
83+
as Uint8List;
84+
});
85+
86+
test(
87+
'sets unhandled exception flag in captureEnvelope to false for handled exception',
88+
() async {
89+
final transport = fixture.getSut();
90+
91+
final unhandledException = SentryException(
92+
mechanism: Mechanism(type: 'UnhandledException', handled: true),
93+
threadId: 99,
94+
type: 'Exception',
95+
value: 'Unhandled exception',
96+
);
97+
final event = SentryEvent(exceptions: [unhandledException]);
98+
final sdkVersion =
99+
SdkVersion(name: 'fixture-sdkName', version: 'fixture-sdkVersion');
100+
final envelope = SentryEnvelope.fromEvent(
101+
event,
102+
sdkVersion,
103+
dsn: fixture.options.dsn,
104+
);
105+
106+
await transport.send(envelope);
107+
108+
verify(fixture.binding.captureEnvelope(captureAny, false)).captured.single
109+
as Uint8List;
110+
});
111+
59112
test('$FileSystemTransport asserts the event', () async {
60113
final transport = fixture.getSut();
61114

@@ -70,9 +123,10 @@ void main() {
70123
);
71124
await transport.send(envelope);
72125

73-
final envelopeData = verify(fixture.binding.captureEnvelope(captureAny))
74-
.captured
75-
.single as Uint8List;
126+
final envelopeData =
127+
verify(fixture.binding.captureEnvelope(captureAny, false))
128+
.captured
129+
.single as Uint8List;
76130
final envelopeString = utf8.decode(envelopeData);
77131
final lines = envelopeString.split('\n');
78132
final envelopeHeader = lines.first;

flutter/test/mocks.mocks.dart

+8-2
Original file line numberDiff line numberDiff line change
@@ -1116,11 +1116,17 @@ class MockSentryNativeBinding extends _i1.Mock
11161116
) as _i8.Future<_i15.NativeAppStart?>);
11171117

11181118
@override
1119-
_i8.Future<void> captureEnvelope(_i16.Uint8List? envelopeData) =>
1119+
_i8.Future<void> captureEnvelope(
1120+
_i16.Uint8List? envelopeData,
1121+
bool? containsUnhandledException,
1122+
) =>
11201123
(super.noSuchMethod(
11211124
Invocation.method(
11221125
#captureEnvelope,
1123-
[envelopeData],
1126+
[
1127+
envelopeData,
1128+
containsUnhandledException,
1129+
],
11241130
),
11251131
returnValue: _i8.Future<void>.value(),
11261132
returnValueForMissingStub: _i8.Future<void>.value(),

flutter/test/sentry_native_channel_test.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ void main() {
244244
(invocation) async =>
245245
{captured = invocation.positionalArguments[1][0] as Uint8List});
246246

247-
await sut.captureEnvelope(data);
247+
await sut.captureEnvelope(data, false);
248248

249249
expect(captured, data);
250250
});

0 commit comments

Comments
 (0)