• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 want for form.
32      * @param formName The name of the form.
33      * @param specificationId specification id.
34      * @param isTemporaryForm temporary form or not.
35      * @param want The want of the form.
36      */
37     static void CreateFormWant(const std::string &formName, const int32_t specificationId,
38         const bool isTemporaryForm, Want &want);
39     /**
40      * @brief create default want for form.
41      * @param want The want of the form..
42      * @param uri The uri.
43      * @param userId user id.
44      */
45     static void CreateDefaultFormWant(Want &want, const std::string &uri, const int32_t userId);
46 
47     /**
48      * @brief create form id for form.
49      * @param udidHash udid hash
50      * @return new form id.
51      */
52     static int64_t GenerateFormId(int64_t udidHash);
53 
54     /**
55      * @brief padding form id.
56      * @param formId The id of the form.
57      * @param udidHash udid hash.
58      * @return new form id.
59      */
60     static int64_t PaddingUdidHash(uint64_t formId, uint64_t udidHash);
61 
62     /**
63      * @brief create udid hash.
64      * @param udidHash udid hash.
65      * @return Returns true on success, false on failure.
66      */
67     static bool GenerateUdidHash(int64_t &udidHash);
68     /**
69      * @brief Get current system nanosecond.
70      * @return Current system nanosecond.
71      */
72     static int64_t GetCurrentNanosecond();
73     /**
74      * @brief Get current system millisecond.
75      * @return Current system millisecond.
76      */
77     static int64_t GetCurrentMillisecond();
78 
79     /**
80      * @brief Get current system microsecond.
81      * @return Current system microsecond.
82      */
83     static int64_t GetCurrentMicrosecond();
84 
85     /**
86      * @brief Get millisecond from tm.
87      * @param tmAtTime tm time.
88      * @return Millisecond.
89      */
90     static int64_t GetMillisecondFromTm(struct tm &tmAtTime);
91 
92     /**
93      * @brief split string.
94      * @param in string.
95      * @param delim delimiter.
96      * @return string list.
97      */
98     static std::vector<std::string> StringSplit(const std::string &in, const std::string &delim);
99 
100     /**
101      * @brief get current active account id.
102      * @return int current active account id.
103      */
104     static int GetCurrentAccountId();
105 
106     /**
107      * @brief Check if the caller ability is SA.
108      * @return Returns true if is SA call; returns false otherwise.
109      */
110     static bool IsSACall();
111 
112     /**
113      * @brief Checks whether the caller has a certain permission.
114      * @param permissionName The name of the permission.
115      * @return Returns true if the caller has certain permissions; returns false otherwise.
116      */
117     static bool VerifyCallingPermission(const std::string &permissionName);
118 
119     /**
120      * @brief Convert string to int64_t
121      *
122      * @param[in] strInfo The string information
123      * @param[out] int64Value Convert string to int64_t
124      *
125      * @return Return the convert result
126      */
127     static bool ConvertStringToInt64(const std::string &strInfo, int64_t &int64Value);
128 };
129 } // namespace AppExecFwk
130 } // namespace OHOS
131 #endif // OHOS_FORM_FWK_FORM_UTIL_H
132