59 lines
2.4 KiB
Java
59 lines
2.4 KiB
Java
package com.discord.utilities.rest;
|
|
|
|
import android.content.ContentResolver;
|
|
import android.database.Cursor;
|
|
import android.net.Uri;
|
|
import android.os.ParcelFileDescriptor;
|
|
import androidx.core.app.NotificationCompat;
|
|
import com.discord.app.AppLog;
|
|
import com.discord.utilities.logging.Logger;
|
|
import d0.y.b;
|
|
import d0.z.d.m;
|
|
/* compiled from: SendUtils.kt */
|
|
public final class SendUtilsKt {
|
|
public static final long computeFileSizeBytes(Uri uri, ContentResolver contentResolver) {
|
|
long j;
|
|
Long l;
|
|
m.checkNotNullParameter(uri, NotificationCompat.MessagingStyle.Message.KEY_DATA_URI);
|
|
m.checkNotNullParameter(contentResolver, "contentResolver");
|
|
try {
|
|
Cursor query = contentResolver.query(uri, null, null, null, null);
|
|
if (query != null) {
|
|
try {
|
|
int columnIndex = query.getColumnIndex("_size");
|
|
query.moveToFirst();
|
|
l = Long.valueOf(query.getLong(columnIndex));
|
|
} catch (Exception unused) {
|
|
j = -1;
|
|
} catch (Throwable th) {
|
|
b.closeFinally(query, th);
|
|
throw th;
|
|
}
|
|
} else {
|
|
l = null;
|
|
}
|
|
if (l == null || l.longValue() <= 0) {
|
|
ParcelFileDescriptor openFileDescriptor = contentResolver.openFileDescriptor(uri, "r");
|
|
Long valueOf = openFileDescriptor != null ? Long.valueOf(openFileDescriptor.getStatSize()) : null;
|
|
if (openFileDescriptor != null) {
|
|
openFileDescriptor.close();
|
|
}
|
|
long longValue = valueOf != null ? valueOf.longValue() : -1;
|
|
b.closeFinally(query, null);
|
|
return longValue;
|
|
}
|
|
j = l.longValue();
|
|
b.closeFinally(query, null);
|
|
return j;
|
|
} catch (Exception e) {
|
|
Logger.e$default(AppLog.g, "Failed querying size of file " + uri, e, null, 4, null);
|
|
return -1;
|
|
}
|
|
}
|
|
|
|
public static final float computeFileSizeMegabytes(Uri uri, ContentResolver contentResolver) {
|
|
m.checkNotNullParameter(uri, NotificationCompat.MessagingStyle.Message.KEY_DATA_URI);
|
|
m.checkNotNullParameter(contentResolver, "contentResolver");
|
|
return ((float) computeFileSizeBytes(uri, contentResolver)) / ((float) 1048576);
|
|
}
|
|
}
|