audio policy: fix STRATEGY_PHONE routing when not in call

commit 2517af3e unintentionaly mapped STRATEGY_PHONE to
STRATEGY_MEDIA when not in call. This mapping is only for
STRATEGY_DTMF.

Also group filtering of available output devices according to
strategy in a helper method and apply the filter also before
checking for preferred devices for a given strategy.

Bug: 179642678
Test: atest AudioCommunicationDeviceTest
Change-Id: Ia47b81ee6aff9a49a83f40870eb811b493141f5b
diff --git a/services/audiopolicy/enginedefault/src/Engine.h b/services/audiopolicy/enginedefault/src/Engine.h
index 6214fe7..6dc6cd0 100644
--- a/services/audiopolicy/enginedefault/src/Engine.h
+++ b/services/audiopolicy/enginedefault/src/Engine.h
@@ -74,6 +74,11 @@
 
     status_t setDefaultDevice(audio_devices_t device);
 
+    void filterOutputDevicesForStrategy(legacy_strategy strategy,
+                                            DeviceVector& availableOutputDevices,
+                                            const DeviceVector availableInputDevices,
+                                            const SwAudioOutputCollection &outputs) const;
+
     DeviceVector getDevicesForStrategyInt(legacy_strategy strategy,
                                           DeviceVector availableOutputDevices,
                                           DeviceVector availableInputDevices,