|
|
|
@ -26,6 +26,7 @@ import java.io.BufferedReader;
|
|
|
|
|
import java.io.InputStream;
|
|
|
|
|
import java.io.InputStreamReader;
|
|
|
|
|
import java.util.HashSet;
|
|
|
|
|
import java.util.Locale;
|
|
|
|
|
|
|
|
|
|
public class UriHelper {
|
|
|
|
|
// https://publicsuffix.org/
|
|
|
|
@ -37,14 +38,23 @@ public class UriHelper {
|
|
|
|
|
static String getParentDomain(Context context, String host) {
|
|
|
|
|
if (host == null)
|
|
|
|
|
return null;
|
|
|
|
|
String parent = _getSuffix(context, host);
|
|
|
|
|
return (parent == null ? host : parent);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static boolean hasParentDomain(Context context, String host) {
|
|
|
|
|
return (host != null && _getSuffix(context, host) != null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static String _getSuffix(Context context, String host) {
|
|
|
|
|
ensureSuffixList(context);
|
|
|
|
|
|
|
|
|
|
String h = host;
|
|
|
|
|
String h = host.toLowerCase(Locale.ROOT);
|
|
|
|
|
while (true) {
|
|
|
|
|
int dot = h.indexOf('.');
|
|
|
|
|
if (dot < 0)
|
|
|
|
|
return host;
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
String prefix = h.substring(0, dot);
|
|
|
|
|
h = h.substring(dot + 1);
|
|
|
|
|
|
|
|
|
@ -52,8 +62,8 @@ public class UriHelper {
|
|
|
|
|
String w = (d < 0 ? null : '*' + h.substring(d));
|
|
|
|
|
|
|
|
|
|
synchronized (suffixList) {
|
|
|
|
|
if ((suffixList.contains(h) || suffixList.contains(w)) &&
|
|
|
|
|
!suffixList.contains('!' + h)) {
|
|
|
|
|
if (!suffixList.contains('!' + h) &&
|
|
|
|
|
(suffixList.contains(h) || suffixList.contains(w))) {
|
|
|
|
|
String parent = prefix + "." + h;
|
|
|
|
|
Log.d("Host=" + host + " parent=" + parent);
|
|
|
|
|
return parent;
|
|
|
|
|