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

Commit 49e9231d authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Confirm UID being reported" into main

parents 364d006c 56eefc53
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -143,6 +143,13 @@ public class JankTracker {
     * stats
     */
    public void mergeAppJankStats(AppJankStats appJankStats) {
        if (appJankStats.getUid() != mAppUid) {
            if (DEBUG) {
                Log.d(DEBUG_KEY, "Reported JankStats AppUID does not match AppUID of "
                        + "enclosing activity.");
            }
            return;
        }
        getHandler().post(new Runnable() {
            @Override
            public void run() {
+42 −0
Original line number Diff line number Diff line
@@ -222,4 +222,46 @@ public class IntegrationTests {

        assertTrue(jankTracker.shouldTrack());
    }

    /*
       When JankTracker is first instantiated it gets passed the apps UID the same UID should be
       passed when reporting AppJankStats. To make sure frames and metrics are all associated with
       the same app these UIDs need to match. This test confirms that mismatched IDs are not
       counted.
     */
    @Test
    @RequiresFlagsEnabled(Flags.FLAG_DETAILED_APP_JANK_METRICS_API)
    public void reportJankStats_statNotMerged_onMisMatchedAppIds() {
        Activity jankTrackerActivity = mJankTrackerActivityRule.launchActivity(null);
        mDevice.wait(Until.findObject(
                        By.text(jankTrackerActivity.getString(R.string.continue_test))),
                WAIT_FOR_TIMEOUT_MS);

        EditText editText = jankTrackerActivity.findViewById(R.id.edit_text);
        JankTracker jankTracker = editText.getJankTracker();

        HashMap<String, JankDataProcessor.PendingJankStat> pendingStats =
                jankTracker.getPendingJankStats();
        assertEquals(0, pendingStats.size());

        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
            }
        }

        pendingStats = jankTracker.getPendingJankStats();

        assertEquals(0, pendingStats.size());
    }
}
+9 −3
Original line number Diff line number Diff line
@@ -18,16 +18,18 @@ package android.app.jank.tests;

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


public class JankUtils {
    private static final int APP_ID = 25;
    private static final int APP_ID = Process.myUid();

    /**
     * Returns a mock AppJankStats object to be used in tests.
     */
    public static AppJankStats getAppJankStats() {
    public static AppJankStats getAppJankStats(int appUID) {
        AppJankStats jankStats = new AppJankStats(
                /*App Uid*/APP_ID,
                /*App Uid*/appUID,
                /*Widget Id*/"test widget id",
                /*navigationComponent*/null,
                /*Widget Category*/AppJankStats.WIDGET_CATEGORY_SCROLL,
@@ -39,6 +41,10 @@ public class JankUtils {
        return jankStats;
    }

    public static AppJankStats getAppJankStats() {
        return getAppJankStats(APP_ID);
    }

    /**
     * Returns a mock histogram to be used with an AppJankStats object.
     */