android输入设备配置文件搜索路径

来源:互联网 发布:java搞笑程序 编辑:程序博客网 时间:2024/04/29 13:11

frameworks/base/libs/ui/Input.cpp:

String8 getInputDeviceConfigurationFilePathByName(        const String8& name, InputDeviceConfigurationFileType type) {    // Search system repository.    String8 path;    path.setTo(getenv("ANDROID_ROOT"));//先搜索system目录    path.append("/usr/");    appendInputDeviceConfigurationFileRelativePath(path, name, type);//这里会根据文件类型不同添加一些前缀和后缀#if DEBUG_PROBE    LOGD("Probing for system provided input device configuration file: path='%s'", path.string());#endif    if (!access(path.string(), R_OK)) {#if DEBUG_PROBE        LOGD("Found");#endif        return path;    }    // Search user repository.    // TODO Should only look here if not in safe mode.    path.setTo(getenv("ANDROID_DATA"));//再搜索data目录    path.append("/system/devices/");    appendInputDeviceConfigurationFileRelativePath(path, name, type);#if DEBUG_PROBE    LOGD("Probing for system user input device configuration file: path='%s'", path.string());#endif    if (!access(path.string(), R_OK)) {#if DEBUG_PROBE        LOGD("Found");#endif        return path;    }    // Not found.#if DEBUG_PROBE    LOGD("Probe failed to find input device configuration file: name='%s', type=%d",            name.string(), type);#endif    return String8();}

static void appendInputDeviceConfigurationFileRelativePath(String8& path,        const String8& name, InputDeviceConfigurationFileType type) {    path.append(CONFIGURATION_FILE_DIR[type]);//全局变量定义了配置文件目录    for (size_t i = 0; i < name.length(); i++) {        char ch = name[i];        if (!isValidNameChar(ch)) {            ch = '_';        }        path.append(&ch, 1);    }    path.append(CONFIGURATION_FILE_EXTENSION[type]);//各种配置文件后缀}

static const char* CONFIGURATION_FILE_DIR[] = {        "idc/",        "keylayout/",        "keychars/",};static const char* CONFIGURATION_FILE_EXTENSION[] = {        ".idc",        ".kl",        ".kcm",};

根据配置文件类型不同,搜索路径会有不同。但每种配置文件都会在system/usr/和data/system/devices/两个目录下搜索相应类型文件。