Backed out 3 changesets (bug 1505685) for android checkstyle failures on GeckoMediaControlAgent.
authorCosmin Sabou <csabou@mozilla.com>
Wed, 21 Nov 2018 11:45:59 +0200
changeset 503950 86d8ead0b9a51d9cd0f780e0c279f8a86d2b187e
parent 503949 6e2a67a9a9c9b5d15e9231716f869fc522dfa99b
child 503951 ab0dfc5b827dcc0a2eef87d8e9ccbf383a397f72
push id10290
push userffxbld-merge
push dateMon, 03 Dec 2018 16:23:23 +0000
treeherdermozilla-beta@700bed2445e6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1505685
milestone65.0a1
backs out6e2a67a9a9c9b5d15e9231716f869fc522dfa99b
a46710b7723fc89bc3e51b437d59f5c169bab1f6
9344087c8d8e0b6a2874d18684c01ffb49f6bdcd
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Backed out 3 changesets (bug 1505685) for android checkstyle failures on GeckoMediaControlAgent. Backed out changeset 6e2a67a9a9c9 (bug 1505685) Backed out changeset a46710b7723f (bug 1505685) Backed out changeset 9344087c8d8e (bug 1505685)
mobile/android/base/java/org/mozilla/gecko/BrowserApp.java
mobile/android/base/java/org/mozilla/gecko/GeckoApplication.java
mobile/android/base/java/org/mozilla/gecko/media/GeckoMediaControlAgent.java
mobile/android/base/java/org/mozilla/gecko/mma/MmaDelegate.java
--- a/mobile/android/base/java/org/mozilla/gecko/BrowserApp.java
+++ b/mobile/android/base/java/org/mozilla/gecko/BrowserApp.java
@@ -889,16 +889,17 @@ public class BrowserApp extends GeckoApp
         final String serverExtra = intent.getStringExtra(INTENT_KEY_SWITCHBOARD_SERVER);
         final String serverUrl = TextUtils.isEmpty(serverExtra) ? SWITCHBOARD_SERVER : serverExtra;
         final SwitchBoard.ConfigStatusListener configStatuslistener = mOnboardingHelper;
         final MmaDelegate.MmaVariablesChangedListener variablesChangedListener = mOnboardingHelper;
         new AsyncConfigLoader(context, serverUrl, configStatuslistener) {
             @Override
             protected Void doInBackground(Void... params) {
                 super.doInBackground(params);
+                SwitchBoard.loadConfig(context, serverUrl, configStatuslistener);
                 if (GeckoPreferences.isMmaAvailableAndEnabled(context)) {
                     // Do LeanPlum start/init here
                     MmaDelegate.init(BrowserApp.this, variablesChangedListener);
                 }
                 return null;
             }
         }.execute();
     }
--- a/mobile/android/base/java/org/mozilla/gecko/GeckoApplication.java
+++ b/mobile/android/base/java/org/mozilla/gecko/GeckoApplication.java
@@ -440,17 +440,17 @@ public class GeckoApplication extends Ap
             ThreadUtils.postToBackgroundThread(new Runnable() {
                 @Override
                 public void run() {
                     initPushService();
                 }
             });
         }
 
