Commit d4232010 authored by Min Qin's avatar Min Qin Committed by Commit Bot

Fix OMA download on Q

OMA download on Q needs to be published to media store
Currently because the file path is set to null, copying
it to media store will fail.
This CL fixes the bug by passing the file path after
querying the Android DownloadManager.

Bug: 978424
Change-Id: Iabf7358de1096a12632eb9546068b3622d377152
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1917749Reviewed-by: default avatarShakti Sahu <shaktisahu@chromium.org>
Commit-Queue: Min Qin <qinmin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#715916}
parent ed5f9d4e
...@@ -1357,6 +1357,7 @@ public class DownloadManagerService implements DownloadController.DownloadNotifi ...@@ -1357,6 +1357,7 @@ public class DownloadManagerService implements DownloadController.DownloadNotifi
builder.setBytesReceived(result.bytesDownloaded); builder.setBytesReceived(result.bytesDownloaded);
if (!TextUtils.isEmpty(result.fileName)) builder.setFileName(result.fileName); if (!TextUtils.isEmpty(result.fileName)) builder.setFileName(result.fileName);
if (!TextUtils.isEmpty(result.mimeType)) builder.setMimeType(result.mimeType); if (!TextUtils.isEmpty(result.mimeType)) builder.setMimeType(result.mimeType);
builder.setFilePath(result.filePath);
item.setDownloadInfo(builder.build()); item.setDownloadInfo(builder.build());
if (result.downloadStatus == DownloadStatus.IN_PROGRESS) return; if (result.downloadStatus == DownloadStatus.IN_PROGRESS) return;
......
...@@ -776,13 +776,6 @@ public class OMADownloadHandler extends BroadcastReceiver { ...@@ -776,13 +776,6 @@ public class OMADownloadHandler extends BroadcastReceiver {
return; return;
} }
if (!TextUtils.isEmpty(response.filePath)) {
DownloadInfo newInfo =
DownloadInfo.Builder.fromDownloadInfo(downloadItem.getDownloadInfo())
.setFilePath(response.filePath)
.build();
downloadItem.setDownloadInfo(newInfo);
}
if (mSystemDownloadIdMap.size() == 0) { if (mSystemDownloadIdMap.size() == 0) {
mContext.registerReceiver( mContext.registerReceiver(
this, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE)); this, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
...@@ -829,10 +822,8 @@ public class OMADownloadHandler extends BroadcastReceiver { ...@@ -829,10 +822,8 @@ public class OMADownloadHandler extends BroadcastReceiver {
builder.setBytesTotalSize(result.bytesTotal); builder.setBytesTotalSize(result.bytesTotal);
if (!TextUtils.isEmpty(result.fileName)) builder.setFileName(result.fileName); if (!TextUtils.isEmpty(result.fileName)) builder.setFileName(result.fileName);
if (!TextUtils.isEmpty(result.mimeType)) builder.setMimeType(result.mimeType); if (!TextUtils.isEmpty(result.mimeType)) builder.setMimeType(result.mimeType);
builder.setFilePath(result.filePath);
// Since the requested file path may not be same as the actual file path, set it to
// null. This will result in using contentUri instead.
builder.setFilePath(null);
item.setDownloadInfo(builder.build()); item.setDownloadInfo(builder.build());
showDownloadsUi(downloadId, item, result, installNotifyURI); showDownloadsUi(downloadId, item, result, installNotifyURI);
...@@ -853,6 +844,11 @@ public class OMADownloadHandler extends BroadcastReceiver { ...@@ -853,6 +844,11 @@ public class OMADownloadHandler extends BroadcastReceiver {
@Override @Override
protected void onPostExecute(Boolean canResolve) { protected void onPostExecute(Boolean canResolve) {
if (result.downloadStatus == DownloadStatus.COMPLETE) { if (result.downloadStatus == DownloadStatus.COMPLETE) {
DownloadInfo.Builder builder = item.getDownloadInfo() == null
? new DownloadInfo.Builder()
: DownloadInfo.Builder.fromDownloadInfo(item.getDownloadInfo());
builder.setFilePath(result.filePath);
item.setDownloadInfo(builder.build());
onDownloadCompleted(item.getDownloadInfo(), downloadId, installNotifyURI); onDownloadCompleted(item.getDownloadInfo(), downloadId, installNotifyURI);
removeOMADownloadFromSharedPrefs(downloadId); removeOMADownloadFromSharedPrefs(downloadId);
showDownloadOnInfoBar(item, result.downloadStatus); showDownloadOnInfoBar(item, result.downloadStatus);
......
...@@ -54,6 +54,7 @@ public class DownloadManagerBridge { ...@@ -54,6 +54,7 @@ public class DownloadManagerBridge {
public long bytesDownloaded; public long bytesDownloaded;
public long bytesTotal; public long bytesTotal;
public int failureReason; public int failureReason;
public String filePath;
public DownloadQueryResult(long downloadId) { public DownloadQueryResult(long downloadId) {
this.downloadId = downloadId; this.downloadId = downloadId;
...@@ -81,7 +82,6 @@ public class DownloadManagerBridge { ...@@ -81,7 +82,6 @@ public class DownloadManagerBridge {
public boolean result; public boolean result;
public int failureReason; public int failureReason;
public long startTime; public long startTime;
public String filePath;
} }
/** /**
...@@ -203,6 +203,11 @@ public class DownloadManagerBridge { ...@@ -203,6 +203,11 @@ public class DownloadManagerBridge {
c.getLong(c.getColumnIndex(DownloadManager.COLUMN_BYTES_DOWNLOADED_SO_FAR)); c.getLong(c.getColumnIndex(DownloadManager.COLUMN_BYTES_DOWNLOADED_SO_FAR));
result.bytesTotal = result.bytesTotal =
c.getLong(c.getColumnIndex(DownloadManager.COLUMN_TOTAL_SIZE_BYTES)); c.getLong(c.getColumnIndex(DownloadManager.COLUMN_TOTAL_SIZE_BYTES));
String localUri = c.getString(c.getColumnIndex(DownloadManager.COLUMN_LOCAL_URI));
if (!TextUtils.isEmpty(localUri)) {
Uri uri = Uri.parse(localUri);
result.filePath = uri.getPath();
}
} else { } else {
result.downloadStatus = DownloadStatus.CANCELLED; result.downloadStatus = DownloadStatus.CANCELLED;
} }
...@@ -352,7 +357,6 @@ public class DownloadManagerBridge { ...@@ -352,7 +357,6 @@ public class DownloadManagerBridge {
private long mDownloadId; private long mDownloadId;
private int mFailureReason; private int mFailureReason;
private long mStartTime; private long mStartTime;
private String mFilePath;
public EnqueueNewDownloadTask( public EnqueueNewDownloadTask(
DownloadEnqueueRequest enqueueRequest, Callback<DownloadEnqueueResponse> callback) { DownloadEnqueueRequest enqueueRequest, Callback<DownloadEnqueueResponse> callback) {
...@@ -385,7 +389,6 @@ public class DownloadManagerBridge { ...@@ -385,7 +389,6 @@ public class DownloadManagerBridge {
File dir = new File(getContext().getExternalFilesDir(null), DOWNLOAD_DIRECTORY); File dir = new File(getContext().getExternalFilesDir(null), DOWNLOAD_DIRECTORY);
if (dir.mkdir() || dir.isDirectory()) { if (dir.mkdir() || dir.isDirectory()) {
File file = new File(dir, mEnqueueRequest.fileName); File file = new File(dir, mEnqueueRequest.fileName);
mFilePath = file.getAbsolutePath();
request.setDestinationUri(Uri.fromFile(file)); request.setDestinationUri(Uri.fromFile(file));
} else { } else {
Log.e(TAG, "Cannot create download directory"); Log.e(TAG, "Cannot create download directory");
...@@ -444,7 +447,6 @@ public class DownloadManagerBridge { ...@@ -444,7 +447,6 @@ public class DownloadManagerBridge {
enqueueResult.failureReason = mFailureReason; enqueueResult.failureReason = mFailureReason;
enqueueResult.downloadId = mDownloadId; enqueueResult.downloadId = mDownloadId;
enqueueResult.startTime = mStartTime; enqueueResult.startTime = mStartTime;
enqueueResult.filePath = mFilePath;
mCallback.onResult(enqueueResult); mCallback.onResult(enqueueResult);
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment