Skip to content

FirebaseApp.UserUnlockReceiver.unregister crashes #5775

Open
@consp1racy

Description

@consp1racy
  • 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:

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.
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions