Commit f01e04c2 authored by Xing Liu's avatar Xing Liu Committed by Chromium LUCI CQ

Download: Fix another potential misuse of addCompletedDownload.

addCompletedDownload for Android download manager is deprecated on Q
and causing crash on R. This CL removes another call site of this on
P+.

Bug: 1120233
Change-Id: Ic8596d7664a831d9c78f6f7f90de5ac65fb8f385
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2565224Reviewed-by: default avatarMin Qin <qinmin@chromium.org>
Reviewed-by: default avatarDavid Trainor <dtrainor@chromium.org>
Commit-Queue: Xing Liu <xingliu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#832646}
parent ad5cd18e
......@@ -14,6 +14,7 @@ import android.database.Cursor;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri;
import android.os.Build;
import android.os.Handler;
import android.provider.MediaStore.MediaColumns;
import android.text.TextUtils;
......@@ -545,9 +546,11 @@ public class DownloadManagerService implements DownloadController.Observer,
public Pair<Boolean, Boolean> doInBackground() {
boolean success = mDisableAddCompletedDownloadForTesting
|| ContentUriUtils.isContentUri(item.getDownloadInfo().getFilePath());
if (!success
&& !ChromeFeatureList.isEnabled(
ChromeFeatureList.DOWNLOAD_OFFLINE_CONTENT_PROVIDER)) {
boolean shouldAddCompletedDownload =
!ChromeFeatureList.isEnabled(
ChromeFeatureList.DOWNLOAD_OFFLINE_CONTENT_PROVIDER)
&& (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q);
if (!success && shouldAddCompletedDownload) {
long systemDownloadId = DownloadManagerBridge.addCompletedDownload(
info.getFileName(), info.getDescription(), info.getMimeType(),
info.getFilePath(), info.getBytesReceived(), info.getOriginalUrl(),
......
......@@ -93,7 +93,8 @@ public class DownloadManagerBridge {
String filePath, long fileSizeBytes, String originalUrl, String referer,
String downloadGuid) {
assert !ThreadUtils.runningOnUiThread();
assert VERSION.SDK_INT < VERSION_CODES.Q : "Deprecated in Q, may cause crash.";
assert VERSION.SDK_INT < VERSION_CODES.Q
: "addCompletedDownload is deprecated in Q, may cause crash.";
long downloadId = getDownloadIdForDownloadGuid(downloadGuid);
if (downloadId != DownloadConstants.INVALID_DOWNLOAD_ID) return downloadId;
......
......@@ -67,6 +67,8 @@ public class DownloadUtils {
public static long addCompletedDownload(String fileName, String description, String mimeType,
String filePath, long fileSizeBytes, String originalUrl, String referer) {
assert !ThreadUtils.runningOnUiThread();
assert Build.VERSION.SDK_INT < Build.VERSION_CODES.Q
: "addCompletedDownload is deprecated in Q, may cause crash.";
Context context = ContextUtils.getApplicationContext();
DownloadManager manager =
(DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
......
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