MCPcopy Create free account
hub / github.com/M66B/FairEmail / download

Method download

app/src/main/java/eu/faircode/email/Adguard.java:390–416  ·  view source on GitHub ↗
(Context context)

Source from the content-addressed store, hash-verified

388 }
389
390 static void download(Context context) throws IOException, JSONException {
391 File file = getFile(context);
392
393 URL url = new URL(LIST);
394 Log.i("GET " + url);
395 HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
396 connection.setRequestMethod("GET");
397 connection.setReadTimeout(FETCH_TIMEOUT);
398 connection.setConnectTimeout(FETCH_TIMEOUT);
399 ConnectionHelper.setUserAgent(context, connection);
400 connection.connect();
401
402 try {
403 int status = connection.getResponseCode();
404 if (status != HttpsURLConnection.HTTP_OK)
405 throw new FileNotFoundException("Error " + status + ": " + connection.getResponseMessage());
406
407 try (OutputStream os = new BufferedOutputStream(new FileOutputStream(file))) {
408 Helper.copy(connection.getInputStream(), os);
409 }
410
411 SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
412 prefs.edit().putLong("adguard_last", new Date().getTime()).apply();
413 } finally {
414 connection.disconnect();
415 }
416 }
417
418 private static File getFile(Context context) {
419 return new File(context.getFilesDir(), "adguard.txt");

Callers 3

doWorkMethod · 0.95
onExecuteMethod · 0.95
adguardMethod · 0.95

Calls 8

getFileMethod · 0.95
iMethod · 0.95
setUserAgentMethod · 0.95
copyMethod · 0.95
getInputStreamMethod · 0.65
connectMethod · 0.45
applyMethod · 0.45
disconnectMethod · 0.45

Tested by

no test coverage detected