From ad437259f72e1ff8bbb54255c292c7fb5442d962 Mon Sep 17 00:00:00 2001 From: Ivan Podogov Date: Thu, 29 Sep 2016 16:29:55 +0100 Subject: Support 180-degree screen rotation for RSB. Bug: 17961466 Change-Id: I640c79e18a524ce03a5215ca5669b920a0fa2642 --- services/inputflinger/InputReader.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'services/inputflinger/InputReader.cpp') diff --git a/services/inputflinger/InputReader.cpp b/services/inputflinger/InputReader.cpp index 97565aa000..72c45602ff 100644 --- a/services/inputflinger/InputReader.cpp +++ b/services/inputflinger/InputReader.cpp @@ -2897,7 +2897,7 @@ void CursorInputMapper::fadePointer() { // --- RotaryEncoderInputMapper --- RotaryEncoderInputMapper::RotaryEncoderInputMapper(InputDevice* device) : - InputMapper(device) { + InputMapper(device), mOrientation(DISPLAY_ORIENTATION_0) { mSource = AINPUT_SOURCE_ROTARY_ENCODER; } @@ -2939,6 +2939,14 @@ void RotaryEncoderInputMapper::configure(nsecs_t when, if (!changes) { mRotaryEncoderScrollAccumulator.configure(getDevice()); } + if (!changes || (InputReaderConfiguration::CHANGE_DISPLAY_INFO)) { + DisplayViewport v; + if (config->getDisplayViewport(ViewportType::VIEWPORT_INTERNAL, NULL, &v)) { + mOrientation = v.orientation; + } else { + mOrientation = DISPLAY_ORIENTATION_0; + } + } } void RotaryEncoderInputMapper::reset(nsecs_t when) { @@ -2976,6 +2984,10 @@ void RotaryEncoderInputMapper::sync(nsecs_t when) { policyFlags |= POLICY_FLAG_WAKE; } + if (mOrientation == DISPLAY_ORIENTATION_180) { + scroll = -scroll; + } + // Send motion event. if (scrolled) { int32_t metaState = mContext->getGlobalMetaState(); -- cgit v1.2.3-59-g8ed1b From b9afef3b818a4878fe99ee9e1ce7dd3fdc01c377 Mon Sep 17 00:00:00 2001 From: Ivan Podogov Date: Mon, 13 Feb 2017 15:34:32 +0000 Subject: Support 180-degree screen rotation for Stem Buttons. Bug: 17961466 Change-Id: I1892db400724bb80fb92bdf0e2cbaf3102dd7c80 --- services/inputflinger/InputReader.cpp | 48 +++++++++++++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 2 deletions(-) (limited to 'services/inputflinger/InputReader.cpp') diff --git a/services/inputflinger/InputReader.cpp b/services/inputflinger/InputReader.cpp index 97565aa000..dae7879d48 100644 --- a/services/inputflinger/InputReader.cpp +++ b/services/inputflinger/InputReader.cpp @@ -147,7 +147,33 @@ static const int32_t keyCodeRotationMap[][4] = { static const size_t keyCodeRotationMapSize = sizeof(keyCodeRotationMap) / sizeof(keyCodeRotationMap[0]); +static int32_t rotateStemKey(int32_t value, int32_t orientation, + const int32_t map[][2], size_t mapSize) { + if (orientation == DISPLAY_ORIENTATION_180) { + for (size_t i = 0; i < mapSize; i++) { + if (value == map[i][0]) { + return map[i][1]; + } + } + } + return value; +} + +// The mapping can be defined using input device configuration properties keyboard.rotated.stem_X +static int32_t stemKeyRotationMap[][2] = { + // key codes enumerated with the original (unrotated) key first + // no rotation, 180 degree rotation + { AKEYCODE_STEM_PRIMARY, AKEYCODE_STEM_PRIMARY }, + { AKEYCODE_STEM_1, AKEYCODE_STEM_1 }, + { AKEYCODE_STEM_2, AKEYCODE_STEM_2 }, + { AKEYCODE_STEM_3, AKEYCODE_STEM_3 }, +}; +static const size_t stemKeyRotationMapSize = + sizeof(stemKeyRotationMap) / sizeof(stemKeyRotationMap[0]); + static int32_t rotateKeyCode(int32_t keyCode, int32_t orientation) { + keyCode = rotateStemKey(keyCode, orientation, + stemKeyRotationMap, stemKeyRotationMapSize); return rotateValueUsingRotationMap(keyCode, orientation, keyCodeRotationMap, keyCodeRotationMapSize); } @@ -2260,18 +2286,36 @@ void KeyboardInputMapper::configure(nsecs_t when, } } +static void mapStemKey(int32_t keyCode, const PropertyMap& config, char const *property) { + int32_t mapped = 0; + if (config.tryGetProperty(String8(property), mapped) && mapped > 0) { + for (size_t i = 0; i < stemKeyRotationMapSize; i++) { + if (stemKeyRotationMap[i][0] == keyCode) { + stemKeyRotationMap[i][1] = mapped; + return; + } + } + } +} + void KeyboardInputMapper::configureParameters() { mParameters.orientationAware = false; - getDevice()->getConfiguration().tryGetProperty(String8("keyboard.orientationAware"), + const PropertyMap& config = getDevice()->getConfiguration(); + config.tryGetProperty(String8("keyboard.orientationAware"), mParameters.orientationAware); mParameters.hasAssociatedDisplay = false; if (mParameters.orientationAware) { mParameters.hasAssociatedDisplay = true; + + mapStemKey(AKEYCODE_STEM_PRIMARY, config, "keyboard.rotated.stem_primary"); + mapStemKey(AKEYCODE_STEM_1, config, "keyboard.rotated.stem_1"); + mapStemKey(AKEYCODE_STEM_2, config, "keyboard.rotated.stem_2"); + mapStemKey(AKEYCODE_STEM_3, config, "keyboard.rotated.stem_3"); } mParameters.handlesKeyRepeat = false; - getDevice()->getConfiguration().tryGetProperty(String8("keyboard.handlesKeyRepeat"), + config.tryGetProperty(String8("keyboard.handlesKeyRepeat"), mParameters.handlesKeyRepeat); } -- cgit v1.2.3-59-g8ed1b From af8a588262bfa1037916be0b75804bc88e1d3303 Mon Sep 17 00:00:00 2001 From: Michael Spang Date: Tue, 5 Sep 2017 20:17:16 -0400 Subject: Fix stack use-after-scope in InputReader READ of size 4 at 0x0079b1ac3a20 thread T121 (InputReader) Viewport [1] to add: virtual:android:277f1a09-b88d-4d1e-8716-796f114d080b #0 0x79b8820d53 in android::InputReaderConfiguration::getDisplayViewport(android::ViewportType, android::String8 const*, android::DisplayViewport*) const frameworks/native/services/inputflinger/InputReader.cpp:246:39 #1 0x79b8843fab in android::TouchInputMapper::configureSurface(long, bool*) frameworks/native/services/inputflinger/InputReader.cpp:3472:22 #2 0x79b88411b3 in android::TouchInputMapper::configure(long, android::InputReaderConfiguration const*, unsigned int) frameworks/native/services/inputflinger/InputReader.cpp:3248:9 #3 0x79b8825ff3 in android::InputDevice::configure(long, android::InputReaderConfiguration const*, unsigned int) frameworks/native/services/inputflinger/InputReader.cpp:1126:21 #4 0x79b8822653 in android::InputReader::refreshConfigurationLocked(unsigned int) frameworks/native/services/inputflinger/InputReader.cpp:612:25 #5 0x79b88239fb in android::InputReader::loopOnce() frameworks/native/services/inputflinger/InputReader.cpp:343:13 #6 0x79b882d507 in android::InputReaderThread::threadLoop() frameworks/native/services/inputflinger/InputReader.cpp:1004:14 #7 0x79d79e6113 in android::Thread::_threadLoop(void*) system/core/libutils/Threads.cpp:747:28 #8 0x79da914bbb in android::AndroidRuntime::javaThreadShell(void*) frameworks/base/core/jni/AndroidRuntime.cpp:1199:14 #9 0x79da20f31b in __pthread_start(void*) bionic/libc/bionic/pthread_create.cpp:214:18 #10 0x79da1c6dff in __start_thread bionic/libc/bionic/clone.cpp:47:16 Bug: 65378805 Test: asan build Change-Id: I5a65cb007fe4879ce9635572014a568583a2ef4a --- services/inputflinger/InputReader.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'services/inputflinger/InputReader.cpp') diff --git a/services/inputflinger/InputReader.cpp b/services/inputflinger/InputReader.cpp index 935d0f626e..d4266f6df9 100644 --- a/services/inputflinger/InputReader.cpp +++ b/services/inputflinger/InputReader.cpp @@ -257,7 +257,7 @@ bool InputReaderConfiguration::getDisplayViewport(ViewportType viewportType, const String8* uniqueDisplayId, DisplayViewport* outViewport) const { const DisplayViewport* viewport = NULL; if (viewportType == ViewportType::VIEWPORT_VIRTUAL && uniqueDisplayId != NULL) { - for (DisplayViewport currentViewport : mVirtualDisplays) { + for (const DisplayViewport& currentViewport : mVirtualDisplays) { if (currentViewport.uniqueId == *uniqueDisplayId) { viewport = ¤tViewport; break; -- cgit v1.2.3-59-g8ed1b