diff options
author | 2022-07-13 07:29:51 -0700 | |
---|---|---|
committer | 2022-07-13 12:07:08 -0700 | |
commit | 4f94c1ad3fe73105a34178af3a086aa571b8bf78 (patch) | |
tree | 9798dc5bce1eec050ef9a3460f3ca5064f128fef | |
parent | 4f4aff66c60ed16e9f089693ef0a64ea227c9a62 (diff) |
Avoid KeyedVector and String8 in PropertyMap
Update the external-facing APIs of PropertyMap to reduce the dependency
on libutils. Here we remove String8 and KeyedVector from the header
file. Eventually the Tokenizer can be moved to libinput as well, which
would allow us to further reduce this dependency.
Bug: 233177558
Test: atest libinput_tests inputflinger_tests
Change-Id: I58965ccf7dbd5514c8526f15e713f0e26e498c83
-rw-r--r-- | include/input/PropertyMap.h | 27 | ||||
-rw-r--r-- | libs/input/Keyboard.cpp | 23 | ||||
-rw-r--r-- | libs/input/PropertyMap.cpp | 47 | ||||
-rwxr-xr-x | libs/input/PropertyMap_fuzz.cpp | 32 | ||||
-rw-r--r-- | services/inputflinger/host/InputDriver.cpp | 19 | ||||
-rw-r--r-- | services/inputflinger/reader/EventHub.cpp | 11 | ||||
-rw-r--r-- | services/inputflinger/reader/include/EventHub.h | 1 | ||||
-rw-r--r-- | services/inputflinger/reader/mapper/CursorInputMapper.cpp | 9 | ||||
-rw-r--r-- | services/inputflinger/reader/mapper/KeyboardInputMapper.cpp | 8 | ||||
-rw-r--r-- | services/inputflinger/reader/mapper/RotaryEncoderInputMapper.cpp | 4 | ||||
-rw-r--r-- | services/inputflinger/reader/mapper/SensorInputMapper.cpp | 2 | ||||
-rw-r--r-- | services/inputflinger/reader/mapper/TouchInputMapper.cpp | 66 | ||||
-rw-r--r-- | services/inputflinger/tests/InputReader_test.cpp | 12 |
13 files changed, 118 insertions, 143 deletions
diff --git a/include/input/PropertyMap.h b/include/input/PropertyMap.h index 451918bb46..b1e3f85ed5 100644 --- a/include/input/PropertyMap.h +++ b/include/input/PropertyMap.h @@ -18,10 +18,8 @@ #define _UTILS_PROPERTY_MAP_H #include <android-base/result.h> -#include <utils/Errors.h> -#include <utils/KeyedVector.h> -#include <utils/String8.h> #include <utils/Tokenizer.h> +#include <unordered_map> namespace android { @@ -58,30 +56,27 @@ public: /* Adds a property. * Replaces the property with the same key if it is already present. */ - void addProperty(const String8& key, const String8& value); - - /* Returns true if the property map contains the specified key. */ - bool hasProperty(const String8& key) const; + void addProperty(const std::string& key, const std::string& value); /* Gets the value of a property and parses it. * Returns true and sets outValue if the key was found and its value was parsed successfully. * Otherwise returns false and does not modify outValue. (Also logs a warning.) */ - bool tryGetProperty(const String8& key, String8& outValue) const; - bool tryGetProperty(const String8& key, bool& outValue) const; - bool tryGetProperty(const String8& key, int32_t& outValue) const; - bool tryGetProperty(const String8& key, float& outValue) const; + bool tryGetProperty(const std::string& key, std::string& outValue) const; + bool tryGetProperty(const std::string& key, bool& outValue) const; + bool tryGetProperty(const std::string& key, int32_t& outValue) const; + bool tryGetProperty(const std::string& key, float& outValue) const; /* Adds all values from the specified property map. */ void addAll(const PropertyMap* map); - /* Gets the underlying property map. */ - inline const KeyedVector<String8, String8>& getProperties() const { return mProperties; } - /* Loads a property map from a file. */ static android::base::Result<std::unique_ptr<PropertyMap>> load(const char* filename); private: + /* Returns true if the property map contains the specified key. */ + bool hasProperty(const std::string& key) const; + class Parser { PropertyMap* mMap; Tokenizer* mTokenizer; @@ -95,11 +90,11 @@ private: status_t parseType(); status_t parseKey(); status_t parseKeyProperty(); - status_t parseModifier(const String8& token, int32_t* outMetaState); + status_t parseModifier(const std::string& token, int32_t* outMetaState); status_t parseCharacterLiteral(char16_t* outCharacter); }; - KeyedVector<String8, String8> mProperties; + std::unordered_map<std::string, std::string> mProperties; }; } // namespace android diff --git a/libs/input/Keyboard.cpp b/libs/input/Keyboard.cpp index c3f5151fd1..3f8467d818 100644 --- a/libs/input/Keyboard.cpp +++ b/libs/input/Keyboard.cpp @@ -49,25 +49,23 @@ status_t KeyMap::load(const InputDeviceIdentifier& deviceIdentifier, const PropertyMap* deviceConfiguration) { // Use the configured key layout if available. if (deviceConfiguration) { - String8 keyLayoutName; - if (deviceConfiguration->tryGetProperty(String8("keyboard.layout"), - keyLayoutName)) { + std::string keyLayoutName; + if (deviceConfiguration->tryGetProperty("keyboard.layout", keyLayoutName)) { status_t status = loadKeyLayout(deviceIdentifier, keyLayoutName.c_str()); if (status == NAME_NOT_FOUND) { ALOGE("Configuration for keyboard device '%s' requested keyboard layout '%s' but " - "it was not found.", - deviceIdentifier.name.c_str(), keyLayoutName.string()); + "it was not found.", + deviceIdentifier.name.c_str(), keyLayoutName.c_str()); } } - String8 keyCharacterMapName; - if (deviceConfiguration->tryGetProperty(String8("keyboard.characterMap"), - keyCharacterMapName)) { + std::string keyCharacterMapName; + if (deviceConfiguration->tryGetProperty("keyboard.characterMap", keyCharacterMapName)) { status_t status = loadKeyCharacterMap(deviceIdentifier, keyCharacterMapName.c_str()); if (status == NAME_NOT_FOUND) { ALOGE("Configuration for keyboard device '%s' requested keyboard character " - "map '%s' but it was not found.", - deviceIdentifier.name.c_str(), keyCharacterMapName.string()); + "map '%s' but it was not found.", + deviceIdentifier.name.c_str(), keyCharacterMapName.c_str()); } } @@ -165,7 +163,7 @@ bool isKeyboardSpecialFunction(const PropertyMap* config) { return false; } bool isSpecialFunction = false; - config->tryGetProperty(String8("keyboard.specialFunction"), isSpecialFunction); + config->tryGetProperty("keyboard.specialFunction", isSpecialFunction); return isSpecialFunction; } @@ -180,8 +178,7 @@ bool isEligibleBuiltInKeyboard(const InputDeviceIdentifier& deviceIdentifier, if (deviceConfiguration) { bool builtIn = false; - if (deviceConfiguration->tryGetProperty(String8("keyboard.builtIn"), builtIn) - && builtIn) { + if (deviceConfiguration->tryGetProperty("keyboard.builtIn", builtIn) && builtIn) { return true; } } diff --git a/libs/input/PropertyMap.cpp b/libs/input/PropertyMap.cpp index a842166761..662e568ac0 100644 --- a/libs/input/PropertyMap.cpp +++ b/libs/input/PropertyMap.cpp @@ -17,6 +17,7 @@ #define LOG_TAG "PropertyMap" #include <input/PropertyMap.h> +#include <log/log.h> // Enables debug output for the parser. #define DEBUG_PARSER 0 @@ -39,25 +40,25 @@ void PropertyMap::clear() { mProperties.clear(); } -void PropertyMap::addProperty(const String8& key, const String8& value) { - mProperties.add(key, value); +void PropertyMap::addProperty(const std::string& key, const std::string& value) { + mProperties.emplace(key, value); } -bool PropertyMap::hasProperty(const String8& key) const { - return mProperties.indexOfKey(key) >= 0; +bool PropertyMap::hasProperty(const std::string& key) const { + return mProperties.find(key) != mProperties.end(); } -bool PropertyMap::tryGetProperty(const String8& key, String8& outValue) const { - ssize_t index = mProperties.indexOfKey(key); - if (index < 0) { +bool PropertyMap::tryGetProperty(const std::string& key, std::string& outValue) const { + auto it = mProperties.find(key); + if (it == mProperties.end()) { return false; } - outValue = mProperties.valueAt(index); + outValue = it->second; return true; } -bool PropertyMap::tryGetProperty(const String8& key, bool& outValue) const { +bool PropertyMap::tryGetProperty(const std::string& key, bool& outValue) const { int32_t intValue; if (!tryGetProperty(key, intValue)) { return false; @@ -67,34 +68,34 @@ bool PropertyMap::tryGetProperty(const String8& key, bool& outValue) const { return true; } -bool PropertyMap::tryGetProperty(const String8& key, int32_t& outValue) const { - String8 stringValue; +bool PropertyMap::tryGetProperty(const std::string& key, int32_t& outValue) const { + std::string stringValue; if (!tryGetProperty(key, stringValue) || stringValue.length() == 0) { return false; } char* end; - int value = strtol(stringValue.string(), &end, 10); + int value = strtol(stringValue.c_str(), &end, 10); if (*end != '\0') { - ALOGW("Property key '%s' has invalid value '%s'. Expected an integer.", key.string(), - stringValue.string()); + ALOGW("Property key '%s' has invalid value '%s'. Expected an integer.", key.c_str(), + stringValue.c_str()); return false; } outValue = value; return true; } -bool PropertyMap::tryGetProperty(const String8& key, float& outValue) const { - String8 stringValue; +bool PropertyMap::tryGetProperty(const std::string& key, float& outValue) const { + std::string stringValue; if (!tryGetProperty(key, stringValue) || stringValue.length() == 0) { return false; } char* end; - float value = strtof(stringValue.string(), &end); + float value = strtof(stringValue.c_str(), &end); if (*end != '\0') { - ALOGW("Property key '%s' has invalid value '%s'. Expected a float.", key.string(), - stringValue.string()); + ALOGW("Property key '%s' has invalid value '%s'. Expected a float.", key.c_str(), + stringValue.c_str()); return false; } outValue = value; @@ -102,8 +103,8 @@ bool PropertyMap::tryGetProperty(const String8& key, float& outValue) const { } void PropertyMap::addAll(const PropertyMap* map) { - for (size_t i = 0; i < map->mProperties.size(); i++) { - mProperties.add(map->mProperties.keyAt(i), map->mProperties.valueAt(i)); + for (const auto& [key, value] : map->mProperties) { + mProperties.emplace(key, value); } } @@ -184,13 +185,13 @@ status_t PropertyMap::Parser::parse() { return BAD_VALUE; } - if (mMap->hasProperty(keyToken)) { + if (mMap->hasProperty(keyToken.string())) { ALOGE("%s: Duplicate property value for key '%s'.", mTokenizer->getLocation().string(), keyToken.string()); return BAD_VALUE; } - mMap->addProperty(keyToken, valueToken); + mMap->addProperty(keyToken.string(), valueToken.string()); } mTokenizer->nextLine(); diff --git a/libs/input/PropertyMap_fuzz.cpp b/libs/input/PropertyMap_fuzz.cpp index afb97a1d47..d985dc1748 100755 --- a/libs/input/PropertyMap_fuzz.cpp +++ b/libs/input/PropertyMap_fuzz.cpp @@ -17,32 +17,22 @@ #include "android-base/file.h" #include "fuzzer/FuzzedDataProvider.h" #include "input/PropertyMap.h" -#include "utils/String8.h" static constexpr int MAX_FILE_SIZE = 256; static constexpr int MAX_STR_LEN = 2048; static constexpr int MAX_OPERATIONS = 1000; -static const std::vector<std::function<void(FuzzedDataProvider*, android::PropertyMap)>> +static const std::vector<std::function<void(FuzzedDataProvider*, android::PropertyMap&)>> operations = { - [](FuzzedDataProvider*, android::PropertyMap propertyMap) -> void { - propertyMap.getProperties(); - }, - [](FuzzedDataProvider*, android::PropertyMap propertyMap) -> void { + [](FuzzedDataProvider*, android::PropertyMap& propertyMap) -> void { propertyMap.clear(); }, - [](FuzzedDataProvider* dataProvider, android::PropertyMap propertyMap) -> void { - std::string keyStr = dataProvider->ConsumeRandomLengthString(MAX_STR_LEN); - android::String8 key = android::String8(keyStr.c_str()); - propertyMap.hasProperty(key); - }, - [](FuzzedDataProvider* dataProvider, android::PropertyMap propertyMap) -> void { - std::string keyStr = dataProvider->ConsumeRandomLengthString(MAX_STR_LEN); - android::String8 key = android::String8(keyStr.c_str()); - android::String8 out; + [](FuzzedDataProvider* dataProvider, android::PropertyMap& propertyMap) -> void { + std::string key = dataProvider->ConsumeRandomLengthString(MAX_STR_LEN); + std::string out; propertyMap.tryGetProperty(key, out); }, - [](FuzzedDataProvider* dataProvider, android::PropertyMap /*unused*/) -> void { + [](FuzzedDataProvider* dataProvider, android::PropertyMap& /*unused*/) -> void { TemporaryFile tf; // Generate file contents std::string contents = dataProvider->ConsumeRandomLengthString(MAX_FILE_SIZE); @@ -54,17 +44,15 @@ static const std::vector<std::function<void(FuzzedDataProvider*, android::Proper } android::PropertyMap::load(tf.path); }, - [](FuzzedDataProvider* dataProvider, android::PropertyMap propertyMap) -> void { - std::string keyStr = dataProvider->ConsumeRandomLengthString(MAX_STR_LEN); - std::string valStr = dataProvider->ConsumeRandomLengthString(MAX_STR_LEN); - android::String8 key = android::String8(keyStr.c_str()); - android::String8 val = android::String8(valStr.c_str()); + [](FuzzedDataProvider* dataProvider, android::PropertyMap& propertyMap) -> void { + std::string key = dataProvider->ConsumeRandomLengthString(MAX_STR_LEN); + std::string val = dataProvider->ConsumeRandomLengthString(MAX_STR_LEN); propertyMap.addProperty(key, val); }, }; extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { FuzzedDataProvider dataProvider(data, size); - android::PropertyMap propertyMap = android::PropertyMap(); + android::PropertyMap propertyMap; int opsRun = 0; while (dataProvider.remaining_bytes() > 0 && opsRun++ < MAX_OPERATIONS) { diff --git a/services/inputflinger/host/InputDriver.cpp b/services/inputflinger/host/InputDriver.cpp index 2ebdbcfcc4..97d57e4bd0 100644 --- a/services/inputflinger/host/InputDriver.cpp +++ b/services/inputflinger/host/InputDriver.cpp @@ -240,19 +240,16 @@ input_property_map_t* InputDriver::inputGetDevicePropertyMap(input_device_identi return nullptr; } -input_property_t* InputDriver::inputGetDeviceProperty(input_property_map_t* map, - const char* key) { - String8 keyString(key); +input_property_t* InputDriver::inputGetDeviceProperty(input_property_map_t* map, const char* key) { if (map != nullptr) { - if (map->propertyMap->hasProperty(keyString)) { - auto prop = new input_property_t(); - if (!map->propertyMap->tryGetProperty(keyString, prop->value)) { - delete prop; - return nullptr; - } - prop->key = keyString; - return prop; + std::string value; + auto prop = std::make_unique<input_property_t>(); + if (!map->propertyMap->tryGetProperty(key, value)) { + return nullptr; } + prop->key = key; + prop->value = value.c_str(); + return prop.release(); } return nullptr; } diff --git a/services/inputflinger/reader/EventHub.cpp b/services/inputflinger/reader/EventHub.cpp index fe4d443aac..a17d2c0fab 100644 --- a/services/inputflinger/reader/EventHub.cpp +++ b/services/inputflinger/reader/EventHub.cpp @@ -502,7 +502,7 @@ status_t EventHub::Device::loadKeyMapLocked() { bool EventHub::Device::isExternalDeviceLocked() { if (configuration) { bool value; - if (configuration->tryGetProperty(String8("device.internal"), value)) { + if (configuration->tryGetProperty("device.internal", value)) { return !value; } } @@ -512,7 +512,7 @@ bool EventHub::Device::isExternalDeviceLocked() { bool EventHub::Device::deviceHasMicLocked() { if (configuration) { bool value; - if (configuration->tryGetProperty(String8("audio.mic"), value)) { + if (configuration->tryGetProperty("audio.mic", value)) { return value; } } @@ -2076,10 +2076,9 @@ void EventHub::openDeviceLocked(const std::string& devicePath) { } // See if this is a rotary encoder type device. - String8 deviceType = String8(); - if (device->configuration && - device->configuration->tryGetProperty(String8("device.type"), deviceType)) { - if (!deviceType.compare(String8("rotaryEncoder"))) { + std::string deviceType; + if (device->configuration && device->configuration->tryGetProperty("device.type", deviceType)) { + if (deviceType == "rotaryEncoder") { device->classes |= InputDeviceClass::ROTARY_ENCODER; } } diff --git a/services/inputflinger/reader/include/EventHub.h b/services/inputflinger/reader/include/EventHub.h index b2d50fc6fb..79188aa2c0 100644 --- a/services/inputflinger/reader/include/EventHub.h +++ b/services/inputflinger/reader/include/EventHub.h @@ -36,7 +36,6 @@ #include <sys/epoll.h> #include <utils/BitSet.h> #include <utils/Errors.h> -#include <utils/KeyedVector.h> #include <utils/List.h> #include <utils/Log.h> #include <utils/Mutex.h> diff --git a/services/inputflinger/reader/mapper/CursorInputMapper.cpp b/services/inputflinger/reader/mapper/CursorInputMapper.cpp index 91dc61923b..baa6007d2c 100644 --- a/services/inputflinger/reader/mapper/CursorInputMapper.cpp +++ b/services/inputflinger/reader/mapper/CursorInputMapper.cpp @@ -225,18 +225,17 @@ void CursorInputMapper::configure(nsecs_t when, const InputReaderConfiguration* void CursorInputMapper::configureParameters() { mParameters.mode = Parameters::Mode::POINTER; - String8 cursorModeString; - if (getDeviceContext().getConfiguration().tryGetProperty(String8("cursor.mode"), - cursorModeString)) { + std::string cursorModeString; + if (getDeviceContext().getConfiguration().tryGetProperty("cursor.mode", cursorModeString)) { if (cursorModeString == "navigation") { mParameters.mode = Parameters::Mode::NAVIGATION; } else if (cursorModeString != "pointer" && cursorModeString != "default") { - ALOGW("Invalid value for cursor.mode: '%s'", cursorModeString.string()); + ALOGW("Invalid value for cursor.mode: '%s'", cursorModeString.c_str()); } } mParameters.orientationAware = false; - getDeviceContext().getConfiguration().tryGetProperty(String8("cursor.orientationAware"), + getDeviceContext().getConfiguration().tryGetProperty("cursor.orientationAware", mParameters.orientationAware); mParameters.hasAssociatedDisplay = false; diff --git a/services/inputflinger/reader/mapper/KeyboardInputMapper.cpp b/services/inputflinger/reader/mapper/KeyboardInputMapper.cpp index 8eb870fc87..6a406d21de 100644 --- a/services/inputflinger/reader/mapper/KeyboardInputMapper.cpp +++ b/services/inputflinger/reader/mapper/KeyboardInputMapper.cpp @@ -160,7 +160,7 @@ void KeyboardInputMapper::configure(nsecs_t when, const InputReaderConfiguration static void mapStemKey(int32_t keyCode, const PropertyMap& config, char const* property) { int32_t mapped = 0; - if (config.tryGetProperty(String8(property), mapped) && mapped > 0) { + if (config.tryGetProperty(property, mapped) && mapped > 0) { for (size_t i = 0; i < stemKeyRotationMapSize; i++) { if (stemKeyRotationMap[i][0] == keyCode) { stemKeyRotationMap[i][1] = mapped; @@ -173,7 +173,7 @@ static void mapStemKey(int32_t keyCode, const PropertyMap& config, char const* p void KeyboardInputMapper::configureParameters() { mParameters.orientationAware = false; const PropertyMap& config = getDeviceContext().getConfiguration(); - config.tryGetProperty(String8("keyboard.orientationAware"), mParameters.orientationAware); + config.tryGetProperty("keyboard.orientationAware", mParameters.orientationAware); if (mParameters.orientationAware) { mapStemKey(AKEYCODE_STEM_PRIMARY, config, "keyboard.rotated.stem_primary"); @@ -183,10 +183,10 @@ void KeyboardInputMapper::configureParameters() { } mParameters.handlesKeyRepeat = false; - config.tryGetProperty(String8("keyboard.handlesKeyRepeat"), mParameters.handlesKeyRepeat); + config.tryGetProperty("keyboard.handlesKeyRepeat", mParameters.handlesKeyRepeat); mParameters.doNotWakeByDefault = false; - config.tryGetProperty(String8("keyboard.doNotWakeByDefault"), mParameters.doNotWakeByDefault); + config.tryGetProperty("keyboard.doNotWakeByDefault", mParameters.doNotWakeByDefault); } void KeyboardInputMapper::dumpParameters(std::string& dump) { diff --git a/services/inputflinger/reader/mapper/RotaryEncoderInputMapper.cpp b/services/inputflinger/reader/mapper/RotaryEncoderInputMapper.cpp index eca25f6e6a..05973f783c 100644 --- a/services/inputflinger/reader/mapper/RotaryEncoderInputMapper.cpp +++ b/services/inputflinger/reader/mapper/RotaryEncoderInputMapper.cpp @@ -40,10 +40,10 @@ void RotaryEncoderInputMapper::populateDeviceInfo(InputDeviceInfo* info) { if (mRotaryEncoderScrollAccumulator.haveRelativeVWheel()) { float res = 0.0f; - if (!getDeviceContext().getConfiguration().tryGetProperty(String8("device.res"), res)) { + if (!getDeviceContext().getConfiguration().tryGetProperty("device.res", res)) { ALOGW("Rotary Encoder device configuration file didn't specify resolution!\n"); } - if (!getDeviceContext().getConfiguration().tryGetProperty(String8("device.scalingFactor"), + if (!getDeviceContext().getConfiguration().tryGetProperty("device.scalingFactor", mScalingFactor)) { ALOGW("Rotary Encoder device configuration file didn't specify scaling factor," "default to 1.0!\n"); diff --git a/services/inputflinger/reader/mapper/SensorInputMapper.cpp b/services/inputflinger/reader/mapper/SensorInputMapper.cpp index b01c2bc13f..573f99cf87 100644 --- a/services/inputflinger/reader/mapper/SensorInputMapper.cpp +++ b/services/inputflinger/reader/mapper/SensorInputMapper.cpp @@ -64,7 +64,7 @@ uint32_t SensorInputMapper::getSources() const { template <typename T> bool SensorInputMapper::tryGetProperty(std::string keyName, T& outValue) { const auto& config = getDeviceContext().getConfiguration(); - return config.tryGetProperty(String8(keyName.c_str()), outValue); + return config.tryGetProperty(keyName, outValue); } void SensorInputMapper::parseSensorConfiguration(InputDeviceSensorType sensorType, int32_t absCode, diff --git a/services/inputflinger/reader/mapper/TouchInputMapper.cpp b/services/inputflinger/reader/mapper/TouchInputMapper.cpp index f07a3e8dd3..2f3337b7cc 100644 --- a/services/inputflinger/reader/mapper/TouchInputMapper.cpp +++ b/services/inputflinger/reader/mapper/TouchInputMapper.cpp @@ -415,15 +415,15 @@ void TouchInputMapper::configureParameters() { ? Parameters::GestureMode::SINGLE_TOUCH : Parameters::GestureMode::MULTI_TOUCH; - String8 gestureModeString; - if (getDeviceContext().getConfiguration().tryGetProperty(String8("touch.gestureMode"), + std::string gestureModeString; + if (getDeviceContext().getConfiguration().tryGetProperty("touch.gestureMode", gestureModeString)) { if (gestureModeString == "single-touch") { mParameters.gestureMode = Parameters::GestureMode::SINGLE_TOUCH; } else if (gestureModeString == "multi-touch") { mParameters.gestureMode = Parameters::GestureMode::MULTI_TOUCH; } else if (gestureModeString != "default") { - ALOGW("Invalid value for touch.gestureMode: '%s'", gestureModeString.string()); + ALOGW("Invalid value for touch.gestureMode: '%s'", gestureModeString.c_str()); } } @@ -445,8 +445,8 @@ void TouchInputMapper::configureParameters() { mParameters.hasButtonUnderPad = getDeviceContext().hasInputProperty(INPUT_PROP_BUTTONPAD); - String8 deviceTypeString; - if (getDeviceContext().getConfiguration().tryGetProperty(String8("touch.deviceType"), + std::string deviceTypeString; + if (getDeviceContext().getConfiguration().tryGetProperty("touch.deviceType", deviceTypeString)) { if (deviceTypeString == "touchScreen") { mParameters.deviceType = Parameters::DeviceType::TOUCH_SCREEN; @@ -457,17 +457,17 @@ void TouchInputMapper::configureParameters() { } else if (deviceTypeString == "pointer") { mParameters.deviceType = Parameters::DeviceType::POINTER; } else if (deviceTypeString != "default") { - ALOGW("Invalid value for touch.deviceType: '%s'", deviceTypeString.string()); + ALOGW("Invalid value for touch.deviceType: '%s'", deviceTypeString.c_str()); } } mParameters.orientationAware = mParameters.deviceType == Parameters::DeviceType::TOUCH_SCREEN; - getDeviceContext().getConfiguration().tryGetProperty(String8("touch.orientationAware"), + getDeviceContext().getConfiguration().tryGetProperty("touch.orientationAware", mParameters.orientationAware); mParameters.orientation = Parameters::Orientation::ORIENTATION_0; - String8 orientationString; - if (getDeviceContext().getConfiguration().tryGetProperty(String8("touch.orientation"), + std::string orientationString; + if (getDeviceContext().getConfiguration().tryGetProperty("touch.orientation", orientationString)) { if (mParameters.deviceType != Parameters::DeviceType::TOUCH_SCREEN) { ALOGW("The configuration 'touch.orientation' is only supported for touchscreens."); @@ -478,7 +478,7 @@ void TouchInputMapper::configureParameters() { } else if (orientationString == "ORIENTATION_270") { mParameters.orientation = Parameters::Orientation::ORIENTATION_270; } else if (orientationString != "ORIENTATION_0") { - ALOGW("Invalid value for touch.orientation: '%s'", orientationString.string()); + ALOGW("Invalid value for touch.orientation: '%s'", orientationString.c_str()); } } @@ -490,8 +490,8 @@ void TouchInputMapper::configureParameters() { mParameters.hasAssociatedDisplay = true; if (mParameters.deviceType == Parameters::DeviceType::TOUCH_SCREEN) { mParameters.associatedDisplayIsExternal = getDeviceContext().isExternal(); - String8 uniqueDisplayId; - getDeviceContext().getConfiguration().tryGetProperty(String8("touch.displayId"), + std::string uniqueDisplayId; + getDeviceContext().getConfiguration().tryGetProperty("touch.displayId", uniqueDisplayId); mParameters.uniqueDisplayId = uniqueDisplayId.c_str(); } @@ -504,7 +504,7 @@ void TouchInputMapper::configureParameters() { // Normally we don't do this for internal touch screens to prevent them from waking // up in your pocket but you can enable it using the input device configuration. mParameters.wake = getDeviceContext().isExternal(); - getDeviceContext().getConfiguration().tryGetProperty(String8("touch.wake"), mParameters.wake); + getDeviceContext().getConfiguration().tryGetProperty("touch.wake", mParameters.wake); } void TouchInputMapper::dumpParameters(std::string& dump) { @@ -1192,8 +1192,8 @@ void TouchInputMapper::parseCalibration() { // Size out.sizeCalibration = Calibration::SizeCalibration::DEFAULT; - String8 sizeCalibrationString; - if (in.tryGetProperty(String8("touch.size.calibration"), sizeCalibrationString)) { + std::string sizeCalibrationString; + if (in.tryGetProperty("touch.size.calibration", sizeCalibrationString)) { if (sizeCalibrationString == "none") { out.sizeCalibration = Calibration::SizeCalibration::NONE; } else if (sizeCalibrationString == "geometric") { @@ -1205,18 +1205,18 @@ void TouchInputMapper::parseCalibration() { } else if (sizeCalibrationString == "area") { out.sizeCalibration = Calibration::SizeCalibration::AREA; } else if (sizeCalibrationString != "default") { - ALOGW("Invalid value for touch.size.calibration: '%s'", sizeCalibrationString.string()); + ALOGW("Invalid value for touch.size.calibration: '%s'", sizeCalibrationString.c_str()); } } - out.haveSizeScale = in.tryGetProperty(String8("touch.size.scale"), out.sizeScale); - out.haveSizeBias = in.tryGetProperty(String8("touch.size.bias"), out.sizeBias); - out.haveSizeIsSummed = in.tryGetProperty(String8("touch.size.isSummed"), out.sizeIsSummed); + out.haveSizeScale = in.tryGetProperty("touch.size.scale", out.sizeScale); + out.haveSizeBias = in.tryGetProperty("touch.size.bias", out.sizeBias); + out.haveSizeIsSummed = in.tryGetProperty("touch.size.isSummed", out.sizeIsSummed); // Pressure out.pressureCalibration = Calibration::PressureCalibration::DEFAULT; - String8 pressureCalibrationString; - if (in.tryGetProperty(String8("touch.pressure.calibration"), pressureCalibrationString)) { + std::string pressureCalibrationString; + if (in.tryGetProperty("touch.pressure.calibration", pressureCalibrationString)) { if (pressureCalibrationString == "none") { out.pressureCalibration = Calibration::PressureCalibration::NONE; } else if (pressureCalibrationString == "physical") { @@ -1225,16 +1225,16 @@ void TouchInputMapper::parseCalibration() { out.pressureCalibration = Calibration::PressureCalibration::AMPLITUDE; } else if (pressureCalibrationString != "default") { ALOGW("Invalid value for touch.pressure.calibration: '%s'", - pressureCalibrationString.string()); + pressureCalibrationString.c_str()); } } - out.havePressureScale = in.tryGetProperty(String8("touch.pressure.scale"), out.pressureScale); + out.havePressureScale = in.tryGetProperty("touch.pressure.scale", out.pressureScale); // Orientation out.orientationCalibration = Calibration::OrientationCalibration::DEFAULT; - String8 orientationCalibrationString; - if (in.tryGetProperty(String8("touch.orientation.calibration"), orientationCalibrationString)) { + std::string orientationCalibrationString; + if (in.tryGetProperty("touch.orientation.calibration", orientationCalibrationString)) { if (orientationCalibrationString == "none") { out.orientationCalibration = Calibration::OrientationCalibration::NONE; } else if (orientationCalibrationString == "interpolated") { @@ -1243,36 +1243,36 @@ void TouchInputMapper::parseCalibration() { out.orientationCalibration = Calibration::OrientationCalibration::VECTOR; } else if (orientationCalibrationString != "default") { ALOGW("Invalid value for touch.orientation.calibration: '%s'", - orientationCalibrationString.string()); + orientationCalibrationString.c_str()); } } // Distance out.distanceCalibration = Calibration::DistanceCalibration::DEFAULT; - String8 distanceCalibrationString; - if (in.tryGetProperty(String8("touch.distance.calibration"), distanceCalibrationString)) { + std::string distanceCalibrationString; + if (in.tryGetProperty("touch.distance.calibration", distanceCalibrationString)) { if (distanceCalibrationString == "none") { out.distanceCalibration = Calibration::DistanceCalibration::NONE; } else if (distanceCalibrationString == "scaled") { out.distanceCalibration = Calibration::DistanceCalibration::SCALED; } else if (distanceCalibrationString != "default") { ALOGW("Invalid value for touch.distance.calibration: '%s'", - distanceCalibrationString.string()); + distanceCalibrationString.c_str()); } } - out.haveDistanceScale = in.tryGetProperty(String8("touch.distance.scale"), out.distanceScale); + out.haveDistanceScale = in.tryGetProperty("touch.distance.scale", out.distanceScale); out.coverageCalibration = Calibration::CoverageCalibration::DEFAULT; - String8 coverageCalibrationString; - if (in.tryGetProperty(String8("touch.coverage.calibration"), coverageCalibrationString)) { + std::string coverageCalibrationString; + if (in.tryGetProperty("touch.coverage.calibration", coverageCalibrationString)) { if (coverageCalibrationString == "none") { out.coverageCalibration = Calibration::CoverageCalibration::NONE; } else if (coverageCalibrationString == "box") { out.coverageCalibration = Calibration::CoverageCalibration::BOX; } else if (coverageCalibrationString != "default") { ALOGW("Invalid value for touch.coverage.calibration: '%s'", - coverageCalibrationString.string()); + coverageCalibrationString.c_str()); } } } diff --git a/services/inputflinger/tests/InputReader_test.cpp b/services/inputflinger/tests/InputReader_test.cpp index 901b4deac6..0fdffdfdef 100644 --- a/services/inputflinger/tests/InputReader_test.cpp +++ b/services/inputflinger/tests/InputReader_test.cpp @@ -546,7 +546,7 @@ public: enqueueEvent(ARBITRARY_TIME, READ_TIME, 0, EventHubInterface::FINISHED_DEVICE_SCAN, 0, 0); } - void addConfigurationProperty(int32_t deviceId, const String8& key, const String8& value) { + void addConfigurationProperty(int32_t deviceId, const char* key, const char* value) { Device* device = getDevice(deviceId); device->configuration.addProperty(key, value); } @@ -2731,7 +2731,7 @@ TEST_F(InputDeviceTest, WhenNoMappersAreRegistered_DeviceIsIgnored) { TEST_F(InputDeviceTest, WhenMappersAreRegistered_DeviceIsNotIgnoredAndForwardsRequestsToMappers) { // Configuration. - mFakeEventHub->addConfigurationProperty(EVENTHUB_ID, String8("key"), String8("value")); + mFakeEventHub->addConfigurationProperty(EVENTHUB_ID, "key", "value"); FakeInputMapper& mapper1 = mDevice->addMapper<FakeInputMapper>(EVENTHUB_ID, AINPUT_SOURCE_KEYBOARD); @@ -2752,10 +2752,10 @@ TEST_F(InputDeviceTest, WhenMappersAreRegistered_DeviceIsNotIgnoredAndForwardsRe InputReaderConfiguration config; mDevice->configure(ARBITRARY_TIME, &config, 0); - String8 propertyValue; - ASSERT_TRUE(mDevice->getConfiguration().tryGetProperty(String8("key"), propertyValue)) + std::string propertyValue; + ASSERT_TRUE(mDevice->getConfiguration().tryGetProperty("key", propertyValue)) << "Device should have read configuration during configuration phase."; - ASSERT_STREQ("value", propertyValue.string()); + ASSERT_EQ("value", propertyValue); ASSERT_NO_FATAL_FAILURE(mapper1.assertConfigureWasCalled()); ASSERT_NO_FATAL_FAILURE(mapper2.assertConfigureWasCalled()); @@ -2953,7 +2953,7 @@ protected: } void addConfigurationProperty(const char* key, const char* value) { - mFakeEventHub->addConfigurationProperty(EVENTHUB_ID, String8(key), String8(value)); + mFakeEventHub->addConfigurationProperty(EVENTHUB_ID, key, value); } void configureDevice(uint32_t changes) { |