bug:3069735 in Download UI app, handle deletes correctly

gingerbread.
High-level details
1. When a file is downloaded by DownloadManager, metadata about the file
   is stored in 2 databases: DownloadProvider and MediaProvider.

2. So, when it is to be deleted, its metadata needs to be cleaned up from
   both the databases.

3. But the 2 databases use differnt content-uri's as "primary keys" and
   DownloadProvider loses the "primary-key" of the row in MediaProvider
   database.

4. Easiest thing would have been to have DownloadProvider give filepath
   to MediaProvider and let MediaProvider linearly scan its database
   to locate the row and delete it.

5. The other - faster but more coding for now - option is to have
   DownloadProvider store the "primary-key" of the MediaProvider's
   row. implemented in this CL.

Low-level details
1. add 2 new columns to downloads table in downloads.db:
    mediaprovider_uri = downloaded file's content_uri in mediaprovider db
      this column is null for downloads that finished before this column is
      added to the database.
    deleted = flag is set to true if a file is to be deleted
2. download UI app shows only those files whose 'deleted' flag is not set.
3. when the user deletes downloads from download UI app,
    3.1. if mediaprovider_uri is NOT null, then the row is deleted from
         downloads table AND from the mediaprovider database.
    3.2 if mediaprovider_uri is NULL, then its row in downloads database
         is marked 'tp be deleted' by setting 'deleted' column to '1'.
4. When DownloadService (in DownloadProvider) processes all rows from
     downloads table, if it sees any rows wth 'deleted' = 1, then
     it uses MediaScanner Service to re-scan the file,
     get the mediaprovider_uri from MediaProvider
     and update the row in downloads table with this mediaprovider_uri value
     and then delete the row by doing the following
        1. delete it from MediaProvider database using mediaprovider_uri
        2. delete it from DownloadProvider database

Problem with this solution:
There is a small window where it is deleted by the user on the Download app
(and the row disappears from the display) but it is still present in
Gallery app.
   Thats due to the following asynchronous operations
   1. DownladService which processes rows-to-be-deleted is not always up
   2. DownloadService uses asynchronous call to have the file re-scanned
        by MediaScanner to get mediaprovider_uri

Change-Id: Ib90eb9e647f543312c865d3bbf9a06fb867a648b
4 files changed