package com.dowse.base.util;

import android.content.Context;
import android.os.Environment;
import android.os.StatFs;
import android.os.storage.StorageManager;
import com.dowse.base.log.DSLog;
import java.io.File;
import java.lang.reflect.Method;
import java.util.List;

/* loaded from: ds_base_2.0.9_23030112.aar:classes.jar:com/dowse/base/util/TFUtil.class */
public class TFUtil {
    private static final String TAG = "TFUtil";
    static final /* synthetic */ boolean $assertionsDisabled;

    static {
        $assertionsDisabled = !TFUtil.class.desiredAssertionStatus();
    }

    public static boolean isExitSDCard() {
        if (Environment.getExternalStorageState().equals("mounted")) {
            return true;
        }
        return false;
    }

    public static long getLeftSize(String path) {
        StatFs sf = new StatFs(path);
        long blockSize = sf.getBlockSize();
        long freeBlocks = sf.getAvailableBlocks();
        return ((freeBlocks * blockSize) / 1024) / 1024;
    }

    public static long getTotalSize(String path) {
        StatFs sf = new StatFs(path);
        long blockSize = sf.getBlockSize();
        long allBlocks = sf.getBlockCount();
        return ((allBlocks * blockSize) / 1024) / 1024;
    }

    public static String getStoragePath(Context context, boolean isUsb) {
        Method VolumeInfo_GetDisk = null;
        Method VolumeInfo_GetPath = null;
        Method DiskInfo_IsUsb = null;
        Method DiskInfo_IsSd = null;
        List<Object> List_VolumeInfo = null;
        String path = "";
        StorageManager mStorageManager = (StorageManager) context.getSystemService("storage");
        try {
            Class<?> volumeInfoClazz = Class.forName("android.os.storage.VolumeInfo");
            Class<?> diskInfoClaszz = Class.forName("android.os.storage.DiskInfo");
            Method StorageManager_getVolumes = Class.forName("android.os.storage.StorageManager").getMethod("getVolumes", new Class[0]);
            VolumeInfo_GetDisk = volumeInfoClazz.getMethod("getDisk", new Class[0]);
            VolumeInfo_GetPath = volumeInfoClazz.getMethod("getPath", new Class[0]);
            DiskInfo_IsUsb = diskInfoClaszz.getMethod("isUsb", new Class[0]);
            DiskInfo_IsSd = diskInfoClaszz.getMethod("isSd", new Class[0]);
            List_VolumeInfo = (List) StorageManager_getVolumes.invoke(mStorageManager, new Object[0]);
        } catch (Exception e) {
            DSLog.e(TAG, "Exception:" + e.getMessage() + "]");
            e.printStackTrace();
        }
        try
        {
            if ($assertionsDisabled || List_VolumeInfo != null) {
                for (int i = 0; i < List_VolumeInfo.size(); i++) {
                    Object volumeInfo = List_VolumeInfo.get(i);
                    Object diskInfo = VolumeInfo_GetDisk.invoke(volumeInfo, new Object[0]);
                    if (diskInfo != null) {
                        boolean sd = ((Boolean) DiskInfo_IsSd.invoke(diskInfo, new Object[0])).booleanValue();
                        boolean usb = ((Boolean) DiskInfo_IsUsb.invoke(diskInfo, new Object[0])).booleanValue();
                        File file = (File) VolumeInfo_GetPath.invoke(volumeInfo, new Object[0]);
                        if (isUsb == usb) {
                            if (!$assertionsDisabled && file == null) {
                                throw new AssertionError();
                            }
                            path = file.getAbsolutePath();
                        } else if ((!isUsb) != sd) {
                            continue;
                        } else if (!$assertionsDisabled && file == null) {
                            throw new AssertionError();
                        } else {
                            path = file.getAbsolutePath();
                        }
                    }
                }
                return path;
            }
        }
        catch (Exception ex)
        {
        }

        throw new AssertionError();
    }
}
