summaryrefslogtreecommitdiff
path: root/packages/SystemUI/shared
diff options
context:
space:
mode:
author Tracy Zhou <tracyzhou@google.com> 2020-02-25 11:41:32 -0800
committer Tracy Zhou <tracyzhou@google.com> 2020-03-04 18:29:35 -0800
commitccfab35bf899800d0eee4c1d604ca5573746ba1e (patch)
treed53a81154556fd2e17d522cd39abf9b1fa56f436 /packages/SystemUI/shared
parentab2c1bb0073aea3a4bda100bacf431fd4e3b6d2a (diff)
Make SurfaceView rendering generic in SysUI
WindowlessWindowManager is not visible as external APIs, so for launcher / wallpaper to use the API the rendering code has to be in the SysUI. Bug: 150224413 Test: Manual. Make sure universal smartspace still works as intended. Change-Id: If006d622f181f6c8cc7c1cebda3f63b0b2ad85d5
Diffstat (limited to 'packages/SystemUI/shared')
-rw-r--r--packages/SystemUI/shared/src/com/android/systemui/shared/system/SurfaceViewRequestReceiver.java71
-rw-r--r--packages/SystemUI/shared/src/com/android/systemui/shared/system/SurfaceViewRequestUtils.java55
-rw-r--r--packages/SystemUI/shared/src/com/android/systemui/shared/system/UniversalSmartspaceUtils.java29
3 files changed, 129 insertions, 26 deletions
diff --git a/packages/SystemUI/shared/src/com/android/systemui/shared/system/SurfaceViewRequestReceiver.java b/packages/SystemUI/shared/src/com/android/systemui/shared/system/SurfaceViewRequestReceiver.java
new file mode 100644
index 000000000000..8809d832d72d
--- /dev/null
+++ b/packages/SystemUI/shared/src/com/android/systemui/shared/system/SurfaceViewRequestReceiver.java
@@ -0,0 +1,71 @@
+/*
+ * Copyright (C) 2020 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.systemui.shared.system;
+
+import android.content.Context;
+import android.graphics.PixelFormat;
+import android.os.Bundle;
+import android.os.IBinder;
+import android.view.SurfaceControl;
+import android.view.SurfaceControlViewHost;
+import android.view.View;
+import android.view.WindowManager;
+import android.view.WindowlessWindowManager;
+
+/**
+ * A generic receiver that specifically handles SurfaceView request created by {@link
+ * com.android.systemui.shared.system.SurfaceViewRequestUtils}.
+ */
+public class SurfaceViewRequestReceiver {
+
+ private final int mOpacity;
+ private SurfaceControlViewHost mSurfaceControlViewHost;
+
+ public SurfaceViewRequestReceiver() {
+ this(PixelFormat.TRANSPARENT);
+ }
+
+ public SurfaceViewRequestReceiver(int opacity) {
+ mOpacity = opacity;
+ }
+
+ /** Called whenever a surface view request is received. */
+ public void onReceive(Context context, Bundle bundle, View view) {
+ if (mSurfaceControlViewHost != null) {
+ mSurfaceControlViewHost.die();
+ }
+ SurfaceControl surfaceControl = SurfaceViewRequestUtils.getSurfaceControl(bundle);
+ if (surfaceControl != null) {
+ IBinder hostToken = SurfaceViewRequestUtils.getHostToken(bundle);
+
+ WindowlessWindowManager windowlessWindowManager =
+ new WindowlessWindowManager(context.getResources().getConfiguration(),
+ surfaceControl, hostToken);
+ mSurfaceControlViewHost = new SurfaceControlViewHost(context,
+ context.getDisplayNoVerify(), windowlessWindowManager);
+ WindowManager.LayoutParams layoutParams =
+ new WindowManager.LayoutParams(
+ surfaceControl.getWidth(),
+ surfaceControl.getHeight(),
+ WindowManager.LayoutParams.TYPE_APPLICATION,
+ 0,
+ mOpacity);
+
+ mSurfaceControlViewHost.addView(view, layoutParams);
+ }
+ }
+}
diff --git a/packages/SystemUI/shared/src/com/android/systemui/shared/system/SurfaceViewRequestUtils.java b/packages/SystemUI/shared/src/com/android/systemui/shared/system/SurfaceViewRequestUtils.java
new file mode 100644
index 000000000000..0cbd541cbc8d
--- /dev/null
+++ b/packages/SystemUI/shared/src/com/android/systemui/shared/system/SurfaceViewRequestUtils.java
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2020 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.systemui.shared.system;
+
+import android.annotation.Nullable;
+import android.os.Bundle;
+import android.os.IBinder;
+import android.view.SurfaceControl;
+import android.view.SurfaceView;
+
+/** Util class that wraps a SurfaceView request into a bundle. */
+public class SurfaceViewRequestUtils {
+ private static final String KEY_HOST_TOKEN = "host_token";
+ private static final String KEY_SURFACE_CONTROL = "surface_control";
+
+ /** Creates a SurfaceView based bundle that stores the input host token and surface control. */
+ public static Bundle createSurfaceBundle(SurfaceView surfaceView) {
+ Bundle bundle = new Bundle();
+ bundle.putBinder(KEY_HOST_TOKEN, surfaceView.getHostToken());
+ bundle.putParcelable(KEY_SURFACE_CONTROL, surfaceView.getSurfaceControl());
+ return bundle;
+ }
+
+ /**
+ * Retrieves the SurfaceControl from an Intent created by
+ * {@link #createSurfaceBundle(SurfaceView)}.
+ **/
+ public static SurfaceControl getSurfaceControl(Bundle bundle) {
+ return bundle.getParcelable(KEY_SURFACE_CONTROL);
+ }
+
+ /**
+ * Retrieves the input token from an Intent created by
+ * {@link #createSurfaceBundle(SurfaceView)}.
+ **/
+ public static @Nullable IBinder getHostToken(Bundle bundle) {
+ return bundle.getBinder(KEY_HOST_TOKEN);
+ }
+
+ private SurfaceViewRequestUtils() {}
+}
diff --git a/packages/SystemUI/shared/src/com/android/systemui/shared/system/UniversalSmartspaceUtils.java b/packages/SystemUI/shared/src/com/android/systemui/shared/system/UniversalSmartspaceUtils.java
index 871cae3b4f8d..359d36939b31 100644
--- a/packages/SystemUI/shared/src/com/android/systemui/shared/system/UniversalSmartspaceUtils.java
+++ b/packages/SystemUI/shared/src/com/android/systemui/shared/system/UniversalSmartspaceUtils.java
@@ -18,50 +18,27 @@ package com.android.systemui.shared.system;
import android.content.Intent;
import android.os.Bundle;
-import android.os.IBinder;
-import android.view.SurfaceControl;
import android.view.SurfaceView;
/** Utility class that is shared between SysUI and Launcher for Universal Smartspace features. */
public final class UniversalSmartspaceUtils {
public static final String ACTION_REQUEST_SMARTSPACE_VIEW =
"com.android.systemui.REQUEST_SMARTSPACE_VIEW";
+ public static final String INTENT_BUNDLE_KEY = "bundle_key";
private static final String SYSUI_PACKAGE = "com.android.systemui";
- private static final String INTENT_KEY_INPUT_BUNDLE = "input_bundle";
- private static final String BUNDLE_KEY_INPUT_TOKEN = "input_token";
- private static final String INTENT_KEY_SURFACE_CONTROL = "surface_control";
/** Creates an intent to request that sysui draws the Smartspace to the SurfaceView. */
public static Intent createRequestSmartspaceIntent(SurfaceView surfaceView) {
Intent intent = new Intent(ACTION_REQUEST_SMARTSPACE_VIEW);
- Bundle inputBundle = new Bundle();
- inputBundle.putBinder(BUNDLE_KEY_INPUT_TOKEN, surfaceView.getHostToken());
+ Bundle bundle = SurfaceViewRequestUtils.createSurfaceBundle(surfaceView);
return intent
- .putExtra(INTENT_KEY_SURFACE_CONTROL, surfaceView.getSurfaceControl())
- .putExtra(INTENT_KEY_INPUT_BUNDLE, inputBundle)
+ .putExtra(INTENT_BUNDLE_KEY, bundle)
.setPackage(SYSUI_PACKAGE)
.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY
| Intent.FLAG_RECEIVER_FOREGROUND);
}
- /**
- * Retrieves the SurfaceControl from an Intent created by
- * {@link #createRequestSmartspaceIntent(SurfaceView)}.
- **/
- public static SurfaceControl getSurfaceControl(Intent intent) {
- return intent.getParcelableExtra(INTENT_KEY_SURFACE_CONTROL);
- }
-
- /**
- * Retrieves the input token from an Intent created by
- * {@link #createRequestSmartspaceIntent(SurfaceView)}.
- **/
- public static IBinder getInputToken(Intent intent) {
- Bundle inputBundle = intent.getBundleExtra(INTENT_KEY_INPUT_BUNDLE);
- return inputBundle == null ? null : inputBundle.getBinder(BUNDLE_KEY_INPUT_TOKEN);
- }
-
private UniversalSmartspaceUtils() {}
}