mirror of
https://github.com/M66B/FairEmail.git
synced 2024-12-27 18:27:43 +00:00
Cache organization names
This commit is contained in:
parent
93b1e7f9fa
commit
8a4c599d9e
1 changed files with 10 additions and 0 deletions
|
@ -84,6 +84,7 @@ import java.text.DecimalFormat;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
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;
|
import static androidx.browser.customtabs.CustomTabsService.ACTION_CUSTOM_TABS_CONNECTION;
|
||||||
|
|
||||||
public class Helper {
|
public class Helper {
|
||||||
|
private static Map<String, String> hostOrganization = new HashMap<>();
|
||||||
|
|
||||||
static final int NOTIFICATION_SYNCHRONIZE = 1;
|
static final int NOTIFICATION_SYNCHRONIZE = 1;
|
||||||
static final int NOTIFICATION_SEND = 2;
|
static final int NOTIFICATION_SEND = 2;
|
||||||
static final int NOTIFICATION_EXTERNAL = 3;
|
static final int NOTIFICATION_EXTERNAL = 3;
|
||||||
|
@ -1018,6 +1021,10 @@ public class Helper {
|
||||||
}
|
}
|
||||||
|
|
||||||
static String getOrganization(String host) throws IOException {
|
static String getOrganization(String host) throws IOException {
|
||||||
|
synchronized (hostOrganization) {
|
||||||
|
if (hostOrganization.containsKey(host))
|
||||||
|
return hostOrganization.get(host);
|
||||||
|
}
|
||||||
InetAddress address = InetAddress.getByName(host);
|
InetAddress address = InetAddress.getByName(host);
|
||||||
URL url = new URL("https://ipinfo.io/" + address.getHostAddress() + "/org");
|
URL url = new URL("https://ipinfo.io/" + address.getHostAddress() + "/org");
|
||||||
HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
|
HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
|
||||||
|
@ -1028,6 +1035,9 @@ public class Helper {
|
||||||
String organization = reader.readLine();
|
String organization = reader.readLine();
|
||||||
if ("undefined".equals(organization))
|
if ("undefined".equals(organization))
|
||||||
organization = null;
|
organization = null;
|
||||||
|
synchronized (hostOrganization) {
|
||||||
|
hostOrganization.put(host, organization);
|
||||||
|
}
|
||||||
return organization;
|
return organization;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue