1 /* 2 * Copyright (C) 2022 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 ACCESSIBILITY_UTILS_H 17 #define ACCESSIBILITY_UTILS_H 18 19 #include "accessibility_ability_info.h" 20 #include "element_name.h" 21 #include "extension_ability_info.h" 22 23 namespace OHOS { 24 namespace Accessibility { 25 enum class TraceTaskId : int32_t { 26 ACCESSIBLE_ABILITY_CONNECT = 0, 27 }; 28 29 enum class A11yUnavailableEvent : uint32_t { 30 READ_EVENT, 31 CONNECT_EVENT, 32 QUERY_EVENT, 33 }; 34 35 enum class A11yDatashareValueType : uint32_t { 36 GET, 37 UPDATE, 38 }; 39 40 enum class A11yError : uint32_t { 41 ERROR_NEED_REPORT_BASE = 1000, // error code > 1000 means need report 42 ERROR_READ_FAILED, 43 ERROR_CONNECT_A11Y_APPLICATION_FAILED, 44 ERROR_A11Y_APPLICATION_DISCONNECT_ABNORMALLY, 45 ERROR_CONNECT_TARGET_APPLICATION_FAILED, 46 ERROR_TARGET_APPLICATION_DISCONNECT_ABNORMALLY, 47 ERROR_QUERY_WINDOW_INFO_FAILED, 48 ERROR_QUERY_PACKAGE_INFO_FAILED, 49 ERROR_NEED_REPORT_END, 50 }; 51 52 class Utils { 53 public: 54 static void Parse(const AppExecFwk::ExtensionAbilityInfo &abilityInfo, AccessibilityAbilityInitParams &initParams); 55 static int64_t GetSystemTime(); 56 static std::string GetUri(const OHOS::AppExecFwk::ElementName &elementName); 57 static std::string GetUri(const std::string &bundleName, const std::string &abilityName); 58 static std::string GetAbilityAutoStartStateKey(const std::string &bundleName, const std::string &abilityName, 59 int32_t accountId); 60 static void SelectUsefulFromVecWithSameBundle(std::vector<std::string> &selectVec, std::vector<std::string> &cmpVec, 61 bool &hasDif, const std::string &bundleName); 62 static void RecordUnavailableEvent(A11yUnavailableEvent event, A11yError errCode, 63 const std::string &bundleName = "", const std::string &abilityName = ""); 64 static void RecordStartingA11yEvent(uint32_t flag); 65 static void RecordStartingA11yEvent(const std::string &name); 66 static void VectorToString(const std::vector<std::string> &vectorVal, std::string &stringOut); 67 static void StringToVector(const std::string &stringIn, std::vector<std::string> &vectorResult); 68 static int32_t GetUserIdByCallingUid(); 69 static void RecordEnableShortkeyAbilityEvent(const std::string &name, const bool &enableState); 70 static void RecordOnZoomGestureEvent(const std::string &state); 71 static void RecordOnRemoveSystemAbility(int32_t systemAbilityId, 72 const std::string &bundleName = "", const std::string &abilityName = ""); 73 static void RecordDatashareInteraction(A11yDatashareValueType type, const std::string &businessName = "", 74 const std::string &bundleName = "", const std::string &abilityName = ""); 75 76 private: 77 static std::string TransferUnavailableEventToString(A11yUnavailableEvent type); 78 }; 79 } // namespace Accessibility 80 } // namespace OHOS 81 #endif // ACCESSIBILITY_UTILS_H