导航菜单

页面标题

页面副标题

Adobe Acrobat v15.3 - ARFileBrowserUtils.java 源代码

正在查看: Adobe Acrobat v15.3 应用的 ARFileBrowserUtils.java JAVA 源代码文件

本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。


package com.adobe.reader.filebrowser;

import a.c.c;
import android.app.Activity;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.drawable.BitmapDrawable;
import android.net.Uri;
import android.os.Environment;
import android.os.Parcelable;
import android.support.v4.content.FileProvider;
import android.widget.Toast;
import com.adobe.libs.buildingblocks.utils.BBFileUtils;
import com.adobe.libs.buildingblocks.utils.g;
import com.adobe.libs.buildingblocks.utils.n;
import com.adobe.libs.e.b;
import com.adobe.reader.R;
import com.adobe.reader.analytics.ARDCMAnalytics;
import com.adobe.reader.config.ARConfig;
import com.adobe.reader.emm.AREMMManager;
import com.adobe.reader.misc.ARAlert;
import com.adobe.reader.misc.ARApp;
import com.adobe.reader.utils.ARUtils;
import com.adobe.reader.viewer.ARAlertDialog;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileFilter;
import java.io.FilenameFilter;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;

public class ARFileBrowserUtils {
    private static final String DEVICE_PATH_FOR_EXSDCARD = "/mnt";
    private static final String DEVICE_PATH_FOR_FUSE = "/dev/fuse";
    private static final String DEVICE_PATH_FOR_MEDIA = "/data/media";
    private static final String DEVICE_PATH_FOR_VOLD = "/dev/block/vold";
    private static final String DIRECTORIES_CONTAINING_PDFS = "directoriesContainingPDFs";
    private static final String DIRECTORIES_NOT_CONTAINING_PDFS = "directoriesNotContainingPDFs";
    private static final String DOWNLOAD_FOLDER_FOR_TEMP_FILES = "Temp";
    public static final String EXTENSION_SEP = ".";
    public static final String INVALID_FILE_CHARS = "|\\?*<\":>/";
    private static final String MOUNT_COMMAND = "mount";
    private static final String SAF_DOWNLOAD_FOLDER = "Downloads";
    private static final String SAF_TEMP_FILES_FOLDER = "ServicesCache";
    private static final int THUMBNAIL_HEIGHT_DIP = 48;
    private static final int THUMBNAIL_SHADOW_DIP = 2;
    private static final int THUMBNAIL_WIDTH_DIP = 48;
    public static final String DEFAULT_PDF_ICON_THUMBNAIL_STRING = g.a(((BitmapDrawable) ARApp.getAppContext().getResources().getDrawable(R.drawable.file_pdf)).getBitmap());
    public static final String DEFAULT_LOCKED_PDF_ICON_THUMBAIL_STRING = g.a(((BitmapDrawable) ARApp.getAppContext().getResources().getDrawable(R.drawable.file_lockedpdf)).getBitmap());
    public static final String FOLDER_ICON_THUMBNAIL_STRING = g.a(((BitmapDrawable) ARApp.getAppContext().getResources().getDrawable(R.drawable.h_folder_small)).getBitmap());
    public static final FilenameFilter PDF_FILE_FILTER = new FilenameFilter() {
        @Override
        public final boolean accept(File file, String str) {
            return (file == null || new File(new StringBuilder().append(file.getAbsolutePath()).append(File.separatorChar).append(str).toString()).isDirectory() || !BBFileUtils.c(str)) ? false : true;
        }
    };
    public static final FilenameFilter PDF_FILE_FILTER_FOR_LOCAL_FILE_BROWSER = new FilenameFilter() {
        @Override
        public final boolean accept(File file, String str) {
            if (file == null) {
                return false;
            }
            File file2 = new File(file.getAbsolutePath() + File.separatorChar + str);
            return (file2.isDirectory() || !BBFileUtils.c(str) || file2.isHidden()) ? false : true;
        }
    };
    public static final FileFilter DIRECTORY_FILTER = new FileFilter() {
        @Override
        public final boolean accept(File file) {
            return file != null && file.isDirectory();
        }
    };
    public static final FileFilter NON_DIRECTORY_FILES_FILTER = new FileFilter() {
        @Override
        public final boolean accept(File file) {
            return (file == null || file.isDirectory()) ? false : true;
        }
    };
    private static final String ROOT_DIR = Environment.getExternalStorageDirectory().getAbsolutePath();
    public static final File sRootDirectory = new File(ROOT_DIR);
    public static final File sEmmcDirectory = new File("/emmc");
    private static int sThumbnailWidth = -1;
    private static int sThumbnailHeight = -1;
    private static int sThumbnailShadow = -1;

