From 204c023ae2fd775bdca8247ef16c4601821a7328 Mon Sep 17 00:00:00 2001 From: Vishnu Nair Date: Thu, 10 Sep 2020 15:46:52 -0700 Subject: Add focus support for SurfaceControlViewHost This change introduces a new call for clients to request focus on their embedded views. In order to accomplish this, the owner of the SurfacePackage sends an input token that can identify the input channel of the embedded window. This token is forwarded as part of the focus request. WindowManager will authenticate the calling window and the relationship between the host and the embedded window. Once authenticated, the request will be forwarded to InputDispatcher. InputDispatcher will grant the focus to the SurfaceControlViewHost if the host window is currently focused or transfer focus back to the host window if the SurfaceControlViewHost is focused. Otherwise the request is dropped. In addition, SurfaceView, the host in this scenario, now overrides the onFocused function to transfer focus to and from the embedded view. Test: atest SurfaceControlViewHostTests Bug: 151179149 Change-Id: Ia95545a60d73db4c03679bce9747d2e275806838 --- .../com/android/test/viewembed/SurfaceControlViewHostTest.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'tests/SurfaceControlViewHostTest/src') diff --git a/tests/SurfaceControlViewHostTest/src/com/android/test/viewembed/SurfaceControlViewHostTest.java b/tests/SurfaceControlViewHostTest/src/com/android/test/viewembed/SurfaceControlViewHostTest.java index 3bc530975580..73e01634709e 100644 --- a/tests/SurfaceControlViewHostTest/src/com/android/test/viewembed/SurfaceControlViewHostTest.java +++ b/tests/SurfaceControlViewHostTest/src/com/android/test/viewembed/SurfaceControlViewHostTest.java @@ -22,12 +22,11 @@ import android.graphics.Color; import android.graphics.PixelFormat; import android.os.Bundle; import android.view.Gravity; -import android.view.SurfaceControl; +import android.view.SurfaceControlViewHost; import android.view.SurfaceHolder; import android.view.SurfaceView; import android.view.View; import android.view.WindowManager; -import android.view.SurfaceControlViewHost; import android.widget.Button; import android.widget.FrameLayout; @@ -46,8 +45,6 @@ public class SurfaceControlViewHostTest extends Activity implements SurfaceHolde mView.setZOrderOnTop(true); mView.getHolder().addCallback(this); - - addEmbeddedView(); } void addEmbeddedView() { @@ -63,6 +60,8 @@ public class SurfaceControlViewHostTest extends Activity implements SurfaceHolde v.setBackgroundColor(Color.RED); } }); + v.getViewTreeObserver().addOnWindowFocusChangeListener(focused -> + v.setBackgroundColor(focused ? Color.MAGENTA : Color.DKGRAY)); WindowManager.LayoutParams lp = new WindowManager.LayoutParams(500, 500, WindowManager.LayoutParams.TYPE_APPLICATION, 0, PixelFormat.OPAQUE); @@ -71,6 +70,7 @@ public class SurfaceControlViewHostTest extends Activity implements SurfaceHolde @Override public void surfaceCreated(SurfaceHolder holder) { + addEmbeddedView(); } @Override -- cgit v1.2.3-59-g8ed1b