package com.google.firebase.messaging; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.text.TextUtils; import android.util.Log; import com.google.android.gms.common.internal.Preconditions; import com.google.android.gms.tasks.Task; import com.google.android.gms.tasks.TaskCompletionSource; import java.io.Closeable; import java.io.IOException; import java.io.InputStream; import java.net.MalformedURLException; import java.net.URL; import java.net.URLConnection; import java.util.concurrent.ExecutorService; import java.util.concurrent.Future; /* loaded from: classes2.dex */ public class d0 implements Closeable { /* renamed from: a, reason: collision with root package name */ private final URL f5567a; /* renamed from: b, reason: collision with root package name */ private volatile Future f5568b; /* renamed from: c, reason: collision with root package name */ private Task f5569c; private d0(URL url) { this.f5567a = url; } private byte[] G() { URLConnection openConnection = this.f5567a.openConnection(); if (openConnection.getContentLength() > 1048576) { throw new IOException("Content-Length exceeds max size of 1048576"); } InputStream inputStream = openConnection.getInputStream(); try { byte[] d10 = b.d(b.b(inputStream, 1048577L)); if (inputStream != null) { inputStream.close(); } if (Log.isLoggable("FirebaseMessaging", 2)) { Log.v("FirebaseMessaging", "Downloaded " + d10.length + " bytes from " + this.f5567a); } if (d10.length <= 1048576) { return d10; } throw new IOException("Image exceeds max size of 1048576"); } catch (Throwable th) { if (inputStream != null) { try { inputStream.close(); } catch (Throwable th2) { th.addSuppressed(th2); } } throw th; } } public static d0 I(String str) { if (TextUtils.isEmpty(str)) { return null; } try { return new d0(new URL(str)); } catch (MalformedURLException unused) { Log.w("FirebaseMessaging", "Not downloading image, bad URL: " + str); return null; } } /* JADX INFO: Access modifiers changed from: private */ public /* synthetic */ void P(TaskCompletionSource taskCompletionSource) { try { taskCompletionSource.setResult(z()); } catch (Exception e10) { taskCompletionSource.setException(e10); } } public Task O() { return (Task) Preconditions.checkNotNull(this.f5569c); } public void R(ExecutorService executorService) { final TaskCompletionSource taskCompletionSource = new TaskCompletionSource(); this.f5568b = executorService.submit(new Runnable() { // from class: com.google.firebase.messaging.c0 @Override // java.lang.Runnable public final void run() { d0.this.P(taskCompletionSource); } }); this.f5569c = taskCompletionSource.getTask(); } @Override // java.io.Closeable, java.lang.AutoCloseable public void close() { this.f5568b.cancel(true); } public Bitmap z() { if (Log.isLoggable("FirebaseMessaging", 4)) { Log.i("FirebaseMessaging", "Starting download of: " + this.f5567a); } byte[] G = G(); Bitmap decodeByteArray = BitmapFactory.decodeByteArray(G, 0, G.length); if (decodeByteArray == null) { throw new IOException("Failed to decode image: " + this.f5567a); } if (Log.isLoggable("FirebaseMessaging", 3)) { Log.d("FirebaseMessaging", "Successfully downloaded image: " + this.f5567a); } return decodeByteArray; } }