init: switch out keychord id with std::vector match of chords
Drop all references to keychord_id and id and instead use keycodes_
as the id. The keycodes are a std::vector<int> with an unique
sorted-order emplacement method added in the parser. Solves the
academic issue with duplicate keychords and trigger all services
that match rather than first match only.
Test: init_tests
Bug: 64114943
Change-Id: I5582779d81458fda393004c551c0d3c03d9471e0
diff --git a/init/service.cpp b/init/service.cpp
index 5778a93..41188f2 100644
--- a/init/service.cpp
+++ b/init/service.cpp
@@ -229,7 +229,6 @@
seclabel_(seclabel),
onrestart_(false, subcontext_for_restart_commands, "<Service '" + name + "' onrestart>", 0,
"onrestart", {}),
- keychord_id_(0),
ioprio_class_(IoSchedClass_NONE),
ioprio_pri_(0),
priority_(0),
@@ -549,7 +548,7 @@
for (auto& key : keycodes_) {
if (key == code) return Error() << "duplicate keycode: " << args[i];
}
- keycodes_.emplace_back(code);
+ keycodes_.insert(std::upper_bound(keycodes_.begin(), keycodes_.end(), code), code);
} else {
return Error() << "invalid keycode: " << args[i];
}