1 /* 2 * Copyright (c) 2021 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 26 namespace OHOS { 27 namespace AppExecFwk { 28 struct AppSpawnStartMsg { 29 int32_t uid; 30 int32_t gid; 31 std::vector<int32_t> gids; 32 std::string procName; 33 std::string soPath; 34 uint32_t accessTokenId; 35 std::string apl; 36 std::string bundleName; 37 std::string renderParam; // only nweb spawn need this param. 38 int32_t pid; 39 int32_t code = 0; // 0: DEFAULT; 1: GET_RENDER_TERMINATION_STATUS 40 uint32_t flags; 41 int32_t bundleIndex; // when dlp launch another app used, default is 0 42 uint8_t setAllowInternet; 43 uint8_t allowInternet; // hap socket allowed 44 uint8_t reserved1; 45 uint8_t reserved2; 46 }; 47 48 using AppSpawnMsg = AppSpawn::ClientSocket::AppProperty; 49 50 constexpr auto LEN_PID = sizeof(pid_t); 51 struct StartFlags { 52 static const int COLD_START = 0; 53 static const int BACKUP_EXTENSION = 1; 54 static const int DLP_MANAGER = 2; 55 static const int DEBUGGABLE = 3; 56 static const int ASANENABLED = 4; 57 }; 58 59 union AppSpawnPidMsg { 60 pid_t pid = 0; 61 char pidBuf[LEN_PID]; 62 }; 63 64 class AppSpawnMsgWrapper { 65 public: 66 /** 67 * Constructor. 68 */ 69 AppSpawnMsgWrapper() = default; 70 71 /** 72 * Destructor 73 */ 74 ~AppSpawnMsgWrapper(); 75 76 /** 77 * Disable copy. 78 */ 79 DISALLOW_COPY_AND_MOVE(AppSpawnMsgWrapper); 80 81 /** 82 * Verify message and assign to member variable. 83 * 84 * @param startMsg, request message. 85 */ 86 bool AssembleMsg(const AppSpawnStartMsg &startMsg); 87 88 /** 89 * Get function, return isValid_. 90 */ IsValid()91 bool IsValid() const 92 { 93 return isValid_; 94 } 95 96 /** 97 * Get function, return member variable message. 98 */ GetMsgBuf()99 const void *GetMsgBuf() const 100 { 101 return reinterpret_cast<void *>(msg_); 102 } 103 104 /** 105 * Get function, return message length. 106 */ GetMsgLength()107 int32_t GetMsgLength() const 108 { 109 return isValid_ ? sizeof(AppSpawnMsg) : 0; 110 } 111 112 private: 113 /** 114 * Verify message. 115 * 116 * @param startMsg, request message. 117 */ 118 bool VerifyMsg(const AppSpawnStartMsg &startMsg) const; 119 120 /** 121 * Print message. 122 * 123 * @param startMsg, request message. 124 */ 125 void DumpMsg() const; 126 127 /** 128 * Release message. 129 */ 130 void FreeMsg(); 131 132 private: 133 bool isValid_ = false; 134 // because AppSpawnMsg's size is uncertain, so should use raw pointer. 135 AppSpawnMsg *msg_ = nullptr; 136 }; 137 } // namespace AppExecFwk 138 } // namespace OHOS 139 #endif // OHOS_ABILITY_RUNTIME_APP_SPAWN_MSG_WRAPPER_H 140