1 /* 2 * Copyright (c) 2023-2025 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_BUNDLEMANAGER_BUNDLE_FRAMEWORK_SERVICE_BUNDLEMGR_INCLUDE_VERIFY_VERIFY_MANAGER_PROXY_H 17 #define FOUNDATION_BUNDLEMANAGER_BUNDLE_FRAMEWORK_SERVICE_BUNDLEMGR_INCLUDE_VERIFY_VERIFY_MANAGER_PROXY_H 18 19 #include <mutex> 20 #include <shared_mutex> 21 #include "bundle_memory_guard.h" 22 #include "verify_manager_stub.h" 23 24 namespace OHOS { 25 namespace AppExecFwk { 26 class VerifyManagerHostImpl : public VerifyManagerStub { 27 public: 28 VerifyManagerHostImpl(); 29 virtual ~VerifyManagerHostImpl(); 30 31 int32_t CallbackEnter([[maybe_unused]] uint32_t code) override; 32 33 int32_t CallbackExit([[maybe_unused]] uint32_t code, [[maybe_unused]] int32_t result) override; 34 35 ErrCode Verify(const std::vector<std::string> &abcPaths, int32_t &funcResult) override; 36 37 ErrCode DeleteAbc(const std::string &path, int32_t &funcResult) override; 38 39 private: 40 ErrCode InnerVerify(const std::string &bundleName, 41 const std::vector<std::string> &abcPaths); 42 bool CopyFilesToTempDir(const std::string &bundleName, int32_t userId, 43 const std::vector<std::string> &abcPaths); 44 bool VerifyAbc(const std::vector<std::string> &abcPaths); 45 bool MoveAbc(const std::string &bundleName, 46 const std::vector<std::string> &abcPaths); 47 void Rollback(const std::vector<std::string> &paths); 48 bool GetFileName(const std::string &sourcePath, std::string &fileName); 49 bool GetFileDir(const std::string &sourcePath, std::string &fileDir); 50 void RemoveTempFiles(const std::string &bundleName); 51 void RemoveTempFiles(const std::vector<std::string> &paths); 52 bool VerifyAbc( 53 const std::string &rootDir, const std::vector<std::string> &names); 54 bool CheckFileParam(const std::vector<std::string> &abcPaths); 55 void Rollback(const std::string &rootDir, const std::vector<std::string> &names); 56 ErrCode MkdirIfNotExist(const std::string &dir); 57 std::mutex &GetBundleMutex(const std::string &bundleName); 58 std::string GetRealPath(const std::string &bundleName, 59 int32_t userId, const std::string &relativePath); 60 bool GetCallingBundleName(std::string &bundleName); 61 ErrCode VerifyDeleteAbcPermission(const std::string &path); 62 63 std::atomic<uint32_t> id_ = 0; 64 mutable std::shared_mutex bundleMutex_; 65 // using for locking by bundleName 66 std::unordered_map<std::string, std::mutex> bundleMutexMap_; 67 }; 68 } // AppExecFwk 69 } // OHOS 70 #endif // FOUNDATION_BUNDLEMANAGER_BUNDLE_FRAMEWORK_SERVICE_BUNDLEMGR_INCLUDE_VERIFY_VERIFY_MANAGER_PROXY_H 71