1 /* 2 * Copyright (c) 2021-2022 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 FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_IPC_INSTALLD_HOST_H 17 #define FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_IPC_INSTALLD_HOST_H 18 19 #include <mutex> 20 #include <string> 21 22 #include "event_handler.h" 23 #include "event_runner.h" 24 #include "iremote_stub.h" 25 #include "ipc/installd_interface.h" 26 27 namespace OHOS { 28 namespace AppExecFwk { 29 class InstalldHost : public IRemoteStub<IInstalld> { 30 public: 31 InstalldHost(); 32 virtual ~InstalldHost() override; 33 34 virtual int OnRemoteRequest( 35 uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; 36 37 private: 38 /** 39 * @brief Handles the CreateBundleDir function called from a IInstalld proxy object. 40 * @param data Indicates the data to be read. 41 * @param reply Indicates the reply to be sent; 42 * @return Returns true if called successfully; returns false otherwise. 43 */ 44 bool HandleCreateBundleDir(MessageParcel &data, MessageParcel &reply); 45 /** 46 * @brief Handles the ExtractModuleFiles function called from a IInstalld proxy object. 47 * @param data Indicates the data to be read. 48 * @param reply Indicates the reply to be sent; 49 * @return Returns true if called successfully; returns false otherwise. 50 */ 51 bool HandleExtractModuleFiles(MessageParcel &data, MessageParcel &reply); 52 /** 53 * @brief Handles the HandleExtractFiles function called from a IInstalld proxy object. 54 * @param data Indicates the data to be read. 55 * @param reply Indicates the reply to be sent; 56 * @return Returns true if called successfully; returns false otherwise. 57 */ 58 bool HandleExtractFiles(MessageParcel &data, MessageParcel &reply); 59 60 bool HandleExecuteAOT(MessageParcel &data, MessageParcel &reply); 61 /** 62 * @brief Handles the RenameModuleDir function called from a IInstalld proxy object. 63 * @param data Indicates the data to be read. 64 * @param reply Indicates the reply to be sent; 65 * @return Returns true if called successfully; returns false otherwise. 66 */ 67 bool HandleRenameModuleDir(MessageParcel &data, MessageParcel &reply); 68 /** 69 * @brief Handles the CreateBundleDataDir function called from a IInstalld proxy object. 70 * @param data Indicates the data to be read. 71 * @param reply Indicates the reply to be sent; 72 * @return Returns true if called successfully; returns false otherwise. 73 */ 74 bool HandleCreateBundleDataDir(MessageParcel &data, MessageParcel &reply); 75 /** 76 * @brief Handles the RemoveBundleDataDir function called from a IInstalld proxy object. 77 * @param data Indicates the data to be read. 78 * @param reply Indicates the reply to be sent; 79 * @return Returns true if called successfully; returns false otherwise. 80 */ 81 bool HandleRemoveBundleDataDir(MessageParcel &data, MessageParcel &reply); 82 /** 83 * @brief Handles the RemoveModuleDataDir function called from a IInstalld proxy object. 84 * @param data Indicates the data to be read. 85 * @param reply Indicates the reply to be sent; 86 * @return Returns true if called successfully; returns false otherwise. 87 */ 88 bool HandleRemoveModuleDataDir(MessageParcel &data, MessageParcel &reply); 89 /** 90 * @brief Handles the RemoveDir function called from a IInstalld proxy object. 91 * @param data Indicates the data to be read. 92 * @param reply Indicates the reply to be sent; 93 * @return Returns true if called successfully; returns false otherwise. 94 */ 95 bool HandleRemoveDir(MessageParcel &data, MessageParcel &reply); 96 /** 97 * @brief Handles the CleanBundleDataDir function called from a IInstalld proxy object. 98 * @param data Indicates the data to be read. 99 * @param reply Indicates the reply to be sent; 100 * @return Returns true if called successfully; returns false otherwise. 101 */ 102 bool HandleCleanBundleDataDir(MessageParcel &data, MessageParcel &reply); 103 /** 104 * @brief Handles the CleanBundleDataDir function called from a IInstalld proxy object. 105 * @param data Indicates the data to be read. 106 * @param reply Indicates the reply to be sent; 107 * @return Returns true if called successfully; returns false otherwise. 108 */ 109 bool HandleGetBundleStats(MessageParcel &data, MessageParcel &reply); 110 111 /** 112 * @brief Init private hash map funcMap_. 113 */ 114 void Init(); 115 /** 116 * @brief Handles the set dir apl function called from a IInstalld proxy object. 117 * @param data Indicates the data to be read. 118 * @param reply Indicates the reply to be sent; 119 * @return Returns true if called successfully; returns false otherwise. 120 */ 121 bool HandleSetDirApl(MessageParcel &data, MessageParcel &reply); 122 123 /** 124 * @brief Handles the all GetBundleCachePath function. 125 * @param data Indicates the data to be read. 126 * @param reply Indicates the reply to be sent; 127 * @return Returns true if called successfully; returns false otherwise. 128 */ 129 bool HandleGetBundleCachePath(MessageParcel &data, MessageParcel &reply); 130 131 bool HandleScanDir(MessageParcel &data, MessageParcel &reply); 132 133 bool HandleMoveFile(MessageParcel &data, MessageParcel &reply); 134 135 bool HandleCopyFile(MessageParcel &data, MessageParcel &reply); 136 137 bool HandleMkdir(MessageParcel &data, MessageParcel &reply); 138 139 bool HandleGetFileStat(MessageParcel &data, MessageParcel &reply); 140 141 bool HandleExtractDiffFiles(MessageParcel &data, MessageParcel &reply); 142 143 bool HandleApplyDiffPatch(MessageParcel &data, MessageParcel &reply); 144 145 bool HandleIsExistDir(MessageParcel &data, MessageParcel &reply); 146 147 bool HandleIsExistFile(MessageParcel &data, MessageParcel &reply); 148 149 bool HandleIsDirEmpty(MessageParcel &data, MessageParcel &reply); 150 151 bool HandObtainQuickFixFileDir(MessageParcel &data, MessageParcel &reply); 152 153 bool HandCopyFiles(MessageParcel &data, MessageParcel &reply); 154 155 bool HandGetNativeLibraryFileNames(MessageParcel &data, MessageParcel &reply); 156 157 bool HandVerifyCodeSignature(MessageParcel &data, MessageParcel &reply); 158 159 bool HandMoveFiles(MessageParcel &data, MessageParcel &reply); 160 161 void AddCloseInstalldTask(); 162 163 void RemoveCloseInstalldTask(); 164 165 void InitEventHandler(); 166 167 using InstalldFunc = bool (InstalldHost::*)(MessageParcel &, MessageParcel &); 168 std::unordered_map<uint32_t, InstalldFunc> funcMap_; 169 std::mutex unloadTaskMutex_; 170 std::shared_ptr<EventHandler> handler_ = nullptr; 171 std::shared_ptr<EventRunner> runner_ = nullptr; 172 }; 173 } // namespace AppExecFwk 174 } // namespace OHOS 175 #endif // FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_IPC_INSTALLD_HOST_H