微波EDA网,见证研发工程师的成长!
首页 > 研发问答 > 手机设计讨论 > MTK手机平台交流 > 支持OTG,默认位置选择OTG U盘,下 载文件,browser发生crash

支持OTG,默认位置选择OTG U盘,下 载文件,browser发生crash

时间:10-02 整理:3721RD 点击:
[DESCRIPTION]

手机支持OTG功能,插入OTG连U盘,将默认位置设为OTG u盘,进入browser下载文件,browser发生crash
[SOLUTION]

crash 是因为google default download provider不支持这个otg path, 如果贵司要修改,可修改JB版本:
一.alps\packages\providers\DownloadProvider\src\com\android\providers\downloADS\DownloadProvider.Java 文件777行
checkFileUriDestination() 函数内容:
private void checkFileUriDestination(ContentValues values) {
String fileUri = values.getAsString(Downloads.Impl.COLUMN_FILE_NAME_HINT);
if (fileUri == null) {
throw new IllegalArgumentException(
"DESTINATION_FILE_URI must include a file URI under COLUMN_FILE_NAME_HINT");
}
Uri uri = Uri.parse(fileUri);
String scheme = uri.getScheme();
if (scheme == null || !scheme.equals("file")) {
throw new IllegalArgumentException("Not a file URI: " + uri);
}
final String path = uri.getPath();
if (path == null) {
throw new IllegalArgumentException("Invalid file URI: " + uri);
}
try {
final String canonicalPath = new File(path).getCanonicalPath();
final String externalPath = Environment.getExternalStorageDirectory().getAbsolutePath();
if (!canonicalPath.startsWith(externalPath) && !canonicalPath.startsWith("/storage/sdcard1/")) {
throw new SecurityException("Destination must be on external storage: " + uri);
}
} catch (IOException e) {
throw new SecurityException("Problem resolving path: " + uri);
}
修该为:
private void checkFileUriDestination(ContentValues values) {
String fileUri = values.getAsString(Downloads.Impl.COLUMN_FILE_NAME_HINT);
if (fileUri == null) {
throw new IllegalArgumentException(
"DESTINATION_FILE_URI must include a file URI under COLUMN_FILE_NAME_HINT");
}
Uri uri = Uri.parse(fileUri);
String scheme = uri.getScheme();
if (scheme == null || !scheme.equals("file")) {
throw new IllegalArgumentException("Not a file URI: " + uri);
}
final String path = uri.getPath();
if (path == null) {
throw new IllegalArgumentException("Invalid file URI: " + uri);
}
try {
final String canonicalPath = new File(path).getCanonicalPath();
final String externalPath =
Environment.getExternalStorageDirectory().getAbsolutePath();
if (!canonicalPath.startsWith(externalPath) &&
!canonicalPath.startsWith("/storage/sdcard1/")
&& !canonicalPath.startsWith("mnt/usbotg")) {
throw new SecurityException("Destination must be on external storage: " + uri);
}
} catch (IOException e) {
throw new SecurityException("Problem resolving path: " + uri);
}
}
二.再帮忙修改
alps\packages\providers\DownloadProvider\src\com\android\providers\downloads\StorageManager.java 文件
1,在第87行处添加以下内容:
private static final String OTG_STORAGE_DIR = "/mnt/usbotg";
2, 第140行函数verifySpace(int destination, String path, long length) 内容:
void verifySpace(int destination, String path, long length) throws StopRequestException {
resetBytesDownloadedSinceLastCheckOnSpace();
File dir = null;
if (Constants.LOGV) {
Log.i(Constants.TAG, "in verifySpace, destination: " + destination +
", path: " + path + ", length: " + length);
}
if (path == null) {
throw new IllegalArgumentException("path can't be null");
}
switch (destination) {
case Downloads.Impl.DESTINATION_CACHE_PARTITION:
case Downloads.Impl.DESTINATION_CACHE_PARTITION_NOROAMING:
case Downloads.Impl.DESTINATION_CACHE_PARTITION_PURGEABLE:
dir = mDownloadDataDir;
break;
case Downloads.Impl.DESTINATION_EXTERNAL:
dir = mExternalStorageDir;
break;
case Downloads.Impl.DESTINATION_SYSTEMCACHE_PARTITION:
dir = mSystemCacheDir;
break;
case Downloads.Impl.DESTINATION_FILE_URI:
if (path.startsWith(EXTRA_STORAGE_DIR)) {
/// M: new file to extr storage dir
dir = new File(EXTRA_STORAGE_DIR);
} else if (path.startsWith(mExternalStorageDir.getPath())) {
dir = mExternalStorageDir;
} else if (path.startsWith(mDownloadDataDir.getPath())) {
dir = mDownloadDataDir;
} else if (path.startsWith(mSystemCacheDir.getPath())) {
dir = mSystemCacheDir;
}
break;
}
if (dir == null) {
throw new IllegalStateException("invalid combination of destination: " + destination +
", path: " + path);
}
finDSPace(dir, length, destination);
}
修改为如下:
void verifySpace(int destination, String path, long length) throws StopRequestException {
resetBytesDownloadedSinceLastCheckOnSpace();
File dir = null;
if (Constants.LOGV) {
Log.i(Constants.TAG, "in verifySpace, destination: " + destination +
", path: " + path + ", length: " + length);
}
if (path == null) {
throw new IllegalArgumentException("path can't be null");
}
switch (destination) {
case Downloads.Impl.DESTINATION_CACHE_PARTITION:
case Downloads.Impl.DESTINATION_CACHE_PARTITION_NOROAMING:
case Downloads.Impl.DESTINATION_CACHE_PARTITION_PURGEABLE:
dir = mDownloadDataDir;
break;
case Downloads.Impl.DESTINATION_EXTERNAL:
dir = mExternalStorageDir;
break;
case Downloads.Impl.DESTINATION_SYSTEMCACHE_PARTITION:
dir = mSystemCacheDir;
break;
case Downloads.Impl.DESTINATION_FILE_URI:
if (path.startsWith(EXTRA_STORAGE_DIR)) {
/// M: new file to extr storage dir
dir = new File(EXTRA_STORAGE_DIR);
} else if (path.startsWith(OTG_STORAGE_DIR)) {
dir = new File(OTG_STORAGE_DIR);
} else if (path.startsWith(mExternalStorageDir.getPath())) {
dir = mExternalStorageDir;
} else if (path.startsWith(mDownloadDataDir.getPath())) {
dir = mDownloadDataDir;
} else if (path.startsWith(mSystemCacheDir.getPath())) {
dir = mSystemCacheDir;
}
break;
}
if (dir == null) {
throw new IllegalStateException("invalid combination of destination: " + destination +
", path: " + path);
}
findSpace(dir, length, destination);
}
KK版本:
修改
alps\packages\providers\DownloadProvider\src\com\android\providers\downloads\Helpers.ja
va文件isFilenameValid函数
static boolean isFilenameValid(String filename, File downloadsDataDir) {
final String[] whitelist;
try {
filename = new File(filename).getCanonicalPath();
whitelist = new String[] {
downloadsDataDir.getCanonicalPath(),
Environment.getDownloADCacheDirectory().getCanonicalPath(),
Environment.getExternalStorageDirectory().getCanonicalPath(),
"/storage/sdcard1",
"/storage/usbotg", //----add this line
};
thanks

谢谢分享

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top