Skip to content

"MESSAGING_EVENT" and "INSTANCE_ID_EVENT" running Services in apps started in "Restricted Mode" #1456

Open
@pablobaxter

Description

@pablobaxter

Describe your environment

  • Android Studio version: 3.6.2
  • Firebase Component: FCM, InstanceID
  • Component version: 16.1.0

Describe the problem

There is a specific instance in Android where an app can be started without calling any ContentProviders or the Application listed in the app's manifest.

From https://developer.android.com/guide/topics/data/autobackup#ImplementingBackupAgent:

During auto backup and restore operations, the system launches the app in a restricted mode to both prevent the app from accessing files that could cause conflicts and let the app execute callback methods in its BackupAgent. In this restricted mode, the app's main activity is not automatically launched, its Content Providers are not initialized, and the base-class Application is instantiated instead
of any subclass declared in the app's manifest.

The problem here is that we can still send intents to a BroadcastReceiver or Service that is exported (such as FirebaseMessagingService). I have seen several crashes in the Google Play console that don't exist in Firebase Crashlytics, that made absolutely no sense unless my Service ran before my custom Application class or any of the ContentProvider classes I had, which I thought was never the case.

After some testing, I verified that this was in fact happening, and explained some other crashes that made no sense. Essentially, the app can start without ever initializing Firebase (unless we initialize it on the Service itself) and still get external intents from Firebase, causing crashes.

Steps to reproduce:

  1. Install any app that is setup with FirebaseMessagingService (ensure FirebaseApp.getInstance() is called in it) and has android:allowBackup="true" in the AndroidManifest.xml.
  2. Ensure the device has a Google account setup in it.
  3. Perform a backup on the device via ADB (adb shell bmgr backupnow com.mypackage.foo. More info here: https://developer.android.com/guide/topics/data/testingbackup)
  4. While the backup is occurring, trigger a MESSAGING_EVENT intent to start the service

If done correctly (or incorrectly?), the app will crash because FirebaseApp was not initialized.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions