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