Loading core/java/android/view/View.java +9 −2 Original line number Diff line number Diff line Loading @@ -34463,7 +34463,10 @@ public class View implements Drawable.Callback, KeyEvent.Callback, */ @FlaggedApi(android.app.jank.Flags.FLAG_DETAILED_APP_JANK_METRICS_API) public void reportAppJankStats(@NonNull AppJankStats appJankStats) { getRootView().reportAppJankStats(appJankStats); View rootView = getRootView(); if (rootView == this) return; rootView.reportAppJankStats(appJankStats); } /** Loading @@ -34471,6 +34474,10 @@ public class View implements Drawable.Callback, KeyEvent.Callback, * @hide */ public @Nullable JankTracker getJankTracker() { return getRootView().getJankTracker(); View rootView = getRootView(); if (rootView == this) { return null; } return rootView.getJankTracker(); } } tests/AppJankTest/src/android/app/jank/tests/JankTrackerTest.java +14 −2 Original line number Diff line number Diff line Loading @@ -18,10 +18,12 @@ package android.app.jank.tests; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import android.app.jank.Flags; import android.app.jank.JankTracker; import android.app.jank.StateTracker; import android.content.Context; import android.platform.test.annotations.RequiresFlagsEnabled; import android.platform.test.flag.junit.CheckFlagsRule; import android.platform.test.flag.junit.DeviceFlagsValueProvider; Loading Loading @@ -55,10 +57,9 @@ public class JankTrackerTest { * Start an empty activity so decore view is not null when creating the JankTracker instance. */ private static ActivityScenario<EmptyActivity> sEmptyActivityRule; private static String sActivityName; private static View sActivityDecorView; private static Context sContext; @BeforeClass public static void classSetup() { Loading @@ -66,6 +67,7 @@ public class JankTrackerTest { sEmptyActivityRule.onActivity(activity -> { sActivityDecorView = activity.getWindow().getDecorView(); sActivityName = activity.toString(); sContext = activity.getApplicationContext(); }); } Loading Loading @@ -168,4 +170,14 @@ public class JankTrackerTest { assertNotNull(jankTracker); } @Test @RequiresFlagsEnabled(Flags.FLAG_DETAILED_APP_JANK_METRICS_API) public void jankTracker_IsNull_WhenViewNotInHierarchy() { TestWidget testWidget = new TestWidget(sContext); JankTracker jankTracker = testWidget.getJankTracker(); assertNull(jankTracker); } } Loading
core/java/android/view/View.java +9 −2 Original line number Diff line number Diff line Loading @@ -34463,7 +34463,10 @@ public class View implements Drawable.Callback, KeyEvent.Callback, */ @FlaggedApi(android.app.jank.Flags.FLAG_DETAILED_APP_JANK_METRICS_API) public void reportAppJankStats(@NonNull AppJankStats appJankStats) { getRootView().reportAppJankStats(appJankStats); View rootView = getRootView(); if (rootView == this) return; rootView.reportAppJankStats(appJankStats); } /** Loading @@ -34471,6 +34474,10 @@ public class View implements Drawable.Callback, KeyEvent.Callback, * @hide */ public @Nullable JankTracker getJankTracker() { return getRootView().getJankTracker(); View rootView = getRootView(); if (rootView == this) { return null; } return rootView.getJankTracker(); } }
tests/AppJankTest/src/android/app/jank/tests/JankTrackerTest.java +14 −2 Original line number Diff line number Diff line Loading @@ -18,10 +18,12 @@ package android.app.jank.tests; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import android.app.jank.Flags; import android.app.jank.JankTracker; import android.app.jank.StateTracker; import android.content.Context; import android.platform.test.annotations.RequiresFlagsEnabled; import android.platform.test.flag.junit.CheckFlagsRule; import android.platform.test.flag.junit.DeviceFlagsValueProvider; Loading Loading @@ -55,10 +57,9 @@ public class JankTrackerTest { * Start an empty activity so decore view is not null when creating the JankTracker instance. */ private static ActivityScenario<EmptyActivity> sEmptyActivityRule; private static String sActivityName; private static View sActivityDecorView; private static Context sContext; @BeforeClass public static void classSetup() { Loading @@ -66,6 +67,7 @@ public class JankTrackerTest { sEmptyActivityRule.onActivity(activity -> { sActivityDecorView = activity.getWindow().getDecorView(); sActivityName = activity.toString(); sContext = activity.getApplicationContext(); }); } Loading Loading @@ -168,4 +170,14 @@ public class JankTrackerTest { assertNotNull(jankTracker); } @Test @RequiresFlagsEnabled(Flags.FLAG_DETAILED_APP_JANK_METRICS_API) public void jankTracker_IsNull_WhenViewNotInHierarchy() { TestWidget testWidget = new TestWidget(sContext); JankTracker jankTracker = testWidget.getJankTracker(); assertNull(jankTracker); } }