- Notifications
You must be signed in to change notification settings - Fork 648
Open
Labels
Description
- Firebase Component: Common
- Component version: 20.4.2
Steps to reproduce:
Crashlytics notified us about a crash in FirebaseApp.UserUnlockReceiver.unregister. The method is only called from FirebaseApp.UserUnlockReceiver.onReceive which in turn only responds to android.intent.action.USER_UNLOCKED. I don't know how many times the system sends the broadcast but it apparently isn't just once.
Relevant Code:
firebase-android-sdk/firebase-common/src/main/java/com/google/firebase/FirebaseApp.java
Lines 668 to 680 in b77c218
| public void onReceive(Context context, Intent intent) { | |
| // API initialization is idempotent. | |
| synchronized (LOCK) { | |
| for (FirebaseApp app : INSTANCES.values()) { | |
| app.initializeAllApis(); | |
| } | |
| } | |
| unregister(); | |
| } | |
| public void unregister() { | |
| applicationContext.unregisterReceiver(this); | |
| } |
FirebaseApp initialization may be idempotent but Context.unregisterReceiver isn't. The method crashes if the receiver isn't registered.
Suggested solution
public void unregister() { try { applicationContext.unregisterReceiver(this); } catch (IllegalArgumentException ignore) { // The receiver isn't registered. } }