367 lines
15 KiB
Java
367 lines
15 KiB
Java
package o;
|
|
|
|
import android.content.ContentProvider;
|
|
import android.content.ContentValues;
|
|
import android.content.Context;
|
|
import android.content.pm.ComponentInfo;
|
|
import android.content.pm.PackageItemInfo;
|
|
import android.content.pm.PackageManager;
|
|
import android.content.pm.ProviderInfo;
|
|
import android.content.res.XmlResourceParser;
|
|
import android.database.Cursor;
|
|
import android.database.MatrixCursor;
|
|
import android.net.Uri;
|
|
import android.os.Bundle;
|
|
import android.os.Environment;
|
|
import android.os.ParcelFileDescriptor;
|
|
import android.text.TextUtils;
|
|
import android.webkit.MimeTypeMap;
|
|
import com.airbnb.deeplinkdispatch.base.MatchIndex;
|
|
import java.io.File;
|
|
import java.io.FileNotFoundException;
|
|
import java.io.IOException;
|
|
import java.util.HashMap;
|
|
import java.util.Map;
|
|
import org.xmlpull.v1.XmlPullParserException;
|
|
|
|
/* renamed from: o.dgM, reason: case insensitive filesystem */
|
|
/* loaded from: classes.dex */
|
|
public class C9257dgM extends ContentProvider {
|
|
private static final String ATTR_NAME = "name";
|
|
private static final String ATTR_PATH = "path";
|
|
private static final String DISPLAYNAME_FIELD = "displayName";
|
|
private static final String META_DATA_FILE_PROVIDER_PATHS = "android.support.FILE_PROVIDER_PATHS";
|
|
private static final String TAG_CACHE_PATH = "cache-path";
|
|
private static final String TAG_EXTERNAL = "external-path";
|
|
private static final String TAG_EXTERNAL_CACHE = "external-cache-path";
|
|
private static final String TAG_EXTERNAL_FILES = "external-files-path";
|
|
private static final String TAG_EXTERNAL_MEDIA = "external-media-path";
|
|
private static final String TAG_FILES_PATH = "files-path";
|
|
private static final String TAG_ROOT_PATH = "root-path";
|
|
private int mResourceId;
|
|
private HBt mStrategy;
|
|
private static final String[] COLUMNS = {"_display_name", "_size"};
|
|
private static final File DEVICE_ROOT = new File("/");
|
|
private static final HashMap<String, HBt> sCache = new HashMap<>();
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
/* renamed from: o.dgM$HBt */
|
|
/* loaded from: classes.dex */
|
|
public interface HBt {
|
|
File nt_(Uri uri);
|
|
|
|
Uri nu_(File file);
|
|
}
|
|
|
|
@Override // android.content.ContentProvider
|
|
public boolean onCreate() {
|
|
return true;
|
|
}
|
|
|
|
public C9257dgM() {
|
|
this.mResourceId = 0;
|
|
}
|
|
|
|
protected C9257dgM(int i) {
|
|
this.mResourceId = i;
|
|
}
|
|
|
|
@Override // android.content.ContentProvider
|
|
public void attachInfo(Context context, ProviderInfo providerInfo) {
|
|
super.attachInfo(context, providerInfo);
|
|
if (ComponentInfo.class.getField("exported").getBoolean(providerInfo)) {
|
|
throw new SecurityException("Provider must not be exported");
|
|
}
|
|
if (!providerInfo.grantUriPermissions) {
|
|
throw new SecurityException("Provider must grant uri permissions");
|
|
}
|
|
String str = providerInfo.authority.split(";")[0];
|
|
HashMap<String, HBt> hashMap = sCache;
|
|
synchronized (hashMap) {
|
|
hashMap.remove(str);
|
|
}
|
|
this.mStrategy = getPathStrategy(context, str, this.mResourceId);
|
|
}
|
|
|
|
public static Uri getUriForFile(Context context, String str, File file) {
|
|
return getPathStrategy(context, str, 0).nu_(file);
|
|
}
|
|
|
|
public static Uri getUriForFile(Context context, String str, File file, String str2) {
|
|
return getUriForFile(context, str, file).buildUpon().appendQueryParameter("displayName", str2).build();
|
|
}
|
|
|
|
@Override // android.content.ContentProvider
|
|
public Cursor query(Uri uri, String[] strArr, String str, String[] strArr2, String str2) {
|
|
int i;
|
|
File nt_ = this.mStrategy.nt_(uri);
|
|
String queryParameter = uri.getQueryParameter("displayName");
|
|
if (strArr == null) {
|
|
strArr = COLUMNS;
|
|
}
|
|
String[] strArr3 = new String[strArr.length];
|
|
Object[] objArr = new Object[strArr.length];
|
|
int i2 = 0;
|
|
for (String str3 : strArr) {
|
|
if ("_display_name".equals(str3)) {
|
|
strArr3[i2] = "_display_name";
|
|
i = i2 + 1;
|
|
objArr[i2] = queryParameter == null ? nt_.getName() : queryParameter;
|
|
} else if ("_size".equals(str3)) {
|
|
strArr3[i2] = "_size";
|
|
i = i2 + 1;
|
|
objArr[i2] = Long.valueOf(nt_.length());
|
|
}
|
|
i2 = i;
|
|
}
|
|
String[] copyOf = copyOf(strArr3, i2);
|
|
Object[] copyOf2 = copyOf(objArr, i2);
|
|
MatrixCursor matrixCursor = new MatrixCursor(copyOf, 1);
|
|
matrixCursor.addRow(copyOf2);
|
|
return matrixCursor;
|
|
}
|
|
|
|
@Override // android.content.ContentProvider
|
|
public String getType(Uri uri) {
|
|
File nt_ = this.mStrategy.nt_(uri);
|
|
int lastIndexOf = nt_.getName().lastIndexOf(46);
|
|
if (lastIndexOf < 0) {
|
|
return "application/octet-stream";
|
|
}
|
|
String mimeTypeFromExtension = MimeTypeMap.getSingleton().getMimeTypeFromExtension(nt_.getName().substring(lastIndexOf + 1));
|
|
return mimeTypeFromExtension != null ? mimeTypeFromExtension : "application/octet-stream";
|
|
}
|
|
|
|
@Override // android.content.ContentProvider
|
|
public Uri insert(Uri uri, ContentValues contentValues) {
|
|
throw new UnsupportedOperationException("No external inserts");
|
|
}
|
|
|
|
@Override // android.content.ContentProvider
|
|
public int update(Uri uri, ContentValues contentValues, String str, String[] strArr) {
|
|
throw new UnsupportedOperationException("No external updates");
|
|
}
|
|
|
|
@Override // android.content.ContentProvider
|
|
public int delete(Uri uri, String str, String[] strArr) {
|
|
return this.mStrategy.nt_(uri).delete() ? 1 : 0;
|
|
}
|
|
|
|
@Override // android.content.ContentProvider
|
|
public ParcelFileDescriptor openFile(Uri uri, String str) throws FileNotFoundException {
|
|
return ParcelFileDescriptor.open(this.mStrategy.nt_(uri), modeToMode(str));
|
|
}
|
|
|
|
private static HBt getPathStrategy(Context context, String str, int i) {
|
|
HBt hBt;
|
|
HashMap<String, HBt> hashMap = sCache;
|
|
synchronized (hashMap) {
|
|
hBt = hashMap.get(str);
|
|
if (hBt == null) {
|
|
try {
|
|
try {
|
|
hBt = parsePathStrategy(context, str, i);
|
|
hashMap.put(str, hBt);
|
|
} catch (XmlPullParserException e) {
|
|
throw new IllegalArgumentException("Failed to parse android.support.FILE_PROVIDER_PATHS meta-data", e);
|
|
}
|
|
} catch (IOException e2) {
|
|
throw new IllegalArgumentException("Failed to parse android.support.FILE_PROVIDER_PATHS meta-data", e2);
|
|
}
|
|
}
|
|
}
|
|
return hBt;
|
|
}
|
|
|
|
static XmlResourceParser getFileProviderPathsMetaData(Context context, String str, ProviderInfo providerInfo, int i) {
|
|
if (providerInfo == null) {
|
|
throw new IllegalArgumentException("Couldn't find meta-data for provider with authority ".concat(String.valueOf(str)));
|
|
}
|
|
if (PackageItemInfo.class.getField("metaData").get(providerInfo) == null && i != 0) {
|
|
PackageItemInfo.class.getField("metaData").set(providerInfo, new Bundle(1));
|
|
((Bundle) PackageItemInfo.class.getField("metaData").get(providerInfo)).putInt(META_DATA_FILE_PROVIDER_PATHS, i);
|
|
}
|
|
try {
|
|
XmlResourceParser xmlResourceParser = (XmlResourceParser) PackageItemInfo.class.getMethod("loadXmlMetaData", PackageManager.class, String.class).invoke(providerInfo, context.getPackageManager(), META_DATA_FILE_PROVIDER_PATHS);
|
|
if (xmlResourceParser != null) {
|
|
return xmlResourceParser;
|
|
}
|
|
throw new IllegalArgumentException("Missing android.support.FILE_PROVIDER_PATHS meta-data");
|
|
} catch (Throwable th) {
|
|
Throwable cause = th.getCause();
|
|
if (cause != null) {
|
|
throw cause;
|
|
}
|
|
throw th;
|
|
}
|
|
}
|
|
|
|
private static HBt parsePathStrategy(Context context, String str, int i) throws IOException, XmlPullParserException {
|
|
IeS ieS = new IeS(str);
|
|
XmlResourceParser fileProviderPathsMetaData = getFileProviderPathsMetaData(context, str, context.getPackageManager().resolveContentProvider(str, 128), i);
|
|
while (true) {
|
|
int next = fileProviderPathsMetaData.next();
|
|
if (next == 1) {
|
|
return ieS;
|
|
}
|
|
if (next == 2) {
|
|
String name = fileProviderPathsMetaData.getName();
|
|
File file = null;
|
|
String attributeValue = fileProviderPathsMetaData.getAttributeValue(null, "name");
|
|
String attributeValue2 = fileProviderPathsMetaData.getAttributeValue(null, ATTR_PATH);
|
|
if (TAG_ROOT_PATH.equals(name)) {
|
|
file = DEVICE_ROOT;
|
|
} else if (TAG_FILES_PATH.equals(name)) {
|
|
file = context.getFilesDir();
|
|
} else if (TAG_CACHE_PATH.equals(name)) {
|
|
file = context.getCacheDir();
|
|
} else if (TAG_EXTERNAL.equals(name)) {
|
|
file = Environment.getExternalStorageDirectory();
|
|
} else if (TAG_EXTERNAL_FILES.equals(name)) {
|
|
File[] externalFilesDirs = nMh.getExternalFilesDirs(context, null);
|
|
if (externalFilesDirs.length > 0) {
|
|
file = externalFilesDirs[0];
|
|
}
|
|
} else if (TAG_EXTERNAL_CACHE.equals(name)) {
|
|
File[] externalCacheDirs = nMh.getExternalCacheDirs(context);
|
|
if (externalCacheDirs.length > 0) {
|
|
file = externalCacheDirs[0];
|
|
}
|
|
} else if (TAG_EXTERNAL_MEDIA.equals(name)) {
|
|
File[] e = RVV.e(context);
|
|
if (e.length > 0) {
|
|
file = e[0];
|
|
}
|
|
}
|
|
if (file != null) {
|
|
File buildPath = buildPath(file, attributeValue2);
|
|
if (TextUtils.isEmpty(attributeValue)) {
|
|
throw new IllegalArgumentException("Name must not be empty");
|
|
}
|
|
try {
|
|
ieS.e.put(attributeValue, buildPath.getCanonicalFile());
|
|
} catch (IOException e2) {
|
|
throw new IllegalArgumentException("Failed to resolve canonical path for ".concat(String.valueOf(buildPath)), e2);
|
|
}
|
|
} else {
|
|
continue;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
/* renamed from: o.dgM$IeS */
|
|
/* loaded from: classes.dex */
|
|
public static class IeS implements HBt {
|
|
private final String d;
|
|
final HashMap<String, File> e = new HashMap<>();
|
|
|
|
IeS(String str) {
|
|
this.d = str;
|
|
}
|
|
|
|
@Override // o.C9257dgM.HBt
|
|
public final Uri nu_(File file) {
|
|
String substring;
|
|
try {
|
|
String canonicalPath = file.getCanonicalPath();
|
|
Map.Entry<String, File> entry = null;
|
|
for (Map.Entry<String, File> entry2 : this.e.entrySet()) {
|
|
String path = entry2.getValue().getPath();
|
|
if (canonicalPath.startsWith(path) && (entry == null || path.length() > entry.getValue().getPath().length())) {
|
|
entry = entry2;
|
|
}
|
|
}
|
|
if (entry == null) {
|
|
throw new IllegalArgumentException("Failed to find configured root that contains ".concat(String.valueOf(canonicalPath)));
|
|
}
|
|
String path2 = entry.getValue().getPath();
|
|
if (path2.endsWith("/")) {
|
|
substring = canonicalPath.substring(path2.length());
|
|
} else {
|
|
substring = canonicalPath.substring(path2.length() + 1);
|
|
}
|
|
StringBuilder sb = new StringBuilder();
|
|
sb.append(Uri.encode(entry.getKey()));
|
|
sb.append('/');
|
|
sb.append(Uri.encode(substring, "/"));
|
|
return new Uri.Builder().scheme("content").authority(this.d).encodedPath(sb.toString()).build();
|
|
} catch (IOException unused) {
|
|
throw new IllegalArgumentException("Failed to resolve canonical path for ".concat(String.valueOf(file)));
|
|
}
|
|
}
|
|
|
|
@Override // o.C9257dgM.HBt
|
|
public final File nt_(Uri uri) {
|
|
String encodedPath = uri.getEncodedPath();
|
|
int indexOf = encodedPath.indexOf(47, 1);
|
|
String decode = Uri.decode(encodedPath.substring(1, indexOf));
|
|
String decode2 = Uri.decode(encodedPath.substring(indexOf + 1));
|
|
File file = this.e.get(decode);
|
|
if (file == null) {
|
|
throw new IllegalArgumentException("Unable to find configured root for ".concat(String.valueOf(uri)));
|
|
}
|
|
File file2 = new File(file, decode2);
|
|
try {
|
|
File canonicalFile = file2.getCanonicalFile();
|
|
if (canonicalFile.getPath().startsWith(file.getPath())) {
|
|
return canonicalFile;
|
|
}
|
|
throw new SecurityException("Resolved path jumped beyond configured root");
|
|
} catch (IOException unused) {
|
|
throw new IllegalArgumentException("Failed to resolve canonical path for ".concat(String.valueOf(file2)));
|
|
}
|
|
}
|
|
}
|
|
|
|
private static int modeToMode(String str) {
|
|
if (MatchIndex.ROOT_VALUE.equals(str)) {
|
|
return 268435456;
|
|
}
|
|
if ("w".equals(str) || "wt".equals(str)) {
|
|
return 738197504;
|
|
}
|
|
if ("wa".equals(str)) {
|
|
return 704643072;
|
|
}
|
|
if ("rw".equals(str)) {
|
|
return 939524096;
|
|
}
|
|
if ("rwt".equals(str)) {
|
|
return 1006632960;
|
|
}
|
|
throw new IllegalArgumentException("Invalid mode: ".concat(String.valueOf(str)));
|
|
}
|
|
|
|
private static File buildPath(File file, String... strArr) {
|
|
for (String str : strArr) {
|
|
if (str != null) {
|
|
file = new File(file, str);
|
|
}
|
|
}
|
|
return file;
|
|
}
|
|
|
|
private static String[] copyOf(String[] strArr, int i) {
|
|
String[] strArr2 = new String[i];
|
|
System.arraycopy(strArr, 0, strArr2, 0, i);
|
|
return strArr2;
|
|
}
|
|
|
|
private static Object[] copyOf(Object[] objArr, int i) {
|
|
Object[] objArr2 = new Object[i];
|
|
System.arraycopy(objArr, 0, objArr2, 0, i);
|
|
return objArr2;
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
/* renamed from: o.dgM$RVV */
|
|
/* loaded from: classes.dex */
|
|
public static class RVV {
|
|
static File[] e(Context context) {
|
|
return context.getExternalMediaDirs();
|
|
}
|
|
}
|
|
}
|