Skip to content

Commit 6df92b9

Browse files
authored
Removing getRunningAppProcesses since the process_name isn't used (#4057)
1 parent 6a566dd commit 6df92b9

File tree

6 files changed

+3
-96
lines changed

6 files changed

+3
-96
lines changed

firebase-perf/src/main/java/com/google/firebase/perf/session/gauges/GaugeManager.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,6 @@ public boolean logGaugeMetadata(String sessionId, ApplicationProcessState appSta
267267

268268
private GaugeMetadata getGaugeMetadata() {
269269
return GaugeMetadata.newBuilder()
270-
.setProcessName(gaugeMetadataManager.getProcessName())
271270
.setDeviceRamSizeKb(gaugeMetadataManager.getDeviceRamSizeKb())
272271
.setMaxAppJavaHeapMemoryKb(gaugeMetadataManager.getMaxAppJavaHeapMemoryKb())
273272
.setMaxEncouragedAppJavaHeapMemoryKb(

firebase-perf/src/main/java/com/google/firebase/perf/session/gauges/GaugeMetadataManager.java

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import android.content.Context;
2020
import android.os.Build.VERSION;
2121
import android.os.Build.VERSION_CODES;
22-
import androidx.annotation.Nullable;
2322
import androidx.annotation.VisibleForTesting;
2423
import com.google.firebase.perf.logging.AndroidLogger;
2524
import com.google.firebase.perf.util.StorageUnit;
@@ -28,7 +27,6 @@
2827
import java.io.BufferedReader;
2928
import java.io.FileReader;
3029
import java.io.IOException;
31-
import java.util.List;
3230
import java.util.regex.Matcher;
3331
import java.util.regex.Pattern;
3432

@@ -43,7 +41,6 @@ class GaugeMetadataManager {
4341
private final Runtime runtime;
4442
private final ActivityManager activityManager;
4543
private final MemoryInfo memoryInfo;
46-
private final String currentProcessName;
4744
private final Context appContext;
4845

4946
GaugeMetadataManager(Context appContext) {
@@ -57,15 +54,6 @@ class GaugeMetadataManager {
5754
this.activityManager = (ActivityManager) appContext.getSystemService(Context.ACTIVITY_SERVICE);
5855
memoryInfo = new ActivityManager.MemoryInfo();
5956
activityManager.getMemoryInfo(memoryInfo);
60-
61-
// Assign the current process name here to avoid iterating through all the running processes
62-
// each time getCurrentProcessName() is called.
63-
currentProcessName = getCurrentProcessName();
64-
}
65-
66-
/** Returns the name of the process FirebaseApp is associated with. */
67-
public String getProcessName() {
68-
return currentProcessName;
6957
}
7058

7159
/**
@@ -112,23 +100,4 @@ int readTotalRAM(String procFileName) {
112100

113101
return 0;
114102
}
115-
116-
/** Returns the name of the process the Application is associated with. */
117-
private String getCurrentProcessName() {
118-
int myProcessPid = android.os.Process.myPid();
119-
120-
@Nullable
121-
List<ActivityManager.RunningAppProcessInfo> runningAppProcessInfos =
122-
activityManager.getRunningAppProcesses();
123-
124-
if (runningAppProcessInfos != null) {
125-
for (ActivityManager.RunningAppProcessInfo processInfo : runningAppProcessInfos) {
126-
if (processInfo.pid == myProcessPid) {
127-
return processInfo.processName;
128-
}
129-
}
130-
}
131-
132-
return appContext.getPackageName();
133-
}
134103
}

firebase-perf/src/main/proto/firebase/perf/v1/perf_metric.proto

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -266,11 +266,8 @@ message AndroidMemoryReading {
266266
//
267267
// Next tag: 7
268268
message GaugeMetadata {
269-
// The process in which Firebase instance is initialized and collecting data.
270-
// Fireperf sdk collects information in the context of a process (instead of
271-
// the whole app). The process name helps developer identifies which process
272-
// are the gauge data coming from.
273-
optional string process_name = 1;
269+
// Deprecated on 09/2022.
270+
optional string process_name = 1 [deprecated = true];
274271

275272
// Clock rate of the cpu of the device, in kHz.
276273
optional int32 cpu_clock_rate_khz = 2;

firebase-perf/src/test/java/com/google/firebase/perf/metrics/validator/FirebasePerfGaugeManagerValidatorTest.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ public void testGaugeMetricIsValid() {
5656
// Construct GaugeMetadata
5757
GaugeMetadata gaugeMetadata =
5858
createValidGaugeMetadata(
59-
"processName",
6059
/* deviceRamSizeKb= */ 2000,
6160
/* maxAppJavaHeapMemoryKb= */ 1000,
6261
/* maxEncouragedAppJavaHeapMemoryKb= */ 800);
@@ -115,7 +114,6 @@ public void testGaugeMetricWithOnlyMemoryMetricIsValid() {
115114
public void testGaugeMetricWithOnlyGaugeMetadataIsValid() {
116115
GaugeMetadata gaugeMetadata =
117116
createValidGaugeMetadata(
118-
"processName",
119117
/* deviceRamSizeKb= */ 2000,
120118
/* maxAppJavaHeapMemoryKb= */ 1000,
121119
/* maxEncouragedAppJavaHeapMemoryKb= */ 800);
@@ -134,7 +132,6 @@ public void testGaugeMetricWithOnlyGaugeMetadataIsValid() {
134132
public void testGaugeMetadataWithoutMaxJavaHeapIsNotValid() {
135133
GaugeMetadata gaugeMetadata =
136134
GaugeMetadata.newBuilder()
137-
.setProcessName("processName")
138135
.setDeviceRamSizeKb(2000)
139136
.setMaxEncouragedAppJavaHeapMemoryKb(800)
140137
.build();
@@ -202,12 +199,8 @@ private AndroidMemoryReading createValidAndroidMetricReading(int currentUsedAppJ
202199
}
203200

204201
private GaugeMetadata createValidGaugeMetadata(
205-
String processName,
206-
int deviceRamSizeKb,
207-
int maxAppJavaHeapMemoryKb,
208-
int maxEncouragedAppJavaHeapMemoryKb) {
202+
int deviceRamSizeKb, int maxAppJavaHeapMemoryKb, int maxEncouragedAppJavaHeapMemoryKb) {
209203
GaugeMetadata.Builder fakeGaugeMetadataBuilder = GaugeMetadata.newBuilder();
210-
fakeGaugeMetadataBuilder.setProcessName(processName);
211204
fakeGaugeMetadataBuilder.setDeviceRamSizeKb(deviceRamSizeKb);
212205
fakeGaugeMetadataBuilder.setMaxAppJavaHeapMemoryKb(maxAppJavaHeapMemoryKb);
213206
fakeGaugeMetadataBuilder.setMaxEncouragedAppJavaHeapMemoryKb(maxEncouragedAppJavaHeapMemoryKb);

firebase-perf/src/test/java/com/google/firebase/perf/session/gauges/GaugeManagerTest.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,6 @@ public void testStartGaugeManagerWithNewSessionIdAndNewAppState() {
637637

638638
@Test
639639
public void testLogGaugeMetadataSendDataToTransport() {
640-
when(fakeGaugeMetadataManager.getProcessName()).thenReturn("processName");
641640
when(fakeGaugeMetadataManager.getDeviceRamSizeKb()).thenReturn(2000);
642641
when(fakeGaugeMetadataManager.getMaxAppJavaHeapMemoryKb()).thenReturn(1000);
643642
when(fakeGaugeMetadataManager.getMaxEncouragedAppJavaHeapMemoryKb()).thenReturn(800);
@@ -649,7 +648,6 @@ public void testLogGaugeMetadataSendDataToTransport() {
649648
GaugeMetadata recordedGaugeMetadata = recordedGaugeMetric.getGaugeMetadata();
650649

651650
assertThat(recordedGaugeMetric.getSessionId()).isEqualTo("sessionId");
652-
assertThat(recordedGaugeMetadata.getProcessName()).isEqualTo("processName");
653651

654652
assertThat(recordedGaugeMetadata.getDeviceRamSizeKb())
655653
.isEqualTo(fakeGaugeMetadataManager.getDeviceRamSizeKb());
@@ -699,7 +697,6 @@ public void testLogGaugeMetadataLogsAfterApplicationContextIsSet() {
699697
GaugeMetadata recordedGaugeMetadata = recordedGaugeMetric.getGaugeMetadata();
700698

701699
assertThat(recordedGaugeMetric.getSessionId()).isEqualTo("sessionId");
702-
assertThat(recordedGaugeMetadata.hasProcessName()).isTrue();
703700
}
704701

705702
@Test

firebase-perf/src/test/java/com/google/firebase/perf/session/gauges/GaugeMetadataManagerTest.java

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,10 @@
1616

1717
import static com.google.common.truth.Truth.assertThat;
1818
import static java.nio.charset.StandardCharsets.UTF_8;
19-
import static org.mockito.Mockito.spy;
20-
import static org.mockito.Mockito.when;
2119
import static org.mockito.MockitoAnnotations.initMocks;
2220
import static org.robolectric.Shadows.shadowOf;
2321

2422
import android.app.ActivityManager;
25-
import android.app.ActivityManager.RunningAppProcessInfo;
2623
import android.content.Context;
2724
import android.os.Environment;
2825
import androidx.test.core.app.ApplicationProvider;
@@ -32,8 +29,6 @@
3229
import java.io.IOException;
3330
import java.io.Writer;
3431
import java.nio.file.Files;
35-
import java.util.ArrayList;
36-
import java.util.List;
3732
import org.junit.Before;
3833
import org.junit.Test;
3934
import org.junit.runner.RunWith;
@@ -78,38 +73,6 @@ private void mockMemory() {
7873
shadowOf(activityManager).setMemoryClass(RUNTIME_MAX_ENCOURAGED_MEMORY_MB);
7974
}
8075

81-
@Test
82-
public void testInitialization_getProcessNameReturnsNull_doesNotCrash() {
83-
ActivityManager activityManagerPartialMock = spy(activityManager);
84-
when(activityManagerPartialMock.getRunningAppProcesses()).thenReturn(null);
85-
86-
assertThat(new GaugeMetadataManager(runtime, appContext)).isNotNull();
87-
}
88-
89-
@Test
90-
public void testGetProcessName_noProcessInfoList_returnsPackageName() {
91-
shadowOf(activityManager).setProcesses(new ArrayList<>());
92-
assertThat(new GaugeMetadataManager(runtime, appContext).getProcessName())
93-
.isEqualTo(appContext.getPackageName());
94-
}
95-
96-
@Test
97-
public void testGetProcessName_processListWithoutCurrentPid_returnsPackageName() {
98-
shadowOf(activityManager)
99-
.setProcesses(
100-
generateFakeAppProcessInfoListThatContainsPid(android.os.Process.myPid() + 100));
101-
assertThat(new GaugeMetadataManager(runtime, appContext).getProcessName())
102-
.isEqualTo(appContext.getPackageName());
103-
}
104-
105-
@Test
106-
public void testGetProcessName_processListWithCurrentPid_returnsProcessName() {
107-
shadowOf(activityManager)
108-
.setProcesses(generateFakeAppProcessInfoListThatContainsPid(android.os.Process.myPid()));
109-
assertThat(new GaugeMetadataManager(runtime, appContext).getProcessName())
110-
.isEqualTo("fakeProcessName");
111-
}
112-
11376
@Test
11477
public void testGetMaxAppJavaHeapMemory_returnsExpectedValue() {
11578
assertThat(testGaugeMetadataManager.getMaxAppJavaHeapMemoryKb()).isGreaterThan(0);
@@ -146,17 +109,6 @@ private String createFakeMemInfoFile() throws IOException {
146109
return file.getAbsolutePath();
147110
}
148111

149-
private List<RunningAppProcessInfo> generateFakeAppProcessInfoListThatContainsPid(int pid) {
150-
ActivityManager.RunningAppProcessInfo fakeProcessInfoList = new RunningAppProcessInfo();
151-
fakeProcessInfoList.pid = pid;
152-
fakeProcessInfoList.processName = "fakeProcessName";
153-
154-
List<RunningAppProcessInfo> processInfoList = new ArrayList<>();
155-
processInfoList.add(fakeProcessInfoList);
156-
157-
return processInfoList;
158-
}
159-
160112
private static final String MEM_INFO_CONTENTS =
161113
"MemTotal: "
162114
+ DEVICE_RAM_SIZE_KB

0 commit comments

Comments
 (0)