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

Method getFavicon

app/src/main/java/eu/faircode/email/ContactInfo.java:972–1000  ·  view source on GitHub ↗
(URL url, String mimeType, int scaleToPixels, Context context)

Source from the content-addressed store, hash-verified

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) {

Callers 2

callMethod · 0.95
parseFaviconMethod · 0.95

Calls 11

iMethod · 0.95
openConnectionUnsafeMethod · 0.95
getScaledBitmapMethod · 0.95
getInputStreamMethod · 0.65
getHeightMethod · 0.65
getMessageMethod · 0.65
equalsMethod · 0.45
getProtocolMethod · 0.45
toStringMethod · 0.45
getWidthMethod · 0.45
disconnectMethod · 0.45

Tested by

no test coverage detected