Skip to content

Commit 1a27900

Browse files
authored
Heartbeat logging passthrough for FIS for mobile platforms. (#853)
* Heartbeat logging passthrough for FIS for mobile platforms. * Call CheckAndClearJniExceptions in LogHeartbeat
1 parent 6323357 commit 1a27900

File tree

7 files changed

+37
-0
lines changed

7 files changed

+37
-0
lines changed

installations/src/android/installations_android.cc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "installations/src/android/installations_android.h"
1616

1717
#include "app/src/util.h"
18+
#include "app/src/util_android.h"
1819
#include "installations/src/common.h"
1920

2021
namespace firebase {
@@ -186,6 +187,19 @@ void InstallationsInternal::Cleanup() {
186187
}
187188
}
188189

190+
void InstallationsInternal::LogHeartbeat(const firebase::App& app) {
191+
// Calling the native getter is sufficient to cause a Heartbeat to be logged.
192+
JNIEnv* env = app.GetJNIEnv();
193+
jobject platform_app = app.GetPlatformApp();
194+
jclass installations_class = installations::GetClass();
195+
jobject installations_instance_local = env->CallStaticObjectMethod(
196+
installations_class,
197+
installations::GetMethodId(installations::kGetInstance), platform_app);
198+
firebase::util::CheckAndClearJniExceptions(env);
199+
env->DeleteLocalRef(installations_instance_local);
200+
env->DeleteLocalRef(platform_app);
201+
}
202+
189203
Future<std::string> InstallationsInternal::GetId() {
190204
const auto handle =
191205
future_impl_.SafeAlloc<std::string>(kInstallationsFnGetId);

installations/src/android/installations_android.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ class InstallationsInternal {
3434
explicit InstallationsInternal(const firebase::App& app);
3535
~InstallationsInternal();
3636

37+
// Platform-specific method that causes a heartbeat to be logged.
38+
// See go/firebase-platform-logging-design for more information.
39+
static void LogHeartbeat(const firebase::App& app);
40+
3741
Future<std::string> GetId();
3842
Future<std::string> GetIdLastResult();
3943

installations/src/installations.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ Installations* Installations::GetInstance(App* app) {
3232
// Return the Installations if it already exists.
3333
Installations* existing_installations = FindInstallations(app);
3434
if (existing_installations) {
35+
// Log heartbeat data when instance getters are called.
36+
// See go/firebase-platform-logging-design for more information.
37+
InstallationsInternal::LogHeartbeat(*app);
3538
return existing_installations;
3639
}
3740

installations/src/ios/installations_ios.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ class InstallationsInternal {
4242
explicit InstallationsInternal(const firebase::App& app);
4343
~InstallationsInternal();
4444

45+
// Platform-specific method that causes a heartbeat to be logged.
46+
// See go/firebase-platform-logging-design for more information.
47+
static void LogHeartbeat(const firebase::App& app);
48+
4549
Future<std::string> GetId();
4650
Future<std::string> GetIdLastResult();
4751

installations/src/ios/installations_ios.mm

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@
4040
// Destructor is necessary for ARC garbage collection.
4141
}
4242

43+
void InstallationsInternal::LogHeartbeat(const firebase::App& app) {
44+
// Calling the native getter is sufficient to cause a Heartbeat to be logged.
45+
FIRApp *platform_app = app.GetPlatformApp();
46+
[FIRInstallations installationsWithApp:platform_app];
47+
}
48+
4349
bool InstallationsInternal::Initialized() const{
4450
return true;
4551
}

installations/src/stub/installations_stub.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ InstallationsInternal::InstallationsInternal(const firebase::App& app)
2626

2727
InstallationsInternal::~InstallationsInternal() {}
2828

29+
void InstallationsInternal::LogHeartbeat(const firebase::App& app) {}
30+
2931
bool InstallationsInternal::Initialized() const { return true; }
3032

3133
void InstallationsInternal::Cleanup() {}

installations/src/stub/installations_stub.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ class InstallationsInternal {
3131
explicit InstallationsInternal(const firebase::App& app);
3232
~InstallationsInternal();
3333

34+
// Platform-specific method that causes a heartbeat to be logged.
35+
// See go/firebase-platform-logging-design for more information.
36+
static void LogHeartbeat(const firebase::App& app);
37+
3438
Future<std::string> GetId();
3539
Future<std::string> GetIdLastResult();
3640

0 commit comments

Comments
 (0)