Skip to content

Commit 8af70fe

Browse files
author
LisoUseInAIKyrios
authored
feat(YouTube Music): Add Check watch history domain name resolution (#5979)
1 parent 191b916 commit 8af70fe

File tree

11 files changed

+118
-44
lines changed

11 files changed

+118
-44
lines changed
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package app.revanced.extension.youtube.patches;
1+
package app.revanced.extension.shared.patches;
22

33
import static app.revanced.extension.shared.StringRef.str;
44

@@ -13,8 +13,8 @@
1313

1414
import app.revanced.extension.shared.Logger;
1515
import app.revanced.extension.shared.Utils;
16+
import app.revanced.extension.shared.settings.BaseSettings;
1617
import app.revanced.extension.shared.ui.CustomDialog;
17-
import app.revanced.extension.youtube.settings.Settings;
1818

1919
@SuppressWarnings("unused")
2020
public class CheckWatchHistoryDomainNameResolutionPatch {
@@ -49,7 +49,7 @@ private static boolean domainResolvesToValidIP(String host) {
4949
* Checks if s.youtube.com is blacklisted and playback history will fail to work.
5050
*/
5151
public static void checkDnsResolver(Activity context) {
52-
if (!Utils.isNetworkConnected() || !Settings.CHECK_WATCH_HISTORY_DOMAIN_NAME.get()) return;
52+
if (!Utils.isNetworkConnected() || !BaseSettings.CHECK_WATCH_HISTORY_DOMAIN_NAME.get()) return;
5353

5454
Utils.runOnBackgroundThread(() -> {
5555
try {
@@ -61,8 +61,8 @@ public static void checkDnsResolver(Activity context) {
6161
// Prevent this false positive by verify youtube.com resolves.
6262
// If youtube.com does not resolve, then it's not a watch history domain resolving error
6363
// because the entire app will not work since no domains are resolving.
64-
if (domainResolvesToValidIP(HISTORY_TRACKING_ENDPOINT)
65-
|| !domainResolvesToValidIP("youtube.com")) {
64+
if (!domainResolvesToValidIP("youtube.com")
65+
|| domainResolvesToValidIP(HISTORY_TRACKING_ENDPOINT)) {
6666
return;
6767
}
6868

@@ -78,7 +78,7 @@ public static void checkDnsResolver(Activity context) {
7878
() -> {}, // OK button action (just dismiss).
7979
() -> {}, // Cancel button action (just dismiss).
8080
str("revanced_check_watch_history_domain_name_dialog_ignore"), // Neutral button text.
81-
() -> Settings.CHECK_WATCH_HISTORY_DOMAIN_NAME.save(false), // Neutral button action (Ignore).
81+
() -> BaseSettings.CHECK_WATCH_HISTORY_DOMAIN_NAME.save(false), // Neutral button action (Ignore).
8282
true // Dismiss dialog on Neutral button click.
8383
);
8484

extensions/shared/library/src/main/java/app/revanced/extension/shared/settings/BaseSettings.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,16 @@ public class BaseSettings {
2828
public static final BooleanSetting SETTINGS_SEARCH_HISTORY = new BooleanSetting("revanced_settings_search_history", TRUE, true);
2929
public static final StringSetting SETTINGS_SEARCH_ENTRIES = new StringSetting("revanced_settings_search_entries", "");
3030

31+
//
32+
// Settings shared by YouTube and YouTube Music.
33+
//
34+
3135
public static final BooleanSetting SPOOF_VIDEO_STREAMS = new BooleanSetting("revanced_spoof_video_streams", TRUE, true, "revanced_spoof_video_streams_user_dialog_message");
3236
public static final EnumSetting<AppLanguage> SPOOF_VIDEO_STREAMS_LANGUAGE = new EnumSetting<>("revanced_spoof_video_streams_language", AppLanguage.DEFAULT, new AudioStreamLanguageOverrideAvailability());
3337
public static final BooleanSetting SPOOF_STREAMING_DATA_STATS_FOR_NERDS = new BooleanSetting("revanced_spoof_streaming_data_stats_for_nerds", TRUE, parent(SPOOF_VIDEO_STREAMS));
3438

3539
public static final BooleanSetting SANITIZE_SHARED_LINKS = new BooleanSetting("revanced_sanitize_sharing_links", TRUE);
3640
public static final BooleanSetting REPLACE_MUSIC_LINKS_WITH_YOUTUBE = new BooleanSetting("revanced_replace_music_with_youtube", FALSE);
41+
42+
public static final BooleanSetting CHECK_WATCH_HISTORY_DOMAIN_NAME = new BooleanSetting("revanced_check_watch_history_domain_name", TRUE, false, false);
3743
}

extensions/youtube/src/main/java/app/revanced/extension/youtube/settings/Settings.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,6 @@ public class Settings extends BaseSettings {
344344
public static final BooleanSetting LOOP_VIDEO = new BooleanSetting("revanced_loop_video", FALSE);
345345
public static final BooleanSetting LOOP_VIDEO_BUTTON = new BooleanSetting("revanced_loop_video_button", FALSE);
346346
public static final BooleanSetting BYPASS_URL_REDIRECTS = new BooleanSetting("revanced_bypass_url_redirects", TRUE);
347-
public static final BooleanSetting CHECK_WATCH_HISTORY_DOMAIN_NAME = new BooleanSetting("revanced_check_watch_history_domain_name", TRUE, false, false);
348347
public static final BooleanSetting DISABLE_HAPTIC_FEEDBACK_CHAPTERS = new BooleanSetting("revanced_disable_haptic_feedback_chapters", FALSE);
349348
public static final BooleanSetting DISABLE_HAPTIC_FEEDBACK_PRECISE_SEEKING = new BooleanSetting("revanced_disable_haptic_feedback_precise_seeking", FALSE);
350349
public static final BooleanSetting DISABLE_HAPTIC_FEEDBACK_SEEK_UNDO = new BooleanSetting("revanced_disable_haptic_feedback_seek_undo", FALSE);

patches/api/patches.api

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,10 @@ public final class app/revanced/patches/music/misc/debugging/EnableDebuggingPatc
405405
public static final fun getEnableDebuggingPatch ()Lapp/revanced/patcher/patch/BytecodePatch;
406406
}
407407

408+
public final class app/revanced/patches/music/misc/dns/CheckWatchHistoryDomainNameResolutionPatchKt {
409+
public static final fun getCheckWatchHistoryDomainNameResolutionPatch ()Lapp/revanced/patcher/patch/BytecodePatch;
410+
}
411+
408412
public final class app/revanced/patches/music/misc/extension/SharedExtensionPatchKt {
409413
public static final fun getSharedExtensionPatch ()Lapp/revanced/patcher/patch/BytecodePatch;
410414
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package app.revanced.patches.music.misc.dns
2+
3+
import app.revanced.patches.music.misc.extension.sharedExtensionPatch
4+
import app.revanced.patches.music.shared.mainActivityOnCreateFingerprint
5+
import app.revanced.patches.shared.misc.dns.checkWatchHistoryDomainNameResolutionPatch
6+
7+
val checkWatchHistoryDomainNameResolutionPatch = checkWatchHistoryDomainNameResolutionPatch(
8+
block = {
9+
dependsOn(
10+
sharedExtensionPatch
11+
)
12+
13+
compatibleWith(
14+
"com.google.android.apps.youtube.music"(
15+
"7.29.52",
16+
"8.10.52"
17+
)
18+
)
19+
},
20+
21+
mainActivityFingerprint = mainActivityOnCreateFingerprint
22+
)
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
package app.revanced.patches.music.misc.extension
22

33
import app.revanced.patches.music.misc.extension.hooks.applicationInitHook
4+
import app.revanced.patches.music.misc.extension.hooks.applicationInitOnCreateHook
45
import app.revanced.patches.shared.misc.extension.sharedExtensionPatch
56

67
val sharedExtensionPatch = sharedExtensionPatch(
78
"music",
8-
applicationInitHook,
9+
applicationInitHook, applicationInitOnCreateHook
910
)

patches/src/main/kotlin/app/revanced/patches/music/misc/extension/hooks/ApplicationInitHook.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package app.revanced.patches.music.misc.extension.hooks
22

3+
import app.revanced.patches.music.shared.YOUTUBE_MUSIC_MAIN_ACTIVITY_CLASS_TYPE
34
import app.revanced.patches.shared.misc.extension.extensionHook
45

56
internal val applicationInitHook = extensionHook {
@@ -8,3 +9,11 @@ internal val applicationInitHook = extensionHook {
89
strings("activity")
910
custom { method, _ -> method.name == "onCreate" }
1011
}
12+
13+
internal val applicationInitOnCreateHook = extensionHook {
14+
returns("V")
15+
parameters("Landroid/os/Bundle;")
16+
custom { method, classDef ->
17+
method.name == "onCreate" && classDef.type == YOUTUBE_MUSIC_MAIN_ACTIVITY_CLASS_TYPE
18+
}
19+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package app.revanced.patches.music.shared
2+
3+
import app.revanced.patcher.fingerprint
4+
5+
internal const val YOUTUBE_MUSIC_MAIN_ACTIVITY_CLASS_TYPE = "Lcom/google/android/apps/youtube/music/activities/MusicActivity;"
6+
7+
internal val mainActivityOnCreateFingerprint = fingerprint {
8+
returns("V")
9+
parameters("Landroid/os/Bundle;")
10+
custom { method, classDef ->
11+
method.name == "onCreate" && classDef.type == YOUTUBE_MUSIC_MAIN_ACTIVITY_CLASS_TYPE
12+
}
13+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package app.revanced.patches.shared.misc.dns
2+
3+
import app.revanced.patcher.Fingerprint
4+
import app.revanced.patcher.extensions.InstructionExtensions.addInstruction
5+
import app.revanced.patcher.patch.BytecodePatchBuilder
6+
import app.revanced.patcher.patch.BytecodePatchContext
7+
import app.revanced.patcher.patch.bytecodePatch
8+
import app.revanced.patches.all.misc.resources.addResources
9+
10+
private const val EXTENSION_CLASS_DESCRIPTOR =
11+
"Lapp/revanced/extension/shared/patches/CheckWatchHistoryDomainNameResolutionPatch;"
12+
13+
/**
14+
* Patch shared with YouTube and YT Music.
15+
*/
16+
internal fun checkWatchHistoryDomainNameResolutionPatch(
17+
block: BytecodePatchBuilder.() -> Unit = {},
18+
executeBlock: BytecodePatchContext.() -> Unit = {},
19+
mainActivityFingerprint: Fingerprint
20+
) = bytecodePatch(
21+
name = "Check watch history domain name resolution",
22+
description = "Checks if the device DNS server is preventing user watch history from being saved.",
23+
) {
24+
block()
25+
26+
execute {
27+
executeBlock()
28+
29+
addResources("shared", "misc.dns.checkWatchHistoryDomainNameResolutionPatch")
30+
31+
mainActivityFingerprint.method.addInstruction(
32+
0,
33+
"invoke-static/range { p0 .. p0 }, $EXTENSION_CLASS_DESCRIPTOR->checkDnsResolver(Landroid/app/Activity;)V",
34+
)
35+
}
36+
}
Lines changed: 15 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,23 @@
11
package app.revanced.patches.youtube.misc.dns
22

3-
import app.revanced.patcher.extensions.InstructionExtensions.addInstruction
4-
import app.revanced.patcher.patch.bytecodePatch
5-
import app.revanced.patches.all.misc.resources.addResources
6-
import app.revanced.patches.all.misc.resources.addResourcesPatch
3+
import app.revanced.patches.shared.misc.dns.checkWatchHistoryDomainNameResolutionPatch
74
import app.revanced.patches.youtube.misc.extension.sharedExtensionPatch
85
import app.revanced.patches.youtube.shared.mainActivityOnCreateFingerprint
96

10-
private const val EXTENSION_CLASS_DESCRIPTOR =
11-
"Lapp/revanced/extension/youtube/patches/CheckWatchHistoryDomainNameResolutionPatch;"
12-
13-
val checkWatchHistoryDomainNameResolutionPatch = bytecodePatch(
14-
name = "Check watch history domain name resolution",
15-
description = "Checks if the device DNS server is preventing user watch history from being saved.",
16-
) {
17-
dependsOn(
18-
sharedExtensionPatch,
19-
addResourcesPatch
20-
)
21-
22-
compatibleWith(
23-
"com.google.android.youtube"(
24-
"19.34.42",
25-
"20.07.39",
26-
"20.13.41",
27-
"20.14.43",
7+
val checkWatchHistoryDomainNameResolutionPatch = checkWatchHistoryDomainNameResolutionPatch(
8+
block = {
9+
dependsOn(
10+
sharedExtensionPatch
2811
)
29-
)
30-
31-
execute {
32-
addResources("youtube", "misc.dns.checkWatchHistoryDomainNameResolutionPatch")
3312

34-
mainActivityOnCreateFingerprint.method.addInstruction(
35-
0,
36-
"invoke-static/range { p0 .. p0 }, $EXTENSION_CLASS_DESCRIPTOR->checkDnsResolver(Landroid/app/Activity;)V",
13+
compatibleWith(
14+
"com.google.android.youtube"(
15+
"19.34.42",
16+
"20.07.39",
17+
"20.13.41",
18+
"20.14.43",
19+
)
3720
)
38-
}
39-
}
21+
},
22+
mainActivityFingerprint = mainActivityOnCreateFingerprint
23+
)

0 commit comments

Comments
 (0)