Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e4d15d72 authored by Steven Terrell's avatar Steven Terrell
Browse files

Move pendingJankStats check to JankUtils

This change cleans up some duplicate code by moving it to a utility
class.

Bug: 404877363
Test: atest CoreAppJanktestCases
Flag: EXEMPT bugfix/refactor.
Change-Id: Ie8d3ef8369dfc0619f930ed22e18d5ee32ed9b75
parent 56eefc53
Loading
Loading
Loading
Loading
+5 −24
Original line number Diff line number Diff line
@@ -60,6 +60,7 @@ import java.util.HashMap;
@RunWith(AndroidJUnit4.class)
public class IntegrationTests {
    public static final int WAIT_FOR_TIMEOUT_MS = 5000;
    public static final int WAIT_FOR_PENDING_JANKSTATS_MS = 1000;

    @Rule
    public final CheckFlagsRule mCheckFlagsRule = DeviceFlagsValueProvider.createCheckFlagsRule();
@@ -116,18 +117,8 @@ public class IntegrationTests {

        editText.reportAppJankStats(JankUtils.getAppJankStats());

        // reportAppJankStats performs the work on a background thread, check periodically to see
        // if the work is complete.
        for (int i = 0; i < 10; i++) {
            try {
                Thread.sleep(100);
                if (jankTracker.getPendingJankStats().size() > 0) {
                    break;
                }
            } catch (InterruptedException exception) {
                //do nothing and continue
            }
        }
        // wait until pending results are available.
        JankUtils.waitForResults(jankTracker, WAIT_FOR_PENDING_JANKSTATS_MS);

        pendingStats = jankTracker.getPendingJankStats();

@@ -247,18 +238,8 @@ public class IntegrationTests {
        int mismatchedAppUID = 25;
        editText.reportAppJankStats(JankUtils.getAppJankStats(mismatchedAppUID));

        // reportAppJankStats performs the work on a background thread, check periodically to see
        // if the work is complete.
        for (int i = 0; i < 10; i++) {
            try {
                Thread.sleep(100);
                if (jankTracker.getPendingJankStats().size() > 0) {
                    break;
                }
            } catch (InterruptedException exception) {
                //do nothing and continue
            }
        }
        // wait until pending results should be available.
        JankUtils.waitForResults(jankTracker, WAIT_FOR_PENDING_JANKSTATS_MS);

        pendingStats = jankTracker.getPendingJankStats();

+23 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package android.app.jank.tests;

import android.app.jank.AppJankStats;
import android.app.jank.JankTracker;
import android.app.jank.RelativeFrameTimeHistogram;
import android.os.Process;

@@ -56,4 +57,26 @@ public class JankUtils {
        overrunHistogram.addRelativeFrameTimeMillis(25);
        return overrunHistogram;
    }

    /**
     * When JankStats are reported they are processed on a background thread. This method checks
     * every 100 ms up to the maxWaitTime to see if the pending stat count is greater than zero.
     * If the pending stat count is greater than zero it will return or keep trying until
     * maxWaitTime has elapsed.
     */
    public static void waitForResults(JankTracker jankTracker, int maxWaitTimeMs) {
        int currentWaitTimeMs = 0;
        int threadSleepTimeMs = 100;
        while (currentWaitTimeMs < maxWaitTimeMs) {
            try {
                Thread.sleep(threadSleepTimeMs);
                if (!jankTracker.getPendingJankStats().isEmpty()) {
                    return;
                }
                currentWaitTimeMs += threadSleepTimeMs;
            } catch (InterruptedException exception) {
                // do nothing and continue.
            }
        }
    }
}