MediaSession: Improve MediaSessionStack logic

There was an issue that media button events (play / pause) didn’t go
to the expected media session. If an app creates a media session during
all media sessions are paused, the next coming media play event is
consumed by the newly created media session. It makes sense in general,
but if the media session is created in a background process without any
visible UI, it causes unexpected results.

This patch resolves the issue by checking if a newly added session comes
from the most recent user-facing app.

Bug: 24990104
Change-Id: Ic9632bced37bffd28260afe3523d9a20ea4d3c21
3 files changed