Skip to content

Commit 733437d

Browse files
Fix inaccurate activity screen metrics.
1 parent 98e066a commit 733437d

File tree

2 files changed

+4
-14
lines changed

2 files changed

+4
-14
lines changed

firebase-perf/src/main/java/com/google/firebase/perf/application/AppStateMonitor.java

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import android.content.Context;
2121
import android.os.Bundle;
2222
import android.util.SparseIntArray;
23-
import android.view.WindowManager;
2423
import androidx.annotation.NonNull;
2524
import androidx.core.app.FrameMetricsAggregator;
2625
import com.google.android.gms.common.util.VisibleForTesting;
@@ -308,7 +307,7 @@ private void sendScreenTrace(Activity activity) {
308307
int slowFrames = 0;
309308
int frozenFrames = 0;
310309
// Stops recording metrics for this Activity and returns the currently-collected metrics
311-
SparseIntArray[] arr = frameMetricsAggregator.remove(activity);
310+
SparseIntArray[] arr = frameMetricsAggregator.reset();
312311
if (arr != null) {
313312
SparseIntArray frameTimes = arr[FrameMetricsAggregator.TOTAL_INDEX];
314313
if (frameTimes != null) {
@@ -391,21 +390,13 @@ private void sendSessionLog(String name, Timer startTime, Timer endTime) {
391390
}
392391

393392
/**
394-
* Only send screen trace if FrameMetricsAggregator exists and the activity is hardware
395-
* accelerated.
393+
* Only send screen trace if FrameMetricsAggregator exists.
396394
*
397395
* @param activity The Activity for which we're monitoring the screen rendering performance.
398396
* @return true if supported, false if not.
399397
*/
400398
private boolean isScreenTraceSupported(Activity activity) {
401-
return hasFrameMetricsAggregator
402-
// This check is needed because we can't observe frame rates for a non hardware accelerated
403-
// view.
404-
// See b/133827763.
405-
&& activity.getWindow() != null
406-
&& ((activity.getWindow().getAttributes().flags
407-
& WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED)
408-
!= 0);
399+
return hasFrameMetricsAggregator;
409400
}
410401

411402
/**

firebase-perf/src/test/java/com/google/firebase/perf/application/AppStateMonitorTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -373,13 +373,12 @@ public void screenTrace_twoActivities_traceStartedAndStoppedWithActivityLifecycl
373373
}
374374

375375
@Test
376-
public void screenTrace_noHardwareAccelerated_traceNotCreated() {
376+
public void screenTrace_noHardwareAccelerated_noExceptionThrown() {
377377
AppStateMonitor monitor = new AppStateMonitor(transportManager, clock);
378378
Activity activityWithNonHardwareAcceleratedView =
379379
createFakeActivity(/* isHardwareAccelerated =*/ false);
380380

381381
monitor.onActivityStarted(activityWithNonHardwareAcceleratedView);
382-
assertThat(monitor.getActivity2ScreenTrace()).isEmpty();
383382

384383
// Confirm that this doesn't throw an exception.
385384
monitor.onActivityStopped(activityWithNonHardwareAcceleratedView);

0 commit comments

Comments
 (0)