In Developer console - Android vitals I see warning that app has "Stuck partial wake locks". In documentation it's described as
A partial wake lock becomes stuck if it is held for a long time while your app is running in the background (no part of your app is visible to the user).
It's true that app is running in background (playing audio) but I use foreground service and whole time when app holds lock notification is visible.
Later in documentation you can read
Make sure some portion of your app remains in the foreground. For example, if you need to run a service, start a foreground service instead. This visually indicates to the user that your app is still running.
But it doesn't seems to be true. Is Android vitals ignoring that app has foreground service? Does anyone has similar experience?
EDIT: here is code from my AudioService
PowerManager.WakeLock mWakeLock = null;
boolean mHasWakeLock;
void acquireLocks(){
if (!mHasWakeLock) {
final PowerManager pm = (PowerManager)
context.getSystemService(Context.POWER_SERVICE);
mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,TAG);
mWakeLock.setReferenceCounted(false);
mWakeLock.acquire();
mHasWakeLock = true;
}
}
void releaseLocks() {
if (mWakeLock != null) {
mWakeLock.release();
mWakeLock = null;
}
mHasWakeLock = false;
}
void play(){
startForeground(NOTIFICATION_ID, notification);
acquireLocks();
}
void stop(){
releaseLocks();
stopForeground(true);
}
I think, the problem is in
Should be
true
, so the System can count, when you release the lock. In your case, you may well be releasing it, but the System does not "see" it. This might confuse vitals.Try it with that flag set to true. Hope this helps.