1 /* 2 * Copyright (c) 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 BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_REMINDER_STORE_H 17 #define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_REMINDER_STORE_H 18 19 #include <vector> 20 21 #include "notification_bundle_option.h" 22 #include "reminder_request.h" 23 #include "rdb_errno.h" 24 #include "rdb_helper.h" 25 #include "rdb_open_callback.h" 26 #include "rdb_store_config.h" 27 28 namespace OHOS { 29 namespace Notification { 30 class ReminderStore { 31 public: ReminderStore()32 ReminderStore() {}; ~ReminderStore()33 virtual ~ReminderStore() {}; 34 int32_t Init(); 35 int32_t Delete(int32_t reminderId); 36 int32_t Delete(const std::string &pkg, int32_t userId); 37 int32_t DeleteUser(int32_t userId); 38 std::vector<sptr<ReminderRequest>> GetAllValidReminders(); 39 bool GetBundleOption(const int32_t &reminderId, sptr<NotificationBundleOption> &bundleOption) const; 40 int32_t GetMaxId(); 41 int64_t UpdateOrInsert(const sptr<ReminderRequest> &reminder, const sptr<NotificationBundleOption> &bundleOption); 42 static uint8_t GetColumnIndex(const std::string& name); 43 44 static const int32_t STATE_OK; 45 46 private: 47 /** 48 * @brief Inits the data in database when system boot on or proxy process reboot on. 49 * 50 * 1. Deletes all the reminders which IS_EXPIRED is true. 51 * 2. Sets all the value of STATE to ReminderRequest::REMINDER_STATUS_INACTIVE 52 * 3. Sets all the value of IS_ACTIVE to false. 53 * 4. Sets all the value of HAS_SCHEDULED_TIMEOUT to false. 54 * 55 * @return int32_t result code. 56 */ 57 int32_t InitData(); 58 sptr<ReminderRequest> BuildReminder(const std::shared_ptr<NativeRdb::ResultSet> &resultSet); 59 int32_t Delete(const std::string &deleteCondition); 60 void GetInt32Val(std::shared_ptr<NativeRdb::ResultSet> &resultSet, 61 const std::string &name, int32_t &value) const; 62 void GetStringVal(std::shared_ptr<NativeRdb::ResultSet> &resultSet, 63 const std::string &name, std::string &value) const; 64 std::vector<sptr<ReminderRequest>> GetReminders(const std::string &queryCondition); 65 void GenerateData(const sptr<ReminderRequest> &reminder, 66 const sptr<NotificationBundleOption> &bundleOption, NativeRdb::ValuesBucket &values) const; 67 bool IsReminderExist(const sptr<ReminderRequest> &reminder); 68 int64_t Insert(const sptr<ReminderRequest> &reminder, const sptr<NotificationBundleOption> &bundleOption); 69 std::shared_ptr<NativeRdb::ResultSet> Query(const std::string &queryCondition) const; 70 int64_t Update(const sptr<ReminderRequest> &reminder, const sptr<NotificationBundleOption> &bundleOption); 71 72 class ReminderStoreDataCallBack : public NativeRdb::RdbOpenCallback { 73 public: 74 int32_t OnCreate(NativeRdb::RdbStore &rdbStore) override; 75 int32_t OnUpgrade(NativeRdb::RdbStore &rdbStore, int32_t oldVersion, int32_t newVersion) override; 76 }; 77 78 private: 79 std::shared_ptr<NativeRdb::RdbStore> rdbStore_ = nullptr; 80 }; 81 } // namespace Notification 82 } // namespace OHOS 83 #endif // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_REMINDER_STORE_H