1 /*
2  * Copyright (c) 2021-2023 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 OHOS_FORM_FWK_FORM_UTIL_H
17 #define OHOS_FORM_FWK_FORM_UTIL_H
18 
19 #include "want.h"
20 
21 namespace OHOS {
22 namespace AppExecFwk {
23 using Want = OHOS::AAFwk::Want;
24 /**
25  * @class FormUtil
26  * form utils.
27  */
28 class FormUtil {
29 public:
30     /**
31      * @brief create form id for form.
32      * @param udidHash udid hash
33      * @return new form id.
34      */
35     static int64_t GenerateFormId(int64_t udidHash);
36 
37     /**
38      * @brief delete form id for form.
39      * @param formId The id of the form.
40      */
41     static void DeleteFormId(int64_t formId);
42 
43     /**
44      * @brief padding form id.
45      * @param formId The id of the form.
46      * @param udidHash udid hash.
47      * @return new form id.
48      */
49     static int64_t PaddingUdidHash(uint64_t formId, uint64_t udidHash);
50 
51     /**
52      * @brief create udid hash.
53      * @param udidHash udid hash.
54      * @return Returns true on success, false on failure.
55      */
56     static bool GenerateUdidHash(int64_t &udidHash);
57     /**
58      * @brief Get current system nanosecond.
59      * @return Current system nanosecond.
60      */
61     static int64_t GetCurrentNanosecond();
62     /**
63      * @brief Get current system millisecond.
64      * @return Current system millisecond.
65      */
66     static int64_t GetCurrentMillisecond();
67     /**
68      * @brief Get current system GetCurrentSteadyClockMillseconds.
69      * @return Current system GetCurrentSteadyClockMillseconds.
70      */
71     static int64_t GetCurrentSteadyClockMillseconds();
72 
73     /**
74      * @brief Get current system millisecond.
75      * @return Current system millisecond.
76      */
77     static int64_t GetNowMillisecond();
78 
79     /**
80      * @brief Get millisecond from tm.
81      * @param tmAtTime tm time.
82      * @return Millisecond.
83      */
84     static int64_t GetMillisecondFromTm(struct tm &tmAtTime);
85 
86     /**
87      * @brief split string.
88      * @param in string.
89      * @param delim delimiter.
90      * @return string list.
91      */
92     static std::vector<std::string> StringSplit(const std::string &in, const std::string &delim);
93 
94     /**
95      * @brief get current active account id.
96      * @return int current active account id.
97      */
98     static int GetCurrentAccountId();
99 
100     /**
101      * @brief Check if the caller ability is SA.
102      * @return Returns true if is SA call; returns false otherwise.
103      */
104     static bool IsSACall();
105 
106     /**
107      * @brief Checks whether the caller has a certain permission.
108      * @param permissionName The name of the permission.
109      * @return Returns true if the caller has certain permissions; returns false otherwise.
110      */
111     static bool VerifyCallingPermission(const std::string &permissionName);
112 
113     /**
114      * @brief Convert string to int64_t
115      *
116      * @param[in] strInfo The string information
117      * @param[out] int64Value Convert string to int64_t
118      *
119      * @return Return the convert result
120      */
121     static bool ConvertStringToInt64(const std::string &strInfo, int64_t &int64Value);
122 };
123 } // namespace AppExecFwk
124 } // namespace OHOS
125 #endif // OHOS_FORM_FWK_FORM_UTIL_H
126