From 08f71754455dd39673db543f8c15cbe4da0c707f Mon Sep 17 00:00:00 2001 From: Ilya Matyukhin Date: Thu, 13 Aug 2020 22:32:11 -0700 Subject: [PATCH] Fix the UDFPS overlay being offset by the status bar "lp.setFitInsetsTypes(0)" alone is not enough to get rid of the status bar offset/inset. After numerous experiments and digging through com.android.server.wm.DisplayPolicy#getLayoutHint I found out that this (now deprecated) flag solves the issue: WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR Setting this flag forces "getLayoutHint" to fill "outDisplayCutout" with the right "safeInsets" and "boundTop". Any other flag either results in zero-filled "outDisplayCutout" or causes WindowManager to crash. FYI, here are some other things that I tried that didn't work: mView.setFitsSystemWindows(false) mView.makeFrameworkOptionalFitsSystemWindows() mView.makeOptionalFitsSystemWindows() mView.setSystemUiVisibility(View.SYSTEM_UI_LAYOUT_FLAGS) lp.flags |= WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS; lp.privateFlags += WindowManager.LayoutParams.PRIVATE_FLAG_APPEARANCE_CONTROLLED; lp.privateFlags += WindowManager.LayoutParams.PRIVATE_FLAG_BEHAVIOR_CONTROLLED; lp.privateFlags += WindowManager.LayoutParams.PRIVATE_FLAG_FIT_INSETS_CONTROLLED; This CL also removes the LinearLayout root view, but it's simply a clean up and is unrelated to the status bar offset issue. The layout was only used to provide WindowManager.LayoutParams to UdfpsView, but it wasn't necessary because the parameters are also provided in the "addView" call to WindowManager. Bug: 162909513 Test: manual on device Change-Id: I58ea27b54e720de4d8051623e0cd56b6f7d9e196 --- .../systemui/biometrics/UdfpsController.java | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsController.java b/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsController.java index e3126b89fe786..62cfdc3124258 100644 --- a/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsController.java +++ b/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsController.java @@ -35,7 +35,6 @@ import android.util.Spline; import android.view.LayoutInflater; import android.view.MotionEvent; import android.view.WindowManager; -import android.widget.LinearLayout; import com.android.internal.BrightnessSynchronizer; import com.android.systemui.R; @@ -56,8 +55,8 @@ class UdfpsController { private final WindowManager mWindowManager; private final ContentResolver mContentResolver; private final Handler mHandler; - private final UdfpsView mView; private final WindowManager.LayoutParams mLayoutParams; + private final UdfpsView mView; // Debugfs path to control the high-brightness mode. private final String mHbmPath; private final String mHbmEnableCommand; @@ -121,12 +120,9 @@ class UdfpsController { mWindowManager = context.getSystemService(WindowManager.class); mContentResolver = context.getContentResolver(); mHandler = new Handler(Looper.getMainLooper()); - mLayoutParams = createLayoutParams(context); - LinearLayout layout = new LinearLayout(context); - layout.setLayoutParams(mLayoutParams); - mView = (UdfpsView) LayoutInflater.from(context).inflate(R.layout.udfps_view, layout, - false); + + mView = (UdfpsView) LayoutInflater.from(context).inflate(R.layout.udfps_view, null, false); mView.setOnTouchListener(mOnTouchListener); mHbmPath = context.getResources().getString(R.string.udfps_hbm_sysfs_path); @@ -254,11 +250,12 @@ class UdfpsController { // TODO(b/152419866): Use the UDFPS window type when it becomes available. WindowManager.LayoutParams.TYPE_BOOT_PROGRESS, WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN + | WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL | WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED, PixelFormat.TRANSLUCENT); lp.setTitle(TAG); - lp.windowAnimations = 0; + lp.setFitInsetsTypes(0); return lp; }