From 3b5011afc9e17963607269bfb6665d04e3ab4ca1 Mon Sep 17 00:00:00 2001 From: Yohei Yukawa Date: Thu, 16 Mar 2017 15:34:12 -0700 Subject: [PATCH] Add a compat hack into SurfaceView#setWindowType() This is a follow up CL to a previous CL [1] that removed an @hide method SurfaceView#setWindowType(int). It turns out that at least one application has relied on this @hide method via refection to set TYPE_APPLICATION_PANEL to the internal Window object for some reasons. Such an operation has never ever been allowed to the application developers. To minimize the risk of compatibility issues and to help developers and QA teams figure out what is going on, this CL re-introduces the method in question to do three things: 1. Show an error message with stack trace in logcat if this method was still called. 2. To emulate the previous behavior for applications that set TYPE_APPLICATION_PANEL, call SurfaceView#setZOrderOnTop(true) on behalf of them as a stop-gap, short-term solution until application developers are notified that their products are doing something unsupported. 3. Throw an exception if the targetApi is Android O or later. [1]: Ie56b6f7ab16f32d7fc459b8eba26594337ad55de d5c7dd6da810a6b89151b337bea79fd817e6b72a Test: Manually verified that the complaint in Bug 36345857 disappeared Bug: 36345857 Change-Id: I5217f6417a73690ae8a978754218b7b089070fdd --- core/java/android/view/SurfaceView.java | 29 ++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/core/java/android/view/SurfaceView.java b/core/java/android/view/SurfaceView.java index 6d320ef32b0da..824e035697fcc 100644 --- a/core/java/android/view/SurfaceView.java +++ b/core/java/android/view/SurfaceView.java @@ -16,8 +16,9 @@ package android.view; -import static android.view.WindowManagerPolicy.APPLICATION_MEDIA_SUBLAYER; +import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_PANEL; import static android.view.WindowManagerPolicy.APPLICATION_MEDIA_OVERLAY_SUBLAYER; +import static android.view.WindowManagerPolicy.APPLICATION_MEDIA_SUBLAYER; import static android.view.WindowManagerPolicy.APPLICATION_PANEL_SUBLAYER; import android.content.Context; @@ -28,6 +29,7 @@ import android.graphics.PixelFormat; import android.graphics.PorterDuff; import android.graphics.Rect; import android.graphics.Region; +import android.os.Build; import android.os.Handler; import android.os.Message; import android.os.SystemClock; @@ -776,6 +778,31 @@ public class SurfaceView extends View { return callbacks; } + /** + * This method still exists only for compatibility reasons because some applications have relied + * on this method via reflection. See Issue 36345857 for details. + * + * @deprecated No platform code is using this method anymore. + * @hide + */ + @Deprecated + public void setWindowType(int type) { + if (getContext().getApplicationInfo().targetSdkVersion > Build.VERSION_CODES.N_MR1) { + throw new UnsupportedOperationException( + "SurfaceView#setWindowType() has never been a public API."); + } + + if (type == TYPE_APPLICATION_PANEL) { + Log.e(TAG, "If you are calling SurfaceView#setWindowType(TYPE_APPLICATION_PANEL) " + + "just to make the SurfaceView to be placed on top of its window, you must " + + "call setZOrderOnTop(true) instead.", new Throwable()); + setZOrderOnTop(true); + return; + } + Log.e(TAG, "SurfaceView#setWindowType(int) is deprecated and now does nothing. " + + "type=" + type, new Throwable()); + } + /** * Check to see if the surface has fixed size dimensions or if the surface's * dimensions are dimensions are dependent on its current layout.