1 /* 2 * Copyright (c) 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 ACCESS_TOKEN_RDB_DLOPEN_MANAGER_H 17 #define ACCESS_TOKEN_RDB_DLOPEN_MANAGER_H 18 19 #include <mutex> 20 #include <vector> 21 22 #ifdef EVENTHANDLER_ENABLE 23 #include "access_event_handler.h" 24 #endif 25 #include "access_token_db_loader.h" 26 #include "atm_data_type.h" 27 #include "generic_values.h" 28 #include "refbase.h" 29 #include "singleton.h" 30 31 namespace OHOS { 32 namespace Security { 33 namespace AccessToken { 34 static constexpr const char* RDB_ADAPTER_LIBPATH = "libaccesstoken_db_loader.z.so"; 35 36 class RdbDlopenManager final : public DelayedSingleton<RdbDlopenManager> { 37 public: 38 RdbDlopenManager(); 39 ~RdbDlopenManager() = default; 40 41 int32_t Modify(const AtmDataType type, const GenericValues& modifyValue, 42 const GenericValues& conditionValue); 43 int32_t Find(AtmDataType type, const GenericValues& conditionValue, std::vector<GenericValues>& results); 44 int32_t DeleteAndInsertValues(const std::vector<DelInfo>& delInfoVec, 45 const std::vector<AddInfo>& addInfoVec); 46 47 private: 48 DISALLOW_COPY_AND_MOVE(RdbDlopenManager); 49 50 #ifdef EVENTHANDLER_ENABLE 51 void InitEventHandler(); 52 std::shared_ptr<AccessEventHandler> GetEventHandler(); 53 54 std::mutex eventHandlerLock_; 55 std::shared_ptr<AppExecFwk::EventRunner> eventRunner_ = nullptr; 56 std::shared_ptr<AccessEventHandler> eventHandler_ = nullptr; 57 #endif 58 59 AccessTokenDbLoaderInterface* GetDbInstance(); 60 void Init(); 61 void Create(void* handle); 62 void Destroy(void* handle); 63 bool CleanUp(); 64 void DelayDlcloseHandle(int64_t delayTime); 65 66 std::mutex handleMutex_; 67 void* handle_ = nullptr; 68 AccessTokenDbLoaderInterface* instance_ = nullptr; 69 std::atomic_int32_t taskNum_ = 0; 70 }; 71 } // namespace AccessToken 72 } // namespace Security 73 } // namespace OHOS 74 #endif // ACCESS_TOKEN_RDB_DLOPEN_MANAGER_H 75