From e1823c84698006aa26a8c5dcfa5c4034858dfbe3 Mon Sep 17 00:00:00 2001 From: Kenny Root Date: Wed, 1 Dec 2010 11:38:41 -0800 Subject: Don't filter by UID for apps with ACCESS_ALL_DOWNLOADS Old platform behavior of DownloadProvider would allow anyone with special access to access all the downloads. New behavior is to return /my_downloads/ on an .insert() call. For things that aren't using the new API where DownloadInfo.getAllDownloadsUri() is accessible, make any application with ACCESS_ALL_DOWNLOADS permission bypass the calling UID check for /my_downloads/ Bug: 3242328 Change-Id: I536fde4525dd74066879f7c7da7fa609ff344645 --- src/com/android/providers/downloads/DownloadProvider.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/com/android/providers/downloads/DownloadProvider.java b/src/com/android/providers/downloads/DownloadProvider.java index 6a67bc12..d97d6189 100644 --- a/src/com/android/providers/downloads/DownloadProvider.java +++ b/src/com/android/providers/downloads/DownloadProvider.java @@ -975,7 +975,9 @@ public final class DownloadProvider extends ContentProvider { if (uriMatch == MY_DOWNLOADS_ID || uriMatch == ALL_DOWNLOADS_ID) { selection.appendClause(Downloads.Impl._ID + " = ?", getDownloadIdFromUri(uri)); } - if (uriMatch == MY_DOWNLOADS || uriMatch == MY_DOWNLOADS_ID) { + if ((uriMatch == MY_DOWNLOADS || uriMatch == MY_DOWNLOADS_ID) + && getContext().checkCallingPermission(Downloads.Impl.PERMISSION_ACCESS_ALL) + != PackageManager.PERMISSION_GRANTED) { selection.appendClause( Constants.UID + "= ? OR " + Downloads.Impl.COLUMN_OTHER_UID + "= ?", Binder.getCallingUid(), Binder.getCallingPid()); -- cgit v1.2.3 From e49f651bdce9fc91c6bad97f5c1bb26bba82e41f Mon Sep 17 00:00:00 2001 From: Vasu Nori Date: Wed, 1 Dec 2010 18:23:09 -0800 Subject: (GB MR) bug:3144642 temporary small fix in GB MR and real fix in HC Real fix is in Change-Id: Ifea1544737023008eff44aef9acd976902a0c143 In the database, sometimes _data column in downloads is set to null and sometimes to empty string. this is inconsistent and causes bugs such as bug:3144642. This bug is caused by line# 793 in DownloadThread. state.mFileName is null sometimes and empty string sometimes - because the correspodning field is set inconsistentlt in downloads.db _data column. in GB MR, apply a bandaid because real fix could be too risky for GB. Change-Id: I115b3ba6cfe0262269dbbc4c336b9e1d63c618e4 --- src/com/android/providers/downloads/DownloadThread.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/com/android/providers/downloads/DownloadThread.java b/src/com/android/providers/downloads/DownloadThread.java index 2995bfb6..d783fea8 100644 --- a/src/com/android/providers/downloads/DownloadThread.java +++ b/src/com/android/providers/downloads/DownloadThread.java @@ -26,6 +26,7 @@ import android.os.PowerManager; import android.os.Process; import android.provider.Downloads; import android.provider.DrmStore; +import android.text.TextUtils; import android.util.Log; import android.util.Pair; @@ -790,7 +791,7 @@ public class DownloadThread extends Thread { */ private void setupDestinationFile(State state, InnerState innerState) throws StopRequest { - if (state.mFilename != null) { // only true if we've already run a thread for this download + if (TextUtils.isEmpty(state.mFilename)) { // only true if we've already run a thread for this download if (!Helpers.isFilenameValid(state.mFilename)) { // this should never happen throw new StopRequest(Downloads.Impl.STATUS_FILE_ERROR, -- cgit v1.2.3 From 5bbe15ed66d72dcab0ef133b9d237bba28cd6d98 Mon Sep 17 00:00:00 2001 From: Vasu Nori Date: Fri, 3 Dec 2010 11:13:50 -0800 Subject: downloads broken by Change-Id: I115b3ba6cfe0262269dbbc4c336b9e1d63c618e4 big typo in that CL broke the downloading functionality. Change-Id: If7dc0f86ea7a3c4394603416ca0fc33847f10fa7 --- src/com/android/providers/downloads/DownloadThread.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/com/android/providers/downloads/DownloadThread.java b/src/com/android/providers/downloads/DownloadThread.java index d783fea8..7c102481 100644 --- a/src/com/android/providers/downloads/DownloadThread.java +++ b/src/com/android/providers/downloads/DownloadThread.java @@ -791,7 +791,7 @@ public class DownloadThread extends Thread { */ private void setupDestinationFile(State state, InnerState innerState) throws StopRequest { - if (TextUtils.isEmpty(state.mFilename)) { // only true if we've already run a thread for this download + if (!TextUtils.isEmpty(state.mFilename)) { // only true if we've already run a thread for this download if (!Helpers.isFilenameValid(state.mFilename)) { // this should never happen throw new StopRequest(Downloads.Impl.STATUS_FILE_ERROR, -- cgit v1.2.3 From 36fe18171c655dcf51d9dc396c70cc0e8e3ab7a4 Mon Sep 17 00:00:00 2001 From: Vasu Nori Date: Fri, 3 Dec 2010 11:35:04 -0800 Subject: (GB/GBMR) (do not merge) delete file from disk when deleting from db bug:3175143 sometimes mediaprovider doesn't delete the file from disk when it is deleted from its db. for example, audio files, pdf files. DownloadManager/DownloadApp should delete the file when it is deleted from downloads db. DO NOT MERGE this is esentially porting HC fix from DownloadService.java to GB Change-Id: I70f3a7ad968f82ccba00d664e9a2993d75a18d15 --- .../providers/downloads/DownloadService.java | 34 ++++++++++++---------- 1 file changed, 18 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/com/android/providers/downloads/DownloadService.java b/src/com/android/providers/downloads/DownloadService.java index 169ef970..95d07d6f 100644 --- a/src/com/android/providers/downloads/DownloadService.java +++ b/src/com/android/providers/downloads/DownloadService.java @@ -363,7 +363,7 @@ public class DownloadService extends Service { if (info.shouldScanFile()) { // initiate rescan of the file to - which will populate // mediaProviderUri column in this row - if (!scanFile(info, true, false)) { + if (!scanFile(info, false, true)) { throw new IllegalStateException("scanFile failed!"); } } else { @@ -377,9 +377,9 @@ public class DownloadService extends Service { // in DownProvider database (the order of deletion is important). getContentResolver().delete(Uri.parse(info.mMediaProviderUri), null, null); - getContentResolver().delete(Downloads.Impl.ALL_DOWNLOADS_CONTENT_URI, - Downloads.Impl._ID + " = ? ", - new String[]{String.valueOf(info.mId)}); + // the following deletes the file and then deletes it from downloads db + Helpers.deleteFile(getContentResolver(), info.mId, info.mFileName, + info.mMimeType); } } } @@ -580,21 +580,23 @@ public class DownloadService extends Service { mMediaScannerService.requestScanFile(info.mFileName, info.mMimeType, new IMediaScannerListener.Stub() { public void scanCompleted(String path, Uri uri) { - if (uri != null && updateDatabase) { - // file is scanned and mediaprovider returned uri. store it in downloads - // table (i.e., update this downloaded file's row) + if (updateDatabase) { + // Mark this as 'scanned' in the database + // so that it is NOT subject to re-scanning by MediaScanner + // next time this database row is encountered ContentValues values = new ContentValues(); values.put(Constants.MEDIA_SCANNED, 1); - values.put(Downloads.Impl.COLUMN_MEDIAPROVIDER_URI, - uri.toString()); + if (uri != null) { + values.put(Downloads.Impl.COLUMN_MEDIAPROVIDER_URI, + uri.toString()); + } getContentResolver().update(key, values, null, null); - } else if (uri == null && deleteFile) { - // callback returned NO uri..that means this file doesn't - // exist in MediaProvider. but it still needs to be deleted - // TODO don't scan files that are not scannable by MediaScanner. - // create a public method in MediaFile.java to return false - // if the given file's mimetype is not any of the types - // the mediaprovider is interested in. + } else if (deleteFile) { + if (uri != null) { + // use the Uri returned to delete it from the MediaProvider + getContentResolver().delete(uri, null, null); + } + // delete the file and delete its row from the downloads db Helpers.deleteFile(resolver, id, path, mimeType); } } -- cgit v1.2.3 From 089951b2b78398975cf0e984356f9ed3b3ae4aa3 Mon Sep 17 00:00:00 2001 From: Vasu Nori Date: Sun, 16 Jan 2011 10:52:14 -0800 Subject: (GB MR) bug:3351783 don't store redirectcount in db redirectcount shouldn't be stored in the db. say, you are downloading a large app and there are redirects involved inthe download. if network connectivity changes during download, then download is paused and resumed once connectivy is back on. when the download is resumed, it should start with redirectcount of 0 instead of redirectcount from the previous download session. Change-Id: I1acf2fb9491d24f5e109206a91dda3eea429e447 --- src/com/android/providers/downloads/DownloadInfo.java | 3 --- src/com/android/providers/downloads/DownloadThread.java | 11 +++++------ 2 files changed, 5 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/com/android/providers/downloads/DownloadInfo.java b/src/com/android/providers/downloads/DownloadInfo.java index 36816b59..7b291683 100644 --- a/src/com/android/providers/downloads/DownloadInfo.java +++ b/src/com/android/providers/downloads/DownloadInfo.java @@ -73,7 +73,6 @@ public class DownloadInfo { info.mNumFailed = getInt(Constants.FAILED_CONNECTIONS); int retryRedirect = getInt(Constants.RETRY_AFTER_X_REDIRECT_COUNT); info.mRetryAfter = retryRedirect & 0xfffffff; - info.mRedirectCount = retryRedirect >> 28; info.mLastMod = getLong(Downloads.Impl.COLUMN_LAST_MODIFICATION); info.mPackage = getString(info.mPackage, Downloads.Impl.COLUMN_NOTIFICATION_PACKAGE); info.mClass = getString(info.mClass, Downloads.Impl.COLUMN_NOTIFICATION_CLASS); @@ -223,7 +222,6 @@ public class DownloadInfo { public int mStatus; public int mNumFailed; public int mRetryAfter; - public int mRedirectCount; public long mLastMod; public String mPackage; public String mClass; @@ -506,7 +504,6 @@ public class DownloadInfo { Log.v(Constants.TAG, "STATUS : " + mStatus); Log.v(Constants.TAG, "FAILED_C: " + mNumFailed); Log.v(Constants.TAG, "RETRY_AF: " + mRetryAfter); - Log.v(Constants.TAG, "REDIRECT: " + mRedirectCount); Log.v(Constants.TAG, "LAST_MOD: " + mLastMod); Log.v(Constants.TAG, "PACKAGE : " + mPackage); Log.v(Constants.TAG, "CLASS : " + mClass); diff --git a/src/com/android/providers/downloads/DownloadThread.java b/src/com/android/providers/downloads/DownloadThread.java index 7c102481..461d8cea 100644 --- a/src/com/android/providers/downloads/DownloadThread.java +++ b/src/com/android/providers/downloads/DownloadThread.java @@ -88,7 +88,6 @@ public class DownloadThread extends Thread { public State(DownloadInfo info) { mMimeType = sanitizeMimeType(info.mMimeType); - mRedirectCount = info.mRedirectCount; mRequestUri = info.mUri; mFilename = info.mFileName; } @@ -200,7 +199,7 @@ public class DownloadThread extends Thread { } cleanupDestination(state, finalStatus); notifyDownloadCompleted(finalStatus, state.mCountRetry, state.mRetryAfter, - state.mRedirectCount, state.mGotData, state.mFilename, + state.mGotData, state.mFilename, state.mNewUri, state.mMimeType); mInfo.mHasActiveThread = false; } @@ -854,17 +853,17 @@ public class DownloadThread extends Thread { * Stores information about the completed download, and notifies the initiating application. */ private void notifyDownloadCompleted( - int status, boolean countRetry, int retryAfter, int redirectCount, boolean gotData, + int status, boolean countRetry, int retryAfter, boolean gotData, String filename, String uri, String mimeType) { notifyThroughDatabase( - status, countRetry, retryAfter, redirectCount, gotData, filename, uri, mimeType); + status, countRetry, retryAfter, gotData, filename, uri, mimeType); if (Downloads.Impl.isStatusCompleted(status)) { mInfo.sendIntentIfRequested(); } } private void notifyThroughDatabase( - int status, boolean countRetry, int retryAfter, int redirectCount, boolean gotData, + int status, boolean countRetry, int retryAfter, boolean gotData, String filename, String uri, String mimeType) { ContentValues values = new ContentValues(); values.put(Downloads.Impl.COLUMN_STATUS, status); @@ -874,7 +873,7 @@ public class DownloadThread extends Thread { } values.put(Downloads.Impl.COLUMN_MIME_TYPE, mimeType); values.put(Downloads.Impl.COLUMN_LAST_MODIFICATION, mSystemFacade.currentTimeMillis()); - values.put(Constants.RETRY_AFTER_X_REDIRECT_COUNT, retryAfter + (redirectCount << 28)); + values.put(Constants.RETRY_AFTER_X_REDIRECT_COUNT, retryAfter); if (!countRetry) { values.put(Constants.FAILED_CONNECTIONS, 0); } else if (gotData) { -- cgit v1.2.3