Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: fix bastardized custom action buttons in media control panel #1043

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
import com.sevtinge.hyperceiler.module.hook.systemui.controlcenter.MediaControlPanelTimeViewTextSize;
import com.sevtinge.hyperceiler.module.hook.systemui.controlcenter.MediaSeekBarColor;
import com.sevtinge.hyperceiler.module.hook.systemui.controlcenter.MuteVisibleNotifications;
import com.sevtinge.hyperceiler.module.hook.systemui.controlcenter.NewBrightnessPct;
import com.sevtinge.hyperceiler.module.hook.systemui.controlcenter.NotificationImportanceHyperOSFix;
import com.sevtinge.hyperceiler.module.hook.systemui.controlcenter.NotificationRowMenu;
import com.sevtinge.hyperceiler.module.hook.systemui.controlcenter.NotificationWeather;
Expand Down Expand Up @@ -349,6 +350,7 @@ public void handleLoadPackage() {
initHook(DisableBottomBar.INSTANCE, mPrefsMap.getBoolean("system_ui_disable_bottombar"));
initHook(UnlockClipboard.INSTANCE, mPrefsMap.getBoolean("system_ui_unlock_clipboard"));
initHook(new VolumeTimerValuesHook(), mPrefsMap.getBoolean("system_ui_volume_timer"));
initHook(NewBrightnessPct.INSTANCE, mPrefsMap.getBoolean("system_showpct_title"));

// 锁屏
initHook(new ScramblePIN(), mPrefsMap.getBoolean("system_ui_lock_screen_scramble_pin"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
import com.sevtinge.hyperceiler.module.hook.systemui.controlcenter.MediaControlPanelTimeViewTextSize;
import com.sevtinge.hyperceiler.module.hook.systemui.controlcenter.MediaSeekBarColor;
import com.sevtinge.hyperceiler.module.hook.systemui.controlcenter.MuteVisibleNotifications;
import com.sevtinge.hyperceiler.module.hook.systemui.controlcenter.NewBrightnessPct;
import com.sevtinge.hyperceiler.module.hook.systemui.controlcenter.NewFlashLight;
import com.sevtinge.hyperceiler.module.hook.systemui.controlcenter.NotificationImportanceHyperOSFix;
import com.sevtinge.hyperceiler.module.hook.systemui.controlcenter.NotificationRowMenu;
Expand Down Expand Up @@ -269,6 +270,7 @@ public void handleLoadPackage() {
initHook(DisableInfinitymodeGesture.INSTANCE, mPrefsMap.getBoolean("system_ui_disable_infinitymode_gesture"));
initHook(DisableBottomBar.INSTANCE, mPrefsMap.getBoolean("system_ui_disable_bottombar"));
initHook(UnlockClipboard.INSTANCE, mPrefsMap.getBoolean("system_ui_unlock_clipboard"));
initHook(NewBrightnessPct.INSTANCE, mPrefsMap.getBoolean("system_showpct_title"));

// 锁屏
initHook(new ScramblePIN(), mPrefsMap.getBoolean("system_ui_lock_screen_scramble_pin"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
import com.sevtinge.hyperceiler.module.hook.systemui.controlcenter.MediaControlPanelTimeViewTextSize;
import com.sevtinge.hyperceiler.module.hook.systemui.controlcenter.MediaSeekBarColor;
import com.sevtinge.hyperceiler.module.hook.systemui.controlcenter.MuteVisibleNotifications;
import com.sevtinge.hyperceiler.module.hook.systemui.controlcenter.NewBrightnessPct;
import com.sevtinge.hyperceiler.module.hook.systemui.controlcenter.NotificationImportanceHyperOSFix;
import com.sevtinge.hyperceiler.module.hook.systemui.controlcenter.NotificationRowMenu;
import com.sevtinge.hyperceiler.module.hook.systemui.controlcenter.NotificationWeather;
Expand Down Expand Up @@ -349,6 +350,7 @@ public void handleLoadPackage() {
initHook(DisableBottomBar.INSTANCE, mPrefsMap.getBoolean("system_ui_disable_bottombar"));
initHook(UnlockClipboard.INSTANCE, mPrefsMap.getBoolean("system_ui_unlock_clipboard"));
initHook(new VolumeTimerValuesHook(), mPrefsMap.getBoolean("system_ui_volume_timer"));
initHook(NewBrightnessPct.INSTANCE, mPrefsMap.getBoolean("system_showpct_title"));

// 锁屏
initHook(new ScramblePIN(), mPrefsMap.getBoolean("system_ui_lock_screen_scramble_pin"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
import com.sevtinge.hyperceiler.module.hook.systemui.controlcenter.MediaControlPanelTimeViewTextSize;
import com.sevtinge.hyperceiler.module.hook.systemui.controlcenter.MediaSeekBarColor;
import com.sevtinge.hyperceiler.module.hook.systemui.controlcenter.MuteVisibleNotifications;
import com.sevtinge.hyperceiler.module.hook.systemui.controlcenter.NewBrightnessPct;
import com.sevtinge.hyperceiler.module.hook.systemui.controlcenter.NewFlashLight;
import com.sevtinge.hyperceiler.module.hook.systemui.controlcenter.NotificationImportanceHyperOSFix;
import com.sevtinge.hyperceiler.module.hook.systemui.controlcenter.NotificationRowMenu;
Expand Down Expand Up @@ -285,6 +286,7 @@ public void handleLoadPackage() {
initHook(DisableInfinitymodeGesture.INSTANCE, mPrefsMap.getBoolean("system_ui_disable_infinitymode_gesture"));
initHook(DisableBottomBar.INSTANCE, mPrefsMap.getBoolean("system_ui_disable_bottombar"));
initHook(UnlockClipboard.INSTANCE, mPrefsMap.getBoolean("system_ui_unlock_clipboard"));
initHook(NewBrightnessPct.INSTANCE, mPrefsMap.getBoolean("system_showpct_title"));

// 锁屏
initHook(new ScramblePIN(), mPrefsMap.getBoolean("system_ui_lock_screen_scramble_pin"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public static void initPct(ViewGroup container, int source, Context context) {
getTextView().setTextColor(ColorStateList.valueOf(Color.parseColor("#FFFFFFFF")));
getTextView().setBackground(modRes.getDrawable(R.drawable.input_background, context.getTheme()));
} catch (Throwable err) {
logE("ShowVolumePct", err);
logE("ShowPct", err);
}
if (mPrefsMap.getBoolean("system_showpct_use_blur")) {
try {
Expand All @@ -188,7 +188,7 @@ public static void initPct(ViewGroup container, int source, Context context) {
MiBlurUtils.clearMiBackgroundBlendColor(getTextView());
MiBlurUtils.addMiBackgroundBlendColor(getTextView(), Color.argb(a, 0, 0, 0), 101);
} catch (Throwable e) {
logE("ShowVolumePct", e);
logE("ShowPct", e);
}
}
container.addView(getTextView());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package com.sevtinge.hyperceiler.module.hook.systemui.controlcenter;

import android.widget.ImageButton;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
Expand All @@ -40,6 +41,35 @@ public class MediaButton extends BaseHook {

@Override
public void init() throws NoSuchMethodException {

Class<?> DrawableUtils = findClassIfExists("com.miui.utils.DrawableUtils", lpparam.classLoader);
hookAllMethods("com.android.systemui.media.controls.ui.controller.MediaControlPanel",
"bindButtonCommon", new MethodHook() {
@Override
protected void before(MethodHookParam param) throws Throwable {
Object mediaAction = param.args[0];
String desc = (String) XposedHelpers.getObjectField(mediaAction, "contentDescription");
if ((typeCustom != 140) &&
!desc.contains("Play") && !desc.contains("Pause") &&
!desc.contains("Previous track") && !desc.contains("Next track")) {
ImageButton button = (ImageButton) param.args[0];
Drawable loadDrawable = (Drawable) XposedHelpers.getObjectField(mediaAction, "icon");
Method method = DrawableUtils.getDeclaredMethod("drawable2Bitmap", Drawable.class);
Bitmap bitmap = (Bitmap) method.invoke(null, loadDrawable);
Bitmap scaledBitmap = Bitmap.createScaledBitmap(bitmap, typeCustom, typeCustom, true);
XposedHelpers.setObjectField(mediaAction, "icon", new BitmapDrawable(button.getContext().getResources(), scaledBitmap));
} else if (type != 140) {
ImageButton button = (ImageButton) param.args[0];
Drawable loadDrawable = (Drawable) XposedHelpers.getObjectField(mediaAction, "icon");
Method method = DrawableUtils.getDeclaredMethod("drawable2Bitmap", Drawable.class);
Bitmap bitmap = (Bitmap) method.invoke(null, loadDrawable);
Bitmap scaledBitmap = Bitmap.createScaledBitmap(bitmap, type, type, true);
XposedHelpers.setObjectField(mediaAction, "icon", new BitmapDrawable(button.getContext().getResources(), scaledBitmap));
}
}
});

/* HyperOS 1.0
findAndHookMethod("com.android.systemui.media.controls.pipeline.MediaDataManager",
"createActionsFromState", String.class, MediaController.class, UserHandle.class,
new MethodHook() {
Expand Down Expand Up @@ -91,6 +121,7 @@ protected void after(MethodHookParam param) throws Throwable {
}
}
}
);
);
*/
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
package com.sevtinge.hyperceiler.module.hook.systemui.controlcenter

import android.annotation.*
import android.view.*
import com.github.kyuubiran.ezxhelper.ClassUtils.loadClass
import com.github.kyuubiran.ezxhelper.ClassUtils.loadClassOrNull
import com.github.kyuubiran.ezxhelper.HookFactory.`-Static`.createAfterHook
import com.github.kyuubiran.ezxhelper.finders.MethodFinder.`-Static`.methodFinder
import com.sevtinge.hyperceiler.module.base.*
import com.sevtinge.hyperceiler.module.base.tool.*
import com.sevtinge.hyperceiler.utils.*
import de.robv.android.xposed.*

object NewBrightnessPct : BaseHook() {
private val MiuiBrightnessController by lazy {
loadClass("com.android.systemui.controlcenter.policy.MiuiBrightnessController")
}
private val brightnessUtils by lazy {
loadClassOrNull("com.android.systemui.controlcenter.policy.BrightnessUtils")
}

fun initLoaderHook(classLoader: ClassLoader) {
loadClass("miui.systemui.controlcenter.panel.main.brightness.BrightnessSliderController\$seekBarListener\$1", classLoader)
.methodFinder().filterByName("onStartTrackingTouch")
.first().createAfterHook {
startPct(it)
}

loadClass("miui.systemui.controlcenter.panel.main.brightness.BrightnessPanelSliderController\$seekBarListener\$1")
.methodFinder().filterByName("onStartTrackingTouch")
.first().createAfterHook {
startPct(it)
}
}

private fun startPct(it: XC_MethodHook.MethodHookParam) {
val brightnessController =
it.thisObject.getObjectField("this$0")!!.getObjectField("brightnessController")
val cl = brightnessController!!.javaClass.classLoader
val controlCenterControllerImpl =
getObject("com.android.systemui.controlcenter.policy.ControlCenterControllerImpl", cl)
val controlCenterContentController =
getObjectArr(controlCenterControllerImpl, "controlCenter.contentController")
val mContext = controlCenterContentController!!.callMethod("get")!!
.getObjectField("content")
val windowView = mContext!!.callMethod("getContentView")
if (windowView == null) {
logE(TAG, lpparam.packageName, "mControlPanelContentView is null")
return
}
OtherTool.initPct(windowView as ViewGroup, 2, windowView.context)
OtherTool.getTextView().visibility = View.VISIBLE
}

@SuppressLint("SetTextI18n")
override fun init() {
hookAllMethods(
MiuiBrightnessController, "onStop",
object : MethodHook() {
override fun after(param: MethodHookParam) {
OtherTool.removePct(OtherTool.getTextView())
}
})

hookAllMethods(
MiuiBrightnessController, "onChanged",
object : MethodHook() {
override fun after(param: MethodHookParam) {
var pctTag = 0
if (OtherTool.getTextView() != null && OtherTool.getTextView().tag != null) {
pctTag = OtherTool.getTextView().tag as Int
}
if (pctTag == 0 || OtherTool.getTextView() == null) return
val currentLevel = param.args[3] as Int
if (brightnessUtils != null) {
val maxLevel =
brightnessUtils!!.getStaticObjectField("GAMMA_SPACE_MAX") as Int
OtherTool.getTextView().text =
((currentLevel * 100) / maxLevel).toString() + "%"
}
}
})
}

private fun getObject(str: String, cl: ClassLoader?): Any? {
val dependency = loadClass("com.android.systemui.Dependency", cl)
val cl2 = loadClass(str, cl)
val mDependency =
dependency.getStaticObjectField("sDependency")!!.callMethod("getDependencyInner", cl2)
return mDependency
}

private fun getObjectArr(obj: Any?, str: String): Any? {
if (obj == null) {
return null
}
val fields = str.split(".")
var currentObj = obj
for (field in fields) {
try {
currentObj = currentObj!!.getObjectField(field)
} catch (e: Throwable) {
currentObj = "ObjectFieldNotExist"
}
if (currentObj == "ObjectFieldNotExist") {
return "ObjectFieldNotExist"
}
}
return currentObj
}
}
Loading
Loading