`
v5browser
  • 浏览: 1138767 次
社区版块
存档分类
最新评论

DownloadProvider

 
阅读更多

DownloadProvider 中 DRM 关注。

DownloadDrmHelper


DrmConvertSession


首先 DownloadThead 中

/**
* Read HTTP response headers and take appropriate action, including setting up the destination
* file and updating the database.
*/
private void processResponseHeaders(State state, InnerState innerState, HttpResponse response)
throws StopRequestException {
// if(Constants.LOGV) Log.v(LOGTAG, "enter processResponseHeaders()");

if (state.mContinuingDownload) {
// ignore response headers on resume requests
return;
}

readResponseHeaders(state, innerState, response);
if (DownloadDrmHelper.isDrmConvertNeeded(state.mMimeType)) { // 检测 是否含有 DRM mimetype 的 数据 , 如有 创建 DrmConvertSession。
mDrmConvertSession = DrmConvertSession.open(mContext, state.mMimeType);
if (mDrmConvertSession == null) {
throw new StopRequestException(Downloads.Impl.STATUS_NOT_ACCEPTABLE, "Mimetype "
+ state.mMimeType + " can not be converted.");
}
}

state.mFilename = Helpers.generateSaveFile(
mContext,
mInfo.mUri,
mInfo.mHint,
innerState.mHeaderContentDisposition,
innerState.mHeaderContentLocation,
state.mMimeType,
mInfo.mDestination,
(innerState.mHeaderContentLength != null) ?
Long.parseLong(innerState.mHeaderContentLength) : 0,
mInfo.mIsPublicApi, mStorageManager);
checkBin(state);
try {
state.mStream = new FileOutputStream(state.mFilename);
} catch (FileNotFoundException exc) {
throw new StopRequestException(Downloads.Impl.STATUS_FILE_ERROR,
"while opening destination file: " + exc.toString(), exc);
}
if (Constants.LOGV) {
Log.v(Constants.TAG, "writing " + mInfo.mUri + " to " + state.mFilename);
}

updateDatabaseFromHeaders(state, innerState);
// check connectivity again now that we know the total size
checkConnectivity();
}



Helper 中


/**
* Creates a filename (where the file should be saved) from info about a download.
*/
static String generateSaveFile(
Context context,
String url,
String hint,
String contentDisposition,
String contentLocation,
String mimeType,
int destination,
long contentLength,
boolean isPublicApi, StorageManager storageManager) throws StopRequestException {
checkCanHandleDownload(context, mimeType, destination, isPublicApi);
String path;
File base = null;
if (destination == Downloads.Impl.DESTINATION_FILE_URI) {
path = Uri.parse(hint).getPath();
} else {
base = storageManager.locateDestinationDirectory(mimeType, destination,
contentLength);
path = chooseFilename(url, hint, contentDisposition, contentLocation,
destination);
}
storageManager.verifySpace(destination, path, contentLength);
path = getFullPath(path, mimeType, destination, base);
if (DownloadDrmHelper.isDrmConvertNeeded(mimeType)) {
path = DownloadDrmHelper.modifyDrmFwLockFileExtension(path); // 文件名的确定
}

return path;
}


DownloadThread

/**
* Write a data buffer to the destination file.
* @param data buffer containing the data to write
* @param bytesRead how many bytes to write from the buffer
*/
private void writeDataToDestination(State state, byte[] data, int bytesRead)
throws StopRequestException {
// if(Constants.LOGV) Log.v(LOGTAG, "enter writeDataToDestination()");

for (;;) {
try {
if (state.mStream == null) {
state.mStream = new FileOutputStream(state.mFilename, true);
}
mStorageManager.verifySpaceBeforeWritingToFile(mInfo.mDestination, state.mFilename,
bytesRead);
if (!DownloadDrmHelper.isDrmConvertNeeded(mInfo.mMimeType)) { //保存数据时 针对 Drm 做处理
state.mStream.write(data, 0, bytesRead);
} else {
byte[] convertedData = mDrmConvertSession.convert(data, bytesRead);
if (convertedData != null) {
state.mStream.write(convertedData, 0, convertedData.length);
} else {
throw new StopRequestException(Downloads.Impl.STATUS_FILE_ERROR,
"Error converting drm data.");
}
}

return;
} catch (IOException ex) {
// couldn't write to file. are we out of space? check.
// TODO this check should only be done once. why is this being done
// in a while(true) loop (see the enclosing statement: for(;;)
if (state.mStream != null) {
mStorageManager.verifySpace(mInfo.mDestination, state.mFilename, bytesRead);
}
} finally {
if (mInfo.mDestination == Downloads.Impl.DESTINATION_EXTERNAL) {
closeDestination(state);
}
}
}
}



Helper

private static void checkCanHandleDownload(Context context, String mimeType, int destination,
boolean isPublicApi) throws StopRequestException {
return;
if (isPublicApi) {
return;
}

if (destination == Downloads.Impl.DESTINATION_EXTERNAL
|| destination == Downloads.Impl.DESTINATION_CACHE_PARTITION_PURGEABLE) {
if (mimeType == null) {
throw new StopRequestException(Downloads.Impl.STATUS_NOT_ACCEPTABLE,
"external download with no mime type not allowed");
}
if (!DownloadDrmHelper.isDrmMimeType(context, mimeType)) { // 查看系统是否支持 DRM 数据的打开
// Check to see if we are allowed to download this file. Only files
// that can be handled by the platform can be downloaded.
// special case DRM files, which we should always allow downloading.
Intent intent = new Intent(Intent.ACTION_VIEW);

// We can provide data as either content: or file: URIs,
// so allow both. (I think it would be nice if we just did
// everything as content: URIs)
// Actually, right now the download manager's UId restrictions
// prevent use from using content: so it's got to be file: or
// nothing

PackageManager pm = context.getPackageManager();
intent.setDataAndType(Uri.fromParts("file", "", null), mimeType);
ResolveInfo ri = pm.resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY);
//Log.i(Constants.TAG, "*** FILENAME QUERY " + intent + ": " + list);

if (ri == null) {
if (Constants.LOGV) {
Log.v(Constants.TAG, "no handler found for type " + mimeType);
}
throw new StopRequestException(Downloads.Impl.STATUS_NOT_ACCEPTABLE,
"no handler found for this download type");
}
}

}
}


分享到:
评论

相关推荐

    apk文件 DownloadProvider(电视直播视频)

    apk文件 DownloadProvider(电视直播视频)apk文件 DownloadProvider(电视直播视频)apk文件 DownloadProvider(电视直播视频)apk文件 DownloadProvider(电视直播视频)apk文件 DownloadProvider(电视直播视频)...

    安卓DownloadProvider下载文件

    android利用系统DownloadProvider实现下载,多文件多线程后台下载,有需要下载功能的可以直接导入到程序中

    修改过的DownloadProvider-master

    修改过的DownloadProvider-master,方便大家使用

    使用DownloadProvider进行文件下载全攻略.pdf

    使用DownloadProvider进行文件下载全攻略.pdf

    DownloadProvider.apk

    DownloadProvider.apk

    com.xunlei.downloadprovider.apk

    com.xunlei.downloadprovider.apk

    Android DownloadProvider 源码详解

    主要介绍了Android DownloadProvider 源码详解的相关资料,需要的朋友可以参考下

    DownloadProvider:Porting Android2.3 DownloadProvider .DownloadManager,can pause, resume downloading.断点续传下载

    modify form 可以识别服务器转发的下载链接 Android平台面向开发者提供了DownloadManager这个服务(service),可以用来完成下载,同时异步地得到下载进度的实时更新提示。 原生的浏览器,Android Market以及GMail...

    Android JPush SDK 集成文档

    Android JPush SDK 集成文档,快速集成极光推送服务功能!

    ContentProvider

    contentprovider存储,主要基于本地存储为基础,是移动开发的重要存储方式,源码已经打包,内部有详细注释。

    安卓ROM文件分析

    安卓系统文件夹及其主要文件详解 \system\app文件夹下是系统默认安装的软件 ...\system\app\Contacts.apk 联系人 \system\app\DownloadProvider.apk下载提供者 \system\app\DrmProvider. apk DRM数字版权提供

    MOTO XT882一键ROOT

    DownloadProvider.apk=下载管理器(绝不能删除) DrmProvider.apk=DRM受保护数据存储服务(绝不能删除) FileManager.apk=简易文件管理(可删,可用ES或RE文件管理器替代) Gallery3D.apk=3D图片浏览器 (可删) ...

    Android代码-下载管理

    This project ports the DownloadProvider of Android 2.3.7. It supports Android 2.2 and above. It is standard Eclipse project, which could be open by Eclipse with the Andoird Development Tools. To ...

    Download Provider Doc

    Download Provider Documentation From: http://www.netmite.com/android/mydroid/1.6/packages/providers/DownloadProvider/docs/

    Android Browser源码

    Android browser源代码 /android/packages/apps/browser /android/packages/providers/DownloadProvider /android/frameworks/base/core/java/android/webkit

    电子市场所需应用程序

    所以还需安装 DownloadProvider.apk DownloadProviderUi.apk。如此便可基本使用电子市场了。但当应用程序出错,向电子市场发送错误报告时,电子市场会出错。所以不发送错误报告就好了。可以查找并下载应用程序就可以...

Global site tag (gtag.js) - Google Analytics