firebase / firebase/firebase-android-sdk

FirebaseApp.UserUnlockReceiver.unregister crashes

Open
#5,775 5 comments 0 reactions 0 assignees View on GitHub
api: core
Dominant language
Java
Stars
2.6k
Forks
710
Avg merge
2d 23h
Merged PRs (30d)
34

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:
https://github.com/firebase/firebase-android-sdk/blob/b77c2188e5ec7c53c2a955fc4663b301e6c98c83/firebase-common/src/main/java/com/google/firebase/FirebaseApp.java#L668-L680

`FirebaseApp` initialization may be idempotent but `Context.unregisterReceiver` isn't. The method crashes if the receiver isn't registered.

#### Suggested solution
```java
public void unregister() {
try {
applicationContext.unregisterReceiver(this);
} catch (IllegalArgumentException ignore) {
// The receiver isn't registered.
}
}
```

Contributor guide

Open the contributing guide

Research direction

Start in firebase-common/src/main/java/com/google/firebase/FirebaseApp.java at FirebaseApp.UserUnlockReceiver.unregister and its onReceive caller. Reproduce or inspect the repeated android.intent.action.USER_UNLOCKED path, then verify that an already-unregistered receiver no longer crashes while normal unregistration still works.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, java
Domain
mobile
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.