Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2a21dd13 authored by Dipankar Bhardwaj's avatar Dipankar Bhardwaj
Browse files

Add null check for uri

If the target process is killed, ContentResolver would
receive a remote exception and would return a null uri
for the insert call. Handling the null check in the
DownloadManager to return -1 as the id in this case.

Bug: 199336863
Change-Id: I176f48317fcfc72f06e27f24dc3aa8180651ce39
parent 3b565b4e
Loading
Loading
Loading
Loading
+7 −2
Original line number Diff line number Diff line
@@ -1112,12 +1112,17 @@ public class DownloadManager {
     * ready to execute it and connectivity is available.
     *
     * @param request the parameters specifying this download
     * @return an ID for the download, unique across the system.  This ID is used to make future
     * calls related to this download.
     * @return an ID for the download, unique across the system.  This ID is used to make
     * future calls related to this download. Returns -1 if the operation fails.
     */
    public long enqueue(Request request) {
        ContentValues values = request.toContentValues(mPackageName);
        Uri downloadUri = mResolver.insert(Downloads.Impl.CONTENT_URI, values);
        if (downloadUri == null) {
            // If insert fails due to RemoteException, it would return a null uri.
            return -1;
        }

        long id = Long.parseLong(downloadUri.getLastPathSegment());
        return id;
    }