Sunbit v2.4.4版本的 MD5 值为:a5021e5e2a58eb1d6741b432fe7533c4

以下内容为反编译后的 s.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.webkit.MimeTypeMap;
import androidx.core.content.FileProvider;
import d.b.f.u.x;
import d.b.f.u.z;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
class s {
    private static final String f24589a = "belvedere-data-v2";
    private static final String b = "media";
    private static final String c = "user";
    private static final String f24590d = "attachment_%s";
    private static final String f24591e = "camera_image_%s";
    private static final String f24592f = ".jpg";
    private static final String f24593g = "yyyyMMddHHmmssSSS";

    private String d(Context context) {
        return context.getCacheDir().getAbsolutePath();
    }

    public void a(Context context, Intent intent, Uri uri, int i2) {
        if (Build.VERSION.SDK_INT >= 23) {
            intent.addFlags(i2);
            return;
        }
        for (ResolveInfo resolveInfo : context.getPackageManager().queryIntentActivities(intent, 65536)) {
            context.grantUriPermission(resolveInfo.activityInfo.packageName, uri, i2);
        }
    }

    public File b(Context context) {
        File a2 = a(context, b);
        if (a2 == null) {
            m.c("Belvedere", "Error creating cache directory");
            return null;
        }
        return a(a2, String.format(Locale.US, f24591e, new SimpleDateFormat("yyyyMMddHHmmssSSS", Locale.US).format(new Date(System.currentTimeMillis()))), ".jpg");
    }

    String c(Context context) {
        return String.format(Locale.US, "%s%s", context.getPackageName(), context.getString(R.string.belvedere_sdk_fpa_suffix_v2));
    }

    public static MediaResult b(Context context, Uri uri) {
        String str;
        String str2;
        long j2;
        String str3 = "";
        long j3 = -1;
        if ("content".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()) {
                        j3 = query.getLong(query.getColumnIndex("_size"));
                        str3 = query.getString(query.getColumnIndex("_display_name"));
                    }
                } finally {
                    query.close();
                }
            }
            str = str3;
            j2 = j3;
            str2 = type;
        } else {
            str = "";
            str2 = str;
            j2 = -1;
        }
        return new MediaResult(null, uri, uri, str, str2, j2, -1L, -1L);
    }

    public void a(Context context, Uri uri, int i2) {
        context.revokeUriPermission(uri, i2);
    }

    public Uri a(Context context, File file) {
        String c2 = c(context);
        try {
            return FileProvider.getUriForFile(context, c2, file);
        } catch (IllegalArgumentException unused) {
            m.b("Belvedere", String.format(Locale.US, "The selected file can't be shared %s", file.toString()));
            return null;
        } catch (NullPointerException e2) {
            m.a("Belvedere", 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=====================", c2), e2);
            throw new RuntimeException("Please specify your application id");
        }
    }

    public File a(Context context, Uri uri, String str) {
        String str2;
        if (TextUtils.isEmpty(str)) {
            str2 = b;
        } else {
            str2 = c + File.separator + str;
        }
        File a2 = a(context, str2);
        String str3 = null;
        if (a2 == null) {
            m.c("Belvedere", "Error creating cache directory");
            return null;
        }
        String a3 = a(context, uri);
        if (TextUtils.isEmpty(a3)) {
            a3 = String.format(Locale.US, f24590d, new SimpleDateFormat("yyyyMMddHHmmssSSS", Locale.US).format(new Date(System.currentTimeMillis())));
            str3 = a(context, uri, true);
        }
        return a(a2, a3, str3);
    }

    public File a(Context context, String str, String str2) {
        boolean isEmpty = TextUtils.isEmpty(str);
        String str3 = c;
        if (!isEmpty) {
            str3 = c + File.separator + str;
        }
        File a2 = a(context, str3);
        if (a2 == null) {
            m.c("Belvedere", "Error creating cache directory");
            return null;
        }
        return a(a2, str2, (String) null);
    }

    private File a(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());
    }

    private File a(Context context, String str) {
        String str2;
        if (TextUtils.isEmpty(str)) {
            str2 = "";
        } else {
            str2 = str + File.separator;
        }
        File file = new File(d(context) + File.separator + f24589a + File.separator + str2);
        if (!file.isDirectory()) {
            file.mkdirs();
        }
        if (file.isDirectory()) {
            return file;
        }
        return null;
    }

    public void a(Context context) {
        File file = new File(d(context) + File.separator + f24589a);
        if (file.isDirectory()) {
            a(file);
        }
    }

    private void a(File file) {
        if (file.isDirectory()) {
            for (File file2 : file.listFiles()) {
                a(file2);
            }
        }
        file.delete();
    }

    private static String a(Context context, Uri uri, boolean z) {
        String substring;
        String lastPathSegment;
        int lastIndexOf;
        MimeTypeMap singleton = MimeTypeMap.getSingleton();
        String scheme = uri.getScheme();
        if ("content".equals(scheme)) {
            substring = singleton.getExtensionFromMimeType(context.getContentResolver().getType(uri));
        } else {
            substring = (!z.f9739e.equals(scheme) || (lastIndexOf = (lastPathSegment = uri.getLastPathSegment()).lastIndexOf(x.f9735r)) == -1) ? "tmp" : lastPathSegment.substring(lastIndexOf + 1, lastPathSegment.length());
        }
        return z ? String.format(Locale.US, ".%s", substring) : substring;
    }

    private static String a(Context context, Uri uri) {
        String scheme = uri.getScheme();
        if (!"content".equals(scheme)) {
            return z.f9739e.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 "";
    }
}