From ccfab35bf899800d0eee4c1d604ca5573746ba1e Mon Sep 17 00:00:00 2001 From: Tracy Zhou Date: Tue, 25 Feb 2020 11:41:32 -0800 Subject: 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 --- .../shared/system/SurfaceViewRequestReceiver.java | 71 ++++++++++++++++++++++ .../shared/system/SurfaceViewRequestUtils.java | 55 +++++++++++++++++ .../shared/system/UniversalSmartspaceUtils.java | 29 +-------- 3 files changed, 129 insertions(+), 26 deletions(-) create mode 100644 packages/SystemUI/shared/src/com/android/systemui/shared/system/SurfaceViewRequestReceiver.java create mode 100644 packages/SystemUI/shared/src/com/android/systemui/shared/system/SurfaceViewRequestUtils.java (limited to 'packages/SystemUI/shared') 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() {} } -- cgit v1.2.3-59-g8ed1b