注册 登录
落伍者 返回首页

编织/ws美梦的个人空间 https://www.im286.net/?908975 [收藏] [复制] [RSS]

日志

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

已有 138 次阅读2016-5-11 14:50

[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文件isFilename valid函数
static boolean isFilename valid(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

本文(支持OTG,默认位置选择OTG U盘,下 载文件,browser发生crash)转载于一牛网论坛,转载请注明原文来源

评论 (0 个评论)

论坛客服/商务合作/投诉举报:2171544 (QQ)
落伍者创建于2001/03/14,本站内容均为会员发表,并不代表落伍立场!
拒绝任何人以任何形式在本论坛发表与中华人民共和国法律相抵触的言论!
落伍官方微信:2030286 邮箱:(djfsys@gmail.com|tech@im286.com)
© 2001-2014

浙公网安备 33060302000191号

浙ICP备11034705号 BBS专项电子公告通信管[2010]226号

  落伍法律顾问: ITlaw-庄毅雄

手机版|找回帐号|不能发帖?|Archiver|落伍者

GMT+8, 2025-5-12 13:51 , Processed in 0.027887 second(s), 21 queries , Gzip On.

返回顶部