-        ThreadUtils.postToUiThread(() -> AudioFocusAgent.getInstance().attachToContext(this));
+        AudioFocusAgent.getInstance().attachToContext(this);
     }
 
     private class EventListener implements BundleEventListener
     {
         private void onProfileCreate(final String name, final String path) {
             // Add everything when we're done loading the distribution.
             final Context context = GeckoApplication.this;
             final GeckoProfile profile = GeckoProfile.get(context, name);
--- a/mobile/android/base/java/org/mozilla/gecko/media/GeckoMediaControlAgent.java
+++ b/mobile/android/base/java/org/mozilla/gecko/media/GeckoMediaControlAgent.java
@@ -117,20 +117,16 @@ public class GeckoMediaControlAgent {
         initialize();
     }
 
     private boolean isAttachedToContext() {
         return (mContext != null);
     }
 
     private void initialize() {
-        // Need to make sure the receiver is registered and mInitialized has it's value set
-        // serially, on the main thread.
-        ThreadUtils.assertOnUiThread();
-        
         if (mInitialized) {
             return;
         }
 
         if (!isAndroidVersionLollipopOrHigher()) {
             return;
         }
 
@@ -155,33 +151,31 @@ public class GeckoMediaControlAgent {
         return Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP;
     }
 
     private void getGeckoPreference() {
         mPrefsObserver = new PrefsHelper.PrefHandlerBase() {
             @Override
             public void prefValue(String pref, boolean value) {
                 if (pref.equals(MEDIA_CONTROL_PREF)) {
-                    ThreadUtils.postToUiThread(() -> {
-                        mIsMediaControlPrefOn = value;
+                    mIsMediaControlPrefOn = value;
 
-                        // If media is playing, we just need to create or remove
-                        // the media control interface.
-                        if (sMediaState.equals(State.PLAYING)) {
-                            setState(mIsMediaControlPrefOn ? State.PLAYING : State.STOPPED);
-                        }
+                    // If media is playing, we just need to create or remove
+                    // the media control interface.
+                    if (sMediaState.equals(State.PLAYING)) {
+                        setState(mIsMediaControlPrefOn ? State.PLAYING : State.STOPPED);
+                    }
 
-                        // If turn off pref during pausing, except removing media
-                        // interface, we also need to stop the service and notify
-                        // gecko about that.
-                        if (sMediaState.equals(State.PAUSED) &&
-                                !mIsMediaControlPrefOn) {
-                            handleAction(ACTION_STOP);
-                        }
-                    });
+                    // If turn off pref during pausing, except removing media
+                    // interface, we also need to stop the service and notify
+                    // gecko about that.
+                    if (sMediaState.equals(State.PAUSED) &&
+                            !mIsMediaControlPrefOn) {
+                        handleAction(ACTION_STOP);
+                    }
                 }
             }
         };
         PrefsHelper.addObserver(mPrefs, mPrefsObserver);
     }
 
     private boolean initMediaSession() {
         // Android MediaSession is introduced since version L.
@@ -542,17 +536,26 @@ public class GeckoMediaControlAgent {
         @CheckResult(suggest = "new HeadSetStateReceiver().registerReceiver(Context)")
         HeadSetStateReceiver registerReceiver(Context context) {
             IntentFilter intentFilter = new IntentFilter(AudioManager.ACTION_AUDIO_BECOMING_NOISY);
             context.registerReceiver(this, intentFilter);
             return this;
         }
 
         void unregisterReceiver(Context context) {
-            context.unregisterReceiver(HeadSetStateReceiver.this);
+            try {
+                // TODO investigate why the receiver would not be registered - bug 1505685
+                context.unregisterReceiver(HeadSetStateReceiver.this);
+            } catch (IllegalArgumentException e) {
+                if (AppConstants.RELEASE_OR_BETA) {
+                    Log.w(LOGTAG, "bug 1505685", e);
+                } else {
+                    throw e;
+                }
+            }
         }
 
         @Override
         public void onReceive(Context context, Intent intent) {
             if (isMediaPlaying()) {
                 handleAction(ACTION_PAUSE);
             }
         }
--- a/mobile/android/base/java/org/mozilla/gecko/mma/MmaDelegate.java
+++ b/mobile/android/base/java/org/mozilla/gecko/mma/MmaDelegate.java
@@ -79,21 +79,16 @@ public class MmaDelegate {
 
     private static final MmaInterface mmaHelper = MmaConstants.getMma();
     private static Context applicationContext;
     private static PackageAddedReceiver packageAddedReceiver;
     private static String activityName;     // used to retrieve Activity's SharedPreferences
 
     public static void init(final Activity activity,
                             final MmaVariablesChangedListener remoteVariablesListener) {
-        ThreadUtils.postToUiThread(() -> {
-            if (isActivityAlive(activity)) {
-                registerInstalledPackagesReceiver(activity);
-            }
-        });
         applicationContext = activity.getApplicationContext();
         // Since user attributes are gathered in Fennec, not in MMA implementation,
         // we gather the information here then pass to mmaHelper.init()
         // Note that generateUserAttribute always return a non null HashMap.
         final Map<String, Object> attributes = gatherUserAttributes(activity);
         final String deviceId = getDeviceId(activity);
         mmaHelper.setDeviceId(deviceId);
         PrefsHelper.setPref(GeckoPreferences.PREFS_MMA_DEVICE_ID, deviceId);
@@ -101,16 +96,17 @@ public class MmaDelegate {
         mmaHelper.init(activity, attributes);
 
         if (!isDefaultBrowser(activity)) {
             mmaHelper.event(MmaDelegate.LAUNCH_BUT_NOT_DEFAULT_BROWSER);
         }
         mmaHelper.event(MmaDelegate.LAUNCH_BROWSER);
 
         activityName = activity.getLocalClassName();
+        registerInstalledPackagesReceiver(activity);
         notifyAboutPreviouslyInstalledPackages(activity);
 
         ThreadUtils.postToUiThread(new Runnable() {
             @Override
             public void run() {
                 mmaHelper.listenOnceForVariableChanges(remoteVariablesListener);
             }
         });
@@ -299,40 +295,28 @@ public class MmaDelegate {
 
     private static void registerInstalledPackagesReceiver(@NonNull final Activity activity) {
         packageAddedReceiver = new PackageAddedReceiver();
         activity.registerReceiver(packageAddedReceiver, PackageAddedReceiver.getIntentFilter());
     }
 
     private static void unregisterInstalledPackagesReceiver(@NonNull final Activity activity) {
         if (packageAddedReceiver != null) {
-            activity.unregisterReceiver(packageAddedReceiver);
+            try {
+                // TODO investigate why the receiver would not be registered - bug 1505685
+                activity.unregisterReceiver(packageAddedReceiver);
+            } catch (IllegalArgumentException e) {
+                if (AppConstants.RELEASE_OR_BETA) {
+                    Log.w(TAG, "bug 1505685", e);
+                } else {
+                   throw e;
+                }
+            }
             packageAddedReceiver = null;
         }
     }
 
-    /**
-     * Check and return if the Activity is still alive.
-     *
-     * @param activity an instance of {@link Activity} to be checked if it is still alive.<br>
-     *                 Might be an already leaked instance.
-     * @return <code>true</code> if the Activity is still alive;<br>
-     *         <code>false</code> if the Activity is destroyed / in the process of being destroyed.
-     * @throws IllegalThreadStateException
-     *         if {@link AppConstants#RELEASE_OR_BETA} and called on another thread than Main
-     */
-    private static boolean isActivityAlive(@NonNull final Activity activity) throws IllegalThreadStateException {
-        // all lifecycle methods are run on Main
-        ThreadUtils.assertOnUiThread();
-
-        if (activity.isFinishing()) {
-            return false;
-        }
-
-        return true;
-    }
-
     public interface MmaVariablesChangedListener {
         void onRemoteVariablesChanged();
 
         void onRemoteVariablesUnavailable();
     }
 }