Skip to content

Commit

Permalink
fix: A13 ignored A14 Adapt
Browse files Browse the repository at this point in the history
  • Loading branch information
hosizoraru committed Oct 31, 2023
1 parent 445ac85 commit d244658
Showing 1 changed file with 18 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ import com.highcapable.yukihookapi.hook.factory.constructor
import com.highcapable.yukihookapi.hook.factory.current
import com.highcapable.yukihookapi.hook.factory.extends
import com.highcapable.yukihookapi.hook.factory.field
import com.highcapable.yukihookapi.hook.factory.hasField
import com.highcapable.yukihookapi.hook.factory.injectModuleAppResources
import com.highcapable.yukihookapi.hook.factory.method
import com.highcapable.yukihookapi.hook.log.YLog
Expand Down Expand Up @@ -622,6 +621,20 @@ object SystemUIHooker : YukiBaseHooker() {
}
}

/**
* Hook 状态栏通知图标最大数量
* @param fieldName 最大通知图标数量 的变量名
* @param instance 被 Hook 的 Method 的实例
*/
private fun hookStatusBarMaxStaticIcons(fieldName: String, instance: Any) {
val maxStaticIconsField = NotificationIconContainerClass.field { name = fieldName }.get(instance)
if (statusBarMaxStaticIcons == -1) statusBarMaxStaticIcons = maxStaticIconsField.int()
/** 解除状态栏通知图标个数限制 */
if (isShowNotificationIcons && ConfigData.isEnableLiftedStatusIconCount)
maxStaticIconsField.set(ConfigData.liftedStatusIconCount.let { if (it in 0..100) it else 5 })
else maxStaticIconsField.set(if (isShowNotificationIcons) statusBarMaxStaticIcons else 0)
}

/**
* Hook 原生通知包装纸实例内容
* @param wrapper 通知包装纸实例
Expand Down Expand Up @@ -888,30 +901,14 @@ object SystemUIHooker : YukiBaseHooker() {
instance<ViewGroup>().layoutParams.width = 9999
}
}
/** 旧版方法 A13MIUI - 新版不存在 */
method {
name = "updateState"
}.hook {
before {
val maxStaticIconsField = NotificationIconContainerClass.field { name = "MAX_STATIC_ICONS" }.get(instance)
if (statusBarMaxStaticIcons == -1) statusBarMaxStaticIcons = maxStaticIconsField.int()
/** 解除状态栏通知图标个数限制 */
if (isShowNotificationIcons && ConfigData.isEnableLiftedStatusIconCount)
maxStaticIconsField.set(ConfigData.liftedStatusIconCount.let { if (it in 0..100) it else 5 })
else maxStaticIconsField.set(if (isShowNotificationIcons) statusBarMaxStaticIcons else 0)
}
}.by { NotificationIconContainerClass.hasField { name = "MAX_STATIC_ICONS" } }
}.ignored().hook().before { hookStatusBarMaxStaticIcons("MAX_STATIC_ICONS", instance) }
/** 新版方法 A14MIUI14/A14HyperOS - 旧版不存在 */
method {
name = "onMeasure"
}.hook {
before {
val maxStaticIconsField = NotificationIconContainerClass.field { name = "mMaxStaticIcons" }.get(instance)
if (statusBarMaxStaticIcons == -1) statusBarMaxStaticIcons = maxStaticIconsField.int()
/** 解除状态栏通知图标个数限制 */
if (isShowNotificationIcons && ConfigData.isEnableLiftedStatusIconCount)
maxStaticIconsField.set(ConfigData.liftedStatusIconCount.let { if (it in 0..100) it else 5 })
else maxStaticIconsField.set(if (isShowNotificationIcons) statusBarMaxStaticIcons else 0)
}
}.by { NotificationIconContainerClass.hasField { name = "mMaxStaticIcons" } }
}.ignored().hook().before { hookStatusBarMaxStaticIcons("mMaxStaticIcons", instance) }
/** 旧版方法 - 新版不存在 */
method {
name = "setMaxStaticIcons"
Expand Down

0 comments on commit d244658

Please sign in to comment.