jimu-decompiled/sources/com/facebook/internal/NativeAppCallAttachmentStore.java
2025-05-13 19:24:51 +02:00

202 lines
6.1 KiB
Java

package com.facebook.internal;
import android.graphics.Bitmap;
import android.net.Uri;
import android.util.Log;
import com.facebook.FacebookContentProvider;
import com.facebook.FacebookException;
import com.facebook.FacebookSdk;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.UUID;
/* loaded from: classes.dex */
public final class NativeAppCallAttachmentStore {
private static final String a = "com.facebook.internal.NativeAppCallAttachmentStore";
private static File b;
public static final class Attachment {
private final UUID a;
private final String b;
private final String c;
private Bitmap d;
private Uri e;
private boolean f;
private boolean g;
private Attachment(UUID uuid, Bitmap bitmap, Uri uri) {
this.a = uuid;
this.d = bitmap;
this.e = uri;
if (uri != null) {
String scheme = uri.getScheme();
if ("content".equalsIgnoreCase(scheme)) {
this.f = true;
this.g = (uri.getAuthority() == null || uri.getAuthority().startsWith("media")) ? false : true;
} else if ("file".equalsIgnoreCase(uri.getScheme())) {
this.g = true;
} else if (!Utility.e(uri)) {
throw new FacebookException("Unsupported scheme for media Uri : " + scheme);
}
} else {
if (bitmap == null) {
throw new FacebookException("Cannot share media without a bitmap or Uri set");
}
this.g = true;
}
this.c = !this.g ? null : UUID.randomUUID().toString();
this.b = !this.g ? this.e.toString() : FacebookContentProvider.a(FacebookSdk.c(), uuid, this.c);
}
public String a() {
return this.b;
}
}
private NativeAppCallAttachmentStore() {
}
public static Attachment a(UUID uuid, Bitmap bitmap) {
Validate.a(uuid, "callId");
Validate.a(bitmap, "attachmentBitmap");
return new Attachment(uuid, bitmap, null);
}
static File b() {
File c = c();
c.mkdirs();
return c;
}
static synchronized File c() {
File file;
synchronized (NativeAppCallAttachmentStore.class) {
if (b == null) {
b = new File(FacebookSdk.b().getCacheDir(), "com.facebook.NativeAppCallAttachmentStore.files");
}
file = b;
}
return file;
}
public static Attachment a(UUID uuid, Uri uri) {
Validate.a(uuid, "callId");
Validate.a(uri, "attachmentUri");
return new Attachment(uuid, null, uri);
}
private static void a(Bitmap bitmap, File file) throws IOException {
FileOutputStream fileOutputStream = new FileOutputStream(file);
try {
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fileOutputStream);
} finally {
Utility.a(fileOutputStream);
}
}
private static void a(Uri uri, boolean z, File file) throws IOException {
InputStream openInputStream;
FileOutputStream fileOutputStream = new FileOutputStream(file);
try {
if (!z) {
openInputStream = new FileInputStream(uri.getPath());
} else {
openInputStream = FacebookSdk.b().getContentResolver().openInputStream(uri);
}
Utility.a(openInputStream, (OutputStream) fileOutputStream);
} finally {
Utility.a(fileOutputStream);
}
}
public static void a(Collection<Attachment> collection) {
if (collection == null || collection.size() == 0) {
return;
}
if (b == null) {
a();
}
b();
ArrayList arrayList = new ArrayList();
try {
for (Attachment attachment : collection) {
if (attachment.g) {
File a2 = a(attachment.a, attachment.c, true);
arrayList.add(a2);
if (attachment.d != null) {
a(attachment.d, a2);
} else if (attachment.e != null) {
a(attachment.e, attachment.f, a2);
}
}
}
} catch (IOException e) {
Log.e(a, "Got unexpected exception:" + e);
Iterator it = arrayList.iterator();
while (it.hasNext()) {
try {
((File) it.next()).delete();
} catch (Exception unused) {
}
}
throw new FacebookException(e);
}
}
public static void a(UUID uuid) {
File a2 = a(uuid, false);
if (a2 != null) {
Utility.a(a2);
}
}
public static File a(UUID uuid, String str) throws FileNotFoundException {
if (!Utility.c(str) && uuid != null) {
try {
return a(uuid, str, false);
} catch (IOException unused) {
throw new FileNotFoundException();
}
}
throw new FileNotFoundException();
}
static File a(UUID uuid, boolean z) {
File file = b;
if (file == null) {
return null;
}
File file2 = new File(file, uuid.toString());
if (z && !file2.exists()) {
file2.mkdirs();
}
return file2;
}
static File a(UUID uuid, String str, boolean z) throws IOException {
File a2 = a(uuid, z);
if (a2 == null) {
return null;
}
try {
return new File(a2, URLEncoder.encode(str, "UTF-8"));
} catch (UnsupportedEncodingException unused) {
return null;
}
}
public static void a() {
Utility.a(c());
}
}