Audio policy: fix volume change on DEVICE_OUT_SPEAKER_SAFE

When changing stream volume, compare given device and current device
  for stream both as filtered through Volume::getDeviceForVolume.
This behavior matters for Android devices playing notifications and
  ringtones on the AUDIO_DEVICE_OUT_SPEAKER_SAFE, which is filtered
  out for volumes (see Volume.h for getDeviceForVolume() method).

Test: play a ringtone and modify volume with vol keys
Bug: 63004956
Change-Id: I139099f34e0ab091fd0ea761c75949656549f77a
diff --git a/services/audiopolicy/managerdefault/AudioPolicyManager.cpp b/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
index b509759..6c86d51 100644
--- a/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
+++ b/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
@@ -2165,7 +2165,8 @@
                 continue;
             }
             routing_strategy curStrategy = getStrategy((audio_stream_type_t)curStream);
-            audio_devices_t curStreamDevice = getDeviceForStrategy(curStrategy, false /*fromCache*/);
+            audio_devices_t curStreamDevice = Volume::getDeviceForVolume(getDeviceForStrategy(
+                    curStrategy, false /*fromCache*/));
             if ((device != AUDIO_DEVICE_OUT_DEFAULT_FOR_VOLUME) &&
                     ((curStreamDevice & device) == 0)) {
                 continue;
@@ -2176,7 +2177,7 @@
                 applyVolume = (curDevice & curStreamDevice) != 0;
             } else {
                 applyVolume = !mVolumeCurves->hasVolumeIndexForDevice(
-                        stream, Volume::getDeviceForVolume(curStreamDevice));
+                        stream, curStreamDevice);
             }
 
             if (applyVolume) {