summaryrefslogtreecommitdiffstats
path: root/src/com/android/browser/OpenDownloadReceiver.java
diff options
context:
space:
mode:
authorLeon Scroggins <scroggo@google.com>2010-11-17 10:13:29 -0500
committerLeon Scroggins <scroggo@google.com>2010-11-18 11:59:32 -0500
commit2d8a51dc35585b01725b8ffdd562d6a6f8a5606d (patch)
treee11474bf6e7f78b075d967ea94294475691c9c81 /src/com/android/browser/OpenDownloadReceiver.java
parent6e3abb99ed885dddd8bf980cbd469c03a5947177 (diff)
downloadpackages_apps_Browser-2d8a51dc35585b01725b8ffdd562d6a6f8a5606d.zip
packages_apps_Browser-2d8a51dc35585b01725b8ffdd562d6a6f8a5606d.tar.gz
packages_apps_Browser-2d8a51dc35585b01725b8ffdd562d6a6f8a5606d.tar.bz2
Perform database accesses in the background.
Bug:3196174 Change-Id: I720dcaa539c3840d49e1e315aeb696261a46d3f2
Diffstat (limited to 'src/com/android/browser/OpenDownloadReceiver.java')
-rw-r--r--src/com/android/browser/OpenDownloadReceiver.java24
1 files changed, 22 insertions, 2 deletions
diff --git a/src/com/android/browser/OpenDownloadReceiver.java b/src/com/android/browser/OpenDownloadReceiver.java
index 0f0ba70..4277ff4 100644
--- a/src/com/android/browser/OpenDownloadReceiver.java
+++ b/src/com/android/browser/OpenDownloadReceiver.java
@@ -22,6 +22,8 @@ import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
+import android.os.Handler;
+import android.os.HandlerThread;
/**
* This {@link BroadcastReceiver} handles clicks to notifications that
@@ -30,8 +32,14 @@ import android.net.Uri;
* a complete, successful download will open the file.
*/
public class OpenDownloadReceiver extends BroadcastReceiver {
+ private static Handler sAsyncHandler;
+ static {
+ HandlerThread thr = new HandlerThread("Open browser download async");
+ thr.start();
+ sAsyncHandler = new Handler(thr.getLooper());
+ }
@Override
- public void onReceive(Context context, Intent intent) {
+ public void onReceive(final Context context, Intent intent) {
String action = intent.getAction();
if (!DownloadManager.ACTION_NOTIFICATION_CLICKED.equals(action)) {
openDownloadsPage(context);
@@ -43,7 +51,19 @@ public class OpenDownloadReceiver extends BroadcastReceiver {
openDownloadsPage(context);
return;
}
- long id = ids[0];
+ final long id = ids[0];
+ final PendingResult result = goAsync();
+ Runnable worker = new Runnable() {
+ @Override
+ public void run() {
+ onReceiveAsync(context, id);
+ result.finish();
+ }
+ };
+ sAsyncHandler.post(worker);
+ }
+
+ private void onReceiveAsync(Context context, long id) {
DownloadManager manager = (DownloadManager) context.getSystemService(
Context.DOWNLOAD_SERVICE);
Uri uri = manager.getUriForDownloadedFile(id);