1 /* 2 * Copyright (c) 2024-2025 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef RESSCHED_SCENE_RECOGNIZE_SLIDE_RECOGNIZER_H 17 #define RESSCHED_SCENE_RECOGNIZE_SLIDE_RECOGNIZER_H 18 19 #include "scene_recognizer_base.h" 20 #include "ffrt.h" 21 22 namespace OHOS { 23 namespace ResourceSchedule { 24 namespace SlideRecognizeStat { 25 enum : uint32_t { 26 IDLE, 27 SLIDE_NORMAL_DETECTING, 28 SLIDE_NORMAL, 29 LIST_FLING, 30 }; 31 } 32 static constexpr int64_t DEFAULT_LIST_FLINT_TIME_OUT_TIME = 3 * 1000 * 1000; 33 static constexpr int64_t DEFAULT_LIST_FLINT_END_TIME = 150 * 1000; 34 static constexpr float DEFAULT_LIST_FLING_SPEED_LIMIT = 3.0; 35 class SlideRecognizer : public SceneRecognizerBase { 36 public: 37 SlideRecognizer(); 38 ~SlideRecognizer(); 39 void OnDispatchResource(uint32_t, int64_t value, const nlohmann::json& payload) override; 40 void SetListFlingTimeoutTime(int64_t value); 41 void SetListFlingEndTime(int64_t value); 42 void SetListFlingSpeedLimit(float value); 43 private: 44 void HandleSlideEvent(int64_t value, const nlohmann::json& payload); 45 void HandleSendFrameEvent(const nlohmann::json& payload); 46 void HandleClickEvent(int64_t value, const nlohmann::json& payload); 47 void HandleSlideDetecting(const nlohmann::json& payload); 48 void HandleListFlingStart(const nlohmann::json& payload); 49 void HandleSlideOFFEvent(); 50 void StartDetecting(const nlohmann::json& payload); 51 nlohmann::json FillRealPidAndUid(const nlohmann::json& payload); 52 void ListFlingEnd(const nlohmann::json& payload); 53 uint32_t GetSlideStatus(); 54 ffrt::task_handle listFlingEndTask_ = nullptr; 55 ffrt::task_handle listFlingTimeOutTask_ = nullptr; 56 int64_t slideDetectingTime_ = -1; 57 uint32_t state_ = SlideRecognizeStat::IDLE; 58 int64_t listFlingTimeOutTime_ = DEFAULT_LIST_FLINT_TIME_OUT_TIME; 59 int64_t listFlingEndTime_ = DEFAULT_LIST_FLINT_END_TIME; 60 float listFlingSpeedLimit_ = DEFAULT_LIST_FLING_SPEED_LIMIT; 61 bool isInTouching_ = false; 62 std::string slidePid_ = ""; 63 std::string slideUid_ = ""; 64 std::string scrTid_ = ""; 65 }; 66 } // namespace ResourceSchedule 67 } // namespace OHOS 68 #endif // RESSCHED_SCENE_RECOGNIZE_SLIDE_RECOGNIZER_H