fix(file): resolveBaseDir 多重尝试创建目录,兼容华为/小米设备
- mkdirs() 静默失败时,尝试 Runtime.exec('mkdir -p')
- 仍失败则回退到 Sandbox 目录,避免 ENOENT 崩溃
这个提交包含在:
父节点
aeeba4fac8
当前提交
a6b1905a66
@ -278,12 +278,25 @@ object FileSDK {
|
||||
private fun resolveBaseDir(context: Context, destination: FileDownloadDestination): File = when (destination) {
|
||||
FileDownloadDestination.PublicDownloads -> {
|
||||
val appName = context.applicationInfo.loadLabel(context.packageManager).toString()
|
||||
File(
|
||||
val dir = File(
|
||||
android.os.Environment.getExternalStoragePublicDirectory(
|
||||
android.os.Environment.DIRECTORY_DOWNLOADS
|
||||
),
|
||||
appName,
|
||||
).apply { mkdirs() }
|
||||
)
|
||||
// mkdirs() 在部分华为/小米设备上静默失败,多重尝试确保目录存在
|
||||
if (!dir.exists()) {
|
||||
dir.mkdirs()
|
||||
}
|
||||
if (!dir.exists()) {
|
||||
runCatching { Runtime.getRuntime().exec(arrayOf("mkdir", "-p", dir.absolutePath)).waitFor() }
|
||||
}
|
||||
if (!dir.exists()) {
|
||||
android.util.Log.w("XWV", "resolveBaseDir: cannot create ${dir.absolutePath}, falling back to Sandbox")
|
||||
context.getExternalFilesDir(null) ?: context.filesDir
|
||||
} else {
|
||||
dir
|
||||
}
|
||||
}
|
||||
FileDownloadDestination.Sandbox -> {
|
||||
context.getExternalFilesDir(null) ?: context.filesDir
|
||||
|
||||
正在加载...
在新工单中引用
屏蔽一个用户