13ceed64fSopenharmony_ci/* 23ceed64fSopenharmony_ci * Copyright (c) 2021-2023 Huawei Device Co., Ltd. 33ceed64fSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License")_; 43ceed64fSopenharmony_ci * you may not use this file except in compliance with the License. 53ceed64fSopenharmony_ci * You may obtain a copy of the License at 63ceed64fSopenharmony_ci * 73ceed64fSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 83ceed64fSopenharmony_ci * 93ceed64fSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 103ceed64fSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 113ceed64fSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 123ceed64fSopenharmony_ci * See the License for the specific language governing permissions and 133ceed64fSopenharmony_ci * limitations under the License. 143ceed64fSopenharmony_ci */ 153ceed64fSopenharmony_ci 163ceed64fSopenharmony_ci#ifndef OHOS_FORM_FWK_FORM_UTIL_H 173ceed64fSopenharmony_ci#define OHOS_FORM_FWK_FORM_UTIL_H 183ceed64fSopenharmony_ci 193ceed64fSopenharmony_ci#include "want.h" 203ceed64fSopenharmony_ci 213ceed64fSopenharmony_cinamespace OHOS { 223ceed64fSopenharmony_cinamespace AppExecFwk { 233ceed64fSopenharmony_ciusing Want = OHOS::AAFwk::Want; 243ceed64fSopenharmony_ci/** 253ceed64fSopenharmony_ci * @class FormUtil 263ceed64fSopenharmony_ci * form utils. 273ceed64fSopenharmony_ci */ 283ceed64fSopenharmony_ciclass FormUtil { 293ceed64fSopenharmony_cipublic: 303ceed64fSopenharmony_ci /** 313ceed64fSopenharmony_ci * @brief create form id for form. 323ceed64fSopenharmony_ci * @param udidHash udid hash 333ceed64fSopenharmony_ci * @return new form id. 343ceed64fSopenharmony_ci */ 353ceed64fSopenharmony_ci static int64_t GenerateFormId(int64_t udidHash); 363ceed64fSopenharmony_ci 373ceed64fSopenharmony_ci /** 383ceed64fSopenharmony_ci * @brief delete form id for form. 393ceed64fSopenharmony_ci * @param formId The id of the form. 403ceed64fSopenharmony_ci */ 413ceed64fSopenharmony_ci static void DeleteFormId(int64_t formId); 423ceed64fSopenharmony_ci 433ceed64fSopenharmony_ci /** 443ceed64fSopenharmony_ci * @brief padding form id. 453ceed64fSopenharmony_ci * @param formId The id of the form. 463ceed64fSopenharmony_ci * @param udidHash udid hash. 473ceed64fSopenharmony_ci * @return new form id. 483ceed64fSopenharmony_ci */ 493ceed64fSopenharmony_ci static int64_t PaddingUdidHash(uint64_t formId, uint64_t udidHash); 503ceed64fSopenharmony_ci 513ceed64fSopenharmony_ci /** 523ceed64fSopenharmony_ci * @brief create udid hash. 533ceed64fSopenharmony_ci * @param udidHash udid hash. 543ceed64fSopenharmony_ci * @return Returns true on success, false on failure. 553ceed64fSopenharmony_ci */ 563ceed64fSopenharmony_ci static bool GenerateUdidHash(int64_t &udidHash); 573ceed64fSopenharmony_ci /** 583ceed64fSopenharmony_ci * @brief Get current system nanosecond. 593ceed64fSopenharmony_ci * @return Current system nanosecond. 603ceed64fSopenharmony_ci */ 613ceed64fSopenharmony_ci static int64_t GetCurrentNanosecond(); 623ceed64fSopenharmony_ci /** 633ceed64fSopenharmony_ci * @brief Get current system millisecond. 643ceed64fSopenharmony_ci * @return Current system millisecond. 653ceed64fSopenharmony_ci */ 663ceed64fSopenharmony_ci static int64_t GetCurrentMillisecond(); 673ceed64fSopenharmony_ci /** 683ceed64fSopenharmony_ci * @brief Get current system GetCurrentSteadyClockMillseconds. 693ceed64fSopenharmony_ci * @return Current system GetCurrentSteadyClockMillseconds. 703ceed64fSopenharmony_ci */ 713ceed64fSopenharmony_ci static int64_t GetCurrentSteadyClockMillseconds(); 723ceed64fSopenharmony_ci 733ceed64fSopenharmony_ci /** 743ceed64fSopenharmony_ci * @brief Get current system millisecond. 753ceed64fSopenharmony_ci * @return Current system millisecond. 763ceed64fSopenharmony_ci */ 773ceed64fSopenharmony_ci static int64_t GetNowMillisecond(); 783ceed64fSopenharmony_ci 793ceed64fSopenharmony_ci /** 803ceed64fSopenharmony_ci * @brief Get millisecond from tm. 813ceed64fSopenharmony_ci * @param tmAtTime tm time. 823ceed64fSopenharmony_ci * @return Millisecond. 833ceed64fSopenharmony_ci */ 843ceed64fSopenharmony_ci static int64_t GetMillisecondFromTm(struct tm &tmAtTime); 853ceed64fSopenharmony_ci 863ceed64fSopenharmony_ci /** 873ceed64fSopenharmony_ci * @brief split string. 883ceed64fSopenharmony_ci * @param in string. 893ceed64fSopenharmony_ci * @param delim delimiter. 903ceed64fSopenharmony_ci * @return string list. 913ceed64fSopenharmony_ci */ 923ceed64fSopenharmony_ci static std::vector<std::string> StringSplit(const std::string &in, const std::string &delim); 933ceed64fSopenharmony_ci 943ceed64fSopenharmony_ci /** 953ceed64fSopenharmony_ci * @brief get current active account id. 963ceed64fSopenharmony_ci * @return int current active account id. 973ceed64fSopenharmony_ci */ 983ceed64fSopenharmony_ci static int GetCurrentAccountId(); 993ceed64fSopenharmony_ci 1003ceed64fSopenharmony_ci /** 1013ceed64fSopenharmony_ci * @brief Check if the caller ability is SA. 1023ceed64fSopenharmony_ci * @return Returns true if is SA call; returns false otherwise. 1033ceed64fSopenharmony_ci */ 1043ceed64fSopenharmony_ci static bool IsSACall(); 1053ceed64fSopenharmony_ci 1063ceed64fSopenharmony_ci /** 1073ceed64fSopenharmony_ci * @brief Checks whether the caller has a certain permission. 1083ceed64fSopenharmony_ci * @param permissionName The name of the permission. 1093ceed64fSopenharmony_ci * @return Returns true if the caller has certain permissions; returns false otherwise. 1103ceed64fSopenharmony_ci */ 1113ceed64fSopenharmony_ci static bool VerifyCallingPermission(const std::string &permissionName); 1123ceed64fSopenharmony_ci 1133ceed64fSopenharmony_ci /** 1143ceed64fSopenharmony_ci * @brief Convert string to int64_t 1153ceed64fSopenharmony_ci * 1163ceed64fSopenharmony_ci * @param[in] strInfo The string information 1173ceed64fSopenharmony_ci * @param[out] int64Value Convert string to int64_t 1183ceed64fSopenharmony_ci * 1193ceed64fSopenharmony_ci * @return Return the convert result 1203ceed64fSopenharmony_ci */ 1213ceed64fSopenharmony_ci static bool ConvertStringToInt64(const std::string &strInfo, int64_t &int64Value); 1223ceed64fSopenharmony_ci}; 1233ceed64fSopenharmony_ci} // namespace AppExecFwk 1243ceed64fSopenharmony_ci} // namespace OHOS 1253ceed64fSopenharmony_ci#endif // OHOS_FORM_FWK_FORM_UTIL_H 126