discord-jadx/app/src/main/java/com/facebook/webpsupport/WebpBitmapFactoryImpl.java
2021-06-27 22:44:35 +02:00

346 lines
12 KiB
Java

package com.facebook.webpsupport;
import android.annotation.SuppressLint;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Rect;
import android.util.TypedValue;
import c.f.d.d.c;
import c.f.d.m.a;
import c.f.d.m.b;
import java.io.BufferedInputStream;
import java.io.FileDescriptor;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
@c
public class WebpBitmapFactoryImpl implements b {
public static b.a a;
public static a b;
public static byte[] b(InputStream inputStream, BitmapFactory.Options options) {
byte[] bArr;
inputStream.mark(20);
if (options == null || (bArr = options.inTempStorage) == null || bArr.length < 20) {
bArr = new byte[20];
}
try {
inputStream.read(bArr, 0, 20);
inputStream.reset();
return bArr;
} catch (IOException unused) {
return null;
}
}
public static void c(String str) {
b.a aVar = a;
if (aVar != null) {
aVar.a(str, "decoding_failure");
}
}
@c
private static Bitmap createBitmap(int i, int i2, BitmapFactory.Options options) {
Bitmap bitmap;
return (options == null || (bitmap = options.inBitmap) == null || !bitmap.isMutable()) ? b.a(i, i2, Bitmap.Config.ARGB_8888) : options.inBitmap;
}
@c
private static byte[] getInTempStorageFromOptions(BitmapFactory.Options options) {
byte[] bArr;
return (options == null || (bArr = options.inTempStorage) == null) ? new byte[8192] : bArr;
}
@c
private static float getScaleFromOptions(BitmapFactory.Options options) {
float f = 1.0f;
if (options == null) {
return 1.0f;
}
int i = options.inSampleSize;
if (i > 1) {
f = 1.0f / ((float) i);
}
if (!options.inScaled) {
return f;
}
int i2 = options.inDensity;
int i3 = options.inTargetDensity;
return (i2 == 0 || i3 == 0 || i2 == options.inScreenDensity) ? f : ((float) i3) / ((float) i2);
}
@c
public static Bitmap hookDecodeByteArray(byte[] bArr, int i, int i2) {
return hookDecodeByteArray(bArr, i, i2, null);
}
@c
public static Bitmap hookDecodeByteArray(byte[] bArr, int i, int i2, BitmapFactory.Options options) {
c.f.j.m.b.a();
b bVar = c.f.d.m.c.a;
Bitmap originalDecodeByteArray = originalDecodeByteArray(bArr, i, i2, options);
if (originalDecodeByteArray == null) {
c("webp_direct_decode_array_failed_on_no_webp");
}
return originalDecodeByteArray;
}
@c
public static Bitmap hookDecodeFile(String str) {
return hookDecodeFile(str, null);
}
/* JADX WARNING: Code restructure failed: missing block: B:11:?, code lost:
r1.close();
*/
/* JADX WARNING: Code restructure failed: missing block: B:12:0x0015, code lost:
r1 = move-exception;
*/
/* JADX WARNING: Code restructure failed: missing block: B:13:0x0016, code lost:
r2.addSuppressed(r1);
*/
/* JADX WARNING: Code restructure failed: missing block: B:14:0x0019, code lost:
throw r3;
*/
/* JADX WARNING: Code restructure failed: missing block: B:9:0x0010, code lost:
r3 = move-exception;
*/
@c
public static Bitmap hookDecodeFile(String str, BitmapFactory.Options options) {
Bitmap bitmap = null;
try {
FileInputStream fileInputStream = new FileInputStream(str);
bitmap = hookDecodeStream(fileInputStream, null, options);
fileInputStream.close();
} catch (Exception unused) {
}
return bitmap;
}
@c
public static Bitmap hookDecodeFileDescriptor(FileDescriptor fileDescriptor) {
return hookDecodeFileDescriptor(fileDescriptor, null, null);
}
@c
public static Bitmap hookDecodeFileDescriptor(FileDescriptor fileDescriptor, Rect rect, BitmapFactory.Options options) {
c.f.j.m.b.a();
long nativeSeek = nativeSeek(fileDescriptor, 0, false);
if (nativeSeek != -1) {
InputStream fileInputStream = new FileInputStream(fileDescriptor);
if (!fileInputStream.markSupported()) {
fileInputStream = new BufferedInputStream(fileInputStream, 20);
}
try {
b(fileInputStream, options);
b bVar = c.f.d.m.c.a;
nativeSeek(fileDescriptor, nativeSeek, true);
Bitmap originalDecodeFileDescriptor = originalDecodeFileDescriptor(fileDescriptor, rect, options);
if (originalDecodeFileDescriptor == null) {
c("webp_direct_decode_fd_failed_on_no_webp");
}
try {
fileInputStream.close();
return originalDecodeFileDescriptor;
} catch (Throwable unused) {
return originalDecodeFileDescriptor;
}
} catch (Throwable unused2) {
}
} else {
Bitmap hookDecodeStream = hookDecodeStream(new FileInputStream(fileDescriptor), rect, options);
setPaddingDefaultValues(rect);
return hookDecodeStream;
}
throw th;
}
@c
public static Bitmap hookDecodeResource(Resources resources, int i) {
return hookDecodeResource(resources, i, null);
}
/* JADX WARNING: Code restructure failed: missing block: B:10:0x0016, code lost:
r0 = move-exception;
*/
/* JADX WARNING: Code restructure failed: missing block: B:11:0x0017, code lost:
if (r3 != null) goto L_0x0019;
*/
/* JADX WARNING: Code restructure failed: missing block: B:13:?, code lost:
r3.close();
*/
/* JADX WARNING: Code restructure failed: missing block: B:14:0x001d, code lost:
r3 = move-exception;
*/
/* JADX WARNING: Code restructure failed: missing block: B:15:0x001e, code lost:
r2.addSuppressed(r3);
*/
/* JADX WARNING: Code restructure failed: missing block: B:16:0x0021, code lost:
throw r0;
*/
@c
public static Bitmap hookDecodeResource(Resources resources, int i, BitmapFactory.Options options) {
TypedValue typedValue = new TypedValue();
Bitmap bitmap = null;
try {
InputStream openRawResource = resources.openRawResource(i, typedValue);
bitmap = hookDecodeResourceStream(resources, typedValue, openRawResource, null, options);
if (openRawResource != null) {
openRawResource.close();
}
} catch (Exception unused) {
}
if (bitmap != null || options == null || options.inBitmap == null) {
return bitmap;
}
throw new IllegalArgumentException("Problem decoding into existing bitmap");
}
@c
public static Bitmap hookDecodeResourceStream(Resources resources, TypedValue typedValue, InputStream inputStream, Rect rect, BitmapFactory.Options options) {
if (options == null) {
options = new BitmapFactory.Options();
}
if (options.inDensity == 0 && typedValue != null) {
int i = typedValue.density;
if (i == 0) {
options.inDensity = 160;
} else if (i != 65535) {
options.inDensity = i;
}
}
if (options.inTargetDensity == 0 && resources != null) {
options.inTargetDensity = resources.getDisplayMetrics().densityDpi;
}
return hookDecodeStream(inputStream, rect, options);
}
@c
public static Bitmap hookDecodeStream(InputStream inputStream) {
return hookDecodeStream(inputStream, null, null);
}
@c
public static Bitmap hookDecodeStream(InputStream inputStream, Rect rect, BitmapFactory.Options options) {
c.f.j.m.b.a();
if (!inputStream.markSupported()) {
inputStream = new BufferedInputStream(inputStream, 20);
}
b(inputStream, options);
b bVar = c.f.d.m.c.a;
Bitmap originalDecodeStream = originalDecodeStream(inputStream, rect, options);
if (originalDecodeStream == null) {
c("webp_direct_decode_stream_failed_on_no_webp");
}
return originalDecodeStream;
}
@c
private static native Bitmap nativeDecodeByteArray(byte[] bArr, int i, int i2, BitmapFactory.Options options, float f, byte[] bArr2);
@c
private static native Bitmap nativeDecodeStream(InputStream inputStream, BitmapFactory.Options options, float f, byte[] bArr);
@c
private static native long nativeSeek(FileDescriptor fileDescriptor, long j, boolean z2);
@c
private static Bitmap originalDecodeByteArray(byte[] bArr, int i, int i2) {
return BitmapFactory.decodeByteArray(bArr, i, i2);
}
@c
private static Bitmap originalDecodeByteArray(byte[] bArr, int i, int i2, BitmapFactory.Options options) {
return BitmapFactory.decodeByteArray(bArr, i, i2, options);
}
@c
private static Bitmap originalDecodeFile(String str) {
return BitmapFactory.decodeFile(str);
}
@c
private static Bitmap originalDecodeFile(String str, BitmapFactory.Options options) {
return BitmapFactory.decodeFile(str, options);
}
@c
private static Bitmap originalDecodeFileDescriptor(FileDescriptor fileDescriptor) {
return BitmapFactory.decodeFileDescriptor(fileDescriptor);
}
@c
private static Bitmap originalDecodeFileDescriptor(FileDescriptor fileDescriptor, Rect rect, BitmapFactory.Options options) {
return BitmapFactory.decodeFileDescriptor(fileDescriptor, rect, options);
}
@c
private static Bitmap originalDecodeResource(Resources resources, int i) {
return BitmapFactory.decodeResource(resources, i);
}
@c
private static Bitmap originalDecodeResource(Resources resources, int i, BitmapFactory.Options options) {
return BitmapFactory.decodeResource(resources, i, options);
}
@c
private static Bitmap originalDecodeResourceStream(Resources resources, TypedValue typedValue, InputStream inputStream, Rect rect, BitmapFactory.Options options) {
return BitmapFactory.decodeResourceStream(resources, typedValue, inputStream, rect, options);
}
@c
private static Bitmap originalDecodeStream(InputStream inputStream) {
return BitmapFactory.decodeStream(inputStream);
}
@c
private static Bitmap originalDecodeStream(InputStream inputStream, Rect rect, BitmapFactory.Options options) {
return BitmapFactory.decodeStream(inputStream, rect, options);
}
@c
private static void setBitmapSize(BitmapFactory.Options options, int i, int i2) {
if (options != null) {
options.outWidth = i;
options.outHeight = i2;
}
}
@c
private static boolean setOutDimensions(BitmapFactory.Options options, int i, int i2) {
if (options == null || !options.inJustDecodeBounds) {
return false;
}
options.outWidth = i;
options.outHeight = i2;
return true;
}
@c
private static void setPaddingDefaultValues(Rect rect) {
if (rect != null) {
rect.top = -1;
rect.left = -1;
rect.bottom = -1;
rect.right = -1;
}
}
@c
@SuppressLint({"NewApi"})
private static boolean shouldPremultiply(BitmapFactory.Options options) {
if (options != null) {
return options.inPremultiplied;
}
return true;
}
@Override // c.f.d.m.b
public Bitmap a(FileDescriptor fileDescriptor, Rect rect, BitmapFactory.Options options) {
return hookDecodeFileDescriptor(fileDescriptor, null, options);
}
}