|
9 | 9 | import android.widget.EditText; |
10 | 10 | import android.widget.RadioGroup; |
11 | 11 | import android.widget.TextView; |
| 12 | + |
| 13 | +import androidx.annotation.NonNull; |
12 | 14 | import androidx.annotation.RequiresApi; |
13 | 15 | import androidx.appcompat.app.AlertDialog; |
14 | 16 | import com.liskovsoft.sharedutils.helpers.Helpers; |
@@ -37,7 +39,7 @@ public class WebProxyDialog { |
37 | 39 | public WebProxyDialog(Context context) { |
38 | 40 | mContext = context; |
39 | 41 | mProxyManager = new ProxyManager(mContext); |
40 | | - mProxyTestHandler = new Handler(Looper.myLooper()); |
| 42 | + mProxyTestHandler = new Handler(Looper.getMainLooper()); |
41 | 43 | mUrlTests = new ArrayList<>(); |
42 | 44 | } |
43 | 45 |
|
@@ -128,25 +130,27 @@ protected void testProxyConnections() { |
128 | 130 |
|
129 | 131 | for (String urlString: testUrls) { |
130 | 132 | int serialNo = ++ mNumTests; |
131 | | - Request request = new Request.Builder().url(urlString).build(); |
| 133 | + Request request = new Request.Builder().url(urlString).head().build(); |
132 | 134 | appendStatusMessage(R.string.proxy_test_start, serialNo, urlString); |
133 | 135 | Call call = okHttpClient.newCall(request); |
134 | 136 | call.enqueue(new Callback() { |
135 | 137 | @Override |
136 | | - public void onFailure(Call call, IOException e) { |
| 138 | + public void onFailure(@NonNull Call call, @NonNull IOException e) { |
137 | 139 | if (call.isCanceled()) |
138 | 140 | mProxyTestHandler.post(() -> appendStatusMessage(R.string.proxy_test_cancelled, serialNo)); |
139 | 141 | else |
140 | 142 | mProxyTestHandler.post(() -> appendStatusMessage(R.string.proxy_test_error, serialNo, e)); |
141 | 143 | } |
142 | 144 |
|
143 | 145 | @Override |
144 | | - public void onResponse(Call call, Response response) { |
145 | | - String protocol = response.protocol().toString().toUpperCase(); |
146 | | - int code = response.code(); |
147 | | - String status = response.message(); |
148 | | - mProxyTestHandler.post(() -> appendStatusMessage(R.string.proxy_test_status, |
149 | | - serialNo, protocol, code, status.isEmpty() ? "OK" : status)); |
| 146 | + public void onResponse(@NonNull Call call, @NonNull Response response) { |
| 147 | + try (Response ignored = response) { |
| 148 | + String protocol = response.protocol().toString().toUpperCase(); |
| 149 | + int code = response.code(); |
| 150 | + String status = response.message(); |
| 151 | + mProxyTestHandler.post(() -> appendStatusMessage(R.string.proxy_test_status, |
| 152 | + serialNo, protocol, code, status.isEmpty() ? "OK" : status)); |
| 153 | + } |
150 | 154 | } |
151 | 155 | }); |
152 | 156 | mUrlTests.add(call); |
|
0 commit comments