diff options
| author | Ben Murdoch <benm@google.com> | 2010-11-25 16:20:14 +0000 |
|---|---|---|
| committer | Ben Murdoch <benm@google.com> | 2010-11-29 11:27:18 +0000 |
| commit | 9446b9351cec1ffddd211ba02d985b91853f8398 (patch) | |
| tree | 6790edfefa25ad574c3209250ee66e6df4d2d43c /src | |
| parent | 528f7a6a79681b9b901896320ae9c30ef2e472c9 (diff) | |
| download | packages_apps_Browser-9446b9351cec1ffddd211ba02d985b91853f8398.tar.gz packages_apps_Browser-9446b9351cec1ffddd211ba02d985b91853f8398.tar.bz2 packages_apps_Browser-9446b9351cec1ffddd211ba02d985b91853f8398.zip | |
Move access to the WebIconDatabase from the UI thread.
the retainIconsOnStartup function was accessing the
WebIconDatabase on the UI thread which is a strict mode
violation. Move that database access into an AsyncTask.
Change-Id: I4f03680d00b7678a89e41f94201ca5309891a8d9
Diffstat (limited to 'src')
| -rw-r--r-- | src/com/android/browser/Controller.java | 47 |
1 files changed, 32 insertions, 15 deletions
diff --git a/src/com/android/browser/Controller.java b/src/com/android/browser/Controller.java index d30ffb2dd..acd76ddf7 100644 --- a/src/com/android/browser/Controller.java +++ b/src/com/android/browser/Controller.java @@ -363,23 +363,40 @@ public class Controller } // Open the icon database and retain all the icons for visited sites. + // This is done on a background thread so as not to stall startup. private void retainIconsOnStartup() { - final WebIconDatabase db = WebIconDatabase.getInstance(); - db.open(mActivity.getDir("icons", 0).getPath()); - Cursor c = null; - try { - c = Browser.getAllBookmarks(mActivity.getContentResolver()); - if (c.moveToFirst()) { - int urlIndex = c.getColumnIndex(Browser.BookmarkColumns.URL); - do { - String url = c.getString(urlIndex); - db.retainIconForPageUrl(url); - } while (c.moveToNext()); + // WebIconDatabase needs to be retrieved on the UI thread so that if + // it has not been created successfully yet the Handler is started on the + // UI thread. + new RetainIconsOnStartupTask(WebIconDatabase.getInstance()).execute(); + } + + private class RetainIconsOnStartupTask extends AsyncTask<Void, Void, Void> { + private WebIconDatabase mDb; + + public RetainIconsOnStartupTask(WebIconDatabase db) { + mDb = db; + } + + protected Void doInBackground(Void... unused) { + mDb.open(mActivity.getDir("icons", 0).getPath()); + Cursor c = null; + try { + c = Browser.getAllBookmarks(mActivity.getContentResolver()); + if (c.moveToFirst()) { + int urlIndex = c.getColumnIndex(Browser.BookmarkColumns.URL); + do { + String url = c.getString(urlIndex); + mDb.retainIconForPageUrl(url); + } while (c.moveToNext()); + } + } catch (IllegalStateException e) { + Log.e(LOGTAG, "retainIconsOnStartup", e); + } finally { + if (c != null) c.close(); } - } catch (IllegalStateException e) { - Log.e(LOGTAG, "retainIconsOnStartup", e); - } finally { - if (c!= null) c.close(); + + return null; } } |