    public static void addDirectoriesWithNoPDFFilesToPreferences(c cVar) {
        if (cVar == null) {
            return;
        }
        String cVar2 = cVar.toString();
        SharedPreferences.Editor edit = ARApp.getAppContext().getSharedPreferences(ARApp.ADOBE_READER_PREFERENCES, 0).edit();
        edit.putString(DIRECTORIES_NOT_CONTAINING_PDFS, cVar2);
        edit.apply();
    }

    public static void addPDFContainingDirectoriesToPreferences(List<String> list) {
        if (list == null) {
            return;
        }
        Collections.sort(list, new Comparator<String>() {
            @Override
            public final int compare(String str, String str2) {
                return str.compareToIgnoreCase(str2);
            }
        });
        StringBuilder sb = new StringBuilder();
        String str = ARFileEntry.DEFAULT_ENTRY_ICON_STRING;
        Iterator<String> it = list.iterator();
        while (true) {
            String str2 = str;
            if (!it.hasNext()) {
                SharedPreferences.Editor edit = ARApp.getAppContext().getSharedPreferences(ARApp.ADOBE_READER_PREFERENCES, 0).edit();
                edit.putString(DIRECTORIES_CONTAINING_PDFS, sb.toString());
                edit.apply();
                return;
            } else {
                String next = it.next();
                sb.append(str2);
                sb.append(next);
                str = ",";
            }
        }
    }

    public static int compareFileName(ARFileEntry aRFileEntry, ARFileEntry aRFileEntry2) {
        return aRFileEntry.getFileName().toLowerCase(Locale.getDefault()).compareTo(aRFileEntry2.getFileName().toLowerCase(Locale.getDefault()));
    }

    public static boolean createDirectory(String str) {
        if (str == null) {
            return false;
        }
        String trim = str.trim();
        if (trim.length() <= 0) {
            return false;
        }
        File file = new File(trim);
        if (file.exists()) {
            return false;
        }
        file.mkdirs();
        return file.exists();
    }

    private static void destroyProcess(Process process) {
        if (process != null) {
            try {
                process.exitValue();
            } catch (IllegalThreadStateException e) {
                process.destroy();
            }
        }
    }

    public static java.lang.String equivalentFileInGivenRangeForFile(java.lang.String r13, java.lang.String r14, java.lang.String r15) {
        throw new UnsupportedOperationException("Method not decompiled: com.adobe.reader.filebrowser.ARFileBrowserUtils.equivalentFileInGivenRangeForFile(java.lang.String, java.lang.String, java.lang.String):java.lang.String");
    }

    public static String getDefaultFileCopyPath() {
        if (isPermanentStorageAvailable()) {
            return getPermanentStorageDownloadDirectoryPath();
        }
        return null;
    }

    public static List<String> getDirectoriesContainingPDFs() {
        String string = ARApp.getAppContext().getSharedPreferences(ARApp.ADOBE_READER_PREFERENCES, 0).getString(DIRECTORIES_CONTAINING_PDFS, null);
        if (string != null) {
            return getUniqueSerialDirectories(Arrays.asList(string.split(",")));
        }
        return null;
    }

    public static c getDirectoriesWithNoPDFs() {
        String string = ARApp.getAppContext().getSharedPreferences(ARApp.ADOBE_READER_PREFERENCES, 0).getString(DIRECTORIES_NOT_CONTAINING_PDFS, null);
        if (string != null) {
            try {
                return new c(string);
            } catch (Exception e) {
            }
        }
        return null;
    }

    private static File getDirectoryFromPath(String str) {
        if (str == null) {
            return null;
        }
        createDirectory(str);
        File file = new File(str);
        if (file.isDirectory()) {
            return file;
        }
        return null;
    }

    public static String getDirectoryPathForSAF() {
        String absolutePath = new File(ARApp.getAppContext().getFilesDir(), SAF_DOWNLOAD_FOLDER).getAbsolutePath();
        if (getDirectoryFromPath(absolutePath) != null) {
            return absolutePath;
        }
        return null;
    }

