Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(264)

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/download/DownloadManagerDelegate.java

Issue 2242213006: Fix an NPE as DownloadManager.query() could return a null cursor (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.chrome.browser.download; 5 package org.chromium.chrome.browser.download;
6 6
7 import android.app.DownloadManager; 7 import android.app.DownloadManager;
8 import android.content.Context; 8 import android.content.Context;
9 import android.database.Cursor; 9 import android.database.Cursor;
10 import android.os.AsyncTask; 10 import android.os.AsyncTask;
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 mShowNotifications = showNotifications; 91 mShowNotifications = showNotifications;
92 mCallback = callback; 92 mCallback = callback;
93 } 93 }
94 94
95 @Override 95 @Override
96 public DownloadQueryResult doInBackground(Void... voids) { 96 public DownloadQueryResult doInBackground(Void... voids) {
97 DownloadManager manager = 97 DownloadManager manager =
98 (DownloadManager) mContext.getSystemService(Context.DOWNLOAD _SERVICE); 98 (DownloadManager) mContext.getSystemService(Context.DOWNLOAD _SERVICE);
99 Cursor c = manager.query( 99 Cursor c = manager.query(
100 new DownloadManager.Query().setFilterById(mDownloadItem.getS ystemDownloadId())); 100 new DownloadManager.Query().setFilterById(mDownloadItem.getS ystemDownloadId()));
101 if (c == null) {
102 return new DownloadQueryResult(mDownloadItem,
103 DownloadManagerService.DOWNLOAD_STATUS_CANCELLED, 0, 0, false, 0);
104 }
101 long bytesDownloaded = 0; 105 long bytesDownloaded = 0;
102 boolean canResolve = false; 106 boolean canResolve = false;
103 int downloadStatus = DownloadManagerService.DOWNLOAD_STATUS_IN_PROGR ESS; 107 int downloadStatus = DownloadManagerService.DOWNLOAD_STATUS_IN_PROGR ESS;
104 int failureReason = 0; 108 int failureReason = 0;
105 long lastModifiedTime = 0; 109 long lastModifiedTime = 0;
106 if (c.moveToNext()) { 110 if (c.moveToNext()) {
107 int statusIndex = c.getColumnIndex(DownloadManager.COLUMN_STATUS ); 111 int statusIndex = c.getColumnIndex(DownloadManager.COLUMN_STATUS );
108 int status = c.getInt(c.getColumnIndex(DownloadManager.COLUMN_ST ATUS)); 112 int status = c.getInt(c.getColumnIndex(DownloadManager.COLUMN_ST ATUS));
109 if (status == DownloadManager.STATUS_SUCCESSFUL) { 113 if (status == DownloadManager.STATUS_SUCCESSFUL) {
110 downloadStatus = DownloadManagerService.DOWNLOAD_STATUS_COMP LETE; 114 downloadStatus = DownloadManagerService.DOWNLOAD_STATUS_COMP LETE;
(...skipping 19 matching lines...) Expand all
130 return new DownloadQueryResult(mDownloadItem, downloadStatus, totalT ime, 134 return new DownloadQueryResult(mDownloadItem, downloadStatus, totalT ime,
131 bytesDownloaded, canResolve, failureReason); 135 bytesDownloaded, canResolve, failureReason);
132 } 136 }
133 137
134 @Override 138 @Override
135 protected void onPostExecute(DownloadQueryResult result) { 139 protected void onPostExecute(DownloadQueryResult result) {
136 mCallback.onQueryCompleted(result, mShowNotifications); 140 mCallback.onQueryCompleted(result, mShowNotifications);
137 } 141 }
138 } 142 }
139 } 143 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698