From 9f25b7fdf216c9ef0bd2322cd223eeaf0d60f77f Mon Sep 17 00:00:00 2001 From: Jeff Brown Date: Tue, 10 Apr 2012 14:30:49 -0700 Subject: Request key maps from input manager service. Instead of each application loading the KeyCharacterMap from the file system, get them from the input manager service as part of the InputDevice object. Refactored InputManager to be a proper singleton instead of having a bunch of static methods. InputManager now maintains a cache of all InputDevice objects that it has loaded. Currently we never invalidate the cache which can cause InputDevice to return stale motion ranges if the device is reconfigured. This will be fixed in a future change. Added a fake InputDevice with ID -1 to represent the virtual keyboard. Change-Id: If7a695839ad0972317a5aab89e9d1e42ace28eb7 --- libs/androidfw/KeyLayoutMap.cpp | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'libs/androidfw/KeyLayoutMap.cpp') diff --git a/libs/androidfw/KeyLayoutMap.cpp b/libs/androidfw/KeyLayoutMap.cpp index 15d81ee2ed74..1809412ee56f 100644 --- a/libs/androidfw/KeyLayoutMap.cpp +++ b/libs/androidfw/KeyLayoutMap.cpp @@ -47,23 +47,23 @@ KeyLayoutMap::KeyLayoutMap() { KeyLayoutMap::~KeyLayoutMap() { } -status_t KeyLayoutMap::load(const String8& filename, KeyLayoutMap** outMap) { - *outMap = NULL; +status_t KeyLayoutMap::load(const String8& filename, sp* outMap) { + outMap->clear(); Tokenizer* tokenizer; status_t status = Tokenizer::open(filename, &tokenizer); if (status) { ALOGE("Error %d opening key layout map file %s.", status, filename.string()); } else { - KeyLayoutMap* map = new KeyLayoutMap(); - if (!map) { + sp map = new KeyLayoutMap(); + if (!map.get()) { ALOGE("Error allocating key layout map."); status = NO_MEMORY; } else { #if DEBUG_PARSER_PERFORMANCE nsecs_t startTime = systemTime(SYSTEM_TIME_MONOTONIC); #endif - Parser parser(map, tokenizer); + Parser parser(map.get(), tokenizer); status = parser.parse(); #if DEBUG_PARSER_PERFORMANCE nsecs_t elapsedTime = systemTime(SYSTEM_TIME_MONOTONIC) - startTime; @@ -71,9 +71,7 @@ status_t KeyLayoutMap::load(const String8& filename, KeyLayoutMap** outMap) { tokenizer->getFilename().string(), tokenizer->getLineNumber(), elapsedTime / 1000000.0); #endif - if (status) { - delete map; - } else { + if (!status) { *outMap = map; } } -- cgit v1.2.3-59-g8ed1b