package com.facebook; import android.content.ContentProvider; import android.content.ContentValues; import android.database.Cursor; import android.net.Uri; import android.os.ParcelFileDescriptor; import android.util.Log; import android.util.Pair; import com.facebook.internal.NativeAppCallAttachmentStore; import com.google.android.gms.drive.DriveFile; import java.io.File; import java.io.FileNotFoundException; import java.util.Arrays; import java.util.List; import java.util.UUID; import kotlin.jvm.internal.DefaultConstructorMarker; import kotlin.jvm.internal.Intrinsics; import kotlin.jvm.internal.StringCompanionObject; import kotlin.text.StringsKt__StringsKt; /* loaded from: classes2.dex */ public final class FacebookContentProvider extends ContentProvider { private static final String ATTACHMENT_URL_BASE = "content://com.facebook.app.FacebookContentProvider"; private static final String INVALID_FILE_NAME = ".."; public static final Companion Companion = new Companion(null); private static final String TAG = FacebookContentProvider.class.getName(); public static final String getAttachmentUrl(String str, UUID uuid, String str2) { return Companion.getAttachmentUrl(str, uuid, str2); } @Override // android.content.ContentProvider public int delete(Uri uri, String str, String[] strArr) { Intrinsics.checkNotNullParameter(uri, "uri"); return 0; } @Override // android.content.ContentProvider public String getType(Uri uri) { Intrinsics.checkNotNullParameter(uri, "uri"); return null; } @Override // android.content.ContentProvider public Uri insert(Uri uri, ContentValues contentValues) { Intrinsics.checkNotNullParameter(uri, "uri"); return null; } @Override // android.content.ContentProvider public boolean onCreate() { return true; } @Override // android.content.ContentProvider public Cursor query(Uri uri, String[] strArr, String str, String[] strArr2, String str2) { Intrinsics.checkNotNullParameter(uri, "uri"); return null; } @Override // android.content.ContentProvider public int update(Uri uri, ContentValues contentValues, String str, String[] strArr) { Intrinsics.checkNotNullParameter(uri, "uri"); return 0; } @Override // android.content.ContentProvider public ParcelFileDescriptor openFile(Uri uri, String mode) throws FileNotFoundException { Intrinsics.checkNotNullParameter(uri, "uri"); Intrinsics.checkNotNullParameter(mode, "mode"); Pair parseCallIdAndAttachmentName = parseCallIdAndAttachmentName(uri); if (parseCallIdAndAttachmentName == null) { throw new FileNotFoundException(); } try { NativeAppCallAttachmentStore nativeAppCallAttachmentStore = NativeAppCallAttachmentStore.INSTANCE; File openAttachment = NativeAppCallAttachmentStore.openAttachment((UUID) parseCallIdAndAttachmentName.first, (String) parseCallIdAndAttachmentName.second); if (openAttachment == null) { throw new FileNotFoundException(); } return ParcelFileDescriptor.open(openAttachment, DriveFile.MODE_READ_ONLY); } catch (FileNotFoundException e) { Log.e(TAG, Intrinsics.stringPlus("Got unexpected exception:", e)); throw e; } } private final Pair parseCallIdAndAttachmentName(Uri uri) { List split$default; try { String path = uri.getPath(); if (path == null) { throw new IllegalStateException("Required value was null.".toString()); } String substring = path.substring(1); Intrinsics.checkNotNullExpressionValue(substring, "(this as java.lang.String).substring(startIndex)"); split$default = StringsKt__StringsKt.split$default((CharSequence) substring, new String[]{"/"}, false, 0, 6, (Object) null); Object[] array = split$default.toArray(new String[0]); if (array == null) { throw new NullPointerException("null cannot be cast to non-null type kotlin.Array"); } String[] strArr = (String[]) array; String str = strArr[0]; String str2 = strArr[1]; if (INVALID_FILE_NAME.contentEquals(str) || INVALID_FILE_NAME.contentEquals(str2)) { throw new Exception(); } return new Pair<>(UUID.fromString(str), str2); } catch (Exception unused) { return null; } } public static final class Companion { public /* synthetic */ Companion(DefaultConstructorMarker defaultConstructorMarker) { this(); } private Companion() { } public final String getAttachmentUrl(String str, UUID callId, String str2) { Intrinsics.checkNotNullParameter(callId, "callId"); StringCompanionObject stringCompanionObject = StringCompanionObject.INSTANCE; String format = String.format("%s%s/%s/%s", Arrays.copyOf(new Object[]{FacebookContentProvider.ATTACHMENT_URL_BASE, str, callId.toString(), str2}, 4)); Intrinsics.checkNotNullExpressionValue(format, "java.lang.String.format(format, *args)"); return format; } } }