resolve merge conflicts of a3de77f to master

Change-Id: Idb3346465ee7f47d95fd24e2dafdd66f3759c1be
diff --git a/services/audiopolicy/managerdefault/AudioPolicyManager.cpp b/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
index 39d156c..5dcd41c 100644
--- a/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
+++ b/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
@@ -1727,7 +1727,7 @@
     if (isInCall()) {
         *concurrency |= API_INPUT_CONCURRENCY_CALL;
     }
-    if (mInputs.activeInputsCount() != 0) {
+    if (mInputs.activeInputsCountOnDevices() != 0) {
         *concurrency |= API_INPUT_CONCURRENCY_CAPTURE;
     }
 
@@ -1739,8 +1739,10 @@
     mInputRoutes.incRouteActivity(session);
 
     if (audioSession->activeCount() == 1 || mInputRoutes.hasRouteChanged(session)) {
-
-        setInputDevice(input, getNewInputDevice(inputDesc), true /* force */);
+        // indicate active capture to sound trigger service if starting capture from a mic on
+        // primary HW module
+        audio_devices_t device = getNewInputDevice(inputDesc);
+        setInputDevice(input, device, true /* force */);
 
         if (inputDesc->getAudioSessionCount(true/*activeOnly*/) == 1) {
             // if input maps to a dynamic policy with an activity listener, notify of state change
@@ -1750,7 +1752,9 @@
                         MIX_STATE_MIXING);
             }
 
-            if (mInputs.activeInputsCount() == 0) {
+            audio_devices_t primaryInputDevices = availablePrimaryInputDevices();
+            if (((device & primaryInputDevices & ~AUDIO_DEVICE_BIT_IN) != 0) &&
+                    mInputs.activeInputsCountOnDevices(primaryInputDevices) == 0) {
                 SoundTrigger::setCaptureState(true);
             }
 
@@ -1833,9 +1837,14 @@
                 }
             }
 
+            audio_devices_t device = inputDesc->mDevice;
             resetInputDevice(input);
 
-            if (mInputs.activeInputsCount() == 0) {
+            // indicate inactive capture to sound trigger service if stopping capture from a mic on
+            // primary HW module
+            audio_devices_t primaryInputDevices = availablePrimaryInputDevices();
+            if (((device & primaryInputDevices & ~AUDIO_DEVICE_BIT_IN) != 0) &&
+                    mInputs.activeInputsCountOnDevices(primaryInputDevices) == 0) {
                 SoundTrigger::setCaptureState(false);
             }
             inputDesc->clearPreemptedSessions();