(URL url, String mimeType, int scaleToPixels, Context context)
| 970 | } |
| 971 | |
| 972 | @NonNull |
| 973 | private static Favicon getFavicon(URL url, String mimeType, int scaleToPixels, Context context) throws IOException { |
| 974 | Log.i("GET favicon " + url); |
| 975 | |
| 976 | if (!"https".equals(url.getProtocol())) |
| 977 | throw new FileNotFoundException(url.toString()); |
| 978 | |
| 979 | HttpURLConnection connection = ConnectionHelper |
| 980 | .openConnectionUnsafe(context, url, FAVICON_CONNECT_TIMEOUT, FAVICON_READ_TIMEOUT); |
| 981 | |
| 982 | try { |
| 983 | int status = connection.getResponseCode(); |
| 984 | if (status != HttpURLConnection.HTTP_OK) |
| 985 | throw new FileNotFoundException("Error " + status + ": " + connection.getResponseMessage()); |
| 986 | |
| 987 | Bitmap bitmap = ImageHelper.getScaledBitmap(connection.getInputStream(), url.toString(), mimeType, scaleToPixels); |
| 988 | if (bitmap == null) |
| 989 | throw new FileNotFoundException("decodeStream"); |
| 990 | if (bitmap.getWidth() <= 1 || bitmap.getHeight() <= 1) |
| 991 | throw new IOException("Too small"); |
| 992 | Log.i("GOT favicon " + url); |
| 993 | return new Favicon(bitmap, url.toString()); |
| 994 | } catch (Throwable ex) { |
| 995 | Log.i("GET favicon " + url + " error=" + ex.getMessage()); |
| 996 | throw ex; |
| 997 | } finally { |
| 998 | connection.disconnect(); |
| 999 | } |
| 1000 | } |
| 1001 | |
| 1002 | private static boolean isRecoverable(Throwable ex, Context context) { |
| 1003 | if (ex instanceof SocketTimeoutException) { |
no test coverage detected