feat(Custom branding): Add in-app settings to change icon and name (#6059)
Co-authored-by: LisoUseInAIKyrios <118716522+LisoUseInAIKyrios@users.noreply.github.com>
This commit is contained in:
co-authored by
LisoUseInAIKyrios
parent
64d22a9c31
commit
a50f3b5177
+14
-16
@@ -4,6 +4,10 @@ import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWith
|
||||
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
|
||||
import app.revanced.patcher.patch.bytecodePatch
|
||||
import app.revanced.patcher.util.smali.ExternalLabel
|
||||
import app.revanced.patches.music.misc.gms.Constants.MUSIC_MAIN_ACTIVITY_NAME
|
||||
import app.revanced.patches.music.misc.gms.Constants.MUSIC_PACKAGE_NAME
|
||||
import app.revanced.patches.music.misc.gms.musicActivityOnCreateFingerprint
|
||||
import app.revanced.patches.music.misc.settings.PreferenceScreen
|
||||
import app.revanced.patches.shared.layout.branding.baseCustomBrandingPatch
|
||||
import app.revanced.patches.shared.misc.mapping.get
|
||||
import app.revanced.patches.shared.misc.mapping.resourceMappingPatch
|
||||
@@ -50,24 +54,18 @@ private val disableSplashAnimationPatch = bytecodePatch {
|
||||
}
|
||||
}
|
||||
|
||||
private const val APP_NAME = "YT Music ReVanced"
|
||||
|
||||
@Suppress("unused")
|
||||
val customBrandingPatch = baseCustomBrandingPatch(
|
||||
defaultAppName = APP_NAME,
|
||||
appNameValues = mapOf(
|
||||
"YT Music ReVanced" to APP_NAME,
|
||||
"Music ReVanced" to "Music ReVanced",
|
||||
"Music" to "Music",
|
||||
"YT Music" to "YT Music",
|
||||
),
|
||||
resourceFolder = "custom-branding/music",
|
||||
iconResourceFileNames = arrayOf(
|
||||
"adaptiveproduct_youtube_music_2024_q4_background_color_108",
|
||||
"adaptiveproduct_youtube_music_2024_q4_foreground_color_108",
|
||||
"ic_launcher_release",
|
||||
),
|
||||
monochromeIconFileNames = arrayOf("ic_app_icons_themed_youtube_music.xml"),
|
||||
addResourcePatchName = "music",
|
||||
originalLauncherIconName = "ic_launcher_release",
|
||||
originalAppName = "@string/app_launcher_name",
|
||||
originalAppPackageName = MUSIC_PACKAGE_NAME,
|
||||
copyExistingIntentsToAliases = false,
|
||||
numberOfPresetAppNames = 5,
|
||||
mainActivityOnCreateFingerprint = musicActivityOnCreateFingerprint,
|
||||
mainActivityName = MUSIC_MAIN_ACTIVITY_NAME,
|
||||
activityAliasNameWithIntents = MUSIC_MAIN_ACTIVITY_NAME,
|
||||
preferenceScreen = PreferenceScreen.GENERAL,
|
||||
|
||||
block = {
|
||||
dependsOn(disableSplashAnimationPatch)
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package app.revanced.patches.music.misc.gms
|
||||
|
||||
object Constants {
|
||||
internal const val MUSIC_MAIN_ACTIVITY_NAME = "com.google.android.apps.youtube.music.activities.MusicActivity"
|
||||
|
||||
internal const val REVANCED_MUSIC_PACKAGE_NAME = "app.revanced.android.apps.youtube.music"
|
||||
internal const val MUSIC_PACKAGE_NAME = "com.google.android.apps.youtube.music"
|
||||
}
|
||||
|
||||
+324
-110
@@ -1,173 +1,387 @@
|
||||
package app.revanced.patches.shared.layout.branding
|
||||
|
||||
import app.revanced.patcher.Fingerprint
|
||||
import app.revanced.patcher.extensions.InstructionExtensions.addInstruction
|
||||
import app.revanced.patcher.patch.PatchException
|
||||
import app.revanced.patcher.patch.ResourcePatch
|
||||
import app.revanced.patcher.patch.ResourcePatchBuilder
|
||||
import app.revanced.patcher.patch.ResourcePatchContext
|
||||
import app.revanced.patcher.patch.bytecodePatch
|
||||
import app.revanced.patcher.patch.resourcePatch
|
||||
import app.revanced.patcher.patch.stringOption
|
||||
import app.revanced.patches.all.misc.packagename.setOrGetFallbackPackageName
|
||||
import app.revanced.patches.all.misc.resources.addResources
|
||||
import app.revanced.patches.all.misc.resources.addResourcesPatch
|
||||
import app.revanced.patches.shared.misc.settings.preference.BasePreferenceScreen
|
||||
import app.revanced.patches.shared.misc.settings.preference.ListPreference
|
||||
import app.revanced.util.ResourceGroup
|
||||
import app.revanced.util.Utils.trimIndentMultiline
|
||||
import app.revanced.util.copyResources
|
||||
import app.revanced.util.findElementByAttributeValueOrThrow
|
||||
import app.revanced.util.removeFromParent
|
||||
import app.revanced.util.returnEarly
|
||||
import org.w3c.dom.Element
|
||||
import org.w3c.dom.Node
|
||||
import org.w3c.dom.NodeList
|
||||
import java.io.File
|
||||
import java.nio.file.Files
|
||||
import java.util.logging.Logger
|
||||
|
||||
private const val REVANCED_ICON = "ReVanced*Logo" // Can never be a valid path.
|
||||
|
||||
internal val mipmapDirectories = arrayOf(
|
||||
private val mipmapDirectories = arrayOf(
|
||||
// Target app does not have ldpi icons.
|
||||
"mdpi",
|
||||
"hdpi",
|
||||
"xhdpi",
|
||||
"xxhdpi",
|
||||
"xxxhdpi",
|
||||
).map { "mipmap-$it" }.toTypedArray()
|
||||
"mipmap-mdpi",
|
||||
"mipmap-hdpi",
|
||||
"mipmap-xhdpi",
|
||||
"mipmap-xxhdpi",
|
||||
"mipmap-xxxhdpi"
|
||||
)
|
||||
|
||||
private fun formatResourceFileList(resourceNames: Array<String>) = resourceNames.joinToString("\n") { "- $it" }
|
||||
private val iconStyleNames = arrayOf(
|
||||
"rounded",
|
||||
"minimal",
|
||||
"scaled"
|
||||
)
|
||||
|
||||
/**
|
||||
* Attempts to fix unescaped and invalid characters not allowed for an Android app name.
|
||||
*/
|
||||
private fun escapeAppName(name: String): String? {
|
||||
// Remove ASCII control characters.
|
||||
val cleanedName = name.filter { it.code >= 32 }
|
||||
private const val ORIGINAL_USER_ICON_STYLE_NAME = "original"
|
||||
private const val CUSTOM_USER_ICON_STYLE_NAME = "custom"
|
||||
|
||||
// Replace invalid XML characters with escaped equivalents.
|
||||
val escapedName = cleanedName
|
||||
.replace("&", "&") // Must be first to avoid double-escaping.
|
||||
.replace("<", "<")
|
||||
.replace(">", ">")
|
||||
.replace(Regex("(?<!&)\""), """)
|
||||
private const val LAUNCHER_RESOURCE_NAME_PREFIX = "revanced_launcher_"
|
||||
private const val LAUNCHER_ADAPTIVE_BACKGROUND_PREFIX = "revanced_adaptive_background_"
|
||||
private const val LAUNCHER_ADAPTIVE_FOREGROUND_PREFIX = "revanced_adaptive_foreground_"
|
||||
private const val LAUNCHER_ADAPTIVE_MONOCHROME_PREFIX = "revanced_adaptive_monochrome_"
|
||||
|
||||
// Trim empty spacing.
|
||||
val trimmed = escapedName.trim()
|
||||
private val USER_CUSTOM_ADAPTIVE_FILE_NAMES = arrayOf(
|
||||
"$LAUNCHER_ADAPTIVE_BACKGROUND_PREFIX$CUSTOM_USER_ICON_STYLE_NAME.png",
|
||||
"$LAUNCHER_ADAPTIVE_FOREGROUND_PREFIX$CUSTOM_USER_ICON_STYLE_NAME.png"
|
||||
)
|
||||
|
||||
return trimmed.ifBlank { null }
|
||||
}
|
||||
private const val USER_CUSTOM_MONOCHROME_NAME = "$LAUNCHER_ADAPTIVE_MONOCHROME_PREFIX$CUSTOM_USER_ICON_STYLE_NAME.xml"
|
||||
|
||||
internal const val EXTENSION_CLASS_DESCRIPTOR = "Lapp/revanced/extension/shared/patches/CustomBrandingPatch;"
|
||||
|
||||
/**
|
||||
* Shared custom branding patch for YouTube and YT Music.
|
||||
*/
|
||||
internal fun baseCustomBrandingPatch(
|
||||
defaultAppName: String,
|
||||
appNameValues: Map<String, String>,
|
||||
resourceFolder: String,
|
||||
iconResourceFileNames: Array<String>,
|
||||
monochromeIconFileNames: Array<String>,
|
||||
block: ResourcePatchBuilder.() -> Unit = {},
|
||||
addResourcePatchName: String,
|
||||
originalLauncherIconName: String,
|
||||
originalAppName: String,
|
||||
originalAppPackageName: String,
|
||||
copyExistingIntentsToAliases: Boolean,
|
||||
numberOfPresetAppNames: Int,
|
||||
mainActivityOnCreateFingerprint: Fingerprint,
|
||||
mainActivityName: String,
|
||||
activityAliasNameWithIntents: String,
|
||||
preferenceScreen: BasePreferenceScreen.Screen,
|
||||
block: ResourcePatchBuilder.() -> Unit,
|
||||
executeBlock: ResourcePatchContext.() -> Unit = {}
|
||||
): ResourcePatch = resourcePatch(
|
||||
name = "Custom branding",
|
||||
description = "Applies a custom app name and icon. Defaults to \"$defaultAppName\" and the ReVanced logo.",
|
||||
use = false,
|
||||
description = "Adds options to change the app icon and app name. " +
|
||||
"Branding cannot be changed for mounted (root) installations."
|
||||
) {
|
||||
val iconResourceFileNamesPng = iconResourceFileNames.map { "$it.png" }.toTypedArray<String>()
|
||||
|
||||
val appName by stringOption(
|
||||
key = "appName",
|
||||
default = defaultAppName,
|
||||
values = appNameValues,
|
||||
val customName by stringOption(
|
||||
key = "customName",
|
||||
title = "App name",
|
||||
description = "The name of the app.",
|
||||
description = "Custom app name."
|
||||
)
|
||||
|
||||
val iconPath by stringOption(
|
||||
key = "iconPath",
|
||||
default = REVANCED_ICON,
|
||||
values = mapOf("ReVanced Logo" to REVANCED_ICON),
|
||||
title = "App icon",
|
||||
val customIcon by stringOption(
|
||||
key = "customIcon",
|
||||
title = "Custom icon",
|
||||
description = """
|
||||
The icon to apply to the app.
|
||||
Folder with images to use as a custom icon.
|
||||
|
||||
If a path to a folder is provided, the folder must contain the following folders:
|
||||
|
||||
${formatResourceFileList(mipmapDirectories)}
|
||||
|
||||
Each of these folders must contain the following files:
|
||||
|
||||
${formatResourceFileList(iconResourceFileNamesPng)}
|
||||
The folder must contain one or more of the following folders, depending on the DPI of the device:
|
||||
${mipmapDirectories.joinToString("\n") { "- $it" }}
|
||||
|
||||
Optionally, a 'drawable' folder with the monochrome icon files:
|
||||
|
||||
${formatResourceFileList(monochromeIconFileNames)}
|
||||
""".trimIndentMultiline(),
|
||||
Each of the folders must contain all of the following files:
|
||||
${USER_CUSTOM_ADAPTIVE_FILE_NAMES.joinToString("\n")}
|
||||
|
||||
Optionally, the path can contain a 'drawable' folder with the monochrome icon file:
|
||||
$USER_CUSTOM_MONOCHROME_NAME
|
||||
""".trimIndentMultiline()
|
||||
)
|
||||
|
||||
block()
|
||||
|
||||
dependsOn(
|
||||
addResourcesPatch,
|
||||
bytecodePatch {
|
||||
execute {
|
||||
mainActivityOnCreateFingerprint.method.addInstruction(
|
||||
0,
|
||||
"invoke-static { }, $EXTENSION_CLASS_DESCRIPTOR->setBranding()V"
|
||||
)
|
||||
|
||||
numberOfPresetAppNamesExtensionFingerprint.method.returnEarly(numberOfPresetAppNames)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
finalize {
|
||||
val useCustomName = customName != null
|
||||
val useCustomIcon = customIcon != null
|
||||
|
||||
if (setOrGetFallbackPackageName(originalAppPackageName) == originalAppPackageName) {
|
||||
if (useCustomName || useCustomIcon) {
|
||||
Logger.getLogger(this::class.java.name).warning(
|
||||
"Custom branding does not work with root installation. No changes applied."
|
||||
)
|
||||
}
|
||||
return@finalize
|
||||
}
|
||||
|
||||
preferenceScreen.addPreferences(
|
||||
if (useCustomName) {
|
||||
ListPreference(
|
||||
key = "revanced_custom_branding_name",
|
||||
entriesKey = "revanced_custom_branding_name_custom_entries",
|
||||
entryValuesKey = "revanced_custom_branding_name_custom_entry_values"
|
||||
)
|
||||
} else {
|
||||
ListPreference("revanced_custom_branding_name")
|
||||
},
|
||||
if (useCustomIcon) {
|
||||
ListPreference(
|
||||
key = "revanced_custom_branding_icon",
|
||||
entriesKey = "revanced_custom_branding_icon_custom_entries",
|
||||
entryValuesKey = "revanced_custom_branding_icon_custom_entry_values"
|
||||
)
|
||||
} else {
|
||||
ListPreference("revanced_custom_branding_icon")
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
execute {
|
||||
val mipmapIconResourceGroups = mipmapDirectories.map { directory ->
|
||||
ResourceGroup(
|
||||
directory,
|
||||
*iconResourceFileNamesPng,
|
||||
addResources("shared", "layout.branding.baseCustomBrandingPatch")
|
||||
addResources(addResourcePatchName, "layout.branding.customBrandingPatch")
|
||||
|
||||
val useCustomName = customName != null
|
||||
val useCustomIcon = customIcon != null
|
||||
|
||||
iconStyleNames.forEach { style ->
|
||||
copyResources(
|
||||
"custom-branding",
|
||||
ResourceGroup(
|
||||
"drawable",
|
||||
"$LAUNCHER_ADAPTIVE_BACKGROUND_PREFIX$style.xml",
|
||||
"$LAUNCHER_ADAPTIVE_FOREGROUND_PREFIX$style.xml",
|
||||
"$LAUNCHER_ADAPTIVE_MONOCHROME_PREFIX$style.xml"
|
||||
),
|
||||
ResourceGroup(
|
||||
"mipmap-anydpi",
|
||||
"$LAUNCHER_RESOURCE_NAME_PREFIX$style.xml"
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
val iconPathTrimmed = iconPath!!.trim()
|
||||
if (iconPathTrimmed == REVANCED_ICON) {
|
||||
// Replace mipmap icons with preset patch icons.
|
||||
mipmapIconResourceGroups.forEach { groupResources ->
|
||||
copyResources(resourceFolder, groupResources)
|
||||
}
|
||||
// Copy template user icon, because the aliases must be added even if no user icon is provided.
|
||||
copyResources(
|
||||
"custom-branding",
|
||||
ResourceGroup(
|
||||
"mipmap-anydpi",
|
||||
"$LAUNCHER_RESOURCE_NAME_PREFIX$CUSTOM_USER_ICON_STYLE_NAME.xml",
|
||||
),
|
||||
ResourceGroup(
|
||||
"drawable",
|
||||
"$LAUNCHER_ADAPTIVE_MONOCHROME_PREFIX$CUSTOM_USER_ICON_STYLE_NAME.xml",
|
||||
)
|
||||
)
|
||||
|
||||
// Replace monochrome icons.
|
||||
monochromeIconFileNames.forEach { fileName ->
|
||||
copyResources(
|
||||
resourceFolder,
|
||||
ResourceGroup("drawable", fileName)
|
||||
// Copy template icon png files.
|
||||
mipmapDirectories.forEach { dpi ->
|
||||
copyResources(
|
||||
"custom-branding",
|
||||
ResourceGroup(
|
||||
dpi,
|
||||
"$LAUNCHER_ADAPTIVE_BACKGROUND_PREFIX$CUSTOM_USER_ICON_STYLE_NAME.png",
|
||||
"$LAUNCHER_ADAPTIVE_FOREGROUND_PREFIX$CUSTOM_USER_ICON_STYLE_NAME.png",
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
if (useCustomIcon) {
|
||||
// Copy user provided files
|
||||
val iconPathFile = File(customIcon!!.trim())
|
||||
|
||||
if (!iconPathFile.exists()) {
|
||||
throw PatchException(
|
||||
"The custom icon path cannot be found: " + iconPathFile.absolutePath
|
||||
)
|
||||
}
|
||||
} else {
|
||||
val filePath = File(iconPathTrimmed)
|
||||
|
||||
if (!iconPathFile.isDirectory) {
|
||||
throw PatchException(
|
||||
"The custom icon path must be a folder: " + iconPathFile.absolutePath
|
||||
)
|
||||
}
|
||||
|
||||
val sourceFolders = iconPathFile.listFiles { file -> file.isDirectory }
|
||||
?: throw PatchException("The custom icon path contains no subfolders: " +
|
||||
iconPathFile.absolutePath)
|
||||
|
||||
val resourceDirectory = get("res")
|
||||
var copiedFiles = false
|
||||
|
||||
// Replace
|
||||
mipmapIconResourceGroups.forEach { groupResources ->
|
||||
val groupResourceDirectoryName = groupResources.resourceDirectoryName
|
||||
val fromDirectory = filePath.resolve(groupResourceDirectoryName)
|
||||
val toDirectory = resourceDirectory.resolve(groupResourceDirectoryName)
|
||||
// For each source folder, copy the files to the target resource directories.
|
||||
sourceFolders.forEach { dpiSourceFolder ->
|
||||
val targetDpiFolder = resourceDirectory.resolve(dpiSourceFolder.name)
|
||||
if (!targetDpiFolder.exists()) return@forEach
|
||||
|
||||
groupResources.resources.forEach { iconFileName ->
|
||||
Files.write(
|
||||
toDirectory.resolve(iconFileName).toPath(),
|
||||
fromDirectory.resolve(iconFileName).readBytes(),
|
||||
)
|
||||
val customFiles = dpiSourceFolder.listFiles { file ->
|
||||
file.isFile && file.name in USER_CUSTOM_ADAPTIVE_FILE_NAMES
|
||||
}!!
|
||||
|
||||
if (customFiles.size > 0 && customFiles.size != USER_CUSTOM_ADAPTIVE_FILE_NAMES.size) {
|
||||
throw PatchException("Must include all required icon files " +
|
||||
"but only found " + customFiles.map { it.name })
|
||||
}
|
||||
|
||||
customFiles.forEach { imgSourceFile ->
|
||||
val imgTargetFile = targetDpiFolder.resolve(imgSourceFile.name)
|
||||
imgSourceFile.copyTo(target = imgTargetFile, overwrite = true)
|
||||
|
||||
copiedFiles = true
|
||||
}
|
||||
}
|
||||
|
||||
// Copy all monochrome icons if provided.
|
||||
monochromeIconFileNames.forEach { fileName ->
|
||||
val replacementMonochrome = filePath.resolve("drawable").resolve(fileName)
|
||||
if (replacementMonochrome.exists()) {
|
||||
Files.write(
|
||||
resourceDirectory.resolve("drawable").resolve(fileName).toPath(),
|
||||
replacementMonochrome.readBytes(),
|
||||
)
|
||||
}
|
||||
// Copy monochrome if it provided.
|
||||
val monochromeRelativePath = "drawable/$USER_CUSTOM_MONOCHROME_NAME"
|
||||
val monochromeFile = iconPathFile.resolve(monochromeRelativePath)
|
||||
if (monochromeFile.exists()) {
|
||||
monochromeFile.copyTo(
|
||||
target = resourceDirectory.resolve(monochromeRelativePath),
|
||||
overwrite = true
|
||||
)
|
||||
copiedFiles = true
|
||||
}
|
||||
|
||||
if (!copiedFiles) {
|
||||
throw PatchException("Could not find any replacement images in " +
|
||||
"patch option path: " + iconPathFile.absolutePath)
|
||||
}
|
||||
}
|
||||
|
||||
// Change the app name.
|
||||
escapeAppName(appName!!)?.let { escapedAppName ->
|
||||
val newValue = "android:label=\"$escapedAppName\""
|
||||
document("AndroidManifest.xml").use { document ->
|
||||
// Create launch aliases that can be programmatically selected in app.
|
||||
fun createAlias(
|
||||
aliasName: String,
|
||||
iconMipmapName: String,
|
||||
appNameIndex: Int,
|
||||
useCustomName: Boolean,
|
||||
enabled: Boolean,
|
||||
intents: NodeList
|
||||
): Element {
|
||||
val label = if (useCustomName) {
|
||||
if (customName == null) {
|
||||
"Custom" // Dummy text, and normally cannot be seen.
|
||||
} else {
|
||||
customName!!
|
||||
}
|
||||
} else if (appNameIndex == 1) {
|
||||
// Indexing starts at 1.
|
||||
originalAppName
|
||||
} else {
|
||||
"@string/revanced_custom_branding_name_entry_$appNameIndex"
|
||||
}
|
||||
val alias = document.createElement("activity-alias")
|
||||
alias.setAttribute("android:name", aliasName)
|
||||
alias.setAttribute("android:enabled", enabled.toString())
|
||||
alias.setAttribute("android:exported", "true")
|
||||
alias.setAttribute("android:icon", "@mipmap/$iconMipmapName")
|
||||
alias.setAttribute("android:label", label)
|
||||
alias.setAttribute("android:targetActivity", mainActivityName)
|
||||
|
||||
val manifest = get("AndroidManifest.xml")
|
||||
val original = manifest.readText()
|
||||
val replacement = original
|
||||
// YouTube
|
||||
.replace("android:label=\"@string/application_name\"", newValue)
|
||||
// YT Music
|
||||
.replace("android:label=\"@string/app_launcher_name\"", newValue)
|
||||
// Copy all intents from the original alias so long press actions still work.
|
||||
if (copyExistingIntentsToAliases) {
|
||||
for (i in 0 until intents.length) {
|
||||
alias.appendChild(
|
||||
intents.item(i).cloneNode(true)
|
||||
)
|
||||
}
|
||||
} else {
|
||||
val intentFilter = document.createElement("intent-filter").apply {
|
||||
val action = document.createElement("action")
|
||||
action.setAttribute("android:name", "android.intent.action.MAIN")
|
||||
appendChild(action)
|
||||
|
||||
if (original == replacement) {
|
||||
Logger.getLogger(this::class.java.name).warning(
|
||||
"Could not replace manifest app name"
|
||||
val category = document.createElement("category")
|
||||
category.setAttribute("android:name", "android.intent.category.LAUNCHER")
|
||||
appendChild(category)
|
||||
}
|
||||
alias.appendChild(intentFilter)
|
||||
}
|
||||
|
||||
return alias
|
||||
}
|
||||
|
||||
val intentFilters = document.childNodes.findElementByAttributeValueOrThrow(
|
||||
"android:name",
|
||||
activityAliasNameWithIntents
|
||||
).childNodes
|
||||
|
||||
val application = document.getElementsByTagName("application").item(0) as Element
|
||||
|
||||
for (appNameIndex in 1 .. numberOfPresetAppNames) {
|
||||
fun aliasName(name: String): String = ".revanced_" + name + '_' + appNameIndex
|
||||
|
||||
val useCustomNameLabel = (useCustomName && appNameIndex == numberOfPresetAppNames)
|
||||
|
||||
// Original icon.
|
||||
application.appendChild(
|
||||
createAlias(
|
||||
aliasName = aliasName(ORIGINAL_USER_ICON_STYLE_NAME),
|
||||
iconMipmapName = originalLauncherIconName,
|
||||
appNameIndex = appNameIndex,
|
||||
useCustomName = useCustomNameLabel,
|
||||
enabled = (appNameIndex == 1),
|
||||
intentFilters
|
||||
)
|
||||
)
|
||||
|
||||
// Bundled icons.
|
||||
iconStyleNames.forEachIndexed { index, style ->
|
||||
application.appendChild(
|
||||
createAlias(
|
||||
aliasName = aliasName(style),
|
||||
iconMipmapName = LAUNCHER_RESOURCE_NAME_PREFIX + style,
|
||||
appNameIndex = appNameIndex,
|
||||
useCustomName = useCustomNameLabel,
|
||||
enabled = false,
|
||||
intentFilters
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
// User provided custom icon.
|
||||
//
|
||||
// Must add all aliases even if the user did not provide a custom icon of their own.
|
||||
// This is because if the user installs with an option, then repatches without the option,
|
||||
// the alias must still exist because if it was previously enabled and then it's removed
|
||||
// the app will become broken and cannot launch. Even if the app data is cleared
|
||||
// it still cannot be launched and the only fix is to uninstall the app.
|
||||
// To prevent this, always include all aliases and use dummy data if needed.
|
||||
application.appendChild(
|
||||
createAlias(
|
||||
aliasName = aliasName(CUSTOM_USER_ICON_STYLE_NAME),
|
||||
iconMipmapName = LAUNCHER_RESOURCE_NAME_PREFIX + CUSTOM_USER_ICON_STYLE_NAME,
|
||||
appNameIndex = appNameIndex,
|
||||
useCustomName = useCustomNameLabel,
|
||||
enabled = false,
|
||||
intentFilters
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
manifest.writeText(replacement)
|
||||
// Remove the main action from the original alias, otherwise two apps icons
|
||||
// can be shown in the launcher. Can only be done after adding the new aliases.
|
||||
intentFilters.findElementByAttributeValueOrThrow(
|
||||
"android:name",
|
||||
"android.intent.action.MAIN"
|
||||
).removeFromParent()
|
||||
}
|
||||
|
||||
executeBlock() // Must be after the main code to rename the new icons for YouTube 19.34+.
|
||||
executeBlock()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
package app.revanced.patches.shared.layout.branding
|
||||
|
||||
import app.revanced.patcher.fingerprint
|
||||
import com.android.tools.smali.dexlib2.AccessFlags
|
||||
|
||||
internal val numberOfPresetAppNamesExtensionFingerprint = fingerprint {
|
||||
accessFlags(AccessFlags.PRIVATE, AccessFlags.STATIC)
|
||||
returns("I")
|
||||
parameters()
|
||||
custom { method, classDef ->
|
||||
method.name == "numberOfPresetAppNames" && classDef.type == EXTENSION_CLASS_DESCRIPTOR
|
||||
}
|
||||
}
|
||||
@@ -79,7 +79,7 @@ internal val darkThemeBackgroundColorOption = stringOption(
|
||||
*/
|
||||
internal fun baseThemePatch(
|
||||
extensionClassDescriptor: String,
|
||||
block: BytecodePatchBuilder.() -> Unit = {},
|
||||
block: BytecodePatchBuilder.() -> Unit,
|
||||
executeBlock: BytecodePatchContext.() -> Unit = {}
|
||||
) = bytecodePatch(
|
||||
name = "Theme",
|
||||
|
||||
@@ -1,16 +1,11 @@
|
||||
package app.revanced.patches.shared.misc.gms
|
||||
|
||||
import app.revanced.patcher.fingerprint
|
||||
import app.revanced.patches.shared.misc.gms.EXTENSION_CLASS_DESCRIPTOR
|
||||
import com.android.tools.smali.dexlib2.AccessFlags
|
||||
|
||||
const val GET_GMS_CORE_VENDOR_GROUP_ID_METHOD_NAME = "getGmsCoreVendorGroupId"
|
||||
|
||||
internal val gmsCoreSupportFingerprint = fingerprint {
|
||||
custom { _, classDef ->
|
||||
classDef.endsWith("GmsCoreSupport;")
|
||||
}
|
||||
}
|
||||
|
||||
internal val googlePlayUtilityFingerprint = fingerprint {
|
||||
accessFlags(AccessFlags.PUBLIC, AccessFlags.STATIC)
|
||||
returns("I")
|
||||
@@ -28,3 +23,21 @@ internal val serviceCheckFingerprint = fingerprint {
|
||||
parameters("L", "I")
|
||||
strings("Google Play Services not available")
|
||||
}
|
||||
|
||||
internal val gmsCoreSupportFingerprint = fingerprint {
|
||||
accessFlags(AccessFlags.PRIVATE, AccessFlags.STATIC)
|
||||
returns("Ljava/lang/String;")
|
||||
parameters()
|
||||
custom { method, classDef ->
|
||||
method.name == "getGmsCoreVendorGroupId" && classDef.type == EXTENSION_CLASS_DESCRIPTOR
|
||||
}
|
||||
}
|
||||
|
||||
internal val originalPackageNameExtensionFingerprint = fingerprint {
|
||||
accessFlags(AccessFlags.PRIVATE, AccessFlags.STATIC)
|
||||
returns("Ljava/lang/String;")
|
||||
parameters()
|
||||
custom { methodDef, classDef ->
|
||||
methodDef.name == "getOriginalPackageName" && classDef.type == EXTENSION_CLASS_DESCRIPTOR
|
||||
}
|
||||
}
|
||||
|
||||
+23
-13
@@ -1,10 +1,18 @@
|
||||
package app.revanced.patches.shared.misc.gms
|
||||
|
||||
import app.revanced.patcher.Fingerprint
|
||||
import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
|
||||
import app.revanced.patcher.extensions.InstructionExtensions.addInstruction
|
||||
import app.revanced.patcher.extensions.InstructionExtensions.instructions
|
||||
import app.revanced.patcher.extensions.InstructionExtensions.replaceInstruction
|
||||
import app.revanced.patcher.patch.*
|
||||
import app.revanced.patcher.patch.BytecodePatchBuilder
|
||||
import app.revanced.patcher.patch.BytecodePatchContext
|
||||
import app.revanced.patcher.patch.Option
|
||||
import app.revanced.patcher.patch.Patch
|
||||
import app.revanced.patcher.patch.ResourcePatchBuilder
|
||||
import app.revanced.patcher.patch.ResourcePatchContext
|
||||
import app.revanced.patcher.patch.bytecodePatch
|
||||
import app.revanced.patcher.patch.resourcePatch
|
||||
import app.revanced.patcher.patch.stringOption
|
||||
import app.revanced.patches.all.misc.packagename.changePackageNamePatch
|
||||
import app.revanced.patches.all.misc.packagename.setOrGetFallbackPackageName
|
||||
import app.revanced.patches.all.misc.resources.addResources
|
||||
@@ -12,7 +20,8 @@ import app.revanced.patches.all.misc.resources.addResourcesPatch
|
||||
import app.revanced.patches.shared.misc.gms.Constants.ACTIONS
|
||||
import app.revanced.patches.shared.misc.gms.Constants.AUTHORITIES
|
||||
import app.revanced.patches.shared.misc.gms.Constants.PERMISSIONS
|
||||
import app.revanced.util.*
|
||||
import app.revanced.util.getReference
|
||||
import app.revanced.util.returnEarly
|
||||
import com.android.tools.smali.dexlib2.Opcode
|
||||
import com.android.tools.smali.dexlib2.builder.instruction.BuilderInstruction21c
|
||||
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
|
||||
@@ -23,6 +32,8 @@ import com.android.tools.smali.dexlib2.util.MethodUtil
|
||||
import org.w3c.dom.Element
|
||||
import org.w3c.dom.Node
|
||||
|
||||
internal const val EXTENSION_CLASS_DESCRIPTOR = "Lapp/revanced/extension/shared/GmsCoreSupport;"
|
||||
|
||||
private const val PACKAGE_NAME_REGEX_PATTERN = "^[a-z]\\w*(\\.[a-z]\\w*)+\$"
|
||||
|
||||
/**
|
||||
@@ -201,19 +212,18 @@ fun gmsCoreSupportPatch(
|
||||
googlePlayUtilityFingerprint.method.returnEarly(0)
|
||||
}
|
||||
|
||||
// Set original and patched package names for extension to use.
|
||||
originalPackageNameExtensionFingerprint.method.returnEarly(fromPackageName)
|
||||
|
||||
// Verify GmsCore is installed and whitelisted for power optimizations and background usage.
|
||||
mainActivityOnCreateFingerprint.method.apply {
|
||||
addInstructions(
|
||||
0,
|
||||
"invoke-static/range { p0 .. p0 }, Lapp/revanced/extension/shared/GmsCoreSupport;->" +
|
||||
"checkGmsCore(Landroid/app/Activity;)V",
|
||||
)
|
||||
}
|
||||
mainActivityOnCreateFingerprint.method.addInstruction(
|
||||
0,
|
||||
"invoke-static/range { p0 .. p0 }, $EXTENSION_CLASS_DESCRIPTOR->" +
|
||||
"checkGmsCore(Landroid/app/Activity;)V"
|
||||
)
|
||||
|
||||
// Change the vendor of GmsCore in the extension.
|
||||
gmsCoreSupportFingerprint.classDef.methods
|
||||
.single { it.name == GET_GMS_CORE_VENDOR_GROUP_ID_METHOD_NAME }
|
||||
.replaceInstruction(0, "const-string v0, \"$gmsCoreVendorGroupId\"")
|
||||
gmsCoreSupportFingerprint.method.returnEarly(gmsCoreVendorGroupId!!)
|
||||
|
||||
executeBlock()
|
||||
}
|
||||
|
||||
+1
-1
@@ -43,7 +43,7 @@ internal fun spoofVideoStreamsPatch(
|
||||
fixMediaFetchHotConfig: BytecodePatchBuilder.() -> Boolean = { false },
|
||||
fixMediaFetchHotConfigAlternative: BytecodePatchBuilder.() -> Boolean = { false },
|
||||
fixParsePlaybackResponseFeatureFlag: BytecodePatchBuilder.() -> Boolean = { false },
|
||||
block: BytecodePatchBuilder.() -> Unit = {},
|
||||
block: BytecodePatchBuilder.() -> Unit,
|
||||
executeBlock: BytecodePatchContext.() -> Unit = {},
|
||||
) = bytecodePatch(
|
||||
name = "Spoof video streams",
|
||||
|
||||
+17
-42
@@ -1,38 +1,28 @@
|
||||
package app.revanced.patches.youtube.layout.branding
|
||||
|
||||
import app.revanced.patches.shared.layout.branding.baseCustomBrandingPatch
|
||||
import app.revanced.patches.shared.layout.branding.mipmapDirectories
|
||||
import java.nio.file.Files
|
||||
|
||||
private const val APP_NAME = "YouTube ReVanced"
|
||||
|
||||
private val youtubeIconResourceFileNames_19_34 = mapOf(
|
||||
"adaptiveproduct_youtube_foreground_color_108" to "adaptiveproduct_youtube_2024_q4_foreground_color_108",
|
||||
"adaptiveproduct_youtube_background_color_108" to "adaptiveproduct_youtube_2024_q4_background_color_108",
|
||||
)
|
||||
import app.revanced.patches.youtube.misc.extension.sharedExtensionPatch
|
||||
import app.revanced.patches.youtube.misc.gms.Constants.YOUTUBE_MAIN_ACTIVITY_NAME
|
||||
import app.revanced.patches.youtube.misc.gms.Constants.YOUTUBE_PACKAGE_NAME
|
||||
import app.revanced.patches.youtube.misc.settings.PreferenceScreen
|
||||
import app.revanced.patches.youtube.shared.mainActivityOnCreateFingerprint
|
||||
|
||||
@Suppress("unused")
|
||||
val customBrandingPatch = baseCustomBrandingPatch(
|
||||
defaultAppName = APP_NAME,
|
||||
appNameValues = mapOf(
|
||||
"YouTube ReVanced" to APP_NAME,
|
||||
"YT ReVanced" to "YT ReVanced",
|
||||
"YT" to "YT",
|
||||
"YouTube" to "YouTube",
|
||||
),
|
||||
resourceFolder = "custom-branding/youtube",
|
||||
iconResourceFileNames = arrayOf(
|
||||
"adaptiveproduct_youtube_background_color_108",
|
||||
"adaptiveproduct_youtube_foreground_color_108",
|
||||
"ic_launcher",
|
||||
"ic_launcher_round",
|
||||
),
|
||||
monochromeIconFileNames = arrayOf(
|
||||
"adaptive_monochrome_ic_youtube_launcher.xml",
|
||||
"ringo2_adaptive_monochrome_ic_youtube_launcher.xml"
|
||||
),
|
||||
addResourcePatchName = "youtube",
|
||||
originalLauncherIconName = "ic_launcher",
|
||||
originalAppName = "@string/application_name",
|
||||
originalAppPackageName = YOUTUBE_PACKAGE_NAME,
|
||||
copyExistingIntentsToAliases = true,
|
||||
numberOfPresetAppNames = 5,
|
||||
mainActivityOnCreateFingerprint = mainActivityOnCreateFingerprint,
|
||||
mainActivityName = YOUTUBE_MAIN_ACTIVITY_NAME,
|
||||
activityAliasNameWithIntents = "com.google.android.youtube.app.honeycomb.Shell\$HomeActivity",
|
||||
preferenceScreen = PreferenceScreen.GENERAL_LAYOUT,
|
||||
|
||||
block = {
|
||||
dependsOn(sharedExtensionPatch)
|
||||
|
||||
compatibleWith(
|
||||
"com.google.android.youtube"(
|
||||
"19.34.42",
|
||||
@@ -41,20 +31,5 @@ val customBrandingPatch = baseCustomBrandingPatch(
|
||||
"20.14.43",
|
||||
)
|
||||
)
|
||||
},
|
||||
|
||||
executeBlock = {
|
||||
val resourceDirectory = get("res")
|
||||
|
||||
mipmapDirectories.forEach { directory ->
|
||||
val targetDirectory = resourceDirectory.resolve(directory)
|
||||
|
||||
youtubeIconResourceFileNames_19_34.forEach { (old, new) ->
|
||||
val oldFile = targetDirectory.resolve("$old.png")
|
||||
val newFile = targetDirectory.resolve("$new.png")
|
||||
|
||||
Files.write(newFile.toPath(), oldFile.readBytes())
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
+17
-3
@@ -136,8 +136,21 @@ val changeHeaderPatch = resourcePatch(
|
||||
)
|
||||
|
||||
if (custom != null) {
|
||||
val sourceFolders = File(custom!!).listFiles { file -> file.isDirectory }
|
||||
?: throw PatchException("The provided path is not a directory: $custom")
|
||||
val customFile = File(custom!!)
|
||||
if (!customFile.exists()) {
|
||||
throw PatchException("The custom icon path cannot be found: " +
|
||||
customFile.absolutePath
|
||||
)
|
||||
}
|
||||
|
||||
if (!customFile.isDirectory) {
|
||||
throw PatchException("The custom icon path must be a folder: "
|
||||
+ customFile.absolutePath)
|
||||
}
|
||||
|
||||
val sourceFolders = customFile.listFiles { file -> file.isDirectory }
|
||||
?: throw PatchException("The custom icon path contains no subfolders: " +
|
||||
customFile.absolutePath)
|
||||
|
||||
val customResourceFileNames = getLightDarkFileNames(CUSTOM_HEADER_RESOURCE_NAME)
|
||||
|
||||
@@ -166,7 +179,8 @@ val changeHeaderPatch = resourcePatch(
|
||||
}
|
||||
|
||||
if (!copiedFiles) {
|
||||
throw PatchException("No custom header images found in the provided path: $custom")
|
||||
throw PatchException("No custom header images found in " +
|
||||
"the provided path: " + customFile.absolutePath)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+3
-2
@@ -27,6 +27,7 @@ import app.revanced.util.forEachLiteralValueInstruction
|
||||
import app.revanced.util.getReference
|
||||
import app.revanced.util.indexOfFirstInstructionOrThrow
|
||||
import app.revanced.util.indexOfFirstLiteralInstruction
|
||||
import app.revanced.util.removeFromParent
|
||||
import app.revanced.util.returnLate
|
||||
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
|
||||
import com.android.tools.smali.dexlib2.iface.reference.MethodReference
|
||||
@@ -127,7 +128,7 @@ private val hideShortsComponentsResourcePatch = resourcePatch {
|
||||
)
|
||||
|
||||
if (hideShortsAppShortcut == true) {
|
||||
shortsItem.parentNode.removeChild(shortsItem)
|
||||
shortsItem.removeFromParent()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -138,7 +139,7 @@ private val hideShortsComponentsResourcePatch = resourcePatch {
|
||||
)
|
||||
|
||||
if (hideShortsWidget == true) {
|
||||
shortsItem.parentNode.removeChild(shortsItem)
|
||||
shortsItem.removeFromParent()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package app.revanced.patches.youtube.misc.gms
|
||||
|
||||
internal object Constants {
|
||||
internal const val YOUTUBE_MAIN_ACTIVITY_NAME = "com.google.android.apps.youtube.app.watchwhile.MainActivity"
|
||||
|
||||
const val YOUTUBE_PACKAGE_NAME = "com.google.android.youtube"
|
||||
const val REVANCED_YOUTUBE_PACKAGE_NAME = "app.revanced.android.youtube"
|
||||
}
|
||||
@@ -14,6 +14,13 @@ import java.nio.file.StandardCopyOption
|
||||
|
||||
private val classLoader = object {}.javaClass.classLoader
|
||||
|
||||
/**
|
||||
* Removes a node from its parent.
|
||||
*
|
||||
* @return The node that was removed (object this method was called on).
|
||||
*/
|
||||
fun Node.removeFromParent() : Node = parentNode.removeChild(this)
|
||||
|
||||
/**
|
||||
* Returns a sequence for all child nodes.
|
||||
*/
|
||||
@@ -70,8 +77,13 @@ fun ResourcePatchContext.copyResources(
|
||||
for (resourceGroup in resources) {
|
||||
resourceGroup.resources.forEach { resource ->
|
||||
val resourceFile = "${resourceGroup.resourceDirectoryName}/$resource"
|
||||
val stream = inputStreamFromBundledResource(sourceResourceDirectory, resourceFile)
|
||||
if (stream == null) {
|
||||
throw IllegalArgumentException("Could not find resource: $resourceFile " +
|
||||
"in directory: $sourceResourceDirectory")
|
||||
}
|
||||
Files.copy(
|
||||
inputStreamFromBundledResource(sourceResourceDirectory, resourceFile)!!,
|
||||
stream,
|
||||
targetResourceDirectory.resolve(resourceFile).toPath(),
|
||||
StandardCopyOption.REPLACE_EXISTING,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user