|
| 1 | +// Copyright BugSplat. All Rights Reserved. |
| 2 | + |
| 3 | +#include "BugSplatAttributes.h" |
| 4 | +#include "GenericPlatform/GenericPlatformCrashContext.h" |
| 5 | + |
| 6 | +#if PLATFORM_IOS |
| 7 | +#import <BugSplat/BugSplat.h> |
| 8 | +#endif |
| 9 | + |
| 10 | +#if PLATFORM_ANDROID |
| 11 | +#include "Android/AndroidJNI.h" |
| 12 | +#include "Android/AndroidApplication.h" |
| 13 | +#include "Android/AndroidJava.h" |
| 14 | +#endif |
| 15 | + |
| 16 | +DEFINE_LOG_CATEGORY_STATIC(LogBugSplatAttributes, Log, All); |
| 17 | + |
| 18 | +void UBugSplatAttributes::SetAttribute(const FString& Key, const FString& Value) |
| 19 | +{ |
| 20 | + if (Key.IsEmpty()) |
| 21 | + { |
| 22 | + UE_LOG(LogBugSplatAttributes, Warning, TEXT("SetAttribute called with empty key")); |
| 23 | + return; |
| 24 | + } |
| 25 | + |
| 26 | +#if PLATFORM_IOS |
| 27 | + NSString* NsKey = [NSString stringWithUTF8String:TCHAR_TO_UTF8(*Key)]; |
| 28 | + NSString* NsValue = [NSString stringWithUTF8String:TCHAR_TO_UTF8(*Value)]; |
| 29 | + [[BugSplat shared] setValue:NsValue forAttribute:NsKey]; |
| 30 | +#elif PLATFORM_ANDROID |
| 31 | + JNIEnv* Env = FAndroidApplication::GetJavaEnv(); |
| 32 | + jclass BugSplatClass = FAndroidApplication::FindJavaClass("com/bugsplat/android/BugSplat"); |
| 33 | + jmethodID SetAttributeMethod = FJavaWrapper::FindStaticMethod(Env, BugSplatClass, "setAttribute", |
| 34 | + "(Ljava/lang/String;Ljava/lang/String;)V", false); |
| 35 | + Env->CallStaticVoidMethod(BugSplatClass, SetAttributeMethod, |
| 36 | + *FJavaClassObject::GetJString(Key), |
| 37 | + *FJavaClassObject::GetJString(Value)); |
| 38 | + Env->DeleteLocalRef(BugSplatClass); |
| 39 | +#else |
| 40 | + FGenericCrashContext::SetGameData(Key, Value); |
| 41 | +#endif |
| 42 | + |
| 43 | + UE_LOG(LogBugSplatAttributes, Verbose, TEXT("SetAttribute: %s"), *Key); |
| 44 | +} |
| 45 | + |
| 46 | +void UBugSplatAttributes::RemoveAttribute(const FString& Key) |
| 47 | +{ |
| 48 | + if (Key.IsEmpty()) |
| 49 | + { |
| 50 | + UE_LOG(LogBugSplatAttributes, Warning, TEXT("RemoveAttribute called with empty key")); |
| 51 | + return; |
| 52 | + } |
| 53 | + |
| 54 | +#if PLATFORM_IOS |
| 55 | + NSString* NsKey = [NSString stringWithUTF8String:TCHAR_TO_UTF8(*Key)]; |
| 56 | + [[BugSplat shared] setValue:nil forAttribute:NsKey]; |
| 57 | +#elif PLATFORM_ANDROID |
| 58 | + JNIEnv* Env = FAndroidApplication::GetJavaEnv(); |
| 59 | + jclass BugSplatClass = FAndroidApplication::FindJavaClass("com/bugsplat/android/BugSplat"); |
| 60 | + jmethodID RemoveAttributeMethod = FJavaWrapper::FindStaticMethod(Env, BugSplatClass, "removeAttribute", |
| 61 | + "(Ljava/lang/String;)V", false); |
| 62 | + Env->CallStaticVoidMethod(BugSplatClass, RemoveAttributeMethod, |
| 63 | + *FJavaClassObject::GetJString(Key)); |
| 64 | + Env->DeleteLocalRef(BugSplatClass); |
| 65 | +#else |
| 66 | + FGenericCrashContext::SetGameData(Key, TEXT("")); |
| 67 | +#endif |
| 68 | + |
| 69 | + UE_LOG(LogBugSplatAttributes, Verbose, TEXT("RemoveAttribute: %s"), *Key); |
| 70 | +} |
0 commit comments