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_ABILITY_RUNTIME_APP_SPAWN_MSG_WRAPPER_H 17 #define OHOS_ABILITY_RUNTIME_APP_SPAWN_MSG_WRAPPER_H 18 19 #include <string> 20 #include <vector> 21 #include <unistd.h> 22 23 #include "nocopyable.h" 24 #include "client_socket.h" 25 #include "data_group_info.h" 26 #include "shared/base_shared_bundle_info.h" 27 28 namespace OHOS { 29 namespace AppExecFwk { 30 using AppSpawnMsg = AppSpawn::ClientSocket::AppProperty; 31 using HspList = std::vector<BaseSharedBundleInfo>; 32 using DataGroupInfoList = std::vector<DataGroupInfo>; 33 34 struct AppSpawnStartMsg { 35 int32_t uid; 36 int32_t gid; 37 std::vector<int32_t> gids; 38 std::string procName; 39 std::string soPath; 40 uint32_t accessTokenId; 41 std::string apl; 42 std::string bundleName; 43 std::string renderParam; // only nweb spawn need this param. 44 int32_t pid; 45 int32_t code = 0; // 0: DEFAULT; 1: GET_RENDER_TERMINATION_STATUS; 2: SPAWN_NATIVE_PROCESS 46 uint32_t flags; 47 int32_t bundleIndex; // when dlp launch another app used, default is 0 48 uint8_t setAllowInternet; 49 uint8_t allowInternet; // hap socket allowed 50 uint8_t reserved1; 51 uint8_t reserved2; 52 uint64_t accessTokenIdEx; 53 uint32_t hapFlags = 0; // whether is pre installed hap 54 HspList hspList; // list of harmony shared package 55 std::string overlayInfo; // overlay hap resource path list 56 DataGroupInfoList dataGroupInfoList; // list of harmony shared package 57 uint32_t mountPermissionFlags; 58 std::string ownerId; 59 }; 60 61 constexpr auto LEN_PID = sizeof(pid_t); 62 struct StartFlags { 63 static const int COLD_START = 0; 64 static const int BACKUP_EXTENSION = 1; 65 static const int DLP_MANAGER = 2; 66 static const int DEBUGGABLE = 3; 67 static const int ASANENABLED = 4; 68 static const int NATIVEDEBUG = 6; 69 static const int NO_SANDBOX = 7; 70 static const int GWP_ENABLED_FORCE = 10; 71 static const int GWP_ENABLED_NORMAL = 11; 72 }; 73 74 union AppSpawnPidMsg { 75 pid_t pid = 0; 76 char pidBuf[LEN_PID]; 77 }; 78 79 class AppSpawnMsgWrapper { 80 public: 81 /** 82 * Constructor. 83 */ 84 AppSpawnMsgWrapper() = default; 85 86 /** 87 * Destructor 88 */ 89 ~AppSpawnMsgWrapper(); 90 91 /** 92 * Disable copy. 93 */ 94 DISALLOW_COPY_AND_MOVE(AppSpawnMsgWrapper); 95 96 /** 97 * Verify message and assign to member variable. 98 * 99 * @param startMsg, request message. 100 */ 101 bool AssembleMsg(const AppSpawnStartMsg &startMsg); 102 103 /** 104 * Get function, return isValid_. 105 */ IsValid()106 bool IsValid() const 107 { 108 return isValid_; 109 } 110 111 /** 112 * Get function, return member variable message. 113 */ GetMsgBuf()114 const void *GetMsgBuf() const 115 { 116 return reinterpret_cast<void *>(msg_); 117 } 118 119 /** 120 * Get function, return message length. 121 */ GetMsgLength()122 int32_t GetMsgLength() const 123 { 124 return isValid_ ? sizeof(AppSpawnMsg) : 0; 125 } 126 127 /** 128 * Get function, return hsp list string 129 */ GetExtraInfoStr()130 const std::string& GetExtraInfoStr() const 131 { 132 return extraInfoStr; 133 } 134 135 private: 136 /** 137 * Verify message. 138 * 139 * @param startMsg, request message. 140 */ 141 bool VerifyMsg(const AppSpawnStartMsg &startMsg) const; 142 143 /** 144 * Print message. 145 * 146 * @param startMsg, request message. 147 */ 148 void DumpMsg() const; 149 150 /** 151 * Release message. 152 */ 153 void FreeMsg(); 154 155 private: 156 bool isValid_ = false; 157 // because AppSpawnMsg's size is uncertain, so should use raw pointer. 158 AppSpawnMsg *msg_ = nullptr; 159 std::string extraInfoStr; 160 }; 161 } // namespace AppExecFwk 162 } // namespace OHOS 163 #endif // OHOS_ABILITY_RUNTIME_APP_SPAWN_MSG_WRAPPER_H 164