现象
storage下可读取,但/mnt/media_rw不可读取
/mnt/media_rw/A009-1B4F/rk3568_s-ota-20230704.zip (Permission Denied)
解决方法
把/mnt/media_rw/ 替换为 /storage
1.在解析ota升级包时,将 /mnt/media_rw/ 替换为 /storage
if (Build.VERSION.SDK_INT >= 30) { if (mImageFilePath.startsWith("/data/media")) { tempPath = mImageFilePath.replace("/data/media", "/storage/emulated"); } else if (mImageFilePath.startsWith("/mnt/media_rw")) { tempPath = mImageFilePath.replace("/mnt/media_rw", "/storage"); } }
2.真正执行升级逻辑时,将 /storage 再替换回 /mnt/media_rw/
if (Build.VERSION.SDK_INT >= 30) { // Build.VERSION_CODES.R Log.d(TAG, "installPackage SDK version >= Build.VERSION_CODES.R,should convert update file path."); if (parsedUpdate.mUrl.startsWith("file:///storage/emulated/0")) { convertPath = parsedUpdate.mUrl.replace("/storage/emulated/0", "/data/media/0"); Log.d(TAG, "startsWith(\"file:///storage/emulated/0\")"); } else if (parsedUpdate.mUrl.startsWith("file:///storage")) { convertPath = parsedUpdate.mUrl.replace("/storage", "/mnt/media_rw"); Log.d(TAG, "startsWith(\"file://storage\")"); } Log.d(TAG, "installPackage update " + parsedUpdate.mUrl + " to " + convertPath); }