|
6 | 6 | import androidx.annotation.Nullable;
|
7 | 7 | import androidx.annotation.VisibleForTesting;
|
8 | 8 |
|
| 9 | +import java.util.concurrent.Callable; |
| 10 | +import java.util.concurrent.Executors; |
9 | 11 | import org.wikipedia.AppAdapter;
|
10 | 12 | import org.wikipedia.dataclient.Service;
|
11 | 13 | import org.wikipedia.dataclient.ServiceFactory;
|
@@ -142,7 +144,9 @@ public void error(@NonNull Throwable caught) {
|
142 | 144 | AppAdapter.get().getPassword(), "");
|
143 | 145 | }
|
144 | 146 |
|
145 |
| - Response<MwQueryResponse> response = service.getCsrfTokenCall().execute(); |
| 147 | + // Get CSRFToken response off the main thread. |
| 148 | + Response<MwQueryResponse> response = Executors.newSingleThreadExecutor().submit(new CsrfTokenCallExecutor(service)).get(); |
| 149 | + |
146 | 150 | if (response.body() == null || response.body().query() == null
|
147 | 151 | || TextUtils.isEmpty(response.body().query().csrfToken())) {
|
148 | 152 | continue;
|
@@ -210,4 +214,34 @@ public void twoFactorPrompt() {
|
210 | 214 | private interface RetryCallback {
|
211 | 215 | void retry();
|
212 | 216 | }
|
| 217 | + |
| 218 | + /** |
| 219 | + * Class CsrfTokenCallExecutor which implement callable interface to get CsrfTokenCall. |
| 220 | + */ |
| 221 | + class CsrfTokenCallExecutor implements Callable<Response<MwQueryResponse>> { |
| 222 | + |
| 223 | + /** |
| 224 | + * Service for token call. |
| 225 | + */ |
| 226 | + private Service service; |
| 227 | + |
| 228 | + /** |
| 229 | + * Default Constructor. |
| 230 | + * @param service |
| 231 | + */ |
| 232 | + public CsrfTokenCallExecutor(Service service){ |
| 233 | + this.service = service; |
| 234 | + } |
| 235 | + |
| 236 | + /** |
| 237 | + * Computes a result, or throws an exception if unable to do so. |
| 238 | + * |
| 239 | + * @return computed result |
| 240 | + * @throws Exception if unable to compute a result |
| 241 | + */ |
| 242 | + @Override |
| 243 | + public Response<MwQueryResponse> call() throws Exception { |
| 244 | + return service.getCsrfTokenCall().execute(); |
| 245 | + } |
| 246 | + } |
213 | 247 | }
|
0 commit comments