Link image download timeout to connection timeout

pull/194/head
M66B 5 years ago
parent 3f6b1be23d
commit 941cdbc393

@ -361,8 +361,6 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
private static final long REVIEW_ASK_DELAY = 14 * 24 * 3600 * 1000L; // milliseconds private static final long REVIEW_ASK_DELAY = 14 * 24 * 3600 * 1000L; // milliseconds
private static final long REVIEW_LATER_DELAY = 3 * 24 * 3600 * 1000L; // milliseconds private static final long REVIEW_LATER_DELAY = 3 * 24 * 3600 * 1000L; // milliseconds
private static final int PRINT_IMAGE_TIMEOUT = 15 * 1000; // milliseconds
static final List<String> SORT_DATE_HEADER = Collections.unmodifiableList(Arrays.asList( static final List<String> SORT_DATE_HEADER = Collections.unmodifiableList(Arrays.asList(
"time", "unread", "starred", "priority" "time", "unread", "starred", "priority"
)); ));
@ -7365,6 +7363,9 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
boolean print_html_header = args.getBoolean("print_html_header"); boolean print_html_header = args.getBoolean("print_html_header");
boolean print_html_images = args.getBoolean("print_html_images"); boolean print_html_images = args.getBoolean("print_html_images");
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
int timeout = prefs.getInt("timeout", ImageHelper.DOWNLOAD_TIMEOUT) * 1000;
DB db = DB.getInstance(context); DB db = DB.getInstance(context);
EntityMessage message = db.message().getMessage(id); EntityMessage message = db.message().getMessage(id);
if (message == null || !message.content) if (message == null || !message.content)
@ -7409,8 +7410,8 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
HttpURLConnection connection = (HttpURLConnection) url.openConnection(); HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET"); connection.setRequestMethod("GET");
connection.setReadTimeout(PRINT_IMAGE_TIMEOUT); connection.setReadTimeout(timeout);
connection.setConnectTimeout(PRINT_IMAGE_TIMEOUT); connection.setConnectTimeout(timeout);
connection.setInstanceFollowRedirects(true); connection.setInstanceFollowRedirects(true);
connection.connect(); connection.connect();

@ -82,7 +82,7 @@ class ImageHelper {
private static final ExecutorService executor_n = private static final ExecutorService executor_n =
Helper.getBackgroundExecutor(0, "image_n"); Helper.getBackgroundExecutor(0, "image_n");
private static final int DOWNLOAD_TIMEOUT = 15 * 1000; // milliseconds static final int DOWNLOAD_TIMEOUT = 15; // seconds
private static final int MAX_REDIRECTS = 5; // https://www.freesoft.org/CIE/RFC/1945/46.htm private static final int MAX_REDIRECTS = 5; // https://www.freesoft.org/CIE/RFC/1945/46.htm
private static final int MAX_PROBE = 64 * 1024; // bytes private static final int MAX_PROBE = 64 * 1024; // bytes
private static final int SLOW_CONNECTION = 2 * 1024; // Kbps private static final int SLOW_CONNECTION = 2 * 1024; // Kbps
@ -601,6 +601,9 @@ class ImageHelper {
Resources res = context.getResources(); Resources res = context.getResources();
DisplayMetrics dm = res.getDisplayMetrics(); DisplayMetrics dm = res.getDisplayMetrics();
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
int timeout = prefs.getInt("timeout", ImageHelper.DOWNLOAD_TIMEOUT) * 1000;
Bitmap bm; Bitmap bm;
HttpURLConnection urlConnection = null; HttpURLConnection urlConnection = null;
try { try {
@ -616,8 +619,8 @@ class ImageHelper {
urlConnection = (HttpURLConnection) url.openConnection(); urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setRequestMethod("GET"); urlConnection.setRequestMethod("GET");
urlConnection.setDoOutput(false); urlConnection.setDoOutput(false);
urlConnection.setReadTimeout(DOWNLOAD_TIMEOUT); urlConnection.setReadTimeout(timeout);
urlConnection.setConnectTimeout(DOWNLOAD_TIMEOUT); urlConnection.setConnectTimeout(timeout);
urlConnection.setInstanceFollowRedirects(true); urlConnection.setInstanceFollowRedirects(true);
if (BuildConfig.DEBUG) if (BuildConfig.DEBUG)
urlConnection.setRequestProperty("User-Agent", ua); urlConnection.setRequestProperty("User-Agent", ua);

Loading…
Cancel
Save