Skip to content

Commit c2e6966

Browse files
Jooyung HanGerrit Code Review
authored andcommitted
Merge "Do not use hard-coded apex name" into main
2 parents ddf0e82 + 70932db commit c2e6966

1 file changed

Lines changed: 17 additions & 14 deletions

File tree

libs/input/InputDevice.cpp

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@
2020
#include <unistd.h>
2121
#include <ctype.h>
2222

23+
#include <android-base/properties.h>
2324
#include <android-base/stringprintf.h>
2425
#include <ftl/enum.h>
2526
#include <gui/constants.h>
2627
#include <input/InputDevice.h>
2728
#include <input/InputEventLabels.h>
2829

30+
using android::base::GetProperty;
2931
using android::base::StringPrintf;
3032

3133
namespace android {
@@ -96,21 +98,22 @@ std::string getInputDeviceConfigurationFilePathByName(
9698

9799
// Treblized input device config files will be located /product/usr, /system_ext/usr,
98100
// /odm/usr or /vendor/usr.
99-
// These files may also be in the com.android.input.config APEX.
100-
const char* rootsForPartition[]{
101-
"/product",
102-
"/system_ext",
103-
"/odm",
104-
"/vendor",
105-
"/apex/com.android.input.config/etc",
106-
getenv("ANDROID_ROOT"),
101+
std::vector<std::string> pathPrefixes{
102+
"/product/usr/",
103+
"/system_ext/usr/",
104+
"/odm/usr/",
105+
"/vendor/usr/",
107106
};
108-
for (size_t i = 0; i < size(rootsForPartition); i++) {
109-
if (rootsForPartition[i] == nullptr) {
110-
continue;
111-
}
112-
path = rootsForPartition[i];
113-
path += "/usr/";
107+
// These files may also be in the APEX pointed by input_device.config_file.apex sysprop.
108+
if (auto apex = GetProperty("input_device.config_file.apex", ""); !apex.empty()) {
109+
pathPrefixes.push_back("/apex/" + apex + "/etc/usr/");
110+
}
111+
// ANDROID_ROOT may not be set on host
112+
if (auto android_root = getenv("ANDROID_ROOT"); android_root != nullptr) {
113+
pathPrefixes.push_back(std::string(android_root) + "/usr/");
114+
}
115+
for (const auto& prefix : pathPrefixes) {
116+
path = prefix;
114117
appendInputDeviceConfigurationFileRelativePath(path, name, type);
115118
#if DEBUG_PROBE
116119
ALOGD("Probing for system provided input device configuration file: path='%s'",

0 commit comments

Comments
 (0)