Loading core/java/android/view/ViewRootImpl.java +8 −6 Original line number Diff line number Diff line Loading @@ -9154,14 +9154,14 @@ public final class ViewRootImpl implements ViewParent, * Handles an inbound request for scroll capture from the system. If a client is not already * active, a search will be dispatched through the view tree to locate scrolling content. * <p> * Either {@link IScrollCaptureCallbacks#onClientConnected(IScrollCaptureConnection, Rect, * Either {@link IScrollCaptureCallbacks#onConnected(IScrollCaptureConnection, Rect, * Point)} or {@link IScrollCaptureCallbacks#onUnavailable()} will be returned * depending on the results of the search. * * @param callbacks to receive responses * @see ScrollCaptureTargetResolver */ private void handleScrollCaptureRequest(@NonNull IScrollCaptureCallbacks callbacks) { public void handleScrollCaptureRequest(@NonNull IScrollCaptureCallbacks callbacks) { LinkedList<ScrollCaptureTarget> targetList = new LinkedList<>(); // Window (root) level callbacks Loading @@ -9169,10 +9169,12 @@ public final class ViewRootImpl implements ViewParent, // Search through View-tree View rootView = getView(); if (rootView != null) { Point point = new Point(); Rect rect = new Rect(0, 0, rootView.getWidth(), rootView.getHeight()); getChildVisibleRect(rootView, rect, point); rootView.dispatchScrollCaptureSearch(rect, point, targetList); } // No-op path. Scroll capture not offered for this window. if (targetList.isEmpty()) { Loading core/tests/coretests/src/android/view/ViewRootImplTest.java +24 −0 Original line number Diff line number Diff line Loading @@ -35,6 +35,7 @@ import static androidx.test.InstrumentationRegistry.getInstrumentation; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import android.content.Context; import android.os.Binder; Loading @@ -50,6 +51,9 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; /** * Tests for {@link ViewRootImpl} * Loading Loading @@ -195,6 +199,26 @@ public class ViewRootImplTest { assertEquals(behavior, controller.getSystemBarsBehavior()); } /** * Ensure scroll capture request handles a ViewRootImpl with no view tree. */ @Test public void requestScrollCapture_withoutContentRoot() { final CountDownLatch latch = new CountDownLatch(1); mViewRootImpl.handleScrollCaptureRequest(new IScrollCaptureCallbacks.Default() { @Override public void onUnavailable() { latch.countDown(); } }); try { if (latch.await(100, TimeUnit.MILLISECONDS)) { return; // pass } } catch (InterruptedException e) { /* ignore */ } fail("requestScrollCapture did not respond"); } /** * When window doesn't have focus, keys should be dropped. */ Loading Loading
core/java/android/view/ViewRootImpl.java +8 −6 Original line number Diff line number Diff line Loading @@ -9154,14 +9154,14 @@ public final class ViewRootImpl implements ViewParent, * Handles an inbound request for scroll capture from the system. If a client is not already * active, a search will be dispatched through the view tree to locate scrolling content. * <p> * Either {@link IScrollCaptureCallbacks#onClientConnected(IScrollCaptureConnection, Rect, * Either {@link IScrollCaptureCallbacks#onConnected(IScrollCaptureConnection, Rect, * Point)} or {@link IScrollCaptureCallbacks#onUnavailable()} will be returned * depending on the results of the search. * * @param callbacks to receive responses * @see ScrollCaptureTargetResolver */ private void handleScrollCaptureRequest(@NonNull IScrollCaptureCallbacks callbacks) { public void handleScrollCaptureRequest(@NonNull IScrollCaptureCallbacks callbacks) { LinkedList<ScrollCaptureTarget> targetList = new LinkedList<>(); // Window (root) level callbacks Loading @@ -9169,10 +9169,12 @@ public final class ViewRootImpl implements ViewParent, // Search through View-tree View rootView = getView(); if (rootView != null) { Point point = new Point(); Rect rect = new Rect(0, 0, rootView.getWidth(), rootView.getHeight()); getChildVisibleRect(rootView, rect, point); rootView.dispatchScrollCaptureSearch(rect, point, targetList); } // No-op path. Scroll capture not offered for this window. if (targetList.isEmpty()) { Loading
core/tests/coretests/src/android/view/ViewRootImplTest.java +24 −0 Original line number Diff line number Diff line Loading @@ -35,6 +35,7 @@ import static androidx.test.InstrumentationRegistry.getInstrumentation; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import android.content.Context; import android.os.Binder; Loading @@ -50,6 +51,9 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; /** * Tests for {@link ViewRootImpl} * Loading Loading @@ -195,6 +199,26 @@ public class ViewRootImplTest { assertEquals(behavior, controller.getSystemBarsBehavior()); } /** * Ensure scroll capture request handles a ViewRootImpl with no view tree. */ @Test public void requestScrollCapture_withoutContentRoot() { final CountDownLatch latch = new CountDownLatch(1); mViewRootImpl.handleScrollCaptureRequest(new IScrollCaptureCallbacks.Default() { @Override public void onUnavailable() { latch.countDown(); } }); try { if (latch.await(100, TimeUnit.MILLISECONDS)) { return; // pass } } catch (InterruptedException e) { /* ignore */ } fail("requestScrollCapture did not respond"); } /** * When window doesn't have focus, keys should be dropped. */ Loading