188 lines
6.7 KiB
Java
188 lines
6.7 KiB
Java
|
package o;
|
||
|
|
||
|
import android.content.Context;
|
||
|
import android.database.Cursor;
|
||
|
import android.net.Uri;
|
||
|
import android.os.Build;
|
||
|
import android.os.storage.StorageManager;
|
||
|
import com.google.android.libraries.places.api.model.PlaceTypes;
|
||
|
import java.io.BufferedInputStream;
|
||
|
import java.io.BufferedOutputStream;
|
||
|
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.lang.reflect.Array;
|
||
|
import java.lang.reflect.Method;
|
||
|
import o.C12776fGw;
|
||
|
|
||
|
/* loaded from: classes3.dex */
|
||
|
public final class VpV {
|
||
|
public static String ON_(Uri uri, Context context) {
|
||
|
String str = null;
|
||
|
try {
|
||
|
if (uri.getScheme().equals("content")) {
|
||
|
Cursor query = context.getContentResolver().query(uri, new String[]{"_display_name"}, null, null, null);
|
||
|
if (query != null) {
|
||
|
try {
|
||
|
if (query.moveToFirst()) {
|
||
|
str = query.getString(query.getColumnIndexOrThrow("_display_name"));
|
||
|
}
|
||
|
} finally {
|
||
|
query.close();
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
if (str != null) {
|
||
|
return str;
|
||
|
}
|
||
|
String path = uri.getPath();
|
||
|
int lastIndexOf = path.lastIndexOf(47);
|
||
|
return lastIndexOf != -1 ? path.substring(lastIndexOf + 1) : path;
|
||
|
} catch (Exception unused) {
|
||
|
return null;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public static boolean d(Context context) {
|
||
|
try {
|
||
|
StringBuilder sb = new StringBuilder();
|
||
|
sb.append(context.getCacheDir());
|
||
|
sb.append("/file_picker/");
|
||
|
File[] listFiles = new File(sb.toString()).listFiles();
|
||
|
if (listFiles == null) {
|
||
|
return true;
|
||
|
}
|
||
|
for (File file : listFiles) {
|
||
|
file.delete();
|
||
|
}
|
||
|
return true;
|
||
|
} catch (Exception unused) {
|
||
|
return false;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public static C12776fGw OO_(Context context, Uri uri, boolean z) {
|
||
|
FileOutputStream fileOutputStream;
|
||
|
C12776fGw.LWm lWm = new C12776fGw.LWm();
|
||
|
String ON_ = ON_(uri, context);
|
||
|
StringBuilder sb = new StringBuilder();
|
||
|
sb.append(context.getCacheDir().getAbsolutePath());
|
||
|
sb.append("/file_picker/");
|
||
|
sb.append(ON_ != null ? ON_ : Long.valueOf(System.currentTimeMillis()));
|
||
|
String obj = sb.toString();
|
||
|
File file = new File(obj);
|
||
|
if (!file.exists()) {
|
||
|
file.getParentFile().mkdirs();
|
||
|
try {
|
||
|
fileOutputStream = new FileOutputStream(obj);
|
||
|
} catch (Exception e) {
|
||
|
e = e;
|
||
|
fileOutputStream = null;
|
||
|
}
|
||
|
try {
|
||
|
try {
|
||
|
BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(fileOutputStream);
|
||
|
InputStream openInputStream = context.getContentResolver().openInputStream(uri);
|
||
|
byte[] bArr = new byte[8192];
|
||
|
while (true) {
|
||
|
int read = openInputStream.read(bArr);
|
||
|
if (read < 0) {
|
||
|
break;
|
||
|
}
|
||
|
bufferedOutputStream.write(bArr, 0, read);
|
||
|
}
|
||
|
bufferedOutputStream.flush();
|
||
|
fileOutputStream.getFD().sync();
|
||
|
} catch (Throwable th) {
|
||
|
fileOutputStream.getFD().sync();
|
||
|
throw th;
|
||
|
}
|
||
|
} catch (Exception e2) {
|
||
|
e = e2;
|
||
|
try {
|
||
|
fileOutputStream.close();
|
||
|
e.getMessage();
|
||
|
return null;
|
||
|
} catch (IOException | NullPointerException unused) {
|
||
|
e.getMessage();
|
||
|
return null;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
if (z) {
|
||
|
try {
|
||
|
int length = (int) file.length();
|
||
|
byte[] bArr2 = new byte[length];
|
||
|
try {
|
||
|
try {
|
||
|
BufferedInputStream bufferedInputStream = new BufferedInputStream(new FileInputStream(file));
|
||
|
bufferedInputStream.read(bArr2, 0, length);
|
||
|
bufferedInputStream.close();
|
||
|
} catch (IOException e3) {
|
||
|
e3.getMessage();
|
||
|
}
|
||
|
} catch (FileNotFoundException e4) {
|
||
|
e4.getMessage();
|
||
|
}
|
||
|
lWm.b = bArr2;
|
||
|
} catch (Exception unused2) {
|
||
|
}
|
||
|
}
|
||
|
lWm.d = obj;
|
||
|
lWm.a = ON_;
|
||
|
lWm.c = uri;
|
||
|
lWm.e = Long.parseLong(String.valueOf(file.length()));
|
||
|
return new C12776fGw(lWm.d, lWm.a, lWm.c, lWm.e, lWm.b);
|
||
|
}
|
||
|
|
||
|
private static String b(Class<?> cls, Object obj) {
|
||
|
try {
|
||
|
if (Build.VERSION.SDK_INT < 30) {
|
||
|
return (String) cls.getMethod("getPath", new Class[0]).invoke(obj, new Object[0]);
|
||
|
}
|
||
|
File file = (File) cls.getMethod("getDirectory", new Class[0]).invoke(obj, new Object[0]);
|
||
|
if (file != null) {
|
||
|
return file.getPath();
|
||
|
}
|
||
|
return null;
|
||
|
} catch (Exception unused) {
|
||
|
return null;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/* JADX INFO: Access modifiers changed from: package-private */
|
||
|
public static String e(String str, Context context) {
|
||
|
Class<?> cls;
|
||
|
Method method;
|
||
|
Method method2;
|
||
|
Object invoke;
|
||
|
try {
|
||
|
StorageManager storageManager = (StorageManager) context.getSystemService(PlaceTypes.STORAGE);
|
||
|
cls = Class.forName("android.os.storage.StorageVolume");
|
||
|
Method method3 = storageManager.getClass().getMethod("getVolumeList", new Class[0]);
|
||
|
method = cls.getMethod("getUuid", new Class[0]);
|
||
|
method2 = cls.getMethod("isPrimary", new Class[0]);
|
||
|
invoke = method3.invoke(storageManager, new Object[0]);
|
||
|
} catch (Exception unused) {
|
||
|
}
|
||
|
if (invoke == null) {
|
||
|
return null;
|
||
|
}
|
||
|
int length = Array.getLength(invoke);
|
||
|
for (int i = 0; i < length; i++) {
|
||
|
Object obj = Array.get(invoke, i);
|
||
|
String str2 = (String) method.invoke(obj, new Object[0]);
|
||
|
if (((Boolean) method2.invoke(obj, new Object[0])) != null && "primary".equals(str)) {
|
||
|
return b(cls, obj);
|
||
|
}
|
||
|
if (str2 != null && str2.equals(str)) {
|
||
|
return b(cls, obj);
|
||
|
}
|
||
|
}
|
||
|
return null;
|
||
|
}
|
||
|
}
|