zacharee / NachoNotch

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

XPosed module for enhancements

TurboLed opened this issue · comments

I own a Pixel 3 XL and Nacho Notch works well for hiding the notch while keeping it for status bar content. However we all know the issue with the navigation bar not behaving the same after Nacho Notch has been activated, and so does other similar apps that uses the same technique (overlay + dim behind). Also the notch is not hidden in the system menus but that is minor.

I wrote a small XPosed (LSPosed) module that fixes theses issues.

  1. Hook into the nacho notch code (removing the dim behind flags):
  2. Hook into the systemui LightBarController code to force the text to light mode:
  3. Hook into the systemui PhoneWindowView code to force the status bar background to black in portrait mode (fixes System menus)

Here is the code for those hooks:

public class HookMain implements IXposedHookLoadPackage, IXposedHookZygoteInit, IXposedHookInitPackageResources {
Context mContext;
Object mDark;

public void handleLoadPackage(final XC_LoadPackage.LoadPackageParam lpparam) throws Exception {

    if (lpparam.packageName.equals("com.android.systemui")) {

        Class c1 = XposedHelpers.findClass("com.android.systemui.plugins.DarkIconDispatcher", lpparam.classLoader);
        Class c2 = XposedHelpers.findClass("com.android.systemui.statusbar.policy.BatteryController", lpparam.classLoader);
        Class c3 = XposedHelpers.findClass("com.android.systemui.statusbar.phone.NavigationModeController", lpparam.classLoader);

        XposedHelpers.findAndHookConstructor("com.android.systemui.statusbar.phone.LightBarController", lpparam.classLoader, Context.class, c1, c2, c3, new XC_MethodHook() {
            @Override
            protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
                mContext = (Context)param.args[0];
                mDark = param.args[1];
            }
        });

        XposedHelpers.findAndHookMethod("com.android.systemui.statusbar.phone.LightBarController", lpparam.classLoader, "updateStatus", new XC_MethodHook() {

            @Override
            protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
                    if (mContext.getDisplay().getRotation() == Surface.ROTATION_0)
                    {
                        Object tc = mDark.getClass().getMethod("getTransitionsController").invoke(mDark);
                        tc.getClass().getMethod("setIconsDark", boolean.class, boolean.class).invoke(tc, false, false);
                        param.setResult(null);
                    }
                }
                XposedBridge.log("updateStatus triggered");
            }
        });

        XposedHelpers.findAndHookMethod("com.android.systemui.statusbar.phone.PhoneStatusBarView", lpparam.classLoader, "updateOrientationAndCutout", new XC_MethodHook() {
            @SuppressLint("SoonBlockedPrivateApi")
            @Override
            protected void afterHookedMethod(MethodHookParam param) throws Throwable {
                if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.R) {
                    mRotation = ((View)param.thisObject).getContext().getDisplay().getRotation();
                    if (mRotation == 0)
                        ((View)param.thisObject).setBackgroundColor(Color.BLACK);
                    else
                        ((View)param.thisObject).setBackgroundColor(Color.argb(0,0,0,0));
                }
            }
        });
    }

    if (lpparam.packageName.equals("com.xda.nachonotch")) {
        {
            XC_MethodHook hook = new XC_MethodHook() {
                @Override
                protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
                    WindowManager.LayoutParams p = (WindowManager.LayoutParams) param.args[1];
                    p.flags &= ~WindowManager.LayoutParams.FLAG_DIM_BEHIND;
                    p.dimAmount = 0.f;
                }
            };

            XposedHelpers.findAndHookMethod("android.view.WindowManagerImpl", lpparam.classLoader, "addView", View.class, ViewGroup.LayoutParams.class, hook);
            XposedHelpers.findAndHookMethod("android.view.WindowManagerImpl", lpparam.classLoader, "updateViewLayout", View.class, ViewGroup.LayoutParams.class, hook);
        }
    }
	
	
    XposedBridge.log("color hook installed");
}