package com.igaworks.ssp.common.k; import android.content.Context; import android.graphics.Bitmap; import android.os.Handler; import android.os.Looper; import android.widget.ImageView; import com.google.android.gms.auth.api.proxy.AuthApiStatusCodes; import com.igaworks.ssp.SSPErrorCode; import com.igaworks.ssp.common.k.a; import java.io.File; import java.io.FileOutputStream; import java.io.InputStream; import java.lang.ref.WeakReference; import java.net.HttpURLConnection; import java.net.URL; import java.net.URLConnection; import java.security.MessageDigest; /* loaded from: classes2.dex */ public class b extends Thread { /* renamed from: n, reason: collision with root package name */ private static Handler f6687n = new Handler(Looper.getMainLooper()); /* renamed from: a, reason: collision with root package name */ public String f6688a; /* renamed from: b, reason: collision with root package name */ public String f6689b; /* renamed from: c, reason: collision with root package name */ private WeakReference f6690c; /* renamed from: d, reason: collision with root package name */ private a.c f6691d; /* renamed from: e, reason: collision with root package name */ private a.d f6692e; /* renamed from: f, reason: collision with root package name */ private boolean f6693f; /* renamed from: g, reason: collision with root package name */ private boolean f6694g; /* renamed from: h, reason: collision with root package name */ private b f6695h; /* renamed from: i, reason: collision with root package name */ private boolean f6696i; /* renamed from: j, reason: collision with root package name */ private boolean f6697j; /* renamed from: k, reason: collision with root package name */ private Context f6698k; /* renamed from: l, reason: collision with root package name */ private int f6699l; /* renamed from: m, reason: collision with root package name */ private int f6700m; class a implements Runnable { /* renamed from: a, reason: collision with root package name */ final /* synthetic */ Bitmap f6701a; a(Bitmap bitmap) { this.f6701a = bitmap; } @Override // java.lang.Runnable public void run() { try { if (b.this.f6694g) { return; } if (b.this.f6693f) { if (this.f6701a != null && !b.this.f6696i) { com.igaworks.ssp.common.k.a.f6683a.put(b.this.f6689b, this.f6701a); } if (b.this.f6692e != null) { b.this.f6692e.a(this.f6701a); return; } return; } if (b.this.f6690c != null) { ImageView imageView = (ImageView) b.this.f6690c.get(); if (b.this.f6695h != b.this.a(imageView)) { if (this.f6701a == null || b.this.f6696i) { return; } com.igaworks.ssp.common.k.a.f6683a.put(b.this.f6689b, this.f6701a); return; } if (!b.this.f6696i) { com.igaworks.ssp.common.k.a.f6683a.put(b.this.f6689b, this.f6701a); } Bitmap bitmap = this.f6701a; if (bitmap != null) { imageView.setImageBitmap(bitmap); } } } catch (Exception e10) { e10.printStackTrace(); } } } public b(Context context, String str, ImageView imageView, a.d dVar, int i10, int i11) { this.f6696i = false; this.f6697j = false; this.f6698k = context; this.f6689b = str; this.f6690c = new WeakReference<>(imageView); this.f6692e = dVar; this.f6693f = true; this.f6694g = false; this.f6695h = this; this.f6696i = false; this.f6697j = false; this.f6699l = i10; this.f6700m = i11; } /* JADX WARN: Can't wrap try/catch for region: R(10:61|62|(2:63|64)|66|67|68|69|70|71|72) */ /* JADX WARN: Can't wrap try/catch for region: R(18:20|21|(2:22|(1:24)(1:25))|26|27|28|(11:32|33|34|35|36|37|38|39|40|41|42)|53|33|34|35|36|37|38|39|40|41|42) */ /* JADX WARN: Code restructure failed: missing block: B:115:0x0262, code lost: if (r2 != null) goto L132; */ /* JADX WARN: Code restructure failed: missing block: B:125:0x0248, code lost: if (r2 != null) goto L132; */ /* JADX WARN: Code restructure failed: missing block: B:44:0x014c, code lost: r12 = move-exception; */ /* JADX WARN: Code restructure failed: missing block: B:45:0x014d, code lost: com.igaworks.ssp.common.o.m.a.a(java.lang.Thread.currentThread(), r12); */ /* JADX WARN: Code restructure failed: missing block: B:50:0x0125, code lost: r12 = move-exception; */ /* JADX WARN: Code restructure failed: missing block: B:51:0x0126, code lost: com.igaworks.ssp.common.o.m.a.a(java.lang.Thread.currentThread(), r12); */ /* JADX WARN: Code restructure failed: missing block: B:77:0x019a, code lost: r12 = e; */ /* JADX WARN: Code restructure failed: missing block: B:78:0x019b, code lost: r13 = java.lang.Thread.currentThread(); */ /* JADX WARN: Multi-variable type inference failed */ /* JADX WARN: Not initialized variable reg: 4, insn: 0x0269: MOVE (r1 I:??[OBJECT, ARRAY]) = (r4 I:??[OBJECT, ARRAY]), block:B:150:0x0269 */ /* JADX WARN: Removed duplicated region for block: B:140:0x027d */ /* JADX WARN: Removed duplicated region for block: B:142:? A[SYNTHETIC] */ /* JADX WARN: Type inference failed for: r5v2, types: [byte[], java.io.InputStream] */ /* JADX WARN: Type inference failed for: r6v1, types: [int, java.io.InputStream] */ /* Code decompiled incorrectly, please refer to instructions dump. To view partially-correct code enable 'Show inconsistent code' option in preferences */ public static android.graphics.Bitmap a(android.content.Context r12, java.lang.String r13, int r14, int r15) { /* Method dump skipped, instructions count: 641 To view this dump change 'Code comments level' option to 'DEBUG' */ throw new UnsupportedOperationException("Method not decompiled: com.igaworks.ssp.common.k.b.a(android.content.Context, java.lang.String, int, int):android.graphics.Bitmap"); } public void b(String str) { try { HttpURLConnection httpURLConnection = (HttpURLConnection) new URL(str).openConnection(); httpURLConnection.setRequestMethod("GET"); httpURLConnection.setDoInput(true); httpURLConnection.setReadTimeout(SSPErrorCode.SERVER_TIMEOUT); httpURLConnection.setConnectTimeout(AuthApiStatusCodes.AUTH_API_INVALID_CREDENTIALS); InputStream a10 = a(httpURLConnection); int contentLength = httpURLConnection.getContentLength(); try { try { } catch (Throwable th) { a10.close(); httpURLConnection.disconnect(); throw th; } } catch (OutOfMemoryError e10) { e10.printStackTrace(); System.gc(); } if (a10 != null) { try { try { a(str, a10, contentLength); } finally { a10.close(); } } catch (OutOfMemoryError e11) { e11.printStackTrace(); System.gc(); } httpURLConnection.disconnect(); } } catch (Exception e12) { e12.printStackTrace(); } a.d dVar = this.f6692e; if (dVar != null) { dVar.a(null); } } @Override // java.lang.Thread, java.lang.Runnable public void run() { super.run(); if (this.f6697j) { b(this.f6689b); } else { a(a(this.f6698k, this.f6689b, this.f6699l, this.f6700m)); } } public b(Context context, String str, a.d dVar, int i10, int i11) { this.f6696i = false; this.f6698k = context; this.f6689b = str; this.f6693f = true; this.f6694g = false; this.f6695h = this; this.f6697j = true; this.f6692e = dVar; this.f6699l = i10; this.f6700m = i11; } /* JADX INFO: Access modifiers changed from: private */ public b a(ImageView imageView) { if (imageView != null) { return this.f6691d.a(); } return null; } private static InputStream a(URLConnection uRLConnection) { boolean z10; HttpURLConnection httpURLConnection; int responseCode; InputStream inputStream = null; int i10 = 0; do { try { if (uRLConnection instanceof HttpURLConnection) { ((HttpURLConnection) uRLConnection).setInstanceFollowRedirects(false); } inputStream = uRLConnection.getInputStream(); if ((uRLConnection instanceof HttpURLConnection) && (responseCode = (httpURLConnection = (HttpURLConnection) uRLConnection).getResponseCode()) >= 300 && responseCode <= 307 && responseCode != 306 && responseCode != 304) { URL url = httpURLConnection.getURL(); String headerField = httpURLConnection.getHeaderField("Location"); URL url2 = headerField != null ? new URL(url, headerField) : null; httpURLConnection.disconnect(); if (url2 != null && ((url2.getProtocol().equals("http") || url2.getProtocol().equals("https")) && i10 < 5)) { uRLConnection = url2.openConnection(); i10++; z10 = true; } return null; } z10 = false; } catch (Exception e10) { com.igaworks.ssp.common.o.m.a.a(Thread.currentThread(), e10); } } while (z10); return inputStream; } private static String a(String str) { try { MessageDigest messageDigest = MessageDigest.getInstance("MD5"); messageDigest.update(str.getBytes()); byte[] digest = messageDigest.digest(); return String.format("%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X", Byte.valueOf(digest[0]), Byte.valueOf(digest[1]), Byte.valueOf(digest[2]), Byte.valueOf(digest[3]), Byte.valueOf(digest[4]), Byte.valueOf(digest[5]), Byte.valueOf(digest[6]), Byte.valueOf(digest[7]), Byte.valueOf(digest[8]), Byte.valueOf(digest[9]), Byte.valueOf(digest[10]), Byte.valueOf(digest[11]), Byte.valueOf(digest[12]), Byte.valueOf(digest[13]), Byte.valueOf(digest[14]), Byte.valueOf(digest[15])); } catch (Exception unused) { return null; } } private static void a(Context context, String str, Bitmap bitmap) { Exception e10; FileOutputStream fileOutputStream = null; try { try { File file = new File(context.getCacheDir() + "/igaw/image"); if (!file.exists()) { file.mkdirs(); } String a10 = a(str); if (a10 != null && a10.length() > 0) { File file2 = new File(file, a10); if (file2.exists()) { file2.delete(); file2.createNewFile(); } FileOutputStream fileOutputStream2 = new FileOutputStream(file2); try { bitmap.compress(Bitmap.CompressFormat.PNG, 100, fileOutputStream2); fileOutputStream = fileOutputStream2; } catch (Exception e11) { e10 = e11; fileOutputStream = fileOutputStream2; e10.printStackTrace(); if (fileOutputStream == null) { return; } fileOutputStream.close(); } catch (Throwable th) { fileOutputStream = fileOutputStream2; th = th; if (fileOutputStream != null) { try { fileOutputStream.close(); } catch (Exception e12) { e12.printStackTrace(); } } throw th; } } if (fileOutputStream == null) { return; } } catch (Throwable th2) { th = th2; } } catch (Exception e13) { e10 = e13; } try { fileOutputStream.close(); } catch (Exception e14) { e14.printStackTrace(); } } public void a(Bitmap bitmap) { try { if (f6687n == null) { f6687n = new Handler(Looper.getMainLooper()); } f6687n.post(new a(bitmap)); } catch (Exception e10) { com.igaworks.ssp.common.o.m.a.a(Thread.currentThread(), e10); } } public void a(a.c cVar) { this.f6691d = cVar; } /* JADX WARN: Removed duplicated region for block: B:45:0x0089 A[Catch: all -> 0x009a, TRY_LEAVE, TryCatch #3 {all -> 0x009a, blocks: (B:43:0x0084, B:45:0x0089), top: B:42:0x0084 }] */ /* JADX WARN: Removed duplicated region for block: B:48:0x008e A[Catch: Exception -> 0x0095, TRY_ENTER, TRY_LEAVE, TryCatch #5 {Exception -> 0x0095, blocks: (B:27:0x007b, B:48:0x008e), top: B:2:0x0001 }] */ /* JADX WARN: Removed duplicated region for block: B:49:? A[RETURN, SYNTHETIC] */ /* JADX WARN: Removed duplicated region for block: B:54:0x009e A[EXC_TOP_SPLITTER, SYNTHETIC] */ /* Code decompiled incorrectly, please refer to instructions dump. To view partially-correct code enable 'Show inconsistent code' option in preferences */ private void a(java.lang.String r5, java.io.InputStream r6, int r7) { /* r4 = this; r0 = 0 java.io.File r1 = new java.io.File // Catch: java.lang.Throwable -> L27 java.lang.Exception -> L82 java.lang.StringBuilder r2 = new java.lang.StringBuilder // Catch: java.lang.Throwable -> L27 java.lang.Exception -> L82 r2.() // Catch: java.lang.Throwable -> L27 java.lang.Exception -> L82 android.content.Context r3 = r4.f6698k // Catch: java.lang.Throwable -> L27 java.lang.Exception -> L82 java.io.File r3 = r3.getCacheDir() // Catch: java.lang.Throwable -> L27 java.lang.Exception -> L82 r2.append(r3) // Catch: java.lang.Throwable -> L27 java.lang.Exception -> L82 java.lang.String r3 = "/igaw/video" r2.append(r3) // Catch: java.lang.Throwable -> L27 java.lang.Exception -> L82 java.lang.String r2 = r2.toString() // Catch: java.lang.Throwable -> L27 java.lang.Exception -> L82 r1.(r2) // Catch: java.lang.Throwable -> L27 java.lang.Exception -> L82 boolean r2 = r1.exists() // Catch: java.lang.Throwable -> L27 java.lang.Exception -> L82 if (r2 != 0) goto L2a r1.mkdirs() // Catch: java.lang.Throwable -> L27 java.lang.Exception -> L82 goto L2a L27: r5 = move-exception goto L9c L2a: java.lang.String r5 = a(r5) // Catch: java.lang.Throwable -> L27 java.lang.Exception -> L82 if (r5 == 0) goto L5e int r2 = r5.length() // Catch: java.lang.Throwable -> L27 java.lang.Exception -> L82 if (r2 <= 0) goto L5e java.io.File r2 = new java.io.File // Catch: java.lang.Throwable -> L27 java.lang.Exception -> L82 r2.(r1, r5) // Catch: java.lang.Throwable -> L27 java.lang.Exception -> L82 boolean r5 = r2.exists() // Catch: java.lang.Throwable -> L27 java.lang.Exception -> L5c if (r5 == 0) goto L44 r2.delete() // Catch: java.lang.Throwable -> L27 java.lang.Exception -> L5c L44: java.io.FileOutputStream r5 = new java.io.FileOutputStream // Catch: java.lang.Throwable -> L27 java.lang.Exception -> L5c r5.(r2) // Catch: java.lang.Throwable -> L27 java.lang.Exception -> L5c r0 = 1024(0x400, float:1.435E-42) byte[] r0 = new byte[r0] // Catch: java.lang.Exception -> L5a java.lang.Throwable -> L6e L4d: int r1 = r6.read(r0) // Catch: java.lang.Exception -> L5a java.lang.Throwable -> L6e if (r1 <= 0) goto L58 r3 = 0 r5.write(r0, r3, r1) // Catch: java.lang.Exception -> L5a java.lang.Throwable -> L6e goto L4d L58: r0 = r2 goto L5f L5a: r6 = move-exception goto L74 L5c: r5 = move-exception goto L76 L5e: r5 = r0 L5f: if (r0 == 0) goto L79 long r1 = r0.length() // Catch: java.lang.Throwable -> L6e java.lang.Exception -> L72 long r6 = (long) r7 // Catch: java.lang.Throwable -> L6e java.lang.Exception -> L72 int r3 = (r1 > r6 ? 1 : (r1 == r6 ? 0 : -1)) if (r3 == 0) goto L79 r0.delete() // Catch: java.lang.Throwable -> L6e java.lang.Exception -> L72 goto L79 L6e: r6 = move-exception r0 = r5 r5 = r6 goto L9c L72: r6 = move-exception r2 = r0 L74: r0 = r5 r5 = r6 L76: r6 = r0 r0 = r2 goto L84 L79: if (r5 == 0) goto L99 r5.flush() // Catch: java.lang.Exception -> L95 r5.close() // Catch: java.lang.Exception -> L95 goto L99 L82: r5 = move-exception r6 = r0 L84: r5.printStackTrace() // Catch: java.lang.Throwable -> L9a if (r0 == 0) goto L8c r0.delete() // Catch: java.lang.Throwable -> L9a L8c: if (r6 == 0) goto L99 r6.flush() // Catch: java.lang.Exception -> L95 r6.close() // Catch: java.lang.Exception -> L95 goto L99 L95: r5 = move-exception r5.printStackTrace() L99: return L9a: r5 = move-exception r0 = r6 L9c: if (r0 == 0) goto La9 r0.flush() // Catch: java.lang.Exception -> La5 r0.close() // Catch: java.lang.Exception -> La5 goto La9 La5: r6 = move-exception r6.printStackTrace() La9: throw r5 */ throw new UnsupportedOperationException("Method not decompiled: com.igaworks.ssp.common.k.b.a(java.lang.String, java.io.InputStream, int):void"); } public void a(boolean z10) { this.f6694g = z10; } }