From 518853579fa7d466bac0289b87a1ad23c8bd660a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BD=99=E7=A9=BA?= <70465933+YuKongA@users.noreply.github.com> Date: Tue, 1 Oct 2024 23:21:27 +0800 Subject: [PATCH] Support Android15 --- .github/workflows/android.yml | 2 +- app/build.gradle.kts | 4 +- .../top/yukonga/mediaControlBlur/MainHook.kt | 81 ++++++++++--------- gradle/libs.versions.toml | 2 +- gradle/wrapper/gradle-wrapper.properties | 2 +- 5 files changed, 47 insertions(+), 44 deletions(-) diff --git a/.github/workflows/android.yml b/.github/workflows/android.yml index 08159ed..38470ee 100644 --- a/.github/workflows/android.yml +++ b/.github/workflows/android.yml @@ -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 diff --git a/app/build.gradle.kts b/app/build.gradle.kts index d7b6871..e6f9d1e 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -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()) } diff --git a/app/src/main/kotlin/top/yukonga/mediaControlBlur/MainHook.kt b/app/src/main/kotlin/top/yukonga/mediaControlBlur/MainHook.kt index bcae066..7a04826 100644 --- a/app/src/main/kotlin/top/yukonga/mediaControlBlur/MainHook.kt +++ b/app/src/main/kotlin/top/yukonga/mediaControlBlur/MainHook.kt @@ -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 @@ -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 @@ -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("action0") - val action1 = it.thisObject.objectHelper().getObjectOrNullAs("action1") - val action2 = it.thisObject.objectHelper().getObjectOrNullAs("action2") - val action3 = it.thisObject.objectHelper().getObjectOrNullAs("action3") - val action4 = it.thisObject.objectHelper().getObjectOrNullAs("action4") val seekBar = it.thisObject.objectHelper().getObjectOrNullAs("seekBar") val backgroundDrawable = GradientDrawable().apply { @@ -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 { @@ -125,10 +112,15 @@ class MainHook : IXposedHookLoadPackage { miuiMediaControlPanel?.methodFinder()?.filterByName("bindPlayer")?.first()?.createAfterHook { val context = it.thisObject.objectHelper().getObjectOrNullUntilSuperclassAs("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("action0") + val action1 = mMediaViewHolder.objectHelper().getObjectOrNullAs("action1") + val action2 = mMediaViewHolder.objectHelper().getObjectOrNullAs("action2") + val action3 = mMediaViewHolder.objectHelper().getObjectOrNullAs("action3") + val action4 = mMediaViewHolder.objectHelper().getObjectOrNullAs("action4") val titleText = mMediaViewHolder.objectHelper().getObjectOrNullAs("titleText") val artistText = mMediaViewHolder.objectHelper().getObjectOrNullAs("artistText") val seamlessIcon = mMediaViewHolder.objectHelper().getObjectOrNullAs("seamlessIcon") @@ -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) @@ -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) @@ -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 { @@ -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("mPaint1") @@ -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) { diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 90d449b..4028c18 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,5 +1,5 @@ [versions] -agp = "8.6.0" +agp = "8.6.1" ezXHelper = "2.2.0" kotlin = "2.0.20" xposed = "82" diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 9355b41..df97d72 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -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