1 /* 2 * Copyright (C) 2019 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #pragma once 18 19 #include <ui/Rotation.h> 20 21 #include "CursorScrollAccumulator.h" 22 #include "InputMapper.h" 23 #include "SlopController.h" 24 25 namespace android { 26 27 class RotaryEncoderInputMapper : public InputMapper { 28 public: 29 template <class T, class... Args> 30 friend std::unique_ptr<T> createInputMapper(InputDeviceContext& deviceContext, 31 const InputReaderConfiguration& readerConfig, 32 Args... args); 33 virtual ~RotaryEncoderInputMapper(); 34 35 virtual uint32_t getSources() const override; 36 virtual void populateDeviceInfo(InputDeviceInfo& deviceInfo) override; 37 virtual void dump(std::string& dump) override; 38 [[nodiscard]] std::list<NotifyArgs> reconfigure(nsecs_t when, 39 const InputReaderConfiguration& config, 40 ConfigurationChanges changes) override; 41 [[nodiscard]] std::list<NotifyArgs> reset(nsecs_t when) override; 42 [[nodiscard]] std::list<NotifyArgs> process(const RawEvent& rawEvent) override; 43 44 private: 45 CursorScrollAccumulator mRotaryEncoderScrollAccumulator; 46 47 int32_t mSource; 48 float mScalingFactor; 49 /** Units per rotation, provided via the `device.res` IDC property. */ 50 float mResolution; 51 ui::Rotation mOrientation; 52 /** 53 * The minimum number of rotations to log for telemetry. 54 * Provided via `rotary_encoder.min_rotations_to_log` IDC property. If no value is provided in 55 * the IDC file, or if a non-positive value is provided, the telemetry will be disabled, and 56 * this value is set to the empty optional. 57 */ 58 std::optional<int32_t> mMinRotationsToLog; 59 /** 60 * A function to log count for telemetry. 61 * The char* is the logging key, and the int64_t is the value to log. 62 * Abstracting the actual logging APIs via this function is helpful for simple unit testing. 63 */ 64 std::function<void(const char*, int64_t)> mTelemetryLogCounter; 65 ui::LogicalDisplayId mDisplayId = ui::LogicalDisplayId::INVALID; 66 std::unique_ptr<SlopController> mSlopController; 67 68 /** Amount of raw scrolls (pre-slop) not yet logged for telemetry. */ 69 float mUnloggedScrolls = 0; 70 71 explicit RotaryEncoderInputMapper(InputDeviceContext& deviceContext, 72 const InputReaderConfiguration& readerConfig); 73 74 /** This is a test constructor that allows injecting the expresslog Counter logic. */ 75 RotaryEncoderInputMapper(InputDeviceContext& deviceContext, 76 const InputReaderConfiguration& readerConfig, 77 std::function<void(const char*, int64_t)> expressLogCounter); 78 [[nodiscard]] std::list<NotifyArgs> sync(nsecs_t when, nsecs_t readTime); 79 80 /** Logs a given amount of scroll for telemetry. */ 81 void logScroll(float scroll); 82 }; 83 84 } // namespace android 85