    public static String getDirectoryPathForTempFile() {
        String absolutePath = new File(ARApp.getAppContext().getFilesDir(), "Temp").getAbsolutePath();
        if (getDirectoryFromPath(absolutePath) != null) {
            return absolutePath;
        }
        return null;
    }

    private static String getDownloadDirectoryPath() {
        String absolutePath = isSDCardAvailable() ? Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getAbsolutePath() : isEmmcAvailable() ? sEmmcDirectory.getAbsolutePath() + File.separator + Environment.DIRECTORY_DOWNLOADS : null;
        if (absolutePath == null || getDirectoryFromPath(absolutePath) != null) {
            return absolutePath;
        }
        return null;
    }

    public static int getFileBrowserDrawableIconForFile(String str) {
        return ARUtils.getDrawableIconForFile(str, false);
    }

    public static String getFileManagerDefaultDirectoryPath() {
        if (isPermanentStorageAvailable()) {
            return getDownloadDirectoryPath();
        }
        return null;
    }

    public static String getFilePathForDirectory(String str, String str2, boolean z) {
        String str3;
        String str4;
        int i = 0;
        if (str != null) {
            String str5 = "availablePathInExtStorageForFileNamed: External Storage path:" + str;
            if (z) {
                int lastIndexOf = str2.lastIndexOf(46);
                if (lastIndexOf == -1) {
                    return null;
                }
                String substring = str2.substring(0, lastIndexOf);
                String substring2 = str2.substring(lastIndexOf);
                String str6 = str2;
                while (true) {
                    str4 = str + File.separator + str6;
                    File file = new File(str4);
                    if (!file.exists() || !file.isFile()) {
                        break;
                    }
                    i++;
                    str6 = substring + getFileRenameSuffixForIndex(i) + substring2;
                }
                if (i > 0) {
                    String str7 = "availablePathInExtStorageForFileNamed: renamed file " + str2 + " to " + str6;
                    str3 = str4;
                } else {
                    str3 = str4;
                }
            } else {
                str3 = str + File.separator + str2;
            }
        } else {
            str3 = null;
        }
        return str3;
    }

    private static String getFileRenameSuffixForIndex(int i) {
        return String.format("-%d", Integer.valueOf(i));
    }

    public static int getFileThumbnailHeight() {
        if (sThumbnailHeight < 0) {
            sThumbnailHeight = Math.round(ARApp.getAppContext().getResources().getDisplayMetrics().density * 48.0f);
        }
        return sThumbnailHeight;
    }

    public static int getFileThumbnailShadow() {
        if (sThumbnailShadow < 0) {
            sThumbnailShadow = Math.round(ARApp.getAppContext().getResources().getDisplayMetrics().density * 2.0f);
        }
        return sThumbnailShadow;
    }

    public static int getFileThumbnailWidth() {
        if (sThumbnailWidth < 0) {
            sThumbnailWidth = Math.round(ARApp.getAppContext().getResources().getDisplayMetrics().density * 48.0f);
        }
        return sThumbnailWidth;
    }

