From 276e867f9a1b6df89dc1b7ef9eb1654870f02ab3 Mon Sep 17 00:00:00 2001 From: Greyson Parrelli Date: Sat, 23 Feb 2019 10:59:42 -0800 Subject: [PATCH] Improved address resolution for ContentProxySelector. We can use an unresolved address to avoid all the threading stuff in that class. --- .../securesms/net/ContentProxySelector.java | 45 +++---------------- 1 file changed, 7 insertions(+), 38 deletions(-) diff --git a/src/org/thoughtcrime/securesms/net/ContentProxySelector.java b/src/org/thoughtcrime/securesms/net/ContentProxySelector.java index 60b31b1cee..5e1ff5f1eb 100644 --- a/src/org/thoughtcrime/securesms/net/ContentProxySelector.java +++ b/src/org/thoughtcrime/securesms/net/ContentProxySelector.java @@ -24,36 +24,23 @@ public class ContentProxySelector extends ProxySelector { private static final String TAG = ContentProxySelector.class.getSimpleName(); - public static final Set WHITELISTED_DOMAINS = new HashSet<>(); + private static final Set WHITELISTED_DOMAINS = new HashSet<>(); static { WHITELISTED_DOMAINS.addAll(LinkPreviewDomains.LINKS); WHITELISTED_DOMAINS.addAll(LinkPreviewDomains.IMAGES); WHITELISTED_DOMAINS.add("giphy.com"); } - private final List EMPTY = new ArrayList<>(1); - private volatile List CONTENT = null; - - public ContentProxySelector() { - EMPTY.add(Proxy.NO_PROXY); - - if (Util.isMainThread()) { - AsyncTask.THREAD_POOL_EXECUTOR.execute(() -> { - synchronized (ContentProxySelector.this) { - initializeContentProxy(); - ContentProxySelector.this.notifyAll(); - } - }); - } else { - initializeContentProxy(); - } - } + private final List CONTENT = new ArrayList(1) {{ + add(new Proxy(Proxy.Type.HTTP, InetSocketAddress.createUnresolved(BuildConfig.CONTENT_PROXY_HOST, + BuildConfig.CONTENT_PROXY_PORT))); + }}; @Override public List select(URI uri) { for (String domain : WHITELISTED_DOMAINS) { if (uri.getHost().endsWith(domain)) { - return getOrCreateContentProxy(); + return CONTENT; } } throw new IllegalArgumentException("Tried to proxy a non-whitelisted domain."); @@ -61,24 +48,6 @@ public class ContentProxySelector extends ProxySelector { @Override public void connectFailed(URI uri, SocketAddress address, IOException failure) { - Log.w(TAG, failure); + Log.w(TAG, "Connection failed.", failure); } - - private void initializeContentProxy() { - CONTENT = new ArrayList(1) {{ - add(new Proxy(Proxy.Type.HTTP, new InetSocketAddress(BuildConfig.CONTENT_PROXY_HOST, - BuildConfig.CONTENT_PROXY_PORT))); - }}; - } - - private List getOrCreateContentProxy() { - if (CONTENT == null) { - synchronized (this) { - while (CONTENT == null) Util.wait(this, 0); - } - } - - return CONTENT; - } - }