Skip to content

Commit 65aba32

Browse files
committed
Simplify change
1 parent 4f853fa commit 65aba32

File tree

2 files changed

+6
-37
lines changed

2 files changed

+6
-37
lines changed

firebase-perf/src/main/java/com/google/firebase/perf/metrics/AppStartTrace.java

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -324,16 +324,14 @@ private void recordOnDrawFrontOfQueue() {
324324
}
325325

326326
private void resolveIsStartedFromBackground() {
327-
// This a fix for b/339891952 where the runnable on the background thread can run before the
328-
// activity lifecycle callbacks.
327+
// If the runnable hasn't run, it isn't a background start.
329328
if (mainThreadRunnableTime == null) {
330329
return;
331330
}
332331

333-
if (isStartedFromBackground
334-
&& (mainThreadRunnableTime.getDurationMicros() < MAX_BACKGROUND_RUNNABLE_DELAY)) {
335-
// Reset it to false as it was executed pre-emptively.
336-
isStartedFromBackground = false;
332+
// Set it to true if the runnable ran more than 100ms prior to onActivityCreated()
333+
if (mainThreadRunnableTime.getDurationMicros() >= MAX_BACKGROUND_RUNNABLE_DELAY) {
334+
isStartedFromBackground = true;
337335
}
338336
}
339337

@@ -633,11 +631,6 @@ Timer getOnResumeTime() {
633631
return onResumeTime;
634632
}
635633

636-
@VisibleForTesting
637-
void setIsStartFromBackground() {
638-
isStartedFromBackground = true;
639-
}
640-
641634
@VisibleForTesting
642635
void setMainThreadRunnableTime(Timer timer) {
643636
mainThreadRunnableTime = timer;

firebase-perf/src/test/java/com/google/firebase/perf/metrics/AppStartTraceTest.java

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -239,35 +239,12 @@ public void testDelayedAppStart() {
239239
}
240240

241241
@Test
242-
public void testStartFromBackground() {
243-
FakeScheduledExecutorService fakeExecutorService = new FakeScheduledExecutorService();
244-
AppStartTrace trace =
245-
new AppStartTrace(transportManager, clock, configResolver, fakeExecutorService);
246-
trace.setIsStartFromBackground();
247-
trace.onActivityCreated(activity1, bundle);
248-
Assert.assertNull(trace.getOnCreateTime());
249-
++currentTime;
250-
trace.onActivityStarted(activity1);
251-
Assert.assertNull(trace.getOnStartTime());
252-
++currentTime;
253-
trace.onActivityResumed(activity1);
254-
Assert.assertNull(trace.getOnResumeTime());
255-
fakeExecutorService.runAll();
256-
// There should be no trace sent.
257-
verify(transportManager, times(0))
258-
.log(
259-
traceArgumentCaptor.capture(),
260-
ArgumentMatchers.nullable(ApplicationProcessState.class));
261-
}
262-
263-
@Test
264-
public void testStartFromBackground_invertedOrder() {
242+
public void testStartFromBackground_within100ms() {
265243
FakeScheduledExecutorService fakeExecutorService = new FakeScheduledExecutorService();
266244
Timer fakeTimer = spy(new Timer(currentTime));
267245
AppStartTrace trace =
268246
new AppStartTrace(transportManager, clock, configResolver, fakeExecutorService);
269247
trace.registerActivityLifecycleCallbacks(appContext);
270-
trace.setIsStartFromBackground();
271248
trace.setMainThreadRunnableTime(fakeTimer);
272249

273250
when(fakeTimer.getDurationMicros()).thenReturn(99L);
@@ -288,13 +265,12 @@ public void testStartFromBackground_invertedOrder() {
288265
}
289266

290267
@Test
291-
public void testStartFromBackground_delayedInvertedOrder() {
268+
public void testStartFromBackground_moreThan100ms() {
292269
FakeScheduledExecutorService fakeExecutorService = new FakeScheduledExecutorService();
293270
Timer fakeTimer = spy(new Timer(currentTime));
294271
AppStartTrace trace =
295272
new AppStartTrace(transportManager, clock, configResolver, fakeExecutorService);
296273
trace.registerActivityLifecycleCallbacks(appContext);
297-
trace.setIsStartFromBackground();
298274
trace.setMainThreadRunnableTime(fakeTimer);
299275

300276
when(fakeTimer.getDurationMicros()).thenReturn(TimeUnit.MILLISECONDS.toMicros(100) + 1);

0 commit comments

Comments
 (0)