discord-jadx/app/src/main/java/c/q/a/j/b.java

495 lines
19 KiB
Java

package c.q.a.j;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import android.net.Uri;
import android.os.AsyncTask;
import android.util.Log;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import c.q.a.k.c;
import c.q.a.l.c;
import com.yalantis.ucrop.UCropActivity;
import d0.z.d.m;
import f0.f0.g.e;
import f0.x;
import f0.z;
import g0.g;
import g0.p;
import g0.y;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Objects;
import okhttp3.Response;
import okhttp3.ResponseBody;
/* compiled from: BitmapLoadTask */
public class b extends AsyncTask<Void, Void, a> {
public final Context a;
public Uri b;
/* renamed from: c reason: collision with root package name */
public Uri f1526c;
public final int d;
public final int e;
public final c.q.a.h.b f;
/* compiled from: BitmapLoadTask */
public static class a {
public Bitmap a;
public c.q.a.i.b b;
/* renamed from: c reason: collision with root package name */
public Exception f1527c;
public a(@NonNull Bitmap bitmap, @NonNull c.q.a.i.b bVar) {
this.a = bitmap;
this.b = bVar;
}
public a(@NonNull Exception exc) {
this.f1527c = exc;
}
}
public b(@NonNull Context context, @NonNull Uri uri, @Nullable Uri uri2, int i, int i2, c.q.a.h.b bVar) {
this.a = context;
this.b = uri;
this.f1526c = uri2;
this.d = i;
this.e = i2;
this.f = bVar;
}
/* JADX WARNING: Removed duplicated region for block: B:28:0x0052 A[SYNTHETIC, Splitter:B:28:0x0052] */
/* JADX WARNING: Removed duplicated region for block: B:32:0x0057 A[SYNTHETIC, Splitter:B:32:0x0057] */
public final void a(@NonNull Uri uri, @Nullable Uri uri2) throws NullPointerException, IOException {
Throwable th;
InputStream inputStream;
Log.d("BitmapWorkerTask", "copyFile");
Objects.requireNonNull(uri2, "Output Uri is null - cannot copy image");
FileOutputStream fileOutputStream = null;
try {
inputStream = this.a.getContentResolver().openInputStream(uri);
try {
FileOutputStream fileOutputStream2 = new FileOutputStream(new File(uri2.getPath()));
if (inputStream != null) {
try {
byte[] bArr = new byte[1024];
while (true) {
int read = inputStream.read(bArr);
if (read > 0) {
fileOutputStream2.write(bArr, 0, read);
} else {
try {
break;
} catch (IOException unused) {
}
}
}
fileOutputStream2.close();
try {
inputStream.close();
} catch (IOException unused2) {
}
this.b = this.f1526c;
} catch (Throwable th2) {
th = th2;
fileOutputStream = fileOutputStream2;
if (fileOutputStream != null) {
try {
fileOutputStream.close();
} catch (IOException unused3) {
}
}
if (inputStream != null) {
try {
inputStream.close();
} catch (IOException unused4) {
}
}
this.b = this.f1526c;
throw th;
}
} else {
throw new NullPointerException("InputStream for given input Uri is null");
}
} catch (Throwable th3) {
th = th3;
if (fileOutputStream != null) {
}
if (inputStream != null) {
}
this.b = this.f1526c;
throw th;
}
} catch (Throwable th4) {
th = th4;
inputStream = null;
if (fileOutputStream != null) {
}
if (inputStream != null) {
}
this.b = this.f1526c;
throw th;
}
}
/* JADX WARNING: Removed duplicated region for block: B:39:0x0080 A[SYNTHETIC, Splitter:B:39:0x0080] */
/* JADX WARNING: Removed duplicated region for block: B:43:0x0085 A[SYNTHETIC, Splitter:B:43:0x0085] */
public final void b(@NonNull Uri uri, @Nullable Uri uri2) throws NullPointerException, IOException {
Throwable th;
Response response;
p pVar;
ResponseBody responseBody;
g c2;
Log.d("BitmapWorkerTask", "downloadFile");
Objects.requireNonNull(uri2, "Output Uri is null - cannot download image");
x xVar = new x();
g gVar = null;
try {
z.a aVar = new z.a();
aVar.f(uri.toString());
try {
response = ((e) xVar.b(aVar.a())).execute();
try {
c2 = response.o.c();
} catch (Throwable th2) {
th = th2;
pVar = null;
if (gVar != null) {
}
if (pVar != null) {
}
try {
responseBody.close();
} catch (IOException unused) {
}
xVar.l.a();
this.b = this.f1526c;
throw th;
}
} catch (Throwable th3) {
th = th3;
response = null;
pVar = null;
if (gVar != null) {
}
if (pVar != null) {
}
responseBody.close();
xVar.l.a();
this.b = this.f1526c;
throw th;
}
try {
OutputStream openOutputStream = this.a.getContentResolver().openOutputStream(uri2);
if (openOutputStream != null) {
m.checkParameterIsNotNull(openOutputStream, "$this$sink");
pVar = new p(openOutputStream, new y());
try {
c2.j0(pVar);
try {
c2.close();
} catch (IOException unused2) {
}
try {
pVar.close();
} catch (IOException unused3) {
}
ResponseBody responseBody2 = response.o;
if (responseBody2 != null) {
try {
responseBody2.close();
} catch (IOException unused4) {
}
}
xVar.l.a();
this.b = this.f1526c;
} catch (Throwable th4) {
th = th4;
gVar = c2;
if (gVar != null) {
}
if (pVar != null) {
}
responseBody.close();
xVar.l.a();
this.b = this.f1526c;
throw th;
}
} else {
throw new NullPointerException("OutputStream for given output Uri is null");
}
} catch (Throwable th5) {
th = th5;
pVar = null;
gVar = c2;
if (gVar != null) {
try {
gVar.close();
} catch (IOException unused5) {
}
}
if (pVar != null) {
try {
pVar.close();
} catch (IOException unused6) {
}
}
if (!(response == null || (responseBody = response.o) == null)) {
responseBody.close();
}
xVar.l.a();
this.b = this.f1526c;
throw th;
}
} catch (Throwable th6) {
th = th6;
response = null;
pVar = null;
if (gVar != null) {
}
if (pVar != null) {
}
responseBody.close();
xVar.l.a();
this.b = this.f1526c;
throw th;
}
}
public final void c() throws NullPointerException, IOException {
String scheme = this.b.getScheme();
Log.d("BitmapWorkerTask", "Uri scheme: " + scheme);
if ("http".equals(scheme) || "https".equals(scheme)) {
try {
b(this.b, this.f1526c);
} catch (IOException | NullPointerException e) {
Log.e("BitmapWorkerTask", "Downloading failed", e);
throw e;
}
} else if ("content".equals(scheme)) {
try {
a(this.b, this.f1526c);
} catch (IOException | NullPointerException e2) {
Log.e("BitmapWorkerTask", "Copying failed", e2);
throw e2;
}
} else if (!"file".equals(scheme)) {
Log.e("BitmapWorkerTask", "Invalid Uri scheme " + scheme);
throw new IllegalArgumentException(c.d.b.a.a.t("Invalid Uri scheme", scheme));
}
}
/* Return type fixed from 'java.lang.Object' to match base method */
/* JADX DEBUG: Method arguments types fixed to match base method, original types: [java.lang.Object[]] */
/* JADX WARNING: Code restructure failed: missing block: B:110:?, code lost:
return new c.q.a.j.b.a(new java.lang.IllegalArgumentException(r2.toString(), r0));
*/
/* JADX WARNING: Code restructure failed: missing block: B:42:0x009d, code lost:
r0 = move-exception;
*/
/* JADX WARNING: Code restructure failed: missing block: B:43:0x009e, code lost:
android.util.Log.e("BitmapWorkerTask", "doInBackground: ImageDecoder.createSource: ", r0);
r2 = c.d.b.a.a.L("Bitmap could not be decoded from the Uri: [");
r2.append(r13.b);
r2.append("]");
*/
/* JADX WARNING: Code restructure failed: missing block: B:44:0x00bf, code lost:
r5 = move-exception;
*/
/* JADX WARNING: Code restructure failed: missing block: B:45:0x00c0, code lost:
android.util.Log.e("BitmapWorkerTask", "doInBackground: BitmapFactory.decodeFileDescriptor: ", r5);
r1.inSampleSize *= 2;
*/
/* JADX WARNING: Failed to process nested try/catch */
/* JADX WARNING: Removed duplicated region for block: B:44:0x00bf A[ExcHandler: OutOfMemoryError (r5v3 'e' java.lang.OutOfMemoryError A[CUSTOM_DECLARE]), PHI: r12
PHI: (r12v5 android.graphics.Bitmap) = (r12v1 android.graphics.Bitmap), (r12v1 android.graphics.Bitmap), (r12v1 android.graphics.Bitmap), (r12v1 android.graphics.Bitmap), (r12v6 android.graphics.Bitmap), (r12v6 android.graphics.Bitmap), (r12v6 android.graphics.Bitmap), (r12v6 android.graphics.Bitmap) binds: [B:18:0x004e, B:19:?, B:38:0x0099, B:39:?, B:32:0x0090, B:33:?, B:26:0x0069, B:27:?] A[DONT_GENERATE, DONT_INLINE], Splitter:B:18:0x004e] */
/* JADX WARNING: Removed duplicated region for block: B:61:0x0122 */
/* JADX WARNING: Removed duplicated region for block: B:62:0x0124 */
/* JADX WARNING: Removed duplicated region for block: B:63:0x0127 */
/* JADX WARNING: Removed duplicated region for block: B:64:0x012a */
/* JADX WARNING: Removed duplicated region for block: B:75:0x0144 */
/* JADX WARNING: Removed duplicated region for block: B:77:0x014a */
/* JADX WARNING: Removed duplicated region for block: B:80:0x0156 */
/* JADX WARNING: Removed duplicated region for block: B:88:0x017a */
@Override // android.os.AsyncTask
@NonNull
public a doInBackground(Void[] voidArr) {
int i;
int i2;
int i3;
Matrix matrix;
a aVar;
if (this.b == null) {
return new a(new NullPointerException("Input Uri cannot be null"));
}
try {
c();
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
int i4 = this.d;
int i5 = this.e;
int i6 = options.outHeight;
int i7 = options.outWidth;
if (i6 > i5 || i7 > i4) {
int i8 = 1;
while (true) {
if (i6 / i8 <= i5 && i7 / i8 <= i4) {
break;
}
i8 *= 2;
}
i = i8;
} else {
i = 1;
}
options.inSampleSize = i;
options.inJustDecodeBounds = false;
boolean z2 = false;
Bitmap bitmap = null;
while (true) {
int i9 = -1;
if (!z2) {
try {
InputStream openInputStream = this.a.getContentResolver().openInputStream(this.b);
try {
bitmap = BitmapFactory.decodeStream(openInputStream, null, options);
if (options.outWidth == -1 || options.outHeight == -1) {
aVar = new a(new IllegalArgumentException("Bounds for bitmap could not be retrieved from the Uri: [" + this.b + "]"));
if (openInputStream == null) {
break;
}
openInputStream.close();
break;
}
z2 = true;
} finally {
if (openInputStream == null) {
break;
}
openInputStream.close();
break;
}
} catch (IOException unused) {
} catch (OutOfMemoryError e) {
}
} else if (bitmap == null) {
StringBuilder L = c.d.b.a.a.L("Bitmap could not be decoded from the Uri: [");
L.append(this.b);
L.append("]");
return new a(new IllegalArgumentException(L.toString()));
} else {
Context context = this.a;
Uri uri = this.b;
try {
InputStream openInputStream2 = context.getContentResolver().openInputStream(uri);
if (openInputStream2 == null) {
i2 = 0;
switch (i2) {
case 3:
case 4:
i3 = 180;
break;
case 5:
case 6:
i3 = 90;
break;
case 7:
case 8:
i3 = 270;
break;
default:
i3 = 0;
break;
}
if (!(i2 == 2 || i2 == 7 || i2 == 4 || i2 == 5)) {
i9 = 1;
}
c.q.a.i.b bVar = new c.q.a.i.b(i2, i3, i9);
matrix = new Matrix();
if (i3 != 0) {
matrix.preRotate((float) i3);
}
if (i9 != 1) {
matrix.postScale((float) i9, 1.0f);
}
if (!matrix.isIdentity()) {
return new a(bitmap, bVar);
}
try {
Bitmap createBitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
if (!bitmap.sameAs(createBitmap)) {
bitmap = createBitmap;
}
} catch (OutOfMemoryError e2) {
Log.e("BitmapLoadUtils", "transformBitmap: ", e2);
}
return new a(bitmap, bVar);
}
i2 = new c(openInputStream2).a();
try {
openInputStream2.close();
} catch (IOException unused2) {
}
switch (i2) {
}
i9 = 1;
c.q.a.i.b bVar = new c.q.a.i.b(i2, i3, i9);
matrix = new Matrix();
if (i3 != 0) {
}
if (i9 != 1) {
}
if (!matrix.isIdentity()) {
}
} catch (IOException e3) {
StringBuilder L2 = c.d.b.a.a.L("getExifOrientation: ");
L2.append(uri.toString());
Log.e("BitmapLoadUtils", L2.toString(), e3);
}
}
}
} catch (IOException | NullPointerException e4) {
return new a(e4);
}
return aVar;
}
/* JADX DEBUG: Method arguments types fixed to match base method, original types: [java.lang.Object] */
@Override // android.os.AsyncTask
public void onPostExecute(@NonNull a aVar) {
a aVar2 = aVar;
Exception exc = aVar2.f1527c;
if (exc == null) {
c.q.a.h.b bVar = this.f;
Bitmap bitmap = aVar2.a;
c.q.a.i.b bVar2 = aVar2.b;
String path = this.b.getPath();
Uri uri = this.f1526c;
String path2 = uri == null ? null : uri.getPath();
c.q.a.l.c cVar = ((c.q.a.l.b) bVar).a;
cVar.u = path;
cVar.v = path2;
cVar.w = bVar2;
cVar.r = true;
cVar.setImageBitmap(bitmap);
return;
}
c.q.a.l.b bVar3 = (c.q.a.l.b) this.f;
Objects.requireNonNull(bVar3);
Log.e("TransformImageView", "onFailure: setImageUri", exc);
c.a aVar3 = bVar3.a.o;
if (aVar3 != null) {
UCropActivity.a aVar4 = (UCropActivity.a) aVar3;
UCropActivity.this.b(exc);
UCropActivity.this.finish();
}
}
}