├── .gitignore ├── Android.mk ├── Makefile ├── README.md ├── acdb_extract.c ├── generate_acdb_data.sh └── get_snd_dev_names.c /.gitignore: -------------------------------------------------------------------------------- 1 | acdb_data.h 2 | -------------------------------------------------------------------------------- /Android.mk: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2017 The LineageOS Project 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | 17 | LOCAL_PATH := $(call my-dir) 18 | 19 | include $(CLEAR_VARS) 20 | 21 | LOCAL_SRC_FILES := acdb_extract.c 22 | 23 | LOCAL_MODULE_TAGS := optional 24 | LOCAL_MODULE := acdb_extract 25 | LOCAL_MODULE_CLASS := EXECUTABLES 26 | 27 | LOCAL_CFLAGS := -Wall -Werror 28 | 29 | LOCAL_32_BIT_ONLY := true 30 | 31 | include $(BUILD_EXECUTABLE) 32 | 33 | include $(CLEAR_VARS) 34 | 35 | LOCAL_SRC_FILES := get_snd_dev_names.c 36 | 37 | LOCAL_MODULE_TAGS := optional 38 | LOCAL_MODULE := get_snd_dev_names 39 | LOCAL_MODULE_CLASS := EXECUTABLES 40 | 41 | LOCAL_CFLAGS := -Wall -Werror 42 | 43 | LOCAL_32_BIT_ONLY := true 44 | 45 | include $(BUILD_EXECUTABLE) 46 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | all: acdb_extract get_snd_dev_names 2 | 3 | acdb_extract: acdb_extract.o 4 | gcc -Wall -g -o acdb_extract $^ 5 | 6 | get_snd_dev_names: get_snd_dev_names.o 7 | gcc -Wall -g -o get_snd_dev_names -ldl $^ 8 | 9 | %.o : %.c acdb_data.h 10 | gcc -Wall -g -c $< 11 | 12 | clean: 13 | rm -f *.o acdb_extract get_snd_dev_names 14 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | acdb_extract 2 | ======== 3 | 4 | This program searches for and and dumps the acdb table from the audio HAL. 5 | 6 | This program should be able to work with any audio HAL which uses the standard acdb 7 | table format (i.e, first entry is always -1, values are ints, etc) whether the 8 | hal lib has the `platform_get_snd_device_acdb_id()` function or not since it does 9 | not use that to extract the acdb table. 10 | 11 | The program does not have to be built and pushed to an android device. It can be built 12 | and used on any system (in theory). 13 | 14 | 0. Generate the acdb_data header 15 | -> ./generate_acdb_data.sh $stock_audio_hal.so 16 | 0. Use `make acdb_extract` to make the binary. 17 | 0. Run `./acdb_extract [path to audio hal] > acdb_table.txt` to save the table in `acdb_table.txt`. 18 | 0. Enjoy your acdb table 19 | 20 | get_snd_dev_names 21 | ================= 22 | 23 | This program fetches the true sound device names from the audio HAL using `dlopen()` and `dlsym()` to 24 | run `platform_get_snd_device_name()` in the audio HAL. 25 | 26 | This *will* have to be built using the android toolchain and pushed to an android device. 27 | 28 | 0. Generate the acdb_data header 29 | -> ./generate_acdb_data.sh $stock_audio_hal.so 30 | 0. Clone the repo and use the android toolchain to make the binary. 31 | 0. Run `./get_snd_dev_names [path to audio hal] > device_names.h` to save the table in `device_names.h`. 32 | -------------------------------------------------------------------------------- /acdb_extract.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #include "acdb_data.h" 12 | 13 | #define TABLE_SIZE (SND_DEVICE_MAX * sizeof(int)) 14 | 15 | int main(int argc, char** argv) { 16 | 17 | int *acdb_device_table; 18 | 19 | int max_acdb_id = 1000; 20 | 21 | struct stat stat_buf; 22 | 23 | /* check args */ 24 | if (argc < 2) { 25 | printf("%s: [audio hal path] [max_acdb_id]\n", argv[0]); 26 | exit(1); 27 | } 28 | 29 | /* get the max acdb_id allowed if any */ 30 | if (argc > 2) { 31 | max_acdb_id = strtol(argv[2], NULL, 10); 32 | } 33 | 34 | /* open the audio hal file */ 35 | int fd = open(argv[1], O_RDONLY); 36 | if (fd < 0) { 37 | perror("open"); 38 | exit(1); 39 | } 40 | 41 | /* get the file stats */ 42 | if (fstat(fd, &stat_buf) < 0) { 43 | perror("stat"); 44 | exit(1); 45 | } 46 | 47 | /* mmap the file to memory */ 48 | char * hal_file = mmap(0, stat_buf.st_size, PROT_READ, MAP_PRIVATE, fd, 0); 49 | if (hal_file == MAP_FAILED) { 50 | perror("mmap"); 51 | exit(1); 52 | } 53 | 54 | /* pointers to beginning of table and end of file */ 55 | char * curr = hal_file; 56 | char * end = hal_file + stat_buf.st_size - 1; 57 | 58 | int i; 59 | 60 | /* go through the whole file every SND_DEVICE_MAX*4 bytes */ 61 | while((curr+TABLE_SIZE) < end) { 62 | 63 | acdb_device_table = (int*)curr; 64 | 65 | /* verify that the first entry is -1 */ 66 | if (acdb_device_table[SND_DEVICE_NONE] != -1) { 67 | goto next; 68 | } 69 | 70 | for (i = 1; i < SND_DEVICE_MAX; i++) { 71 | //if ((acdb_device_table[i] < 0) || (acdb_device_table[i] > max_acdb_id)) goto next; 72 | if (acdb_device_table[i] > max_acdb_id) goto next; 73 | } 74 | 75 | /* print the table */ 76 | printf("\t\n"); 77 | for (i = 1; i < SND_DEVICE_MAX; i++) 78 | printf("\t\t\n", faux_device_table[i], acdb_device_table[i]); 79 | printf("\t\n"); 80 | 81 | next: 82 | /*advance to the next byte in the file */ 83 | curr = curr + 1; 84 | } 85 | 86 | return 0; 87 | } 88 | -------------------------------------------------------------------------------- /generate_acdb_data.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [ ! -f $1 ]; then 4 | echo "You need to specify the target lib" 5 | exit 1 6 | fi 7 | 8 | devices=`strings $1 | egrep "^(SND_DEVICE_OUT|SND_DEVICE_IN)"` 9 | 10 | echo -ne "" > acdb_data.h 11 | 12 | echo "enum {" >> acdb_data.h 13 | echo " SND_DEVICE_NONE = 0," >> acdb_data.h 14 | 15 | for device in $devices; do 16 | echo " $device," >> acdb_data.h 17 | done 18 | 19 | echo " SND_DEVICE_MAX," >> acdb_data.h 20 | echo "};" >> acdb_data.h 21 | 22 | echo >> acdb_data.h 23 | 24 | echo "static char * faux_device_table[SND_DEVICE_MAX] = {" >> acdb_data.h 25 | echo " [SND_DEVICE_NONE] = \"SND_DEVICE_NONE\"," >> acdb_data.h 26 | for device in $devices; do 27 | echo " [$device] = \"$device\"," >> acdb_data.h 28 | done 29 | echo "};" >> acdb_data.h 30 | -------------------------------------------------------------------------------- /get_snd_dev_names.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include "acdb_data.h" 6 | 7 | typedef char* (*platform_get_snd_device_name_t)(int); 8 | 9 | int main(int argc, char** argv) { 10 | void *handle; 11 | platform_get_snd_device_name_t platform_get_snd_device_name; 12 | 13 | if (argc != 2) { 14 | printf("%s: [audio hal path]\n", argv[0]); 15 | exit(1); 16 | } 17 | 18 | handle = dlopen(argv[1], RTLD_LAZY); 19 | if (!handle) { 20 | fprintf(stderr, "%s\n", dlerror()); 21 | return 1; 22 | } 23 | 24 | platform_get_snd_device_name = (platform_get_snd_device_name_t) dlsym(handle, "platform_get_snd_device_name"); 25 | 26 | if (!platform_get_snd_device_name) { 27 | fprintf(stderr, "%s\n", dlerror()); 28 | return 1; 29 | } 30 | 31 | printf("static char * device_table[SND_DEVICE_MAX] = {\n"); 32 | int dev; 33 | for (dev = 0; dev < SND_DEVICE_MAX; dev++) 34 | printf("\t[%s] = \"%s\",\n", faux_device_table[dev], platform_get_snd_device_name(dev)); 35 | printf("};\n"); 36 | 37 | dlclose(handle); 38 | return 0; 39 | } 40 | --------------------------------------------------------------------------------