    public static File[] getListOfExternalStorageMountPoints() {
        Process process;
        Process start;
        boolean z;
        ArrayList arrayList = new ArrayList();
        try {
            ProcessBuilder processBuilder = new ProcessBuilder(MOUNT_COMMAND);
            processBuilder.redirectErrorStream(true);
            start = processBuilder.start();
            try {
                start.waitFor();
            } catch (Exception e) {
            }
        } catch (Exception e2) {
            process = null;
        }
        try {
            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(start.getInputStream()));
            while (true) {
                String readLine = bufferedReader.readLine();
                if (readLine == null) {
                    break;
                }
                if (readLine.startsWith(DEVICE_PATH_FOR_VOLD) || readLine.startsWith(DEVICE_PATH_FOR_FUSE) || readLine.startsWith(DEVICE_PATH_FOR_MEDIA) || readLine.startsWith(DEVICE_PATH_FOR_EXSDCARD)) {
                    String str = readLine.split(" ")[1];
                    File file = new File(str);
                    String str2 = "getListOfExternalStorageMountPoints: external storage path:" + str;
                    arrayList.add(file);
                }
            }
            int size = arrayList.size();
            ArrayList arrayList2 = new ArrayList();
            for (int i = 0; i < size; i++) {
                String parent = ((File) arrayList.get(i)).getParent();
                int i2 = 0;
                while (true) {
                    if (i2 >= size) {
                        z = false;
                        break;
                    }
                    if (i != i2 && parent != null && parent.indexOf(((File) arrayList.get(i2)).getAbsolutePath()) == 0) {
                        z = true;
                        break;
                    }
                    i2++;
                }
                if (z) {
                    arrayList2.add(arrayList.get(i));
                } else {
                    String str3 = "getListOfExternalStorageMountPoints: external storage path after filter :" + ((File) arrayList.get(i)).getAbsolutePath();
                }
            }
            arrayList.removeAll(arrayList2);
            arrayList2.clear();
            destroyProcess(start);
            if (!arrayList.contains(sRootDirectory)) {
                arrayList.add(sRootDirectory);
            }
            return (File[]) arrayList.toArray(new File[arrayList.size()]);
        } catch (Exception e3) {
            process = start;
            if (process != null) {
                process.destroy();
            }
            return new File[]{sRootDirectory};
        }
    }

    public static File getPermanentStorageDownloadDirectory() {
        return getDirectoryFromPath(getPermanentStorageDownloadDirectoryPath());
    }

    private static String getPermanentStorageDownloadDirectoryPath() {
        String str;
        String downloadDirectoryPath = getDownloadDirectoryPath();
        if (downloadDirectoryPath != null) {
            str = downloadDirectoryPath + File.separator + (AREMMManager.getInstance().getEMMName() == b.INTUNE ? ARConfig.DOWNLOAD_FOLDER_NAME_INTUNE : ARConfig.DOWNLOAD_FOLDER_NAME);
        } else {
            str = null;
        }
        if (getDirectoryFromPath(str) == null) {
            return null;
        }
        return str;
    }

    public static String getTempDirectoryPathForSAF() {
        String absolutePath = new File(ARApp.getAppContext().getCacheDir(), SAF_TEMP_FILES_FOLDER).getAbsolutePath();
        if (getDirectoryFromPath(absolutePath) != null) {
            return absolutePath;
        }
        return null;
    }

    public static String getTempFileCopyPath() {
        return getDefaultFileCopyPath() + File.separator + "Temp";
    }

    public static List<String> getUniqueSerialDirectories(List<String> list) {
        ArrayList arrayList = new ArrayList();
        ArrayList arrayList2 = new ArrayList();
        if (list == null || list.size() <= 0) {
            return list;
        }
        for (String str : list) {
            Long valueOf = Long.valueOf(ARUtils.getFileMountId(str));
            if (!arrayList.contains(valueOf)) {
                arrayList.add(valueOf);
                arrayList2.add(str);
            }
        }
        return arrayList2;
    }

    public static String internalPathForFileNamed(String str, boolean z) {
        return getFilePathForDirectory(getDirectoryPathForSAF(), str, z);
    }

    public static boolean isCachedFile(String str) {
        if (str == null) {
            return false;
        }
        File file = new File(str);
        if (file.exists()) {
            return BBFileUtils.c(file, ARApp.getAppContext().getCacheDir());
        }
        return false;
    }

    public static boolean isDirectoryWithUniqueSerial(String str, List<String> list) {
        try {
            long fileMountId = ARUtils.getFileMountId(str);
            File file = null;
            if (list != null && list.size() > 0) {
                for (String str2 : list) {
                    if (fileMountId == ARUtils.getFileMountId(str2)) {
                        if (file == null) {
                            file = new File(str);
                        }
                        File file2 = new File(str2);
                        if (file != null && file.isDirectory() && file2.isDirectory() && file2.getFreeSpace() == file.getFreeSpace() && file2.list().length == file.list().length) {
                            return false;
                        }
                    }
                    file = file;
                }
            }
            return true;
        } catch (Exception e) {
            return true;
        }
    }

    public static boolean isEmmcAvailable() {
        return sEmmcDirectory.exists() && sEmmcDirectory.isDirectory();
    }

    public static boolean isPermanentStorageAvailable() {
        return isSDCardAvailable() || isEmmcAvailable();
    }

    public static boolean isSDCardAvailable() {
        return Environment.getExternalStorageState().equals("mounted");
    }

    public static String pathInExtStorageForFileNamed(String str, boolean z) {
        String str2 = null;
        File permanentStorageDownloadDirectory = getPermanentStorageDownloadDirectory();
        if (permanentStorageDownloadDirectory != null && permanentStorageDownloadDirectory.exists()) {
            str2 = permanentStorageDownloadDirectory.getAbsolutePath();
        }
        return getFilePathForDirectory(str2, str, z);
    }

    public static void shareFile(Activity activity, List<ARFileEntry> list) {
        Intent intent = new Intent("android.intent.action.SEND_MULTIPLE");
        intent.setType("*/*");
        ARDCMAnalytics.getInstance().trackAction("Local", ARDCMAnalytics.SHARE, ARDCMAnalytics.DOCUMENT_BUTTON_TAPPED);
        ArrayList<? extends Parcelable> arrayList = new ArrayList<>();
        Iterator<ARFileEntry> it = list.iterator();
        while (it.hasNext()) {
            String filePath = it.next().getFilePath();
            File file = new File(filePath);
            if (file.exists()) {
                Uri fromFile = Uri.fromFile(file);
                if (n.a()) {
                    fromFile = FileProvider.getUriForFile(activity, ARApp.getContentProviderAuthority(), file);
                    intent.addFlags(1);
                } else if (BBFileUtils.c(filePath, getDirectoryPathForSAF())) {
                    String equivalentFileInGivenRangeForFile = equivalentFileInGivenRangeForFile(getFilePathForDirectory(getTempFileCopyPath(), file.getName(), false), getFilePathForDirectory(getTempFileCopyPath(), file.getName(), true), filePath);
                    if (equivalentFileInGivenRangeForFile == null) {
                        File file2 = new File(getFilePathForDirectory(getTempFileCopyPath(), file.getName(), true));
                        if (BBFileUtils.b(file, file2)) {
                            fromFile = Uri.fromFile(file2);
                        }
                    } else {
                        fromFile = Uri.fromFile(new File(equivalentFileInGivenRangeForFile));
                    }
                }
                arrayList.add(fromFile);
            }
        }
        intent.putParcelableArrayListExtra("android.intent.extra.STREAM", arrayList);
        intent.putExtra("android.intent.extra.SUBJECT", String.format(activity.getResources().getString(R.string.IDS_SHARE_STR), new Object[0]));
        if (intent.resolveActivity(activity.getPackageManager()) != null) {
            activity.startActivity(Intent.createChooser(intent, activity.getResources().getString(R.string.IDS_SHARE_APP_CHOOSER_TITLE)));
        } else {
            Toast.makeText(activity, activity.getString(2131230746), 0).show();
        }
    }

    public static void shareFileBrowserFiles(Activity activity, List<ARFileEntry> list) {
        boolean z;
        if (list.size() == 0) {
            return;
        }
        Iterator<ARFileEntry> it = list.iterator();
        while (true) {
            if (!it.hasNext()) {
                z = false;
                break;
            }
            ARFileEntry next = it.next();
            if (!n.a() && BBFileUtils.c(next.getFilePath(), getDirectoryPathForSAF())) {
                z = true;
                break;
            }
        }
        if (z) {
            showDialogForSharingPrivateAreaFile(activity, list);
        } else {
            shareFile(activity, list);
        }
    }

    private static void showDialogForSharingPrivateAreaFile(final Activity activity, final List<ARFileEntry> list) {
        new ARAlert(activity, new ARAlert.DialogProvider() {
            @Override
            public final Dialog getDialog() {
                ARAlertDialog aRAlertDialog = new ARAlertDialog(activity);
                aRAlertDialog.setTitle(ARApp.getAppContext().getString(R.string.IDS_SHARE_APP_CHOOSER_TITLE));
                aRAlertDialog.setMessage(list.size() > 1 ? activity.getResources().getString(R.string.IDS_MULTIPLE_PRIVATE_DOCUMENT_COPY_WARNING_MESSAGE) : activity.getResources().getString(R.string.IDS_ADC_SHARE_CONFIRMATION_STR));
                aRAlertDialog.setButton(-1, activity.getResources().getString(2131230753), new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        ARFileBrowserUtils.shareFile(activity, list);
                    }
                });
                aRAlertDialog.setButton(-2, ARApp.getAppContext().getString(2131230745), new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        dialogInterface.dismiss();
                    }
                });
                return aRAlertDialog;
            }
        }).show();
    }

    public static void sortFileList(File[] fileArr) {
        if (fileArr != null) {
            Arrays.sort(fileArr, new Comparator<File>() {
                @Override
                public final int compare(File file, File file2) {
                    return file.getName().toLowerCase().compareTo(file2.getName().toLowerCase());
                }
            });
        }
    }

    public static String tempPathForFileNamed(String str, boolean z) {
        return getFilePathForDirectory(getDirectoryPathForTempFile(), str, z);
    }
}