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 constexpr int BASE_REQUEST_CODE_NUM = 10; 24 using Want = OHOS::AAFwk::Want; 25 26 enum class TestFormNum { 27 Num1 = 1, Num2, Num3, Num4, Num5, 28 Num6, Num7, Num8, Num9, Num10, 29 Num11, Num12, Num13, Num14, Num15, 30 Num16, Num17, Num18, Num19, Num20, 31 Num21, Num22, Num23, Num24, Num25, 32 Num26, Num27, Num28, Num29, Num30, 33 Num31, Num32, Num33, Num34, Num35, 34 Num36, Num37, Num38, Num39, Num40, 35 }; 36 37 /** 38 * @class FormUtil 39 * form utils. 40 */ 41 class FormUtil { 42 public: 43 /** 44 * @brief create form id for form. 45 * @param udidHash udid hash 46 * @return new form id. 47 */ 48 static int64_t GenerateFormId(int64_t udidHash); 49 50 /** 51 * @brief delete form id for form. 52 * @param formId The id of the form. 53 */ 54 static void DeleteFormId(int64_t formId); 55 56 /** 57 * @brief padding form id. 58 * @param formId The id of the form. 59 * @param udidHash udid hash. 60 * @return new form id. 61 */ 62 static int64_t PaddingUdidHash(uint64_t formId, uint64_t udidHash); 63 64 /** 65 * @brief create udid hash. 66 * @param udidHash udid hash. 67 * @return Returns true on success, false on failure. 68 */ 69 static bool GenerateUdidHash(int64_t &udidHash); 70 /** 71 * @brief Get current system nanosecond. 72 * @return Current system nanosecond. 73 */ 74 static int64_t GetCurrentNanosecond(); 75 /** 76 * @brief Get current system millisecond. 77 * @return Current system millisecond. 78 */ 79 static int64_t GetCurrentMillisecond(); 80 /** 81 * @brief Get current system GetCurrentSteadyClockMillseconds. 82 * @return Current system GetCurrentSteadyClockMillseconds. 83 */ 84 static int64_t GetCurrentSteadyClockMillseconds(); 85 86 /** 87 * @brief Get current system millisecond. 88 * @return Current system millisecond. 89 */ 90 static int64_t GetNowMillisecond(); 91 92 /** 93 * @brief Get millisecond from tm. 94 * @param tmAtTime tm time. 95 * @return Millisecond. 96 */ 97 static int64_t GetMillisecondFromTm(struct tm &tmAtTime); 98 99 /** 100 * @brief split string. 101 * @param in string. 102 * @param delim delimiter. 103 * @return string list. 104 */ 105 static std::vector<std::string> StringSplit(const std::string &in, const std::string &delim); 106 static int TestFormId1(int &formId); 107 static int TestFormId2(int &formId); 108 static int TestFormId3(int &formId); 109 static int TestFormId4(int &formId); 110 static int TestFormId5(int &formId); 111 static int TestFormId6(int &formId); 112 static int TestFormId7(int &formId); 113 static int TestFormId8(int &formId); 114 static int TestFormId9(int &formId); 115 static int TestFormId10(int &formId); 116 static int TestFormId11(int &formId); 117 static int TestFormId12(int &formId); 118 static int TestFormId13(int &formId); 119 static int TestFormId14(int &formId); 120 static int TestFormId15(int &formId); 121 static int TestFormId16(int &formId); 122 static int TestFormId17(int &formId); 123 static int TestFormId18(int &formId); 124 static int TestFormId19(int &formId); 125 static int TestFormId20(int &formId); 126 static int TestFormId21(int &formId); 127 static int TestFormId22(int &formId); 128 static int TestFormId23(int &formId); 129 static int TestFormId24(int &formId); 130 static int TestFormId25(int &formId); 131 static int TestFormId26(int &formId); 132 static int TestFormId27(int &formId); 133 static int TestFormId28(int &formId); 134 static int TestFormId29(int &formId); 135 static int TestFormId30(int &formId); 136 static int TestFormId31(int &formId); 137 static int TestFormId32(int &formId); 138 static int TestFormId33(int &formId); 139 static int TestFormId34(int &formId); 140 static int TestFormId35(int &formId); 141 142 /** 143 * @brief get current active account id. 144 * @return int current active account id. 145 */ 146 static int GetCurrentAccountId(); 147 148 /** 149 * @brief Check if the caller ability is SA. 150 * @return Returns true if is SA call; returns false otherwise. 151 */ 152 static bool IsSACall(); 153 154 /** 155 * @brief Checks whether the caller has a certain permission. 156 * @param permissionName The name of the permission. 157 * @return Returns true if the caller has certain permissions; returns false otherwise. 158 */ 159 static bool VerifyCallingPermission(const std::string &permissionName); 160 161 /** 162 * @brief Convert string to int64_t 163 * 164 * @param[in] strInfo The string information 165 * @param[out] int64Value Convert string to int64_t 166 * 167 * @return Return the convert result 168 */ 169 static bool ConvertStringToInt64(const std::string &strInfo, int64_t &int64Value); 170 171 static int ConvertStringToInt(const std::string &strInfo, int radix = BASE_REQUEST_CODE_NUM); 172 173 static long long ConvertStringToLongLong(const std::string &strInfo, int radix = BASE_REQUEST_CODE_NUM); 174 175 static bool IsActiveUser(const int32_t userId); 176 }; 177 } // namespace AppExecFwk 178 } // namespace OHOS 179 #endif // OHOS_FORM_FWK_FORM_UTIL_H 180