diff options
| -rw-r--r-- | include/input/DisplayViewport.h | 4 | ||||
| -rw-r--r-- | include/input/Input.h | 1 | ||||
| -rw-r--r-- | include/input/InputDevice.h | 24 | ||||
| -rw-r--r-- | include/input/InputTransport.h | 2 | ||||
| -rw-r--r-- | include/input/KeyCharacterMap.h | 7 | ||||
| -rw-r--r-- | include/input/KeyLayoutMap.h | 2 | ||||
| -rw-r--r-- | include/input/Keyboard.h | 19 | ||||
| -rw-r--r-- | include/input/VirtualKeyMap.h | 3 | ||||
| -rw-r--r-- | libs/input/InputDevice.cpp | 62 | ||||
| -rw-r--r-- | libs/input/KeyCharacterMap.cpp | 18 | ||||
| -rw-r--r-- | libs/input/KeyLayoutMap.cpp | 6 | ||||
| -rw-r--r-- | libs/input/Keyboard.cpp | 44 | ||||
| -rw-r--r-- | libs/input/VirtualKeyMap.cpp | 6 | ||||
| -rw-r--r-- | services/inputflinger/EventHub.cpp | 156 | ||||
| -rw-r--r-- | services/inputflinger/EventHub.h | 18 | ||||
| -rw-r--r-- | services/inputflinger/InputApplication.h | 2 | ||||
| -rw-r--r-- | services/inputflinger/InputManager.h | 1 | ||||
| -rw-r--r-- | services/inputflinger/InputReader.cpp | 59 | ||||
| -rw-r--r-- | services/inputflinger/InputReader.h | 18 | ||||
| -rw-r--r-- | services/inputflinger/host/InputDriver.cpp | 10 | ||||
| -rw-r--r-- | services/inputflinger/tests/InputReader_test.cpp | 74 |
21 files changed, 276 insertions, 260 deletions
diff --git a/include/input/DisplayViewport.h b/include/input/DisplayViewport.h index 86da4d38e8..0f336dd2b8 100644 --- a/include/input/DisplayViewport.h +++ b/include/input/DisplayViewport.h @@ -39,13 +39,13 @@ struct DisplayViewport { int32_t physicalBottom; int32_t deviceWidth; int32_t deviceHeight; - String8 uniqueId; + std::string uniqueId; DisplayViewport() : displayId(ADISPLAY_ID_NONE), orientation(DISPLAY_ORIENTATION_0), logicalLeft(0), logicalTop(0), logicalRight(0), logicalBottom(0), physicalLeft(0), physicalTop(0), physicalRight(0), physicalBottom(0), - deviceWidth(0), deviceHeight(0) { + deviceWidth(0), deviceHeight(0), uniqueId() { } bool operator==(const DisplayViewport& other) const { diff --git a/include/input/Input.h b/include/input/Input.h index 7c4379eda1..819a89f37c 100644 --- a/include/input/Input.h +++ b/include/input/Input.h @@ -25,7 +25,6 @@ #include <utils/BitSet.h> #include <utils/KeyedVector.h> #include <utils/RefBase.h> -#include <utils/String8.h> #include <utils/Timers.h> #include <utils/Vector.h> #include <stdint.h> diff --git a/include/input/InputDevice.h b/include/input/InputDevice.h index 1ea69d352d..34d164c280 100644 --- a/include/input/InputDevice.h +++ b/include/input/InputDevice.h @@ -31,9 +31,9 @@ struct InputDeviceIdentifier { } // Information provided by the kernel. - String8 name; - String8 location; - String8 uniqueId; + std::string name; + std::string location; + std::string uniqueId; uint16_t bus; uint16_t vendor; uint16_t product; @@ -45,7 +45,7 @@ struct InputDeviceIdentifier { // It is hashed from whatever kernel provided information is available. // Ideally, the way this value is computed should not change between Android releases // because that would invalidate persistent settings that rely on it. - String8 descriptor; + std::string descriptor; // A value added to uniquely identify a device in the absence of a unique id. This // is intended to be a minimum way to distinguish from other active devices and may @@ -73,16 +73,16 @@ public: }; void initialize(int32_t id, int32_t generation, int32_t controllerNumber, - const InputDeviceIdentifier& identifier, const String8& alias, bool isExternal, + const InputDeviceIdentifier& identifier, const std::string& alias, bool isExternal, bool hasMic); inline int32_t getId() const { return mId; } inline int32_t getControllerNumber() const { return mControllerNumber; } inline int32_t getGeneration() const { return mGeneration; } inline const InputDeviceIdentifier& getIdentifier() const { return mIdentifier; } - inline const String8& getAlias() const { return mAlias; } - inline const String8& getDisplayName() const { - return mAlias.isEmpty() ? mIdentifier.name : mAlias; + inline const std::string& getAlias() const { return mAlias; } + inline const std::string& getDisplayName() const { + return mAlias.empty() ? mIdentifier.name : mAlias; } inline bool isExternal() const { return mIsExternal; } inline bool hasMic() const { return mHasMic; } @@ -121,7 +121,7 @@ private: int32_t mGeneration; int32_t mControllerNumber; InputDeviceIdentifier mIdentifier; - String8 mAlias; + std::string mAlias; bool mIsExternal; bool mHasMic; uint32_t mSources; @@ -149,7 +149,7 @@ enum InputDeviceConfigurationFileType { * * Returns an empty string if not found. */ -extern String8 getInputDeviceConfigurationFilePathByDeviceIdentifier( +extern std::string getInputDeviceConfigurationFilePathByDeviceIdentifier( const InputDeviceIdentifier& deviceIdentifier, InputDeviceConfigurationFileType type); @@ -162,8 +162,8 @@ extern String8 getInputDeviceConfigurationFilePathByDeviceIdentifier( * * Returns an empty string if not found. */ -extern String8 getInputDeviceConfigurationFilePathByName( - const String8& name, InputDeviceConfigurationFileType type); +extern std::string getInputDeviceConfigurationFilePathByName( + const std::string& name, InputDeviceConfigurationFileType type); } // namespace android diff --git a/include/input/InputTransport.h b/include/input/InputTransport.h index e8d1345096..5fd86b48f7 100644 --- a/include/input/InputTransport.h +++ b/include/input/InputTransport.h @@ -27,6 +27,8 @@ * The InputConsumer is used by the application to receive events from the input dispatcher. */ +#include <string> + #include <input/Input.h> #include <utils/Errors.h> #include <utils/Timers.h> diff --git a/include/input/KeyCharacterMap.h b/include/input/KeyCharacterMap.h index 33d2757ec8..9f4559f53c 100644 --- a/include/input/KeyCharacterMap.h +++ b/include/input/KeyCharacterMap.h @@ -27,7 +27,6 @@ #include <utils/Errors.h> #include <utils/KeyedVector.h> #include <utils/Tokenizer.h> -#include <utils/String8.h> #include <utils/Unicode.h> #include <utils/RefBase.h> @@ -75,10 +74,10 @@ public: }; /* Loads a key character map from a file. */ - static status_t load(const String8& filename, Format format, sp<KeyCharacterMap>* outMap); + static status_t load(const std::string& filename, Format format, sp<KeyCharacterMap>* outMap); /* Loads a key character map from its string contents. */ - static status_t loadContents(const String8& filename, + static status_t loadContents(const std::string& filename, const char* contents, Format format, sp<KeyCharacterMap>* outMap); /* Combines a base key character map and an overlay. */ @@ -221,7 +220,7 @@ private: status_t parseKey(); status_t parseKeyProperty(); status_t finishKey(Key* key); - 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); }; diff --git a/include/input/KeyLayoutMap.h b/include/input/KeyLayoutMap.h index 1e8de7173b..73815fe8b4 100644 --- a/include/input/KeyLayoutMap.h +++ b/include/input/KeyLayoutMap.h @@ -62,7 +62,7 @@ struct AxisInfo { */ class KeyLayoutMap : public RefBase { public: - static status_t load(const String8& filename, sp<KeyLayoutMap>* outMap); + static status_t load(const std::string& filename, sp<KeyLayoutMap>* outMap); status_t mapKey(int32_t scanCode, int32_t usageCode, int32_t* outKeyCode, uint32_t* outFlags) const; diff --git a/include/input/Keyboard.h b/include/input/Keyboard.h index d4903e98df..8b66f693cc 100644 --- a/include/input/Keyboard.h +++ b/include/input/Keyboard.h @@ -21,7 +21,6 @@ #include <input/InputDevice.h> #include <input/InputEventLabels.h> #include <utils/Errors.h> -#include <utils/String8.h> #include <utils/PropertyMap.h> namespace android { @@ -43,10 +42,10 @@ class KeyCharacterMap; */ class KeyMap { public: - String8 keyLayoutFile; + std::string keyLayoutFile; sp<KeyLayoutMap> keyLayoutMap; - String8 keyCharacterMapFile; + std::string keyCharacterMapFile; sp<KeyCharacterMap> keyCharacterMap; KeyMap(); @@ -56,11 +55,11 @@ public: const PropertyMap* deviceConfiguration); inline bool haveKeyLayout() const { - return !keyLayoutFile.isEmpty(); + return !keyLayoutFile.empty(); } inline bool haveKeyCharacterMap() const { - return !keyCharacterMapFile.isEmpty(); + return !keyCharacterMapFile.empty(); } inline bool isComplete() const { @@ -68,12 +67,12 @@ public: } private: - bool probeKeyMap(const InputDeviceIdentifier& deviceIdentifier, const String8& name); - status_t loadKeyLayout(const InputDeviceIdentifier& deviceIdentifier, const String8& name); + bool probeKeyMap(const InputDeviceIdentifier& deviceIdentifier, const std::string& name); + status_t loadKeyLayout(const InputDeviceIdentifier& deviceIdentifier, const std::string& name); status_t loadKeyCharacterMap(const InputDeviceIdentifier& deviceIdentifier, - const String8& name); - String8 getPath(const InputDeviceIdentifier& deviceIdentifier, - const String8& name, InputDeviceConfigurationFileType type); + const std::string& name); + std::string getPath(const InputDeviceIdentifier& deviceIdentifier, + const std::string& name, InputDeviceConfigurationFileType type); }; /** diff --git a/include/input/VirtualKeyMap.h b/include/input/VirtualKeyMap.h index e245ead682..24e0e0ed9e 100644 --- a/include/input/VirtualKeyMap.h +++ b/include/input/VirtualKeyMap.h @@ -23,7 +23,6 @@ #include <utils/Errors.h> #include <utils/KeyedVector.h> #include <utils/Tokenizer.h> -#include <utils/String8.h> #include <utils/Unicode.h> namespace android { @@ -50,7 +49,7 @@ class VirtualKeyMap { public: ~VirtualKeyMap(); - static status_t load(const String8& filename, VirtualKeyMap** outMap); + static status_t load(const std::string& filename, VirtualKeyMap** outMap); inline const Vector<VirtualKeyDefinition>& getVirtualKeys() const { return mVirtualKeys; diff --git a/libs/input/InputDevice.cpp b/libs/input/InputDevice.cpp index 5d27bf687d..778c4539fa 100644 --- a/libs/input/InputDevice.cpp +++ b/libs/input/InputDevice.cpp @@ -20,9 +20,12 @@ #include <unistd.h> #include <ctype.h> +#include <android-base/stringprintf.h> #include <input/InputDevice.h> #include <input/InputEventLabels.h> +using android::base::StringPrintf; + namespace android { static const char* CONFIGURATION_FILE_DIR[] = { @@ -41,8 +44,8 @@ static bool isValidNameChar(char ch) { return isascii(ch) && (isdigit(ch) || isalpha(ch) || ch == '-' || ch == '_'); } -static void appendInputDeviceConfigurationFileRelativePath(String8& path, - const String8& name, InputDeviceConfigurationFileType type) { +static void appendInputDeviceConfigurationFileRelativePath(std::string& path, + const std::string& name, InputDeviceConfigurationFileType type) { path.append(CONFIGURATION_FILE_DIR[type]); for (size_t i = 0; i < name.length(); i++) { char ch = name[i]; @@ -54,28 +57,28 @@ static void appendInputDeviceConfigurationFileRelativePath(String8& path, path.append(CONFIGURATION_FILE_EXTENSION[type]); } -String8 getInputDeviceConfigurationFilePathByDeviceIdentifier( +std::string getInputDeviceConfigurationFilePathByDeviceIdentifier( const InputDeviceIdentifier& deviceIdentifier, InputDeviceConfigurationFileType type) { if (deviceIdentifier.vendor !=0 && deviceIdentifier.product != 0) { if (deviceIdentifier.version != 0) { // Try vendor product version. - String8 versionPath(getInputDeviceConfigurationFilePathByName( - String8::format("Vendor_%04x_Product_%04x_Version_%04x", + std::string versionPath = getInputDeviceConfigurationFilePathByName( + StringPrintf("Vendor_%04x_Product_%04x_Version_%04x", deviceIdentifier.vendor, deviceIdentifier.product, deviceIdentifier.version), - type)); - if (!versionPath.isEmpty()) { + type); + if (!versionPath.empty()) { return versionPath; } } // Try vendor product. - String8 productPath(getInputDeviceConfigurationFilePathByName( - String8::format("Vendor_%04x_Product_%04x", + std::string productPath = getInputDeviceConfigurationFilePathByName( + StringPrintf("Vendor_%04x_Product_%04x", deviceIdentifier.vendor, deviceIdentifier.product), - type)); - if (!productPath.isEmpty()) { + type); + if (!productPath.empty()) { return productPath; } } @@ -84,22 +87,25 @@ String8 getInputDeviceConfigurationFilePathByDeviceIdentifier( return getInputDeviceConfigurationFilePathByName(deviceIdentifier.name, type); } -String8 getInputDeviceConfigurationFilePathByName( - const String8& name, InputDeviceConfigurationFileType type) { +std::string getInputDeviceConfigurationFilePathByName( + const std::string& name, InputDeviceConfigurationFileType type) { // Search system repository. - String8 path; + std::string path; // Treblized input device config files will be located /odm/usr or /vendor/usr. const char *rootsForPartition[] {"/odm", "/vendor", getenv("ANDROID_ROOT")}; for (size_t i = 0; i < size(rootsForPartition); i++) { - path.setTo(rootsForPartition[i]); - path.append("/usr/"); + if (rootsForPartition[i] == nullptr) { + continue; + } + path = rootsForPartition[i]; + path += "/usr/"; appendInputDeviceConfigurationFileRelativePath(path, name, type); #if DEBUG_PROBE ALOGD("Probing for system provided input device configuration file: path='%s'", - path.string()); + path.c_str()); #endif - if (!access(path.string(), R_OK)) { + if (!access(path.c_str(), R_OK)) { #if DEBUG_PROBE ALOGD("Found"); #endif @@ -109,13 +115,17 @@ String8 getInputDeviceConfigurationFilePathByName( // Search user repository. // TODO Should only look here if not in safe mode. - path.setTo(getenv("ANDROID_DATA")); - path.append("/system/devices/"); + path = ""; + char *androidData = getenv("ANDROID_DATA"); + if (androidData != nullptr) { + path += androidData; + } + path += "/system/devices/"; appendInputDeviceConfigurationFileRelativePath(path, name, type); #if DEBUG_PROBE - ALOGD("Probing for system user input device configuration file: path='%s'", path.string()); + ALOGD("Probing for system user input device configuration file: path='%s'", path.c_str()); #endif - if (!access(path.string(), R_OK)) { + if (!access(path.c_str(), R_OK)) { #if DEBUG_PROBE ALOGD("Found"); #endif @@ -125,16 +135,16 @@ String8 getInputDeviceConfigurationFilePathByName( // Not found. #if DEBUG_PROBE ALOGD("Probe failed to find input device configuration file: name='%s', type=%d", - name.string(), type); + name.c_str(), type); #endif - return String8(); + return ""; } // --- InputDeviceInfo --- InputDeviceInfo::InputDeviceInfo() { - initialize(-1, 0, -1, InputDeviceIdentifier(), String8(), false, false); + initialize(-1, 0, -1, InputDeviceIdentifier(), "", false, false); } InputDeviceInfo::InputDeviceInfo(const InputDeviceInfo& other) : @@ -150,7 +160,7 @@ InputDeviceInfo::~InputDeviceInfo() { } void InputDeviceInfo::initialize(int32_t id, int32_t generation, int32_t controllerNumber, - const InputDeviceIdentifier& identifier, const String8& alias, bool isExternal, + const InputDeviceIdentifier& identifier, const std::string& alias, bool isExternal, bool hasMic) { mId = id; mGeneration = generation; diff --git a/libs/input/KeyCharacterMap.cpp b/libs/input/KeyCharacterMap.cpp index 26747bdbbc..e189d20e28 100644 --- a/libs/input/KeyCharacterMap.cpp +++ b/libs/input/KeyCharacterMap.cpp @@ -106,14 +106,14 @@ KeyCharacterMap::~KeyCharacterMap() { } } -status_t KeyCharacterMap::load(const String8& filename, +status_t KeyCharacterMap::load(const std::string& filename, Format format, sp<KeyCharacterMap>* outMap) { outMap->clear(); Tokenizer* tokenizer; - status_t status = Tokenizer::open(filename, &tokenizer); + status_t status = Tokenizer::open(String8(filename.c_str()), &tokenizer); if (status) { - ALOGE("Error %d opening key character map file %s.", status, filename.string()); + ALOGE("Error %d opening key character map file %s.", status, filename.c_str()); } else { status = load(tokenizer, format, outMap); delete tokenizer; @@ -121,12 +121,12 @@ status_t KeyCharacterMap::load(const String8& filename, return status; } -status_t KeyCharacterMap::loadContents(const String8& filename, const char* contents, +status_t KeyCharacterMap::loadContents(const std::string& filename, const char* contents, Format format, sp<KeyCharacterMap>* outMap) { outMap->clear(); Tokenizer* tokenizer; - status_t status = Tokenizer::fromContents(filename, contents, &tokenizer); + status_t status = Tokenizer::fromContents(String8(filename.c_str()), contents, &tokenizer); if (status) { ALOGE("Error %d opening key character map.", status); } else { @@ -944,7 +944,7 @@ status_t KeyCharacterMap::Parser::parseKeyProperty() { properties.add(Property(PROPERTY_NUMBER)); } else { int32_t metaState; - status_t status = parseModifier(token, &metaState); + status_t status = parseModifier(token.string(), &metaState); if (status) { ALOGE("%s: Expected a property name or modifier, got '%s'.", mTokenizer->getLocation().string(), token.string()); @@ -1137,7 +1137,7 @@ status_t KeyCharacterMap::Parser::finishKey(Key* key) { return NO_ERROR; } -status_t KeyCharacterMap::Parser::parseModifier(const String8& token, int32_t* outMetaState) { +status_t KeyCharacterMap::Parser::parseModifier(const std::string& token, int32_t* outMetaState) { if (token == "base") { *outMetaState = 0; return NO_ERROR; @@ -1145,7 +1145,7 @@ status_t KeyCharacterMap::Parser::parseModifier(const String8& token, int32_t* o int32_t combinedMeta = 0; - const char* str = token.string(); + const char* str = token.c_str(); const char* start = str; for (const char* cur = str; ; cur++) { char ch = *cur; @@ -1164,7 +1164,7 @@ status_t KeyCharacterMap::Parser::parseModifier(const String8& token, int32_t* o } if (combinedMeta & metaState) { ALOGE("%s: Duplicate modifier combination '%s'.", - mTokenizer->getLocation().string(), token.string()); + mTokenizer->getLocation().string(), token.c_str()); return BAD_VALUE; } diff --git a/libs/input/KeyLayoutMap.cpp b/libs/input/KeyLayoutMap.cpp index c440078666..88cb0dbdb4 100644 --- a/libs/input/KeyLayoutMap.cpp +++ b/libs/input/KeyLayoutMap.cpp @@ -49,13 +49,13 @@ KeyLayoutMap::KeyLayoutMap() { KeyLayoutMap::~KeyLayoutMap() { } -status_t KeyLayoutMap::load(const String8& filename, sp<KeyLayoutMap>* outMap) { +status_t KeyLayoutMap::load(const std::string& filename, sp<KeyLayoutMap>* outMap) { outMap->clear(); Tokenizer* tokenizer; - status_t status = Tokenizer::open(filename, &tokenizer); + status_t status = Tokenizer::open(String8(filename.c_str()), &tokenizer); if (status) { - ALOGE("Error %d opening key layout map file %s.", status, filename.string()); + ALOGE("Error %d opening key layout map file %s.", status, filename.c_str()); } else { sp<KeyLayoutMap> map = new KeyLayoutMap(); if (!map.get()) { diff --git a/libs/input/Keyboard.cpp b/libs/input/Keyboard.cpp index 11842ee7ff..0c22bfefed 100644 --- a/libs/input/Keyboard.cpp +++ b/libs/input/Keyboard.cpp @@ -45,22 +45,22 @@ status_t KeyMap::load(const InputDeviceIdentifier& deviceIdenfifier, String8 keyLayoutName; if (deviceConfiguration->tryGetProperty(String8("keyboard.layout"), keyLayoutName)) { - status_t status = loadKeyLayout(deviceIdenfifier, keyLayoutName); + status_t status = loadKeyLayout(deviceIdenfifier, keyLayoutName.c_str()); if (status == NAME_NOT_FOUND) { ALOGE("Configuration for keyboard device '%s' requested keyboard layout '%s' but " "it was not found.", - deviceIdenfifier.name.string(), keyLayoutName.string()); + deviceIdenfifier.name.c_str(), keyLayoutName.string()); } } String8 keyCharacterMapName; if (deviceConfiguration->tryGetProperty(String8("keyboard.characterMap"), keyCharacterMapName)) { - status_t status = loadKeyCharacterMap(deviceIdenfifier, keyCharacterMapName); + status_t status = loadKeyCharacterMap(deviceIdenfifier, keyCharacterMapName.c_str()); if (status == NAME_NOT_FOUND) { ALOGE("Configuration for keyboard device '%s' requested keyboard character " "map '%s' but it was not found.", - deviceIdenfifier.name.string(), keyLayoutName.string()); + deviceIdenfifier.name.c_str(), keyLayoutName.string()); } } @@ -70,30 +70,30 @@ status_t KeyMap::load(const InputDeviceIdentifier& deviceIdenfifier, } // Try searching by device identifier. - if (probeKeyMap(deviceIdenfifier, String8::empty())) { + if (probeKeyMap(deviceIdenfifier, "")) { return OK; } // Fall back on the Generic key map. // TODO Apply some additional heuristics here to figure out what kind of // generic key map to use (US English, etc.) for typical external keyboards. - if (probeKeyMap(deviceIdenfifier, String8("Generic"))) { + if (probeKeyMap(deviceIdenfifier, "Generic")) { return OK; } // Try the Virtual key map as a last resort. - if (probeKeyMap(deviceIdenfifier, String8("Virtual"))) { + if (probeKeyMap(deviceIdenfifier, "Virtual")) { return OK; } // Give up! ALOGE("Could not determine key map for device '%s' and no default key maps were found!", - deviceIdenfifier.name.string()); + deviceIdenfifier.name.c_str()); return NAME_NOT_FOUND; } bool KeyMap::probeKeyMap(const InputDeviceIdentifier& deviceIdentifier, - const String8& keyMapName) { + const std::string& keyMapName) { if (!haveKeyLayout()) { loadKeyLayout(deviceIdentifier, keyMapName); } @@ -104,10 +104,10 @@ bool KeyMap::probeKeyMap(const InputDeviceIdentifier& deviceIdentifier, } status_t KeyMap::loadKeyLayout(const InputDeviceIdentifier& deviceIdentifier, - const String8& name) { - String8 path(getPath(deviceIdentifier, name, + const std::string& name) { + std::string path(getPath(deviceIdentifier, name, INPUT_DEVICE_CONFIGURATION_FILE_TYPE_KEY_LAYOUT)); - if (path.isEmpty()) { + if (path.empty()) { return NAME_NOT_FOUND; } @@ -116,15 +116,15 @@ status_t KeyMap::loadKeyLayout(const InputDeviceIdentifier& deviceIdentifier, return status; } - keyLayoutFile.setTo(path); + keyLayoutFile = path; return OK; } status_t KeyMap::loadKeyCharacterMap(const InputDeviceIdentifier& deviceIdentifier, - const String8& name) { - String8 path(getPath(deviceIdentifier, name, - INPUT_DEVICE_CONFIGURATION_FILE_TYPE_KEY_CHARACTER_MAP)); - if (path.isEmpty()) { + const std::string& name) { + std::string path = getPath(deviceIdentifier, name, + INPUT_DEVICE_CONFIGURATION_FILE_TYPE_KEY_CHARACTER_MAP); + if (path.empty()) { return NAME_NOT_FOUND; } @@ -134,13 +134,13 @@ status_t KeyMap::loadKeyCharacterMap(const InputDeviceIdentifier& deviceIdentifi return status; } - keyCharacterMapFile.setTo(path); + keyCharacterMapFile = path; return OK; } -String8 KeyMap::getPath(const InputDeviceIdentifier& deviceIdentifier, - const String8& name, InputDeviceConfigurationFileType type) { - return name.isEmpty() +std::string KeyMap::getPath(const InputDeviceIdentifier& deviceIdentifier, + const std::string& name, InputDeviceConfigurationFileType type) { + return name.empty() ? getInputDeviceConfigurationFilePathByDeviceIdentifier(deviceIdentifier, type) : getInputDeviceConfigurationFilePathByName(name, type); } @@ -174,7 +174,7 @@ bool isEligibleBuiltInKeyboard(const InputDeviceIdentifier& deviceIdentifier, } } - return strstr(deviceIdentifier.name.string(), "-keypad"); + return strstr(deviceIdentifier.name.c_str(), "-keypad"); } static int32_t setEphemeralMetaState(int32_t mask, bool down, int32_t oldMetaState) { diff --git a/libs/input/VirtualKeyMap.cpp b/libs/input/VirtualKeyMap.cpp index 993297319e..3ec53bf5a0 100644 --- a/libs/input/VirtualKeyMap.cpp +++ b/libs/input/VirtualKeyMap.cpp @@ -46,13 +46,13 @@ VirtualKeyMap::VirtualKeyMap() { VirtualKeyMap::~VirtualKeyMap() { } -status_t VirtualKeyMap::load(const String8& filename, VirtualKeyMap** outMap) { +status_t VirtualKeyMap::load(const std::string& filename, VirtualKeyMap** outMap) { *outMap = nullptr; Tokenizer* tokenizer; - status_t status = Tokenizer::open(filename, &tokenizer); + status_t status = Tokenizer::open(String8(filename.c_str()), &tokenizer); if (status) { - ALOGE("Error %d opening virtual key map file %s.", status, filename.string()); + ALOGE("Error %d opening virtual key map file %s.", status, filename.c_str()); } else { VirtualKeyMap* map = new VirtualKeyMap(); if (!map) { diff --git a/services/inputflinger/EventHub.cpp b/services/inputflinger/EventHub.cpp index 77a474fa82..a964d29489 100644 --- a/services/inputflinger/EventHub.cpp +++ b/services/inputflinger/EventHub.cpp @@ -76,16 +76,16 @@ static inline const char* toString(bool value) { return value ? "true" : "false"; } -static String8 sha1(const String8& in) { +static std::string sha1(const std::string& in) { SHA_CTX ctx; SHA1_Init(&ctx); - SHA1_Update(&ctx, reinterpret_cast<const u_char*>(in.string()), in.size()); + SHA1_Update(&ctx, reinterpret_cast<const u_char*>(in.c_str()), in.size()); u_char digest[SHA_DIGEST_LENGTH]; SHA1_Final(digest, &ctx); - String8 out; + std::string out; for (size_t i = 0; i < SHA_DIGEST_LENGTH; i++) { - out.appendFormat("%02x", digest[i]); + out += StringPrintf("%02x", digest[i]); } return out; } @@ -141,7 +141,7 @@ uint32_t getAbsAxisUsage(int32_t axis, uint32_t deviceClasses) { // --- EventHub::Device --- -EventHub::Device::Device(int fd, int32_t id, const String8& path, +EventHub::Device::Device(int fd, int32_t id, const std::string& path, const InputDeviceIdentifier& identifier) : next(nullptr), fd(fd), id(id), path(path), identifier(identifier), @@ -172,9 +172,9 @@ void EventHub::Device::close() { } status_t EventHub::Device::enable() { - fd = open(path, O_RDWR | O_CLOEXEC | O_NONBLOCK); + fd = open(path.c_str(), O_RDWR | O_CLOEXEC | O_NONBLOCK); if(fd < 0) { - ALOGE("could not open %s, %s\n", path.string(), strerror(errno)); + ALOGE("could not open %s, %s\n", path.c_str(), strerror(errno)); return -errno; } enabled = true; @@ -307,7 +307,7 @@ status_t EventHub::getAbsoluteAxisInfo(int32_t deviceId, int axis, struct input_absinfo info; if(ioctl(device->fd, EVIOCGABS(axis), &info)) { ALOGW("Error reading absolute controller %d for device %s fd %d, errno=%d", - axis, device->identifier.name.string(), device->fd, errno); + axis, device->identifier.name.c_str(), device->fd, errno); return -errno; } @@ -416,7 +416,7 @@ status_t EventHub::getAbsoluteAxisValue(int32_t deviceId, int32_t axis, int32_t* struct input_absinfo info; if(ioctl(device->fd, EVIOCGABS(axis), &info)) { ALOGW("Error reading absolute controller %d for device %s fd %d, errno=%d", - axis, device->identifier.name.string(), device->fd, errno); + axis, device->identifier.name.c_str(), device->fd, errno); return -errno; } @@ -512,7 +512,7 @@ status_t EventHub::mapAxis(int32_t deviceId, int32_t scanCode, AxisInfo* outAxis return NAME_NOT_FOUND; } -void EventHub::setExcludedDevices(const Vector<String8>& devices) { +void EventHub::setExcludedDevices(const std::vector<std::string>& devices) { AutoMutex _l(mLock); mExcludedDevices = devices; @@ -599,16 +599,16 @@ bool EventHub::setKeyboardLayoutOverlay(int32_t deviceId, return false; } -static String8 generateDescriptor(InputDeviceIdentifier& identifier) { - String8 rawDescriptor; - rawDescriptor.appendFormat(":%04x:%04x:", identifier.vendor, +static std::string generateDescriptor(InputDeviceIdentifier& identifier) { + std::string rawDescriptor; + rawDescriptor += StringPrintf(":%04x:%04x:", identifier.vendor, identifier.product); // TODO add handling for USB devices to not uniqueify kbs that show up twice - if (!identifier.uniqueId.isEmpty()) { - rawDescriptor.append("uniqueId:"); - rawDescriptor.append(identifier.uniqueId); + if (!identifier.uniqueId.empty()) { + rawDescriptor += "uniqueId:"; + rawDescriptor += identifier.uniqueId; } else if (identifier.nonce != 0) { - rawDescriptor.appendFormat("nonce:%04x", identifier.nonce); + rawDescriptor += StringPrintf("nonce:%04x", identifier.nonce); } if (identifier.vendor == 0 && identifier.product == 0) { @@ -616,12 +616,12 @@ static String8 generateDescriptor(InputDeviceIdentifier& identifier) { // built-in so we need to rely on other information to uniquely identify // the input device. Usually we try to avoid relying on the device name or // location but for built-in input device, they are unlikely to ever change. - if (!identifier.name.isEmpty()) { - rawDescriptor.append("name:"); - rawDescriptor.append(identifier.name); - } else if (!identifier.location.isEmpty()) { - rawDescriptor.append("location:"); - rawDescriptor.append(identifier.location); + if (!identifier.name.empty()) { + rawDescriptor += "name:"; + rawDescriptor += identifier.name; + } else if (!identifier.location.empty()) { + rawDescriptor += "location:"; + rawDescriptor += identifier.location; } } identifier.descriptor = sha1(rawDescriptor); @@ -637,8 +637,8 @@ void EventHub::assignDescriptorLocked(InputDeviceIdentifier& identifier) { // Ideally, we also want the descriptor to be short and relatively opaque. identifier.nonce = 0; - String8 rawDescriptor = generateDescriptor(identifier); - if (identifier.uniqueId.isEmpty()) { + std::string rawDescriptor = generateDescriptor(identifier); + if (identifier.uniqueId.empty()) { // If it didn't have a unique id check for conflicts and enforce // uniqueness if necessary. while(getDeviceByDescriptorLocked(identifier.descriptor) != nullptr) { @@ -646,8 +646,8 @@ void EventHub::assignDescriptorLocked(InputDeviceIdentifier& identifier) { rawDescriptor = generateDescriptor(identifier); } } - ALOGV("Created descriptor: raw=%s, cooked=%s", rawDescriptor.string(), - identifier.descriptor.string()); + ALOGV("Created descriptor: raw=%s, cooked=%s", rawDescriptor.c_str(), + identifier.descriptor.c_str()); } void EventHub::vibrate(int32_t deviceId, nsecs_t duration) { @@ -664,7 +664,7 @@ void EventHub::vibrate(int32_t deviceId, nsecs_t duration) { effect.replay.delay = 0; if (ioctl(device->fd, EVIOCSFF, &effect)) { ALOGW("Could not upload force feedback effect to device %s due to error %d.", - device->identifier.name.string(), errno); + device->identifier.name.c_str(), errno); return; } device->ffEffectId = effect.id; @@ -677,7 +677,7 @@ void EventHub::vibrate(int32_t deviceId, nsecs_t duration) { ev.value = 1; if (write(device->fd, &ev, sizeof(ev)) != sizeof(ev)) { ALOGW("Could not start force feedback effect on device %s due to error %d.", - device->identifier.name.string(), errno); + device->identifier.name.c_str(), errno); return; } device->ffEffectPlaying = true; @@ -699,18 +699,18 @@ void EventHub::cancelVibrate(int32_t deviceId) { ev.value = 0; if (write(device->fd, &ev, sizeof(ev)) != sizeof(ev)) { ALOGW("Could not stop force feedback effect on device %s due to error %d.", - device->identifier.name.string(), errno); + device->identifier.name.c_str(), errno); return; } } } } -EventHub::Device* EventHub::getDeviceByDescriptorLocked(String8& descriptor) const { +EventHub::Device* EventHub::getDeviceByDescriptorLocked(const std::string& descriptor) const { size_t size = mDevices.size(); for (size_t i = 0; i < size; i++) { Device* device = mDevices.valueAt(i); - if (descriptor.compare(device->identifier.descriptor) == 0) { + if (descriptor == device->identifier.descriptor) { return device; } } @@ -763,7 +763,7 @@ size_t EventHub::getEvents(int timeoutMillis, RawEvent* buffer, size_t bufferSiz while (mClosingDevices) { Device* device = mClosingDevices; ALOGV("Reporting device closed: id=%d, name=%s\n", - device->id, device->path.string()); + device->id, device->path.c_str()); mClosingDevices = device->next; event->when = now; event->deviceId = device->id == mBuiltInKeyboardId ? BUILT_IN_KEYBOARD_ID : device->id; @@ -785,7 +785,7 @@ size_t EventHub::getEvents(int timeoutMillis, RawEvent* buffer, size_t bufferSiz while (mOpeningDevices != nullptr) { Device* device = mOpeningDevices; ALOGV("Reporting device opened: id=%d, name=%s\n", - device->id, device->path.string()); + device->id, device->path.c_str()); mOpeningDevices = device->next; event->when = now; event->deviceId = device->id == mBuiltInKeyboardId ? 0 : device->id; @@ -867,7 +867,7 @@ size_t EventHub::getEvents(int timeoutMillis, RawEvent* buffer, size_t bufferSiz for (size_t i = 0; i < count; i++) { struct input_event& iev = readBuffer[i]; ALOGV("%s got: time=%d.%06d, type=%d, code=%d, value=%d", - device->path.string(), + device->path.c_str(), (int) iev.time.tv_sec, (int) iev.time.tv_usec, iev.type, iev.code, iev.value); @@ -936,7 +936,7 @@ size_t EventHub::getEvents(int timeoutMillis, RawEvent* buffer, size_t bufferSiz "event time %" PRId64 ", current time %" PRId64 ", call time %" PRId64 ". " "Using current time instead.", - device->path.string(), event->when, time, now); + device->path.c_str(), event->when, time, now); event->when = time; } else { ALOGV("Event time is ok but failed the fast path and required " @@ -962,12 +962,12 @@ size_t EventHub::getEvents(int timeoutMillis, RawEvent* buffer, size_t bufferSiz } } else if (eventItem.events & EPOLLHUP) { ALOGI("Removing device %s due to epoll hang-up event.", - device->identifier.name.string()); + device->identifier.name.c_str()); deviceChanged = true; closeDeviceLocked(device); } else { ALOGW("Received unexpected epoll event 0x%08x for device %s.", - eventItem.events, device->identifier.name.string()); + eventItem.events, device->identifier.name.c_str()); } } @@ -1125,14 +1125,14 @@ status_t EventHub::openDeviceLocked(const char *devicePath) { //fprintf(stderr, "could not get device name for %s, %s\n", devicePath, strerror(errno)); } else { buffer[sizeof(buffer) - 1] = '\0'; - identifier.name.setTo(buffer); + identifier.name = buffer; } // Check to see if the device is on our excluded list for (size_t i = 0; i < mExcludedDevices.size(); i++) { - const String8& item = mExcludedDevices.itemAt(i); + const std::string& item = mExcludedDevices[i]; if (identifier.name == item) { - ALOGI("ignoring event id %s driver %s\n", devicePath, item.string()); + ALOGI("ignoring event id %s driver %s\n", devicePath, item.c_str()); close(fd); return -1; } @@ -1163,7 +1163,7 @@ status_t EventHub::openDeviceLocked(const char *devicePath) { //fprintf(stderr, "could not get location for %s, %s\n", devicePath, strerror(errno)); } else { buffer[sizeof(buffer) - 1] = '\0'; - identifier.location.setTo(buffer); + identifier.location = buffer; } // Get device unique id. @@ -1171,7 +1171,7 @@ status_t EventHub::openDeviceLocked(const char *devicePath) { //fprintf(stderr, "could not get idstring for %s, %s\n", devicePath, strerror(errno)); } else { buffer[sizeof(buffer) - 1] = '\0'; - identifier.uniqueId.setTo(buffer); + identifier.uniqueId = buffer; } // Fill in the descriptor. @@ -1179,7 +1179,7 @@ status_t EventHub::openDeviceLocked(const char *devicePath) { // Allocate device. (The device object takes ownership of the fd at this point.) int32_t deviceId = mNextDeviceId++; - Device* device = new Device(fd, deviceId, String8(devicePath), identifier); + Device* device = new Device(fd, deviceId, devicePath, identifier); ALOGV("add device %d: %s\n", deviceId, devicePath); ALOGV(" bus: %04x\n" @@ -1187,10 +1187,10 @@ status_t EventHub::openDeviceLocked(const char *devicePath) { " product %04x\n" " version %04x\n", identifier.bus, identifier.vendor, identifier.product, identifier.version); - ALOGV(" name: \"%s\"\n", identifier.name.string()); - ALOGV(" location: \"%s\"\n", identifier.location.string()); - ALOGV(" unique id: \"%s\"\n", identifier.uniqueId.string()); - ALOGV(" descriptor: \"%s\"\n", identifier.descriptor.string()); + ALOGV(" name: \"%s\"\n", identifier.name.c_str()); + ALOGV(" location: \"%s\"\n", identifier.location.c_str()); + ALOGV(" unique id: \"%s\"\n", identifier.uniqueId.c_str()); + ALOGV(" descriptor: \"%s\"\n", identifier.descriptor.c_str()); ALOGV(" driver: v%d.%d.%d\n", driverVersion >> 16, (driverVersion >> 8) & 0xff, driverVersion & 0xff); @@ -1343,7 +1343,7 @@ status_t EventHub::openDeviceLocked(const char *devicePath) { // If the device isn't recognized as something we handle, don't monitor it. if (device->classes == 0) { ALOGV("Dropping device: id=%d, path='%s', name='%s'", - deviceId, devicePath, device->identifier.name.string()); + deviceId, devicePath, device->identifier.name.c_str()); delete device; return -1; } @@ -1374,11 +1374,11 @@ status_t EventHub::openDeviceLocked(const char *devicePath) { ALOGI("New device: id=%d, fd=%d, path='%s', name='%s', classes=0x%x, " "configuration='%s', keyLayout='%s', keyCharacterMap='%s', builtinKeyboard=%s, ", - deviceId, fd, devicePath, device->identifier.name.string(), + deviceId, fd, devicePath, device->identifier.name.c_str(), device->classes, - device->configurationFile.string(), - device->keyMap.keyLayoutFile.string(), - device->keyMap.keyCharacterMapFile.string(), + device->configurationFile.c_str(), + device->keyMap.keyLayoutFile.c_str(), + device->keyMap.keyCharacterMapFile.c_str(), toString(mBuiltInKeyboardId == deviceId)); addDeviceLocked(device); @@ -1392,11 +1392,11 @@ void EventHub::configureFd(Device* device) { unsigned int repeatRate[] = {0, 0}; if (ioctl(device->fd, EVIOCSREP, repeatRate)) { ALOGW("Unable to disable kernel key repeat for %s: %s", - device->path.string(), strerror(errno)); + device->path.c_str(), strerror(errno)); } } - String8 wakeMechanism("EPOLLWAKEUP"); + std::string wakeMechanism = "EPOLLWAKEUP"; if (!mUsingEpollWakeup) { #ifndef EVIOCSSUSPENDBLOCK // uapi headers don't include EVIOCSSUSPENDBLOCK, and future kernels @@ -1416,7 +1416,7 @@ void EventHub::configureFd(Device* device) { // clock. int clockId = CLOCK_MONOTONIC; bool usingClockIoctl = !ioctl(device->fd, EVIOCSCLOCKID, &clockId); - ALOGI("wakeMechanism=%s, usingClockIoctl=%s", wakeMechanism.string(), + ALOGI("wakeMechanism=%s, usingClockIoctl=%s", wakeMechanism.c_str(), toString(usingClockIoctl)); } @@ -1473,7 +1473,7 @@ void EventHub::createVirtualKeyboardLocked() { identifier.uniqueId = "<virtual>"; assignDescriptorLocked(identifier); - Device* device = new Device(-1, VIRTUAL_KEYBOARD_ID, String8("<virtual>"), identifier); + Device* device = new Device(-1, VIRTUAL_KEYBOARD_ID, "<virtual>", identifier); device->classes = INPUT_DEVICE_CLASS_KEYBOARD | INPUT_DEVICE_CLASS_ALPHAKEY | INPUT_DEVICE_CLASS_DPAD @@ -1491,26 +1491,26 @@ void EventHub::addDeviceLocked(Device* device) { void EventHub::loadConfigurationLocked(Device* device) { device->configurationFile = getInputDeviceConfigurationFilePathByDeviceIdentifier( device->identifier, INPUT_DEVICE_CONFIGURATION_FILE_TYPE_CONFIGURATION); - if (device->configurationFile.isEmpty()) { + if (device->configurationFile.empty()) { ALOGD("No input device configuration file found for device '%s'.", - device->identifier.name.string()); + device->identifier.name.c_str()); } else { - status_t status = PropertyMap::load(device->configurationFile, + status_t status = PropertyMap::load(String8(device->configurationFile.c_str()), &device->configuration); if (status) { ALOGE("Error loading input device configuration file for device '%s'. " "Using default configuration.", - device->identifier.name.string()); + device->identifier.name.c_str()); } } } status_t EventHub::loadVirtualKeyMapLocked(Device* device) { // The virtual key map is supplied by the kernel as a system board property file. - String8 path; - path.append("/sys/board_properties/virtualkeys."); - path.append(device->identifier.name); - if (access(path.string(), R_OK)) { + std::string path; + path += "/sys/board_properties/virtualkeys."; + path += device->identifier.name; + if (access(path.c_str(), R_OK)) { return NAME_NOT_FOUND; } return VirtualKeyMap::load(path, &device->virtualKeyMap); @@ -1543,7 +1543,7 @@ bool EventHub::deviceHasMicLocked(Device* device) { int32_t EventHub::getNextControllerNumberLocked(Device* device) { if (mControllerNumbers.isFull()) { ALOGI("Maximum number of controllers reached, assigning controller number 0 to device %s", - device->identifier.name.string()); + device->identifier.name.c_str()); return 0; } // Since the controller number 0 is reserved for non-controllers, translate all numbers up by @@ -1617,12 +1617,12 @@ void EventHub::closeAllDevicesLocked() { void EventHub::closeDeviceLocked(Device* device) { ALOGI("Removed device: path=%s name=%s id=%d fd=%d classes=0x%x\n", - device->path.string(), device->identifier.name.string(), device->id, + device->path.c_str(), device->identifier.name.c_str(), device->id, device->fd, device->classes); if (device->id == mBuiltInKeyboardId) { ALOGW("built-in keyboard device %s (id=%d) is closing! the apps will not like this", - device->path.string(), mBuiltInKeyboardId); + device->path.c_str(), mBuiltInKeyboardId); mBuiltInKeyboardId = NO_BUILT_IN_KEYBOARD; } @@ -1648,7 +1648,7 @@ void EventHub::closeDeviceLocked(Device* device) { // Unlink the device from the opening devices list then delete it. // We don't need to tell the client that the device was closed because // it does not even know it was opened in the first place. - ALOGI("Device %s was immediately closed after opening.", device->path.string()); + ALOGI("Device %s was immediately closed after opening.", device->path.c_str()); if (pred) { pred->next = device->next; } else { @@ -1750,28 +1750,28 @@ void EventHub::dump(std::string& dump) { const Device* device = mDevices.valueAt(i); if (mBuiltInKeyboardId == device->id) { dump += StringPrintf(INDENT2 "%d: %s (aka device 0 - built-in keyboard)\n", - device->id, device->identifier.name.string()); + device->id, device->identifier.name.c_str()); } else { dump += StringPrintf(INDENT2 "%d: %s\n", device->id, - device->identifier.name.string()); + device->identifier.name.c_str()); } dump += StringPrintf(INDENT3 "Classes: 0x%08x\n", device->classes); - dump += StringPrintf(INDENT3 "Path: %s\n", device->path.string()); + dump += StringPrintf(INDENT3 "Path: %s\n", device->path.c_str()); dump += StringPrintf(INDENT3 "Enabled: %s\n", toString(device->enabled)); - dump += StringPrintf(INDENT3 "Descriptor: %s\n", device->identifier.descriptor.string()); - dump += StringPrintf(INDENT3 "Location: %s\n", device->identifier.location.string()); + dump += StringPrintf(INDENT3 "Descriptor: %s\n", device->identifier.descriptor.c_str()); + dump += StringPrintf(INDENT3 "Location: %s\n", device->identifier.location.c_str()); dump += StringPrintf(INDENT3 "ControllerNumber: %d\n", device->controllerNumber); - dump += StringPrintf(INDENT3 "UniqueId: %s\n", device->identifier.uniqueId.string()); + dump += StringPrintf(INDENT3 "UniqueId: %s\n", device->identifier.uniqueId.c_str()); dump += StringPrintf(INDENT3 "Identifier: bus=0x%04x, vendor=0x%04x, " "product=0x%04x, version=0x%04x\n", device->identifier.bus, device->identifier.vendor, device->identifier.product, device->identifier.version); dump += StringPrintf(INDENT3 "KeyLayoutFile: %s\n", - device->keyMap.keyLayoutFile.string()); + device->keyMap.keyLayoutFile.c_str()); dump += StringPrintf(INDENT3 "KeyCharacterMapFile: %s\n", - device->keyMap.keyCharacterMapFile.string()); + device->keyMap.keyCharacterMapFile.c_str()); dump += StringPrintf(INDENT3 "ConfigurationFile: %s\n", - device->configurationFile.string()); + device->configurationFile.c_str()); dump += StringPrintf(INDENT3 "HaveKeyboardLayoutOverlay: %s\n", toString(device->overlayKeyMap != nullptr)); } diff --git a/services/inputflinger/EventHub.h b/services/inputflinger/EventHub.h index dfe3defc73..ea663b7cb6 100644 --- a/services/inputflinger/EventHub.h +++ b/services/inputflinger/EventHub.h @@ -18,6 +18,8 @@ #ifndef _RUNTIME_EVENT_HUB_H #define _RUNTIME_EVENT_HUB_H +#include <vector> + #include <input/Input.h> #include <input/InputDevice.h> #include <input/Keyboard.h> @@ -29,7 +31,6 @@ #include <utils/List.h> #include <utils/Errors.h> #include <utils/PropertyMap.h> -#include <utils/Vector.h> #include <utils/KeyedVector.h> #include <utils/BitSet.h> @@ -207,7 +208,7 @@ public: // Sets devices that are excluded from opening. // This can be used to ignore input devices for sensors. - virtual void setExcludedDevices(const Vector<String8>& devices) = 0; + virtual void setExcludedDevices(const std::vector<std::string>& devices) = 0; /* * Wait for events to become available and returns them. @@ -303,7 +304,7 @@ public: virtual status_t mapAxis(int32_t deviceId, int32_t scanCode, AxisInfo* outAxisInfo) const; - virtual void setExcludedDevices(const Vector<String8>& devices); + virtual void setExcludedDevices(const std::vector<std::string>& devices); virtual int32_t getScanCodeState(int32_t deviceId, int32_t scanCode) const; virtual int32_t getKeyCodeState(int32_t deviceId, int32_t keyCode) const; @@ -344,7 +345,7 @@ private: int fd; // may be -1 if device is closed const int32_t id; - const String8 path; + const std::string path; const InputDeviceIdentifier identifier; uint32_t classes; @@ -357,7 +358,7 @@ private: uint8_t ffBitmask[(FF_MAX + 1) / 8]; uint8_t propBitmask[(INPUT_PROP_MAX + 1) / 8]; - String8 configurationFile; + std::string configurationFile; PropertyMap* configuration; VirtualKeyMap* virtualKeyMap; KeyMap keyMap; @@ -373,7 +374,8 @@ private: int32_t timestampOverrideSec; int32_t timestampOverrideUsec; - Device(int fd, int32_t id, const String8& path, const InputDeviceIdentifier& identifier); + Device(int fd, int32_t id, const std::string& path, + const InputDeviceIdentifier& identifier); ~Device(); void close(); @@ -413,7 +415,7 @@ private: void scanDevicesLocked(); status_t readNotifyLocked(); - Device* getDeviceByDescriptorLocked(String8& descriptor) const; + Device* getDeviceByDescriptorLocked(const std::string& descriptor) const; Device* getDeviceLocked(int32_t deviceId) const; Device* getDeviceByPathLocked(const char* devicePath) const; @@ -457,7 +459,7 @@ private: bool mNeedToSendFinishedDeviceScan; bool mNeedToReopenDevices; bool mNeedToScanDevices; - Vector<String8> mExcludedDevices; + std::vector<std::string> mExcludedDevices; int mEpollFd; int mINotifyFd; diff --git a/services/inputflinger/InputApplication.h b/services/inputflinger/InputApplication.h index 724fc2c4f4..9b365b9f0d 100644 --- a/services/inputflinger/InputApplication.h +++ b/services/inputflinger/InputApplication.h @@ -17,6 +17,8 @@ #ifndef _UI_INPUT_APPLICATION_H #define _UI_INPUT_APPLICATION_H +#include <string> + #include <input/Input.h> #include <utils/RefBase.h> #include <utils/Timers.h> diff --git a/services/inputflinger/InputManager.h b/services/inputflinger/InputManager.h index a213b2dfaa..92e0af21c3 100644 --- a/services/inputflinger/InputManager.h +++ b/services/inputflinger/InputManager.h @@ -31,7 +31,6 @@ #include <utils/Vector.h> #include <utils/Timers.h> #include <utils/RefBase.h> -#include <utils/String8.h> namespace android { diff --git a/services/inputflinger/InputReader.cpp b/services/inputflinger/InputReader.cpp index a4f83b7ebb..8f12129455 100644 --- a/services/inputflinger/InputReader.cpp +++ b/services/inputflinger/InputReader.cpp @@ -257,11 +257,12 @@ static void synthesizeButtonKeys(InputReaderContext* context, int32_t action, // --- InputReaderConfiguration --- bool InputReaderConfiguration::getDisplayViewport(ViewportType viewportType, - const String8* uniqueDisplayId, DisplayViewport* outViewport) const { + const std::string& uniqueDisplayId, DisplayViewport* outViewport) const { const DisplayViewport* viewport = nullptr; - if (viewportType == ViewportType::VIEWPORT_VIRTUAL && uniqueDisplayId != nullptr) { + if (viewportType == ViewportType::VIEWPORT_VIRTUAL && !uniqueDisplayId.empty()) { + for (const DisplayViewport& currentViewport : mVirtualDisplays) { - if (currentViewport.uniqueId == *uniqueDisplayId) { + if (currentViewport.uniqueId == uniqueDisplayId) { viewport = ¤tViewport; break; } @@ -473,10 +474,10 @@ void InputReader::addDeviceLocked(nsecs_t when, int32_t deviceId) { if (device->isIgnored()) { ALOGI("Device added: id=%d, name='%s' (ignored non-input device)", deviceId, - identifier.name.string()); + identifier.name.c_str()); } else { ALOGI("Device added: id=%d, name='%s', sources=0x%08x", deviceId, - identifier.name.string(), device->getSources()); + identifier.name.c_str(), device->getSources()); } mDevices.add(deviceId, device); @@ -501,10 +502,10 @@ void InputReader::removeDeviceLocked(nsecs_t when, int32_t deviceId) { if (device->isIgnored()) { ALOGI("Device removed: id=%d, name='%s' (ignored non-input device)", - device->getId(), device->getName().string()); + device->getId(), device->getName().c_str()); } else { ALOGI("Device removed: id=%d, name='%s', sources=0x%08x", - device->getId(), device->getName().string(), device->getSources()); + device->getId(), device->getName().c_str(), device->getSources()); } if (device->getClasses() & INPUT_DEVICE_CLASS_EXTERNAL_STYLUS) { @@ -687,7 +688,7 @@ bool InputReader::shouldDropVirtualKeyLocked(nsecs_t now, if (now < mDisableVirtualKeysTimeout) { ALOGI("Dropping virtual key from device %s because virtual keys are " "temporarily disabled for the next %0.3fms. keyCode=%d, scanCode=%d", - device->getName().string(), + device->getName().c_str(), (mDisableVirtualKeysTimeout - now) * 0.000001, keyCode, scanCode); return true; @@ -894,7 +895,7 @@ void InputReader::dump(std::string& dump) { if (i != 0) { dump += ", "; } - dump += mConfig.excludedDeviceNames.itemAt(i).string(); + dump += mConfig.excludedDeviceNames[i]; } dump += "]\n"; dump += StringPrintf(INDENT2 "VirtualKeyQuietTime: %0.1fms\n", @@ -1077,7 +1078,7 @@ void InputDevice::dump(std::string& dump) { getDeviceInfo(& deviceInfo); dump += StringPrintf(INDENT "Device %d: %s\n", deviceInfo.getId(), - deviceInfo.getDisplayName().string()); + deviceInfo.getDisplayName().c_str()); dump += StringPrintf(INDENT2 "Generation: %d\n", mGeneration); dump += StringPrintf(INDENT2 "IsExternal: %s\n", toString(mIsExternal)); dump += StringPrintf(INDENT2 "HasMic: %s\n", toString(mHasMic)); @@ -1135,7 +1136,7 @@ void InputDevice::configure(nsecs_t when, const InputReaderConfiguration* config if (!changes || (changes & InputReaderConfiguration::CHANGE_DEVICE_ALIAS)) { if (!(mClasses & INPUT_DEVICE_CLASS_VIRTUAL)) { - String8 alias = mContext->getPolicy()->getDeviceAlias(mIdentifier); + std::string alias = mContext->getPolicy()->getDeviceAlias(mIdentifier); if (mAlias != alias) { mAlias = alias; bumpGeneration(); @@ -1196,7 +1197,7 @@ void InputDevice::process(const RawEvent* rawEvents, size_t count) { #endif } } else if (rawEvent->type == EV_SYN && rawEvent->code == SYN_DROPPED) { - ALOGI("Detected input event buffer overrun for device %s.", getName().string()); + ALOGI("Detected input event buffer overrun for device %s.", getName().c_str()); mDropUntilNextSync = true; reset(rawEvent->when); } else { @@ -2294,7 +2295,7 @@ void KeyboardInputMapper::configure(nsecs_t when, if (!changes || (changes & InputReaderConfiguration::CHANGE_DISPLAY_INFO)) { if (mParameters.orientationAware) { DisplayViewport dvp; - config->getDisplayViewport(ViewportType::VIEWPORT_INTERNAL, nullptr, &dvp); + config->getDisplayViewport(ViewportType::VIEWPORT_INTERNAL, "", &dvp); mViewport = dvp; } } @@ -2464,7 +2465,7 @@ void KeyboardInputMapper::processKey(nsecs_t when, bool down, int32_t scanCode, // key was not actually down ALOGI("Dropping key up from device %s because the key was not down. " "keyCode=%d, scanCode=%d", - getDeviceName().string(), keyCode, scanCode); + getDeviceName().c_str(), keyCode, scanCode); return; } } @@ -2705,7 +2706,7 @@ void CursorInputMapper::configure(nsecs_t when, mOrientation = DISPLAY_ORIENTATION_0; if (mParameters.orientationAware && mParameters.hasAssociatedDisplay) { DisplayViewport v; - if (config->getDisplayViewport(ViewportType::VIEWPORT_INTERNAL, nullptr, &v)) { + if (config->getDisplayViewport(ViewportType::VIEWPORT_INTERNAL, "", &v)) { mOrientation = v.orientation; } } @@ -3020,7 +3021,7 @@ void RotaryEncoderInputMapper::configure(nsecs_t when, } if (!changes || (changes & InputReaderConfiguration::CHANGE_DISPLAY_INFO)) { DisplayViewport v; - if (config->getDisplayViewport(ViewportType::VIEWPORT_INTERNAL, nullptr, &v)) { + if (config->getDisplayViewport(ViewportType::VIEWPORT_INTERNAL, "", &v)) { mOrientation = v.orientation; } else { mOrientation = DISPLAY_ORIENTATION_0; @@ -3394,8 +3395,10 @@ void TouchInputMapper::configureParameters() { mParameters.hasAssociatedDisplay = true; if (mParameters.deviceType == Parameters::DEVICE_TYPE_TOUCH_SCREEN) { mParameters.associatedDisplayIsExternal = getDevice()->isExternal(); + String8 uniqueDisplayId; getDevice()->getConfiguration().tryGetProperty(String8("touch.displayId"), - mParameters.uniqueDisplayId); + uniqueDisplayId); + mParameters.uniqueDisplayId = uniqueDisplayId.c_str(); } } @@ -3506,7 +3509,7 @@ void TouchInputMapper::configureSurface(nsecs_t when, bool* outResetNeeded) { // Ensure we have valid X and Y axes. if (!mRawPointerAxes.x.valid || !mRawPointerAxes.y.valid) { ALOGW(INDENT "Touch device '%s' did not report support for X or Y axis! " - "The device will be inoperable.", getDeviceName().string()); + "The device will be inoperable.", getDeviceName().c_str()); mDeviceMode = DEVICE_MODE_DISABLED; return; } @@ -3518,15 +3521,15 @@ void TouchInputMapper::configureSurface(nsecs_t when, bool* outResetNeeded) { // Get associated display dimensions. DisplayViewport newViewport; if (mParameters.hasAssociatedDisplay) { - const String8* uniqueDisplayId = nullptr; + std::string uniqueDisplayId; ViewportType viewportTypeToUse; if (mParameters.associatedDisplayIsExternal) { viewportTypeToUse = ViewportType::VIEWPORT_EXTERNAL; - } else if (!mParameters.uniqueDisplayId.isEmpty()) { + } else if (!mParameters.uniqueDisplayId.empty()) { // If the IDC file specified a unique display Id, then it expects to be linked to a // virtual display with the same unique ID. - uniqueDisplayId = &mParameters.uniqueDisplayId; + uniqueDisplayId = mParameters.uniqueDisplayId; viewportTypeToUse = ViewportType::VIEWPORT_VIRTUAL; } else { viewportTypeToUse = ViewportType::VIEWPORT_INTERNAL; @@ -3536,7 +3539,7 @@ void TouchInputMapper::configureSurface(nsecs_t when, bool* outResetNeeded) { ALOGI(INDENT "Touch device '%s' could not query the properties of its associated " "display. The device will be inoperable until the display size " "becomes available.", - getDeviceName().string()); + getDeviceName().c_str()); mDeviceMode = DEVICE_MODE_DISABLED; return; } @@ -3642,7 +3645,7 @@ void TouchInputMapper::configureSurface(nsecs_t when, bool* outResetNeeded) { if (viewportChanged || deviceModeChanged) { ALOGI("Device reconfigured: id=%d, name='%s', size %dx%d, orientation %d, mode %d, " "display id %d", - getDeviceId(), getDeviceName().string(), mSurfaceWidth, mSurfaceHeight, + getDeviceId(), getDeviceName().c_str(), mSurfaceWidth, mSurfaceHeight, mSurfaceOrientation, mDeviceMode, mViewport.displayId); // Configure X and Y factors. @@ -6925,7 +6928,7 @@ void MultiTouchInputMapper::syncTouch(nsecs_t when, RawState* outState) { #if DEBUG_POINTERS ALOGD("MultiTouch device %s emitted more than maximum of %d pointers; " "ignoring the rest.", - getDeviceName().string(), MAX_POINTERS); + getDeviceName().c_str(), MAX_POINTERS); #endif break; // too many fingers! } @@ -7016,7 +7019,7 @@ void MultiTouchInputMapper::configureRawPointerAxes() { if (slotCount > MAX_SLOTS) { ALOGW("MultiTouch Device %s reported %zu slots but the framework " "only supports a maximum of %zu slots at this time.", - getDeviceName().string(), slotCount, MAX_SLOTS); + getDeviceName().c_str(), slotCount, MAX_SLOTS); slotCount = MAX_SLOTS; } mMultiTouchMotionAccumulator.configure(getDevice(), @@ -7259,7 +7262,7 @@ void JoystickInputMapper::configure(nsecs_t when, // Prefer to keep explicitly mapped axes. if (mAxes.size() > PointerCoords::MAX_AXES) { ALOGI("Joystick '%s' has %zu axes but the framework only supports a maximum of %d.", - getDeviceName().string(), mAxes.size(), PointerCoords::MAX_AXES); + getDeviceName().c_str(), mAxes.size(), PointerCoords::MAX_AXES); pruneAxes(true); pruneAxes(false); } @@ -7281,7 +7284,7 @@ void JoystickInputMapper::configure(nsecs_t when, } else { ALOGI("Ignoring joystick '%s' axis %d because all of the generic axis ids " "have already been assigned to other axes.", - getDeviceName().string(), mAxes.keyAt(i)); + getDeviceName().c_str(), mAxes.keyAt(i)); mAxes.removeItemsAt(i--); numAxes -= 1; } @@ -7310,7 +7313,7 @@ void JoystickInputMapper::pruneAxes(bool ignoreExplicitlyMappedAxes) { continue; } ALOGI("Discarding joystick '%s' axis %d because there are too many axes.", - getDeviceName().string(), mAxes.keyAt(i)); + getDeviceName().c_str(), mAxes.keyAt(i)); mAxes.removeItemsAt(i); } } diff --git a/services/inputflinger/InputReader.h b/services/inputflinger/InputReader.h index af26b4f27b..c06168d5a2 100644 --- a/services/inputflinger/InputReader.h +++ b/services/inputflinger/InputReader.h @@ -101,7 +101,7 @@ struct InputReaderConfiguration { // The excluded device names for the platform. // Devices with these names will be ignored. - Vector<String8> excludedDeviceNames; + std::vector<std::string> excludedDeviceNames; // Velocity control parameters for mouse pointer movements. VelocityControlParameters pointerVelocityControlParameters; @@ -201,7 +201,7 @@ struct InputReaderConfiguration { pointerGestureZoomSpeedRatio(0.3f), showTouches(false) { } - bool getDisplayViewport(ViewportType viewportType, const String8* displayId, + bool getDisplayViewport(ViewportType viewportType, const std::string& uniqueDisplayId, DisplayViewport* outViewport) const; void setPhysicalDisplayViewport(ViewportType viewportType, const DisplayViewport& viewport); void setVirtualDisplayViewports(const Vector<DisplayViewport>& viewports); @@ -274,11 +274,11 @@ public: const InputDeviceIdentifier& identifier) = 0; /* Gets a user-supplied alias for a particular input device, or an empty string if none. */ - virtual String8 getDeviceAlias(const InputDeviceIdentifier& identifier) = 0; + virtual std::string getDeviceAlias(const InputDeviceIdentifier& identifier) = 0; /* Gets the affine calibration associated with the specified device. */ virtual TouchAffineTransformation getTouchAffineTransformation( - const String8& inputDeviceDescriptor, int32_t surfaceRotation) = 0; + const std::string& inputDeviceDescriptor, int32_t surfaceRotation) = 0; }; @@ -553,8 +553,8 @@ public: inline int32_t getId() const { return mId; } inline int32_t getControllerNumber() const { return mControllerNumber; } inline int32_t getGeneration() const { return mGeneration; } - inline const String8& getName() const { return mIdentifier.name; } - inline const String8& getDescriptor() { return mIdentifier.descriptor; } + inline const std::string getName() const { return mIdentifier.name; } + inline const std::string getDescriptor() { return mIdentifier.descriptor; } inline uint32_t getClasses() const { return mClasses; } inline uint32_t getSources() const { return mSources; } @@ -625,7 +625,7 @@ private: int32_t mGeneration; int32_t mControllerNumber; InputDeviceIdentifier mIdentifier; - String8 mAlias; + std::string mAlias; uint32_t mClasses; Vector<InputMapper*> mMappers; @@ -981,7 +981,7 @@ public: inline InputDevice* getDevice() { return mDevice; } inline int32_t getDeviceId() { return mDevice->getId(); } - inline const String8 getDeviceName() { return mDevice->getName(); } + inline const std::string getDeviceName() { return mDevice->getName(); } inline InputReaderContext* getContext() { return mContext; } inline InputReaderPolicyInterface* getPolicy() { return mContext->getPolicy(); } inline InputListenerInterface* getListener() { return mContext->getListener(); } @@ -1309,7 +1309,7 @@ protected: bool associatedDisplayIsExternal; bool orientationAware; bool hasButtonUnderPad; - String8 uniqueDisplayId; + std::string uniqueDisplayId; enum GestureMode { GESTURE_MODE_SINGLE_TOUCH, diff --git a/services/inputflinger/host/InputDriver.cpp b/services/inputflinger/host/InputDriver.cpp index bd11d5620b..2f046c3527 100644 --- a/services/inputflinger/host/InputDriver.cpp +++ b/services/inputflinger/host/InputDriver.cpp @@ -217,18 +217,18 @@ input_property_map_t* InputDriver::inputGetDevicePropertyMap(input_device_identi idi.product = id->productId; idi.version = id->version; - String8 configFile = getInputDeviceConfigurationFilePathByDeviceIdentifier( + std::string configFile = getInputDeviceConfigurationFilePathByDeviceIdentifier( idi, INPUT_DEVICE_CONFIGURATION_FILE_TYPE_CONFIGURATION); - if (configFile.isEmpty()) { + if (configFile.empty()) { ALOGD("No input device configuration file found for device '%s'.", - idi.name.string()); + idi.name.c_str()); } else { auto propMap = new input_property_map_t(); - status_t status = PropertyMap::load(configFile, &propMap->propertyMap); + status_t status = PropertyMap::load(String8(configFile.c_str()), &propMap->propertyMap); if (status) { ALOGE("Error loading input device configuration file for device '%s'. " "Using default configuration.", - idi.name.string()); + idi.name.c_str()); delete propMap; return nullptr; } diff --git a/services/inputflinger/tests/InputReader_test.cpp b/services/inputflinger/tests/InputReader_test.cpp index 286cf880f1..9b985dc23d 100644 --- a/services/inputflinger/tests/InputReader_test.cpp +++ b/services/inputflinger/tests/InputReader_test.cpp @@ -142,7 +142,7 @@ public: } void setDisplayViewport(int32_t displayId, int32_t width, int32_t height, int32_t orientation, - const String8& uniqueId) { + const std::string& uniqueId) { DisplayViewport v = createDisplayViewport(displayId, width, height, orientation, uniqueId); // Set the size of both the internal and external display at the same time. mConfig.setPhysicalDisplayViewport(ViewportType::VIEWPORT_INTERNAL, v); @@ -150,14 +150,14 @@ public: } void setVirtualDisplayViewport(int32_t displayId, int32_t width, int32_t height, int32_t orientation, - const String8& uniqueId) { + const std::string& uniqueId) { Vector<DisplayViewport> viewports; viewports.push_back(createDisplayViewport(displayId, width, height, orientation, uniqueId)); mConfig.setVirtualDisplayViewports(viewports); } - void addExcludedDeviceName(const String8& deviceName) { - mConfig.excludedDeviceNames.push(deviceName); + void addExcludedDeviceName(const std::string& deviceName) { + mConfig.excludedDeviceNames.push_back(deviceName); } void addDisabledDevice(int32_t deviceId) { @@ -188,7 +188,7 @@ public: return mInputDevices; } - TouchAffineTransformation getTouchAffineTransformation(const String8& inputDeviceDescriptor, + TouchAffineTransformation getTouchAffineTransformation(const std::string& inputDeviceDescriptor, int32_t surfaceRotation) { return transform; } @@ -203,7 +203,7 @@ public: private: DisplayViewport createDisplayViewport(int32_t displayId, int32_t width, int32_t height, - int32_t orientation, const String8& uniqueId) { + int32_t orientation, const std::string& uniqueId) { bool isRotated = (orientation == DISPLAY_ORIENTATION_90 || orientation == DISPLAY_ORIENTATION_270); DisplayViewport v; @@ -239,8 +239,8 @@ private: return nullptr; } - virtual String8 getDeviceAlias(const InputDeviceIdentifier&) { - return String8::empty(); + virtual std::string getDeviceAlias(const InputDeviceIdentifier&) { + return ""; } }; @@ -392,7 +392,7 @@ class FakeEventHub : public EventHubInterface { }; KeyedVector<int32_t, Device*> mDevices; - Vector<String8> mExcludedDevices; + std::vector<std::string> mExcludedDevices; List<RawEvent> mEvents; protected: @@ -405,7 +405,7 @@ protected: public: FakeEventHub() { } - void addDevice(int32_t deviceId, const String8& name, uint32_t classes) { + void addDevice(int32_t deviceId, const std::string& name, uint32_t classes) { Device* device = new Device(classes); device->identifier.name = name; mDevices.add(deviceId, device); @@ -534,7 +534,7 @@ public: return device->leds.valueFor(led); } - Vector<String8>& getExcludedDevices() { + std::vector<std::string>& getExcludedDevices() { return mExcludedDevices; } @@ -566,7 +566,7 @@ public: private: Device* getDevice(int32_t deviceId) const { ssize_t index = mDevices.indexOfKey(deviceId); - return index >= 0 ? mDevices.valueAt(index) : NULL; + return index >= 0 ? mDevices.valueAt(index) : nullptr; } virtual uint32_t getDeviceClasses(int32_t deviceId) const { @@ -658,7 +658,7 @@ private: return NAME_NOT_FOUND; } - virtual void setExcludedDevices(const Vector<String8>& devices) { + virtual void setExcludedDevices(const std::vector<std::string>& devices) { mExcludedDevices = devices; } @@ -1052,7 +1052,7 @@ public: mNextDevice = device; } - InputDevice* newDevice(int32_t deviceId, int32_t controllerNumber, const String8& name, + InputDevice* newDevice(int32_t deviceId, int32_t controllerNumber, const std::string& name, uint32_t classes) { InputDeviceIdentifier identifier; identifier.name = name; @@ -1101,7 +1101,7 @@ protected: mFakeEventHub.clear(); } - void addDevice(int32_t deviceId, const String8& name, uint32_t classes, + void addDevice(int32_t deviceId, const std::string& name, uint32_t classes, const PropertyMap* configuration) { mFakeEventHub->addDevice(deviceId, name, classes); @@ -1129,7 +1129,7 @@ protected: } FakeInputMapper* addDeviceWithFakeInputMapper(int32_t deviceId, int32_t controllerNumber, - const String8& name, uint32_t classes, uint32_t sources, + const std::string& name, uint32_t classes, uint32_t sources, const PropertyMap* configuration) { InputDevice* device = mReader->newDevice(deviceId, controllerNumber, name, classes); FakeInputMapper* mapper = new FakeInputMapper(device, sources); @@ -1141,17 +1141,18 @@ protected: }; TEST_F(InputReaderTest, GetInputDevices) { - ASSERT_NO_FATAL_FAILURE(addDevice(1, String8("keyboard"), + ASSERT_NO_FATAL_FAILURE(addDevice(1, "keyboard", INPUT_DEVICE_CLASS_KEYBOARD, nullptr)); - ASSERT_NO_FATAL_FAILURE(addDevice(2, String8("ignored"), + ASSERT_NO_FATAL_FAILURE(addDevice(2, "ignored", 0, nullptr)); // no classes so device will be ignored + Vector<InputDeviceInfo> inputDevices; mReader->getInputDevices(inputDevices); ASSERT_EQ(1U, inputDevices.size()); ASSERT_EQ(1, inputDevices[0].getId()); - ASSERT_STREQ("keyboard", inputDevices[0].getIdentifier().name.string()); + ASSERT_STREQ("keyboard", inputDevices[0].getIdentifier().name.c_str()); ASSERT_EQ(AINPUT_KEYBOARD_TYPE_NON_ALPHABETIC, inputDevices[0].getKeyboardType()); ASSERT_EQ(AINPUT_SOURCE_KEYBOARD, inputDevices[0].getSources()); ASSERT_EQ(size_t(0), inputDevices[0].getMotionRanges().size()); @@ -1160,7 +1161,7 @@ TEST_F(InputReaderTest, GetInputDevices) { inputDevices = mFakePolicy->getInputDevices(); ASSERT_EQ(1U, inputDevices.size()); ASSERT_EQ(1, inputDevices[0].getId()); - ASSERT_STREQ("keyboard", inputDevices[0].getIdentifier().name.string()); + ASSERT_STREQ("keyboard", inputDevices[0].getIdentifier().name.c_str()); ASSERT_EQ(AINPUT_KEYBOARD_TYPE_NON_ALPHABETIC, inputDevices[0].getKeyboardType()); ASSERT_EQ(AINPUT_SOURCE_KEYBOARD, inputDevices[0].getSources()); ASSERT_EQ(size_t(0), inputDevices[0].getMotionRanges().size()); @@ -1169,12 +1170,12 @@ TEST_F(InputReaderTest, GetInputDevices) { TEST_F(InputReaderTest, WhenEnabledChanges_SendsDeviceResetNotification) { constexpr int32_t deviceId = 1; constexpr uint32_t deviceClass = INPUT_DEVICE_CLASS_KEYBOARD; - InputDevice* device = mReader->newDevice(deviceId, 0, String8("fake"), deviceClass); + InputDevice* device = mReader->newDevice(deviceId, 0, "fake", deviceClass); // Must add at least one mapper or the device will be ignored! FakeInputMapper* mapper = new FakeInputMapper(device, AINPUT_SOURCE_KEYBOARD); device->addMapper(mapper); mReader->setNextDevice(device); - addDevice(deviceId, String8("fake"), deviceClass, nullptr); + addDevice(deviceId, "fake", deviceClass, nullptr); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyConfigurationChangedWasCalled(nullptr)); @@ -1208,7 +1209,7 @@ TEST_F(InputReaderTest, WhenEnabledChanges_SendsDeviceResetNotification) { TEST_F(InputReaderTest, GetKeyCodeState_ForwardsRequestsToMappers) { FakeInputMapper* mapper = nullptr; - ASSERT_NO_FATAL_FAILURE(mapper = addDeviceWithFakeInputMapper(1, 0, String8("fake"), + ASSERT_NO_FATAL_FAILURE(mapper = addDeviceWithFakeInputMapper(1, 0, "fake", INPUT_DEVICE_CLASS_KEYBOARD, AINPUT_SOURCE_KEYBOARD, nullptr)); mapper->setKeyCodeState(AKEYCODE_A, AKEY_STATE_DOWN); @@ -1235,7 +1236,7 @@ TEST_F(InputReaderTest, GetKeyCodeState_ForwardsRequestsToMappers) { TEST_F(InputReaderTest, GetScanCodeState_ForwardsRequestsToMappers) { FakeInputMapper* mapper = nullptr; - ASSERT_NO_FATAL_FAILURE(mapper = addDeviceWithFakeInputMapper(1, 0, String8("fake"), + ASSERT_NO_FATAL_FAILURE(mapper = addDeviceWithFakeInputMapper(1, 0, "fake", INPUT_DEVICE_CLASS_KEYBOARD, AINPUT_SOURCE_KEYBOARD, nullptr)); mapper->setScanCodeState(KEY_A, AKEY_STATE_DOWN); @@ -1262,7 +1263,7 @@ TEST_F(InputReaderTest, GetScanCodeState_ForwardsRequestsToMappers) { TEST_F(InputReaderTest, GetSwitchState_ForwardsRequestsToMappers) { FakeInputMapper* mapper = nullptr; - ASSERT_NO_FATAL_FAILURE(mapper = addDeviceWithFakeInputMapper(1, 0, String8("fake"), + ASSERT_NO_FATAL_FAILURE(mapper = addDeviceWithFakeInputMapper(1, 0, "fake", INPUT_DEVICE_CLASS_KEYBOARD, AINPUT_SOURCE_KEYBOARD, nullptr)); mapper->setSwitchState(SW_LID, AKEY_STATE_DOWN); @@ -1289,8 +1290,9 @@ TEST_F(InputReaderTest, GetSwitchState_ForwardsRequestsToMappers) { TEST_F(InputReaderTest, MarkSupportedKeyCodes_ForwardsRequestsToMappers) { FakeInputMapper* mapper = nullptr; - ASSERT_NO_FATAL_FAILURE(mapper = addDeviceWithFakeInputMapper(1, 0, String8("fake"), + ASSERT_NO_FATAL_FAILURE(mapper = addDeviceWithFakeInputMapper(1, 0, "fake", INPUT_DEVICE_CLASS_KEYBOARD, AINPUT_SOURCE_KEYBOARD, nullptr)); + mapper->addSupportedKeyCode(AKEYCODE_A); mapper->addSupportedKeyCode(AKEYCODE_B); @@ -1323,7 +1325,7 @@ TEST_F(InputReaderTest, MarkSupportedKeyCodes_ForwardsRequestsToMappers) { } TEST_F(InputReaderTest, LoopOnce_WhenDeviceScanFinished_SendsConfigurationChanged) { - addDevice(1, String8("ignored"), INPUT_DEVICE_CLASS_KEYBOARD, nullptr); + addDevice(1, "ignored", INPUT_DEVICE_CLASS_KEYBOARD, nullptr); NotifyConfigurationChangedArgs args; @@ -1333,7 +1335,7 @@ TEST_F(InputReaderTest, LoopOnce_WhenDeviceScanFinished_SendsConfigurationChange TEST_F(InputReaderTest, LoopOnce_ForwardsRawEventsToMappers) { FakeInputMapper* mapper = nullptr; - ASSERT_NO_FATAL_FAILURE(mapper = addDeviceWithFakeInputMapper(1, 0, String8("fake"), + ASSERT_NO_FATAL_FAILURE(mapper = addDeviceWithFakeInputMapper(1, 0, "fake", INPUT_DEVICE_CLASS_KEYBOARD, AINPUT_SOURCE_KEYBOARD, nullptr)); mFakeEventHub->enqueueEvent(0, 1, EV_KEY, KEY_A, 1); @@ -1373,7 +1375,7 @@ protected: mFakeListener = new FakeInputListener(); mFakeContext = new FakeInputReaderContext(mFakeEventHub, mFakePolicy, mFakeListener); - mFakeEventHub->addDevice(DEVICE_ID, String8(DEVICE_NAME), 0); + mFakeEventHub->addDevice(DEVICE_ID, DEVICE_NAME, 0); InputDeviceIdentifier identifier; identifier.name = DEVICE_NAME; mDevice = new InputDevice(mFakeContext, DEVICE_ID, DEVICE_GENERATION, @@ -1399,7 +1401,7 @@ const uint32_t InputDeviceTest::DEVICE_CLASSES = INPUT_DEVICE_CLASS_KEYBOARD TEST_F(InputDeviceTest, ImmutableProperties) { ASSERT_EQ(DEVICE_ID, mDevice->getId()); - ASSERT_STREQ(DEVICE_NAME, mDevice->getName()); + ASSERT_STREQ(DEVICE_NAME, mDevice->getName().c_str()); ASSERT_EQ(DEVICE_CLASSES, mDevice->getClasses()); } @@ -1427,7 +1429,7 @@ TEST_F(InputDeviceTest, WhenNoMappersAreRegistered_DeviceIsIgnored) { InputDeviceInfo info; mDevice->getDeviceInfo(&info); ASSERT_EQ(DEVICE_ID, info.getId()); - ASSERT_STREQ(DEVICE_NAME, info.getIdentifier().name.string()); + ASSERT_STREQ(DEVICE_NAME, info.getIdentifier().name.c_str()); ASSERT_EQ(AINPUT_KEYBOARD_TYPE_NONE, info.getKeyboardType()); ASSERT_EQ(AINPUT_SOURCE_UNKNOWN, info.getSources()); @@ -1497,7 +1499,7 @@ TEST_F(InputDeviceTest, WhenMappersAreRegistered_DeviceIsNotIgnoredAndForwardsRe InputDeviceInfo info; mDevice->getDeviceInfo(&info); ASSERT_EQ(DEVICE_ID, info.getId()); - ASSERT_STREQ(DEVICE_NAME, info.getIdentifier().name.string()); + ASSERT_STREQ(DEVICE_NAME, info.getIdentifier().name.c_str()); ASSERT_EQ(AINPUT_KEYBOARD_TYPE_ALPHABETIC, info.getKeyboardType()); ASSERT_EQ(uint32_t(AINPUT_SOURCE_KEYBOARD | AINPUT_SOURCE_TOUCHSCREEN), info.getSources()); @@ -1570,7 +1572,7 @@ protected: mDevice = new InputDevice(mFakeContext, DEVICE_ID, DEVICE_GENERATION, DEVICE_CONTROLLER_NUMBER, identifier, DEVICE_CLASSES); - mFakeEventHub->addDevice(DEVICE_ID, String8(DEVICE_NAME), 0); + mFakeEventHub->addDevice(DEVICE_ID, DEVICE_NAME, 0); } virtual void TearDown() { @@ -1597,12 +1599,12 @@ protected: void setDisplayInfoAndReconfigure(int32_t displayId, int32_t width, int32_t height, int32_t orientation) { - mFakePolicy->setDisplayViewport(displayId, width, height, orientation, String8::empty()); + mFakePolicy->setDisplayViewport(displayId, width, height, orientation, ""); configureDevice(InputReaderConfiguration::CHANGE_DISPLAY_INFO); } void setVirtualDisplayInfoAndReconfigure(int32_t displayId, int32_t width, int32_t height, - int32_t orientation, const String8& uniqueId) { + int32_t orientation, const std::string& uniqueId) { mFakePolicy->setVirtualDisplayViewport(displayId, width, height, orientation, uniqueId); configureDevice(InputReaderConfiguration::CHANGE_DISPLAY_INFO); } @@ -3048,7 +3050,7 @@ void TouchInputMapperTest::prepareDisplay(int32_t orientation) { void TouchInputMapperTest::prepareVirtualDisplay(int32_t orientation) { setVirtualDisplayInfoAndReconfigure(VIRTUAL_DISPLAY_ID, VIRTUAL_DISPLAY_WIDTH, - VIRTUAL_DISPLAY_HEIGHT, orientation, String8(VIRTUAL_DISPLAY_UNIQUE_ID)); + VIRTUAL_DISPLAY_HEIGHT, orientation, VIRTUAL_DISPLAY_UNIQUE_ID); } void TouchInputMapperTest::prepareVirtualKeys() { |