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; 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; 56 DataGroupInfoList dataGroupInfoList; // list of harmony shared package 57 uint32_t mountPermissionFlags; 58 }; 59 60 constexpr auto LEN_PID = sizeof(pid_t); 61 struct StartFlags { 62 static const int COLD_START = 0; 63 static const int BACKUP_EXTENSION = 1; 64 static const int DLP_MANAGER = 2; 65 static const int DEBUGGABLE = 3; 66 static const int ASANENABLED = 4; 67 static const int NATIVEDEBUG = 6; 68 }; 69 70 union AppSpawnPidMsg { 71 pid_t pid = 0; 72 char pidBuf[LEN_PID]; 73 }; 74 75 class AppSpawnMsgWrapper { 76 public: 77 /** 78 * Constructor. 79 */ 80 AppSpawnMsgWrapper() = default; 81 82 /** 83 * Destructor 84 */ 85 ~AppSpawnMsgWrapper(); 86 87 /** 88 * Disable copy. 89 */ 90 DISALLOW_COPY_AND_MOVE(AppSpawnMsgWrapper); 91 92 /** 93 * Verify message and assign to member variable. 94 * 95 * @param startMsg, request message. 96 */ 97 bool AssembleMsg(const AppSpawnStartMsg &startMsg); 98 99 /** 100 * Get function, return isValid_. 101 */ IsValid()102 bool IsValid() const 103 { 104 return isValid_; 105 } 106 107 /** 108 * Get function, return member variable message. 109 */ GetMsgBuf()110 const void *GetMsgBuf() const 111 { 112 return reinterpret_cast<void *>(msg_); 113 } 114 115 /** 116 * Get function, return message length. 117 */ GetMsgLength()118 int32_t GetMsgLength() const 119 { 120 return isValid_ ? sizeof(AppSpawnMsg) : 0; 121 } 122 123 /** 124 * Get function, return hsp list string 125 */ GetHspListStr()126 const std::string& GetHspListStr() const 127 { 128 return hspListStr; 129 } 130 131 /** 132 * Get function, return data group info list string 133 */ GetDataGroupInfoListStr()134 const std::string& GetDataGroupInfoListStr() const 135 { 136 return dataGroupInfoListStr; 137 } 138 139 private: 140 /** 141 * Verify message. 142 * 143 * @param startMsg, request message. 144 */ 145 bool VerifyMsg(const AppSpawnStartMsg &startMsg) const; 146 147 /** 148 * Print message. 149 * 150 * @param startMsg, request message. 151 */ 152 void DumpMsg() const; 153 154 /** 155 * Release message. 156 */ 157 void FreeMsg(); 158 159 private: 160 bool isValid_ = false; 161 // because AppSpawnMsg's size is uncertain, so should use raw pointer. 162 AppSpawnMsg *msg_ = nullptr; 163 std::string hspListStr; 164 std::string dataGroupInfoListStr; 165 }; 166 } // namespace AppExecFwk 167 } // namespace OHOS 168 #endif // OHOS_ABILITY_RUNTIME_APP_SPAWN_MSG_WRAPPER_H 169