From 7288ab87a7aa730ffe97d7dc7e118123107bfcea Mon Sep 17 00:00:00 2001 From: Eric Laurent Date: Wed, 6 May 2015 18:44:02 -0700 Subject: audio policy: clarify use of mName field for audio devices The audio port field mName was used for two different purposes which caused a problem when exposing this information at the SDK API. Create a new "mTag" field storing the audio_policy.conf device tag if needed. Field "mName" is now used to store any additional name associated to a given device when available (e.g Manufacturer and model name for a USB device). Change-Id: I17fa872e4a3a2e1b7cbb807c6f72e095a8a2c9c5 --- .../managerdefinitions/include/DeviceDescriptor.h | 9 +++--- .../managerdefinitions/src/ConfigParsingUtils.cpp | 6 ++-- .../managerdefinitions/src/DeviceDescriptor.cpp | 33 +++++++++------------- .../common/managerdefinitions/src/HwModule.cpp | 18 ++++++------ 4 files changed, 31 insertions(+), 35 deletions(-) (limited to 'services/audiopolicy/common') diff --git a/services/audiopolicy/common/managerdefinitions/include/DeviceDescriptor.h b/services/audiopolicy/common/managerdefinitions/include/DeviceDescriptor.h index aa37eec..d1a2f4f 100644 --- a/services/audiopolicy/common/managerdefinitions/include/DeviceDescriptor.h +++ b/services/audiopolicy/common/managerdefinitions/include/DeviceDescriptor.h @@ -29,7 +29,7 @@ namespace android { class DeviceDescriptor : public AudioPort, public AudioPortConfig { public: - DeviceDescriptor(const String8& name, audio_devices_t type); + DeviceDescriptor(audio_devices_t type); virtual ~DeviceDescriptor() {} @@ -50,10 +50,9 @@ public: status_t dump(int fd, int spaces, int index) const; void log() const; + String8 mTag; String8 mAddress; - static String8 emptyNameStr; - private: audio_devices_t mDeviceType; audio_port_handle_t mId; @@ -73,12 +72,12 @@ public: audio_devices_t types() const { return mDeviceTypes; } void loadDevicesFromType(audio_devices_t types); - void loadDevicesFromName(char *name, const DeviceVector& declaredDevices); + void loadDevicesFromTag(char *tag, const DeviceVector& declaredDevices); sp getDevice(audio_devices_t type, String8 address) const; DeviceVector getDevicesFromType(audio_devices_t types) const; sp getDeviceFromId(audio_port_handle_t id) const; - sp getDeviceFromName(const String8& name) const; + sp getDeviceFromTag(const String8& tag) const; DeviceVector getDevicesFromTypeAddr(audio_devices_t type, String8 address) const; audio_devices_t getDevicesFromHwModule(audio_module_handle_t moduleHandle) const; diff --git a/services/audiopolicy/common/managerdefinitions/src/ConfigParsingUtils.cpp b/services/audiopolicy/common/managerdefinitions/src/ConfigParsingUtils.cpp index 9ab1d61..89ef045 100644 --- a/services/audiopolicy/common/managerdefinitions/src/ConfigParsingUtils.cpp +++ b/services/audiopolicy/common/managerdefinitions/src/ConfigParsingUtils.cpp @@ -218,7 +218,7 @@ void ConfigParsingUtils::loadGlobalConfig(cnode *root, const sp& modul node = node->first_child; while (node) { if (strcmp(ATTACHED_OUTPUT_DEVICES_TAG, node->name) == 0) { - availableOutputDevices.loadDevicesFromName((char *)node->value, + availableOutputDevices.loadDevicesFromTag((char *)node->value, declaredDevices); ALOGV("loadGlobalConfig() Attached Output Devices %08x", availableOutputDevices.types()); @@ -228,13 +228,13 @@ void ConfigParsingUtils::loadGlobalConfig(cnode *root, const sp& modul ARRAY_SIZE(sDeviceTypeToEnumTable), (char *)node->value); if (device != AUDIO_DEVICE_NONE) { - defaultOutputDevice = new DeviceDescriptor(String8("default-output"), device); + defaultOutputDevice = new DeviceDescriptor(device); } else { ALOGW("loadGlobalConfig() default device not specified"); } ALOGV("loadGlobalConfig() mDefaultOutputDevice %08x", defaultOutputDevice->type()); } else if (strcmp(ATTACHED_INPUT_DEVICES_TAG, node->name) == 0) { - availableInputDevices.loadDevicesFromName((char *)node->value, + availableInputDevices.loadDevicesFromTag((char *)node->value, declaredDevices); ALOGV("loadGlobalConfig() Available InputDevices %08x", availableInputDevices.types()); } else if (strcmp(SPEAKER_DRC_ENABLED_TAG, node->name) == 0) { diff --git a/services/audiopolicy/common/managerdefinitions/src/DeviceDescriptor.cpp b/services/audiopolicy/common/managerdefinitions/src/DeviceDescriptor.cpp index 0715eea..797077a 100644 --- a/services/audiopolicy/common/managerdefinitions/src/DeviceDescriptor.cpp +++ b/services/audiopolicy/common/managerdefinitions/src/DeviceDescriptor.cpp @@ -24,13 +24,11 @@ namespace android { -String8 DeviceDescriptor::emptyNameStr = String8(""); - -DeviceDescriptor::DeviceDescriptor(const String8& name, audio_devices_t type) : - AudioPort(name, AUDIO_PORT_TYPE_DEVICE, +DeviceDescriptor::DeviceDescriptor(audio_devices_t type) : + AudioPort(String8(""), AUDIO_PORT_TYPE_DEVICE, audio_is_output_device(type) ? AUDIO_PORT_ROLE_SINK : AUDIO_PORT_ROLE_SOURCE), - mAddress(""), mDeviceType(type), mId(0) + mTag(""), mAddress(""), mDeviceType(type), mId(0) { } @@ -142,24 +140,21 @@ void DeviceVector::loadDevicesFromType(audio_devices_t types) uint32_t i = 31 - __builtin_clz(types); uint32_t type = 1 << i; types &= ~type; - add(new DeviceDescriptor(String8("device_type"), type | role_bit)); + add(new DeviceDescriptor(type | role_bit)); } } -void DeviceVector::loadDevicesFromName(char *name, +void DeviceVector::loadDevicesFromTag(char *tag, const DeviceVector& declaredDevices) { - char *devName = strtok(name, "|"); - while (devName != NULL) { - if (strlen(devName) != 0) { + char *devTag = strtok(tag, "|"); + while (devTag != NULL) { + if (strlen(devTag) != 0) { audio_devices_t type = ConfigParsingUtils::stringToEnum(sDeviceTypeToEnumTable, ARRAY_SIZE(sDeviceTypeToEnumTable), - devName); + devTag); if (type != AUDIO_DEVICE_NONE) { - devName = (char *)ConfigParsingUtils::enumToString(sDeviceNameToEnumTable, - ARRAY_SIZE(sDeviceNameToEnumTable), - type); - sp dev = new DeviceDescriptor(String8(devName), type); + sp dev = new DeviceDescriptor(type); if (type == AUDIO_DEVICE_IN_REMOTE_SUBMIX || type == AUDIO_DEVICE_OUT_REMOTE_SUBMIX ) { dev->mAddress = String8("0"); @@ -167,13 +162,13 @@ void DeviceVector::loadDevicesFromName(char *name, add(dev); } else { sp deviceDesc = - declaredDevices.getDeviceFromName(String8(devName)); + declaredDevices.getDeviceFromTag(String8(devTag)); if (deviceDesc != 0) { add(deviceDesc); } } } - devName = strtok(NULL, "|"); + devTag = strtok(NULL, "|"); } } @@ -239,11 +234,11 @@ DeviceVector DeviceVector::getDevicesFromTypeAddr( return devices; } -sp DeviceVector::getDeviceFromName(const String8& name) const +sp DeviceVector::getDeviceFromTag(const String8& tag) const { sp device; for (size_t i = 0; i < size(); i++) { - if (itemAt(i)->mName == name) { + if (itemAt(i)->mTag == tag) { device = itemAt(i); break; } diff --git a/services/audiopolicy/common/managerdefinitions/src/HwModule.cpp b/services/audiopolicy/common/managerdefinitions/src/HwModule.cpp index e955447..7e2050b 100644 --- a/services/audiopolicy/common/managerdefinitions/src/HwModule.cpp +++ b/services/audiopolicy/common/managerdefinitions/src/HwModule.cpp @@ -58,7 +58,7 @@ status_t HwModule::loadInput(cnode *root) } else if (strcmp(node->name, CHANNELS_TAG) == 0) { profile->loadInChannels((char *)node->value); } else if (strcmp(node->name, DEVICES_TAG) == 0) { - profile->mSupportedDevices.loadDevicesFromName((char *)node->value, + profile->mSupportedDevices.loadDevicesFromTag((char *)node->value, mDeclaredDevices); } else if (strcmp(node->name, FLAGS_TAG) == 0) { profile->mFlags = ConfigParsingUtils::parseInputFlagNames((char *)node->value); @@ -105,7 +105,7 @@ status_t HwModule::loadOutput(cnode *root) } else if (strcmp(node->name, CHANNELS_TAG) == 0) { profile->loadOutChannels((char *)node->value); } else if (strcmp(node->name, DEVICES_TAG) == 0) { - profile->mSupportedDevices.loadDevicesFromName((char *)node->value, + profile->mSupportedDevices.loadDevicesFromTag((char *)node->value, mDeclaredDevices); } else if (strcmp(node->name, FLAGS_TAG) == 0) { profile->mFlags = ConfigParsingUtils::parseOutputFlagNames((char *)node->value); @@ -154,7 +154,8 @@ status_t HwModule::loadDevice(cnode *root) ALOGW("loadDevice() bad type %08x", type); return BAD_VALUE; } - sp deviceDesc = new DeviceDescriptor(String8(root->name), type); + sp deviceDesc = new DeviceDescriptor(type); + deviceDesc->mTag = String8(root->name); node = root->first_child; while (node) { @@ -172,8 +173,8 @@ status_t HwModule::loadDevice(cnode *root) node = node->next; } - ALOGV("loadDevice() adding device name %s type %08x address %s", - deviceDesc->mName.string(), type, deviceDesc->mAddress.string()); + ALOGV("loadDevice() adding device tag %s type %08x address %s", + deviceDesc->mTag.string(), type, deviceDesc->mAddress.string()); mDeclaredDevices.add(deviceDesc); @@ -189,7 +190,7 @@ status_t HwModule::addOutputProfile(String8 name, const audio_config_t *config, profile->mChannelMasks.add(config->channel_mask); profile->mFormats.add(config->format); - sp devDesc = new DeviceDescriptor(name, device); + sp devDesc = new DeviceDescriptor(device); devDesc->mAddress = address; profile->mSupportedDevices.add(devDesc); @@ -220,7 +221,7 @@ status_t HwModule::addInputProfile(String8 name, const audio_config_t *config, profile->mChannelMasks.add(config->channel_mask); profile->mFormats.add(config->format); - sp devDesc = new DeviceDescriptor(name, device); + sp devDesc = new DeviceDescriptor(device); devDesc->mAddress = address; profile->mSupportedDevices.add(devDesc); @@ -350,7 +351,8 @@ sp HwModuleCollection::getDeviceDescriptor(const audio_device } sp devDesc = - new DeviceDescriptor(String8(device_name != NULL ? device_name : ""), device); + new DeviceDescriptor(device); + devDesc->mName = device_name; devDesc->mAddress = address; return devDesc; } -- cgit v1.1