diff --git a/mobile/android/base/AboutHomeContent.java b/mobile/android/base/AboutHomeContent.java index 450c24e5b2d3..7268645aa7cf 100644 --- a/mobile/android/base/AboutHomeContent.java +++ b/mobile/android/base/AboutHomeContent.java @@ -12,6 +12,7 @@ import org.mozilla.gecko.db.BrowserDB.URLColumns; import org.mozilla.gecko.db.BrowserDB.TopSitesCursorWrapper; import org.mozilla.gecko.sync.setup.SyncAccounts; import org.mozilla.gecko.util.ActivityResultHandler; +import org.mozilla.gecko.util.ThreadUtils; import org.mozilla.gecko.util.UiAsyncTask; import org.json.JSONArray; @@ -143,7 +144,7 @@ public class AboutHomeContent extends ScrollView // Because the tabs URI is coarse grained, this updates the // remote tabs component on *every* tab change // The observer will run on the background thread (see constructor argument) - mTabsContentObserver = new ContentObserver(GeckoAppShell.getHandler()) { + mTabsContentObserver = new ContentObserver(ThreadUtils.getBackgroundHandler()) { @Override public void onChange(boolean selfChange) { update(EnumSet.of(AboutHomeContent.UpdateFlags.REMOTE_TABS)); @@ -426,7 +427,7 @@ public class AboutHomeContent extends ScrollView if (urls.size() == 0) return; - (new UiAsyncTask(GeckoAppShell.getHandler()) { + (new UiAsyncTask(ThreadUtils.getBackgroundHandler()) { @Override public Cursor doInBackground(Void... params) { return BrowserDB.getThumbnailsForUrls(cr, urls); @@ -440,7 +441,7 @@ public class AboutHomeContent extends ScrollView } void update(final EnumSet flags) { - GeckoAppShell.getHandler().post(new Runnable() { + ThreadUtils.postToBackgroundThread(new Runnable() { @Override public void run() { if (flags.contains(UpdateFlags.TOP_SITES)) @@ -990,7 +991,7 @@ public class AboutHomeContent extends ScrollView final String url = holder.getUrl(); // Quickly update the view so that there isn't as much lag between the request and response clearThumbnail(holder); - (new UiAsyncTask(GeckoAppShell.getHandler()) { + (new UiAsyncTask(ThreadUtils.getBackgroundHandler()) { @Override public Void doInBackground(Void... params) { final ContentResolver resolver = mActivity.getContentResolver(); @@ -1011,7 +1012,7 @@ public class AboutHomeContent extends ScrollView holder.setPinned(true); // update the database on a background thread - (new UiAsyncTask(GeckoAppShell.getHandler()) { + (new UiAsyncTask(ThreadUtils.getBackgroundHandler()) { @Override public Void doInBackground(Void... params) { final ContentResolver resolver = mActivity.getContentResolver(); @@ -1056,7 +1057,7 @@ public class AboutHomeContent extends ScrollView holder.setPinned(true); // update the database on a background thread - (new UiAsyncTask(GeckoAppShell.getHandler()) { + (new UiAsyncTask(ThreadUtils.getBackgroundHandler()) { @Override public Bitmap doInBackground(Void... params) { final ContentResolver resolver = mActivity.getContentResolver(); diff --git a/mobile/android/base/AboutHomePromoBox.java b/mobile/android/base/AboutHomePromoBox.java index df8a4f5750bc..7cdb65dd35bd 100644 --- a/mobile/android/base/AboutHomePromoBox.java +++ b/mobile/android/base/AboutHomePromoBox.java @@ -7,6 +7,7 @@ package org.mozilla.gecko; import org.mozilla.gecko.db.BrowserDB; import org.mozilla.gecko.sync.setup.activities.SetupSyncActivity; import org.mozilla.gecko.sync.setup.SyncAccounts; +import org.mozilla.gecko.util.ThreadUtils; import org.mozilla.gecko.util.UiAsyncTask; import android.accounts.Account; @@ -70,7 +71,7 @@ public class AboutHomePromoBox extends TextView implements View.OnClickListener showRandomPromo(); } }; - AccountManager.get(mContext).addOnAccountsUpdatedListener(mAccountListener, GeckoAppShell.getHandler(), false); + AccountManager.get(mContext).addOnAccountsUpdatedListener(mAccountListener, ThreadUtils.getBackgroundHandler(), false); } @Override public boolean canShow() { @@ -193,7 +194,7 @@ public class AboutHomePromoBox extends TextView implements View.OnClickListener } private void getAvailableTypes(final GetTypesCallback callback) { - (new UiAsyncTask>(GeckoAppShell.getHandler()) { + (new UiAsyncTask>(ThreadUtils.getBackgroundHandler()) { @Override public ArrayList doInBackground(Void... params) { // Run all of this on a background thread diff --git a/mobile/android/base/AndroidImportPreference.java b/mobile/android/base/AndroidImportPreference.java index c9dcae79ea79..045ce7fdbbeb 100644 --- a/mobile/android/base/AndroidImportPreference.java +++ b/mobile/android/base/AndroidImportPreference.java @@ -5,7 +5,7 @@ package org.mozilla.gecko; -import org.mozilla.gecko.util.GeckoBackgroundThread; +import org.mozilla.gecko.util.ThreadUtils; import android.app.ProgressDialog; import android.content.Context; @@ -85,7 +85,7 @@ class AndroidImportPreference extends MultiChoicePreference { } }; - GeckoBackgroundThread.getHandler().post( + ThreadUtils.postToBackgroundThread( // Constructing AndroidImport may need finding the profile, // which hits disk, so it needs to go into a Runnable too. new Runnable() { diff --git a/mobile/android/base/AwesomeBar.java b/mobile/android/base/AwesomeBar.java index b94279bbe626..a0a197a5a91f 100644 --- a/mobile/android/base/AwesomeBar.java +++ b/mobile/android/base/AwesomeBar.java @@ -579,7 +579,7 @@ public class AwesomeBar extends GeckoActivity { editPrompt.setPositiveButton(R.string.button_ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int whichButton) { - (new UiAsyncTask(GeckoAppShell.getHandler()) { + (new UiAsyncTask(ThreadUtils.getBackgroundHandler()) { @Override public Void doInBackground(Void... params) { String newUrl = locationText.getText().toString().trim(); @@ -629,7 +629,7 @@ public class AwesomeBar extends GeckoActivity { break; } case R.id.remove_bookmark: { - (new UiAsyncTask(GeckoAppShell.getHandler()) { + (new UiAsyncTask(ThreadUtils.getBackgroundHandler()) { private boolean mInReadingList; @Override @@ -659,7 +659,7 @@ public class AwesomeBar extends GeckoActivity { break; } case R.id.remove_history: { - (new UiAsyncTask(GeckoAppShell.getHandler()) { + (new UiAsyncTask(ThreadUtils.getBackgroundHandler()) { @Override public Void doInBackground(Void... params) { BrowserDB.removeHistoryEntry(getContentResolver(), id); diff --git a/mobile/android/base/BrowserApp.java b/mobile/android/base/BrowserApp.java index aac1d807362d..71a1589aa89d 100644 --- a/mobile/android/base/BrowserApp.java +++ b/mobile/android/base/BrowserApp.java @@ -10,7 +10,6 @@ import org.mozilla.gecko.db.BrowserDB; import org.mozilla.gecko.gfx.BitmapUtils; import org.mozilla.gecko.gfx.ImmutableViewportMetrics; import org.mozilla.gecko.util.UiAsyncTask; -import org.mozilla.gecko.util.GeckoBackgroundThread; import org.mozilla.gecko.util.ThreadUtils; import org.json.JSONArray; @@ -377,7 +376,7 @@ abstract public class BrowserApp extends GeckoApp return; } - GeckoAppShell.getHandler().post(new Runnable() { + ThreadUtils.postToBackgroundThread(new Runnable() { @Override public void run() { BrowserDB.addReadingListItem(getContentResolver(), title, url); @@ -387,7 +386,7 @@ abstract public class BrowserApp extends GeckoApp } void handleReaderRemoved(final String url) { - GeckoAppShell.getHandler().post(new Runnable() { + ThreadUtils.postToBackgroundThread(new Runnable() { @Override public void run() { BrowserDB.removeReadingListItemWithURL(getContentResolver(), url); @@ -1198,7 +1197,7 @@ abstract public class BrowserApp extends GeckoApp item.setIcon(drawable); } else if (info.icon.startsWith("jar:") || info.icon.startsWith("file://")) { - GeckoAppShell.getHandler().post(new Runnable() { + ThreadUtils.postToBackgroundThread(new Runnable() { @Override public void run() { try { @@ -1548,7 +1547,7 @@ abstract public class BrowserApp extends GeckoApp return; } - (new UiAsyncTask(GeckoAppShell.getHandler()) { + (new UiAsyncTask(ThreadUtils.getBackgroundHandler()) { @Override public synchronized Boolean doInBackground(Void... params) { // Check to see how many times the app has been launched. @@ -1575,7 +1574,7 @@ abstract public class BrowserApp extends GeckoApp } private void resetFeedbackLaunchCount() { - GeckoBackgroundThread.post(new Runnable() { + ThreadUtils.postToBackgroundThread(new Runnable() { @Override public synchronized void run() { SharedPreferences settings = getPreferences(Activity.MODE_PRIVATE); @@ -1585,7 +1584,7 @@ abstract public class BrowserApp extends GeckoApp } private void getLastUrl() { - (new UiAsyncTask(GeckoAppShell.getHandler()) { + (new UiAsyncTask(ThreadUtils.getBackgroundHandler()) { @Override public synchronized String doInBackground(Void... params) { // Get the most recent URL stored in browser history. diff --git a/mobile/android/base/Distribution.java b/mobile/android/base/Distribution.java index 89f554be9231..1a09295b2c01 100644 --- a/mobile/android/base/Distribution.java +++ b/mobile/android/base/Distribution.java @@ -9,7 +9,7 @@ package org.mozilla.gecko; -import org.mozilla.gecko.util.GeckoBackgroundThread; +import org.mozilla.gecko.util.ThreadUtils; import android.app.Activity; import android.content.Context; @@ -45,7 +45,7 @@ public final class Distribution { */ public static void init(final Context context, final String packagePath) { // Read/write preferences and files on the background thread. - GeckoBackgroundThread.getHandler().post(new Runnable() { + ThreadUtils.postToBackgroundThread(new Runnable() { @Override public void run() { // Bail if we've already initialized the distribution. diff --git a/mobile/android/base/Favicons.java b/mobile/android/base/Favicons.java index fa14b073f660..d8619b1dd959 100644 --- a/mobile/android/base/Favicons.java +++ b/mobile/android/base/Favicons.java @@ -112,7 +112,7 @@ public class Favicons { return -1; } - LoadFaviconTask task = new LoadFaviconTask(GeckoAppShell.getHandler(), pageUrl, faviconUrl, persist, listener); + LoadFaviconTask task = new LoadFaviconTask(ThreadUtils.getBackgroundHandler(), pageUrl, faviconUrl, persist, listener); long taskId = task.getId(); mLoadTasks.put(taskId, task); diff --git a/mobile/android/base/GeckoAccessibility.java b/mobile/android/base/GeckoAccessibility.java index 0f724af5e47a..80602b8aa101 100644 --- a/mobile/android/base/GeckoAccessibility.java +++ b/mobile/android/base/GeckoAccessibility.java @@ -43,7 +43,7 @@ public class GeckoAccessibility { })); public static void updateAccessibilitySettings () { - GeckoAppShell.getHandler().post(new Runnable() { + ThreadUtils.postToBackgroundThread(new Runnable() { @Override public void run() { JSONObject ret = new JSONObject(); @@ -130,7 +130,7 @@ public class GeckoAccessibility { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) { // Before Jelly Bean we send events directly from here while spoofing the source by setting // the package and class name manually. - GeckoAppShell.getHandler().post(new Runnable() { + ThreadUtils.postToBackgroundThread(new Runnable() { @Override public void run() { sendDirectAccessibilityEvent(eventType, message); diff --git a/mobile/android/base/GeckoApp.java b/mobile/android/base/GeckoApp.java index adad2b9b393e..75c8e44e773c 100644 --- a/mobile/android/base/GeckoApp.java +++ b/mobile/android/base/GeckoApp.java @@ -15,7 +15,6 @@ import org.mozilla.gecko.gfx.PluginLayer; import org.mozilla.gecko.gfx.PointUtils; import org.mozilla.gecko.updater.UpdateService; import org.mozilla.gecko.updater.UpdateServiceHelper; -import org.mozilla.gecko.util.GeckoBackgroundThread; import org.mozilla.gecko.util.GeckoEventListener; import org.mozilla.gecko.util.GeckoEventResponder; import org.mozilla.gecko.util.ThreadUtils; @@ -626,7 +625,7 @@ abstract public class GeckoApp } void handleFaviconRequest(final String url) { - (new UiAsyncTask(GeckoAppShell.getHandler()) { + (new UiAsyncTask(ThreadUtils.getBackgroundHandler()) { @Override public String doInBackground(Void... params) { return Favicons.getInstance().getFaviconUrlForPageUrl(url); @@ -802,7 +801,7 @@ abstract public class GeckoApp @Override public void run() { Toast.makeText(GeckoApp.mAppContext, R.string.bookmark_added, Toast.LENGTH_SHORT).show(); - GeckoAppShell.getHandler().post(new Runnable() { + ThreadUtils.postToBackgroundThread(new Runnable() { @Override public void run() { BrowserDB.addBookmark(GeckoApp.mAppContext.getContentResolver(), title, url); @@ -1104,7 +1103,7 @@ abstract public class GeckoApp notification.setLatestEventInfo(mAppContext, fileName, progText, emptyIntent ); notification.flags |= Notification.FLAG_ONGOING_EVENT; notification.show(); - new UiAsyncTask(GeckoAppShell.getHandler()){ + new UiAsyncTask(ThreadUtils.getBackgroundHandler()) { @Override protected Boolean doInBackground(Void... params) { @@ -1440,7 +1439,7 @@ abstract public class GeckoApp mPrivateBrowsingSession = savedInstanceState.getString(SAVED_STATE_PRIVATE_SESSION); } - GeckoBackgroundThread.getHandler().post(new Runnable() { + ThreadUtils.postToBackgroundThread(new Runnable() { @Override public void run() { SharedPreferences prefs = @@ -1545,7 +1544,7 @@ abstract public class GeckoApp Uri data = intent.getData(); if (data != null && "http".equals(data.getScheme())) { startupAction = StartupAction.PREFETCH; - GeckoAppShell.getHandler().post(new PrefetchRunnable(data.toString())); + ThreadUtils.postToBackgroundThread(new PrefetchRunnable(data.toString())); } Tabs.registerOnTabsChangedListener(this); @@ -1706,7 +1705,7 @@ abstract public class GeckoApp // End of the startup of our Java App mJavaUiStartupTimer.stop(); - GeckoAppShell.getHandler().postDelayed(new Runnable() { + ThreadUtils.getBackgroundHandler().postDelayed(new Runnable() { @Override public void run() { // Sync settings need Gecko to be loaded, so @@ -1949,7 +1948,7 @@ abstract public class GeckoApp // User may have enabled/disabled accessibility. GeckoAccessibility.updateAccessibilitySettings(); - GeckoBackgroundThread.getHandler().post(new Runnable() { + ThreadUtils.postToBackgroundThread(new Runnable() { @Override public void run() { SharedPreferences prefs = @@ -1995,7 +1994,7 @@ abstract public class GeckoApp // In some way it's sad that Android will trigger StrictMode warnings // here as the whole point is to save to disk while the activity is not // interacting with the user. - GeckoBackgroundThread.getHandler().post(new Runnable() { + ThreadUtils.postToBackgroundThread(new Runnable() { @Override public void run() { SharedPreferences prefs = @@ -2017,7 +2016,7 @@ abstract public class GeckoApp @Override public void onRestart() { - GeckoBackgroundThread.getHandler().post(new Runnable() { + ThreadUtils.postToBackgroundThread(new Runnable() { @Override public void run() { SharedPreferences prefs = @@ -2213,7 +2212,7 @@ abstract public class GeckoApp if (profileDir != null) { final GeckoApp app = GeckoApp.mAppContext; - GeckoAppShell.getHandler().post(new Runnable() { + ThreadUtils.postToBackgroundThread(new Runnable() { @Override public void run() { ProfileMigrator profileMigrator = new ProfileMigrator(app); diff --git a/mobile/android/base/GeckoAppShell.java b/mobile/android/base/GeckoAppShell.java index 5a3d48f15b4b..8f19dcf5fa8c 100644 --- a/mobile/android/base/GeckoAppShell.java +++ b/mobile/android/base/GeckoAppShell.java @@ -12,7 +12,6 @@ import org.mozilla.gecko.gfx.LayerView; import org.mozilla.gecko.gfx.PanZoomController; import org.mozilla.gecko.mozglue.GeckoLoader; import org.mozilla.gecko.util.EventDispatcher; -import org.mozilla.gecko.util.GeckoBackgroundThread; import org.mozilla.gecko.util.GeckoEventListener; import org.mozilla.gecko.util.ThreadUtils; @@ -49,7 +48,6 @@ import android.net.ConnectivityManager; import android.net.NetworkInfo; import android.net.Uri; import android.os.Build; -import android.os.Handler; import android.os.Looper; import android.os.Message; import android.os.MessageQueue; @@ -256,10 +254,6 @@ public class GeckoAppShell } } - public static Handler getHandler() { - return GeckoBackgroundThread.getHandler(); - } - public static void runGecko(String apkPath, String args, String url, String type) { Looper.prepare(); @@ -608,7 +602,7 @@ public class GeckoAppShell public static void createShortcut(final String aTitle, final String aURI, final String aUniqueURI, final Bitmap aIcon, final String aType) { - getHandler().post(new Runnable() { + ThreadUtils.postToBackgroundThread(new Runnable() { @Override public void run() { // the intent to be launched by the shortcut @@ -645,7 +639,7 @@ public class GeckoAppShell } public static void removeShortcut(final String aTitle, final String aURI, final String aUniqueURI, final String aType) { - getHandler().post(new Runnable() { + ThreadUtils.postToBackgroundThread(new Runnable() { @Override public void run() { // the intent to be launched by the shortcut @@ -680,7 +674,7 @@ public class GeckoAppShell // On uninstall, we need to do a couple of things: // 1. nuke the running app process. // 2. nuke the profile that was assigned to that webapp - getHandler().post(new Runnable() { + ThreadUtils.postToBackgroundThread(new Runnable() { @Override public void run() { int index = WebAppAllocator.getInstance(GeckoApp.mAppContext).releaseIndexForApp(uniqueURI); @@ -1117,7 +1111,7 @@ public class GeckoAppShell // Note: the main looper won't work because it may be blocked on the // gecko thread, which is most likely this thread static String getClipboardText() { - getHandler().post(new Runnable() { + ThreadUtils.postToBackgroundThread(new Runnable() { @Override @SuppressWarnings("deprecation") public void run() { @@ -1151,7 +1145,7 @@ public class GeckoAppShell } static void setClipboardText(final String text) { - getHandler().post(new Runnable() { + ThreadUtils.postToBackgroundThread(new Runnable() { @Override @SuppressWarnings("deprecation") public void run() { @@ -1852,7 +1846,7 @@ public class GeckoAppShell } static void markUriVisited(final String uri) { // invoked from native JNI code - getHandler().post(new Runnable() { + ThreadUtils.postToBackgroundThread(new Runnable() { @Override public void run() { GlobalHistory.getInstance().add(uri); @@ -1861,7 +1855,7 @@ public class GeckoAppShell } static void setUriTitle(final String uri, final String title) { // invoked from native JNI code - getHandler().post(new Runnable() { + ThreadUtils.postToBackgroundThread(new Runnable() { @Override public void run() { GlobalHistory.getInstance().update(uri, title); diff --git a/mobile/android/base/GlobalHistory.java b/mobile/android/base/GlobalHistory.java index 37d1dfb3d773..4e6d96f1a66b 100644 --- a/mobile/android/base/GlobalHistory.java +++ b/mobile/android/base/GlobalHistory.java @@ -6,6 +6,7 @@ package org.mozilla.gecko; import org.mozilla.gecko.db.BrowserDB; +import org.mozilla.gecko.util.ThreadUtils; import android.database.Cursor; import android.net.Uri; @@ -39,7 +40,7 @@ class GlobalHistory { private boolean mProcessing; // = false // whether or not the runnable is queued/working private GlobalHistory() { - mHandler = GeckoAppShell.getHandler(); + mHandler = ThreadUtils.getBackgroundHandler(); mPendingUris = new LinkedList(); mVisitedCache = new SoftReference>(null); mNotifierRunnable = new Runnable() { diff --git a/mobile/android/base/MemoryMonitor.java b/mobile/android/base/MemoryMonitor.java index 5a6833adb37f..37c5669fdf38 100644 --- a/mobile/android/base/MemoryMonitor.java +++ b/mobile/android/base/MemoryMonitor.java @@ -7,6 +7,7 @@ package org.mozilla.gecko; import org.mozilla.gecko.db.BrowserDB; import org.mozilla.gecko.db.BrowserContract; +import org.mozilla.gecko.util.ThreadUtils; import android.content.BroadcastReceiver; import android.content.ComponentCallbacks2; @@ -105,7 +106,7 @@ class MemoryMonitor extends BroadcastReceiver { if (Intent.ACTION_DEVICE_STORAGE_LOW.equals(intent.getAction())) { Log.d(LOGTAG, "Device storage is low"); mStoragePressure = true; - GeckoAppShell.getHandler().post(new StorageReducer(context)); + ThreadUtils.postToBackgroundThread(new StorageReducer(context)); } else if (Intent.ACTION_DEVICE_STORAGE_OK.equals(intent.getAction())) { Log.d(LOGTAG, "Device storage is ok"); mStoragePressure = false; @@ -178,9 +179,9 @@ class MemoryMonitor extends BroadcastReceiver { synchronized void start() { if (mPosted) { // cancel the old one before scheduling a new one - GeckoAppShell.getHandler().removeCallbacks(this); + ThreadUtils.getBackgroundHandler().removeCallbacks(this); } - GeckoAppShell.getHandler().postDelayed(this, DECREMENT_DELAY); + ThreadUtils.getBackgroundHandler().postDelayed(this, DECREMENT_DELAY); mPosted = true; } @@ -193,7 +194,7 @@ class MemoryMonitor extends BroadcastReceiver { } // need to keep decrementing - GeckoAppShell.getHandler().postDelayed(this, DECREMENT_DELAY); + ThreadUtils.getBackgroundHandler().postDelayed(this, DECREMENT_DELAY); } } @@ -207,7 +208,7 @@ class MemoryMonitor extends BroadcastReceiver { public void run() { // this might get run right on startup, if so wait 10 seconds and try again if (!GeckoThread.checkLaunchState(GeckoThread.LaunchState.GeckoRunning)) { - GeckoAppShell.getHandler().postDelayed(this, 10000); + ThreadUtils.getBackgroundHandler().postDelayed(this, 10000); return; } diff --git a/mobile/android/base/MultiChoicePreference.java b/mobile/android/base/MultiChoicePreference.java index 76e3f45e1f3d..dadde0558748 100644 --- a/mobile/android/base/MultiChoicePreference.java +++ b/mobile/android/base/MultiChoicePreference.java @@ -5,6 +5,8 @@ package org.mozilla.gecko; +import org.mozilla.gecko.util.ThreadUtils; + import android.app.AlertDialog; import android.app.AlertDialog.Builder; import android.content.Context; @@ -184,7 +186,7 @@ class MultiChoicePreference extends DialogPreference { mPrevValues = mValues.clone(); } - GeckoAppShell.getHandler().post(new Runnable() { + ThreadUtils.postToBackgroundThread(new Runnable() { @Override public void run() { for (int i = 0; i < mEntryKeys.length; i++) { @@ -233,7 +235,7 @@ class MultiChoicePreference extends DialogPreference { } mValues = new boolean[entryCount]; - GeckoAppShell.getHandler().post(new Runnable() { + ThreadUtils.postToBackgroundThread(new Runnable() { @Override public void run() { for (int i = 0; i < entryCount; i++) { diff --git a/mobile/android/base/ProfileMigrator.java b/mobile/android/base/ProfileMigrator.java index 484c028cccf0..1aa905a87070 100644 --- a/mobile/android/base/ProfileMigrator.java +++ b/mobile/android/base/ProfileMigrator.java @@ -14,6 +14,7 @@ import org.mozilla.gecko.sqlite.SQLiteBridge; import org.mozilla.gecko.sqlite.SQLiteBridgeException; import org.mozilla.gecko.sync.setup.SyncAccounts; import org.mozilla.gecko.sync.setup.SyncAccounts.SyncAccountParameters; +import org.mozilla.gecko.util.ThreadUtils; import android.accounts.Account; import android.content.ContentProviderOperation; @@ -609,7 +610,7 @@ public class ProfileMigrator { final String clientName = mSyncSettingsMap.get("services.sync.client.name"); final String clientGuid = mSyncSettingsMap.get("services.sync.client.GUID"); - GeckoAppShell.getHandler().post(new Runnable() { + ThreadUtils.postToBackgroundThread(new Runnable() { @Override public void run() { if (userName == null || syncKey == null || syncPass == null) { @@ -637,7 +638,7 @@ public class ProfileMigrator { } protected void registerAndRequest() { - GeckoAppShell.getHandler().post(new Runnable() { + ThreadUtils.postToBackgroundThread(new Runnable() { @Override public void run() { requestValues(); @@ -652,7 +653,7 @@ public class ProfileMigrator { @Override protected void onPostExecute(Boolean result) { if (result.booleanValue()) { - GeckoAppShell.getHandler().post(new Runnable() { + ThreadUtils.postToBackgroundThread(new Runnable() { @Override public void run() { Log.i(LOGTAG, "Sync account already configured, skipping."); @@ -933,7 +934,7 @@ public class ProfileMigrator { // GlobalHistory access communicates with Gecko // and must run on its thread. - GeckoAppShell.getHandler().post(new Runnable() { + ThreadUtils.postToBackgroundThread(new Runnable() { @Override public void run() { for (String url : placesHistory) { diff --git a/mobile/android/base/Tab.java b/mobile/android/base/Tab.java index 5f98663dc1df..b3155b7f18d7 100644 --- a/mobile/android/base/Tab.java +++ b/mobile/android/base/Tab.java @@ -15,6 +15,7 @@ import org.json.JSONException; import org.json.JSONObject; import org.mozilla.gecko.db.BrowserDB; import org.mozilla.gecko.gfx.Layer; +import org.mozilla.gecko.util.ThreadUtils; import android.content.ContentResolver; import android.graphics.Bitmap; @@ -163,7 +164,7 @@ public class Tab { } public void updateThumbnail(final Bitmap b) { - GeckoAppShell.getHandler().post(new Runnable() { + ThreadUtils.postToBackgroundThread(new Runnable() { @Override public void run() { if (b != null) { @@ -321,7 +322,7 @@ public class Tab { } void updateBookmark() { - GeckoAppShell.getHandler().post(new Runnable() { + ThreadUtils.postToBackgroundThread(new Runnable() { @Override public void run() { final String url = getURL(); @@ -339,7 +340,7 @@ public class Tab { } public void addBookmark() { - GeckoAppShell.getHandler().post(new Runnable() { + ThreadUtils.postToBackgroundThread(new Runnable() { @Override public void run() { String url = getURL(); @@ -352,7 +353,7 @@ public class Tab { } public void removeBookmark() { - GeckoAppShell.getHandler().post(new Runnable() { + ThreadUtils.postToBackgroundThread(new Runnable() { @Override public void run() { String url = getURL(); @@ -549,7 +550,7 @@ public class Tab { final String oldURL = getURL(); final Tab tab = this; - GeckoAppShell.getHandler().postDelayed(new Runnable() { + ThreadUtils.getBackgroundHandler().postDelayed(new Runnable() { @Override public void run() { // tab.getURL() may return null diff --git a/mobile/android/base/Tabs.java b/mobile/android/base/Tabs.java index 40247745d55d..4ac1faef2f5c 100644 --- a/mobile/android/base/Tabs.java +++ b/mobile/android/base/Tabs.java @@ -6,8 +6,9 @@ package org.mozilla.gecko; import org.mozilla.gecko.db.BrowserDB; -import org.mozilla.gecko.util.GeckoEventListener; import org.mozilla.gecko.sync.setup.SyncAccounts; +import org.mozilla.gecko.util.GeckoEventListener; +import org.mozilla.gecko.util.ThreadUtils; import org.json.JSONObject; @@ -106,7 +107,7 @@ public class Tabs implements GeckoEventListener { }; // The listener will run on the background thread (see 2nd argument). - mAccountManager.addOnAccountsUpdatedListener(mAccountListener, GeckoAppShell.getHandler(), false); + mAccountManager.addOnAccountsUpdatedListener(mAccountListener, ThreadUtils.getBackgroundHandler(), false); if (mContentObserver != null) { BrowserDB.registerBookmarkObserver(getContentResolver(), mContentObserver); @@ -449,7 +450,7 @@ public class Tabs implements GeckoEventListener { public void refreshThumbnails() { final ThumbnailHelper helper = ThumbnailHelper.getInstance(); - GeckoAppShell.getHandler().post(new Runnable() { + ThreadUtils.postToBackgroundThread(new Runnable() { @Override public void run() { for (final Tab tab : mOrder) { @@ -553,7 +554,7 @@ public class Tabs implements GeckoEventListener { public void persistAllTabs() { final GeckoApp activity = getActivity(); final Iterable tabs = getTabsInOrder(); - GeckoAppShell.getHandler().post(new Runnable() { + ThreadUtils.postToBackgroundThread(new Runnable() { @Override public void run() { boolean syncIsSetup = SyncAccounts.syncAccountsExist(activity); diff --git a/mobile/android/base/TabsAccessor.java b/mobile/android/base/TabsAccessor.java index 56bd8575fb94..a09b7b24eef2 100644 --- a/mobile/android/base/TabsAccessor.java +++ b/mobile/android/base/TabsAccessor.java @@ -5,6 +5,7 @@ package org.mozilla.gecko; import org.mozilla.gecko.db.BrowserContract; +import org.mozilla.gecko.util.ThreadUtils; import org.mozilla.gecko.util.UiAsyncTask; import org.json.JSONArray; @@ -73,11 +74,11 @@ public final class TabsAccessor { if (listener == null) return; - (new UiAsyncTask>(GeckoAppShell.getHandler()) { + (new UiAsyncTask>(ThreadUtils.getBackgroundHandler()) { @Override protected List doInBackground(Void... unused) { Uri uri = BrowserContract.Tabs.CONTENT_URI; - + if (limit > 0) { uri = uri.buildUpon() .appendQueryParameter(BrowserContract.PARAM_LIMIT, String.valueOf(limit)) diff --git a/mobile/android/base/WebAppAllocator.java b/mobile/android/base/WebAppAllocator.java index e64da544b96d..add7d2b0dede 100644 --- a/mobile/android/base/WebAppAllocator.java +++ b/mobile/android/base/WebAppAllocator.java @@ -10,7 +10,7 @@ import android.content.SharedPreferences; import android.graphics.Bitmap; import org.mozilla.gecko.gfx.BitmapUtils; -import org.mozilla.gecko.util.GeckoBackgroundThread; +import org.mozilla.gecko.util.ThreadUtils; public class WebAppAllocator { private final String LOGTAG = "GeckoWebAppAllocator"; @@ -70,7 +70,7 @@ public class WebAppAllocator { if (!mPrefs.contains(appKey(i))) { // found unused index i final int foundIndex = i; - GeckoBackgroundThread.getHandler().post(new Runnable() { + ThreadUtils.postToBackgroundThread(new Runnable() { @Override public void run() { int color = 0; @@ -118,7 +118,7 @@ public class WebAppAllocator { } public synchronized void releaseIndex(final int index) { - GeckoBackgroundThread.getHandler().post(new Runnable() { + ThreadUtils.postToBackgroundThread(new Runnable() { @Override public void run() { mPrefs.edit() diff --git a/mobile/android/base/awesomebar/AllPagesTab.java b/mobile/android/base/awesomebar/AllPagesTab.java index 8c7df57c3a95..c5d291b5cb23 100644 --- a/mobile/android/base/awesomebar/AllPagesTab.java +++ b/mobile/android/base/awesomebar/AllPagesTab.java @@ -177,7 +177,7 @@ public class AllPagesTab extends AwesomeBarTab implements GeckoEventListener { * Query for suggestions, but don't show them yet. */ private void primeSuggestions() { - GeckoAppShell.getHandler().post(new Runnable() { + ThreadUtils.postToBackgroundThread(new Runnable() { @Override public void run() { mSuggestClient.query(mSearchTerm); @@ -844,7 +844,7 @@ public class AllPagesTab extends AwesomeBarTab implements GeckoEventListener { if (urls.size() == 0) return; - (new UiAsyncTask(GeckoAppShell.getHandler()) { + (new UiAsyncTask(ThreadUtils.getBackgroundHandler()) { @Override public Cursor doInBackground(Void... params) { return BrowserDB.getFaviconsForUrls(getContentResolver(), urls); diff --git a/mobile/android/base/awesomebar/HistoryTab.java b/mobile/android/base/awesomebar/HistoryTab.java index 92f0290dcae8..d3e14a5a885b 100644 --- a/mobile/android/base/awesomebar/HistoryTab.java +++ b/mobile/android/base/awesomebar/HistoryTab.java @@ -356,7 +356,7 @@ public class HistoryTab extends AwesomeBarTab { if (mContentObserver == null) { // Register an observer to update the history tab contents if they change. - mContentObserver = new ContentObserver(GeckoAppShell.getHandler()) { + mContentObserver = new ContentObserver(ThreadUtils.getBackgroundHandler()) { @Override public void onChange(boolean selfChange) { mQueryTask = new HistoryQueryTask(); diff --git a/mobile/android/base/db/BrowserProvider.java.in b/mobile/android/base/db/BrowserProvider.java.in index e68d0df81704..7fa7c5335e99 100644 --- a/mobile/android/base/db/BrowserProvider.java.in +++ b/mobile/android/base/db/BrowserProvider.java.in @@ -38,8 +38,8 @@ import org.mozilla.gecko.db.DBUtils; import org.mozilla.gecko.gfx.BitmapUtils; import org.mozilla.gecko.ProfileMigrator; import org.mozilla.gecko.sync.Utils; -import org.mozilla.gecko.util.GeckoBackgroundThread; import org.mozilla.gecko.util.GeckoJarReader; +import org.mozilla.gecko.util.ThreadUtils; import android.app.SearchManager; import android.content.ContentProvider; @@ -1026,7 +1026,7 @@ public class BrowserProvider extends ContentProvider { } // create icons in a separate thread to avoid blocking about:home on startup - GeckoBackgroundThread.getHandler().post(new Runnable() { + ThreadUtils.postToBackgroundThread(new Runnable() { @Override public void run() { try { @@ -1069,7 +1069,7 @@ public class BrowserProvider extends ContentProvider { createBookmark(db, title, url, pos); // create icons in a separate thread to avoid blocking about:home on startup - GeckoBackgroundThread.getHandler().post(new Runnable() { + ThreadUtils.postToBackgroundThread(new Runnable() { @Override public void run() { Bitmap icon = getDefaultFaviconFromPath(name); @@ -1993,7 +1993,7 @@ public class BrowserProvider extends ContentProvider { public boolean onCreate() { debug("Creating BrowserProvider"); - GeckoBackgroundThread.post(new Runnable() { + ThreadUtils.postToBackgroundThread(new Runnable() { @Override public void run() { // Kick this off early. It is synchronized so that other callers will wait diff --git a/mobile/android/base/db/TabsProvider.java.in b/mobile/android/base/db/TabsProvider.java.in index b7baec0c5a8f..2259b6fa9a59 100644 --- a/mobile/android/base/db/TabsProvider.java.in +++ b/mobile/android/base/db/TabsProvider.java.in @@ -15,7 +15,7 @@ import org.mozilla.gecko.db.BrowserContract.Clients; import org.mozilla.gecko.db.BrowserContract.Tabs; import org.mozilla.gecko.db.BrowserContract; import org.mozilla.gecko.db.DBUtils; -import org.mozilla.gecko.util.GeckoBackgroundThread; +import org.mozilla.gecko.util.ThreadUtils; import android.content.ContentProvider; import android.content.ContentUris; @@ -289,7 +289,7 @@ public class TabsProvider extends ContentProvider { public boolean onCreate() { debug("Creating TabsProvider"); - GeckoBackgroundThread.post(new Runnable() { + ThreadUtils.postToBackgroundThread(new Runnable() { @Override public void run() { // Kick this off early. It is synchronized so that other callers will wait diff --git a/mobile/android/base/util/GeckoBackgroundThread.java b/mobile/android/base/util/GeckoBackgroundThread.java index f08f6cb96052..f7873fe733d3 100644 --- a/mobile/android/base/util/GeckoBackgroundThread.java +++ b/mobile/android/base/util/GeckoBackgroundThread.java @@ -9,7 +9,7 @@ import android.os.Looper; import java.util.concurrent.SynchronousQueue; -public final class GeckoBackgroundThread extends Thread { +final class GeckoBackgroundThread extends Thread { private static final String LOOPER_NAME = "GeckoBackgroundThread"; // Guarded by 'this'. @@ -33,7 +33,7 @@ public final class GeckoBackgroundThread extends Thread { } // Get a Handler for a looper thread, or create one if it doesn't yet exist. - public static synchronized Handler getHandler() { + /*package*/ static synchronized Handler getHandler() { if (sHandler == null) { GeckoBackgroundThread lt = new GeckoBackgroundThread(); ThreadUtils.setBackgroundThread(lt); @@ -45,7 +45,7 @@ public final class GeckoBackgroundThread extends Thread { return sHandler; } - public static void post(Runnable runnable) { + /*package*/ static void post(Runnable runnable) { Handler handler = getHandler(); if (handler == null) { throw new IllegalStateException("No handler! Must have been interrupted. Not posting."); diff --git a/mobile/android/base/util/ThreadUtils.java b/mobile/android/base/util/ThreadUtils.java index 29d4a4f87347..8b17069810e0 100644 --- a/mobile/android/base/util/ThreadUtils.java +++ b/mobile/android/base/util/ThreadUtils.java @@ -47,6 +47,14 @@ public final class ThreadUtils { return sBackgroundThread; } + public static Handler getBackgroundHandler() { + return GeckoBackgroundThread.getHandler(); + } + + public static void postToBackgroundThread(Runnable runnable) { + GeckoBackgroundThread.post(runnable); + } + public static void assertOnUiThread() { assertOnThread(getUiThread()); }