From 6ec6f79e1ac1714e3b837796e99f07ff88f66601 Mon Sep 17 00:00:00 2001 From: Jeff Brown Date: Tue, 17 Apr 2012 16:52:41 -0700 Subject: Support loading keyboard layout overlays from resources. Added the concept of a keyboard layout overlay, which is a key character map file that has "type OVERLAY". Added support for loading keyboard layout overlays from resources dynamically. The layouts are reloaded whenever they are changed in the Settings application or an application is installed. This is somewhat more aggressive than necessary so we might want to optimize it later. Before system-ready, the input system uses just the generic keyboard layouts that are included on the device system image. After system-ready, it considers the user's selected keyboard layout overlay and attempts to load it as necessary. We need to wait until system-ready before doing this because we need to be in a state where it is safe to start applications or access their resources. Bug: 6110399 Change-Id: Iae0886d3356649b0d2440aa00910a888cedd8323 --- include/androidfw/KeyCharacterMap.h | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/androidfw/KeyCharacterMap.h b/include/androidfw/KeyCharacterMap.h index 3cc1cb2..e0e6ffa 100644 --- a/include/androidfw/KeyCharacterMap.h +++ b/include/androidfw/KeyCharacterMap.h @@ -49,6 +49,17 @@ public: KEYBOARD_TYPE_ALPHA = 3, KEYBOARD_TYPE_FULL = 4, KEYBOARD_TYPE_SPECIAL_FUNCTION = 5, + KEYBOARD_TYPE_OVERLAY = 6, + }; + + enum Format { + // Base keyboard layout, may contain device-specific options, such as "type" declaration. + FORMAT_BASE = 0, + // Overlay keyboard layout, more restrictive, may be published by applications, + // cannot override device-specific options. + FORMAT_OVERLAY = 1, + // Either base or overlay layout ok. + FORMAT_ANY = 2, }; // Substitute key code and meta state for fallback action. @@ -58,7 +69,15 @@ public: }; /* Loads a key character map from a file. */ - static status_t load(const String8& filename, sp* outMap); + static status_t load(const String8& filename, Format format, sp* outMap); + + /* Loads a key character map from its string contents. */ + static status_t loadContents(const String8& filename, + const char* contents, Format format, sp* outMap); + + /* Combines a base key character map and an overlay. */ + static sp combine(const sp& base, + const sp& overlay); /* Returns an empty key character map. */ static sp empty(); @@ -115,6 +134,7 @@ protected: private: struct Behavior { Behavior(); + Behavior(const Behavior& other); /* The next behavior in the list, or NULL if none. */ Behavior* next; @@ -131,6 +151,7 @@ private: struct Key { Key(); + Key(const Key& other); ~Key(); /* The single character label printed on the key, or 0 if none. */ @@ -166,11 +187,12 @@ private: KeyCharacterMap* mMap; Tokenizer* mTokenizer; + Format mFormat; State mState; int32_t mKeyCode; public: - Parser(KeyCharacterMap* map, Tokenizer* tokenizer); + Parser(KeyCharacterMap* map, Tokenizer* tokenizer, Format format); ~Parser(); status_t parse(); @@ -188,6 +210,7 @@ private: int mType; KeyCharacterMap(); + KeyCharacterMap(const KeyCharacterMap& other); bool getKey(int32_t keyCode, const Key** outKey) const; bool getKeyBehavior(int32_t keyCode, int32_t metaState, @@ -195,6 +218,8 @@ private: bool findKey(char16_t ch, int32_t* outKeyCode, int32_t* outMetaState) const; + static status_t load(Tokenizer* tokenizer, Format format, sp* outMap); + static void addKey(Vector& outEvents, int32_t deviceId, int32_t keyCode, int32_t metaState, bool down, nsecs_t time); static void addMetaKeys(Vector& outEvents, -- cgit v1.1