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.internal.firebase_messaging.zzm; import com.google.android.gms.tasks.Task; import com.google.android.gms.tasks.Tasks; 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.Callable; import java.util.concurrent.Executor; /* JADX INFO: Access modifiers changed from: package-private */ /* loaded from: classes2.dex */ public final class zzq implements Closeable { private final URL zza; private Task zzb; private volatile InputStream zzc; public static zzq zza(String str) { if (TextUtils.isEmpty(str)) { return null; } try { return new zzq(new URL(str)); } catch (MalformedURLException unused) { return null; } } private zzq(URL url) { this.zza = url; } public final void zza(Executor executor) { this.zzb = Tasks.call(executor, new Callable(this) { // from class: com.google.firebase.messaging.zzs private final zzq zza; @Override // java.util.concurrent.Callable public final Object call() { return this.zza.zzb(); } /* JADX INFO: Access modifiers changed from: package-private */ { this.zza = this; } }); } public final Task zza() { return (Task) Preconditions.checkNotNull(this.zzb); } public final Bitmap zzb() throws IOException { byte[] zzc = zzc(); Bitmap decodeByteArray = BitmapFactory.decodeByteArray(zzc, 0, zzc.length); if (decodeByteArray == null) { String valueOf = String.valueOf(this.zza); StringBuilder sb = new StringBuilder(String.valueOf(valueOf).length() + 24); sb.append("Failed to decode image: "); sb.append(valueOf); throw new IOException(sb.toString()); } Log.isLoggable("FirebaseMessaging", 3); return decodeByteArray; } private final byte[] zzc() throws IOException { URLConnection openConnection = this.zza.openConnection(); if (openConnection.getContentLength() > 1048576) { throw new IOException("Content-Length exceeds max size of 1048576"); } InputStream inputStream = openConnection.getInputStream(); try { this.zzc = inputStream; byte[] zza = com.google.android.gms.internal.firebase_messaging.zzj.zza(com.google.android.gms.internal.firebase_messaging.zzj.zza(inputStream, 1048577L)); if (inputStream != null) { inputStream.close(); } if (Log.isLoggable("FirebaseMessaging", 2)) { int length = zza.length; } if (zza.length <= 1048576) { return zza; } throw new IOException("Image exceeds max size of 1048576"); } catch (Throwable th) { if (inputStream != null) { try { inputStream.close(); } catch (Throwable th2) { zzm.zza(th, th2); } } throw th; } } @Override // java.io.Closeable, java.lang.AutoCloseable public final void close() { try { com.google.android.gms.internal.firebase_messaging.zzk.zza(this.zzc); } catch (NullPointerException unused) { } } }