audio policy: optimize preferred device selection

Several optimizations to avoid redundant track invalidation
when a preferred device is specified for an AudioTrack.
1) in AudioTrack: only invalidate the track if the preferred device
   differs from the actual device. If the track is not active,
   immediately restore it instead of waiting for next start.
2) in AudioPolicyManager: avoid invalidating the track in startSource() and
   stopSource() if another active client with the same preferred device
   exists.

Also fix a problem in getOutput() preventing MediaPlayer to open a sink
for call assistant use case.

Bug: 272560885
Test: atest RoutingTest
Change-Id: Ia3fb06eaf2e292d2795d588226c7672b7ab6722f
7 files changed