audiopolicy: Make fields of HwModule private
It's a good practice not to expose fields of the class.
Use getter / setter methods instead.
Test: compiles
Change-Id: I9d939d17fafdfff016a300d4f5a979bdc8414f2b
diff --git a/services/audiopolicy/common/managerdefinitions/include/AudioPolicyConfig.h b/services/audiopolicy/common/managerdefinitions/include/AudioPolicyConfig.h
index f2756b5..5685141 100644
--- a/services/audiopolicy/common/managerdefinitions/include/AudioPolicyConfig.h
+++ b/services/audiopolicy/common/managerdefinitions/include/AudioPolicyConfig.h
@@ -112,7 +112,7 @@
mAvailableOutputDevices.add(mDefaultOutputDevices);
mAvailableInputDevices.add(defaultInputDevice);
- module = new HwModule("primary");
+ module = new HwModule(AUDIO_HARDWARE_MODULE_ID_PRIMARY);
sp<OutputProfile> outProfile;
outProfile = new OutputProfile(String8("primary"));
@@ -121,7 +121,7 @@
new AudioProfile(AUDIO_FORMAT_PCM_16_BIT, AUDIO_CHANNEL_OUT_STEREO, 44100));
outProfile->addSupportedDevice(mDefaultOutputDevices);
outProfile->setFlags(AUDIO_OUTPUT_FLAG_PRIMARY);
- module->mOutputProfiles.add(outProfile);
+ module->addOutputProfile(outProfile);
sp<InputProfile> inProfile;
inProfile = new InputProfile(String8("primary"));
@@ -129,7 +129,7 @@
inProfile->addAudioProfile(
new AudioProfile(AUDIO_FORMAT_PCM_16_BIT, AUDIO_CHANNEL_IN_MONO, 8000));
inProfile->addSupportedDevice(defaultInputDevice);
- module->mInputProfiles.add(inProfile);
+ module->addInputProfile(inProfile);
mHwModules.add(module);
}
diff --git a/services/audiopolicy/common/managerdefinitions/include/HwModule.h b/services/audiopolicy/common/managerdefinitions/include/HwModule.h
index 29b6b9c..a8ba040 100644
--- a/services/audiopolicy/common/managerdefinitions/include/HwModule.h
+++ b/services/audiopolicy/common/managerdefinitions/include/HwModule.h
@@ -44,12 +44,10 @@
const char *getName() const { return mName.string(); }
-
const DeviceVector &getDeclaredDevices() const { return mDeclaredDevices; }
void setDeclaredDevices(const DeviceVector &devices);
const InputProfileCollection &getInputProfiles() const { return mInputProfiles; }
-
const OutputProfileCollection &getOutputProfiles() const { return mOutputProfiles; }
void setProfiles(const IOProfileCollection &profiles);
@@ -76,6 +74,7 @@
status_t removeInputProfile(const String8& name);
audio_module_handle_t getHandle() const { return mHandle; }
+ void setHandle(audio_module_handle_t handle);
sp<AudioPort> findPortByTagName(const String8 &tagName) const
{
@@ -85,14 +84,13 @@
// TODO remove from here (split serialization)
void dump(int fd);
+private:
+ void refreshSupportedDevices();
+
const String8 mName; // base name of the audio HW module (primary, a2dp ...)
audio_module_handle_t mHandle;
OutputProfileCollection mOutputProfiles; // output profiles exposed by this module
InputProfileCollection mInputProfiles; // input profiles exposed by this module
-
-private:
- void refreshSupportedDevices();
-
uint32_t mHalVersion; // audio HAL API version
DeviceVector mDeclaredDevices; // devices declared in audio_policy configuration file.
AudioRouteVector mRoutes;
diff --git a/services/audiopolicy/common/managerdefinitions/src/AudioPort.cpp b/services/audiopolicy/common/managerdefinitions/src/AudioPort.cpp
index 53e694b..6807ea5 100644
--- a/services/audiopolicy/common/managerdefinitions/src/AudioPort.cpp
+++ b/services/audiopolicy/common/managerdefinitions/src/AudioPort.cpp
@@ -45,26 +45,17 @@
audio_module_handle_t AudioPort::getModuleHandle() const
{
- if (mModule == 0) {
- return AUDIO_MODULE_HANDLE_NONE;
- }
- return mModule->mHandle;
+ return mModule != 0 ? mModule->getHandle() : AUDIO_MODULE_HANDLE_NONE;
}
uint32_t AudioPort::getModuleVersionMajor() const
{
- if (mModule == 0) {
- return 0;
- }
- return mModule->getHalVersionMajor();
+ return mModule != 0 ? mModule->getHalVersionMajor() : 0;
}
const char *AudioPort::getModuleName() const
{
- if (mModule == 0) {
- return "invalid module";
- }
- return mModule->getName();
+ return mModule != 0 ? mModule->getName() : "invalid module";
}
void AudioPort::toAudioPort(struct audio_port *port) const
diff --git a/services/audiopolicy/common/managerdefinitions/src/DeviceDescriptor.cpp b/services/audiopolicy/common/managerdefinitions/src/DeviceDescriptor.cpp
index fdeea29..ced7a66 100644
--- a/services/audiopolicy/common/managerdefinitions/src/DeviceDescriptor.cpp
+++ b/services/audiopolicy/common/managerdefinitions/src/DeviceDescriptor.cpp
@@ -245,7 +245,8 @@
// without the test?
// This has been demonstrated to NOT be true (at start up)
// ALOG_ASSERT(mModule != NULL);
- dstConfig->ext.device.hw_module = mModule != 0 ? mModule->mHandle : AUDIO_MODULE_HANDLE_NONE;
+ dstConfig->ext.device.hw_module =
+ mModule != 0 ? mModule->getHandle() : AUDIO_MODULE_HANDLE_NONE;
strncpy(dstConfig->ext.device.address, mAddress.string(), AUDIO_DEVICE_MAX_ADDRESS_LEN);
}
@@ -256,7 +257,7 @@
port->id = mId;
toAudioPortConfig(&port->active_config);
port->ext.device.type = mDeviceType;
- port->ext.device.hw_module = mModule->mHandle;
+ port->ext.device.hw_module = mModule->getHandle();
strncpy(port->ext.device.address, mAddress.string(), AUDIO_DEVICE_MAX_ADDRESS_LEN);
}
diff --git a/services/audiopolicy/common/managerdefinitions/src/HwModule.cpp b/services/audiopolicy/common/managerdefinitions/src/HwModule.cpp
index b4feb4d..aef7dbe 100644
--- a/services/audiopolicy/common/managerdefinitions/src/HwModule.cpp
+++ b/services/audiopolicy/common/managerdefinitions/src/HwModule.cpp
@@ -212,6 +212,12 @@
}
}
+void HwModule::setHandle(audio_module_handle_t handle) {
+ ALOGW_IF(mHandle != AUDIO_MODULE_HANDLE_NONE,
+ "HwModule handle is changing from %d to %d", mHandle, handle);
+ mHandle = handle;
+}
+
void HwModule::dump(int fd)
{
const size_t SIZE = 256;
@@ -258,8 +264,8 @@
sp <HwModule> HwModuleCollection::getModuleForDevice(audio_devices_t device) const
{
for (const auto& module : *this) {
- IOProfileCollection& profiles = audio_is_output_device(device) ?
- module->mOutputProfiles : module->mInputProfiles;
+ const auto& profiles = audio_is_output_device(device) ?
+ module->getOutputProfiles() : module->getInputProfiles();
for (const auto& profile : profiles) {
if (profile->supportDevice(device)) {
return module;
diff --git a/services/audiopolicy/managerdefault/AudioPolicyManager.cpp b/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
index 7366378..b717419 100644
--- a/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
+++ b/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
@@ -718,7 +718,7 @@
sp<IOProfile> profile;
for (const auto& hwModule : mHwModules) {
- for (const auto& curProfile : hwModule->mOutputProfiles) {
+ for (const auto& curProfile : hwModule->getOutputProfiles()) {
if (!curProfile->isCompatibleProfile(device, String8(""),
samplingRate, NULL /*updatedSamplingRate*/,
format, NULL /*updatedFormat*/,
@@ -3529,7 +3529,7 @@
audio_devices_t outputDeviceTypes = mAvailableOutputDevices.types();
audio_devices_t inputDeviceTypes = mAvailableInputDevices.types() & ~AUDIO_DEVICE_BIT_IN;
for (const auto& hwModule : mHwModulesAll) {
- hwModule->mHandle = mpClientInterface->loadHwModule(hwModule->getName());
+ hwModule->setHandle(mpClientInterface->loadHwModule(hwModule->getName()));
if (hwModule->getHandle() == AUDIO_MODULE_HANDLE_NONE) {
ALOGW("could not open HW module %s", hwModule->getName());
continue;
@@ -3539,7 +3539,7 @@
// except for direct output streams that are only opened when they are actually
// required by an app.
// This also validates mAvailableOutputDevices list
- for (const auto& outProfile : hwModule->mOutputProfiles) {
+ for (const auto& outProfile : hwModule->getOutputProfiles()) {
if (!outProfile->hasSupportedDevices()) {
ALOGW("Output profile contains no device on module %s", hwModule->getName());
continue;
@@ -3599,7 +3599,7 @@
}
// open input streams needed to access attached devices to validate
// mAvailableInputDevices list
- for (const auto& inProfile : hwModule->mInputProfiles) {
+ for (const auto& inProfile : hwModule->getInputProfiles()) {
if (!inProfile->hasSupportedDevices()) {
ALOGW("Input profile contains no device on module %s", hwModule->getName());
continue;
@@ -3761,8 +3761,8 @@
// then look for output profiles that can be routed to this device
SortedVector< sp<IOProfile> > profiles;
for (const auto& hwModule : mHwModules) {
- for (size_t j = 0; j < hwModule->mOutputProfiles.size(); j++) {
- sp<IOProfile> profile = hwModule->mOutputProfiles[j];
+ for (size_t j = 0; j < hwModule->getOutputProfiles().size(); j++) {
+ sp<IOProfile> profile = hwModule->getOutputProfiles()[j];
if (profile->supportDevice(device)) {
if (!device_distinguishes_on_address(device) ||
profile->supportDeviceAddress(address)) {
@@ -3933,8 +3933,8 @@
}
// Clear any profiles associated with the disconnected device.
for (const auto& hwModule : mHwModules) {
- for (size_t j = 0; j < hwModule->mOutputProfiles.size(); j++) {
- sp<IOProfile> profile = hwModule->mOutputProfiles[j];
+ for (size_t j = 0; j < hwModule->getOutputProfiles().size(); j++) {
+ sp<IOProfile> profile = hwModule->getOutputProfiles()[j];
if (profile->supportDevice(device)) {
ALOGV("checkOutputsForDevice(): "
"clearing direct output profile %zu on module %s",
@@ -3974,9 +3974,9 @@
SortedVector< sp<IOProfile> > profiles;
for (const auto& hwModule : mHwModules) {
for (size_t profile_index = 0;
- profile_index < hwModule->mInputProfiles.size();
+ profile_index < hwModule->getInputProfiles().size();
profile_index++) {
- sp<IOProfile> profile = hwModule->mInputProfiles[profile_index];
+ sp<IOProfile> profile = hwModule->getInputProfiles()[profile_index];
if (profile->supportDevice(device)) {
if (!device_distinguishes_on_address(device) ||
@@ -4072,9 +4072,9 @@
// Clear any profiles associated with the disconnected device.
for (const auto& hwModule : mHwModules) {
for (size_t profile_index = 0;
- profile_index < hwModule->mInputProfiles.size();
+ profile_index < hwModule->getInputProfiles().size();
profile_index++) {
- sp<IOProfile> profile = hwModule->mInputProfiles[profile_index];
+ sp<IOProfile> profile = hwModule->getInputProfiles()[profile_index];
if (profile->supportDevice(device)) {
ALOGV("checkInputsForDevice(): clearing direct input profile %zu on module %s",
profile_index, hwModule->getName());
@@ -4916,7 +4916,7 @@
// the best matching profile, not the first one.
for (const auto& hwModule : mHwModules) {
- for (const auto& profile : hwModule->mInputProfiles) {
+ for (const auto& profile : hwModule->getInputProfiles()) {
// profile->log();
if (profile->isCompatibleProfile(device, address, samplingRate,
&samplingRate /*updatedSamplingRate*/,