From 1fec3e0c55ed303b6d514b423d665d7aa37e9e01 Mon Sep 17 00:00:00 2001 From: LisoUseInAIKyrios <118716522+LisoUseInAIKyrios@users.noreply.github.com> Date: Sat, 20 May 2023 00:45:12 +0400 Subject: [PATCH] fix(youtube/settings): fix non functional back button in settings (#2178) --- .../ReturnYouTubeDislikeResourcePatch.kt | 7 +-- .../patch/SponsorBlockResourcePatch.kt | 9 +-- .../settings/bytecode/patch/SettingsPatch.kt | 22 ++++--- .../resource/patch/SettingsResourcePatch.kt | 58 +++++++++++------- .../quantum_ic_arrow_back_white_24.png | Bin 200 -> 0 bytes .../quantum_ic_arrow_back_white_24.png | Bin 194 -> 0 bytes .../settings/host/values/strings.xml | 1 + .../layout/revanced_settings_toolbar.xml | 4 -- .../layout/revanced_settings_with_toolbar.xml | 33 +++++++++- .../revanced_settings_with_toolbar_layout.xml | 5 -- 10 files changed, 85 insertions(+), 54 deletions(-) delete mode 100644 src/main/resources/settings/drawable-ldrtl-xxxhdpi/quantum_ic_arrow_back_white_24.png delete mode 100644 src/main/resources/settings/drawable-xxxhdpi/quantum_ic_arrow_back_white_24.png delete mode 100644 src/main/resources/settings/layout/revanced_settings_toolbar.xml delete mode 100644 src/main/resources/settings/layout/revanced_settings_with_toolbar_layout.xml diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/returnyoutubedislike/resource/patch/ReturnYouTubeDislikeResourcePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/returnyoutubedislike/resource/patch/ReturnYouTubeDislikeResourcePatch.kt index 2f3df4953e0..866890cbc01 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/returnyoutubedislike/resource/patch/ReturnYouTubeDislikeResourcePatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/returnyoutubedislike/resource/patch/ReturnYouTubeDislikeResourcePatch.kt @@ -26,16 +26,11 @@ class ReturnYouTubeDislikeResourcePatch : ResourcePatch { } override fun execute(context: ResourceContext): PatchResult { - val youtubePackage = "com.google.android.youtube" SettingsPatch.addPreference( Preference( StringResource("revanced_ryd_settings_title", "Return YouTube Dislike"), StringResource("revanced_ryd_settings_summary", "Settings for Return YouTube Dislike"), - Preference.Intent( - youtubePackage, - "ryd_settings", - "com.google.android.libraries.social.licenses.LicenseActivity" - ) + SettingsPatch.createReVancedSettingsIntent("ryd_settings") ) ) // merge strings diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/sponsorblock/resource/patch/SponsorBlockResourcePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/sponsorblock/resource/patch/SponsorBlockResourcePatch.kt index 495778c94d4..c5b97a993f0 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/sponsorblock/resource/patch/SponsorBlockResourcePatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/sponsorblock/resource/patch/SponsorBlockResourcePatch.kt @@ -22,16 +22,11 @@ import app.revanced.util.resources.ResourceUtils.mergeStrings class SponsorBlockResourcePatch : ResourcePatch { override fun execute(context: ResourceContext): PatchResult { - val youtubePackage = "com.google.android.youtube" SettingsPatch.addPreference( Preference( - StringResource("sb_settings", "SponsorBlock"), + StringResource("revanced_sponsorblock_settings_title", "SponsorBlock"), StringResource("revanced_sponsorblock_settings_summary", "SponsorBlock related settings"), - Preference.Intent( - youtubePackage, - "sponsorblock_settings", - "com.google.android.libraries.social.licenses.LicenseActivity" - ) + SettingsPatch.createReVancedSettingsIntent("sponsorblock_settings") ) ) val classLoader = this.javaClass.classLoader diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/settings/bytecode/patch/SettingsPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/settings/bytecode/patch/SettingsPatch.kt index c46053a0852..8804f02c55d 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/settings/bytecode/patch/SettingsPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/settings/bytecode/patch/SettingsPatch.kt @@ -60,14 +60,17 @@ class SettingsPatch : BytecodePatch( } } ?: return SetThemeFingerprint.toErrorResult() - // set the theme based on the preference of the device + + // Modify the license activity and remove all existing layout code. + // Must modify an existing activity and cannot add a new activity to the manifest, + // as that fails for root installations. LicenseActivityFingerprint.result!!.apply licenseActivity@{ mutableMethod.apply { fun buildSettingsActivityInvokeString( registers: String = "p0", classDescriptor: String = SETTINGS_ACTIVITY_DESCRIPTOR, methodName: String = "initializeSettings", - parameters: String = this@licenseActivity.mutableClass.type + parameters: String = "Landroid/app/Activity;" ) = getSetThemeInstructionString(registers, classDescriptor, methodName, parameters) // initialize the settings @@ -77,9 +80,6 @@ class SettingsPatch : BytecodePatch( return-void """ ) - - // set the current theme - addInstruction(0, buildSettingsActivityInvokeString(methodName = "setTheme")) } // remove method overrides @@ -88,14 +88,13 @@ class SettingsPatch : BytecodePatch( } } + return PatchResultSuccess() } internal companion object { private const val INTEGRATIONS_PACKAGE = "app/revanced/integrations" - private const val SETTINGS_ACTIVITY_DESCRIPTOR = "L$INTEGRATIONS_PACKAGE/settingsmenu/ReVancedSettingActivity;" - private const val THEME_HELPER_DESCRIPTOR = "L$INTEGRATIONS_PACKAGE/utils/ThemeHelper;" private const val SET_THEME_METHOD_NAME = "setTheme" @@ -110,6 +109,15 @@ class SettingsPatch : BytecodePatch( fun renameIntentsTargetPackage(newPackage: String) { SettingsResourcePatch.overrideIntentsTargetPackage = newPackage } + + /** + * Creates an intent to open ReVanced settings of the given name + */ + fun createReVancedSettingsIntent(settingsName: String) = Preference.Intent( + "com.google.android.youtube", + settingsName, + "com.google.android.libraries.social.licenses.LicenseActivity" + ) } /** diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/settings/resource/patch/SettingsResourcePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/settings/resource/patch/SettingsResourcePatch.kt index 7ed6f2ee052..86665f51132 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/settings/resource/patch/SettingsResourcePatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/settings/resource/patch/SettingsResourcePatch.kt @@ -16,6 +16,7 @@ import app.revanced.patches.youtube.misc.settings.bytecode.patch.SettingsPatch import app.revanced.util.resources.ResourceUtils import app.revanced.util.resources.ResourceUtils.copyResources import app.revanced.util.resources.ResourceUtils.mergeStrings +import org.w3c.dom.Element import org.w3c.dom.Node @Name("settings-resource-patch") @@ -34,40 +35,51 @@ class SettingsResourcePatch : AbstractSettingsResourcePatch( it.type == "string" && it.name == "app_theme_appearance_dark" }!!.id - - // Create missing directory for the resources. - context["res/drawable-ldrtl-xxxhdpi"].mkdirs() - - - // Copy layout resources. + /* + * copy layout resources + */ arrayOf( - ResourceUtils.ResourceGroup( - "layout", - "revanced_settings_toolbar.xml", - "revanced_settings_with_toolbar.xml", - "revanced_settings_with_toolbar_layout.xml" - ), ResourceUtils.ResourceGroup( - // required resource for back button, because when the base APK is used, this resource will not exist - "drawable-xxxhdpi", "quantum_ic_arrow_back_white_24.png" - ), ResourceUtils.ResourceGroup( - // required resource for back button, because when the base APK is used, this resource will not exist - "drawable-ldrtl-xxxhdpi", "quantum_ic_arrow_back_white_24.png" - ) + ResourceUtils.ResourceGroup("layout", "revanced_settings_with_toolbar.xml") ).forEach { resourceGroup -> context.copyResources("settings", resourceGroup) } preferencesEditor = context.xmlEditor["res/xml/settings_fragment.xml"] - // Add the ReVanced settings to the YouTube settings. - val youtubePackage = "com.google.android.youtube" + // Modify the manifest and add an data intent filter to the LicenseActivity. + // Some devices freak out if undeclared data is passed to an intent, + // and this change appears to fix the issue. + context.xmlEditor["AndroidManifest.xml"].use { editor -> + // An xml regular expression would probably work better than this manual searching. + val manifestNodes = editor.file.getElementsByTagName("manifest").item(0).childNodes + for (i in 0..manifestNodes.length) { + val node = manifestNodes.item(i) + if (node != null && node.nodeName == "application") { + val applicationNodes = node.childNodes + for (j in 0..applicationNodes.length) { + val applicationChild = applicationNodes.item(j) + if (applicationChild is Element && applicationChild.nodeName == "activity" + && applicationChild.getAttribute("android:name") == "com.google.android.libraries.social.licenses.LicenseActivity" + ) { + val intentFilter = editor.file.createElement("intent-filter") + val mimeType = editor.file.createElement("data") + mimeType.setAttribute("android:mimeType", "text/plain") + intentFilter.appendChild(mimeType) + applicationChild.appendChild(intentFilter) + break + } + } + } + } + } + + + // Add the ReVanced settings to the YouTube settings SettingsPatch.addPreference( Preference( StringResource("revanced_settings", "ReVanced"), StringResource("revanced_settings_summary", "ReVanced specific settings"), - Preference.Intent( - youtubePackage, "revanced_settings", "com.google.android.libraries.social.licenses.LicenseActivity" - ) + SettingsPatch.createReVancedSettingsIntent("revanced_settings") ) ) diff --git a/src/main/resources/settings/drawable-ldrtl-xxxhdpi/quantum_ic_arrow_back_white_24.png b/src/main/resources/settings/drawable-ldrtl-xxxhdpi/quantum_ic_arrow_back_white_24.png deleted file mode 100644 index d409b544b7f62950a69d7d1ea58e97ef6c5ea546..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 200 zcmeAS@N?(olHy`uVBq!ia0vp^2_VeD0wg^q?%xcg`aNA7Ln;{G-nuAwkU@eaku@Vo zy*{7I`hn!617~ZZ53W<`EZBV>sE~nSrqA|&tuL?bH@N#td|C81OZ4 j;g=t)KhFPL4YI<5v2M!JY~kXSEg+t!tDnm{r-UW|+8j)X diff --git a/src/main/resources/settings/drawable-xxxhdpi/quantum_ic_arrow_back_white_24.png b/src/main/resources/settings/drawable-xxxhdpi/quantum_ic_arrow_back_white_24.png deleted file mode 100644 index e27034d67874687a900f0f960c662e94cd633e2a..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 194 zcmeAS@N?(olHy`uVBq!ia0vp^2_VeD0wg^q?%xcgIz3$+Ln;{G-r^K&b`Wq0WJxHR z+hbl+*u(m6U6udA_c1Lg>hl;G7;?6Tmes9(^C#@)&$XLAN2fmDK5_2;oXs^qKRrD? zT|a&wl=0u{XMX3o{EI(zZSFU;t5*oK`xGb|A7l~sF+e3G`eLnqRNcP#_|M_{efOCe b7~U|>UYh-J>#;zfqZmA0{an^LB{Ts5m>*B+ diff --git a/src/main/resources/settings/host/values/strings.xml b/src/main/resources/settings/host/values/strings.xml index cc00d46f11d..75802473c6f 100644 --- a/src/main/resources/settings/host/values/strings.xml +++ b/src/main/resources/settings/host/values/strings.xml @@ -1,5 +1,6 @@ + ReVanced Do you wish to proceed? Reset diff --git a/src/main/resources/settings/layout/revanced_settings_toolbar.xml b/src/main/resources/settings/layout/revanced_settings_toolbar.xml deleted file mode 100644 index 86c71771260..00000000000 --- a/src/main/resources/settings/layout/revanced_settings_toolbar.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/src/main/resources/settings/layout/revanced_settings_with_toolbar.xml b/src/main/resources/settings/layout/revanced_settings_with_toolbar.xml index 21ff5978078..150088114ec 100644 --- a/src/main/resources/settings/layout/revanced_settings_with_toolbar.xml +++ b/src/main/resources/settings/layout/revanced_settings_with_toolbar.xml @@ -1,4 +1,33 @@ - - + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/settings/layout/revanced_settings_with_toolbar_layout.xml b/src/main/resources/settings/layout/revanced_settings_with_toolbar_layout.xml deleted file mode 100644 index 31b20d94518..00000000000 --- a/src/main/resources/settings/layout/revanced_settings_with_toolbar_layout.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - - \ No newline at end of file