Improve support for external keyboards.
Use Vendor ID, Product ID and optionally the Version to locate keymaps and configuration files for external devices. Moved virtual key definition parsing to native code so that EventHub can identify touch screens with virtual keys and load the appropriate key layout file. Cleaned up a lot of old code in EventHub. Fixed a regression in ViewRoot's fallback event handling. Fixed a minor bug in FileMap that caused it to try to munmap or close invalid handled when released if the attempt to map the file failed. Added a couple of new String8 conveniences for formatting strings. Modified Tokenizer to fall back to open+read when mmap fails since we can't mmap sysfs files as needed to open the virtual key definition files in /sys/board_properties/. Change-Id: I6ca5e5f9547619fd082ddac47e87ce185da69ee6
This commit is contained in:
parent
04cbbc1c47
commit
1d618d63c1
|
@ -47,7 +47,12 @@ public:
|
|||
explicit String8(const char32_t* o);
|
||||
explicit String8(const char32_t* o, size_t numChars);
|
||||
~String8();
|
||||
|
||||
|
||||
static inline const String8 empty();
|
||||
|
||||
static String8 format(const char* fmt, ...) __attribute__((format (printf, 1, 2)));
|
||||
static String8 formatV(const char* fmt, va_list args);
|
||||
|
||||
inline const char* string() const;
|
||||
inline size_t size() const;
|
||||
inline size_t length() const;
|
||||
|
@ -229,6 +234,10 @@ inline int strictly_order_type(const String8& lhs, const String8& rhs)
|
|||
return compare_type(lhs, rhs) < 0;
|
||||
}
|
||||
|
||||
inline const String8 String8::empty() {
|
||||
return String8();
|
||||
}
|
||||
|
||||
inline const char* String8::string() const
|
||||
{
|
||||
return mString;
|
||||
|
|
|
@ -28,7 +28,7 @@ namespace android {
|
|||
* A simple tokenizer for loading and parsing ASCII text files line by line.
|
||||
*/
|
||||
class Tokenizer {
|
||||
Tokenizer(const String8& filename, FileMap* fileMap, const char* buffer, size_t length);
|
||||
Tokenizer(const String8& filename, FileMap* fileMap, char* buffer, size_t length);
|
||||
|
||||
public:
|
||||
~Tokenizer();
|
||||
|
@ -110,7 +110,7 @@ private:
|
|||
|
||||
String8 mFilename;
|
||||
FileMap* mFileMap;
|
||||
const char* mBuffer;
|
||||
char* mBuffer;
|
||||
size_t mLength;
|
||||
|
||||
const char* mCurrent;
|
||||
|
|
|
@ -63,16 +63,18 @@ FileMap::~FileMap(void)
|
|||
free(mFileName);
|
||||
}
|
||||
#ifdef HAVE_POSIX_FILEMAP
|
||||
if (munmap(mBasePtr, mBaseLength) != 0) {
|
||||
if (mBasePtr && munmap(mBasePtr, mBaseLength) != 0) {
|
||||
LOGD("munmap(%p, %d) failed\n", mBasePtr, (int) mBaseLength);
|
||||
}
|
||||
#endif
|
||||
#ifdef HAVE_WIN32_FILEMAP
|
||||
if ( UnmapViewOfFile(mBasePtr) == 0) {
|
||||
if (mBasePtr && UnmapViewOfFile(mBasePtr) == 0) {
|
||||
LOGD("UnmapViewOfFile(%p) failed, error = %ld\n", mBasePtr,
|
||||
GetLastError() );
|
||||
}
|
||||
CloseHandle(mFileMapping);
|
||||
if (mFileMapping != INVALID_HANDLE_VALUE) {
|
||||
CloseHandle(mFileMapping);
|
||||
}
|
||||
CloseHandle(mFileHandle);
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -195,6 +195,24 @@ String8::~String8()
|
|||
SharedBuffer::bufferFromData(mString)->release();
|
||||
}
|
||||
|
||||
String8 String8::format(const char* fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
|
||||
String8 result(formatV(fmt, args));
|
||||
|
||||
va_end(args);
|
||||
return result;
|
||||
}
|
||||
|
||||
String8 String8::formatV(const char* fmt, va_list args)
|
||||
{
|
||||
String8 result;
|
||||
result.appendFormatV(fmt, args);
|
||||
return result;
|
||||
}
|
||||
|
||||
void String8::clear() {
|
||||
SharedBuffer::bufferFromData(mString)->release();
|
||||
mString = getEmptyString();
|
||||
|
|
|
@ -35,16 +35,16 @@ static inline bool isDelimiter(char ch, const char* delimiters) {
|
|||
return strchr(delimiters, ch) != NULL;
|
||||
}
|
||||
|
||||
|
||||
Tokenizer::Tokenizer(const String8& filename, FileMap* fileMap,
|
||||
const char* buffer, size_t length) :
|
||||
mFilename(filename), mFileMap(fileMap), mBuffer(buffer), mLength(length),
|
||||
mCurrent(buffer), mLineNumber(1) {
|
||||
Tokenizer::Tokenizer(const String8& filename, FileMap* fileMap, char* buffer, size_t length) :
|
||||
mFilename(filename), mFileMap(fileMap),
|
||||
mBuffer(buffer), mLength(length), mCurrent(buffer), mLineNumber(1) {
|
||||
}
|
||||
|
||||
Tokenizer::~Tokenizer() {
|
||||
if (mFileMap) {
|
||||
mFileMap->release();
|
||||
} else {
|
||||
delete[] mBuffer;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -63,22 +63,33 @@ status_t Tokenizer::open(const String8& filename, Tokenizer** outTokenizer) {
|
|||
LOGE("Error getting size of file '%s', %s.", filename.string(), strerror(errno));
|
||||
} else {
|
||||
size_t length = size_t(stat.st_size);
|
||||
FileMap* fileMap = new FileMap();
|
||||
if (!fileMap->create(NULL, fd, 0, length, true)) {
|
||||
result = NO_MEMORY;
|
||||
LOGE("Error mapping file '%s', %s.", filename.string(), strerror(errno));
|
||||
} else {
|
||||
fileMap->advise(FileMap::SEQUENTIAL);
|
||||
|
||||
*outTokenizer = new Tokenizer(filename, fileMap,
|
||||
static_cast<const char*>(fileMap->getDataPtr()), length);
|
||||
if (!*outTokenizer) {
|
||||
result = NO_MEMORY;
|
||||
LOGE("Error allocating tokenizer for file=%s.", filename.string());
|
||||
FileMap* fileMap = new FileMap();
|
||||
char* buffer;
|
||||
if (fileMap->create(NULL, fd, 0, length, true)) {
|
||||
fileMap->advise(FileMap::SEQUENTIAL);
|
||||
buffer = static_cast<char*>(fileMap->getDataPtr());
|
||||
} else {
|
||||
fileMap->release();
|
||||
fileMap = NULL;
|
||||
|
||||
// Fall back to reading into a buffer since we can't mmap files in sysfs.
|
||||
// The length we obtained from stat is wrong too (it will always be 4096)
|
||||
// so we must trust that read will read the entire file.
|
||||
buffer = new char[length];
|
||||
ssize_t nrd = read(fd, buffer, length);
|
||||
if (nrd < 0) {
|
||||
result = -errno;
|
||||
LOGE("Error reading file '%s', %s.", filename.string(), strerror(errno));
|
||||
delete[] buffer;
|
||||
buffer = NULL;
|
||||
} else {
|
||||
length = size_t(nrd);
|
||||
}
|
||||
}
|
||||
if (result) {
|
||||
fileMap->release();
|
||||
|
||||
if (!result) {
|
||||
*outTokenizer = new Tokenizer(filename, fileMap, buffer, length);
|
||||
}
|
||||
}
|
||||
close(fd);
|
||||
|
|
Loading…
Reference in New Issue