Skip to content

Commit 2ce2133

Browse files
committed
fix: When the object of sending lyrics is SystemUI, it will cause the problem that the icon cannot be obtained and the system interface will crash.
Closes: #1566
1 parent d4242b8 commit 2ce2133

1 file changed

Lines changed: 12 additions & 7 deletions

File tree

  • library/libhook/src/main/java/com/sevtinge/hyperceiler/libhook/appbase/systemui

library/libhook/src/main/java/com/sevtinge/hyperceiler/libhook/appbase/systemui/MusicBaseHook.kt

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ abstract class MusicBaseHook : BaseHook() {
7777
private const val SALT_MUSIC_PACKAGE = "com.salt.music"}
7878

7979
val context: Context by lazy { EzXposed.appContext }
80+
var songPackageName: String = "unknown"
8081

8182
private val nSize: Float by lazy {
8283
PrefsBridge.getInt("system_ui_statusbar_music_size_n", DEFAULT_FONT_SIZE).toFloat()
@@ -125,12 +126,15 @@ abstract class MusicBaseHook : BaseHook() {
125126

126127
private val receiver = object : ISuperLyricReceiver.Stub() {
127128
override fun onLyric(publisher: String, data: SuperLyricData) {
128-
runCatching { this@MusicBaseHook.onSuperLyric(publisher, data) }
129-
.onFailure { XposedLog.e(TAG, lpparam.packageName, it) }
129+
runCatching {
130+
songPackageName = publisher
131+
this@MusicBaseHook.onSuperLyric(publisher, data)
132+
}.onFailure { XposedLog.e(TAG, lpparam.packageName, it) }
130133
}
131134

132135
override fun onStop(publisher: String, data: SuperLyricData) {
133136
runCatching {
137+
songPackageName = "unknown"
134138
if (data.playbackState?.state == PlaybackState.STATE_BUFFERING) return
135139
this@MusicBaseHook.onStop()
136140
}.onFailure { XposedLog.e(TAG, lpparam.packageName, it) }
@@ -208,13 +212,13 @@ abstract class MusicBaseHook : BaseHook() {
208212
private fun resolveAppNameAndLaunchIntent(): Pair<String, Intent?> {
209213
return runCatching {
210214
val pm = context.packageManager
211-
val appInfo = pm.getApplicationInfo(context.packageName, 0)
215+
val appInfo = pm.getApplicationInfo(songPackageName, 0)
212216
val label = pm.getApplicationLabel(appInfo).toString()
213-
val launchIntent = pm.getLaunchIntentForPackage(context.packageName)
217+
val launchIntent = pm.getLaunchIntentForPackage(songPackageName)
214218
label to launchIntent
215219
}.getOrElse { e ->
216220
XposedLog.e(TAG, e)
217-
packageName to context.packageManager.getLaunchIntentForPackage(packageName)
221+
lpparam.packageName to context.packageManager.getLaunchIntentForPackage(lpparam.packageName)
218222
}
219223
}
220224

@@ -227,7 +231,7 @@ abstract class MusicBaseHook : BaseHook() {
227231
runCatching { context.packageManager.getActivityIcon(it).toBitmap() }.getOrNull()
228232
}
229233

230-
val isSaltMusic = context.packageName == SALT_MUSIC_PACKAGE
234+
val isSaltMusic = songPackageName == SALT_MUSIC_PACKAGE
231235
val primaryBitmap = when {
232236
isSaltMusic -> activityIconBitmap
233237
else -> baseBitmap ?: activityIconBitmap
@@ -260,7 +264,8 @@ abstract class MusicBaseHook : BaseHook() {
260264
*/
261265
private fun createIconsBundle(iconBundle: IconBundle): Bundle = Bundle().apply {
262266
putParcelable("miui.focus.icon", iconBundle.circularIcon)
263-
putParcelable("miui.focus.share_icon", Icon.createWithBitmap(iconBundle.activityIcon))
267+
val shareIconBitmap = iconBundle.activityIcon ?: iconBundle.primaryBitmap
268+
putParcelable("miui.focus.share_icon", Icon.createWithBitmap(shareIconBitmap))
264269
if (!isShowApp) putParcelable("miui.appIcon", iconBundle.primaryBitmap)
265270
}
266271

0 commit comments

Comments
 (0)