Loading core/java/android/app/jank/JankTracker.java +7 −0 Original line number Diff line number Diff line Loading @@ -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() { Loading tests/AppJankTest/src/android/app/jank/tests/IntegrationTests.java +42 −0 Original line number Diff line number Diff line Loading @@ -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()); } } tests/AppJankTest/src/android/app/jank/tests/JankUtils.java +9 −3 Original line number Diff line number Diff line Loading @@ -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, Loading @@ -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. */ Loading Loading
core/java/android/app/jank/JankTracker.java +7 −0 Original line number Diff line number Diff line Loading @@ -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() { Loading
tests/AppJankTest/src/android/app/jank/tests/IntegrationTests.java +42 −0 Original line number Diff line number Diff line Loading @@ -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()); } }
tests/AppJankTest/src/android/app/jank/tests/JankUtils.java +9 −3 Original line number Diff line number Diff line Loading @@ -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, Loading @@ -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. */ Loading