From d78dd9b184cc700b9a887820056e5ed6a4c0ea56 Mon Sep 17 00:00:00 2001 From: Linnan Li Date: Tue, 15 Oct 2024 15:50:01 +0000 Subject: Copy KeyCharacterMap object when we fill InputDeviceInfo(1/n) Currently, in InputDeviceInfo, we store the KeyCharacterMap object, which is actually the original KeyCharacterMap from the EventHub. This could potentially lead to issues where two threads operate on the same KeyCharacterMap object simultaneously, resulting in thread safety problems. To avoid potential risks in the future, we make a copy of the original KeyCharacterMap when generating InputDeviceInfo. This change should not introduce any behavioral changes. Bug: 373011069 Flag: EXEMPT refactor Test: presubmit Signed-off-by: Linnan Li (cherry picked from https://partner-android-review.googlesource.com/q/commit:1be9c1ce7400e38cf3f45921d7181e947929f91c) Merged-In: I0d0155133f95b0f1dc925422eda0da04c6f196ea Change-Id: I0d0155133f95b0f1dc925422eda0da04c6f196ea --- libs/input/KeyCharacterMap.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'libs/input/KeyCharacterMap.cpp') diff --git a/libs/input/KeyCharacterMap.cpp b/libs/input/KeyCharacterMap.cpp index d775327a80..90d29dd190 100644 --- a/libs/input/KeyCharacterMap.cpp +++ b/libs/input/KeyCharacterMap.cpp @@ -84,15 +84,15 @@ static String8 toString(const char16_t* chars, size_t numChars) { KeyCharacterMap::KeyCharacterMap(const std::string& filename) : mLoadFileName(filename) {} -base::Result> KeyCharacterMap::load(const std::string& filename, +base::Result> KeyCharacterMap::load(const std::string& filename, Format format) { Tokenizer* tokenizer; status_t status = Tokenizer::open(String8(filename.c_str()), &tokenizer); if (status) { return Errorf("Error {} opening key character map file {}.", status, filename.c_str()); } - std::shared_ptr map = - std::shared_ptr(new KeyCharacterMap(filename)); + std::unique_ptr map = + std::unique_ptr(new KeyCharacterMap(filename)); if (!map.get()) { ALOGE("Error allocating key character map."); return Errorf("Error allocating key character map."); -- cgit v1.2.3-59-g8ed1b