Cache organization names

This commit is contained in:
M66B 2019-03-10 08:08:33 +00:00
parent 93b1e7f9fa
commit 8a4c599d9e
1 changed files with 10 additions and 0 deletions

View File

@ -84,6 +84,7 @@ import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@ -108,6 +109,8 @@ import static android.os.Process.THREAD_PRIORITY_BACKGROUND;
import static androidx.browser.customtabs.CustomTabsService.ACTION_CUSTOM_TABS_CONNECTION;
public class Helper {
private static Map<String, String> hostOrganization = new HashMap<>();
static final int NOTIFICATION_SYNCHRONIZE = 1;
static final int NOTIFICATION_SEND = 2;
static final int NOTIFICATION_EXTERNAL = 3;
@ -1018,6 +1021,10 @@ public class Helper {
}
static String getOrganization(String host) throws IOException {
synchronized (hostOrganization) {
if (hostOrganization.containsKey(host))
return hostOrganization.get(host);
}
InetAddress address = InetAddress.getByName(host);
URL url = new URL("https://ipinfo.io/" + address.getHostAddress() + "/org");
HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
@ -1028,6 +1035,9 @@ public class Helper {
String organization = reader.readLine();
if ("undefined".equals(organization))
organization = null;
synchronized (hostOrganization) {
hostOrganization.put(host, organization);
}
return organization;
}
}