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

469 lines
18 KiB
Java
Raw Normal View History

2021-12-17 21:59:34 +00:00
package b.q.a.j;
2021-08-03 07:33:18 +00:00
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;
2021-12-17 21:59:34 +00:00
import b.q.a.l.c;
import com.adjust.sdk.Constants;
2021-08-03 07:33:18 +00:00
import com.yalantis.ucrop.UCropActivity;
2021-11-02 06:38:17 +00:00
import d0.z.d.m;
import f0.e0.g.e;
import f0.x;
import g0.g;
import g0.p;
import g0.y;
2021-08-03 07:33:18 +00:00
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Objects;
2021-08-10 21:19:22 +00:00
import okhttp3.Request;
2021-08-03 07:33:18 +00:00
import okhttp3.Response;
import okhttp3.ResponseBody;
2022-03-07 09:34:54 +00:00
/* compiled from: BitmapLoadTask.java */
/* loaded from: classes3.dex */
2021-08-03 07:33:18 +00:00
public class b extends AsyncTask<Void, Void, a> {
public final Context a;
2021-12-17 21:59:34 +00:00
/* renamed from: b reason: collision with root package name */
2022-03-12 00:35:13 +00:00
public Uri f1980b;
2021-12-17 21:59:34 +00:00
public Uri c;
2021-08-03 07:33:18 +00:00
public final int d;
public final int e;
2021-12-17 21:59:34 +00:00
public final b.q.a.h.b f;
2021-08-03 07:33:18 +00:00
2022-03-07 09:34:54 +00:00
/* compiled from: BitmapLoadTask.java */
/* loaded from: classes3.dex */
2021-08-03 07:33:18 +00:00
public static class a {
public Bitmap a;
2021-12-17 21:59:34 +00:00
/* renamed from: b reason: collision with root package name */
2022-03-12 00:35:13 +00:00
public b.q.a.i.b f1981b;
2021-12-17 21:59:34 +00:00
public Exception c;
2021-08-03 07:33:18 +00:00
2021-12-17 21:59:34 +00:00
public a(@NonNull Bitmap bitmap, @NonNull b.q.a.i.b bVar) {
2021-08-03 07:33:18 +00:00
this.a = bitmap;
2022-03-12 00:35:13 +00:00
this.f1981b = bVar;
2021-08-03 07:33:18 +00:00
}
public a(@NonNull Exception exc) {
2021-12-17 21:59:34 +00:00
this.c = exc;
2021-08-03 07:33:18 +00:00
}
}
2021-12-17 21:59:34 +00:00
public b(@NonNull Context context, @NonNull Uri uri, @Nullable Uri uri2, int i, int i2, b.q.a.h.b bVar) {
2021-08-03 07:33:18 +00:00
this.a = context;
2022-03-12 00:35:13 +00:00
this.f1980b = uri;
2021-12-17 21:59:34 +00:00
this.c = uri2;
2021-08-03 07:33:18 +00:00
this.d = i;
this.e = i2;
this.f = bVar;
}
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()));
2022-03-07 09:34:54 +00:00
try {
if (inputStream != null) {
2021-08-03 07:33:18 +00:00
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) {
}
2022-03-12 00:35:13 +00:00
this.f1980b = this.c;
2022-03-07 09:34:54 +00:00
return;
}
throw new NullPointerException("InputStream for given input Uri is null");
} catch (Throwable th2) {
th = th2;
fileOutputStream = fileOutputStream2;
if (fileOutputStream != null) {
try {
fileOutputStream.close();
} catch (IOException unused3) {
2021-08-03 07:33:18 +00:00
}
2022-03-07 09:34:54 +00:00
}
if (inputStream != null) {
try {
inputStream.close();
} catch (IOException unused4) {
2021-08-03 07:33:18 +00:00
}
}
2022-03-12 00:35:13 +00:00
this.f1980b = this.c;
2022-03-07 09:34:54 +00:00
throw th;
2021-08-03 07:33:18 +00:00
}
} catch (Throwable th3) {
th = th3;
}
} catch (Throwable th4) {
th = th4;
inputStream = null;
}
}
2022-03-07 09:34:54 +00:00
/* JADX WARN: Removed duplicated region for block: B:46:0x0085 A[EXC_TOP_SPLITTER, SYNTHETIC] */
/* JADX WARN: Removed duplicated region for block: B:52:0x0080 A[EXC_TOP_SPLITTER, SYNTHETIC] */
/*
Code decompiled incorrectly, please refer to instructions dump.
*/
2021-08-03 07:33:18 +00:00
public final void b(@NonNull Uri uri, @Nullable Uri uri2) throws NullPointerException, IOException {
Throwable th;
Response response;
p pVar;
ResponseBody responseBody;
Log.d("BitmapWorkerTask", "downloadFile");
Objects.requireNonNull(uri2, "Output Uri is null - cannot download image");
x xVar = new x();
g gVar = null;
try {
2021-08-10 21:19:22 +00:00
Request.a aVar = new Request.a();
2021-08-03 07:33:18 +00:00
aVar.f(uri.toString());
try {
response = ((e) xVar.b(aVar.a())).execute();
try {
2022-03-07 09:34:54 +00:00
g c = response.p.c();
2021-08-03 07:33:18 +00:00
try {
2022-03-07 09:34:54 +00:00
OutputStream openOutputStream = this.a.getContentResolver().openOutputStream(uri2);
if (openOutputStream != null) {
m.checkParameterIsNotNull(openOutputStream, "$this$sink");
pVar = new p(openOutputStream, new y());
2021-08-03 07:33:18 +00:00
try {
2022-03-07 09:34:54 +00:00
c.k0(pVar);
try {
c.close();
} catch (IOException unused) {
}
try {
pVar.close();
} catch (IOException unused2) {
}
ResponseBody responseBody2 = response.p;
if (responseBody2 != null) {
try {
responseBody2.close();
} catch (IOException unused3) {
}
}
xVar.m.a();
2022-03-12 00:35:13 +00:00
this.f1980b = this.c;
2022-03-07 09:34:54 +00:00
} catch (Throwable th2) {
th = th2;
gVar = c;
if (gVar != null) {
try {
gVar.close();
} catch (IOException unused4) {
}
}
if (pVar != null) {
try {
pVar.close();
} catch (IOException unused5) {
}
}
if (!(response == null || (responseBody = response.p) == null)) {
try {
responseBody.close();
} catch (IOException unused6) {
}
}
xVar.m.a();
2022-03-12 00:35:13 +00:00
this.f1980b = this.c;
2022-03-07 09:34:54 +00:00
throw th;
2021-08-03 07:33:18 +00:00
}
2022-03-07 09:34:54 +00:00
} else {
throw new NullPointerException("OutputStream for given output Uri is null");
2021-08-03 07:33:18 +00:00
}
2022-03-07 09:34:54 +00:00
} catch (Throwable th3) {
th = th3;
pVar = null;
2021-08-03 07:33:18 +00:00
}
2022-03-07 09:34:54 +00:00
} catch (Throwable th4) {
th = th4;
pVar = null;
2021-08-03 07:33:18 +00:00
}
} catch (Throwable th5) {
th = th5;
2022-03-07 09:34:54 +00:00
response = null;
2021-08-03 07:33:18 +00:00
pVar = null;
if (gVar != null) {
}
if (pVar != null) {
}
2022-03-07 09:34:54 +00:00
if (response == null) {
2021-08-03 07:33:18 +00:00
responseBody.close();
}
2021-12-02 18:53:44 +00:00
xVar.m.a();
2022-03-12 00:35:13 +00:00
this.f1980b = this.c;
2021-08-03 07:33:18 +00:00
throw th;
}
} catch (Throwable th6) {
th = th6;
}
}
public final void c() throws NullPointerException, IOException {
2022-03-12 00:35:13 +00:00
String scheme = this.f1980b.getScheme();
2021-08-03 07:33:18 +00:00
Log.d("BitmapWorkerTask", "Uri scheme: " + scheme);
if ("http".equals(scheme) || Constants.SCHEME.equals(scheme)) {
2021-08-03 07:33:18 +00:00
try {
2022-03-12 00:35:13 +00:00
b(this.f1980b, this.c);
2021-08-03 07:33:18 +00:00
} catch (IOException | NullPointerException e) {
Log.e("BitmapWorkerTask", "Downloading failed", e);
throw e;
}
} else if ("content".equals(scheme)) {
try {
2022-03-12 00:35:13 +00:00
a(this.f1980b, this.c);
2021-08-03 07:33:18 +00:00
} catch (IOException | NullPointerException e2) {
Log.e("BitmapWorkerTask", "Copying failed", e2);
throw e2;
}
} else if (!"file".equals(scheme)) {
Log.e("BitmapWorkerTask", "Invalid Uri scheme " + scheme);
2021-12-17 21:59:34 +00:00
throw new IllegalArgumentException(b.d.b.a.a.v("Invalid Uri scheme", scheme));
2021-08-03 07:33:18 +00:00
}
}
2022-03-07 09:34:54 +00:00
/* JADX WARN: Removed duplicated region for block: B:62:0x013c */
/* JADX WARN: Removed duplicated region for block: B:63:0x013e */
/* JADX WARN: Removed duplicated region for block: B:64:0x0141 */
/* JADX WARN: Removed duplicated region for block: B:65:0x0144 */
/* JADX WARN: Removed duplicated region for block: B:76:0x015e */
/* JADX WARN: Removed duplicated region for block: B:78:0x0164 */
/* JADX WARN: Removed duplicated region for block: B:81:0x0170 */
/* JADX WARN: Removed duplicated region for block: B:88:0x0194 */
2021-08-03 07:33:18 +00:00
@Override // android.os.AsyncTask
@NonNull
2022-03-07 09:34:54 +00:00
/*
Code decompiled incorrectly, please refer to instructions dump.
*/
2021-08-03 07:33:18 +00:00
public a doInBackground(Void[] voidArr) {
int i;
int i2;
int i3;
Matrix matrix;
2022-03-07 09:34:54 +00:00
InputStream openInputStream;
InputStream openInputStream2;
2021-08-03 07:33:18 +00:00
boolean z2;
2022-03-12 00:35:13 +00:00
if (this.f1980b == null) {
2021-08-03 07:33:18 +00:00
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 z3 = false;
Bitmap bitmap = null;
while (true) {
int i9 = -1;
if (!z3) {
try {
try {
2022-03-12 00:35:13 +00:00
openInputStream2 = this.a.getContentResolver().openInputStream(this.f1980b);
2022-03-07 09:34:54 +00:00
try {
bitmap = BitmapFactory.decodeStream(openInputStream2, null, options);
} catch (Throwable th) {
if (openInputStream2 != null) {
try {
openInputStream2.close();
} catch (IOException unused) {
}
2021-08-03 07:33:18 +00:00
}
2022-03-07 09:34:54 +00:00
throw th;
2021-08-03 07:33:18 +00:00
}
2022-03-07 09:34:54 +00:00
} catch (IOException e) {
Log.e("BitmapWorkerTask", "doInBackground: ImageDecoder.createSource: ", e);
2022-03-21 18:52:30 +00:00
StringBuilder R = b.d.b.a.a.R("Bitmap could not be decoded from the Uri: [");
R.append(this.f1980b);
R.append("]");
return new a(new IllegalArgumentException(R.toString(), e));
2021-08-03 07:33:18 +00:00
}
2022-03-07 09:34:54 +00:00
} catch (OutOfMemoryError e2) {
Log.e("BitmapWorkerTask", "doInBackground: BitmapFactory.decodeFileDescriptor: ", e2);
options.inSampleSize *= 2;
}
if (options.outWidth == -1 || options.outHeight == -1) {
break;
}
if (openInputStream2 != null) {
try {
openInputStream2.close();
} catch (IOException unused2) {
}
}
if ((bitmap != null ? bitmap.getByteCount() : 0) > 104857600) {
options.inSampleSize *= 2;
z2 = true;
} else {
z2 = false;
}
if (!z2) {
z3 = true;
2021-08-03 07:33:18 +00:00
}
} else if (bitmap == null) {
2022-03-21 18:52:30 +00:00
StringBuilder R2 = b.d.b.a.a.R("Bitmap could not be decoded from the Uri: [");
R2.append(this.f1980b);
R2.append("]");
return new a(new IllegalArgumentException(R2.toString()));
2021-08-03 07:33:18 +00:00
} else {
Context context = this.a;
2022-03-12 00:35:13 +00:00
Uri uri = this.f1980b;
2021-08-03 07:33:18 +00:00
try {
2022-03-07 09:34:54 +00:00
openInputStream = context.getContentResolver().openInputStream(uri);
} catch (IOException e3) {
2022-03-21 18:52:30 +00:00
StringBuilder R3 = b.d.b.a.a.R("getExifOrientation: ");
R3.append(uri.toString());
Log.e("BitmapLoadUtils", R3.toString(), e3);
2022-03-07 09:34:54 +00:00
}
if (openInputStream == null) {
i2 = 0;
2021-08-03 07:33:18 +00:00
switch (i2) {
2022-03-07 09:34:54 +00:00
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;
2021-08-03 07:33:18 +00:00
}
2021-12-17 21:59:34 +00:00
b.q.a.i.b bVar = new b.q.a.i.b(i2, i3, i9);
2021-08-03 07:33:18 +00:00
matrix = new Matrix();
if (i3 != 0) {
2022-03-07 09:34:54 +00:00
matrix.preRotate(i3);
2021-08-03 07:33:18 +00:00
}
if (i9 != 1) {
2022-03-07 09:34:54 +00:00
matrix.postScale(i9, 1.0f);
2021-08-03 07:33:18 +00:00
}
if (!matrix.isIdentity()) {
2022-03-07 09:34:54 +00:00
return new a(bitmap, bVar);
2021-08-03 07:33:18 +00:00
}
2022-03-07 09:34:54 +00:00
try {
Bitmap createBitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
if (!bitmap.sameAs(createBitmap)) {
bitmap = createBitmap;
}
} catch (OutOfMemoryError e4) {
Log.e("BitmapLoadUtils", "transformBitmap: ", e4);
}
return new a(bitmap, bVar);
}
i2 = new b.q.a.k.b(openInputStream).a();
try {
openInputStream.close();
} catch (IOException unused3) {
}
switch (i2) {
2021-08-03 07:33:18 +00:00
}
2022-03-07 09:34:54 +00:00
if (i2 == 2) {
i9 = 1;
}
b.q.a.i.b bVar2 = new b.q.a.i.b(i2, i3, i9);
matrix = new Matrix();
if (i3 != 0) {
}
if (i9 != 1) {
}
if (!matrix.isIdentity()) {
}
}
}
2022-03-12 00:35:13 +00:00
a aVar = new a(new IllegalArgumentException("Bounds for bitmap could not be retrieved from the Uri: [" + this.f1980b + "]"));
2022-03-07 09:34:54 +00:00
if (openInputStream2 != null) {
try {
openInputStream2.close();
} catch (IOException unused4) {
2021-08-03 07:33:18 +00:00
}
}
2022-03-07 09:34:54 +00:00
return aVar;
} catch (IOException | NullPointerException e5) {
return new a(e5);
2021-08-03 07:33:18 +00:00
}
}
@Override // android.os.AsyncTask
public void onPostExecute(@NonNull a aVar) {
a aVar2 = aVar;
2021-12-17 21:59:34 +00:00
Exception exc = aVar2.c;
2021-08-03 07:33:18 +00:00
if (exc == null) {
2021-12-17 21:59:34 +00:00
b.q.a.h.b bVar = this.f;
2021-08-03 07:33:18 +00:00
Bitmap bitmap = aVar2.a;
2022-03-12 00:35:13 +00:00
b.q.a.i.b bVar2 = aVar2.f1981b;
String path = this.f1980b.getPath();
2021-12-17 21:59:34 +00:00
Uri uri = this.c;
2021-08-03 07:33:18 +00:00
String path2 = uri == null ? null : uri.getPath();
2021-12-17 21:59:34 +00:00
c cVar = ((b.q.a.l.b) bVar).a;
2021-12-02 18:53:44 +00:00
cVar.v = path;
cVar.w = path2;
2022-03-12 00:35:13 +00:00
cVar.f1989x = bVar2;
cVar.f1988s = true;
2021-08-03 07:33:18 +00:00
cVar.setImageBitmap(bitmap);
return;
}
2021-12-17 21:59:34 +00:00
b.q.a.l.b bVar3 = (b.q.a.l.b) this.f;
2021-08-03 07:33:18 +00:00
Objects.requireNonNull(bVar3);
Log.e("TransformImageView", "onFailure: setImageUri", exc);
2021-12-02 18:53:44 +00:00
c.a aVar3 = bVar3.a.p;
2021-08-03 07:33:18 +00:00
if (aVar3 != null) {
UCropActivity.a aVar4 = (UCropActivity.a) aVar3;
UCropActivity.this.b(exc);
UCropActivity.this.finish();
}
}
}