From 524bb4ddedf65000e71099ca16165883be29e919 Mon Sep 17 00:00:00 2001 From: Wes Johnston Date: Fri, 19 Sep 2014 16:55:18 -0700 Subject: [PATCH] Bug 1064669 - Initialize MediaPlayers in delayed startup. r=mfinkle --- mobile/android/base/BrowserApp.java | 24 ++++++++++++++---------- mobile/android/base/GeckoApp.java | 12 ++++++++++++ 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/mobile/android/base/BrowserApp.java b/mobile/android/base/BrowserApp.java index 868a5f4d769..fd4325b387b 100644 --- a/mobile/android/base/BrowserApp.java +++ b/mobile/android/base/BrowserApp.java @@ -662,16 +662,6 @@ public class BrowserApp extends GeckoApp // Set the maximum bits-per-pixel the favicon system cares about. IconDirectoryEntry.setMaxBPP(GeckoAppShell.getScreenDepth()); - Class mediaManagerClass = getMediaPlayerManager(); - if (mediaManagerClass != null) { - try { - Method init = mediaManagerClass.getMethod("init", Context.class); - init.invoke(null, this); - } catch(Exception ex) { - Log.e(LOGTAG, "Error initializing media manager", ex); - } - } - if (getProfile().inGuestMode()) { GuestSession.showNotification(this); } else { @@ -1547,6 +1537,19 @@ public class BrowserApp extends GeckoApp } }); + if (AppConstants.MOZ_MEDIA_PLAYER) { + // If casting is disabled, these classes aren't built. We use reflection to initialize them. + Class mediaManagerClass = getMediaPlayerManager(); + if (mediaManagerClass != null) { + try { + Method init = mediaManagerClass.getMethod("init", Context.class); + init.invoke(null, this); + } catch(Exception ex) { + Log.e(LOGTAG, "Error initializing media manager", ex); + } + } + } + if (AppConstants.MOZ_STUMBLER_BUILD_TIME_ENABLED) { // Start (this acts as ping if started already) the stumbler lib; if the stumbler has queued data it will upload it. // Stumbler operates on its own thread, and startup impact is further minimized by delaying work (such as upload) a few seconds. @@ -1559,6 +1562,7 @@ public class BrowserApp extends GeckoApp } }, oneSecondInMillis); } + super.handleMessage(event, message); } else if (event.equals("Gecko:Ready")) { // Handle this message in GeckoApp, but also enable the Settings diff --git a/mobile/android/base/GeckoApp.java b/mobile/android/base/GeckoApp.java index 165ec68a57d..781d07459a8 100644 --- a/mobile/android/base/GeckoApp.java +++ b/mobile/android/base/GeckoApp.java @@ -191,6 +191,7 @@ public abstract class GeckoApp private Telemetry.Timer mGeckoReadyStartupTimer; private String mPrivateBrowsingSession; + private volatile boolean mIsPaused = true; private volatile HealthRecorder mHealthRecorder; private volatile Locale mLastLocale; @@ -246,7 +247,13 @@ public abstract class GeckoApp } public void addAppStateListener(GeckoAppShell.AppStateListener listener) { + ThreadUtils.assertOnUiThread(); mAppStateListeners.add(listener); + + // If we're already resumed, make sure the listener gets a notification. + if (!mIsPaused) { + listener.onResume(); + } } public void removeAppStateListener(GeckoAppShell.AppStateListener listener) { @@ -1885,6 +1892,8 @@ public abstract class GeckoApp listener.onResume(); } } + // Setting this state will force any listeners added after this to have their onResume() method called + mIsPaused = false; // We use two times: a pseudo-unique wall-clock time to identify the // current session across power cycles, and the elapsed realtime to @@ -1961,6 +1970,9 @@ public abstract class GeckoApp } }); + // Setting this state will keep any listeners registered after this from having their onResume + // method called. + mIsPaused = true; if (mAppStateListeners != null) { for(GeckoAppShell.AppStateListener listener: mAppStateListeners) { listener.onPause();