1 /* 2 * Copyright (c) 2021-2024 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 KEY_COMMAND_HANDLER_UTIL_H 17 #define KEY_COMMAND_HANDLER_UTIL_H 18 19 #include "config_policy_utils.h" 20 #include "system_ability_definition.h" 21 22 #include "bytrace_adapter.h" 23 #include "dfx_hisysevent.h" 24 #include "display_event_monitor.h" 25 #include "input_event_data_transformation.h" 26 #include "input_event_handler.h" 27 #include "i_preference_manager.h" 28 #include "json_parser.h" 29 #include "setting_datashare.h" 30 #include "util_ex.h" 31 32 #undef MMI_LOG_TAG 33 #define MMI_LOG_TAG "KeyCommandHandlerUtil" 34 35 namespace OHOS { 36 namespace MMI { 37 constexpr int32_t MAX_PREKEYS_NUM = 4; 38 constexpr int32_t MAX_SEQUENCEKEYS_NUM = 10; 39 constexpr int64_t MAX_DELAY_TIME = 1000000; 40 constexpr int64_t MAX_REPEATKEY_DELAY_TIME = 1000; 41 constexpr int64_t MAX_KEYDOWNDURATION_TIME = 10000; 42 constexpr int64_t MAX_ABILITYSTARTDELAY_TIME = 3000; 43 constexpr int64_t SECONDS_SYSTEM = 1000; 44 constexpr int32_t SPECIAL_KEY_DOWN_DELAY = 150; 45 constexpr int32_t MAX_SHORT_KEY_DOWN_DURATION = 4000; 46 constexpr int32_t MIN_SHORT_KEY_DOWN_DURATION = 0; 47 constexpr int32_t TOUCH_MAX_THRESHOLD = 20; 48 constexpr int32_t TOUCH_MOVE_THRESHOLD = 15; 49 constexpr int32_t TWO_FINGERS_DISTANCE_LIMIT = 16; 50 constexpr int32_t TWO_FINGERS_TIME_LIMIT = 150000; 51 constexpr int32_t SIMULATE_POINTER_ID = 10000; 52 constexpr int32_t TOUCH_LIFT_LIMIT = 24; 53 constexpr int32_t TOUCH_RIGHT_LIMIT = 24; 54 constexpr int32_t TOUCH_TOP_LIMIT = 80; 55 constexpr int32_t TOUCH_BOTTOM_LIMIT = 41; 56 constexpr int32_t PARAMETER_ERROR = 401; 57 constexpr int32_t KNUCKLE_KNOCKS = 1; 58 constexpr size_t SINGLE_KNUCKLE_SIZE = 1; 59 constexpr size_t DOUBLE_KNUCKLE_SIZE = 2; 60 constexpr int32_t MAX_TIME_FOR_ADJUST_CONFIG = 5; 61 constexpr int32_t POW_SQUARE = 2; 62 constexpr int64_t DOUBLE_CLICK_INTERVAL_TIME_SLOW = 450000; 63 constexpr float DOUBLE_CLICK_DISTANCE_DEFAULT_CONFIG = 64.0f; 64 constexpr float DOUBLE_CLICK_DISTANCE_LONG_CONFIG = 96.0f; 65 constexpr float VPR_CONFIG = 3.25f; 66 constexpr int32_t REMOVE_OBSERVER = -2; 67 constexpr int32_t ACTIVE_EVENT = 2; 68 constexpr int32_t LONG_ABILITY_START_DELAY = 2000; 69 constexpr int32_t WINDOW_INPUT_METHOD_TYPE = 2105; 70 constexpr int32_t WINDOW_SCREENSHOT_TYPE = 2123; 71 const std::string EXTENSION_ABILITY = "extensionAbility"; 72 const std::string SINGLE_KNUCKLE_ABILITY = "SingleKnuckleDoubleClickGesture"; 73 const std::string DOUBLE_KNUCKLE_ABILITY = "DoubleKnuckleDoubleClickGesture"; 74 const std::string TOUCHPAD_TRIP_TAP_ABILITY = "ThreeFingersTap"; 75 const std::string RECORD_KNUCKLE_SWITCH = "fingersense_screen_recording_enabled"; 76 const std::string SNAPSHOT_KNUCKLE_SWITCH = "fingersense_smartshot_enabled"; 77 constexpr int32_t MENU_KEY_DOWN_DELAY = 800; 78 79 enum SpecialType { 80 SPECIAL_ALL = 0, 81 SUBSCRIBER_BEFORE_DELAY = 1, 82 KEY_DOWN_ACTION = 2 83 }; 84 const std::map<int32_t, SpecialType> SPECIAL_KEYS = { 85 { KeyEvent::KEYCODE_POWER, SpecialType::KEY_DOWN_ACTION }, 86 { KeyEvent::KEYCODE_VOLUME_DOWN, SpecialType::KEY_DOWN_ACTION }, 87 { KeyEvent::KEYCODE_VOLUME_UP, SpecialType::KEY_DOWN_ACTION } 88 }; 89 90 bool IsSpecialType(int32_t keyCode, SpecialType type); 91 bool GetBusinessId(const cJSON* jsonData, std::string &businessIdValue, std::vector<std::string> &businessIds); 92 bool GetPreKeys(const cJSON* jsonData, ShortcutKey &shortcutKey); 93 bool GetTrigger(const cJSON* jsonData, int32_t &triggerType); 94 bool GetKeyDownDuration(const cJSON* jsonData, int32_t &keyDownDurationInt); 95 bool GetKeyFinalKey(const cJSON* jsonData, int32_t &finalKeyInt); 96 void GetKeyVal(const cJSON* json, const std::string &key, std::string &value); 97 bool GetEntities(const cJSON* jsonAbility, Ability &ability); 98 bool GetParams(const cJSON* jsonAbility, Ability &ability); 99 bool PackageAbility(const cJSON* jsonAbility, Ability &ability); 100 bool ConvertToShortcutKey(const cJSON* jsonData, ShortcutKey &shortcutKey, std::vector<std::string> &businessIds); 101 bool GetKeyCode(const cJSON* jsonData, int32_t &keyCodeInt); 102 bool GetKeyAction(const cJSON* jsonData, int32_t &keyActionInt); 103 bool GetDelay(const cJSON* jsonData, int64_t &delayInt); 104 bool GetRepeatKeyDelay(const cJSON* jsonData, int64_t &delayInt); 105 bool GetRepeatTimes(const cJSON* jsonData, int32_t &repeatTimesInt); 106 bool GetAbilityStartDelay(const cJSON* jsonData, int64_t &abilityStartDelayInt); 107 bool PackageSequenceKey(const cJSON* sequenceKeysJson, SequenceKey &sequenceKey); 108 bool GetSequenceKeys(const cJSON* jsonData, Sequence &sequence); 109 bool IsSequenceKeysValid(const Sequence &sequence); 110 bool ConvertToKeySequence(const cJSON* jsonData, Sequence &sequence); 111 bool ConvertToExcludeKey(const cJSON* jsonData, ExcludeKey &exKey); 112 bool ConvertToKeyRepeat(const cJSON* jsonData, RepeatKey &repeatKey); 113 std::string GenerateKey(const ShortcutKey& key); 114 bool ParseShortcutKeys(const JsonParser& parser, std::map<std::string, ShortcutKey>& shortcutKeyMap, 115 std::vector<std::string>& businessIds); 116 bool ParseSequences(const JsonParser& parser, std::vector<Sequence>& sequenceVec); 117 bool ParseExcludeKeys(const JsonParser& parser, std::vector<ExcludeKey>& excludeKeyVec); 118 bool ParseRepeatKeys(const JsonParser& parser, std::vector<RepeatKey>& repeatKeyVec, 119 std::map<int32_t, int32_t>& repeatKeyMaxTimes); 120 bool ParseTwoFingerGesture(const JsonParser& parser, TwoFingerGesture& gesture); 121 bool IsPackageKnuckleGesture(const cJSON* jsonData, const std::string knuckleGesture, Ability &launchAbility); 122 bool IsParseKnuckleGesture(const JsonParser &parser, const std::string ability, KnuckleGesture &knuckleGesture); 123 float AbsDiff(KnuckleGesture knuckleGesture, const std::shared_ptr<PointerEvent> pointerEvent); 124 bool IsEqual(float f1, float f2); 125 bool ParseMultiFingersTap(const JsonParser &parser, const std::string ability, MultiFingersTap &mulFingersTap); 126 char* GetProFileAbsPath(const char* fileName, char* buf, int32_t length); 127 } // namespace MMI 128 } // namespace OHOS 129 #endif // KEY_COMMAND_HANDLER_UTIL_H 130