Skip to content

Heartbeat logging passthrough for Auth on Mobile Platforms #846

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

Merged
merged 7 commits into from
Feb 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions auth/src/android/auth_android.cc
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,17 @@ void Auth::DestroyPlatformAuth(AuthData* auth_data) {
}
}

void LogHeartbeat(Auth* auth) {
// Calling the native getter is sufficient to cause a Heartbeat to be logged.
JNIEnv* env = Env(auth->auth_data_);
jobject platform_app = auth->app().GetPlatformApp();
jobject j_auth_impl = env->CallStaticObjectMethod(
auth::GetClass(), auth::GetMethodId(auth::kGetInstance), platform_app);
util::CheckAndClearJniExceptions(env);
env->DeleteLocalRef(j_auth_impl);
env->DeleteLocalRef(platform_app);
}

JNIEXPORT void JNICALL JniAuthStateListener_nativeOnAuthStateChanged(
JNIEnv* env, jobject clazz, jlong callback_data) {
AuthData* auth_data = reinterpret_cast<AuthData*>(callback_data);
Expand Down
3 changes: 3 additions & 0 deletions auth/src/auth.cc
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ Auth* Auth::GetAuth(App* app, InitResult* init_result_out) {
Auth* existing_auth = FindAuth(app);
if (existing_auth) {
if (init_result_out != nullptr) *init_result_out = kInitResultSuccess;
// Log heartbeat data when instance getters are called.
// See go/firebase-platform-logging-design for more information.
LogHeartbeat(existing_auth);
return existing_auth;
}

Expand Down
4 changes: 4 additions & 0 deletions auth/src/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ void InitPlatformAuth(AuthData* auth_data);
// Platform-specific method to destroy the wrapped Auth class.
void DestroyPlatformAuth(AuthData* auth_data);

// Platform-specific method that causes a heartbeat to be logged.
// See go/firebase-platform-logging-design for more information.
void LogHeartbeat(Auth* auth);

// All the result functions are similar.
// Just return the local Future, cast to the proper result type.
#define AUTH_RESULT_FN(class_name, fn_name, result_type) \
Expand Down
4 changes: 4 additions & 0 deletions auth/src/desktop/auth_desktop.cc
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ void* CreatePlatformAuth(App* const app) {
void InitializeFunctionRegistryListener(AuthData* auth_data);
void DestroyFunctionRegistryListener(AuthData* auth_data);

// TODO(b/211006737): This is a stub until desktop implementation supports
// heartbeat logging.
void LogHeartbeat(Auth* const auth) {}

IdTokenRefreshListener::IdTokenRefreshListener() : token_timestamp_(0) {}

IdTokenRefreshListener::~IdTokenRefreshListener() {}
Expand Down
1 change: 1 addition & 0 deletions auth/src/include/firebase/auth.h
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,7 @@ class Auth {
friend void EnableTokenAutoRefresh(AuthData* authData);
friend void DisableTokenAutoRefresh(AuthData* authData);
friend void ResetTokenRefreshCounter(AuthData* authData);
friend void LogHeartbeat(Auth* auth);
/// @endcond

// Find Auth instance using App. Return null if the instance does not exist.
Expand Down
5 changes: 5 additions & 0 deletions auth/src/ios/auth_ios.mm
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,11 @@ void UpdateCurrentUser(AuthData *auth_data) {
auth_data->auth_impl = nullptr;
}

void LogHeartbeat(Auth *auth) {
// Calling the native getter is sufficient to cause a Heartbeat to be logged.
[FIRAuth authWithApp:auth->app().GetPlatformApp()];
}

Future<Auth::FetchProvidersResult> Auth::FetchProvidersForEmail(const char *email) {
// Create data structure to hold asynchronous results.
FetchProvidersResult initial_data;
Expand Down