Skip to content

Commit 4508c99

Browse files
committed
Add remove attachments on Android
1 parent 70e4a13 commit 4508c99

File tree

5 files changed

+39
-2
lines changed

5 files changed

+39
-2
lines changed

android_lib/src/main/java/io/sentry/godotplugin/SentryAndroidGodotPlugin.kt

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import org.godotengine.godot.Godot
1919
import org.godotengine.godot.plugin.GodotPlugin
2020
import org.godotengine.godot.plugin.UsedByGodot
2121
import org.godotengine.godot.variant.Callable
22+
import java.io.File
2223
import kotlin.random.Random
2324

2425

@@ -123,11 +124,24 @@ class SentryAndroidGodotPlugin(godot: Godot) : GodotPlugin(godot) {
123124
}
124125

125126
@UsedByGodot
126-
fun addGlobalAttachment(path: String) {
127-
val attachment = Attachment(path)
127+
fun addFileAttachment(path: String, filename: String, contentType: String, attachmentType: String) {
128+
val attachment = Attachment(
129+
path,
130+
filename.ifEmpty { File(path).name },
131+
contentType.ifEmpty { null },
132+
attachmentType.ifEmpty { null },
133+
true
134+
)
128135
Sentry.getGlobalScope().addAttachment(attachment)
129136
}
130137

138+
@UsedByGodot
139+
fun removeFileAttachment(path: String) {
140+
val globalScope = Sentry.getGlobalScope()
141+
val attachment = globalScope.attachments.find { att -> att.pathname == path }
142+
globalScope.attachments.remove(attachment)
143+
}
144+
131145
@UsedByGodot
132146
fun setContext(key: String, value: Dictionary) {
133147
Sentry.getGlobalScope().setContexts(key, value)

src/sentry/android/android_sdk.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "android_event.h"
44
#include "android_string_names.h"
55
#include "sentry/util/print.h"
6+
#include "sentry_attachment.h"
67

78
#include <godot_cpp/classes/engine.hpp>
89
#include <godot_cpp/variant/callable.hpp>
@@ -112,6 +113,21 @@ String AndroidSDK::capture_event(const Ref<SentryEvent> &p_event) {
112113
return android_event->get_id();
113114
}
114115

116+
void AndroidSDK::add_attachment(const Ref<SentryAttachment> &p_attachment) {
117+
ERR_FAIL_COND(p_attachment.is_null());
118+
android_plugin->call(ANDROID_SN(addFileAttachment),
119+
p_attachment->get_file_path(),
120+
String(),
121+
p_attachment->get_content_type(),
122+
String());
123+
}
124+
125+
void AndroidSDK::remove_attachment(const Ref<SentryAttachment> &p_attachment) {
126+
ERR_FAIL_COND(p_attachment.is_null());
127+
android_plugin->call(ANDROID_SN(removeFileAttachment),
128+
p_attachment->get_file_path());
129+
}
130+
115131
void AndroidSDK::initialize(const PackedStringArray &p_global_attachments) {
116132
ERR_FAIL_NULL(android_plugin);
117133

src/sentry/android/android_sdk.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ class AndroidSDK : public InternalSDK {
4747
virtual Ref<SentryEvent> create_event() override;
4848
virtual String capture_event(const Ref<SentryEvent> &p_event) override;
4949

50+
virtual void add_attachment(const Ref<SentryAttachment> &p_attachment) override;
51+
virtual void remove_attachment(const Ref<SentryAttachment> &p_attachment) override;
52+
5053
virtual void initialize(const PackedStringArray &p_global_attachments) override;
5154

5255
bool has_android_plugin() const { return android_plugin != nullptr; }

src/sentry/android/android_string_names.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ AndroidStringNames::AndroidStringNames() {
2929
createEvent = StringName("createEvent");
3030
releaseEvent = StringName("releaseEvent");
3131
captureEvent = StringName("captureEvent");
32+
addFileAttachment = StringName("addFileAttachment");
33+
removeFileAttachment = StringName("removeFileAttachment");
3234

3335
// Event methods.
3436
eventGetId = StringName("eventGetId");

src/sentry/android/android_string_names.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ class AndroidStringNames {
4141
StringName createEvent;
4242
StringName releaseEvent;
4343
StringName captureEvent;
44+
StringName addFileAttachment;
45+
StringName removeFileAttachment;
4446

4547
// Event methods.
4648
StringName eventGetId;

0 commit comments

Comments
 (0)