diff options
author | 2020-08-12 10:13:15 -0700 | |
---|---|---|
committer | 2020-08-28 22:39:47 -0700 | |
commit | 3a1e446866d905223e731cf1319f41152cd629c3 (patch) | |
tree | 164bd13d0aaa6f72691d2c130b7f2f990c8bfe4b | |
parent | 1abffbd101f77f100789dc7fb8b33f729bb64dc9 (diff) |
Move KeyCharacterMap from RefBase to shared_ptr.
Move KeyCharacterMap from RefBase and make it shared_ptr in EventHub
device when loaded from file.
A shared_ptr of KeyCharacterMap is returned by EventHub getKeyCharacterMap
to be shared in InputdeviceInfo.
Remove extra KeyCharacterMap in EventHub to save memory sapce.
Bug: 160010896
Test: atest inputflinger, atest libinput_tests
Change-Id: Ibb317ea0684e6af6e7a6d808f816fc4a05c7b421
-rw-r--r-- | include/input/InputDevice.h | 6 | ||||
-rw-r--r-- | include/input/KeyCharacterMap.h | 31 | ||||
-rw-r--r-- | include/input/Keyboard.h | 2 | ||||
-rw-r--r-- | libs/input/InputDevice.cpp | 22 | ||||
-rw-r--r-- | libs/input/KeyCharacterMap.cpp | 134 | ||||
-rw-r--r-- | libs/input/Keyboard.cpp | 10 | ||||
-rw-r--r-- | services/inputflinger/include/InputReaderBase.h | 2 | ||||
-rw-r--r-- | services/inputflinger/reader/EventHub.cpp | 27 | ||||
-rw-r--r-- | services/inputflinger/reader/InputDevice.cpp | 2 | ||||
-rw-r--r-- | services/inputflinger/reader/include/EventHub.h | 16 | ||||
-rw-r--r-- | services/inputflinger/reader/include/InputDevice.h | 4 | ||||
-rw-r--r-- | services/inputflinger/tests/InputReader_test.cpp | 7 |
12 files changed, 130 insertions, 133 deletions
diff --git a/include/input/InputDevice.h b/include/input/InputDevice.h index c7685b7c13..60638caaab 100644 --- a/include/input/InputDevice.h +++ b/include/input/InputDevice.h @@ -108,11 +108,11 @@ public: inline void setKeyboardType(int32_t keyboardType) { mKeyboardType = keyboardType; } inline int32_t getKeyboardType() const { return mKeyboardType; } - inline void setKeyCharacterMap(const sp<KeyCharacterMap>& value) { + inline void setKeyCharacterMap(const std::shared_ptr<KeyCharacterMap> value) { mKeyCharacterMap = value; } - inline sp<KeyCharacterMap> getKeyCharacterMap() const { + inline const std::shared_ptr<KeyCharacterMap> getKeyCharacterMap() const { return mKeyCharacterMap; } @@ -136,7 +136,7 @@ private: bool mHasMic; uint32_t mSources; int32_t mKeyboardType; - sp<KeyCharacterMap> mKeyCharacterMap; + std::shared_ptr<KeyCharacterMap> mKeyCharacterMap; bool mHasVibrator; bool mHasButtonUnderPad; diff --git a/include/input/KeyCharacterMap.h b/include/input/KeyCharacterMap.h index a1a32a63de..d874347929 100644 --- a/include/input/KeyCharacterMap.h +++ b/include/input/KeyCharacterMap.h @@ -23,12 +23,12 @@ #include <binder/IBinder.h> #endif +#include <android-base/result.h> #include <input/Input.h> #include <utils/Errors.h> #include <utils/KeyedVector.h> #include <utils/Tokenizer.h> #include <utils/Unicode.h> -#include <utils/RefBase.h> // Maximum number of keys supported by KeyCharacterMaps #define MAX_KEYS 8192 @@ -42,7 +42,7 @@ namespace android { * * This object is immutable after it has been loaded. */ -class KeyCharacterMap : public RefBase { +class KeyCharacterMap { public: enum KeyboardType { KEYBOARD_TYPE_UNKNOWN = 0, @@ -74,18 +74,18 @@ public: }; /* Loads a key character map from a file. */ - static status_t load(const std::string& filename, Format format, sp<KeyCharacterMap>* outMap); + static base::Result<std::shared_ptr<KeyCharacterMap>> load(const std::string& filename, + Format format); /* Loads a key character map from its string contents. */ - static status_t loadContents(const std::string& filename, - const char* contents, Format format, sp<KeyCharacterMap>* outMap); + static base::Result<std::shared_ptr<KeyCharacterMap>> loadContents(const std::string& filename, + const char* contents, + Format format); - /* Combines a base key character map and an overlay. */ - static sp<KeyCharacterMap> combine(const sp<KeyCharacterMap>& base, - const sp<KeyCharacterMap>& overlay); + const std::string getLoadFileName() const; - /* Returns an empty key character map. */ - static sp<KeyCharacterMap> empty(); + /* Combines this key character map with an overlay. */ + void combine(const KeyCharacterMap& overlay); /* Gets the keyboard type. */ int32_t getKeyboardType() const; @@ -136,13 +136,14 @@ public: #ifdef __ANDROID__ /* Reads a key map from a parcel. */ - static sp<KeyCharacterMap> readFromParcel(Parcel* parcel); + static std::shared_ptr<KeyCharacterMap> readFromParcel(Parcel* parcel); /* Writes a key map to a parcel. */ void writeToParcel(Parcel* parcel) const; #endif -protected: + KeyCharacterMap(const KeyCharacterMap& other); + virtual ~KeyCharacterMap(); private: @@ -224,16 +225,14 @@ private: status_t parseCharacterLiteral(char16_t* outCharacter); }; - static sp<KeyCharacterMap> sEmpty; - KeyedVector<int32_t, Key*> mKeys; int mType; + std::string mLoadFileName; KeyedVector<int32_t, int32_t> mKeysByScanCode; KeyedVector<int32_t, int32_t> mKeysByUsageCode; KeyCharacterMap(); - KeyCharacterMap(const KeyCharacterMap& other); bool getKey(int32_t keyCode, const Key** outKey) const; bool getKeyBehavior(int32_t keyCode, int32_t metaState, @@ -242,7 +241,7 @@ private: bool findKey(char16_t ch, int32_t* outKeyCode, int32_t* outMetaState) const; - static status_t load(Tokenizer* tokenizer, Format format, sp<KeyCharacterMap>* outMap); + static base::Result<std::shared_ptr<KeyCharacterMap>> load(Tokenizer* tokenizer, Format format); static void addKey(Vector<KeyEvent>& outEvents, int32_t deviceId, int32_t keyCode, int32_t metaState, bool down, nsecs_t time); diff --git a/include/input/Keyboard.h b/include/input/Keyboard.h index 4c56a694b4..2ae4fd564e 100644 --- a/include/input/Keyboard.h +++ b/include/input/Keyboard.h @@ -37,7 +37,7 @@ public: std::shared_ptr<KeyLayoutMap> keyLayoutMap; std::string keyCharacterMapFile; - sp<KeyCharacterMap> keyCharacterMap; + std::shared_ptr<KeyCharacterMap> keyCharacterMap; KeyMap(); ~KeyMap(); diff --git a/libs/input/InputDevice.cpp b/libs/input/InputDevice.cpp index dbd6293a64..34eba5be7f 100644 --- a/libs/input/InputDevice.cpp +++ b/libs/input/InputDevice.cpp @@ -153,14 +153,20 @@ InputDeviceInfo::InputDeviceInfo() { initialize(-1, 0, -1, InputDeviceIdentifier(), "", false, false); } -InputDeviceInfo::InputDeviceInfo(const InputDeviceInfo& other) : - mId(other.mId), mGeneration(other.mGeneration), mControllerNumber(other.mControllerNumber), - mIdentifier(other.mIdentifier), mAlias(other.mAlias), mIsExternal(other.mIsExternal), - mHasMic(other.mHasMic), mSources(other.mSources), - mKeyboardType(other.mKeyboardType), mKeyCharacterMap(other.mKeyCharacterMap), - mHasVibrator(other.mHasVibrator), mHasButtonUnderPad(other.mHasButtonUnderPad), - mMotionRanges(other.mMotionRanges) { -} +InputDeviceInfo::InputDeviceInfo(const InputDeviceInfo& other) + : mId(other.mId), + mGeneration(other.mGeneration), + mControllerNumber(other.mControllerNumber), + mIdentifier(other.mIdentifier), + mAlias(other.mAlias), + mIsExternal(other.mIsExternal), + mHasMic(other.mHasMic), + mSources(other.mSources), + mKeyboardType(other.mKeyboardType), + mKeyCharacterMap(other.mKeyCharacterMap), + mHasVibrator(other.mHasVibrator), + mHasButtonUnderPad(other.mHasButtonUnderPad), + mMotionRanges(other.mMotionRanges) {} InputDeviceInfo::~InputDeviceInfo() { } diff --git a/libs/input/KeyCharacterMap.cpp b/libs/input/KeyCharacterMap.cpp index 5c03d50fbc..fd35131b6b 100644 --- a/libs/input/KeyCharacterMap.cpp +++ b/libs/input/KeyCharacterMap.cpp @@ -85,15 +85,14 @@ static String8 toString(const char16_t* chars, size_t numChars) { // --- KeyCharacterMap --- -sp<KeyCharacterMap> KeyCharacterMap::sEmpty = new KeyCharacterMap(); - KeyCharacterMap::KeyCharacterMap() : mType(KEYBOARD_TYPE_UNKNOWN) { } -KeyCharacterMap::KeyCharacterMap(const KeyCharacterMap& other) : - RefBase(), mType(other.mType), mKeysByScanCode(other.mKeysByScanCode), - mKeysByUsageCode(other.mKeysByUsageCode) { +KeyCharacterMap::KeyCharacterMap(const KeyCharacterMap& other) + : mType(other.mType), + mKeysByScanCode(other.mKeysByScanCode), + mKeysByUsageCode(other.mKeysByUsageCode) { for (size_t i = 0; i < other.mKeys.size(); i++) { mKeys.add(other.mKeys.keyAt(i), new Key(*other.mKeys.valueAt(i))); } @@ -106,104 +105,95 @@ KeyCharacterMap::~KeyCharacterMap() { } } -status_t KeyCharacterMap::load(const std::string& filename, - Format format, sp<KeyCharacterMap>* outMap) { - outMap->clear(); - +base::Result<std::shared_ptr<KeyCharacterMap>> KeyCharacterMap::load(const std::string& filename, + Format format) { Tokenizer* tokenizer; status_t status = Tokenizer::open(String8(filename.c_str()), &tokenizer); if (status) { - ALOGE("Error %d opening key character map file %s.", status, filename.c_str()); - } else { - status = load(tokenizer, format, outMap); - delete tokenizer; + return Errorf("Error {} opening key character map file {}.", status, filename.c_str()); } - return status; + std::unique_ptr<Tokenizer> t(tokenizer); + auto ret = load(t.get(), format); + if (ret) { + (*ret)->mLoadFileName = filename; + } + return ret; } -status_t KeyCharacterMap::loadContents(const std::string& filename, const char* contents, - Format format, sp<KeyCharacterMap>* outMap) { - outMap->clear(); - +base::Result<std::shared_ptr<KeyCharacterMap>> KeyCharacterMap::loadContents( + const std::string& filename, const char* contents, Format format) { Tokenizer* tokenizer; status_t status = Tokenizer::fromContents(String8(filename.c_str()), contents, &tokenizer); if (status) { ALOGE("Error %d opening key character map.", status); - } else { - status = load(tokenizer, format, outMap); - delete tokenizer; + return Errorf("Error {} opening key character map.", status); } - return status; + std::unique_ptr<Tokenizer> t(tokenizer); + auto ret = load(t.get(), format); + if (ret) { + (*ret)->mLoadFileName = filename; + } + return ret; } -status_t KeyCharacterMap::load(Tokenizer* tokenizer, - Format format, sp<KeyCharacterMap>* outMap) { +base::Result<std::shared_ptr<KeyCharacterMap>> KeyCharacterMap::load(Tokenizer* tokenizer, + Format format) { status_t status = OK; - sp<KeyCharacterMap> map = new KeyCharacterMap(); + std::shared_ptr<KeyCharacterMap> map = std::shared_ptr<KeyCharacterMap>(new KeyCharacterMap()); if (!map.get()) { ALOGE("Error allocating key character map."); - status = NO_MEMORY; - } else { + return Errorf("Error allocating key character map."); + } #if DEBUG_PARSER_PERFORMANCE - nsecs_t startTime = systemTime(SYSTEM_TIME_MONOTONIC); + nsecs_t startTime = systemTime(SYSTEM_TIME_MONOTONIC); #endif - Parser parser(map.get(), tokenizer, format); - status = parser.parse(); + Parser parser(map.get(), tokenizer, format); + 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); + 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) { - *outMap = map; - } + if (status == OK) { + return map; } - return status; -} -sp<KeyCharacterMap> KeyCharacterMap::combine(const sp<KeyCharacterMap>& base, - const sp<KeyCharacterMap>& overlay) { - if (overlay == nullptr) { - return base; - } - if (base == nullptr) { - return overlay; - } + return Errorf("Load KeyCharacterMap failed {}.", status); +} - sp<KeyCharacterMap> map = new KeyCharacterMap(*base.get()); - for (size_t i = 0; i < overlay->mKeys.size(); i++) { - int32_t keyCode = overlay->mKeys.keyAt(i); - Key* key = overlay->mKeys.valueAt(i); - ssize_t oldIndex = map->mKeys.indexOfKey(keyCode); +void KeyCharacterMap::combine(const KeyCharacterMap& overlay) { + for (size_t i = 0; i < overlay.mKeys.size(); i++) { + int32_t keyCode = overlay.mKeys.keyAt(i); + Key* key = overlay.mKeys.valueAt(i); + ssize_t oldIndex = mKeys.indexOfKey(keyCode); if (oldIndex >= 0) { - delete map->mKeys.valueAt(oldIndex); - map->mKeys.editValueAt(oldIndex) = new Key(*key); + delete mKeys.valueAt(oldIndex); + mKeys.editValueAt(oldIndex) = new Key(*key); } else { - map->mKeys.add(keyCode, new Key(*key)); + mKeys.add(keyCode, new Key(*key)); } } - for (size_t i = 0; i < overlay->mKeysByScanCode.size(); i++) { - map->mKeysByScanCode.replaceValueFor(overlay->mKeysByScanCode.keyAt(i), - overlay->mKeysByScanCode.valueAt(i)); + for (size_t i = 0; i < overlay.mKeysByScanCode.size(); i++) { + mKeysByScanCode.replaceValueFor(overlay.mKeysByScanCode.keyAt(i), + overlay.mKeysByScanCode.valueAt(i)); } - for (size_t i = 0; i < overlay->mKeysByUsageCode.size(); i++) { - map->mKeysByUsageCode.replaceValueFor(overlay->mKeysByUsageCode.keyAt(i), - overlay->mKeysByUsageCode.valueAt(i)); + for (size_t i = 0; i < overlay.mKeysByUsageCode.size(); i++) { + mKeysByUsageCode.replaceValueFor(overlay.mKeysByUsageCode.keyAt(i), + overlay.mKeysByUsageCode.valueAt(i)); } - return map; -} - -sp<KeyCharacterMap> KeyCharacterMap::empty() { - return sEmpty; + mLoadFileName = overlay.mLoadFileName; } int32_t KeyCharacterMap::getKeyboardType() const { return mType; } +const std::string KeyCharacterMap::getLoadFileName() const { + return mLoadFileName; +} + char16_t KeyCharacterMap::getDisplayLabel(int32_t keyCode) const { char16_t result = 0; const Key* key; @@ -600,8 +590,12 @@ void KeyCharacterMap::addLockedMetaKey(Vector<KeyEvent>& outEvents, } #ifdef __ANDROID__ -sp<KeyCharacterMap> KeyCharacterMap::readFromParcel(Parcel* parcel) { - sp<KeyCharacterMap> map = new KeyCharacterMap(); +std::shared_ptr<KeyCharacterMap> KeyCharacterMap::readFromParcel(Parcel* parcel) { + if (parcel == nullptr) { + ALOGE("%s: Null parcel", __func__); + return nullptr; + } + std::shared_ptr<KeyCharacterMap> map = std::shared_ptr<KeyCharacterMap>(new KeyCharacterMap()); map->mType = parcel->readInt32(); size_t numKeys = parcel->readInt32(); if (parcel->errorCheck()) { @@ -656,6 +650,10 @@ sp<KeyCharacterMap> KeyCharacterMap::readFromParcel(Parcel* parcel) { } void KeyCharacterMap::writeToParcel(Parcel* parcel) const { + if (parcel == nullptr) { + ALOGE("%s: Null parcel", __func__); + return; + } parcel->writeInt32(mType); size_t numKeys = mKeys.size(); diff --git a/libs/input/Keyboard.cpp b/libs/input/Keyboard.cpp index 1a64a9ca1e..38a68b3884 100644 --- a/libs/input/Keyboard.cpp +++ b/libs/input/Keyboard.cpp @@ -127,12 +127,12 @@ status_t KeyMap::loadKeyCharacterMap(const InputDeviceIdentifier& deviceIdentifi return NAME_NOT_FOUND; } - status_t status = KeyCharacterMap::load(path, - KeyCharacterMap::FORMAT_BASE, &keyCharacterMap); - if (status) { - return status; + base::Result<std::shared_ptr<KeyCharacterMap>> ret = + KeyCharacterMap::load(path, KeyCharacterMap::FORMAT_BASE); + if (!ret) { + return ret.error().code(); } - + keyCharacterMap = *ret; keyCharacterMapFile = path; return OK; } diff --git a/services/inputflinger/include/InputReaderBase.h b/services/inputflinger/include/InputReaderBase.h index a24b293c17..573524e708 100644 --- a/services/inputflinger/include/InputReaderBase.h +++ b/services/inputflinger/include/InputReaderBase.h @@ -341,7 +341,7 @@ public: virtual void notifyInputDevicesChanged(const std::vector<InputDeviceInfo>& inputDevices) = 0; /* Gets the keyboard layout for a particular input device. */ - virtual sp<KeyCharacterMap> getKeyboardLayoutOverlay( + virtual std::shared_ptr<KeyCharacterMap> getKeyboardLayoutOverlay( const InputDeviceIdentifier& identifier) = 0; /* Gets a user-supplied alias for a particular input device, or an empty string if none. */ diff --git a/services/inputflinger/reader/EventHub.cpp b/services/inputflinger/reader/EventHub.cpp index dda19c6695..67d3cc2115 100644 --- a/services/inputflinger/reader/EventHub.cpp +++ b/services/inputflinger/reader/EventHub.cpp @@ -216,10 +216,7 @@ bool EventHub::Device::hasValidFd() const { return !isVirtual && enabled; } -const sp<KeyCharacterMap>& EventHub::Device::getKeyCharacterMap() const { - if (combinedKeyMap != nullptr) { - return combinedKeyMap; - } +const std::shared_ptr<KeyCharacterMap> EventHub::Device::getKeyCharacterMap() const { return keyMap.keyCharacterMap; } @@ -661,8 +658,8 @@ status_t EventHub::mapKey(int32_t deviceId, int32_t scanCode, int32_t usageCode, if (device != nullptr) { // Check the key character map first. - sp<KeyCharacterMap> kcm = device->getKeyCharacterMap(); - if (kcm != nullptr) { + const std::shared_ptr<KeyCharacterMap> kcm = device->getKeyCharacterMap(); + if (kcm) { if (!kcm->mapKey(scanCode, usageCode, outKeycode)) { *outFlags = 0; status = NO_ERROR; @@ -677,7 +674,7 @@ status_t EventHub::mapKey(int32_t deviceId, int32_t scanCode, int32_t usageCode, } if (status == NO_ERROR) { - if (kcm != nullptr) { + if (kcm) { kcm->tryRemapKey(*outKeycode, metaState, outKeycode, outMetaState); } else { *outMetaState = metaState; @@ -754,7 +751,7 @@ void EventHub::getVirtualKeyDefinitions(int32_t deviceId, } } -sp<KeyCharacterMap> EventHub::getKeyCharacterMap(int32_t deviceId) const { +const std::shared_ptr<KeyCharacterMap> EventHub::getKeyCharacterMap(int32_t deviceId) const { AutoMutex _l(mLock); Device* device = getDeviceLocked(deviceId); if (device != nullptr) { @@ -763,15 +760,13 @@ sp<KeyCharacterMap> EventHub::getKeyCharacterMap(int32_t deviceId) const { return nullptr; } -bool EventHub::setKeyboardLayoutOverlay(int32_t deviceId, const sp<KeyCharacterMap>& map) { +bool EventHub::setKeyboardLayoutOverlay(int32_t deviceId, std::shared_ptr<KeyCharacterMap> map) { AutoMutex _l(mLock); Device* device = getDeviceLocked(deviceId); - if (device != nullptr) { - if (map != device->overlayKeyMap) { - device->overlayKeyMap = map; - device->combinedKeyMap = KeyCharacterMap::combine(device->keyMap.keyCharacterMap, map); - return true; - } + if (device != nullptr && map != nullptr && device->keyMap.keyCharacterMap != nullptr) { + device->keyMap.keyCharacterMap->combine(*map); + device->keyMap.keyCharacterMapFile = device->keyMap.keyCharacterMap->getLoadFileName(); + return true; } return false; } @@ -1853,8 +1848,6 @@ void EventHub::dump(std::string& dump) { device->keyMap.keyCharacterMapFile.c_str()); dump += StringPrintf(INDENT3 "ConfigurationFile: %s\n", device->configurationFile.c_str()); - dump += StringPrintf(INDENT3 "HaveKeyboardLayoutOverlay: %s\n", - toString(device->overlayKeyMap != nullptr)); dump += INDENT3 "VideoDevice: "; if (device->videoDevice) { dump += device->videoDevice->dump() + "\n"; diff --git a/services/inputflinger/reader/InputDevice.cpp b/services/inputflinger/reader/InputDevice.cpp index 49607798ef..b2244762b8 100644 --- a/services/inputflinger/reader/InputDevice.cpp +++ b/services/inputflinger/reader/InputDevice.cpp @@ -240,7 +240,7 @@ void InputDevice::configure(nsecs_t when, const InputReaderConfiguration* config if (!changes || (changes & InputReaderConfiguration::CHANGE_KEYBOARD_LAYOUTS)) { if (!mClasses.test(InputDeviceClass::VIRTUAL)) { - sp<KeyCharacterMap> keyboardLayout = + std::shared_ptr<KeyCharacterMap> keyboardLayout = mContext->getPolicy()->getKeyboardLayoutOverlay(mIdentifier); bool shouldBumpGeneration = false; for_each_subdevice( diff --git a/services/inputflinger/reader/include/EventHub.h b/services/inputflinger/reader/include/EventHub.h index fb0f19e33f..aec4837a30 100644 --- a/services/inputflinger/reader/include/EventHub.h +++ b/services/inputflinger/reader/include/EventHub.h @@ -226,8 +226,9 @@ public: virtual void getVirtualKeyDefinitions( int32_t deviceId, std::vector<VirtualKeyDefinition>& outVirtualKeys) const = 0; - virtual sp<KeyCharacterMap> getKeyCharacterMap(int32_t deviceId) const = 0; - virtual bool setKeyboardLayoutOverlay(int32_t deviceId, const sp<KeyCharacterMap>& map) = 0; + virtual const std::shared_ptr<KeyCharacterMap> getKeyCharacterMap(int32_t deviceId) const = 0; + virtual bool setKeyboardLayoutOverlay(int32_t deviceId, + std::shared_ptr<KeyCharacterMap> map) = 0; /* Control the vibrator. */ virtual void vibrate(int32_t deviceId, const VibrationElement& effect) = 0; @@ -373,8 +374,10 @@ public: int32_t deviceId, std::vector<VirtualKeyDefinition>& outVirtualKeys) const override final; - sp<KeyCharacterMap> getKeyCharacterMap(int32_t deviceId) const override final; - bool setKeyboardLayoutOverlay(int32_t deviceId, const sp<KeyCharacterMap>& map) override final; + const std::shared_ptr<KeyCharacterMap> getKeyCharacterMap( + int32_t deviceId) const override final; + bool setKeyboardLayoutOverlay(int32_t deviceId, + std::shared_ptr<KeyCharacterMap> map) override final; void vibrate(int32_t deviceId, const VibrationElement& effect) override final; void cancelVibrate(int32_t deviceId) override final; @@ -421,9 +424,6 @@ private: std::unique_ptr<VirtualKeyMap> virtualKeyMap; KeyMap keyMap; - sp<KeyCharacterMap> overlayKeyMap; - sp<KeyCharacterMap> combinedKeyMap; - bool ffEffectPlaying; int16_t ffEffectId; // initially -1 @@ -441,7 +441,7 @@ private: bool hasValidFd() const; const bool isVirtual; // set if fd < 0 is passed to constructor - const sp<KeyCharacterMap>& getKeyCharacterMap() const; + const std::shared_ptr<KeyCharacterMap> getKeyCharacterMap() const; template <std::size_t N> status_t readDeviceBitMask(unsigned long ioctlCode, BitArray<N>& bitArray); diff --git a/services/inputflinger/reader/include/InputDevice.h b/services/inputflinger/reader/include/InputDevice.h index 307eeb4e4f..7f5e1c8443 100644 --- a/services/inputflinger/reader/include/InputDevice.h +++ b/services/inputflinger/reader/include/InputDevice.h @@ -261,10 +261,10 @@ public: inline void getVirtualKeyDefinitions(std::vector<VirtualKeyDefinition>& outVirtualKeys) const { return mEventHub->getVirtualKeyDefinitions(mId, outVirtualKeys); } - inline sp<KeyCharacterMap> getKeyCharacterMap() const { + inline const std::shared_ptr<KeyCharacterMap> getKeyCharacterMap() const { return mEventHub->getKeyCharacterMap(mId); } - inline bool setKeyboardLayoutOverlay(const sp<KeyCharacterMap>& map) { + inline bool setKeyboardLayoutOverlay(std::shared_ptr<KeyCharacterMap> map) { return mEventHub->setKeyboardLayoutOverlay(mId, map); } inline void vibrate(const VibrationElement& element) { diff --git a/services/inputflinger/tests/InputReader_test.cpp b/services/inputflinger/tests/InputReader_test.cpp index 82157b69d9..b28b6ea4e2 100644 --- a/services/inputflinger/tests/InputReader_test.cpp +++ b/services/inputflinger/tests/InputReader_test.cpp @@ -340,7 +340,8 @@ private: mDevicesChangedCondition.notify_all(); } - virtual sp<KeyCharacterMap> getKeyboardLayoutOverlay(const InputDeviceIdentifier&) { + virtual std::shared_ptr<KeyCharacterMap> getKeyboardLayoutOverlay( + const InputDeviceIdentifier&) { return nullptr; } @@ -814,11 +815,11 @@ private: } } - virtual sp<KeyCharacterMap> getKeyCharacterMap(int32_t) const { + virtual const std::shared_ptr<KeyCharacterMap> getKeyCharacterMap(int32_t) const { return nullptr; } - virtual bool setKeyboardLayoutOverlay(int32_t, const sp<KeyCharacterMap>&) { + virtual bool setKeyboardLayoutOverlay(int32_t, std::shared_ptr<KeyCharacterMap>) { return false; } |