diff options
| author | 2019-09-04 13:34:06 -0700 | |
|---|---|---|
| committer | 2019-09-04 13:34:06 -0700 | |
| commit | 9c724d78b9f2e00a7d4de3bfd2c65f6226fa8529 (patch) | |
| tree | a3796f67d19deece6118e60d2faebde9499ce083 /libs/input/VirtualKeyMap.cpp | |
| parent | 0bc2361309d705f8c7f7766f1912fd0f7035d199 (diff) | |
| parent | 638c07856510784987e81ba0b026780850bf5775 (diff) | |
DO NOT MERGE - Merge Android 10 into master
Bug: 139893257
Change-Id: I0b8ce4715e111f1378ddada95d746b1788645a6d
Diffstat (limited to 'libs/input/VirtualKeyMap.cpp')
| -rw-r--r-- | libs/input/VirtualKeyMap.cpp | 59 |
1 files changed, 22 insertions, 37 deletions
diff --git a/libs/input/VirtualKeyMap.cpp b/libs/input/VirtualKeyMap.cpp index 28ea7177cf..865366bcb2 100644 --- a/libs/input/VirtualKeyMap.cpp +++ b/libs/input/VirtualKeyMap.cpp @@ -28,10 +28,6 @@ // Enables debug output for the parser. #define DEBUG_PARSER 0 -// Enables debug output for parser performance. -#define DEBUG_PARSER_PERFORMANCE 0 - - namespace android { static const char* WHITESPACE = " \t\r"; @@ -46,39 +42,28 @@ VirtualKeyMap::VirtualKeyMap() { VirtualKeyMap::~VirtualKeyMap() { } -status_t VirtualKeyMap::load(const String8& filename, VirtualKeyMap** outMap) { - *outMap = NULL; - - Tokenizer* tokenizer; - status_t status = Tokenizer::open(filename, &tokenizer); - if (status) { - ALOGE("Error %d opening virtual key map file %s.", status, filename.string()); - } else { - VirtualKeyMap* map = new VirtualKeyMap(); - if (!map) { - ALOGE("Error allocating virtual key map."); - status = NO_MEMORY; - } else { -#if DEBUG_PARSER_PERFORMANCE - nsecs_t startTime = systemTime(SYSTEM_TIME_MONOTONIC); -#endif - Parser parser(map, tokenizer); - status = parser.parse(); -#if DEBUG_PARSER_PERFORMANCE - nsecs_t elapsedTime = systemTime(SYSTEM_TIME_MONOTONIC) - startTime; - ALOGD("Parsed key character map file '%s' %d lines in %0.3fms.", - tokenizer->getFilename().string(), tokenizer->getLineNumber(), - elapsedTime / 1000000.0); -#endif - if (status) { - delete map; - } else { - *outMap = map; - } - } - delete tokenizer; +std::unique_ptr<VirtualKeyMap> VirtualKeyMap::load(const std::string& filename) { + Tokenizer* t; + status_t status = Tokenizer::open(String8(filename.c_str()), &t); + if (status != OK) { + ALOGE("Error %d opening virtual key map file %s.", status, filename.c_str()); + return nullptr; + } + std::unique_ptr<Tokenizer> tokenizer(t); + // Using 'new' to access a non-public constructor + std::unique_ptr<VirtualKeyMap> map(new VirtualKeyMap()); + if (!map) { + ALOGE("Error allocating virtual key map."); + return nullptr; } - return status; + + Parser parser(map.get(), tokenizer.get()); + status = parser.parse(); + if (status != OK) { + return nullptr; + } + + return map; } @@ -127,7 +112,7 @@ status_t VirtualKeyMap::Parser::parse() { "width=%d, height=%d", defn.scanCode, defn.centerX, defn.centerY, defn.width, defn.height); #endif - mMap->mVirtualKeys.push(defn); + mMap->mVirtualKeys.push_back(defn); } while (consumeFieldDelimiterAndSkipWhitespace()); if (!mTokenizer->isEol()) { |