• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 std::string GetBundleNameFromUri(const std::string &uri);
61     static void SelectUsefulFromVecWithSameBundle(std::vector<std::string> &selectVec, std::vector<std::string> &cmpVec,
62         bool &hasDif, const std::string &bundleName);
63     static void RecordUnavailableEvent(A11yUnavailableEvent event, A11yError errCode,
64         const std::string &bundleName = "", const std::string &abilityName = "");
65     static void RecordStartingA11yEvent(uint32_t flag);
66     static void RecordStartingA11yEvent(const std::string &name);
67     static void RecordMSDPUnavailableEvent(const std::string &name);
68     static void VectorToString(const std::vector<std::string> &vectorVal, std::string &stringOut);
69     static void StringToVector(const std::string &stringIn, std::vector<std::string> &vectorResult);
70     static int32_t GetUserIdByCallingUid();
71     static bool GetBundleNameByCallingUid(std::string &bundleName);
72     static void RecordEnableShortkeyAbilityEvent(const std::string &name, const bool &enableState);
73     static void RecordOnZoomGestureEvent(const std::string &state, const bool &isFullType);
74     static void RecordOnRemoveSystemAbility(int32_t systemAbilityId,
75         const std::string &bundleName = "", const std::string &abilityName = "");
76     static void RecordDatashareInteraction(A11yDatashareValueType type, const std::string &businessName = "",
77         const std::string &bundleName = "", const std::string &abilityName = "");
78     static bool UpdateColorModeConfiguration(int32_t &accountId);
79     static bool IsWideFold();
80     static bool IsBigFold();
81     static std::string FormatString(const std::string& format, const std::string& value);
82 private:
83     static std::string TransferUnavailableEventToString(A11yUnavailableEvent type);
84 };
85 } // namespace Accessibility
86 } // namespace OHOS
87 #endif // ACCESSIBILITY_UTILS_H