Skip to content

Commit

Permalink
Update 2.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
YuKongA committed Feb 7, 2024
1 parent c5379c5 commit 4181c92
Show file tree
Hide file tree
Showing 5 changed files with 235 additions and 67 deletions.
6 changes: 2 additions & 4 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ android {
applicationId = namespace
minSdk = 34
targetSdk = 34
versionCode = 2000
versionName = "2.0.0"
versionCode = 2010
versionName = "2.0.1"
}

buildTypes {
Expand Down Expand Up @@ -58,7 +58,5 @@ android {

dependencies {
compileOnly(libs.xposed)
implementation(libs.coreKtx)
implementation(libs.ezXHelper)
implementation(libs.hiddenapibypass)
}
186 changes: 143 additions & 43 deletions app/src/main/kotlin/top/yukonga/mediaControlBlur/MainHook.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,10 @@ import de.robv.android.xposed.callbacks.XC_LoadPackage
import top.yukonga.mediaControlBlur.utils.AppUtils.GREY
import top.yukonga.mediaControlBlur.utils.AppUtils.colorFilterCompat
import top.yukonga.mediaControlBlur.utils.AppUtils.isDarkMode
import top.yukonga.mediaControlBlur.utils.blur.MiBlurUtils.clearMiBackgroundBlendColor
import top.yukonga.mediaControlBlur.utils.blur.MiBlurUtils.setBlurRoundRect
import top.yukonga.mediaControlBlur.utils.blur.MiBlurUtils.setMiBackgroundBlendColors
import top.yukonga.mediaControlBlur.utils.blur.MiBlurUtils.setMiViewBlurMode
import top.yukonga.mediaControlBlur.utils.blur.MiBlurUtils.setPassWindowBlurEnabled
import top.yukonga.mediaControlBlur.utils.blur.MiBlurUtils.supportBackgroundBlur

private const val TAG = "MediaControlBlur"

Expand All @@ -42,7 +41,14 @@ class MainHook : IXposedHookLoadPackage, IXposedHookZygoteInit {
when (lpparam.packageName) {
"com.android.systemui" -> {
try {
if (!supportBackgroundBlur()) return

val miuiMediaControlPanel = loadClassOrNull("com.android.systemui.statusbar.notification.mediacontrol.MiuiMediaControlPanel")
val playerTwoCircleView = loadClassOrNull("com.android.systemui.statusbar.notification.mediacontrol.PlayerTwoCircleView")
val miuiExpandableNotificationRow = loadClassOrNull("com.android.systemui.statusbar.notification.row.MiuiExpandableNotificationRow")
val notificationUtil = loadClassOrNull("com.android.systemui.statusbar.notification.NotificationUtil")
val zenModeView = loadClassOrNull("com.android.systemui.statusbar.notification.zen.ZenModeView")

miuiMediaControlPanel?.methodFinder()?.filterByName("bindPlayer")?.first()?.createHook {
after {
val context = AndroidAppHelper.currentApplication().applicationContext
Expand All @@ -51,7 +57,7 @@ class MainHook : IXposedHookLoadPackage, IXposedHookZygoteInit {

val titleText = mMediaViewHolder.objectHelper().getObjectOrNullAs<TextView>("titleText")
val artistText = mMediaViewHolder.objectHelper().getObjectOrNullAs<TextView>("artistText")
val seamlesIcon = mMediaViewHolder.objectHelper().getObjectOrNullAs<ImageView>("seamlessIcon")
val seamlessIcon = mMediaViewHolder.objectHelper().getObjectOrNullAs<ImageView>("seamlessIcon")
val action0 = mMediaViewHolder.objectHelper().getObjectOrNullAs<ImageButton>("action0")
val action1 = mMediaViewHolder.objectHelper().getObjectOrNullAs<ImageButton>("action1")
val action2 = mMediaViewHolder.objectHelper().getObjectOrNullAs<ImageButton>("action2")
Expand All @@ -66,7 +72,7 @@ class MainHook : IXposedHookLoadPackage, IXposedHookZygoteInit {
artistText?.setTextColor(GREY)
elapsedTimeView?.setTextColor(GREY)
totalTimeView?.setTextColor(GREY)
seamlesIcon?.setColorFilter(Color.BLACK)
seamlessIcon?.setColorFilter(Color.BLACK)
action0?.setColorFilter(Color.BLACK)
action1?.setColorFilter(Color.BLACK)
action2?.setColorFilter(Color.BLACK)
Expand All @@ -76,7 +82,7 @@ class MainHook : IXposedHookLoadPackage, IXposedHookZygoteInit {
seekBar?.thumb?.colorFilter = colorFilterCompat(Color.BLACK)
} else {
titleText?.setTextColor(Color.WHITE)
seamlesIcon?.setColorFilter(Color.WHITE)
seamlessIcon?.setColorFilter(Color.WHITE)
action0?.setColorFilter(Color.WHITE)
action1?.setColorFilter(Color.WHITE)
action2?.setColorFilter(Color.WHITE)
Expand All @@ -89,62 +95,156 @@ class MainHook : IXposedHookLoadPackage, IXposedHookZygoteInit {
}
}

val playerTwoCircleView = loadClassOrNull("com.android.systemui.statusbar.notification.mediacontrol.PlayerTwoCircleView")
playerTwoCircleView?.methodFinder()?.filterByName("setBackground")?.first()?.createHook {
replace {
val mediaBg = it.thisObject as ImageView
mediaBg.background = null
mediaBg.setImageDrawable(null)
}
}

val miuiExpandableNotificationRow = loadClassOrNull("com.android.systemui.statusbar.notification.row.MiuiExpandableNotificationRow")
miuiExpandableNotificationRow?.methodFinder()?.filterByName("updateBlurBg")?.first()?.createHook {
after {
val context = AndroidAppHelper.currentApplication().applicationContext

val isBackgroundBlurOpened = XposedHelpers.callStaticMethod(notificationUtil, "isBackgroundBlurOpened", context)
if (isBackgroundBlurOpened == false) return@after

val isHeadsUpState = it.thisObject.objectHelper().invokeMethodBestMatch("isHeadsUpState") as Boolean
val mExpandedParamsUpdating = it.thisObject.objectHelper().getObjectOrNullUntilSuperclassAs<Boolean>("mExpandedParamsUpdating")!!
val mExpandedParamsUpdating = it.thisObject.objectHelper().getObjectOrNullUntilSuperclassAs<Boolean>("mExpandedParamsUpdating")
val getViewState = it.thisObject.objectHelper().invokeMethodBestMatch("getViewState")
val animatingMiniWindowEnter = getViewState?.objectHelper()?.getObjectOrNullUntilSuperclassAs<Boolean>("animatingMiniWindowEnter")!!
val z2 = !(!mExpandedParamsUpdating && !animatingMiniWindowEnter)
val animatingMiniWindowEnter = getViewState?.objectHelper()?.getObjectOrNullUntilSuperclassAs<Boolean>("animatingMiniWindowEnter")

if (mExpandedParamsUpdating == null || animatingMiniWindowEnter == null) return@after
val z = !(!mExpandedParamsUpdating && !animatingMiniWindowEnter)

val intArray = if (isHeadsUpState) {
if (isDarkMode(context)) moduleRes.getIntArray(R.array.notification_element_blend_headsUp_colors_night) else moduleRes.getIntArray(R.array.notification_element_blend_headsUp_colors_light)
if (isDarkMode(context)) {
moduleRes.getIntArray(R.array.notification_element_blend_headsUp_colors_night)
} else {
moduleRes.getIntArray(R.array.notification_element_blend_headsUp_colors_light)
}
} else {
if (z2) {
if (isDarkMode(context)) moduleRes.getIntArray(R.array.notification_element_blend_keyguard_colors_night) else moduleRes.getIntArray(
R.array.notification_element_blend_keyguard_colors_light
)
if (z) {
if (isDarkMode(context)) {
moduleRes.getIntArray(R.array.notification_element_blend_keyguard_colors_night)
} else {
moduleRes.getIntArray(R.array.notification_element_blend_keyguard_colors_light)
}
} else {
if (isDarkMode(context)) moduleRes.getIntArray(R.array.notification_element_blend_shade_colors_night) else moduleRes.getIntArray(
R.array.notification_element_blend_shade_colors_light
)
if (isDarkMode(context)) {
moduleRes.getIntArray(R.array.notification_element_blend_shade_colors_night)
} else {
moduleRes.getIntArray(R.array.notification_element_blend_shade_colors_light)
}
}
}

val mBackgroundNormal = it.thisObject.objectHelper().getObjectOrNullUntilSuperclass("mBackgroundNormal")
val notificationUtil = loadClassOrNull("com.android.systemui.statusbar.notification.NotificationUtil")
XposedHelpers.callStaticMethod(notificationUtil, "applyElementViewBlend", context, mBackgroundNormal, intArray, z2)

playerTwoCircleView?.methodFinder()?.filterByName("onDraw")?.first()?.createHook {
before {
(it.thisObject.objectHelper().getObjectOrNullAs<Paint>("mPaint1"))?.alpha = 0
(it.thisObject.objectHelper().getObjectOrNullAs<Paint>("mPaint2"))?.alpha = 0
it.thisObject.objectHelper().setObject("mRadius", 0.0f)

val mediaBg = it.thisObject as ImageView

mediaBg.apply {
clearMiBackgroundBlendColor()
setPassWindowBlurEnabled(true)
setMiViewBlurMode(1)
setBlurRoundRect(60)
setMiBackgroundBlendColors(intArray, 1.0f)
if (mBackgroundNormal != null) {
XposedHelpers.callStaticMethod(notificationUtil, "applyElementViewBlend", context, mBackgroundNormal, intArray, z)
}
}

zenModeView?.methodFinder()?.filterByName("updateBackgroundBg")?.first()?.createHook {
after {

val mRealContent = it.thisObject.objectHelper().getObjectOrNull("mRealContent") ?: return@after

val context = AndroidAppHelper.currentApplication().applicationContext

val isBackgroundBlurOpened = XposedHelpers.callStaticMethod(notificationUtil, "isBackgroundBlurOpened", context)
if (isBackgroundBlurOpened == false) return@after

val mController = it.thisObject.objectHelper().getObjectOrNull("mController")
val statusBarStateController = mController?.objectHelper()?.getObjectOrNull("statusBarStateController")
val mState = statusBarStateController?.objectHelper()?.getObjectOrNull("mState") as Int

val intArray = if (mState == 2) {
if (isDarkMode(context)) {
moduleRes.getIntArray(R.array.notification_element_blend_keyguard_colors_night)
} else {
moduleRes.getIntArray(R.array.notification_element_blend_keyguard_colors_light)
}
} else {
if (isDarkMode(context)) {
moduleRes.getIntArray(R.array.notification_element_blend_shade_colors_night)
} else {
moduleRes.getIntArray(R.array.notification_element_blend_shade_colors_light)
}
}
XposedHelpers.callStaticMethod(notificationUtil, "applyElementViewBlend", context, mRealContent, intArray, true)
}
}

playerTwoCircleView?.methodFinder()?.filterByName("onDraw")?.first()?.createHook {
after {

val context = AndroidAppHelper.currentApplication().applicationContext

val isBackgroundBlurOpened = XposedHelpers.callStaticMethod(notificationUtil, "isBackgroundBlurOpened", context)
if (isBackgroundBlurOpened == false) return@after

it.thisObject.objectHelper().getObjectOrNullAs<Paint>("mPaint1")?.alpha = 0
it.thisObject.objectHelper().getObjectOrNullAs<Paint>("mPaint2")?.alpha = 0
it.thisObject.objectHelper().setObject("mRadius", 0f)
it.thisObject.objectHelper().setObject("c1x", 0f)
it.thisObject.objectHelper().setObject("c1y", 0f)
it.thisObject.objectHelper().setObject("c2x", 0f)
it.thisObject.objectHelper().setObject("c2y", 0f)

val mediaBg = it.thisObject as ImageView
miuiExpandableNotificationRow.methodFinder().filterByName("updateBlurBg").first().createHook {
after { hookParam ->
val isHeadsUpState = hookParam.thisObject.objectHelper().invokeMethodBestMatch("isHeadsUpState") as Boolean
val mExpandedParamsUpdating =
hookParam.thisObject.objectHelper().getObjectOrNullUntilSuperclassAs<Boolean>("mExpandedParamsUpdating")!!
val getViewState = hookParam.thisObject.objectHelper().invokeMethodBestMatch("getViewState")
val animatingMiniWindowEnter =
getViewState?.objectHelper()?.getObjectOrNullUntilSuperclassAs<Boolean>("animatingMiniWindowEnter")!!
val z2 = !(!mExpandedParamsUpdating && !animatingMiniWindowEnter)

val intArray = if (isHeadsUpState) {
if (isDarkMode(context)) moduleRes.getIntArray(R.array.notification_element_blend_headsUp_colors_night) else moduleRes.getIntArray(
R.array.notification_element_blend_headsUp_colors_light
)
} else {
if (z2) {
if (isDarkMode(context)) moduleRes.getIntArray(R.array.notification_element_blend_keyguard_colors_night) else moduleRes.getIntArray(
R.array.notification_element_blend_keyguard_colors_light
)
} else {
if (isDarkMode(context)) moduleRes.getIntArray(R.array.notification_element_blend_shade_colors_night) else moduleRes.getIntArray(
R.array.notification_element_blend_shade_colors_light
)
}
}
mediaBg.apply {
setMiViewBlurMode(1)
setBlurRoundRect(60)
setMiBackgroundBlendColors(intArray, 1.0f)
}
}
}
}
}

playerTwoCircleView?.methodFinder()?.filterByName("setBackground")?.first()?.createHook {
after {
val context = AndroidAppHelper.currentApplication().applicationContext

val isBackgroundBlurOpened = XposedHelpers.callStaticMethod(notificationUtil, "isBackgroundBlurOpened", context)
if (isBackgroundBlurOpened == false) return@after

val mediaBg = it.thisObject as ImageView
mediaBg.background = null
mediaBg.setImageDrawable(null)
}
}

playerTwoCircleView?.methodFinder()?.filterByName("setPaintColor")?.first()?.createHook {
after {
val context = AndroidAppHelper.currentApplication().applicationContext

val isBackgroundBlurOpened = XposedHelpers.callStaticMethod(notificationUtil, "isBackgroundBlurOpened", context)
if (isBackgroundBlurOpened == false) return@after

it.result = null
}
}

}

} catch (t: Throwable) {
Expand Down
31 changes: 31 additions & 0 deletions app/src/main/kotlin/top/yukonga/mediaControlBlur/utils/AppUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ import android.content.res.Configuration
import android.graphics.BlendMode
import android.graphics.BlendModeColorFilter
import android.graphics.Color
import android.os.Environment
import java.io.BufferedReader
import java.io.File
import java.io.FileInputStream
import java.io.IOException
import java.io.InputStreamReader
import java.util.Properties

object AppUtils {

Expand All @@ -14,4 +21,28 @@ object AppUtils {

fun isDarkMode(context: Context): Boolean = context.resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK == Configuration.UI_MODE_NIGHT_YES

fun getProp(name: String): String {
var prop = getPropByStream(name)
if (prop.isEmpty()) prop = getPropByShell(name)
return prop
}

private fun getPropByStream(key: String): String {
return try {
val prop = Properties()
FileInputStream(File(Environment.getRootDirectory(), "build.prop")).use { prop.load(it) }
prop.getProperty(key, "")
} catch (_: Exception) {
""
}
}

private fun getPropByShell(propName: String): String {
return try {
val p = Runtime.getRuntime().exec("getprop $propName")
BufferedReader(InputStreamReader(p.inputStream), 1024).use { it.readLine() ?: "" }
} catch (ignore: IOException) {
""
}
}
}
Loading

0 comments on commit 4181c92

Please sign in to comment.