|
|
@ -6,8 +6,7 @@ import android.os.storage.StorageManager
|
|
|
|
import android.os.storage.StorageVolume
|
|
|
|
import android.os.storage.StorageVolume
|
|
|
|
import java.lang.reflect.InvocationTargetException
|
|
|
|
import java.lang.reflect.InvocationTargetException
|
|
|
|
|
|
|
|
|
|
|
|
val USB_KEYWORDS = arrayOf("USB", "U 盘")
|
|
|
|
val NVME_KEYWORDS = arrayOf("yinuo nvme", "YINUO NVME", "YINUO", "NVME")
|
|
|
|
val NVME_KEYWORDS = arrayOf("新加卷")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
object StorageUtils {
|
|
|
|
object StorageUtils {
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -31,15 +30,21 @@ object StorageUtils {
|
|
|
|
val getUserLabel = storageVolumeClazz.getMethod("getUserLabel")
|
|
|
|
val getUserLabel = storageVolumeClazz.getMethod("getUserLabel")
|
|
|
|
for (i in 0 until length) {
|
|
|
|
for (i in 0 until length) {
|
|
|
|
val storageVolumeElement: StorageVolume = result[i]
|
|
|
|
val storageVolumeElement: StorageVolume = result[i]
|
|
|
|
|
|
|
|
// 内部存储
|
|
|
|
|
|
|
|
if (storageVolumeElement.isPrimary) {
|
|
|
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
}
|
|
|
|
val userLabel = getUserLabel.invoke(storageVolumeElement) as String
|
|
|
|
val userLabel = getUserLabel.invoke(storageVolumeElement) as String
|
|
|
|
val path = getPath.invoke(storageVolumeElement) as String
|
|
|
|
val path = getPath.invoke(storageVolumeElement) as String
|
|
|
|
if (isUsb) {
|
|
|
|
// nvme
|
|
|
|
if (USB_KEYWORDS.contains(userLabel)) {
|
|
|
|
if (!isUsb) {
|
|
|
|
|
|
|
|
// 大于400GB的也当硬盘看待
|
|
|
|
|
|
|
|
if (containsNvmeKeys(userLabel) || getSizeInGB(path) > 400) {
|
|
|
|
targetpath = path
|
|
|
|
targetpath = path
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
// 大于400GB的也当硬盘看待
|
|
|
|
// 不是内部存储,也不是硬盘,就当作U盘
|
|
|
|
if (NVME_KEYWORDS.contains(userLabel) || getSizeInGB(path) > 400) {
|
|
|
|
if (!containsNvmeKeys(userLabel)) {
|
|
|
|
targetpath = path
|
|
|
|
targetpath = path
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -56,6 +61,16 @@ object StorageUtils {
|
|
|
|
return targetpath
|
|
|
|
return targetpath
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private fun containsNvmeKeys(label: String): Boolean {
|
|
|
|
|
|
|
|
NVME_KEYWORDS.forEach {
|
|
|
|
|
|
|
|
if (label.contains(it)) {
|
|
|
|
|
|
|
|
LogUtils.w("label:${label} is nvme")
|
|
|
|
|
|
|
|
return true
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private const val BYTE_GB = 1024 * 1024 * 1024f
|
|
|
|
private const val BYTE_GB = 1024 * 1024 * 1024f
|
|
|
|
private fun getSizeInGB(path: String): Int {
|
|
|
|
private fun getSizeInGB(path: String): Int {
|
|
|
|
val statfs = StatFs(path)
|
|
|
|
val statfs = StatFs(path)
|
|
|
|