desc:nvme适配

main
xiaowusky 1 year ago
parent 6c3de9796b
commit 6671c991c0

@ -54,5 +54,6 @@ object SoundUtils {
fun stopSoundIo() { fun stopSoundIo() {
soundPlaying = false soundPlaying = false
GPIOUtils.setGpioValue(152, 0)
} }
} }

@ -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)

@ -226,11 +226,20 @@ public class CameraHelper {
if (context != null) { if (context != null) {
String nvmePath = StorageUtils.INSTANCE.getStoragePath(context, false); String nvmePath = StorageUtils.INSTANCE.getStoragePath(context, false);
if (!TextUtils.isEmpty(nvmePath)) { if (!TextUtils.isEmpty(nvmePath)) {
File mediaStorageDir = new File(nvmePath + File.separator + "video"); File parentFile = new File(nvmePath);
if (!mediaStorageDir.exists() && !mediaStorageDir.mkdirs()) { File[] externalFilesDir = context.getExternalMediaDirs();
int length = externalFilesDir.length;
for (int i = 0; i< length; i++){
File file = externalFilesDir[i];
if (file.getAbsolutePath().contains(nvmePath)){
parentFile = file;
break;
}
}
if (!parentFile.exists() && !parentFile.mkdirs()) {
return null; return null;
} }
return mediaStorageDir; return parentFile;
} else { } else {
if (!Environment.getExternalStorageState().equalsIgnoreCase(Environment.MEDIA_MOUNTED)) { if (!Environment.getExternalStorageState().equalsIgnoreCase(Environment.MEDIA_MOUNTED)) {
return null; return null;

Loading…
Cancel
Save