Enable views to be placed in windowless surfaces.

For purposes of parcelling SurfaceControl to embed view hierarchies across
processes. We also want these Surfaces to receive input, but we can't
let the clients call setInputWindowInfo directly (or we could have issues
with clients stealing focus, etc...) and so we provide a method
blessInputSurface which has the WM configure a surface for input with
a minimal and safe set of parameters.

Test: WindowlessWmTests
Bug: 111373437
Bug: 134365580
Change-Id: I45fde62ba9b810e783d62c4dd5442abd038734d5
diff --git a/tests/WindowlessWmTest/Android.bp b/tests/WindowlessWmTest/Android.bp
new file mode 100644
index 0000000..2ace3f3
--- /dev/null
+++ b/tests/WindowlessWmTest/Android.bp
@@ -0,0 +1,22 @@
+//
+// Copyright (C) 2019 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+android_test {
+    name: "WindowlessWmTest",
+    srcs: ["**/*.java"],
+    platform_apis: true,
+    certificate: "platform",
+}
diff --git a/tests/WindowlessWmTest/AndroidManifest.xml b/tests/WindowlessWmTest/AndroidManifest.xml
new file mode 100644
index 0000000..babfd76
--- /dev/null
+++ b/tests/WindowlessWmTest/AndroidManifest.xml
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2019 The Android Open Source Project
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     You may obtain a copy of the License at
+          http://www.apache.org/licenses/LICENSE-2.0
+     Unless required by applicable law or agreed to in writing, software
+     distributed under the License is distributed on an "AS IS" BASIS,
+     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     See the License for the specific language governing permissions and
+     limitations under the License.
+-->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+          package="com.android.test.viewembed">
+
+    <application>
+        <activity android:name="WindowlessWmTest" android:label="View Embedding Test">
+            <intent-filter>
+                <action android:name="android.intent.action.MAIN"/>
+                <category android:name="android.intent.category.LAUNCHER"/>
+            </intent-filter>
+        </activity>
+    </application>
+
+
+</manifest>
diff --git a/tests/WindowlessWmTest/src/com/android/test/viewembed/WindowlessWmTest.java b/tests/WindowlessWmTest/src/com/android/test/viewembed/WindowlessWmTest.java
new file mode 100644
index 0000000..5a146da
--- /dev/null
+++ b/tests/WindowlessWmTest/src/com/android/test/viewembed/WindowlessWmTest.java
@@ -0,0 +1,78 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.test.viewembed;
+
+import android.app.Activity;
+import android.os.Bundle;
+import android.graphics.Canvas;
+import android.graphics.Color;
+import android.graphics.PixelFormat;
+import android.view.Gravity;
+import android.view.WindowlessViewRoot;
+import android.view.SurfaceHolder;
+import android.view.SurfaceHolder.Callback;
+import android.view.SurfaceView;
+import android.view.View;
+import android.view.WindowManager;
+import android.widget.Button;
+import android.widget.FrameLayout;
+
+
+public class WindowlessWmTest extends Activity implements SurfaceHolder.Callback{
+    SurfaceView mView;
+    WindowlessViewRoot mVr;
+
+    protected void onCreate(Bundle savedInstanceState) {
+        FrameLayout content = new FrameLayout(this);
+        super.onCreate(savedInstanceState);
+        mView = new SurfaceView(this);
+        content.addView(mView, new FrameLayout.LayoutParams(
+                500, 500, Gravity.CENTER_HORIZONTAL | Gravity.TOP));
+        setContentView(content);
+
+        mView.setZOrderOnTop(true);
+        mView.getHolder().addCallback(this);
+    }
+
+    @Override
+    public void surfaceCreated(SurfaceHolder holder) {
+        mVr = new WindowlessViewRoot(this, this.getDisplay(),
+                mView.getSurfaceControl());
+        Button v = new Button(this);
+        v.setBackgroundColor(Color.BLUE);
+        v.setOnClickListener(new View.OnClickListener() {
+                public void onClick(View v) {
+                    v.setBackgroundColor(Color.RED);
+                }
+        });
+        WindowManager.LayoutParams lp =
+            new WindowManager.LayoutParams(500, 500, WindowManager.LayoutParams.TYPE_APPLICATION,
+                    0, PixelFormat.OPAQUE);
+        mVr.addView(v, lp);
+    }
+
+    @Override
+    public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
+        Canvas canvas = holder.lockCanvas();
+        canvas.drawColor(Color.GREEN);
+        holder.unlockCanvasAndPost(canvas);
+    }
+
+    @Override
+    public void surfaceDestroyed(SurfaceHolder holder) {
+    }
+}