Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2014, The Linux Foundation. All rights reserved. |
| 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions are |
| 6 | * met: |
| 7 | * * Redistributions of source code must retain the above copyright |
| 8 | * notice, this list of conditions and the following disclaimer. |
| 9 | * * Redistributions in binary form must reproduce the above |
| 10 | * copyright notice, this list of conditions and the following |
| 11 | * disclaimer in the documentation and/or other materials provided |
| 12 | * with the distribution. |
| 13 | * * Neither the name of The Linux Foundation nor the names of its |
| 14 | * contributors may be used to endorse or promote products derived |
| 15 | * from this software without specific prior written permission. |
| 16 | * |
| 17 | * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED |
| 18 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT |
| 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS |
| 21 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 22 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 23 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| 24 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 25 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE |
| 26 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN |
| 27 | * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 | */ |
| 29 | |
Ben Romberger | 61764e3 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 30 | #define LOG_TAG "platform_info" |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 31 | #define LOG_NDDEBUG 0 |
| 32 | |
| 33 | #include <errno.h> |
| 34 | #include <stdio.h> |
| 35 | #include <expat.h> |
| 36 | #include <cutils/log.h> |
| 37 | #include <audio_hw.h> |
Ben Romberger | 61764e3 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 38 | #include "platform_api.h" |
| 39 | #include <platform.h> |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 40 | |
Ben Romberger | 61764e3 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 41 | #define PLATFORM_INFO_XML_PATH "/system/etc/audio_platform_info.xml" |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 42 | #define BUF_SIZE 1024 |
| 43 | |
Ben Romberger | 61764e3 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 44 | static void process_device(const XML_Char **attr) |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 45 | { |
Ben Romberger | 61764e3 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 46 | int index; |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 47 | |
Ben Romberger | 61764e3 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 48 | if (strcmp(attr[0], "name") != 0) { |
| 49 | ALOGE("%s: 'name' not found, no ACDB ID set!", __func__); |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 50 | goto done; |
Ben Romberger | 61764e3 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 51 | } |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 52 | |
Ben Romberger | 61764e3 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 53 | index = platform_get_snd_device_index((char *)attr[1]); |
| 54 | if (index < 0) { |
| 55 | ALOGE("%s: Device %s in %s not found, no ACDB ID set!", |
| 56 | __func__, attr[1], PLATFORM_INFO_XML_PATH); |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 57 | goto done; |
| 58 | } |
| 59 | |
| 60 | if (strcmp(attr[2], "acdb_id") != 0) { |
Ben Romberger | 61764e3 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 61 | ALOGE("%s: Device %s in %s has no acdb_id, no ACDB ID set!", |
| 62 | __func__, attr[1], PLATFORM_INFO_XML_PATH); |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 63 | goto done; |
| 64 | } |
| 65 | |
Ben Romberger | 61764e3 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 66 | if(platform_set_snd_device_acdb_id(index, atoi((char *)attr[3])) < 0) { |
| 67 | ALOGE("%s: Device %s in %s, ACDB ID %d was not set!", |
| 68 | __func__, attr[1], PLATFORM_INFO_XML_PATH, atoi((char *)attr[3])); |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 69 | goto done; |
Ben Romberger | 61764e3 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 70 | } |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 71 | |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 72 | done: |
| 73 | return; |
| 74 | } |
| 75 | |
| 76 | static void start_tag(void *userdata, const XML_Char *tag_name, |
| 77 | const XML_Char **attr) |
| 78 | { |
| 79 | const XML_Char *attr_name = NULL; |
| 80 | const XML_Char *attr_value = NULL; |
| 81 | unsigned int i; |
| 82 | |
| 83 | if (strcmp(tag_name, "device") == 0) |
Ben Romberger | 61764e3 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 84 | process_device(attr); |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 85 | |
| 86 | return; |
| 87 | } |
| 88 | |
| 89 | static void end_tag(void *userdata, const XML_Char *tag_name) |
| 90 | { |
| 91 | |
| 92 | } |
| 93 | |
| 94 | int platform_info_init(void) |
| 95 | { |
| 96 | XML_Parser parser; |
| 97 | FILE *file; |
| 98 | int ret = 0; |
| 99 | int bytes_read; |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 100 | void *buf; |
| 101 | |
Ben Romberger | 61764e3 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 102 | file = fopen(PLATFORM_INFO_XML_PATH, "r"); |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 103 | if (!file) { |
| 104 | ALOGD("%s: Failed to open %s, using defaults.", |
Ben Romberger | 61764e3 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 105 | __func__, PLATFORM_INFO_XML_PATH); |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 106 | ret = -ENODEV; |
| 107 | goto done; |
| 108 | } |
| 109 | |
| 110 | parser = XML_ParserCreate(NULL); |
| 111 | if (!parser) { |
| 112 | ALOGE("%s: Failed to create XML parser!", __func__); |
| 113 | ret = -ENODEV; |
| 114 | goto err_close_file; |
| 115 | } |
| 116 | |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 117 | XML_SetElementHandler(parser, start_tag, end_tag); |
| 118 | |
| 119 | while (1) { |
| 120 | buf = XML_GetBuffer(parser, BUF_SIZE); |
| 121 | if (buf == NULL) { |
| 122 | ALOGE("%s: XML_GetBuffer failed", __func__); |
| 123 | ret = -ENOMEM; |
| 124 | goto err_free_parser; |
| 125 | } |
| 126 | |
| 127 | bytes_read = fread(buf, 1, BUF_SIZE, file); |
| 128 | if (bytes_read < 0) { |
| 129 | ALOGE("%s: fread failed, bytes read = %d", __func__, bytes_read); |
| 130 | ret = bytes_read; |
| 131 | goto err_free_parser; |
| 132 | } |
| 133 | |
| 134 | if (XML_ParseBuffer(parser, bytes_read, |
| 135 | bytes_read == 0) == XML_STATUS_ERROR) { |
| 136 | ALOGE("%s: XML_ParseBuffer failed, for %s", |
Ben Romberger | 61764e3 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 137 | __func__, PLATFORM_INFO_XML_PATH); |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 138 | ret = -EINVAL; |
| 139 | goto err_free_parser; |
| 140 | } |
| 141 | |
| 142 | if (bytes_read == 0) |
| 143 | break; |
| 144 | } |
| 145 | |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 146 | err_free_parser: |
| 147 | XML_ParserFree(parser); |
| 148 | err_close_file: |
| 149 | fclose(file); |
| 150 | done: |
| 151 | return ret; |
| 152 | } |