FreezyExp / Oneplus-No-Red-One

An Xposed module to prevent Oneplus from making red "1" digits on the clocks
GNU General Public License v3.0
1 stars 0 forks source link

Quickfix for OS 14 #1

Open FreezyExp opened 8 months ago

FreezyExp commented 8 months ago

this is probably not a complete patch, but it is enough for me as I do not use the Always On Display (AOD)

ClockStyleOp14.java:

package com.upbad.apps.opgo.plugin.systemui;

import android.content.Context;
import android.text.SpannableStringBuilder;
import android.text.TextUtils;
import android.widget.TextView;

import com.upbad.apps.opgo.plugin.IPlugin;

import de.robv.android.xposed.XC_MethodHook;
import de.robv.android.xposed.XposedHelpers;
import de.robv.android.xposed.callbacks.XC_LoadPackage;

import static com.upbad.apps.opgo.util.LogUtil.log;

public class ClockStyleOp14 implements IPlugin {
    @Override
    public void hook(XC_LoadPackage.LoadPackageParam lpparam, ClassLoader classLoader) {
        log("SystemUI hook() started");

        // in com.oplus.systemui.common.clock.OplusClockExImpl
        // found function: public boolean setTextWithRedOneStyle(@NotNull TextView textView, @NotNull CharSequence charSequence)
        XposedHelpers.findAndHookMethod("com.oplus.systemui.common.clock.OplusClockExImpl",
                classLoader,
                "setTextWithRedOneStyle",
                TextView.class,
                CharSequence.class,
                new XC_MethodHook() {
                    @Override
                    protected void beforeHookedMethod(MethodHookParam param) {
                        TextView textView = (TextView) param.args[0];
                        CharSequence text = (CharSequence) param.args[1];

                        if (textView == null) {
                            param.setResult(false);
                            log("OplusClockExImpl textview was null");
                            return;
                        }
                        if (text == null || TextUtils.isEmpty(text)) text = "time";

                        textView.setText(text);
                        param.setResult(false);
                    }
                });

        XposedHelpers.findAndHookMethod("com.oplus.keyguard.utils.KeyguardUtils",
                classLoader,
                "getSpannedHourString",
                Context.class,
                String.class,
                new XC_MethodHook() {
                    @Override
                    protected void beforeHookedMethod(MethodHookParam param) {
                        Context context = (Context) param.args[0];
                        String text = (String) param.args[1];

                        if (context == null || TextUtils.isEmpty(text)) {
                            text = "";
                        }
                        param.setResult(new SpannableStringBuilder(text.toString()));
                    }
                });

        log("SystemUI hook() ended");
    }
}
zehuanli commented 3 months ago

I wish I had seen your repo before tackling into OOS 14 and getting the similar hooks as yours...

The hook for AOD is kind of the same except https://github.com/FreezyExp/Oneplus-No-Red-One/blob/f52592ef11826e5c69ff27dc616415bf2ae9c351/app/src/main/java/com/upbad/apps/opgo/plugin/uiengine/UIEngineClockStyleOp13.java#L31 should return null due to the change of the source code.