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 A11yError : uint32_t {
36     ERROR_NEED_REPORT_BASE = 1000, // error code > 1000 means need report
37     ERROR_READ_FAILED,
38     ERROR_CONNECT_A11Y_APPLICATION_FAILED,
39     ERROR_A11Y_APPLICATION_DISCONNECT_ABNORMALLY,
40     ERROR_CONNECT_TARGET_APPLICATION_FAILED,
41     ERROR_TARGET_APPLICATION_DISCONNECT_ABNORMALLY,
42     ERROR_QUERY_WINDOW_INFO_FAILED,
43     ERROR_QUERY_PACKAGE_INFO_FAILED,
44     ERROR_NEED_REPORT_END,
45 };
46 
47 class Utils {
48 public:
49     static void Parse(const AppExecFwk::ExtensionAbilityInfo &abilityInfo, AccessibilityAbilityInitParams &initParams);
50     static int64_t GetSystemTime();
51     static std::string GetUri(const OHOS::AppExecFwk::ElementName &elementName);
52     static std::string GetUri(const std::string &bundleName, const std::string &abilityName);
53     static std::string GetAbilityAutoStartStateKey(const std::string &bundleName, const std::string &abilityName,
54         int32_t accountId);
55     static void SelectUsefulFromVecWithSameBundle(std::vector<std::string> &selectVec, std::vector<std::string> &cmpVec,
56         bool &hasDif, const std::string &bundleName);
57     static void RecordUnavailableEvent(A11yUnavailableEvent event, A11yError errCode,
58         const std::string &bundleName = "", const std::string &abilityName = "");
59     static void RecordStartingA11yEvent(uint32_t flag);
60     static void RecordStartingA11yEvent(const std::string &name);
61     static void VectorToString(const std::vector<std::string> &vectorVal, std::string &stringOut);
62     static void StringToVector(const std::string &stringIn, std::vector<std::string> &vectorResult);
63     static int32_t GetUserIdByCallingUid();
64     static void RecordEnableShortkeyAbilityEvent(const std::string &name);
65     static void RecordOnZoomGestureEvent(const std::string &state);
66 
67 private:
68     static std::string TransferUnavailableEventToString(A11yUnavailableEvent type);
69 };
70 } // namespace Accessibility
71 } // namespace OHOS
72 #endif // ACCESSIBILITY_UTILS_H