• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 SYS_INSTALLER_MODULE_UTILS_H
17 #define SYS_INSTALLER_MODULE_UTILS_H
18 
19 #include <sstream>
20 #include <string>
21 #include <sys/stat.h>
22 #include <unistd.h>
23 #include <vector>
24 #include "module_file.h"
25 
26 namespace OHOS {
27 namespace SysInstaller {
28 bool CreateDirIfNeeded(const std::string &fpInfo, mode_t mode);
29 bool CheckPathExists(const std::string &path);
30 bool CheckFileSuffix(const std::string &file, const std::string &suffix);
31 std::string GetFileName(const std::string &file);
32 std::string GetHmpName(const std::string &filePath);
33 bool WaitForFile(const std::string &fpInfo, const std::chrono::nanoseconds &timeout);
34 bool StartsWith(const std::string &str, const std::string &prefix);
35 bool ReadFullyAtOffset(int fd, uint8_t *data, size_t count, off_t offset);
36 bool WriteFullyAtOffset(int fd, const uint8_t *data, size_t count, off_t offset);
37 uint16_t ReadLE16(const uint8_t *buff);
38 uint32_t ReadLE32(const uint8_t *buff);
39 std::string GetRealPath(const std::string &path);
40 void Revert(const std::string &hmpName, bool reboot);
41 bool IsHotSa(int32_t saId);
42 bool IsRunning(int32_t saId);
43 bool CheckBootComplete(void);
44 bool RemoveSpecifiedDir(const std::string &fpInfo, bool keepDir);
45 std::string GetDeviceSaSdkVersion(void);
46 int GetDeviceApiVersion(void);
47 std::string GetContentFromZip(const std::string &zipPath, const std::string &fpInfo);
48 bool CheckAndUpdateRevertResult(const std::string &hmpPath, const std::string &resultInfo, const std::string &keyWord);
49 std::string GetCurrentHmpName(void);
50 int32_t NotifyBmsRevert(const std::string &hmpName, bool record);
51 
52 #ifdef __cplusplus
53 extern "C" {
54 #endif
55 bool RevertImageCert(const std::string &hmpName, bool revertMore);
56 bool VerityInfoWrite(const ModuleFile &file);
57 bool PrepareFileToDestDir(const std::string &pkgPath, const std::string &outPath);
58 void SetModuleVersion(const ModuleFile &file);
59 #ifdef __cplusplus
60 }
61 #endif
62 
63 class Timer {
64 public:
Timer()65     Timer() : start_(std::chrono::steady_clock::now()) {}
66 
duration()67     std::chrono::milliseconds duration() const
68     {
69         return std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now() - start_);
70     }
71 private:
72     std::chrono::steady_clock::time_point start_;
73 };
74 std::ostream &operator<<(std::ostream &os, const Timer &timer);
75 } // namespace SysInstaller
76 } // namespace OHOS
77 #endif // SYS_INSTALLER_MODULE_UTILS_H
78