-
Notifications
You must be signed in to change notification settings - Fork 52
Implement Crashlytics Unity ODFs #549
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
Changes from all commits
c3bef10
918a1a3
3e07f14
60744ef
092a567
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -62,19 +62,25 @@ METHOD_LOOKUP_DEFINITION(firebase_crashlytics, | |
| CRASHLYTICS_METHODS, CRASHLYTICS_FIELDS) | ||
|
|
||
| // clang-format off | ||
| #define CRASHLYTICS_CORE_METHODS(X) \ | ||
| X(LogFatalException, "logFatalException", \ | ||
| "(Ljava/lang/Throwable;)V", \ | ||
| util::kMethodTypeInstance) | ||
|
|
||
| #define CRASHLYTICS_CORE_FIELDS(X) \ | ||
| X(DataCollectionArbiter, "dataCollectionArbiter", \ | ||
| "Lcom/google/firebase/crashlytics/internal/common/DataCollectionArbiter;", \ | ||
| util::kFieldTypeInstance) | ||
|
|
||
| // clang-format on | ||
| METHOD_LOOKUP_DECLARATION(crashlytics_core, | ||
| METHOD_LOOKUP_NONE, CRASHLYTICS_CORE_FIELDS) | ||
| CRASHLYTICS_CORE_METHODS, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what the reason of making this change?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The logFatalException method is an internal api of CrashlyticsCore, not a public api of Crashlytics. So we added it here so we can call it via jni. |
||
| CRASHLYTICS_CORE_FIELDS) | ||
| METHOD_LOOKUP_DEFINITION( | ||
| crashlytics_core, | ||
| PROGUARD_KEEP_CLASS | ||
| "com/google/firebase/crashlytics/internal/common/CrashlyticsCore", | ||
| METHOD_LOOKUP_NONE, CRASHLYTICS_CORE_FIELDS) | ||
| CRASHLYTICS_CORE_METHODS, CRASHLYTICS_CORE_FIELDS) | ||
|
|
||
| // clang-format off | ||
| #define CRASHLYTICS_DATA_COLLECTION_METHODS(X) \ | ||
|
|
@@ -144,6 +150,7 @@ bool cached_data_collection_enabled_ = false; | |
|
|
||
| CrashlyticsInternal::CrashlyticsInternal(App* app) { | ||
| data_collection_obj_ = nullptr; | ||
| core_ = nullptr; | ||
| obj_ = nullptr; | ||
| java_vm_ = app->java_vm(); | ||
|
|
||
|
|
@@ -188,6 +195,7 @@ CrashlyticsInternal::CrashlyticsInternal(App* app) { | |
| env->DeleteLocalRef(application_context); | ||
| assert(data_collection_obj != nullptr); | ||
| data_collection_obj_ = env->NewGlobalRef(data_collection_obj); | ||
| core_ = env->NewGlobalRef(core); | ||
| env->DeleteLocalRef(data_collection_obj); | ||
| env->DeleteLocalRef(core); | ||
|
|
||
|
|
@@ -212,6 +220,10 @@ CrashlyticsInternal::~CrashlyticsInternal() { | |
| env->DeleteGlobalRef(data_collection_obj_); | ||
| data_collection_obj_ = nullptr; | ||
| } | ||
| if (core_) { | ||
| env->DeleteGlobalRef(core_); | ||
| core_ = nullptr; | ||
| } | ||
| Terminate(); | ||
| java_vm_ = nullptr; | ||
|
|
||
|
|
@@ -227,6 +239,7 @@ bool CrashlyticsInternal::Initialize(JNIEnv* env, jobject activity) { | |
| if (!(firebase_crashlytics::CacheMethodIds(env, activity) && | ||
| firebase_crashlytics::CacheFieldIds(env, activity) && | ||
| firebase_crashlytics_ndk::CacheMethodIds(env, activity) && | ||
| crashlytics_core::CacheMethodIds(env, activity) && | ||
| crashlytics_core::CacheFieldIds(env, activity) && | ||
| crashlytics_data_collection::CacheMethodIds(env, activity) && | ||
| java_exception::CacheMethodIds(env, activity) && | ||
|
|
@@ -340,6 +353,29 @@ void CrashlyticsInternal::LogException( | |
| env->DeleteLocalRef(exception_object); | ||
| } | ||
|
|
||
| void CrashlyticsInternal::LogExceptionAsFatal( | ||
| const char* name, const char* reason, | ||
| std::vector<firebase::crashlytics::Frame> frames) { | ||
| if (!cached_data_collection_enabled_) { | ||
| return; | ||
| } | ||
| JNIEnv* env = util::GetThreadsafeJNIEnv(java_vm_); | ||
|
|
||
| std::string message(name); | ||
| message += EXCEPTION_MESSAGE_SEPARATOR; | ||
| message += reason; | ||
|
|
||
| jobject exception_object = BuildJavaException(message, frames); | ||
|
|
||
| env->CallVoidMethod( | ||
| core_, | ||
| crashlytics_core::GetMethodId(crashlytics_core::kLogFatalException), | ||
| exception_object); | ||
| util::LogException(env, kLogLevelError, | ||
| "Crashlytics::LogExceptionAsFatal() failed"); | ||
| env->DeleteLocalRef(exception_object); | ||
| } | ||
|
|
||
| bool CrashlyticsInternal::GetCrashlyticsCollectionEnabled( | ||
| JavaVM* java_vm, jobject data_collection_obj) { | ||
| JNIEnv* env = util::GetThreadsafeJNIEnv(java_vm); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| /* | ||
| * Copyright 2023 Google LLC | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| // | ||
| // Crashlytics_ExceptionModel.h | ||
| // Crashlytics | ||
| // | ||
|
|
||
| #import <FIRCrashlytics.h> | ||
|
|
||
| @interface FIRExceptionModel (Platform) | ||
|
|
||
| @property(nonatomic) BOOL isFatal; | ||
| @property(nonatomic) BOOL onDemand; | ||
|
|
||
| @end |
Uh oh!
There was an error while loading. Please reload this page.