/* * Copyright (C) 2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef SECURITY_GUARD_DATABASE_MANAGER_H #define SECURITY_GUARD_DATABASE_MANAGER_H #include #include #include #include "config_define.h" #include "i_db_listener.h" namespace OHOS::Security::SecurityGuard { class DatabaseManager { public: static DatabaseManager &GetInstance(); void Init(); int32_t SetAuditState(bool enable); int InsertEvent(uint32_t source, SecEvent& event); int QueryAllEvent(std::string table, std::vector &events); int QueryAllEventFromMem(std::vector &events); int QueryRecentEventByEventId(int64_t eventId, SecEvent &event); int QueryRecentEventByEventId(std::string table, const std::vector &eventId, std::vector &event); int QueryEventByEventIdAndDate(std::string table, std::vector &eventIds, std::vector &events, std::string beginTime, std::string endTime); int QueryEventByEventId(int64_t eventId, std::vector &events); int QueryEventByEventId(std::string table, std::vector &eventIds, std::vector &events); int QueryEventByEventType(std::string table, int32_t eventType, std::vector &events); int QueryEventByLevel(std::string table, int32_t level, std::vector &events); int QueryEventByOwner(std::string table, std::string owner, std::vector &events); int64_t CountAllEvent(std::string table); int64_t CountEventByEventId(int64_t eventId); int DeleteOldEventByEventId(int64_t eventId, int64_t count); int DeleteAllEventByEventId(int64_t eventId); int32_t SubscribeDb(std::vector eventIds, std::shared_ptr listener); int32_t UnSubscribeDb(std::vector eventIds, std::shared_ptr listener); private: std::mutex mutex_; std::mutex dbMutex_; std::unordered_map>> listenerMap_; std::string deviceId_; void FillUserIdAndDeviceId(SecEvent& event); void DbChanged(int32_t optType, const SecEvent &event); int32_t OpenAudit(); int32_t CloseAudit(); }; } // namespace OHOS::Security::SecurityGuard { #endif // SECURITY_GUARD_DATABASE_MANAGER_H