Skip to content

Commit

Permalink
opt: revert plugin loader
Browse files Browse the repository at this point in the history
  • Loading branch information
Sevtinge committed Dec 6, 2024
1 parent d27906e commit 0e981f6
Show file tree
Hide file tree
Showing 10 changed files with 432 additions and 95 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
import com.sevtinge.hyperceiler.module.hook.systemui.navigation.RotationButton;
import com.sevtinge.hyperceiler.module.hook.systemui.plugin.FocusNotifLyricPluginHelper;
import com.sevtinge.hyperceiler.module.hook.systemui.plugin.NewPluginHelper;
import com.sevtinge.hyperceiler.module.hook.systemui.plugin.NewPluginHelperKt;
import com.sevtinge.hyperceiler.module.hook.systemui.statusbar.BlurEnable;
import com.sevtinge.hyperceiler.module.hook.systemui.statusbar.DoubleTapToSleep;
import com.sevtinge.hyperceiler.module.hook.systemui.statusbar.HideStatusBarBeforeScreenshot;
Expand Down Expand Up @@ -133,8 +134,9 @@ public class SystemUiV extends BaseModule {
@Override
public void handleLoadPackage() {
// PluginHelper
initHook(new NewPluginHelper());
initHook(FocusNotifLyricPluginHelper.INSTANCE, mPrefsMap.getBoolean("system_ui_statusbar_music_switch"));
initHook(NewPluginHelperKt.INSTANCE);
/*initHook(new NewPluginHelper());
initHook(FocusNotifLyricPluginHelper.INSTANCE, mPrefsMap.getBoolean("system_ui_statusbar_music_switch"));*/
// initHook(Island.INSTANCE, true); // 灵动岛

// 小窗
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
/*
* This file is part of HyperCeiler.
* HyperCeiler is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
* Copyright (C) 2023-2024 HyperCeiler Contributions
*/
package com.sevtinge.hyperceiler.module.hook.systemui.controlcenter;

import static com.sevtinge.hyperceiler.utils.prefs.PrefsUtils.mPrefsMap;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.GradientDrawable;
import android.view.View;

import com.sevtinge.hyperceiler.module.base.tool.HookTool;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

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

public class CCGridForHyperOS {
private static final float radius = (float) mPrefsMap.getInt("system_ui_control_center_rounded_rect_radius", 72);

private static Drawable warningD = null;
private static Drawable enabledD = null;
private static Drawable restrictedD = null;
private static Drawable disabledD = null;
private static Drawable unavailableD = null;
private static int configuration = 0;
private static int orientation;

public static void initCCGridForHyperOS(ClassLoader classLoader) {
Class<?> clazz = XposedHelpers.findClass("miui.systemui.controlcenter.qs.tileview.QSTileItemIconView", classLoader);
XposedHelpers.findAndHookMethod(clazz, "getCornerRadius",
new HookTool.MethodHook() {
@Override
protected void before(XC_MethodHook.MethodHookParam param) {
param.setResult((float) mPrefsMap.getInt("system_ui_control_center_rounded_rect_radius", 72));
}
}
);
XposedHelpers.findAndHookMethod("miui.systemui.controlcenter.qs.tileview.QSTileItemIconView", classLoader, "updateIcon",
"com.android.systemui.plugins.qs.QSTile$State", boolean.class, boolean.class,
new HookTool.MethodHook() {
@Override
protected void before(MethodHookParam param) {
XposedHelpers.callMethod(param.thisObject, "updateResources");
}
}
);

XposedHelpers.findAndHookMethod("miui.systemui.controlcenter.qs.tileview.QSTileItemIconView", classLoader,
"updateResources",
new HookTool.MethodHook() {
@Override
protected void before(MethodHookParam param) {
orientation = ((View) param.thisObject).getContext().getResources().getConfiguration().orientation;

StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
Set<String> targetMethods = new HashSet<>(Arrays.asList(
"miui.systemui.controlcenter.qs.tileview.QSTileItemView.updateState",
"miui.systemui.controlcenter.panel.main.recyclerview.MainPanelItemViewHolder.onSuperSaveModeChanged",
"miui.systemui.controlcenter.qs.tileview.QSTileItemView.updateCustomizeState",
"miui.systemui.controlcenter.qs.tileview.QSTileItemView.onModeChanged"
));

boolean isMethodFound = Arrays.stream(stackTrace)
.anyMatch(element -> targetMethods.contains(element.getClassName() + "." + element.getMethodName()));

if (configuration == orientation && isMethodFound) return;

Context pluginContext = (Context) XposedHelpers.getObjectField(param.thisObject, "pluginContext");
int warning = pluginContext.getResources().getIdentifier("qs_background_warning", "drawable", "miui.systemui.plugin");
int enabled = pluginContext.getResources().getIdentifier("qs_background_enabled", "drawable", "miui.systemui.plugin");
int restricted = pluginContext.getResources().getIdentifier("qs_background_restricted", "drawable", "miui.systemui.plugin");
int disabled = pluginContext.getResources().getIdentifier("qs_background_disabled", "drawable", "miui.systemui.plugin");
int unavailable = pluginContext.getResources().getIdentifier("qs_background_unavailable", "drawable", "miui.systemui.plugin");
warningD = pluginContext.getTheme().getDrawable(warning);
enabledD = pluginContext.getTheme().getDrawable(enabled);
restrictedD = pluginContext.getTheme().getDrawable(restricted);
disabledD = pluginContext.getTheme().getDrawable(disabled);
unavailableD = pluginContext.getTheme().getDrawable(unavailable);
if (warningD != null) {
GradientDrawable warningG = (GradientDrawable) warningD;
warningG.setCornerRadius(radius);
}
if (enabledD != null) {
GradientDrawable enabledG = (GradientDrawable) enabledD;
enabledG.setCornerRadius(radius);
}
if (restrictedD != null) {
GradientDrawable restrictedG = (GradientDrawable) restrictedD;
restrictedG.setCornerRadius(radius);
}
if (disabledD != null) {
GradientDrawable disabledG = (GradientDrawable) disabledD;
disabledG.setCornerRadius(radius);
}
if (unavailableD != null) {
GradientDrawable unavailableG = (GradientDrawable) unavailableD;
unavailableG.setCornerRadius(radius);
}

configuration = orientation;
}
}
);

XposedHelpers.findAndHookMethod("miui.systemui.controlcenter.qs.tileview.QSTileItemIconView", classLoader,
"setCornerRadius", float.class,
new HookTool.MethodHook() {
@Override
protected void before(MethodHookParam param) {
param.setResult(null);
}
}
);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*
* This file is part of HyperCeiler.
* HyperCeiler is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
* Copyright (C) 2023-2024 HyperCeiler Contributions
*/
package com.sevtinge.hyperceiler.module.hook.systemui.controlcenter

import android.content.*
import android.graphics.drawable.*
import android.view.*
import com.sevtinge.hyperceiler.module.base.tool.HookTool.*
import com.sevtinge.hyperceiler.utils.prefs.*
import de.robv.android.xposed.*

object CCGridForHyperOSKt {
private val radius by lazy {
PrefsUtils.mPrefsMap.getInt("system_ui_control_center_rounded_rect_radius", 72).toFloat() }

@JvmStatic
fun initCCGridForHyperOS(classLoader: ClassLoader?) {
var warningD: Drawable? = null
var enabledD: Drawable? = null
var restrictedD: Drawable? = null
var disabledD: Drawable? = null
var unavailableD: Drawable? = null
var configuration = 0
var orientation: Int

XposedHelpers.findAndHookMethod("miui.systemui.controlcenter.qs.tileview.QSTileItemIconView", classLoader, "updateIcon", "com.android.systemui.plugins.qs.QSTile\$State", Boolean::class.javaPrimitiveType, Boolean::class.javaPrimitiveType, object : MethodHook() {
override fun before(param: MethodHookParam) {
orientation = (param.thisObject as View).context.resources.configuration.orientation
val stackTrace = Thread.currentThread().stackTrace
val targetMethods = setOf(
"miui.systemui.controlcenter.qs.tileview.QSTileItemView.updateState",
"miui.systemui.controlcenter.panel.main.recyclerview.MainPanelItemViewHolder.onSuperSaveModeChanged",
"miui.systemui.controlcenter.qs.tileview.QSTileItemView.updateCustomizeState",
"miui.systemui.controlcenter.qs.tileview.QSTileItemView.onModeChanged"
)

val isMethodFound = stackTrace.any { element ->
"${element.className}.${element.methodName}" in targetMethods
}

if (configuration == orientation && isMethodFound) return

val pluginContext: Context = XposedHelpers.getObjectField(param.thisObject, "pluginContext") as Context

val warning: Int = pluginContext.resources.getIdentifier("qs_background_warning", "drawable", "miui.systemui.plugin")
val enabled: Int = pluginContext.resources.getIdentifier("qs_background_enabled", "drawable", "miui.systemui.plugin")
val restricted: Int = pluginContext.resources.getIdentifier("qs_background_restricted", "drawable", "miui.systemui.plugin")
val disabled: Int = pluginContext.resources.getIdentifier("qs_background_disabled", "drawable", "miui.systemui.plugin")
val unavailable: Int = pluginContext.resources.getIdentifier("qs_background_unavailable", "drawable", "miui.systemui.plugin")
warningD = pluginContext.theme.getDrawable(warning)
enabledD = pluginContext.theme.getDrawable(enabled)
restrictedD = pluginContext.theme.getDrawable(restricted)
disabledD = pluginContext.theme.getDrawable(disabled)
unavailableD = pluginContext.theme.getDrawable(unavailable)

if (warningD is GradientDrawable) {
(warningD as GradientDrawable).cornerRadius = radius
}
if (enabledD is GradientDrawable) {
(enabledD as GradientDrawable).cornerRadius = radius
}
if (restrictedD is GradientDrawable) {
(restrictedD as GradientDrawable).cornerRadius = radius
}
if (disabledD is GradientDrawable) {
(disabledD as GradientDrawable).cornerRadius = radius
}
if (unavailableD is GradientDrawable) {
(unavailableD as GradientDrawable).cornerRadius = radius
}

configuration = orientation
}
}
)
}
}
Loading

0 comments on commit 0e981f6

Please sign in to comment.