Skip to content

Commit 51f26d1

Browse files
committed
style(lint): yarn lint:android on performance files
1 parent 1b8df4c commit 51f26d1

3 files changed

Lines changed: 99 additions & 87 deletions

File tree

packages/perf/android/src/main/java/io/invertase/firebase/perf/ScreenTrace.java

Lines changed: 69 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -3,53 +3,48 @@
33
/**
44
* Copyright 2021 Google Inc. All Rights Reserved.
55
*
6-
* Licensed under the Apache License, Version 2.0 (the "License");
7-
* you may not use this file except in compliance with the License.
8-
* You may obtain a copy of the License at
6+
* <p>Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
7+
* except in compliance with the License. You may obtain a copy of the License at
98
*
10-
* http://www.apache.org/licenses/LICENSE-2.0
9+
* <p>http://www.apache.org/licenses/LICENSE-2.0
1110
*
12-
* Unless required by applicable law or agreed to in writing, software
13-
* distributed under the License is distributed on an "AS IS" BASIS,
14-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15-
* See the License for the specific language governing permissions and
11+
* <p>Unless required by applicable law or agreed to in writing, software distributed under the
12+
* License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
13+
* express or implied. See the License for the specific language governing permissions and
1614
* limitations under the License.
1715
*/
18-
1916
import android.app.Activity;
2017
import android.os.Build;
2118
import android.util.Log;
2219
import android.util.SparseIntArray;
2320
import android.view.WindowManager;
24-
2521
import androidx.core.app.FrameMetricsAggregator;
26-
2722
import com.google.firebase.perf.FirebasePerformance;
2823
import com.google.firebase.perf.metrics.Trace;
2924
import com.google.firebase.perf.util.Constants;
3025

