Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 08f71754 authored by Ilya Matyukhin's avatar Ilya Matyukhin
Browse files

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
parent 6c1cf6cc
Loading
Loading
Loading
Loading
+5 −8
Original line number Diff line number Diff line
@@ -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;
    }