This repository has been archived by the owner on Oct 26, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 251
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
85 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
...app/revanced/integrations/youtube/patches/CheckWatchHistoryDomainNameResolutionPatch.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package app.revanced.integrations.youtube.patches; | ||
|
||
import static app.revanced.integrations.shared.StringRef.str; | ||
|
||
import android.app.Activity; | ||
import android.text.Html; | ||
|
||
import java.net.InetAddress; | ||
import java.net.UnknownHostException; | ||
|
||
import app.revanced.integrations.shared.Logger; | ||
import app.revanced.integrations.shared.Utils; | ||
import app.revanced.integrations.youtube.settings.Settings; | ||
|
||
@SuppressWarnings("unused") | ||
public class CheckWatchHistoryDomainNameResolutionPatch { | ||
|
||
private static final String HISTORY_TRACKING_ENDPOINT = "s.youtube.com"; | ||
|
||
private static final String SINKHOLE_IPV4 = "0.0.0.0"; | ||
private static final String SINKHOLE_IPV6 = "::"; | ||
|
||
/** @noinspection SameParameterValue */ | ||
private static boolean domainResolvesToValidIP(String host) { | ||
try { | ||
InetAddress address = InetAddress.getByName(host); | ||
String hostAddress = address.getHostAddress(); | ||
|
||
if (address.isLoopbackAddress()) { | ||
Logger.printDebug(() -> host + " resolves to localhost"); | ||
} else if (SINKHOLE_IPV4.equals(hostAddress) || SINKHOLE_IPV6.equals(hostAddress)) { | ||
Logger.printDebug(() -> host + " resolves to sinkhole ip"); | ||
} else { | ||
return true; // Domain is not blocked. | ||
} | ||
} catch (UnknownHostException e) { | ||
Logger.printDebug(() -> host + " failed to resolve"); | ||
} | ||
|
||
return false; | ||
} | ||
|
||
/** | ||
* Injection point. | ||
* | ||
* Checks if s.youtube.com is blacklisted and playback history will fail to work. | ||
*/ | ||
public static void checkDnsResolver(Activity context) { | ||
if (!Utils.isNetworkConnected() || !Settings.CHECK_WATCH_HISTORY_DOMAIN_NAME.get()) return; | ||
|
||
Utils.runOnBackgroundThread(() -> { | ||
try { | ||
if (domainResolvesToValidIP(HISTORY_TRACKING_ENDPOINT)) { | ||
return; | ||
} | ||
|
||
Utils.runOnMainThread(() -> { | ||
var alertDialog = new android.app.AlertDialog.Builder(context) | ||
.setTitle(str("revanced_check_watch_history_domain_name_dialog_title")) | ||
.setMessage(Html.fromHtml(str("revanced_check_watch_history_domain_name_dialog_message"))) | ||
.setIconAttribute(android.R.attr.alertDialogIcon) | ||
.setPositiveButton(android.R.string.ok, (dialog, which) -> { | ||
dialog.dismiss(); | ||
}).setNegativeButton(str("revanced_check_watch_history_domain_name_dialog_ignore"), (dialog, which) -> { | ||
Settings.CHECK_WATCH_HISTORY_DOMAIN_NAME.save(false); | ||
dialog.dismiss(); | ||
}) | ||
.setCancelable(false) | ||
.show(); | ||
}); | ||
} catch (Exception ex) { | ||
Logger.printException(() -> "checkDnsResolver failure", ex); | ||
} | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
org.gradle.parallel = true | ||
org.gradle.caching = true | ||
android.useAndroidX = true | ||
version = 1.12.0 | ||
version = 1.13.0-dev.1 |