mirror of
https://github.com/inotia00/revanced-patches.git
synced 2025-06-12 21:27:43 +02:00
refactor: reformat code and optimize imports
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
package app.revanced.util.enum
|
||||
|
||||
internal enum class CategoryType(val value: String) {
|
||||
ADS("ads"),
|
||||
LAYOUT("layout"),
|
||||
MISC("misc")
|
||||
ADS("ads"),
|
||||
LAYOUT("layout"),
|
||||
MISC("misc")
|
||||
}
|
@ -1,13 +1,13 @@
|
||||
package app.revanced.util.enum
|
||||
|
||||
internal enum class ResourceType(val value: String) {
|
||||
ATTR("attr"),
|
||||
BOOL("bool"),
|
||||
COLOR("color"),
|
||||
DIMEN("dimen"),
|
||||
DRAWABLE("drawable"),
|
||||
ID("id"),
|
||||
LAYOUT("layout"),
|
||||
STRING("string"),
|
||||
STYLE("style")
|
||||
ATTR("attr"),
|
||||
BOOL("bool"),
|
||||
COLOR("color"),
|
||||
DIMEN("dimen"),
|
||||
DRAWABLE("drawable"),
|
||||
ID("id"),
|
||||
LAYOUT("layout"),
|
||||
STRING("string"),
|
||||
STYLE("style")
|
||||
}
|
@ -18,7 +18,8 @@ internal object Constants {
|
||||
/**
|
||||
* meta-data for microG package signature spoofing on patched builds
|
||||
*/
|
||||
const val META_SPOOFED_PACKAGE_SIGNATURE = "$MICROG_VENDOR.android.gms.SPOOFED_PACKAGE_SIGNATURE"
|
||||
const val META_SPOOFED_PACKAGE_SIGNATURE =
|
||||
"$MICROG_VENDOR.android.gms.SPOOFED_PACKAGE_SIGNATURE"
|
||||
|
||||
/**
|
||||
* meta-data for microG package detection
|
||||
|
@ -32,7 +32,11 @@ internal object MicroGBytecodeHelper {
|
||||
return { referencedString ->
|
||||
when (referencedString) {
|
||||
"$fromPackageName.SuggestionsProvider",
|
||||
"$fromPackageName.fileprovider" -> referencedString.replace(fromPackageName, toPackageName)
|
||||
"$fromPackageName.fileprovider" -> referencedString.replace(
|
||||
fromPackageName,
|
||||
toPackageName
|
||||
)
|
||||
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
@ -61,7 +65,8 @@ internal object MicroGBytecodeHelper {
|
||||
val targetIndex = implementation!!.instructions.indexOfFirst { instructions ->
|
||||
if (instructions.opcode != Opcode.CONST_STRING) return@indexOfFirst false
|
||||
|
||||
val instructionString = ((instructions as Instruction21c).reference as StringReference).string
|
||||
val instructionString =
|
||||
((instructions as Instruction21c).reference as StringReference).string
|
||||
if (instructionString != fromPackageName) return@indexOfFirst false
|
||||
|
||||
targetRegister = instructions.registerA
|
||||
|
@ -170,7 +170,7 @@ internal object IconHelper {
|
||||
iconPath: String,
|
||||
directory: String,
|
||||
iconArray: Array<String>
|
||||
){
|
||||
) {
|
||||
arrayOf(
|
||||
"xxxhdpi",
|
||||
"xxhdpi",
|
||||
@ -192,7 +192,7 @@ internal object IconHelper {
|
||||
appName: String,
|
||||
monochromeIconName: String,
|
||||
iconName: String
|
||||
){
|
||||
) {
|
||||
try {
|
||||
val relativePath = "drawable/$monochromeIconName.xml"
|
||||
Files.copy(
|
||||
@ -200,14 +200,15 @@ internal object IconHelper {
|
||||
this["res"].resolve(relativePath).toPath(),
|
||||
StandardCopyOption.REPLACE_EXISTING
|
||||
)
|
||||
} catch (_: Exception) {}
|
||||
} catch (_: Exception) {
|
||||
}
|
||||
}
|
||||
|
||||
private fun ResourceContext.copyMusicResources(
|
||||
iconName: String,
|
||||
iconArray: Array<String>,
|
||||
resourceNames: String
|
||||
){
|
||||
) {
|
||||
iconArray.forEach { path ->
|
||||
val relativePath = "drawable-$path/$resourceNames.png"
|
||||
|
||||
@ -225,7 +226,9 @@ internal object IconHelper {
|
||||
xmlEditor[targetPath].use { editor ->
|
||||
val tags = editor.file.getElementsByTagName("item")
|
||||
List(tags.length) { tags.item(it) as Element }
|
||||
.filter { it.getAttribute("name").contains("android:windowSplashScreenAnimatedIcon") }
|
||||
.filter {
|
||||
it.getAttribute("name").contains("android:windowSplashScreenAnimatedIcon")
|
||||
}
|
||||
.forEach { it.parentNode.removeChild(it) }
|
||||
}
|
||||
}
|
||||
|
@ -30,22 +30,25 @@ internal object MusicResourceHelper {
|
||||
|
||||
private const val YOUTUBE_MUSIC_SETTINGS_KEY = "revanced_extended_settings"
|
||||
|
||||
private const val YOUTUBE_MUSIC_CATEGORY_TAG_NAME = "com.google.android.apps.youtube.music.ui.preference.PreferenceCategoryCompat"
|
||||
private const val YOUTUBE_MUSIC_CATEGORY_TAG_NAME =
|
||||
"com.google.android.apps.youtube.music.ui.preference.PreferenceCategoryCompat"
|
||||
|
||||
private const val YOUTUBE_MUSIC_PREFERENCE_TAG_NAME = "com.google.android.apps.youtube.music.ui.preference.SwitchCompatPreference"
|
||||
private const val YOUTUBE_MUSIC_PREFERENCE_TAG_NAME =
|
||||
"com.google.android.apps.youtube.music.ui.preference.SwitchCompatPreference"
|
||||
|
||||
private const val YOUTUBE_MUSIC_PREFERENCE_TARGET_CLASS = "com.google.android.libraries.strictmode.penalties.notification.FullStackTraceActivity"
|
||||
private const val YOUTUBE_MUSIC_PREFERENCE_TARGET_CLASS =
|
||||
"com.google.android.libraries.strictmode.penalties.notification.FullStackTraceActivity"
|
||||
|
||||
private var currentMusicPreferenceCategory = emptyArray<String>()
|
||||
|
||||
private var targetPackage = "com.google.android.apps.youtube.music"
|
||||
|
||||
internal fun ResourceContext.setMicroG (newPackage: String) {
|
||||
internal fun ResourceContext.setMicroG(newPackage: String) {
|
||||
targetPackage = newPackage
|
||||
replacePackageName()
|
||||
}
|
||||
|
||||
private fun setMusicPreferenceCategory (newCategory: String) {
|
||||
private fun setMusicPreferenceCategory(newCategory: String) {
|
||||
currentMusicPreferenceCategory += listOf(newCategory)
|
||||
}
|
||||
|
||||
@ -85,9 +88,10 @@ internal object MusicResourceHelper {
|
||||
replacePackageName()
|
||||
}
|
||||
|
||||
private fun ResourceContext.replacePackageName(){
|
||||
private fun ResourceContext.replacePackageName() {
|
||||
this[YOUTUBE_MUSIC_SETTINGS_PATH].writeText(
|
||||
this[YOUTUBE_MUSIC_SETTINGS_PATH].readText().replace("\"com.google.android.apps.youtube.music\"", "\"" + targetPackage + "\"")
|
||||
this[YOUTUBE_MUSIC_SETTINGS_PATH].readText()
|
||||
.replace("\"com.google.android.apps.youtube.music\"", "\"" + targetPackage + "\"")
|
||||
)
|
||||
}
|
||||
|
||||
@ -129,7 +133,10 @@ internal object MusicResourceHelper {
|
||||
this.adoptChild("intent") {
|
||||
setAttribute("android:targetPackage", targetPackage)
|
||||
setAttribute("android:data", key)
|
||||
setAttribute("android:targetClass", YOUTUBE_MUSIC_PREFERENCE_TARGET_CLASS)
|
||||
setAttribute(
|
||||
"android:targetClass",
|
||||
YOUTUBE_MUSIC_PREFERENCE_TARGET_CLASS
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -138,13 +145,19 @@ internal object MusicResourceHelper {
|
||||
|
||||
internal fun ResourceContext.addReVancedMusicPreference() {
|
||||
this.xmlEditor[YOUTUBE_MUSIC_SETTINGS_PATH].use { editor ->
|
||||
with (editor.file) {
|
||||
with(editor.file) {
|
||||
doRecursively loop@{
|
||||
if (it !is Element) return@loop
|
||||
it.getAttributeNode("android:key")?.let { attribute ->
|
||||
if (attribute.textContent == "settings_header_about_youtube_music" && it.getAttributeNode("app:allowDividerBelow").textContent == "false") {
|
||||
if (attribute.textContent == "settings_header_about_youtube_music" && it.getAttributeNode(
|
||||
"app:allowDividerBelow"
|
||||
).textContent == "false"
|
||||
) {
|
||||
it.insertNode("PreferenceScreen", it) {
|
||||
setAttribute("android:title", "@string/" + YOUTUBE_MUSIC_SETTINGS_KEY + "_title")
|
||||
setAttribute(
|
||||
"android:title",
|
||||
"@string/" + YOUTUBE_MUSIC_SETTINGS_KEY + "_title"
|
||||
)
|
||||
setAttribute("android:key", YOUTUBE_MUSIC_SETTINGS_KEY)
|
||||
}
|
||||
it.getAttributeNode("app:allowDividerBelow").textContent = "true"
|
||||
|
@ -22,7 +22,7 @@ internal object ResourceHelper {
|
||||
|
||||
private var targetPackage = "com.google.android.youtube"
|
||||
|
||||
internal fun setMicroG (newPackage: String) {
|
||||
internal fun setMicroG(newPackage: String) {
|
||||
targetPackage = newPackage
|
||||
}
|
||||
|
||||
@ -96,21 +96,26 @@ internal object ResourceHelper {
|
||||
}
|
||||
|
||||
internal fun ResourceContext.addReVancedPreference(key: String) {
|
||||
val targetClass = "com.google.android.apps.youtube.app.settings.videoquality.VideoQualitySettingsActivity"
|
||||
val targetClass =
|
||||
"com.google.android.apps.youtube.app.settings.videoquality.VideoQualitySettingsActivity"
|
||||
|
||||
this.xmlEditor[YOUTUBE_SETTINGS_PATH].use { editor ->
|
||||
with (editor.file) {
|
||||
with(editor.file) {
|
||||
doRecursively loop@{
|
||||
if (it !is Element) return@loop
|
||||
it.getAttributeNode("android:key")?.let { attribute ->
|
||||
if (attribute.textContent == "@string/about_key" && it.getAttributeNode("app:iconSpaceReserved").textContent == "false") {
|
||||
it.insertNode("Preference", it) {
|
||||
setAttribute("android:title", "@string/revanced_" + key + "_title")
|
||||
this.appendChild(ownerDocument.createElement("intent").also { intentNode ->
|
||||
intentNode.setAttribute("android:targetPackage", targetPackage)
|
||||
intentNode.setAttribute("android:data", key)
|
||||
intentNode.setAttribute("android:targetClass", targetClass)
|
||||
})
|
||||
this.appendChild(
|
||||
ownerDocument.createElement("intent").also { intentNode ->
|
||||
intentNode.setAttribute(
|
||||
"android:targetPackage",
|
||||
targetPackage
|
||||
)
|
||||
intentNode.setAttribute("android:data", key)
|
||||
intentNode.setAttribute("android:targetClass", targetClass)
|
||||
})
|
||||
}
|
||||
it.getAttributeNode("app:iconSpaceReserved").textContent = "true"
|
||||
return@loop
|
||||
|
@ -11,7 +11,10 @@ internal object ResourceUtils {
|
||||
* @param sourceResourceDirectory The source resource directory name.
|
||||
* @param resources The resources to copy.
|
||||
*/
|
||||
internal fun ResourceContext.copyResources(sourceResourceDirectory: String, vararg resources: ResourceGroup) {
|
||||
internal fun ResourceContext.copyResources(
|
||||
sourceResourceDirectory: String,
|
||||
vararg resources: ResourceGroup
|
||||
) {
|
||||
val classLoader = ResourceUtils.javaClass.classLoader
|
||||
val targetResourceDirectory = this["res"]
|
||||
|
||||
@ -20,7 +23,8 @@ internal object ResourceUtils {
|
||||
val resourceFile = "${resourceGroup.resourceDirectoryName}/$resource"
|
||||
Files.copy(
|
||||
classLoader.getResourceAsStream("$sourceResourceDirectory/$resourceFile")!!,
|
||||
targetResourceDirectory.resolve(resourceFile).toPath(), StandardCopyOption.REPLACE_EXISTING
|
||||
targetResourceDirectory.resolve(resourceFile).toPath(),
|
||||
StandardCopyOption.REPLACE_EXISTING
|
||||
)
|
||||
}
|
||||
}
|
||||
@ -39,8 +43,13 @@ internal object ResourceUtils {
|
||||
* @param targetResource The target resource.
|
||||
* @param elementTag The element to copy.
|
||||
*/
|
||||
internal fun ResourceContext.copyXmlNode(resourceDirectory: String, targetResource: String, elementTag: String) {
|
||||
val stringsResourceInputStream = ResourceUtils.javaClass.classLoader.getResourceAsStream("$resourceDirectory/$targetResource")!!
|
||||
internal fun ResourceContext.copyXmlNode(
|
||||
resourceDirectory: String,
|
||||
targetResource: String,
|
||||
elementTag: String
|
||||
) {
|
||||
val stringsResourceInputStream =
|
||||
ResourceUtils.javaClass.classLoader.getResourceAsStream("$resourceDirectory/$targetResource")!!
|
||||
|
||||
// Copy nodes from the resources node to the real resource node
|
||||
elementTag.copyXmlNode(
|
||||
|
Reference in New Issue
Block a user