3126
/**
32-
* Utility class to capture Screen rendering information (Slow/Frozen frames) for the
33-
* {@code Activity} passed to the constructor {@link io.invertase.firebase.perf.ScreenTrace#ScreenTrace(Activity, String)}.
34-
* <p>
35-
* Learn more at https://firebase.google.com/docs/perf-mon/screen-traces?platform=android.
36-
* <p>
37-
* A slow screen rendering often leads to a UI Jank which creates a bad user experience. Below are
38-
* some tips and references to understand and fix common UI Jank issues:
39-
* - https://developer.android.com/topic/performance/vitals/render.html#fixing_jank
40-
* - https://youtu.be/CaMTIgxCSqU (Why 60fps?)
41-
* - https://youtu.be/HXQhu6qfTVU (Rendering Performance)
42-
* - https://youtu.be/1iaHxmfZGGc (Understanding VSYNC)
43-
* - https://www.youtube.com/playlist?list=PLOU2XLYxmsIKEOXh5TwZEv89aofHzNCiu (Android Performance Patterns)
44-
* <p>
45-
* References:
46-
* - Fireperf Source Code
27+
* Utility class to capture Screen rendering information (Slow/Frozen frames) for the {@code
28+
* Activity} passed to the constructor {@link
29+
* io.invertase.firebase.perf.ScreenTrace#ScreenTrace(Activity, String)}.
30+
*
31+
* <p>Learn more at https://firebase.google.com/docs/perf-mon/screen-traces?platform=android.
32+
*
33+
* <p>A slow screen rendering often leads to a UI Jank which creates a bad user experience. Below
34+
* are some tips and references to understand and fix common UI Jank issues: -
35+
* https://developer.android.com/topic/performance/vitals/render.html#fixing_jank -
36+
* https://youtu.be/CaMTIgxCSqU (Why 60fps?) - https://youtu.be/HXQhu6qfTVU (Rendering Performance)
37+
* - https://youtu.be/1iaHxmfZGGc (Understanding VSYNC) -
38+
* https://www.youtube.com/playlist?list=PLOU2XLYxmsIKEOXh5TwZEv89aofHzNCiu (Android Performance
39+
* Patterns)
40+
*
41+
* <p>References: - Fireperf Source Code
4742
*/
4843
public class ScreenTrace {
4944

5045
private static final String TAG = "RNFirebasePerf";
5146
private static final String FRAME_METRICS_AGGREGATOR_CLASSNAME =
52-
"androidx.core.app.FrameMetricsAggregator";
47+
"androidx.core.app.FrameMetricsAggregator";
5348

5449
private final Activity activity;
5550
private final String traceName;
@@ -61,8 +56,8 @@ public class ScreenTrace {
6156
* Default constructor for this class.
6257
*
6358
* @param activity for which the screen traces should be recorded.
64-
* @param tag used as an identifier for the name to be used to log screen rendering
65-
* information (like "MyFancyScreen").
59+
* @param tag used as an identifier for the name to be used to log screen rendering information
60+
* (like "MyFancyScreen").
6661
* @implNote It requires hardware acceleration to be on or it throws.
6762
*/
6863
public ScreenTrace(Activity activity, String tag) throws IllegalStateException {
@@ -75,17 +70,17 @@ public ScreenTrace(Activity activity, String tag) throws IllegalStateException {
7570
boolean isScreenTraceSupported = checkScreenTraceSupport(activity);
7671

7772
if (!isScreenTraceSupported) {
78-
throw new IllegalStateException("Device does not support screen traces. Hardware acceleration must be enabled and Android must not be 8.0 or 8.1.");
73+
throw new IllegalStateException(
74+
"Device does not support screen traces. Hardware acceleration must be enabled and Android"
75+
+ " must not be 8.0 or 8.1.");
7976
}
8077

8178
frameMetricsAggregator = new FrameMetricsAggregator();
8279
}
8380

8481
// region Public APIs
8582

86-
/**
87-
* Starts recording the frame metrics for the screen traces.
88-
*/
83+
/** Starts recording the frame metrics for the screen traces. */
8984
public void recordScreenTrace() {
9085
Log.d(TAG, "Recording screen trace " + traceName);
9186

@@ -97,7 +92,7 @@ public void recordScreenTrace() {
9792
* Stops recording screen traces and dispatches the trace capturing information on %age of
9893
* Slow/Frozen frames.
9994
*
100-
* Inspired by fireperf source.
95+
* <p>Inspired by fireperf source.
10196
*/
10297
public void sendScreenTrace() {
10398
if (perfScreenTrace == null) return;
@@ -143,12 +138,20 @@ public void sendScreenTrace() {
143138
perfScreenTrace.putMetric(Constants.CounterNames.FRAMES_FROZEN.toString(), frozenFrames);
144139
}
145140

146-
Log.d(TAG, new StringBuilder()
147-
.append("sendScreenTrace ").append(traceName)
148-
.append(", name: ").append(getScreenTraceName())
149-
.append(", total_frames: ").append(totalFrames)
150-
.append(", slow_frames: ").append(slowFrames)
151-
.append(", frozen_frames: ").append(frozenFrames).toString());
141+
Log.d(
142+
TAG,
143+
new StringBuilder()
144+
.append("sendScreenTrace ")
145+
.append(traceName)
146+
.append(", name: ")
147+
.append(getScreenTraceName())
148+
.append(", total_frames: ")
149+
.append(totalFrames)
150+
.append(", slow_frames: ")
151+
.append(slowFrames)
152+
.append(", frozen_frames: ")
153+
.append(frozenFrames)
154+
.toString());
152155

153156
// Stop and record trace
154157
perfScreenTrace.stop();
@@ -161,17 +164,30 @@ public void sendScreenTrace() {
161164
private static boolean checkScreenTraceSupport(Activity activity) {
162165
boolean isValidSDKVersion = checkSDKVersion();
163166
boolean hasFrameMetricsAggregatorClass = checkFrameMetricsAggregatorClass();
164-
boolean isActivityHardwareAccelerated = activity.getWindow() != null
165-
&& ((activity.getWindow().getAttributes().flags & WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED) != 0);
166-
167-
168-
boolean supported = isValidSDKVersion && hasFrameMetricsAggregatorClass && isActivityHardwareAccelerated;
169-
170-
Log.d(TAG, new StringBuilder()
171-
.append("isValidSDKVersion: ").append(isValidSDKVersion)
172-
.append("isScreenTraceSupported(").append(activity).append("): ").append(supported)
173-
.append(" [hasFrameMetricsAggregatorClass: ").append(hasFrameMetricsAggregatorClass)
174-
.append(", isActivityHardwareAccelerated: ").append(isActivityHardwareAccelerated).append("]").toString());
167+
boolean isActivityHardwareAccelerated =
168+
activity.getWindow() != null
169+
&& ((activity.getWindow().getAttributes().flags
170+
& WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED)
171+
!= 0);
172+
173+
boolean supported =
174+
isValidSDKVersion && hasFrameMetricsAggregatorClass && isActivityHardwareAccelerated;
175+
176+
Log.d(
177+
TAG,
178+
new StringBuilder()
179+
.append("isValidSDKVersion: ")
180+
.append(isValidSDKVersion)
181+
.append("isScreenTraceSupported(")
182+
.append(activity)
183+
.append("): ")
184+
.append(supported)
185+
.append(" [hasFrameMetricsAggregatorClass: ")
186+
.append(hasFrameMetricsAggregatorClass)
187+
.append(", isActivityHardwareAccelerated: ")
188+
.append(isActivityHardwareAccelerated)
189+
.append("]")
190+
.toString());
175191

176192
return supported;
177193
}
@@ -184,9 +200,7 @@ private static boolean checkSDKVersion() {
184200
return true;
185201
}
186202

187-
/**
188-
* Inspired by fireperf source.
189-
*/
203+
/** Inspired by fireperf source. */
190204
private static boolean checkFrameMetricsAggregatorClass() {
191205
try {
192206
Class<?> initializerClass = Class.forName(FRAME_METRICS_AGGREGATOR_CLASSNAME);
@@ -196,9 +210,7 @@ private static boolean checkFrameMetricsAggregatorClass() {
196210
}
197211
}
198212

199-
/**
200-
* Inspired by fireperf source.
201-
*/
213+
/** Inspired by fireperf source. */
202214
private String getScreenTraceName() {
203215
return Constants.SCREEN_TRACE_PREFIX + traceName;
204216
}

packages/perf/android/src/main/java/io/invertase/firebase/perf/UniversalFirebasePerfModule.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -105,24 +105,24 @@ Task<Void> stopTrace(int id, Bundle metrics, Bundle attributes) {
105105

106106
Task<Void> startScreenTrace(Activity activity, int id, String identifier) {
107107
return Tasks.call(
108-
() -> {
109-
ScreenTrace screenTrace = new ScreenTrace(activity, identifier);
110-
screenTrace.recordScreenTrace();
111-
screenTraces.put(id, screenTrace);
108+
() -> {
109+
ScreenTrace screenTrace = new ScreenTrace(activity, identifier);
110+
screenTrace.recordScreenTrace();
111+
screenTraces.put(id, screenTrace);
112112

113-
return null;
114-
});
113+
return null;
114+
});
115115
}
116116

117117
Task<Void> stopScreenTrace(int id) {
118118
return Tasks.call(
119-
() -> {
120-
ScreenTrace trace = screenTraces.get(id);
121-
trace.sendScreenTrace();
122-
screenTraces.remove(id);
119+
() -> {
120+
ScreenTrace trace = screenTraces.get(id);
121+
trace.sendScreenTrace();
122+
screenTraces.remove(id);
123123

124-
return null;
125-
});
124+
return null;
125+
});
126126
}
127127

128128
Task<Void> startHttpMetric(int id, String url, String httpMethod) {

packages/perf/android/src/reactnative/java/io/invertase/firebase/perf/ReactNativeFirebasePerfModule.java

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -97,29 +97,29 @@ public void startScreenTrace(int id, String identifier, Promise promise) {
9797
}
9898

9999
module
100-
.startScreenTrace(currentActivity, id, identifier)
101-
.addOnCompleteListener(
102-
task -> {
103-
if (task.isSuccessful()) {
104-
promise.resolve(task.getResult());
105-
} else {
106-
rejectPromiseWithExceptionMap(promise, task.getException());
107-
}
108-
});
100+
.startScreenTrace(currentActivity, id, identifier)
101+
.addOnCompleteListener(
102+
task -> {
103+
if (task.isSuccessful()) {
104+
promise.resolve(task.getResult());
105+
} else {
106+
rejectPromiseWithExceptionMap(promise, task.getException());
107+
}
108+
});
109109
}
110110

111111
@ReactMethod
112112
public void stopScreenTrace(int id, Promise promise) {
113113
module
114-
.stopScreenTrace(id)
115-
.addOnCompleteListener(
116-
task -> {
117-
if (task.isSuccessful()) {
118-
promise.resolve(task.getResult());
119-
} else {
120-
rejectPromiseWithExceptionMap(promise, task.getException());
121-
}
122-
});
114+
.stopScreenTrace(id)
115+
.addOnCompleteListener(
116+
task -> {
117+
if (task.isSuccessful()) {
118+
promise.resolve(task.getResult());
119+
} else {
120+
rejectPromiseWithExceptionMap(promise, task.getException());
121+
}
122+
});
123123
}
124124

125125
@ReactMethod

0 commit comments

Comments
 (0)