feat(YouTube Music/Settings): add Open MicroG settings

This commit is contained in:
inotia00 2023-11-25 13:30:56 +09:00
parent 1f001b4ce6
commit 6633eb515f
4 changed files with 58 additions and 3 deletions

View File

@ -7,13 +7,23 @@ import app.revanced.patcher.patch.annotation.Patch
import app.revanced.patches.music.utils.microg.Constants.MUSIC_PACKAGE_NAME
import app.revanced.patches.music.utils.microg.Constants.SPOOFED_PACKAGE_NAME
import app.revanced.patches.music.utils.microg.Constants.SPOOFED_PACKAGE_SIGNATURE
import app.revanced.patches.music.utils.settings.SettingsPatch
import app.revanced.patches.shared.patch.packagename.PackageNamePatch
import app.revanced.util.enum.CategoryType
import app.revanced.util.microg.Constants.MICROG_PACKAGE_NAME
import app.revanced.util.microg.MicroGManifestHelper.addSpoofingMetadata
import app.revanced.util.microg.MicroGResourceHelper.patchManifest
import app.revanced.util.resources.MusicResourceHelper.addMicroGPreference
import app.revanced.util.resources.MusicResourceHelper.setMicroG
@Patch(dependencies = [PackageNamePatch::class])
@Patch(
dependencies = [
PackageNamePatch::class,
SettingsPatch::class
]
)
object MicroGResourcePatch : ResourcePatch() {
private const val MICROG_TARGET_CLASS = "org.microg.gms.ui.SettingsActivity"
override fun execute(context: ResourceContext) {
val packageName = PackageNamePatch.PackageNameYouTubeMusic
?: throw PatchException("Invalid package name.")
@ -35,5 +45,12 @@ object MicroGResourcePatch : ResourcePatch() {
context.setMicroG(packageName)
context.addMicroGPreference(
CategoryType.MISC.value,
"microg_settings",
MICROG_PACKAGE_NAME,
MICROG_TARGET_CLASS
)
}
}

View File

@ -10,16 +10,21 @@ internal object Constants {
*/
const val MICROG_VENDOR = "com.mgoogle"
/**
* microG package name
*/
const val MICROG_PACKAGE_NAME = "$MICROG_VENDOR.android.gms"
/**
* meta-data for microG package name spoofing on patched builds
*/
const val META_SPOOFED_PACKAGE_NAME = "$MICROG_VENDOR.android.gms.SPOOFED_PACKAGE_NAME"
const val META_SPOOFED_PACKAGE_NAME = "$MICROG_PACKAGE_NAME.SPOOFED_PACKAGE_NAME"
/**
* meta-data for microG package signature spoofing on patched builds
*/
const val META_SPOOFED_PACKAGE_SIGNATURE =
"$MICROG_VENDOR.android.gms.SPOOFED_PACKAGE_SIGNATURE"
"$MICROG_PACKAGE_NAME.SPOOFED_PACKAGE_SIGNATURE"
/**
* meta-data for microG package detection

View File

@ -107,6 +107,33 @@ internal object MusicResourceHelper {
)
}
internal fun ResourceContext.addMicroGPreference(
category: String,
key: String,
packageName: String,
targetClassName: String
) {
this.xmlEditor[YOUTUBE_MUSIC_SETTINGS_PATH].use { editor ->
val tags = editor.file.getElementsByTagName(YOUTUBE_MUSIC_PREFERENCE_SCREEN_TAG_NAME)
List(tags.length) { tags.item(it) as Element }
.filter { it.getAttribute("android:key").contains("revanced_settings_$category") }
.forEach {
it.adoptChild("Preference") {
setAttribute("android:title", "@string/$key" + "_title")
setAttribute("android:summary", "@string/$key" + "_summary")
this.adoptChild("intent") {
setAttribute("android:targetPackage", packageName)
setAttribute("android:data", key)
setAttribute(
"android:targetClass",
targetClassName
)
}
}
}
}
}
internal fun ResourceContext.addMusicPreference(
category: String,
key: String,

View File

@ -1,5 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="microg_not_installed_notice">Please install MicroG.</string>
<string name="microg_not_installed_warning">MicroG is not found.</string>
<string name="microg_not_running_warning">MicroG does not run in the background.</string>
<string name="microg_settings_summary">Enable cloud messaging settings to receive notifications.</string>
<string name="microg_settings_title">Open MicroG</string>
<string name="revanced_category_account">Account</string>
<string name="revanced_category_action_bar">Action Bar</string>
<string name="revanced_category_ads">Ads</string>