Bug 1501648 - Prevent crashes for unregistered receivers from MmaDelegate and GeckoMediaControlAgent; r=jchen,JanH
authorPetru Lingurar <petru.lingurar@softvision.ro>
Thu, 08 Nov 2018 12:08:40 +0000
changeset 501554 4f8d41b9bb67403c5021a9829ff9fae13ccc8b5c
parent 501553 c9f524cff7df54bf578bd34874e88b4ed524a4c8
child 501555 22d08a6ea7cc9c44390357d0e2ad93cf240ca23c
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)
reviewersjchen, JanH
bugs1501648, 1505685
milestone65.0a1
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
Bug 1501648 - Prevent crashes for unregistered receivers from MmaDelegate and GeckoMediaControlAgent; r=jchen,JanH Although this two receivers are guarded by checks for if they were initialized (and so registered) there are reports of crashes because of trying to unregister them without them actually being registered. The underlying issue will be investigated further in bug 1505685 but for the moment wrapping the unregister operations in a try-catch saves the users from a crash and because the unregister is done when the app is closed (for the MmaDelegate receiver) or when the app finished playing media (for the GeckoMediaControlAgent receiver) the user doesn't loose any functionality going forward. Differential Revision: https://phabricator.services.mozilla.com/D11177
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/media/GeckoMediaControlAgent.java
+++ b/mobile/android/base/java/org/mozilla/gecko/media/GeckoMediaControlAgent.java
@@ -536,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
@@ -7,17 +7,19 @@
 package org.mozilla.gecko.mma;
 
 import android.app.Activity;
 import android.content.Context;
 import android.content.SharedPreferences;
 import android.os.Bundle;
 import android.support.annotation.NonNull;
 import android.text.TextUtils;
+import android.util.Log;
 
+import org.mozilla.gecko.AppConstants;
 import org.mozilla.gecko.Experiments;
 import org.mozilla.gecko.MmaConstants;
 import org.mozilla.gecko.PrefsHelper;
 import org.mozilla.gecko.R;
 import org.mozilla.gecko.Tab;
 import org.mozilla.gecko.Tabs;
 import org.mozilla.gecko.activitystream.homepanel.ActivityStreamConfiguration;
 import org.mozilla.gecko.firstrun.PanelConfig;
@@ -293,17 +295,26 @@ 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;
         }
     }
 
     public interface MmaVariablesChangedListener {
         void onRemoteVariablesChanged();
 
         void onRemoteVariablesUnavailable();