From a0e7f731c748e937879856a38368f8bcae29e190 Mon Sep 17 00:00:00 2001 From: Siarhei Vishniakou Date: Wed, 17 Jan 2018 11:49:04 -0800 Subject: Add an InputClassifier HAL The new HAL will be responsible for processing touch video frames that are received from InputClassifier stage. After processing, the HAL will generate a classification of the current gesture. This classification will later be provided to the app via the MotionEvent.getClassification() public API. The eventual goal is to classify each event stream as a force touch or not a force touch. An example implementation of the HAL is presented here. This code was used for local testing on blueline, and should not be actually installed or used in any way other than for reference. Bug: 62940136 Test: observed "detected deep press" logs when pressing with large finger area on the touchscreen Change-Id: Id6ac4337435e4ac07877da11ca184b6dd4d64780 --- input/classifier/1.0/default/InputClassifier.cpp | 65 ++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 input/classifier/1.0/default/InputClassifier.cpp (limited to 'input/classifier/1.0/default/InputClassifier.cpp') diff --git a/input/classifier/1.0/default/InputClassifier.cpp b/input/classifier/1.0/default/InputClassifier.cpp new file mode 100644 index 0000000000..c463361dcb --- /dev/null +++ b/input/classifier/1.0/default/InputClassifier.cpp @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2019 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define LOG_TAG "InputClassifierHAL" + +#include "InputClassifier.h" +#include +#include +#include + +using namespace android::hardware::input::classifier::V1_0; + +namespace android { +namespace hardware { +namespace input { +namespace classifier { +namespace V1_0 { +namespace implementation { + +// Methods from ::android::hardware::input::classifier::V1_0::IInputClassifier follow. +Return InputClassifier::classify(const MotionEvent& event) { + /** + * In this example implementation, we will see how many "pixels" inside the video frame + * exceed the value of 250. If more than 6 such pixels are present, then treat the event + * as a "DEEP_PRESS". + */ + if (event.frames.size() == 0) { + return Classification::NONE; + } + ALOGI("Frame(O) timestamp = %" PRIu64 ", received %zu frame(s)", event.frames[0].timestamp, + event.frames.size()); + for (const VideoFrame& frame : event.frames) { + size_t count = 0; + for (size_t i = 0; i < frame.data.size(); i++) { + if (frame.data[i] > 250) { + count++; + } + } + if (count > 6) { + return Classification::DEEP_PRESS; + } + } + + return Classification::NONE; +} + +} // namespace implementation +} // namespace V1_0 +} // namespace classifier +} // namespace input +} // namespace hardware +} // namespace android -- cgit v1.2.3 From 45c1d0c19285f3abcbf394357541027841995c8e Mon Sep 17 00:00:00 2001 From: Siarhei Vishniakou Date: Thu, 24 Jan 2019 10:38:02 -0800 Subject: Move input definitions into separate HAL The types added for input in InputClassifier HAL are not specific to that HAL. These are common input definitions. To allow for future reuse in this and other HALs, move these definitions into a separate, type-only HAL android::hardware::input::common. This will be similar to such existing HALs as: hardware/interfaces/graphics/common hardware/interfaces/camera/common hardware/interfaces/audio/common Test: make only Bug: 111480215 Change-Id: I16d76d6bdb48b24487b232fda45c6146e1003fe9 --- input/classifier/1.0/default/InputClassifier.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'input/classifier/1.0/default/InputClassifier.cpp') diff --git a/input/classifier/1.0/default/InputClassifier.cpp b/input/classifier/1.0/default/InputClassifier.cpp index c463361dcb..7005e9d8b6 100644 --- a/input/classifier/1.0/default/InputClassifier.cpp +++ b/input/classifier/1.0/default/InputClassifier.cpp @@ -21,7 +21,7 @@ #include #include -using namespace android::hardware::input::classifier::V1_0; +using namespace android::hardware::input::common::V1_0; namespace android { namespace hardware { -- cgit v1.2.3 From ba9d3c83b7c1a7cd6d48c1f49c7f3cfc418592fe Mon Sep 17 00:00:00 2001 From: Siarhei Vishniakou Date: Wed, 23 Jan 2019 15:14:20 -0800 Subject: Add reset to InputClassifier HAL The reset will be used to prevent an inconsistent stream of events to be sent to the HAL. Bug: 111480215 Test: make only Change-Id: I40c7d671f094065e3fcaff0d83e826c580dcae7a --- input/classifier/1.0/default/InputClassifier.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'input/classifier/1.0/default/InputClassifier.cpp') diff --git a/input/classifier/1.0/default/InputClassifier.cpp b/input/classifier/1.0/default/InputClassifier.cpp index 7005e9d8b6..a78bbc5c94 100644 --- a/input/classifier/1.0/default/InputClassifier.cpp +++ b/input/classifier/1.0/default/InputClassifier.cpp @@ -57,6 +57,18 @@ Return InputClassifier::classify(const MotionEvent& event) { return Classification::NONE; } +Return InputClassifier::reset() { + // We don't have any internal state in this example implementation, + // so no work needed here. + return Void(); +} + +Return InputClassifier::resetDevice(int32_t /*deviceId*/) { + // We don't have any internal per-device state in this example implementation, + // so no work needed here. + return Void(); +} + } // namespace implementation } // namespace V1_0 } // namespace classifier -- cgit v1.2.3 From 443e98b12d829a83f25b845f31a7eccd71aa01db Mon Sep 17 00:00:00 2001 From: Siarhei Vishniakou Date: Thu, 7 Feb 2019 15:42:06 -0800 Subject: Remove impl from InputClassifier HAL Make the reference implementation for InputClassifier HAL do nothing. This is to allow cuttlefish to install this implementation. It is safe for any device to install this implementation, and is equivalent to not having the HAL running at all. Test: boot up cuttlefish, and interact with the virtual device to ensure that input works okay. Then 'ps -A | grep -i input' and ensure that the HAL is running on the device. Bug: 122600147 Change-Id: I841811bc0da3d78db8d7c1589cf1c59819d901a1 --- input/classifier/1.0/default/InputClassifier.cpp | 33 ++++++------------------ 1 file changed, 8 insertions(+), 25 deletions(-) (limited to 'input/classifier/1.0/default/InputClassifier.cpp') diff --git a/input/classifier/1.0/default/InputClassifier.cpp b/input/classifier/1.0/default/InputClassifier.cpp index a78bbc5c94..cce9190cc8 100644 --- a/input/classifier/1.0/default/InputClassifier.cpp +++ b/input/classifier/1.0/default/InputClassifier.cpp @@ -31,41 +31,24 @@ namespace V1_0 { namespace implementation { // Methods from ::android::hardware::input::classifier::V1_0::IInputClassifier follow. -Return InputClassifier::classify(const MotionEvent& event) { +Return InputClassifier::classify(const MotionEvent& /*event*/) { /** - * In this example implementation, we will see how many "pixels" inside the video frame - * exceed the value of 250. If more than 6 such pixels are present, then treat the event - * as a "DEEP_PRESS". + * The touchscreen data is highly device-dependent. + * As a result, the implementation of this method will likely be hardware-specific. + * Here we just report gesture as not having any classification, which means that the + * default action will be taken in the framework. + * This is equivalent to not having the InputClassifier HAL at all. */ - if (event.frames.size() == 0) { - return Classification::NONE; - } - ALOGI("Frame(O) timestamp = %" PRIu64 ", received %zu frame(s)", event.frames[0].timestamp, - event.frames.size()); - for (const VideoFrame& frame : event.frames) { - size_t count = 0; - for (size_t i = 0; i < frame.data.size(); i++) { - if (frame.data[i] > 250) { - count++; - } - } - if (count > 6) { - return Classification::DEEP_PRESS; - } - } - return Classification::NONE; } Return InputClassifier::reset() { - // We don't have any internal state in this example implementation, - // so no work needed here. + // We don't have any internal state, so no work needed here. return Void(); } Return InputClassifier::resetDevice(int32_t /*deviceId*/) { - // We don't have any internal per-device state in this example implementation, - // so no work needed here. + // We don't have any internal per-device state, so no work needed here. return Void(); } -- cgit v1.2.3