diff options
author | Mark Renouf <mrenouf@google.com> | 2020-10-02 16:14:12 -0400 |
---|---|---|
committer | Mark Renouf <mrenouf@google.com> | 2020-10-19 14:48:32 -0400 |
commit | 749b6360a15d3b4c215163cc1237b2c75b7410bf (patch) | |
tree | 78ea3f282689f46fed8224ce85028dbb774b9193 | |
parent | c1a295c62b7ba92e9dd592d4c7b4c3cc27361124 (diff) |
Refactor names of internal scrollcapture interfaces
Renames to better align with use and existing naming patterns.
Using 'connection' to avoid confusion as to control flow or
roles. (A connection is direct from SystemUI --> App process)
IScrollCaptureClient -> IScrollCaptureConnection
IScrollCaptureController -> IScrollCaptureCallbacks
Test: atest FrameworksCoreTests:ScrollCaptureConnectionTest \
FrameworksCoreTests:ScrollCaptureTargetResolverTest \
ScrollCaptureTest
Change-Id: I9afd33109f6718b61d172ce3e4b3bb5d71a2897e
18 files changed, 178 insertions, 225 deletions
diff --git a/config/boot-image-profile.txt b/config/boot-image-profile.txt index f43bd2bd61b9..01272c7966ac 100644 --- a/config/boot-image-profile.txt +++ b/config/boot-image-profile.txt @@ -47131,8 +47131,8 @@ Landroid/view/IRemoteAnimationRunner; Landroid/view/IRotationWatcher$Stub$Proxy; Landroid/view/IRotationWatcher$Stub; Landroid/view/IRotationWatcher; -Landroid/view/IScrollCaptureController$Stub; -Landroid/view/IScrollCaptureController; +Landroid/view/IScrollCaptureCallbacks$Stub; +Landroid/view/IScrollCaptureCallbacks; Landroid/view/ISystemGestureExclusionListener$Stub$Proxy; Landroid/view/ISystemGestureExclusionListener$Stub; Landroid/view/ISystemGestureExclusionListener; diff --git a/core/java/android/view/IScrollCaptureController.aidl b/core/java/android/view/IScrollCaptureCallbacks.aidl index 8474a00b302f..d97e3c66cc5d 100644 --- a/core/java/android/view/IScrollCaptureController.aidl +++ b/core/java/android/view/IScrollCaptureCallbacks.aidl @@ -20,32 +20,31 @@ import android.graphics.Point; import android.graphics.Rect; import android.view.Surface; -import android.view.IScrollCaptureClient; +import android.view.IScrollCaptureConnection; /** - * Interface to a controller passed to the {@link IScrollCaptureClient} which provides the client an - * asynchronous callback channel for responses. + * Asynchronous callback channel for responses to scroll capture requests. * * {@hide} */ -interface IScrollCaptureController { +interface IScrollCaptureCallbacks { /** - * Scroll capture is available, and a client connect has been returned. + * Scroll capture is available, and a connection has been provided. * - * @param client interface to a ScrollCaptureCallback in the window process + * @param connection a connection to a window process and scrollable content * @param scrollAreaInWindow the location of scrolling in global (window) coordinate space */ - oneway void onClientConnected(in IScrollCaptureClient client, in Rect scrollBounds, + oneway void onConnected(in IScrollCaptureConnection connection, in Rect scrollBounds, in Point positionInWindow); /** - * Nothing in the window can be scrolled, scroll capture not offered. + * The window does not support scroll capture. */ - oneway void onClientUnavailable(); + oneway void onUnavailable(); /** - * Notifies the system that the client has confirmed the request and is ready to begin providing - * image requests. + * Called when the remote end has confirmed the request and is ready to begin providing image + * requests. */ oneway void onCaptureStarted(); diff --git a/core/java/android/view/IScrollCaptureClient.aidl b/core/java/android/view/IScrollCaptureConnection.aidl index 5f135a37dfef..63a4f48aeb20 100644 --- a/core/java/android/view/IScrollCaptureClient.aidl +++ b/core/java/android/view/IScrollCaptureConnection.aidl @@ -26,7 +26,7 @@ import android.view.Surface; * * {@hide} */ -interface IScrollCaptureClient { +interface IScrollCaptureConnection { /** * Informs the client that it has been selected for scroll capture and should prepare to diff --git a/core/java/android/view/IWindow.aidl b/core/java/android/view/IWindow.aidl index 193e674dd1b0..e685b30421be 100644 --- a/core/java/android/view/IWindow.aidl +++ b/core/java/android/view/IWindow.aidl @@ -26,7 +26,7 @@ import android.view.DisplayCutout; import android.view.DragEvent; import android.view.InsetsSourceControl; import android.view.InsetsState; -import android.view.IScrollCaptureController; +import android.view.IScrollCaptureCallbacks; import android.view.KeyEvent; import android.view.MotionEvent; import android.window.ClientWindowFrames; @@ -137,7 +137,7 @@ oneway interface IWindow { /** * Called when Scroll Capture support is requested for a window. * - * @param controller the controller to receive responses + * @param callbacks to receive responses */ - void requestScrollCapture(in IScrollCaptureController controller); + void requestScrollCapture(in IScrollCaptureCallbacks callbacks); } diff --git a/core/java/android/view/IWindowManager.aidl b/core/java/android/view/IWindowManager.aidl index c460f74e7460..3c5d336b840d 100644 --- a/core/java/android/view/IWindowManager.aidl +++ b/core/java/android/view/IWindowManager.aidl @@ -42,7 +42,7 @@ import android.view.IDisplayFoldListener; import android.view.IDisplayWindowRotationController; import android.view.IOnKeyguardExitResult; import android.view.IPinnedStackListener; -import android.view.IScrollCaptureController; +import android.view.IScrollCaptureCallbacks; import android.view.RemoteAnimationAdapter; import android.view.IRotationWatcher; import android.view.ISystemGestureExclusionListener; @@ -751,12 +751,10 @@ interface IWindowManager * @param behindClient token for a window, used to filter the search to windows behind it, or * {@code null} to accept a window at any zOrder * @param taskId specifies the id of a task the result must belong to, or -1 to ignore task ids - * @param controller the controller to receive results, a call to either - * {@link IScrollCaptureController#onClientConnected} or - * {@link IScrollCaptureController#onClientUnavailable}. + * @param callbacks the object to receive replies */ void requestScrollCapture(int displayId, IBinder behindClient, int taskId, - IScrollCaptureController controller); + IScrollCaptureCallbacks callbacks); /** * Holds the WM lock for the specified amount of milliseconds. diff --git a/core/java/android/view/ScrollCaptureCallback.java b/core/java/android/view/ScrollCaptureCallback.java index e1a4e7443600..d3aad2c72d27 100644 --- a/core/java/android/view/ScrollCaptureCallback.java +++ b/core/java/android/view/ScrollCaptureCallback.java @@ -29,8 +29,8 @@ import java.util.function.Consumer; * callbacks registered within the window. * <p> * A callback is assigned to a View using {@link View#setScrollCaptureCallback}, or to the window as - * {@link Window#addScrollCaptureCallback}. The point where the callback is registered defines the - * frame of reference for the bounds measurements used. + * {@link Window#registerScrollCaptureCallback}. The point where the callback is registered defines + * the frame of reference for the bounds measurements used. * <p> * <b>Terminology</b> * <dl> @@ -39,9 +39,9 @@ import java.util.function.Consumer; * is assigned directly to a window.</dd> * * <dt>Scroll Bounds</dt> - * <dd>A rectangle which describes an area within the containing view where scrolling content may - * be positioned. This may be the Containing View bounds itself, or any rectangle within. - * Requested by {@link #onScrollCaptureSearch}.</dd> + * <dd>A rectangle which describes an area within the containing view where scrolling content + * appears. This may be the entire view or any rectangle within. This defines a frame of reference + * for requests as well as the width and maximum height of a single request.</dd> * * <dt>Scroll Delta</dt> * <dd>The distance the scroll position has moved since capture started. Implementations are @@ -57,7 +57,7 @@ import java.util.function.Consumer; * * @see View#setScrollCaptureHint(int) * @see View#setScrollCaptureCallback(ScrollCaptureCallback) - * @see Window#addScrollCaptureCallback(ScrollCaptureCallback) + * @see Window#registerScrollCaptureCallback(ScrollCaptureCallback) * * @hide */ diff --git a/core/java/android/view/ScrollCaptureClient.java b/core/java/android/view/ScrollCaptureConnection.java index f163124f3a98..0e6cdd1dbec5 100644 --- a/core/java/android/view/ScrollCaptureClient.java +++ b/core/java/android/view/ScrollCaptureConnection.java @@ -19,7 +19,6 @@ package android.view; import static java.util.Objects.requireNonNull; import android.annotation.NonNull; -import android.annotation.Nullable; import android.annotation.UiThread; import android.annotation.WorkerThread; import android.graphics.Point; @@ -33,15 +32,15 @@ import com.android.internal.annotations.VisibleForTesting; import java.util.concurrent.atomic.AtomicBoolean; /** - * A client of the system providing Scroll Capture capability on behalf of a Window. + * Mediator between a selected scroll capture target view and a remote process. * <p> * An instance is created to wrap the selected {@link ScrollCaptureCallback}. * * @hide */ -public class ScrollCaptureClient extends IScrollCaptureClient.Stub { +public class ScrollCaptureConnection extends IScrollCaptureConnection.Stub { - private static final String TAG = "ScrollCaptureClient"; + private static final String TAG = "ScrollCaptureConnection"; private static final int DEFAULT_TIMEOUT = 1000; private final Handler mHandler; @@ -49,7 +48,7 @@ public class ScrollCaptureClient extends IScrollCaptureClient.Stub { private int mTimeoutMillis = DEFAULT_TIMEOUT; protected Surface mSurface; - private IScrollCaptureController mController; + private IScrollCaptureCallbacks mCallbacks; private final Rect mScrollBounds; private final Point mPositionInWindow; @@ -62,18 +61,18 @@ public class ScrollCaptureClient extends IScrollCaptureClient.Stub { private DelayedAction mTimeoutAction; /** - * Constructs a ScrollCaptureClient. + * Constructs a ScrollCaptureConnection. * * @param selectedTarget the target the client is controlling - * @param controller the callbacks to reply to system requests + * @param callbacks the callbacks to reply to system requests * * @hide */ - public ScrollCaptureClient( + public ScrollCaptureConnection( @NonNull ScrollCaptureTarget selectedTarget, - @NonNull IScrollCaptureController controller) { + @NonNull IScrollCaptureCallbacks callbacks) { requireNonNull(selectedTarget, "<selectedTarget> must non-null"); - requireNonNull(controller, "<controller> must non-null"); + requireNonNull(callbacks, "<callbacks> must non-null"); final Rect scrollBounds = requireNonNull(selectedTarget.getScrollBounds(), "target.getScrollBounds() must be non-null to construct a client"); @@ -82,7 +81,7 @@ public class ScrollCaptureClient extends IScrollCaptureClient.Stub { mScrollBounds = new Rect(scrollBounds); mPositionInWindow = new Point(selectedTarget.getPositionInWindow()); - mController = controller; + mCallbacks = callbacks; mCloseGuard = new CloseGuard(); mCloseGuard.open("close"); @@ -106,14 +105,13 @@ public class ScrollCaptureClient extends IScrollCaptureClient.Stub { mTimeoutMillis = timeoutMillis; } - @Nullable @VisibleForTesting public DelayedAction getTimeoutAction() { return mTimeoutAction; } private void checkConnected() { - if (mSelectedTarget == null || mController == null) { + if (mSelectedTarget == null || mCallbacks == null) { throw new IllegalStateException("This client has been disconnected."); } } @@ -124,7 +122,7 @@ public class ScrollCaptureClient extends IScrollCaptureClient.Stub { } } - @WorkerThread // IScrollCaptureClient + @WorkerThread // IScrollCaptureConnection @Override public void startCapture(Surface surface) throws RemoteException { checkConnected(); @@ -140,7 +138,7 @@ public class ScrollCaptureClient extends IScrollCaptureClient.Stub { if (cancelTimeout()) { mHandler.post(() -> { try { - mController.onCaptureStarted(); + mCallbacks.onCaptureStarted(); } catch (RemoteException e) { doShutdown(); } @@ -153,7 +151,7 @@ public class ScrollCaptureClient extends IScrollCaptureClient.Stub { endCapture(); } - @WorkerThread // IScrollCaptureClient + @WorkerThread // IScrollCaptureConnection @Override public void requestImage(Rect requestRect) { checkConnected(); @@ -170,7 +168,7 @@ public class ScrollCaptureClient extends IScrollCaptureClient.Stub { if (cancelTimeout()) { mHandler.post(() -> { try { - mController.onCaptureBufferSent(frameNumber, finalCapturedArea); + mCallbacks.onCaptureBufferSent(frameNumber, finalCapturedArea); } catch (RemoteException e) { doShutdown(); } @@ -183,7 +181,7 @@ public class ScrollCaptureClient extends IScrollCaptureClient.Stub { endCapture(); } - @WorkerThread // IScrollCaptureClient + @WorkerThread // IScrollCaptureConnection @Override public void endCapture() { if (isStarted()) { @@ -196,7 +194,7 @@ public class ScrollCaptureClient extends IScrollCaptureClient.Stub { } private boolean isStarted() { - return mController != null && mSelectedTarget != null; + return mCallbacks != null && mSelectedTarget != null; } @UiThread @@ -214,8 +212,8 @@ public class ScrollCaptureClient extends IScrollCaptureClient.Stub { private void doShutdown() { try { - if (mController != null) { - mController.onConnectionClosed(); + if (mCallbacks != null) { + mCallbacks.onConnectionClosed(); } } catch (RemoteException e) { // Ignore @@ -235,15 +233,15 @@ public class ScrollCaptureClient extends IScrollCaptureClient.Stub { } mSelectedTarget = null; - mController = null; + mCallbacks = null; } /** @return a string representation of the state of this client */ public String toString() { - return "ScrollCaptureClient{" + return "ScrollCaptureConnection{" + ", session=" + mSession + ", selectedTarget=" + mSelectedTarget - + ", clientCallbacks=" + mController + + ", clientCallbacks=" + mCallbacks + "}"; } diff --git a/core/java/android/view/ScrollCaptureSession.java b/core/java/android/view/ScrollCaptureSession.java index 628e23fb3f5e..92617a325265 100644 --- a/core/java/android/view/ScrollCaptureSession.java +++ b/core/java/android/view/ScrollCaptureSession.java @@ -36,15 +36,15 @@ public class ScrollCaptureSession { private final Point mPositionInWindow; @Nullable - private ScrollCaptureClient mClient; + private ScrollCaptureConnection mConnection; /** @hide */ public ScrollCaptureSession(Surface surface, Rect scrollBounds, Point positionInWindow, - ScrollCaptureClient client) { + ScrollCaptureConnection connection) { mSurface = surface; mScrollBounds = scrollBounds; mPositionInWindow = positionInWindow; - mClient = client; + mConnection = connection; } /** @@ -88,8 +88,8 @@ public class ScrollCaptureSession { * @param capturedArea the area captured, relative to scroll bounds */ public void notifyBufferSent(long frameNumber, @NonNull Rect capturedArea) { - if (mClient != null) { - mClient.onRequestImageCompleted(frameNumber, capturedArea); + if (mConnection != null) { + mConnection.onRequestImageCompleted(frameNumber, capturedArea); } } @@ -97,7 +97,7 @@ public class ScrollCaptureSession { * @hide */ public void disconnect() { - mClient = null; + mConnection = null; if (mSurface.isValid()) { mSurface.release(); } diff --git a/core/java/android/view/ScrollCaptureTargetResolver.java b/core/java/android/view/ScrollCaptureTargetResolver.java index 71e82c511e2c..5106534694a1 100644 --- a/core/java/android/view/ScrollCaptureTargetResolver.java +++ b/core/java/android/view/ScrollCaptureTargetResolver.java @@ -57,7 +57,6 @@ import java.util.function.Consumer; @UiThread public class ScrollCaptureTargetResolver { private static final String TAG = "ScrollCaptureTargetRes"; - private static final boolean DEBUG = true; private final Object mLock = new Object(); @@ -86,18 +85,11 @@ public class ScrollCaptureTargetResolver { * Binary operator which selects the best {@link ScrollCaptureTarget}. */ private static ScrollCaptureTarget chooseTarget(ScrollCaptureTarget a, ScrollCaptureTarget b) { - Log.d(TAG, "chooseTarget: " + a + " or " + b); - // Nothing plus nothing is still nothing. if (a == null && b == null) { - Log.d(TAG, "chooseTarget: (both null) return " + null); return null; - } - // Prefer non-null. - if (a == null || b == null) { + } else if (a == null || b == null) { ScrollCaptureTarget c = (a == null) ? b : a; - Log.d(TAG, "chooseTarget: (other is null) return " + c); return c; - } boolean emptyScrollBoundsA = nullOrEmpty(a.getScrollBounds()); @@ -155,8 +147,7 @@ public class ScrollCaptureTargetResolver { * * @param targets a list of {@link ScrollCaptureTarget} as collected by {@link * View#dispatchScrollCaptureSearch}. - * @param uiHandler the UI thread handler for the view tree - * @see #start(long, Consumer) + * @see #start(Handler, long, Consumer) */ public ScrollCaptureTargetResolver(Queue<ScrollCaptureTarget> targets) { mTargets = targets; @@ -184,7 +175,6 @@ public class ScrollCaptureTargetResolver { return mResult; } - private void supplyResult(ScrollCaptureTarget target) { checkThread(); if (mFinished) { @@ -232,12 +222,11 @@ public class ScrollCaptureTargetResolver { return; } mStarted = true; - uiHandler.post(() -> run(timeLimitMillis, resultConsumer)); + uiHandler.post(this::run); } } - - private void run(long timeLimitMillis, Consumer<ScrollCaptureTarget> resultConsumer) { + private void run() { checkThread(); mPendingBoundsRequests = mTargets.size(); @@ -248,15 +237,11 @@ public class ScrollCaptureTargetResolver { mHandler.postAtTime(mTimeoutRunnable, mDeadlineMillis); } - private final Runnable mTimeoutRunnable = new Runnable() { - @Override - public void run() { - checkThread(); - supplyResult(null); - } + private final Runnable mTimeoutRunnable = () -> { + checkThread(); + supplyResult(null); }; - /** * Adds a target to the list and requests {@link ScrollCaptureCallback#onScrollCaptureSearch} * scrollBounds} from it. Results are returned by a call to {@link #onScrollBoundsProvided}. @@ -274,7 +259,6 @@ public class ScrollCaptureTargetResolver { // Queue and consume on the UI thread ((scrollBounds) -> mHandler.post( () -> onScrollBoundsProvided(target, scrollBounds))))); - } @UiThread @@ -300,14 +284,8 @@ public class ScrollCaptureTargetResolver { supplyResult(target); } - System.err.println("mPendingBoundsRequests: " + mPendingBoundsRequests); - System.err.println("mDeadlineMillis: " + mDeadlineMillis); - System.err.println("SystemClock.elapsedRealtime(): " + SystemClock.elapsedRealtime()); - if (!mFinished) { // Reschedule the timeout. - System.err.println( - "We think we're NOT done yet and will check back at " + mDeadlineMillis); mHandler.postAtTime(mTimeoutRunnable, mDeadlineMillis); } } @@ -334,44 +312,17 @@ public class ScrollCaptureTargetResolver { return otherParent == view; } - private static int findRelation(@NonNull View a, @NonNull View b) { - if (a == b) { - return 0; - } - - ViewParent parentA = a.getParent(); - ViewParent parentB = b.getParent(); - - while (parentA != null || parentB != null) { - if (parentA == parentB) { - return 0; - } - if (parentA == b) { - return 1; // A is descendant of B - } - if (parentB == a) { - return -1; // B is descendant of A - } - if (parentA != null) { - parentA = parentA.getParent(); - } - if (parentB != null) { - parentB = parentB.getParent(); - } - } - return 0; - } - /** * A safe wrapper for a consumer callbacks intended to accept a single value. It ensures * that the receiver of the consumer does not retain a reference to {@code target} after use nor * cause race conditions by invoking {@link Consumer#accept accept} more than once. - * - * @param target the target consumer */ static class SingletonConsumer<T> implements Consumer<T> { final AtomicReference<Consumer<T>> mAtomicRef; + /** + * @param target the target consumer + **/ SingletonConsumer(Consumer<T> target) { mAtomicRef = new AtomicReference<>(target); } diff --git a/core/java/android/view/ViewRootImpl.java b/core/java/android/view/ViewRootImpl.java index 80f5c0fb8257..f0203011b4f2 100644 --- a/core/java/android/view/ViewRootImpl.java +++ b/core/java/android/view/ViewRootImpl.java @@ -649,7 +649,7 @@ public final class ViewRootImpl implements ViewParent, private final InsetsController mInsetsController; private final ImeFocusController mImeFocusController; - private ScrollCaptureClient mScrollCaptureClient; + private ScrollCaptureConnection mScrollCaptureConnection; /** * @return {@link ImeFocusController} for this instance. @@ -659,10 +659,10 @@ public final class ViewRootImpl implements ViewParent, return mImeFocusController; } - /** @return The current {@link ScrollCaptureClient} for this instance, if any is active. */ + /** @return The current {@link ScrollCaptureConnection} for this instance, if any is active. */ @Nullable - public ScrollCaptureClient getScrollCaptureClient() { - return mScrollCaptureClient; + public ScrollCaptureConnection getScrollCaptureConnection() { + return mScrollCaptureConnection; } private final GestureExclusionTracker mGestureExclusionTracker = new GestureExclusionTracker(); @@ -5192,7 +5192,7 @@ public final class ViewRootImpl implements ViewParent, updateLocationInParentDisplay(msg.arg1, msg.arg2); } break; case MSG_REQUEST_SCROLL_CAPTURE: - handleScrollCaptureRequest((IScrollCaptureController) msg.obj); + handleScrollCaptureRequest((IScrollCaptureCallbacks) msg.obj); break; } } @@ -8979,10 +8979,10 @@ public final class ViewRootImpl implements ViewParent, /** * Dispatches a scroll capture request to the view hierarchy on the ui thread. * - * @param controller the controller to receive replies + * @param callbacks for replies */ - public void dispatchScrollCaptureRequest(@NonNull IScrollCaptureController controller) { - mHandler.obtainMessage(MSG_REQUEST_SCROLL_CAPTURE, controller).sendToTarget(); + public void dispatchScrollCaptureRequest(@NonNull IScrollCaptureCallbacks callbacks) { + mHandler.obtainMessage(MSG_REQUEST_SCROLL_CAPTURE, callbacks).sendToTarget(); } /** @@ -9007,14 +9007,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 IScrollCaptureController#onClientConnected(IScrollCaptureClient, Rect, - * Point)} or {@link IScrollCaptureController#onClientUnavailable()} will be returned + * Either {@link IScrollCaptureCallbacks#onClientConnected(IScrollCaptureConnection, Rect, + * Point)} or {@link IScrollCaptureCallbacks#onUnavailable()} will be returned * depending on the results of the search. * - * @param controller the interface to the system controller + * @param callbacks to receive responses * @see ScrollCaptureTargetResolver */ - private void handleScrollCaptureRequest(@NonNull IScrollCaptureController controller) { + private void handleScrollCaptureRequest(@NonNull IScrollCaptureCallbacks callbacks) { LinkedList<ScrollCaptureTarget> targetList = new LinkedList<>(); // Window (root) level callbacks @@ -9029,7 +9029,7 @@ public final class ViewRootImpl implements ViewParent, // No-op path. Scroll capture not offered for this window. if (targetList.isEmpty()) { - dispatchScrollCaptureSearchResult(controller, null); + dispatchScrollCaptureSearchResult(callbacks, null); return; } @@ -9037,12 +9037,12 @@ public final class ViewRootImpl implements ViewParent, // Continues with the consumer once all responses are consumed, or the timeout expires. ScrollCaptureTargetResolver resolver = new ScrollCaptureTargetResolver(targetList); resolver.start(mHandler, 1000, - (selected) -> dispatchScrollCaptureSearchResult(controller, selected)); + (selected) -> dispatchScrollCaptureSearchResult(callbacks, selected)); } /** Called by {@link #handleScrollCaptureRequest} when a result is returned */ private void dispatchScrollCaptureSearchResult( - @NonNull IScrollCaptureController controller, + @NonNull IScrollCaptureCallbacks callbacks, @Nullable ScrollCaptureTarget selectedTarget) { // If timeout or no eligible targets found. @@ -9051,31 +9051,31 @@ public final class ViewRootImpl implements ViewParent, if (DEBUG_SCROLL_CAPTURE) { Log.d(TAG, "scrollCaptureSearch returned no targets available."); } - controller.onClientUnavailable(); + callbacks.onUnavailable(); } catch (RemoteException e) { if (DEBUG_SCROLL_CAPTURE) { - Log.w(TAG, "Failed to notify controller of scroll capture search result.", e); + Log.w(TAG, "Failed to send scroll capture search result.", e); } } return; } // Create a client instance and return it to the caller - mScrollCaptureClient = new ScrollCaptureClient(selectedTarget, controller); + mScrollCaptureConnection = new ScrollCaptureConnection(selectedTarget, callbacks); try { if (DEBUG_SCROLL_CAPTURE) { - Log.d(TAG, "scrollCaptureSearch returning client: " + getScrollCaptureClient()); + Log.d(TAG, "scrollCaptureSearch returning client: " + getScrollCaptureConnection()); } - controller.onClientConnected( - mScrollCaptureClient, + callbacks.onConnected( + mScrollCaptureConnection, selectedTarget.getScrollBounds(), selectedTarget.getPositionInWindow()); } catch (RemoteException e) { if (DEBUG_SCROLL_CAPTURE) { - Log.w(TAG, "Failed to notify controller of scroll capture search result.", e); + Log.w(TAG, "Failed to send scroll capture search result.", e); } - mScrollCaptureClient.disconnect(); - mScrollCaptureClient = null; + mScrollCaptureConnection.disconnect(); + mScrollCaptureConnection = null; } } @@ -9373,10 +9373,10 @@ public final class ViewRootImpl implements ViewParent, } @Override - public void requestScrollCapture(IScrollCaptureController controller) { + public void requestScrollCapture(IScrollCaptureCallbacks callbacks) { final ViewRootImpl viewAncestor = mViewAncestor.get(); if (viewAncestor != null) { - viewAncestor.dispatchScrollCaptureRequest(controller); + viewAncestor.dispatchScrollCaptureRequest(callbacks); } } } diff --git a/core/java/android/view/Window.java b/core/java/android/view/Window.java index 1dbf37aca689..5331a1b8d538 100644 --- a/core/java/android/view/Window.java +++ b/core/java/android/view/Window.java @@ -2560,19 +2560,20 @@ public abstract class Window { /** * System request to begin scroll capture. * - * @param controller the controller to receive responses + * @param callbacks to receive responses * @hide */ - public void requestScrollCapture(IScrollCaptureController controller) { + public void requestScrollCapture(IScrollCaptureCallbacks callbacks) { } /** - * Registers a {@link ScrollCaptureCallback} with the root of this window. + * Used to provide scroll capture support for an arbitrary window. This registeres the given + * callback with the root view of the window. * * @param callback the callback to add * @hide */ - public void addScrollCaptureCallback(@NonNull ScrollCaptureCallback callback) { + public void registerScrollCaptureCallback(@NonNull ScrollCaptureCallback callback) { } /** @@ -2581,7 +2582,7 @@ public abstract class Window { * @param callback the callback to remove * @hide */ - public void removeScrollCaptureCallback(@NonNull ScrollCaptureCallback callback) { + public void unregisterScrollCaptureCallback(@NonNull ScrollCaptureCallback callback) { } /** @hide */ diff --git a/core/java/com/android/internal/policy/PhoneWindow.java b/core/java/com/android/internal/policy/PhoneWindow.java index 50eed27976ad..469c41e5efb9 100644 --- a/core/java/com/android/internal/policy/PhoneWindow.java +++ b/core/java/com/android/internal/policy/PhoneWindow.java @@ -77,7 +77,7 @@ import android.util.TypedValue; import android.view.ContextThemeWrapper; import android.view.Gravity; import android.view.IRotationWatcher.Stub; -import android.view.IScrollCaptureController; +import android.view.IScrollCaptureCallbacks; import android.view.IWindowManager; import android.view.InputDevice; import android.view.InputEvent; @@ -3910,12 +3910,12 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback { /** * System request to begin scroll capture. * - * @param controller the controller to receive responses + * @param callbacks to receive responses * @hide */ @Override - public void requestScrollCapture(IScrollCaptureController controller) { - getViewRootImpl().dispatchScrollCaptureRequest(controller); + public void requestScrollCapture(IScrollCaptureCallbacks callbacks) { + getViewRootImpl().dispatchScrollCaptureRequest(callbacks); } /** @@ -3924,7 +3924,7 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback { * @param callback the callback to add */ @Override - public void addScrollCaptureCallback(@NonNull ScrollCaptureCallback callback) { + public void registerScrollCaptureCallback(@NonNull ScrollCaptureCallback callback) { getViewRootImpl().addScrollCaptureCallback(callback); } @@ -3934,7 +3934,7 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback { * @param callback the callback to remove */ @Override - public void removeScrollCaptureCallback(@NonNull ScrollCaptureCallback callback) { + public void unregisterScrollCaptureCallback(@NonNull ScrollCaptureCallback callback) { getViewRootImpl().removeScrollCaptureCallback(callback); } diff --git a/core/java/com/android/internal/view/BaseIWindow.java b/core/java/com/android/internal/view/BaseIWindow.java index fff9ac9e49b7..8962dc3d59da 100644 --- a/core/java/com/android/internal/view/BaseIWindow.java +++ b/core/java/com/android/internal/view/BaseIWindow.java @@ -24,7 +24,7 @@ import android.os.ParcelFileDescriptor; import android.os.RemoteException; import android.util.MergedConfiguration; import android.view.DragEvent; -import android.view.IScrollCaptureController; +import android.view.IScrollCaptureCallbacks; import android.view.IWindow; import android.view.IWindowSession; import android.view.InsetsSourceControl; @@ -162,9 +162,9 @@ public class BaseIWindow extends IWindow.Stub { } @Override - public void requestScrollCapture(IScrollCaptureController controller) { + public void requestScrollCapture(IScrollCaptureCallbacks callbacks) { try { - controller.onClientUnavailable(); + callbacks.onUnavailable(); } catch (RemoteException ex) { // ignore } diff --git a/core/tests/coretests/src/android/view/ScrollCaptureClientTest.java b/core/tests/coretests/src/android/view/ScrollCaptureConnectionTest.java index e6ac2d6c43da..b9cf1e4a234c 100644 --- a/core/tests/coretests/src/android/view/ScrollCaptureClientTest.java +++ b/core/tests/coretests/src/android/view/ScrollCaptureConnectionTest.java @@ -47,11 +47,11 @@ import org.mockito.MockitoAnnotations; import org.mockito.stubbing.Answer; /** - * Tests of {@link ScrollCaptureClient}. + * Tests of {@link ScrollCaptureConnection}. */ @SuppressWarnings("UnnecessaryLocalVariable") @RunWith(AndroidJUnit4.class) -public class ScrollCaptureClientTest { +public class ScrollCaptureConnectionTest { private final Point mPositionInWindow = new Point(1, 2); private final Rect mLocalVisibleRect = new Rect(2, 3, 4, 5); @@ -63,7 +63,7 @@ public class ScrollCaptureClientTest { @Mock private Surface mSurface; @Mock - private IScrollCaptureController mClientCallbacks; + private IScrollCaptureCallbacks mConnectionCallbacks; @Mock private View mMockView1; @Mock @@ -86,8 +86,8 @@ public class ScrollCaptureClientTest { @Test public void testDelayedAction() { Runnable action = Mockito.mock(Runnable.class); - ScrollCaptureClient.DelayedAction delayed = - new ScrollCaptureClient.DelayedAction(mHandler, 100, action); + ScrollCaptureConnection.DelayedAction delayed = + new ScrollCaptureConnection.DelayedAction(mHandler, 100, action); try { Thread.sleep(200); } catch (InterruptedException ex) { @@ -103,8 +103,8 @@ public class ScrollCaptureClientTest { @Test public void testDelayedAction_cancel() { Runnable action = Mockito.mock(Runnable.class); - ScrollCaptureClient.DelayedAction delayed = - new ScrollCaptureClient.DelayedAction(mHandler, 100, action); + ScrollCaptureConnection.DelayedAction delayed = + new ScrollCaptureConnection.DelayedAction(mHandler, 100, action); try { Thread.sleep(50); } catch (InterruptedException ex) { @@ -125,8 +125,8 @@ public class ScrollCaptureClientTest { @Test public void testDelayedAction_timeoutNow() { Runnable action = Mockito.mock(Runnable.class); - ScrollCaptureClient.DelayedAction delayed = - new ScrollCaptureClient.DelayedAction(mHandler, 100, action); + ScrollCaptureConnection.DelayedAction delayed = + new ScrollCaptureConnection.DelayedAction(mHandler, 100, action); try { Thread.sleep(50); } catch (InterruptedException ex) { @@ -141,7 +141,7 @@ public class ScrollCaptureClientTest { /** Test creating a client with valid info */ @Test public void testConstruction() { - new ScrollCaptureClient(mTarget1, mClientCallbacks); + new ScrollCaptureConnection(mTarget1, mConnectionCallbacks); } /** Test creating a client fails if arguments are not valid. */ @@ -149,7 +149,7 @@ public class ScrollCaptureClientTest { public void testConstruction_requiresScrollBounds() { try { mTarget1.setScrollBounds(null); - new ScrollCaptureClient(mTarget1, mClientCallbacks); + new ScrollCaptureConnection(mTarget1, mConnectionCallbacks); fail("An exception was expected."); } catch (RuntimeException ex) { // Ignore, expected. @@ -174,48 +174,51 @@ public class ScrollCaptureClientTest { }; } - /** @see ScrollCaptureClient#startCapture(Surface) */ + /** @see ScrollCaptureConnection#startCapture(Surface) */ @Test public void testStartCapture() throws Exception { - final ScrollCaptureClient client = new ScrollCaptureClient(mTarget1, mClientCallbacks); + final ScrollCaptureConnection connection = new ScrollCaptureConnection(mTarget1, + mConnectionCallbacks); // Have the session start accepted immediately doAnswer(runRunnable(1)).when(mCallback1) .onScrollCaptureStart(any(ScrollCaptureSession.class), any(Runnable.class)); - client.startCapture(mSurface); + connection.startCapture(mSurface); getInstrumentation().waitForIdleSync(); verify(mCallback1, times(1)) .onScrollCaptureStart(any(ScrollCaptureSession.class), any(Runnable.class)); - verify(mClientCallbacks, times(1)).onCaptureStarted(); - verifyNoMoreInteractions(mClientCallbacks); + verify(mConnectionCallbacks, times(1)).onCaptureStarted(); + verifyNoMoreInteractions(mConnectionCallbacks); } @Test public void testStartCaptureTimeout() throws Exception { - final ScrollCaptureClient client = new ScrollCaptureClient(mTarget1, mClientCallbacks); - client.startCapture(mSurface); + final ScrollCaptureConnection connection = new ScrollCaptureConnection(mTarget1, + mConnectionCallbacks); + connection.startCapture(mSurface); // Force timeout to fire - client.getTimeoutAction().timeoutNow(); + connection.getTimeoutAction().timeoutNow(); getInstrumentation().waitForIdleSync(); verify(mCallback1, times(1)).onScrollCaptureEnd(any(Runnable.class)); } - private void startClient(ScrollCaptureClient client) throws Exception { + private void startCapture(ScrollCaptureConnection connection) throws Exception { doAnswer(runRunnable(1)).when(mCallback1) .onScrollCaptureStart(any(ScrollCaptureSession.class), any(Runnable.class)); - client.startCapture(mSurface); + connection.startCapture(mSurface); getInstrumentation().waitForIdleSync(); - reset(mCallback1, mClientCallbacks); + reset(mCallback1, mConnectionCallbacks); } - /** @see ScrollCaptureClient#requestImage(Rect) */ + /** @see ScrollCaptureConnection#requestImage(Rect) */ @Test public void testRequestImage() throws Exception { - final ScrollCaptureClient client = new ScrollCaptureClient(mTarget1, mClientCallbacks); - startClient(client); + final ScrollCaptureConnection connection = new ScrollCaptureConnection(mTarget1, + mConnectionCallbacks); + startCapture(connection); // Stub the callback to complete the request immediately doAnswer(reportBufferSent(/* sessionArg */ 0, /* frameNum */ 1L, new Rect(1, 2, 3, 4))) @@ -223,7 +226,7 @@ public class ScrollCaptureClientTest { .onScrollCaptureImageRequest(any(ScrollCaptureSession.class), any(Rect.class)); // Make the inbound binder call - client.requestImage(new Rect(1, 2, 3, 4)); + connection.requestImage(new Rect(1, 2, 3, 4)); // Wait for handler thread dispatch getInstrumentation().waitForIdleSync(); @@ -232,18 +235,20 @@ public class ScrollCaptureClientTest { // Wait for binder thread dispatch getInstrumentation().waitForIdleSync(); - verify(mClientCallbacks, times(1)).onCaptureBufferSent(eq(1L), eq(new Rect(1, 2, 3, 4))); + verify(mConnectionCallbacks, times(1)) + .onCaptureBufferSent(eq(1L), eq(new Rect(1, 2, 3, 4))); - verifyNoMoreInteractions(mCallback1, mClientCallbacks); + verifyNoMoreInteractions(mCallback1, mConnectionCallbacks); } @Test public void testRequestImageTimeout() throws Exception { - final ScrollCaptureClient client = new ScrollCaptureClient(mTarget1, mClientCallbacks); - startClient(client); + final ScrollCaptureConnection connection = new ScrollCaptureConnection(mTarget1, + mConnectionCallbacks); + startCapture(connection); // Make the inbound binder call - client.requestImage(new Rect(1, 2, 3, 4)); + connection.requestImage(new Rect(1, 2, 3, 4)); // Wait for handler thread dispatch getInstrumentation().waitForIdleSync(); @@ -251,20 +256,21 @@ public class ScrollCaptureClientTest { any(ScrollCaptureSession.class), eq(new Rect(1, 2, 3, 4))); // Force timeout to fire - client.getTimeoutAction().timeoutNow(); + connection.getTimeoutAction().timeoutNow(); getInstrumentation().waitForIdleSync(); // (callback not stubbed, does nothing) // Timeout triggers request to end capture verify(mCallback1, times(1)).onScrollCaptureEnd(any(Runnable.class)); - verifyNoMoreInteractions(mCallback1, mClientCallbacks); + verifyNoMoreInteractions(mCallback1, mConnectionCallbacks); } - /** @see ScrollCaptureClient#endCapture() */ + /** @see ScrollCaptureConnection#endCapture() */ @Test public void testEndCapture() throws Exception { - final ScrollCaptureClient client = new ScrollCaptureClient(mTarget1, mClientCallbacks); - startClient(client); + final ScrollCaptureConnection connection = new ScrollCaptureConnection(mTarget1, + mConnectionCallbacks); + startCapture(connection); // Stub the callback to complete the request immediately doAnswer(runRunnable(0)) @@ -272,7 +278,7 @@ public class ScrollCaptureClientTest { .onScrollCaptureEnd(any(Runnable.class)); // Make the inbound binder call - client.endCapture(); + connection.endCapture(); // Wait for handler thread dispatch getInstrumentation().waitForIdleSync(); @@ -280,30 +286,31 @@ public class ScrollCaptureClientTest { // Wait for binder thread dispatch getInstrumentation().waitForIdleSync(); - verify(mClientCallbacks, times(1)).onConnectionClosed(); + verify(mConnectionCallbacks, times(1)).onConnectionClosed(); - verifyNoMoreInteractions(mCallback1, mClientCallbacks); + verifyNoMoreInteractions(mCallback1, mConnectionCallbacks); } @Test public void testEndCaptureTimeout() throws Exception { - final ScrollCaptureClient client = new ScrollCaptureClient(mTarget1, mClientCallbacks); - startClient(client); + final ScrollCaptureConnection connection = new ScrollCaptureConnection(mTarget1, + mConnectionCallbacks); + startCapture(connection); // Make the inbound binder call - client.endCapture(); + connection.endCapture(); // Wait for handler thread dispatch getInstrumentation().waitForIdleSync(); verify(mCallback1, times(1)).onScrollCaptureEnd(any(Runnable.class)); // Force timeout to fire - client.getTimeoutAction().timeoutNow(); + connection.getTimeoutAction().timeoutNow(); // Wait for binder thread dispatch getInstrumentation().waitForIdleSync(); - verify(mClientCallbacks, times(1)).onConnectionClosed(); + verify(mConnectionCallbacks, times(1)).onConnectionClosed(); - verifyNoMoreInteractions(mCallback1, mClientCallbacks); + verifyNoMoreInteractions(mCallback1, mConnectionCallbacks); } } diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/common/SystemWindows.java b/libs/WindowManager/Shell/src/com/android/wm/shell/common/SystemWindows.java index 17fd16bccc4a..eaf5d7960aa9 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/common/SystemWindows.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/common/SystemWindows.java @@ -32,7 +32,7 @@ import android.util.Slog; import android.util.SparseArray; import android.view.Display; import android.view.DragEvent; -import android.view.IScrollCaptureController; +import android.view.IScrollCaptureCallbacks; import android.view.IWindow; import android.view.IWindowManager; import android.view.IWindowSession; @@ -373,9 +373,9 @@ public class SystemWindows { public void dispatchPointerCaptureChanged(boolean hasCapture) {} @Override - public void requestScrollCapture(IScrollCaptureController controller) { + public void requestScrollCapture(IScrollCaptureCallbacks callbacks) { try { - controller.onClientUnavailable(); + callbacks.onUnavailable(); } catch (RemoteException ex) { // ignore } diff --git a/packages/SystemUI/tests/src/com/android/systemui/screenshot/ScrollCaptureTest.java b/packages/SystemUI/tests/src/com/android/systemui/screenshot/ScrollCaptureTest.java index e7ef64e6adad..2b3ca7c00a49 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/screenshot/ScrollCaptureTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/screenshot/ScrollCaptureTest.java @@ -25,8 +25,8 @@ import android.os.RemoteException; import android.testing.AndroidTestingRunner; import android.util.Log; import android.view.Display; -import android.view.IScrollCaptureClient; -import android.view.IScrollCaptureController; +import android.view.IScrollCaptureCallbacks; +import android.view.IScrollCaptureConnection; import android.view.IWindowManager; import android.view.WindowManagerGlobal; @@ -65,19 +65,20 @@ public class ScrollCaptureTest extends SysuiTestCase { final CountDownLatch latch = new CountDownLatch(1); try { wms.requestScrollCapture(Display.DEFAULT_DISPLAY, null, -1, - new IScrollCaptureController.Stub() { + new IScrollCaptureCallbacks.Stub() { @Override - public void onClientConnected( - IScrollCaptureClient client, Rect scrollBounds, + public void onConnected( + IScrollCaptureConnection connection, Rect scrollBounds, Point positionInWindow) { Log.d(TAG, - "client connected: " + client + "[scrollBounds= " + scrollBounds - + ", positionInWindow=" + positionInWindow + "]"); + "client connected: " + connection + "[scrollBounds= " + + scrollBounds + ", " + + "positionInWindow=" + positionInWindow + "]"); latch.countDown(); } @Override - public void onClientUnavailable() { + public void onUnavailable() { } @Override diff --git a/services/core/java/com/android/server/wm/WindowManagerService.java b/services/core/java/com/android/server/wm/WindowManagerService.java index 40b770fc67ec..e348103159fc 100644 --- a/services/core/java/com/android/server/wm/WindowManagerService.java +++ b/services/core/java/com/android/server/wm/WindowManagerService.java @@ -225,7 +225,7 @@ import android.view.IOnKeyguardExitResult; import android.view.IPinnedStackListener; import android.view.IRecentsAnimationRunner; import android.view.IRotationWatcher; -import android.view.IScrollCaptureController; +import android.view.IScrollCaptureCallbacks; import android.view.ISystemGestureExclusionListener; import android.view.IWallpaperVisibilityListener; import android.view.IWindow; @@ -6902,13 +6902,11 @@ public class WindowManagerService extends IWindowManager.Stub * * @param displayId the display for the request * @param behindClient token for a window, used to filter the search to windows behind it - * @param taskId specifies the id of a task the result must belong to or -1 to ignore task ids - * @param controller the controller to receive results; a call to either - * {@link IScrollCaptureController#onClientConnected} or - * {@link IScrollCaptureController#onClientUnavailable}. + * @param taskId specifies the id of a task the result must belong to or -1 to match any task + * @param callbacks to receive responses */ public void requestScrollCapture(int displayId, @Nullable IBinder behindClient, int taskId, - IScrollCaptureController controller) { + IScrollCaptureCallbacks callbacks) { if (!checkCallingPermission(READ_FRAME_BUFFER, "requestScrollCapture()")) { throw new SecurityException("Requires READ_FRAME_BUFFER permission"); } @@ -6919,7 +6917,7 @@ public class WindowManagerService extends IWindowManager.Stub if (dc == null) { ProtoLog.e(WM_ERROR, "Invalid displayId for requestScrollCapture: %d", displayId); - controller.onClientUnavailable(); + callbacks.onUnavailable(); return; } WindowState topWindow = null; @@ -6928,17 +6926,17 @@ public class WindowManagerService extends IWindowManager.Stub } WindowState targetWindow = dc.findScrollCaptureTargetWindow(topWindow, taskId); if (targetWindow == null) { - controller.onClientUnavailable(); + callbacks.onUnavailable(); return; } // Forward to the window for handling. try { - targetWindow.mClient.requestScrollCapture(controller); + targetWindow.mClient.requestScrollCapture(callbacks); } catch (RemoteException e) { ProtoLog.w(WM_ERROR, "requestScrollCapture: caught exception dispatching to window." + "token=%s", targetWindow.mClient.asBinder()); - controller.onClientUnavailable(); + callbacks.onUnavailable(); } } } catch (RemoteException e) { diff --git a/services/tests/wmtests/src/com/android/server/wm/TestIWindow.java b/services/tests/wmtests/src/com/android/server/wm/TestIWindow.java index ea1223312cb2..db1c12f525f3 100644 --- a/services/tests/wmtests/src/com/android/server/wm/TestIWindow.java +++ b/services/tests/wmtests/src/com/android/server/wm/TestIWindow.java @@ -22,7 +22,7 @@ import android.os.ParcelFileDescriptor; import android.os.RemoteException; import android.util.MergedConfiguration; import android.view.DragEvent; -import android.view.IScrollCaptureController; +import android.view.IScrollCaptureCallbacks; import android.view.IWindow; import android.view.InsetsSourceControl; import android.view.InsetsState; @@ -107,7 +107,7 @@ public class TestIWindow extends IWindow.Stub { } @Override - public void requestScrollCapture(IScrollCaptureController controller) throws RemoteException { + public void requestScrollCapture(IScrollCaptureCallbacks callbacks) throws RemoteException { } @Override |