Skip to content

Add process name to application info #6890

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 1 commit into from
Apr 17, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

package com.google.firebase.perf.transport;

import static com.google.firebase.sessions.ProcessDetailsProvider.getProcessDetailsProvider;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static java.util.concurrent.TimeUnit.MINUTES;

Expand Down Expand Up @@ -230,6 +231,8 @@ private void finishInitialization() {
applicationInfoBuilder = ApplicationInfo.newBuilder();
applicationInfoBuilder
.setGoogleAppId(firebaseApp.getOptions().getApplicationId())
.setProcessName(
getProcessDetailsProvider().getCurrentProcessDetails(appContext).getProcessName())
.setAndroidAppInfo(
AndroidApplicationInfo.newBuilder()
.setPackageName(packageName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ message GaugeMetadata {
// Additional metadata about an application and its state (including state of
// the device at runtime) that is not provided by firebase data transport.
//
// Next tag: 8
// Next tag: 9
message ApplicationInfo {
// Identifier for the application that has been registered with firebase.
// Contains pantheon project number, platform and the hash of the (package
Expand All @@ -316,6 +316,9 @@ message ApplicationInfo {

// A map of global-level custom attribute names to values.
map<string, string> custom_attributes = 6;

// The name of process that initiate the event. Currently only populated for Android apps.
optional string process_name = 8;
}

// Additional metadata about an android application that is not provided by
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

import android.content.Context;
import android.content.pm.PackageInfo;
import android.os.Process;
import androidx.test.core.app.ApplicationProvider;
import com.google.android.datatransport.TransportFactory;
import com.google.android.gms.tasks.Tasks;
Expand Down Expand Up @@ -1399,6 +1400,11 @@ private void initializeTransport(boolean shouldInitialize) {
if (shouldInitialize) {
// Set the version name since Firebase sessions needs it.
Context context = ApplicationProvider.getApplicationContext();

// For unit test, app context does not application info related to uid, so we have to force
// set it through process info.
context.getApplicationInfo().uid = Process.myUid();

ShadowPackageManager shadowPackageManager = shadowOf(context.getPackageManager());

PackageInfo packageInfo =
Expand Down Expand Up @@ -1468,6 +1474,8 @@ private static void validateApplicationInfo(
.isEqualTo(FAKE_FIREBASE_APPLICATION_ID);
assertThat(loggedPerfMetric.getApplicationInfo().getApplicationProcessState())
.isEqualTo(applicationProcessState);
assertThat(loggedPerfMetric.getApplicationInfo().getProcessName())
.isEqualTo("com.google.firebase.perf.test");
assertThat(loggedPerfMetric.getApplicationInfo().hasAndroidAppInfo()).isTrue();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ import com.google.android.gms.common.util.ProcessUtils
*
* @hide
*/
internal object ProcessDetailsProvider {
object ProcessDetailsProvider {
@JvmStatic
fun getProcessDetailsProvider(): ProcessDetailsProvider {
return this
}
/** Gets the details for all of this app's running processes. */
fun getAppProcessDetails(context: Context): List<ProcessDetails> {
val appUid = context.applicationInfo.uid
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ internal data class DataCollectionStatus(
)

/** Container for information about the process */
internal data class ProcessDetails(
data class ProcessDetails(
val processName: String,
val pid: Int,
val importance: Int,
Expand Down
Loading