Skip to content

Commit

Permalink
Support Android15
Browse files Browse the repository at this point in the history
  • Loading branch information
YuKongA committed Oct 1, 2024
1 parent 7faef9b commit 5188535
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 44 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,5 @@ jobs:
{ echo -e 'New CI from MediaControl-BlurBg\n'; git log -$commit_count --pretty=format:"%h %s"; } > ${{ github.workspace }}/git_log
ESCAPED="$(cat ${{ github.workspace }}/git_log | gawk '{gsub(/[_*[\]()~`>#+=\|{}.!-]/,"\\\\\\\\&")}1' | sed -e 's|"|\\"|g' -e 's|^[0-9a-z]\+|__&__|' | hexdump -v -e '/1 "%02X"' | sed 's/\(..\)/%\1/g')"
cd ${{ github.workspace }}
curl -v "https://api.telegram.org/bot${BOT_TOKEN}/sendMediaGroup?chat_id=${CHANNEL_ID}&media=%5B%7B%22type%22%3A%22document%22%2C%22media%22%3A%22attach%3A%2F%2Frelease%22%7D%2C%7B%22type%22%3A%22document%22%2C%22media%22%3A%22attach%3A%2F%2Fdebug%22%2C%22caption%22%3A%22${ESCAPED}%22%2C%22parse_mode%22%3A%22MarkdownV2%22%7D%5D" -F release="@$RELEASE" -F debug="@$DEBUG"
curl -v "https://api.telegram.org/bot${BOT_TOKEN}/sendMediaGroup?chat_id=${CHANNEL_ID}&media=%5B%7B%22type%22%3A%22document%22%2C%22media%22%3A%22attach%3A%2F%2Frelease%22%7D%2C%7B%22type%22%3A%22document%22%2C%22media%22%3A%22attach%3A%2F%2Fdebug%22%2C%22caption%22%3A%22${ESCAPED}%22%2C%22parse_mode%22%3A%22MarkdownV2%22%7D%5D" -F release="@$RELEASE" -F debug="@$DEBUG"
fi
4 changes: 2 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ android {
applicationId = namespace
minSdk = 34
targetSdk = 35
versionCode = 2530
versionName = "2.5.3"
versionCode = 3000
versionName = "3.0.0"
}
val properties = Properties()
runCatching { properties.load(project.rootProject.file("local.properties").inputStream()) }
Expand Down
81 changes: 42 additions & 39 deletions app/src/main/kotlin/top/yukonga/mediaControlBlur/MainHook.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import android.app.AndroidAppHelper
import android.content.Context
import android.content.res.ColorStateList
import android.content.res.Resources
import android.database.ContentObserver
import android.graphics.Bitmap
import android.graphics.Canvas
import android.graphics.Color
Expand All @@ -19,9 +18,7 @@ import android.graphics.drawable.ClipDrawable
import android.graphics.drawable.GradientDrawable
import android.graphics.drawable.Icon
import android.graphics.drawable.LayerDrawable
import android.os.Handler
import android.os.Looper
import android.provider.Settings
import android.os.Build
import android.util.TypedValue
import android.view.Gravity
import android.view.ViewGroup
Expand Down Expand Up @@ -60,22 +57,33 @@ class MainHook : IXposedHookLoadPackage {
var lockScreenStatus: Boolean? = null
var darkModeStatus: Boolean? = null

val mediaViewHolder = loadClassOrNull("com.android.systemui.media.controls.models.player.MediaViewHolder")
val seekBarObserver = loadClassOrNull("com.android.systemui.media.controls.models.player.SeekBarObserver")
val mediaViewHolder = if (Build.VERSION.SDK_INT > 34) {
loadClassOrNull("com.android.systemui.media.controls.ui.view.MediaViewHolder")
} else {
loadClassOrNull("com.android.systemui.media.controls.models.player.MediaViewHolder")
}
val seekBarObserver = if (Build.VERSION.SDK_INT > 34) {
loadClassOrNull("com.android.systemui.media.controls.ui.binder.SeekBarObserver")
} else {
loadClassOrNull("com.android.systemui.media.controls.models.player.SeekBarObserver")
}
val notifUtil = if (Build.VERSION.SDK_INT > 34) {
loadClassOrNull("com.miui.systemui.notification.MiuiBaseNotifUtil")
} else {
loadClassOrNull("com.android.systemui.statusbar.notification.NotificationUtil")
}
val playerTwoCircleView =
if (Build.VERSION.SDK_INT > 34) {
loadClassOrNull("com.miui.systemui.notification.media.PlayerTwoCircleView")
} else {
loadClassOrNull("com.android.systemui.statusbar.notification.mediacontrol.PlayerTwoCircleView")
}
val miuiMediaControlPanel = loadClassOrNull("com.android.systemui.statusbar.notification.mediacontrol.MiuiMediaControlPanel")
val notificationUtil = loadClassOrNull("com.android.systemui.statusbar.notification.NotificationUtil")
val playerTwoCircleView = loadClassOrNull("com.android.systemui.statusbar.notification.mediacontrol.PlayerTwoCircleView")
val statusBarStateControllerImpl = loadClassOrNull("com.android.systemui.statusbar.StatusBarStateControllerImpl")
val miuiStubClass = loadClassOrNull("miui.stub.MiuiStub")
val miuiStubInstance = XposedHelpers.getStaticObjectField(miuiStubClass, "INSTANCE")

mediaViewHolder?.constructors?.first()?.createAfterHook {
val context = AndroidAppHelper.currentApplication().applicationContext
val action0 = it.thisObject.objectHelper().getObjectOrNullAs<ImageButton>("action0")
val action1 = it.thisObject.objectHelper().getObjectOrNullAs<ImageButton>("action1")
val action2 = it.thisObject.objectHelper().getObjectOrNullAs<ImageButton>("action2")
val action3 = it.thisObject.objectHelper().getObjectOrNullAs<ImageButton>("action3")
val action4 = it.thisObject.objectHelper().getObjectOrNullAs<ImageButton>("action4")
val seekBar = it.thisObject.objectHelper().getObjectOrNullAs<SeekBar>("seekBar")

val backgroundDrawable = GradientDrawable().apply {
Expand All @@ -95,27 +103,6 @@ class MainHook : IXposedHookLoadPackage {
thumb = thumbDrawable
progressDrawable = layerDrawable
}

fun updateColorFilter() {
val color = if (isDarkMode(context)) Color.WHITE else Color.BLACK
action0?.setColorFilter(color)
action1?.setColorFilter(color)
action2?.setColorFilter(color)
action3?.setColorFilter(color)
action4?.setColorFilter(color)
}

updateColorFilter()

val darkModeObserver = object : ContentObserver(Handler(Looper.getMainLooper())) {
override fun onChange(selfChange: Boolean) {
updateColorFilter()
}
}

context.contentResolver.registerContentObserver(
Settings.Secure.getUriFor("ui_night_mode"), false, darkModeObserver
)
}

seekBarObserver?.constructors?.first()?.createAfterHook {
Expand All @@ -125,10 +112,15 @@ class MainHook : IXposedHookLoadPackage {
miuiMediaControlPanel?.methodFinder()?.filterByName("bindPlayer")?.first()?.createAfterHook {
val context = it.thisObject.objectHelper().getObjectOrNullUntilSuperclassAs<Context>("mContext") ?: return@createAfterHook

val isBackgroundBlurOpened = XposedHelpers.callStaticMethod(notificationUtil, "isBackgroundBlurOpened", context) as Boolean
val isBackgroundBlurOpened = XposedHelpers.callStaticMethod(notifUtil, "isBackgroundBlurOpened", context) as Boolean

val mMediaViewHolder = it.thisObject.objectHelper().getObjectOrNullUntilSuperclass("mMediaViewHolder") ?: return@createAfterHook

val action0 = mMediaViewHolder.objectHelper().getObjectOrNullAs<ImageButton>("action0")
val action1 = mMediaViewHolder.objectHelper().getObjectOrNullAs<ImageButton>("action1")
val action2 = mMediaViewHolder.objectHelper().getObjectOrNullAs<ImageButton>("action2")
val action3 = mMediaViewHolder.objectHelper().getObjectOrNullAs<ImageButton>("action3")
val action4 = mMediaViewHolder.objectHelper().getObjectOrNullAs<ImageButton>("action4")
val titleText = mMediaViewHolder.objectHelper().getObjectOrNullAs<TextView>("titleText")
val artistText = mMediaViewHolder.objectHelper().getObjectOrNullAs<TextView>("artistText")
val seamlessIcon = mMediaViewHolder.objectHelper().getObjectOrNullAs<ImageView>("seamlessIcon")
Expand Down Expand Up @@ -173,6 +165,11 @@ class MainHook : IXposedHookLoadPackage {
elapsedTimeView?.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 11f)
totalTimeView?.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 11f)
if (!isBackgroundBlurOpened) {
action0?.setColorFilter(color)
action1?.setColorFilter(color)
action2?.setColorFilter(color)
action3?.setColorFilter(color)
action4?.setColorFilter(color)
titleText?.setTextColor(Color.WHITE)
seamlessIcon?.setColorFilter(Color.WHITE)
seekBar?.progressDrawable?.colorFilter = colorFilter(Color.WHITE)
Expand All @@ -181,6 +178,11 @@ class MainHook : IXposedHookLoadPackage {
elapsedTimeView?.setTextColor(grey)
totalTimeView?.setTextColor(grey)
titleText?.setTextColor(grey)
action0?.setColorFilter(color)
action1?.setColorFilter(color)
action2?.setColorFilter(color)
action3?.setColorFilter(color)
action4?.setColorFilter(color)
titleText?.setTextColor(color)
seamlessIcon?.setColorFilter(color)
seekBar?.progressDrawable?.colorFilter = colorFilter(color)
Expand All @@ -196,7 +198,6 @@ class MainHook : IXposedHookLoadPackage {
val getLazyClass = XposedHelpers.callMethod(mStatusBarStateController, "get")
val getState = XposedHelpers.callMethod(getLazyClass, "getState")


(it.thisObject as ImageView).setMiViewBlurMode(BACKGROUND)
(it.thisObject as ImageView).setBlurRoundRect(getNotificationElementRoundRect(context))
(it.thisObject as ImageView).apply {
Expand All @@ -223,7 +224,7 @@ class MainHook : IXposedHookLoadPackage {
playerTwoCircleView?.methodFinder()?.filterByName("onDraw")?.first()?.createBeforeHook {
val context = AndroidAppHelper.currentApplication().applicationContext

val isBackgroundBlurOpened = XposedHelpers.callStaticMethod(notificationUtil, "isBackgroundBlurOpened", context) as Boolean
val isBackgroundBlurOpened = XposedHelpers.callStaticMethod(notifUtil, "isBackgroundBlurOpened", context) as Boolean
if (!isBackgroundBlurOpened) return@createBeforeHook

val mPaint1 = it.thisObject.objectHelper().getObjectOrNullAs<Paint>("mPaint1")
Expand All @@ -240,9 +241,11 @@ class MainHook : IXposedHookLoadPackage {
playerTwoCircleView?.methodFinder()?.filterByName("setBackground")?.first()?.createBeforeHook {
val context = AndroidAppHelper.currentApplication().applicationContext

val isBackgroundBlurOpened = XposedHelpers.callStaticMethod(notificationUtil, "isBackgroundBlurOpened", context) as Boolean
val isBackgroundBlurOpened = XposedHelpers.callStaticMethod(notifUtil, "isBackgroundBlurOpened", context) as Boolean
if (!isBackgroundBlurOpened) return@createBeforeHook

(it.thisObject as ImageView).background = null

it.result = null
}
} catch (t: Throwable) {
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[versions]
agp = "8.6.0"
agp = "8.6.1"
ezXHelper = "2.2.0"
kotlin = "2.0.20"
xposed = "82"
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down

0 comments on commit 5188535

Please sign in to comment.