1 /* 2 * Copyright (c) 2020 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_BUNLDE_DAEMON_CLIENT_H 17 #define OHOS_BUNLDE_DAEMON_CLIENT_H 18 19 #include <semaphore.h> 20 21 #include "ohos_errno.h" 22 #include "iproxy_client.h" 23 #include "liteipc_adapter.h" 24 #include "mutex_lock.h" 25 #include "nocopyable.h" 26 27 namespace OHOS { 28 class BundleDaemonClient : public NoCopyable { 29 public: GetInstance()30 static BundleDaemonClient &GetInstance() 31 { 32 static BundleDaemonClient instance; 33 return instance; 34 } 35 bool Initialize(); 36 int32_t ExtractHap(const char *hapFile, const char *codePath); 37 int32_t RenameFile(const char *oldFile, const char *newFile); 38 int32_t CreatePermissionDir(); 39 int32_t CreateDataDirectory(const char *dataPath, int32_t uid, int32_t gid, bool isChown); 40 int32_t StoreContentToFile(const char *file, const void *buffer, uint32_t size); 41 int32_t MoveFile(const char *oldFile, const char *newFile); 42 int32_t RemoveFile(const char *file); 43 int32_t RemoveInstallDirectory(const char *codePath, const char *dataPath, bool keepData); 44 int32_t CallClientInvoke(int32_t funcId, const char *firstPath, const char *secondPath); 45 static int32_t BundleDaemonCallback(const IpcContext* context, void *ipcMsg, IpcIo *io, void *arg); 46 static int32_t DeathCallback(const IpcContext* context, void* ipcMsg, IpcIo* data, void* arg); 47 static int Notify(IOwner owner, int code, IpcIo *reply); 48 49 private: 50 BundleDaemonClient() = default; 51 ~BundleDaemonClient(); 52 53 IClientProxy *bdsClient_ { nullptr }; 54 SvcIdentity svcIdentity_ {}; 55 SvcIdentity bdsSvcIdentity_ {}; 56 uint32_t cbid_ = INVALID_INDEX; 57 sem_t sem_; 58 Mutex mutex_; 59 int32_t result_ = EC_FAILURE; 60 bool initialized_ = false; 61 62 static void *RegisterDeathCallback(void *); 63 int32_t RegisterCallback(); 64 int32_t WaitResultSync(int32_t result); 65 }; 66 } // namespace OHOS 67 #endif // OHOS_BUNLDE_DAEMON_CLIENT_H 68