diff options
author | 2025-03-21 10:14:22 -0700 | |
---|---|---|
committer | 2025-03-21 10:14:22 -0700 | |
commit | 49e9231d00d809cec6d38957051b9eafcf491f6a (patch) | |
tree | 73362c949f1b6d60223acc1045771505caad014b | |
parent | 364d006c19c6b43d5e1c7cccebf8aeeae6e2a6f1 (diff) | |
parent | 56eefc53ecc7fbe9e23abe3da1b64fac86d648f7 (diff) |
Merge "Confirm UID being reported" into main
3 files changed, 58 insertions, 3 deletions
diff --git a/core/java/android/app/jank/JankTracker.java b/core/java/android/app/jank/JankTracker.java index e3f67811757c..a085701b006a 100644 --- a/core/java/android/app/jank/JankTracker.java +++ b/core/java/android/app/jank/JankTracker.java @@ -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() { diff --git a/tests/AppJankTest/src/android/app/jank/tests/IntegrationTests.java b/tests/AppJankTest/src/android/app/jank/tests/IntegrationTests.java index 229c7bfb53e9..a08b650b4c2f 100644 --- a/tests/AppJankTest/src/android/app/jank/tests/IntegrationTests.java +++ b/tests/AppJankTest/src/android/app/jank/tests/IntegrationTests.java @@ -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()); + } } diff --git a/tests/AppJankTest/src/android/app/jank/tests/JankUtils.java b/tests/AppJankTest/src/android/app/jank/tests/JankUtils.java index 9640a84eb9ca..7067b873d4b7 100644 --- a/tests/AppJankTest/src/android/app/jank/tests/JankUtils.java +++ b/tests/AppJankTest/src/android/app/jank/tests/JankUtils.java @@ -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. */ |