• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) Huawei Technologies Co., Ltd. 2021-2023. All rights reserved.
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 #ifndef COMMON_H
16 #define COMMON_H
17 
18 #include <malloc.h>
19 #include <string>
20 #include <vector>
21 #include <sys/types.h>
22 #include <unistd.h>
23 
24 
25 namespace COMMON {
26 bool IsProcessRunning(int& lockFileFd); // add file lock, only one process can run
27 bool IsProcessExist(const std::string& processName, int& pid); // Check if the process exists and get PID
28 int StartProcess(const std::string& processBin, std::vector<char*>& argv);
29 int KillProcess(int pid);
30 void PrintMallinfoLog(const std::string& mallInfoPrefix, const struct mallinfo2& mi);
31 inline int CustomFdClose(int& fd);
32 inline int CustomFdFclose(FILE** fp);
33 bool IsUserMode();
34 FILE* CustomPopen(const std::vector<std::string>& command, const char* type, int fds[],
35                   volatile pid_t& childPid, bool needUnblock = false);
36 int CustomPclose(FILE* fp, int fds[], volatile pid_t& childPid, bool needUnblock = false);
37 int CustomPUnblock(int fds[]);
38 int GetServicePort();
39 void SplitString(const std::string& str, const std::string &sep, std::vector<std::string>& ret);
40 bool CheckApplicationPermission(int pid, const std::string& processName);
41 bool CheckApplicationEncryped(int pid, const std::string& processName);
42 bool VerifyPath(const std::string& filePath, const std::vector<std::string>& validPaths);
43 bool ReadFile(const std::string& filePath, const std::vector<std::string>& validPaths, std::string& fileContent);
44 std::string GetErrorMsg();
45 std::string GetTimeStr();
46 clockid_t GetClockId(const std::string& clockIdStr);
47 std::string GetClockStr(const int32_t clockId);
48 void AdaptSandboxPath(std::string& filePath, int pid);
49 int32_t GetPackageUid(const std::string &name);
50 bool GetCurrentUserId(int32_t &userId);
51 bool GetDeveloperMode();
52 bool IsBetaVersion();
53 } // COMMON
54 #endif // COMMON_H