refactor: completion code optimizing

This commit is contained in:
2024-12-13 10:35:06 +08:00
parent 0c43bc5b97
commit 8b6d35fa01
2 changed files with 66 additions and 110 deletions

View File

@@ -96,8 +96,8 @@ import com.highcapable.yukihookapi.hook.type.android.StatusBarNotificationClass
import com.highcapable.yukihookapi.hook.type.java.ArrayListClass import com.highcapable.yukihookapi.hook.type.java.ArrayListClass
import com.highcapable.yukihookapi.hook.type.java.BooleanClass import com.highcapable.yukihookapi.hook.type.java.BooleanClass
import com.highcapable.yukihookapi.hook.type.java.BooleanType import com.highcapable.yukihookapi.hook.type.java.BooleanType
import com.highcapable.yukihookapi.hook.type.java.FloatType
import com.highcapable.yukihookapi.hook.type.java.IntType import com.highcapable.yukihookapi.hook.type.java.IntType
import de.robv.android.xposed.XposedHelpers
import top.defaults.drawabletoolbox.DrawableBuilder import top.defaults.drawabletoolbox.DrawableBuilder
/** /**
@@ -197,10 +197,10 @@ object SystemUIHooker : YukiBaseHooker() {
) )
) )
/** HyperOS 焦点通知的用到的 */ /** HyperOS 焦点通知的用到的 API */
private val FocusUtilsClass by lazyClassOrNull("${PackageName.SYSTEMUI}.statusbar.notification.utils.FocusUtils") private val FocusUtilsClass by lazyClassOrNull("${PackageName.SYSTEMUI}.statusbar.notification.utils.FocusUtils")
/** HyperOS 焦点通知的用到的 */ /** HyperOS 焦点通知的用到的 API */
private val FocusedNotifPromptViewClass by lazyClassOrNull("${PackageName.SYSTEMUI}.statusbar.phone.FocusedNotifPromptView") private val FocusedNotifPromptViewClass by lazyClassOrNull("${PackageName.SYSTEMUI}.statusbar.phone.FocusedNotifPromptView")
/** 缓存的通知图标优化数组 */ /** 缓存的通知图标优化数组 */
@@ -308,31 +308,32 @@ object SystemUIHooker : YukiBaseHooker() {
* @param isCustom 是否为通知优化生效图标 * @param isCustom 是否为通知优化生效图标
* @param isGrayscale 是否为灰度图标 * @param isGrayscale 是否为灰度图标
*/ */
@Suppress("DEPRECATION")
private fun loggerDebug(tag: String, context: Context, nf: StatusBarNotification?, isCustom: Boolean, isGrayscale: Boolean) { private fun loggerDebug(tag: String, context: Context, nf: StatusBarNotification?, isCustom: Boolean, isGrayscale: Boolean) {
if (ConfigData.isEnableModuleLog) { if (ConfigData.isEnableModuleLog) {
val focusticker = nf?.notification?.extras?.getString("miui.focus.ticker","") val focusTicker = nf?.notification?.extras?.getString("miui.focus.ticker")
val focusiconId = nf?.notification?.extras?.getInt(" miui.focus.iconId",0) val focusIconId = nf?.notification?.extras?.getInt("miui.focus.iconId", -1)
val focusrv = nf?.notification?.extras?.getParcelable<RemoteViews>("miui.focus.rv") val focusRv = nf?.notification?.extras?.getParcelable<RemoteViews?>("miui.focus.rv")
val focus = nf?.notification?.extras?.getString("miui.focus.param","") val focusParam = nf?.notification?.extras?.getString("miui.focus.param")
if (focusticker != "" ){ if (!focusTicker.isNullOrBlank())
YLog.debug( YLog.debug(
msg = "(Focus open,Processing $tag) ↓\n" + msg = "(Processing $tag with Focus Notification) ↓\n" +
"[Title]: ${nf?.notification?.extras?.getString(Notification.EXTRA_TITLE)}\n" + "[Title]: ${nf.notification?.extras?.getString(Notification.EXTRA_TITLE)}\n" +
"[Content]: ${nf?.notification?.extras?.getString(Notification.EXTRA_TEXT)}\n" + "[Content]: ${nf.notification?.extras?.getString(Notification.EXTRA_TEXT)}\n" +
"[App Name]: ${context.appNameOf(packageName = nf?.packageName ?: "")}\n" + "[App Name]: ${context.appNameOf(packageName = nf.packageName ?: "")}\n" +
"[Package Name]: ${nf?.packageName}\n" + "[Package Name]: ${nf.packageName}\n" +
"[Sender Package Name]: ${nf?.compatOpPkgName}\n" + "[Sender Package Name]: ${nf.compatOpPkgName}\n" +
"[Custom Icon]: $isCustom\n" + "[Custom Icon]: $isCustom\n" +
"[Grayscale Icon]: $isGrayscale\n" + "[Grayscale Icon]: $isGrayscale\n" +
"[From Xmsf]: ${nf?.isXmsf}\n" + "[From Xmsf]: ${nf.isXmsf}\n" +
"[String]: ${nf?.notification}\n" + "[String]: ${nf.notification}\n" +
"[Focus IconId]: $focusiconId\n" + "[Focus IconId]: $focusIconId\n" +
"[Focus String] : ${focus}\n" + "[Focus String]: ${focusParam}\n" +
"[Focus rv String] : ${focusrv}\n" + "[Focus rv String]: ${focusRv}\n" +
"[Focus ticker String] : ${focusticker}\n" + "[Focus Ticker String]: ${focusTicker}\n" +
"[Dark mode] ${isDarkIconMode} " "[Dark Icon Mode]: $isDarkIconMode"
) )
} else { else
YLog.debug( YLog.debug(
msg = "(Processing $tag) ↓\n" + msg = "(Processing $tag) ↓\n" +
"[Title]: ${nf?.notification?.extras?.getString(Notification.EXTRA_TITLE)}\n" + "[Title]: ${nf?.notification?.extras?.getString(Notification.EXTRA_TITLE)}\n" +
@@ -344,11 +345,10 @@ object SystemUIHooker : YukiBaseHooker() {
"[Grayscale Icon]: $isGrayscale\n" + "[Grayscale Icon]: $isGrayscale\n" +
"[From Xmsf]: ${nf?.isXmsf}\n" + "[From Xmsf]: ${nf?.isXmsf}\n" +
"[String]: ${nf?.notification}\n" + "[String]: ${nf?.notification}\n" +
"[Dark mode] $isDarkIconMode " "[Dark Icon Mode]: $isDarkIconMode"
) )
} }
} }
}
/** /**
* - 这个是修复彩色图标的关键核心代码判断 * - 这个是修复彩色图标的关键核心代码判断
@@ -962,8 +962,7 @@ object SystemUIHooker : YukiBaseHooker() {
context = context, context = context,
nf = expandedNf, nf = expandedNf,
iconDrawable = result<Icon>()?.loadDrawable(context) iconDrawable = result<Icon>()?.loadDrawable(context)
).also { pair -> if (pair.second) result = Icon.createWithBitmap(pair.first?.toBitmap()) ).also { pair -> if (pair.second) result = Icon.createWithBitmap(pair.first?.toBitmap()) }
}
} }
} }
} }
@@ -971,34 +970,22 @@ object SystemUIHooker : YukiBaseHooker() {
FocusedNotifPromptViewClass?.apply { FocusedNotifPromptViewClass?.apply {
method { method {
name = "onDarkChanged" name = "onDarkChanged"
param(ArrayListClass, Float::class.java, IntType, IntType, IntType, BooleanType) param(ArrayListClass, FloatType, IntType, IntType, IntType, BooleanType)
}.hook().after { }.hook().after {
val isdark = args(index = 1).float() val isDark = args(index = 1).float()
val mIcon = field { name = "mIcon" }.get(instance).any() val mIcon = field { name = "mIcon" }.get(instance)
if (ConfigData.isEnableModuleLog){ if (ConfigData.isEnableModuleLog)
YLog.debug("FocusedNotifPromptView debug $isdark ${mIcon}") YLog.debug("FocusedNotifPromptView DEBUG $isDark ${mIcon.any()}")
} /** HyperOS 1.x 旧版本适配 */
if (miosVersion == "1.0" || miosVersion == "1.1"){ if (miosVersion == "1.0" || miosVersion == "1.1")
if (isdark <= 0.5f ) { mIcon.current()?.method { name = "setColorFilter" }?.call(if (isDark <= 0.5f) Color.WHITE else Color.BLACK)
XposedHelpers.callMethod(mIcon, "setColorFilter", Color.WHITE)
} else {
XposedHelpers.callMethod(mIcon, "setColorFilter", Color.BLACK)
} }
} }
}
}
/** 去他妈的焦点通知彩色图标 */ /** 去他妈的焦点通知彩色图标 */
FocusUtilsClass?.apply { FocusUtilsClass?.method {
method { name { it == "getStatusBarTickerDarkIcon" || it == "getStatusBarTickerIcon" }
name = "getStatusBarTickerDarkIcon" param { (it[0] == StatusBarNotificationClass || it[0] == ExpandedNotificationClass) && it.size == 1 }
param(StatusBarNotificationClass) }?.hookAll()?.after {
}.remedys {
method {
name = "getStatusBarTickerDarkIcon"
param(ExpandedNotificationClass)
}
}.hook().after {
(globalContext ?: args().first().cast())?.also { context -> (globalContext ?: args().first().cast())?.also { context ->
val expandedNf = args().first().cast<StatusBarNotification?>() val expandedNf = args().first().cast<StatusBarNotification?>()
val small = expandedNf?.notification?.smallIcon val small = expandedNf?.notification?.smallIcon
@@ -1010,36 +997,7 @@ object SystemUIHooker : YukiBaseHooker() {
).also { pair -> ).also { pair ->
val originalBitmap = pair.first?.toBitmap() val originalBitmap = pair.first?.toBitmap()
val bitmap = originalBitmap?.let { Bitmap.createScaledBitmap(it, 50, 50, true) } val bitmap = originalBitmap?.let { Bitmap.createScaledBitmap(it, 50, 50, true) }
val icon = Icon.createWithBitmap(bitmap) result = Icon.createWithBitmap(bitmap).apply { setTint(Color.BLACK) }
icon.setTint(Color.BLACK)
result = icon
}
}
}
method {
name = "getStatusBarTickerIcon"
param(StatusBarNotificationClass)
}.remedys {
method {
name = "getStatusBarTickerIcon"
param(ExpandedNotificationClass)
}
}.hook().after {
(globalContext ?: args().first().cast())?.also { context ->
val expandedNf = args(0).cast<StatusBarNotification?>()
val small = expandedNf?.notification?.smallIcon
/** Hook 状态栏小图标 */
compatStatusIcon(
context = context,
nf = expandedNf,
iconDrawable = small?.loadDrawable(context)
).also { pair ->
val originalBitmap = pair.first?.toBitmap()
val bitmap = originalBitmap?.let { Bitmap.createScaledBitmap(it, 50, 50, true) }
val icon = Icon.createWithBitmap(bitmap)
icon.setTint(Color.WHITE)
result = icon
}
} }
} }
} }
@@ -1056,10 +1014,9 @@ object SystemUIHooker : YukiBaseHooker() {
nf = expandedNf, nf = expandedNf,
iconDrawable = expandedNf?.notification?.smallIcon?.loadDrawable(iconView.context) iconDrawable = expandedNf?.notification?.smallIcon?.loadDrawable(iconView.context)
).also { pair -> ).also { pair ->
if (pair.second){ if (pair.second)
result = iconView.setImageDrawable(pair.first?.toBitmap()?.toDrawable(iconView.resources)) result = iconView.setImageDrawable(pair.first?.toBitmap()?.toDrawable(iconView.resources))
} }
}
updateStatusBarIconColor(iconView) updateStatusBarIconColor(iconView)
} }
/** /**

View File

@@ -77,7 +77,6 @@ import java.text.SimpleDateFormat
import java.util.Calendar import java.util.Calendar
import java.util.Date import java.util.Date
import java.util.Locale import java.util.Locale
import kotlin.math.abs
/** /**
* 系统深色模式是否开启 * 系统深色模式是否开启