CEEX v1.0.1版本的 MD5 值为:d20246587215ec3471b0d051724c6d34
以下内容为反编译后的 Storage.java 源代码,内容仅作参考
package zendesk.belvedere;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ResolveInfo;
import android.database.Cursor;
import android.net.Uri;
import android.os.Build;
import android.text.TextUtils;
import android.util.Log;
import android.webkit.MimeTypeMap;
import androidx.core.content.FileProvider;
import com.umeng.analytics.pro.b;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
class Storage {
private static final String ATTACHMENT_NAME = "attachment_%s";
private static final String CAMERA_DATETIME_STRING_FORMAT = "yyyyMMddHHmmssSSS";
private static final String CAMERA_IMG_NAME = "camera_image_%s";
private static final String CAMERA_IMG_SUFFIX = ".jpg";
private static final String FILE_DIR_BELVEDERE = "belvedere-data-v2";
private static final String FILE_DIR_MEDIA = "media";
private static final String FILE_DIR_USER = "user";
private void clearDirectory(File file) {
if (file.isDirectory()) {
for (File file2 : file.listFiles()) {
clearDirectory(file2);
}
}
file.delete();
}
private File createTempFile(File file, String str, String str2) {
StringBuilder sb = new StringBuilder();
sb.append(str);
if (TextUtils.isEmpty(str2)) {
str2 = "";
}
sb.append(str2);
return new File(file, sb.toString());
}
public static MediaResult g(Context context, Uri uri) {
String str;
String str2;
long j;
String str3 = "";
long j2 = -1;
if (b.W.equals(uri.getScheme())) {
ContentResolver contentResolver = context.getContentResolver();
Cursor query = contentResolver.query(uri, new String[]{"_size", "_display_name"}, null, null, null);
String type = contentResolver.getType(uri);
if (query != null) {
try {
if (query.moveToFirst()) {
long j3 = query.getLong(query.getColumnIndex("_size"));
str3 = query.getString(query.getColumnIndex("_display_name"));
j2 = j3;
}
} finally {
query.close();
}
}
str = str3;
j = j2;
str2 = type;
} else {
str = "";
str2 = str;
j = -1;
}
return new MediaResult(null, uri, uri, str, str2, j, -1L, -1L);
}
private File getAttachmentDir(Context context, String str) {
String str2;
if (TextUtils.isEmpty(str)) {
str2 = "";
} else {
str2 = str + File.separator;
}
StringBuilder sb = new StringBuilder();
sb.append(getRootDir(context));
String str3 = File.separator;
sb.append(str3);
sb.append(FILE_DIR_BELVEDERE);
sb.append(str3);
sb.append(str2);
File file = new File(sb.toString());
if (!file.isDirectory()) {
file.mkdirs();
}
if (file.isDirectory()) {
return file;
}
return null;
}
private static String getExtension(Context context, Uri uri, boolean z) {
String substring;
String lastPathSegment;
int lastIndexOf;
MimeTypeMap singleton = MimeTypeMap.getSingleton();
String scheme = uri.getScheme();
if (b.W.equals(scheme)) {
substring = singleton.getExtensionFromMimeType(context.getContentResolver().getType(uri));
} else {
substring = (!"file".equals(scheme) || (lastIndexOf = (lastPathSegment = uri.getLastPathSegment()).lastIndexOf(".")) == -1) ? "tmp" : lastPathSegment.substring(lastIndexOf + 1, lastPathSegment.length());
}
return z ? String.format(Locale.US, ".%s", substring) : substring;
}
private static String getFileNameFromUri(Context context, Uri uri) {
String scheme = uri.getScheme();
if (!b.W.equals(scheme)) {
return "file".equals(scheme) ? uri.getLastPathSegment() : "";
}
Cursor query = context.getContentResolver().query(uri, new String[]{"_display_name"}, null, null, null);
if (query != null) {
try {
return query.moveToFirst() ? query.getString(0) : "";
} finally {
query.close();
}
}
return "";
}
private String getRootDir(Context context) {
return context.getCacheDir().getAbsolutePath();
}
public void a(Context context) {
File file = new File(getRootDir(context) + File.separator + FILE_DIR_BELVEDERE);
if (file.isDirectory()) {
clearDirectory(file);
}
}
public File b(Context context, String str, String str2) {
boolean isEmpty = TextUtils.isEmpty(str);
String str3 = FILE_DIR_USER;
if (!isEmpty) {
str3 = FILE_DIR_USER + File.separator + str;
}
File attachmentDir = getAttachmentDir(context, str3);
if (attachmentDir == null) {
L.e("Belvedere", "Error creating cache directory");
return null;
}
return createTempFile(attachmentDir, str2, null);
}
public File c(Context context) {
File attachmentDir = getAttachmentDir(context, FILE_DIR_MEDIA);
if (attachmentDir == null) {
L.e("Belvedere", "Error creating cache directory");
return null;
}
Locale locale = Locale.US;
return createTempFile(attachmentDir, String.format(locale, CAMERA_IMG_NAME, new SimpleDateFormat(CAMERA_DATETIME_STRING_FORMAT, locale).format(new Date(System.currentTimeMillis()))), CAMERA_IMG_SUFFIX);
}
public File d(Context context, Uri uri, String str) {
String str2;
if (TextUtils.isEmpty(str)) {
str2 = FILE_DIR_MEDIA;
} else {
str2 = FILE_DIR_USER + File.separator + str;
}
File attachmentDir = getAttachmentDir(context, str2);
String str3 = null;
if (attachmentDir == null) {
L.e("Belvedere", "Error creating cache directory");
return null;
}
String fileNameFromUri = getFileNameFromUri(context, uri);
if (TextUtils.isEmpty(fileNameFromUri)) {
Locale locale = Locale.US;
fileNameFromUri = String.format(locale, ATTACHMENT_NAME, new SimpleDateFormat(CAMERA_DATETIME_STRING_FORMAT, locale).format(new Date(System.currentTimeMillis())));
str3 = getExtension(context, uri, true);
}
return createTempFile(attachmentDir, fileNameFromUri, str3);
}
String e(Context context) {
return String.format(Locale.US, "%s%s", context.getPackageName(), context.getString(R.string.belvedere_sdk_fpa_suffix_v2));
}
public Uri f(Context context, File file) {
String e = e(context);
try {
return FileProvider.getUriForFile(context, e, file);
} catch (IllegalArgumentException unused) {
L.b("Belvedere", String.format(Locale.US, "The selected file can't be shared %s", file.toString()));
return null;
} catch (NullPointerException e2) {
String format = String.format(Locale.US, "=====================\nFileProvider failed to retrieve file uri. There might be an issue with the FileProvider \nPlease make sure that manifest-merger is working, and that you have defined the applicationId (package name) in the build.gradle\nManifest merger: http://tools.android.com/tech-docs/new-build-system/user-guide/manifest-merger\nIf your are not able to use gradle or the manifest merger, please add the following to your AndroidManifest.xml:\n <provider\n android:name=\"com.zendesk.belvedere.BelvedereFileProvider\"\n android:authorities=\"${applicationId}%s\"\n android:exported=\"false\"\n android:grantUriPermissions=\"true\">\n <meta-data\n android:name=\"android.support.FILE_PROVIDER_PATHS\"\n android:resource=\"@xml/belvedere_attachment_storage_v2\" />\n </provider>\n=====================", e);
Log.e("Belvedere", format, e2);
L.c("Belvedere", format, e2);
throw new RuntimeException("Please specify your application id");
}
}
public void h(Context context, Intent intent, Uri uri, int i) {
if (Build.VERSION.SDK_INT >= 23) {
intent.addFlags(i);
return;
}
for (ResolveInfo resolveInfo : context.getPackageManager().queryIntentActivities(intent, 65536)) {
context.grantUriPermission(resolveInfo.activityInfo.packageName, uri, i);
}
}
public void i(Context context, Uri uri, int i) {
context.revokeUriPermission(uri, i);
}
}