Merge "audio policy: fix configurable engine and dynamic policies"
diff --git a/services/audiopolicy/common/managerdefinitions/src/DeviceDescriptor.cpp b/services/audiopolicy/common/managerdefinitions/src/DeviceDescriptor.cpp
index 91961d0..1a74f48 100644
--- a/services/audiopolicy/common/managerdefinitions/src/DeviceDescriptor.cpp
+++ b/services/audiopolicy/common/managerdefinitions/src/DeviceDescriptor.cpp
@@ -40,7 +40,7 @@
mTagName(tagName), mDeviceType(type), mEncodedFormats(encodedFormats)
{
mCurrentEncodedFormat = AUDIO_FORMAT_DEFAULT;
- if (type == AUDIO_DEVICE_IN_REMOTE_SUBMIX || type == AUDIO_DEVICE_OUT_REMOTE_SUBMIX ) {
+ if (audio_is_remote_submix_device(type)) {
mAddress = String8("0");
}
/* If framework runs against a pre 5.0 Audio HAL, encoded formats are absent from the config.
diff --git a/services/audiopolicy/managerdefault/AudioPolicyManager.cpp b/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
index d60fc03..a12bdaa 100644
--- a/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
+++ b/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
@@ -169,8 +169,6 @@
broadcastDeviceConnectionState(device, AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE);
return INVALID_OPERATION;
}
- // Propagate device availability to Engine
- mEngine->setDeviceConnectionState(device, state);
// outputs should never be empty here
ALOG_ASSERT(outputs.size() != 0, "setDeviceConnectionState():"
@@ -200,8 +198,6 @@
// Reset active device codec
device->setEncodedFormat(AUDIO_FORMAT_DEFAULT);
- // Propagate device availability to Engine
- mEngine->setDeviceConnectionState(device, state);
} break;
default:
@@ -209,6 +205,9 @@
return BAD_VALUE;
}
+ // Propagate device availability to Engine
+ setEngineDeviceConnectionState(device, state);
+
// No need to evaluate playback routing when connecting a remote submix
// output device used by a dynamic policy of type recorder as no
// playback use case is affected.
@@ -318,9 +317,6 @@
if (mAvailableInputDevices.add(device) < 0) {
return NO_MEMORY;
}
-
- // Propagate device availability to Engine
- mEngine->setDeviceConnectionState(device, state);
} break;
// handle input device disconnection
@@ -337,9 +333,6 @@
checkInputsForDevice(device, state, inputs);
mAvailableInputDevices.remove(device);
-
- // Propagate device availability to Engine
- mEngine->setDeviceConnectionState(device, state);
} break;
default:
@@ -347,6 +340,9 @@
return BAD_VALUE;
}
+ // Propagate device availability to Engine
+ setEngineDeviceConnectionState(device, state);
+
closeAllInputs();
// As the input device list can impact the output device selection, update
// getDeviceForStrategy() cache
@@ -369,6 +365,17 @@
return BAD_VALUE;
}
+void AudioPolicyManager::setEngineDeviceConnectionState(const sp<DeviceDescriptor> device,
+ audio_policy_dev_state_t state) {
+
+ // the Engine does not have to know about remote submix devices used by dynamic audio policies
+ if (audio_is_remote_submix_device(device->type()) && device->address() != "0") {
+ return;
+ }
+ mEngine->setDeviceConnectionState(device, state);
+}
+
+
audio_policy_dev_state_t AudioPolicyManager::getDeviceConnectionState(audio_devices_t device,
const char *device_address)
{
@@ -4399,7 +4406,7 @@
continue;
}
// Device is now validated and can be appended to the available devices of the engine
- mEngine->setDeviceConnectionState(device, AUDIO_POLICY_DEVICE_STATE_AVAILABLE);
+ setEngineDeviceConnectionState(device, AUDIO_POLICY_DEVICE_STATE_AVAILABLE);
i++;
}
};
@@ -4413,7 +4420,7 @@
status = NO_INIT;
}
// If microphones address is empty, set it according to device type
- for (size_t i = 0; i < mAvailableInputDevices.size(); i++) {
+ for (size_t i = 0; i < mAvailableInputDevices.size(); i++) {
if (mAvailableInputDevices[i]->address().isEmpty()) {
if (mAvailableInputDevices[i]->type() == AUDIO_DEVICE_IN_BUILTIN_MIC) {
mAvailableInputDevices[i]->setAddress(String8(AUDIO_BOTTOM_MICROPHONE_ADDRESS));
diff --git a/services/audiopolicy/managerdefault/AudioPolicyManager.h b/services/audiopolicy/managerdefault/AudioPolicyManager.h
index 41327bc..26208c8 100644
--- a/services/audiopolicy/managerdefault/AudioPolicyManager.h
+++ b/services/audiopolicy/managerdefault/AudioPolicyManager.h
@@ -847,6 +847,10 @@
const char *device_address,
const char *device_name,
audio_format_t encodedFormat);
+
+ void setEngineDeviceConnectionState(const sp<DeviceDescriptor> device,
+ audio_policy_dev_state_t state);
+
void updateMono(audio_io_handle_t output) {
AudioParameter param;
param.addInt(String8(AudioParameter::keyMonoOutput), (int)mMasterMono);