Use new stop_all_recogntions when changing sound trigger state.

If no implementation is provided to the hal or uses an earlier version,
will fallback to using the single stop_recognition on all running
models.

Change-Id: Ifc1bd3f2887ad9397499bfd291241fd907b55421
diff --git a/services/soundtrigger/SoundTriggerHwService.cpp b/services/soundtrigger/SoundTriggerHwService.cpp
index 66310b5..8f37bed 100644
--- a/services/soundtrigger/SoundTriggerHwService.cpp
+++ b/services/soundtrigger/SoundTriggerHwService.cpp
@@ -70,7 +70,8 @@
               SOUND_TRIGGER_HARDWARE_MODULE_ID, HW_MODULE_PREFIX, strerror(-rc));
         return;
     }
-    if (dev->common.version != SOUND_TRIGGER_DEVICE_API_VERSION_CURRENT) {
+    if (dev->common.version < SOUND_TRIGGER_DEVICE_API_VERSION_1_0 ||
+        dev->common.version > SOUND_TRIGGER_DEVICE_API_VERSION_CURRENT) {
         ALOGE("wrong sound trigger hw device version %04x", dev->common.version);
         return;
     }
@@ -808,10 +809,20 @@
             goto exit;
         }
 
+        const bool supports_stop_all =
+            (mHwDevice->common.version >= SOUND_TRIGGER_DEVICE_API_VERSION_1_1 &&
+             mHwDevice->stop_all_recognitions);
+
+        if (supports_stop_all) {
+            mHwDevice->stop_all_recognitions(mHwDevice);
+        }
+
         for (size_t i = 0; i < mModels.size(); i++) {
             sp<Model> model = mModels.valueAt(i);
             if (model->mState == Model::STATE_ACTIVE) {
-                mHwDevice->stop_recognition(mHwDevice, model->mHandle);
+                if (!supports_stop_all) {
+                    mHwDevice->stop_recognition(mHwDevice, model->mHandle);
+                }
                 // keep model in ACTIVE state so that event is processed by onCallbackEvent()
                 if (model->mType == SOUND_MODEL_TYPE_KEYPHRASE) {
                     struct sound_trigger_phrase_recognition_event event;