2

I'm using several Firebase products in an Android app:

compile 'com.google.firebase:firebase-core:11.0.1'
compile 'com.google.firebase:firebase-database:11.0.1'
compile 'com.google.firebase:firebase-storage:11.0.1'
compile 'com.google.firebase:firebase-auth:11.0.1'
compile 'com.google.firebase:firebase-messaging:11.0.1'

One or more of these products seems to be using the WAKE_LOCK permission. Possibly Analytics or FCM.

I can understand where it's needed. The problem however is that in the Google Play Console, in the Android Vitals section, Google warns me that the Stuck partial wake locks percentage is 2.30% which is larger than the Bad behavior threshold which is 0.70%. Similarly, the Background stuck partial wake locks is 1.40% which is again larger than the Bad behavior threshold which is 0.10%.

In other words, Google considers this number of wake locks a 'bad behavior'.

I don't use wake locks, so it seems that the issue is coming from the Firebase SDK.

Anyone knows what's causing that? Can we fix that?

steliosf
  • 3,669
  • 2
  • 31
  • 45

1 Answers1

0

You can tell where Android manifest items come from by using Android Studio's Merged Manifest tab when viewing your app's manifest file. When you view this on you manifest, you'll see that WAKE_LOCK comes from firebase-iid.

To find out what includes firebase-iid, you can use gradle to show a dependency graph.

./gradlew dependencies

The output of this shows that it's included by both firebase-core and firebase-messaging:

+--- com.google.firebase:firebase-messaging:11.6.0
|    +--- com.google.firebase:firebase-iid:11.6.0
|    |    +--- com.google.android.gms:play-services-basement:11.6.0 (*)
|    |    +--- com.google.firebase:firebase-common:11.6.0 (*)
|    |    +--- com.google.android.gms:play-services-tasks:11.6.0 (*)
|    |    \--- com.google.firebase:firebase-iid-license:11.6.0
|    +--- com.google.android.gms:play-services-basement:11.6.0 (*)
|    +--- com.google.firebase:firebase-common:11.6.0 (*)
|    \--- com.google.firebase:firebase-messaging-license:11.6.0
\--- com.google.firebase:firebase-core:11.6.0
     \--- com.google.firebase:firebase-analytics:11.6.0
          +--- com.google.android.gms:play-services-basement:11.6.0 (*)
          +--- com.google.firebase:firebase-common:11.6.0 (*)
          +--- com.google.firebase:firebase-analytics-impl:11.6.0
          |    +--- com.google.android.gms:play-services-basement:11.6.0 (*)
          |    +--- com.google.firebase:firebase-iid:11.6.0 (*)
          |    +--- com.google.firebase:firebase-common:11.6.0 (*)
          |    +--- com.google.android.gms:play-services-tasks:11.6.0 (*)
          |    \--- com.google.firebase:firebase-analytics-impl-license:11.6.0
          \--- com.google.firebase:firebase-analytics-license:11.6.0

There is nothing here that needs to be "fixed". Firebase simply makes use of wake locks to do its normal business. You can always try to remove the permission, but then Firebase may not work correctly any more. Just leave it alone.

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
  • There is definitely something that needs to be fixed, since Google flags this as **bad behavior**. There's also an official guide from Google that suggests possible solutions, mainly by using JobScheduler: https://developer.android.com/topic/performance/vitals/wakelock.html – steliosf Jan 14 '18 at 23:48
  • You're misunderstanding the message. Usage of wake locks is not always bad. __Incorrect__ usage of wake locks is bad. – Doug Stevenson Jan 15 '18 at 00:00
  • The wake lock permission is not going away any time soon, but if you think that Firebase is provably at fault for anything, please file a bug report. https://firebase.google.com/support/contact/bugs-features/ – Doug Stevenson Jan 15 '18 at 00:02
  • 1
    Of course wake locks are not always bad. However, Google flags this large number of wake locks as a 'bad behavior' in Android vitals. And 'bad behavior' issues affect the app ranking in the Play Store searches (_source: https://developer.android.com/distribute/best-practices/develop/android-vitals.html_). They also suggest that when using wake locks, the app should be in the foreground, while Firebase Analytics seem to be using a wake lock to upload the data on the background. Again, I personally don't have a problem with that, however that is flagged as an issue in Google Play console. – steliosf Jan 15 '18 at 00:17
  • In any case, I'll file a bug report – steliosf Jan 15 '18 at 00:18