10fbfc30aSopenharmony_ci/*
20fbfc30aSopenharmony_ci * Copyright (c) 2023 Huawei Device Co., Ltd.
30fbfc30aSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
40fbfc30aSopenharmony_ci * you may not use this file except in compliance with the License.
50fbfc30aSopenharmony_ci * You may obtain a copy of the License at
60fbfc30aSopenharmony_ci *
70fbfc30aSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
80fbfc30aSopenharmony_ci *
90fbfc30aSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
100fbfc30aSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
110fbfc30aSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
120fbfc30aSopenharmony_ci * See the License for the specific language governing permissions and
130fbfc30aSopenharmony_ci * limitations under the License.
140fbfc30aSopenharmony_ci */
150fbfc30aSopenharmony_ci
160fbfc30aSopenharmony_ci#include "native_calendar.h"
170fbfc30aSopenharmony_ci#include "data_share_helper_manager.h"
180fbfc30aSopenharmony_ci#include "calendar_log.h"
190fbfc30aSopenharmony_ci#include "calendar_env.h"
200fbfc30aSopenharmony_ci#include "data_ability_helper.h"
210fbfc30aSopenharmony_ci#include "native_util.h"
220fbfc30aSopenharmony_ci
230fbfc30aSopenharmony_cinamespace {
240fbfc30aSopenharmony_ci    const string eventUrl = "datashare:///calendardata/Events";
250fbfc30aSopenharmony_ci    const string attendeeUrl = "datashare:///calendardata/Attendees";
260fbfc30aSopenharmony_ci    const string calendarUrl = "datashare:///calendardata/Calendars";
270fbfc30aSopenharmony_ci    const string reminderUrl = "datashare:///calendardata/Reminders";
280fbfc30aSopenharmony_ci}
290fbfc30aSopenharmony_cinamespace OHOS::CalendarApi::Native {
300fbfc30aSopenharmony_ciCalendar::Calendar(int id)
310fbfc30aSopenharmony_ci    : m_id(id)
320fbfc30aSopenharmony_ci{
330fbfc30aSopenharmony_ci    uint64_t tokenId = CalendarEnv::GetInstance().GetTokenId();
340fbfc30aSopenharmony_ci    auto bumdleName = CalendarEnv::GetInstance().GetBundleName();
350fbfc30aSopenharmony_ci    auto bundleName_tokeId = "?bundleName=" + bumdleName + "&tokenId=" + std::to_string(tokenId);
360fbfc30aSopenharmony_ci    m_eventUri = std::make_unique<Uri>(eventUrl + bundleName_tokeId);
370fbfc30aSopenharmony_ci    m_calendarUri = std::make_unique<Uri>(calendarUrl + bundleName_tokeId);
380fbfc30aSopenharmony_ci}
390fbfc30aSopenharmony_ci
400fbfc30aSopenharmony_ciCalendar::Calendar(CalendarAccount account, int id)
410fbfc30aSopenharmony_ci    :m_account(std::move(account)), m_id(id)
420fbfc30aSopenharmony_ci{
430fbfc30aSopenharmony_ci    // todo getallcalendar的时候会重复,需要复用
440fbfc30aSopenharmony_ci    uint64_t tokenId = CalendarEnv::GetInstance().GetTokenId();
450fbfc30aSopenharmony_ci    auto bumdleName = CalendarEnv::GetInstance().GetBundleName();
460fbfc30aSopenharmony_ci    auto bundleName_tokeId = "?bundleName=" + bumdleName + "&tokenId=" + std::to_string(tokenId);
470fbfc30aSopenharmony_ci    m_eventUri = std::make_unique<Uri>(eventUrl + bundleName_tokeId);
480fbfc30aSopenharmony_ci    m_attendeeUri = std::make_unique<Uri>(attendeeUrl + bundleName_tokeId);
490fbfc30aSopenharmony_ci    m_calendarUri = std::make_unique<Uri>(calendarUrl + bundleName_tokeId);
500fbfc30aSopenharmony_ci    m_reminderUrl = std::make_unique<Uri>(reminderUrl + bundleName_tokeId);
510fbfc30aSopenharmony_ci}
520fbfc30aSopenharmony_civoid Calendar::InsertReminders(int eventId, vector<int> reminders)
530fbfc30aSopenharmony_ci{
540fbfc30aSopenharmony_ci    for (const auto &reminder : reminders) {
550fbfc30aSopenharmony_ci            DataShare::DataShareValuesBucket valuesBucket;
560fbfc30aSopenharmony_ci            valuesBucket.Put("event_id", eventId);
570fbfc30aSopenharmony_ci            valuesBucket.Put("minutes", reminder);
580fbfc30aSopenharmony_ci            auto index = DataShareHelperManager::GetInstance().Insert(*(m_reminderUrl.get()), valuesBucket);
590fbfc30aSopenharmony_ci            LOG_INFO("Insert reminder index %{private}d", index);
600fbfc30aSopenharmony_ci        }
610fbfc30aSopenharmony_ci}
620fbfc30aSopenharmony_ci
630fbfc30aSopenharmony_ciint Calendar::AddEventInfo(const Event& event, int channelId)
640fbfc30aSopenharmony_ci{
650fbfc30aSopenharmony_ci    auto valueEvent = BuildValueEvent(event, m_id, channelId);
660fbfc30aSopenharmony_ci    auto eventId = DataShareHelperManager::GetInstance().Insert(*(m_eventUri.get()), valueEvent);
670fbfc30aSopenharmony_ci    LOG_INFO("Insert Event eventId %{private}d", eventId);
680fbfc30aSopenharmony_ci    if (eventId <= 0) {
690fbfc30aSopenharmony_ci        return eventId;
700fbfc30aSopenharmony_ci    }
710fbfc30aSopenharmony_ci    // insert attendee
720fbfc30aSopenharmony_ci    auto valueAttendees = std::vector<DataShare::DataShareValuesBucket>();
730fbfc30aSopenharmony_ci    for (const auto &attendee : event.attendees) {
740fbfc30aSopenharmony_ci        auto valueAttendee = BuildAttendeeValue(attendee, eventId);
750fbfc30aSopenharmony_ci        valueAttendees.emplace_back(valueAttendee);
760fbfc30aSopenharmony_ci    }
770fbfc30aSopenharmony_ci    if (valueAttendees.size() > 0) {
780fbfc30aSopenharmony_ci        auto count = DataShareHelperManager::GetInstance().BatchInsert(*(m_attendeeUri.get()), valueAttendees);
790fbfc30aSopenharmony_ci        LOG_INFO("batchInsert attendees count %{private}d", count);
800fbfc30aSopenharmony_ci    }
810fbfc30aSopenharmony_ci
820fbfc30aSopenharmony_ci    // insert reminder
830fbfc30aSopenharmony_ci    if (event.reminderTime.has_value()) {
840fbfc30aSopenharmony_ci        InsertReminders(eventId, event.reminderTime.value());
850fbfc30aSopenharmony_ci    }
860fbfc30aSopenharmony_ci
870fbfc30aSopenharmony_ci    return eventId;
880fbfc30aSopenharmony_ci}
890fbfc30aSopenharmony_ci
900fbfc30aSopenharmony_ciint Calendar::AddEvent(const Event& event)
910fbfc30aSopenharmony_ci{
920fbfc30aSopenharmony_ci    return Calendar::AddEventInfo(event, 0);
930fbfc30aSopenharmony_ci}
940fbfc30aSopenharmony_ci#define SUPPORT_BATCH_INSERT 0
950fbfc30aSopenharmony_ci
960fbfc30aSopenharmony_ci#if SUPPORT_BATCH_INSERT
970fbfc30aSopenharmony_ciint Calendar::AddEvents(const std::vector<Event>& events)
980fbfc30aSopenharmony_ci{
990fbfc30aSopenharmony_ci    std::vector<DataShare::DataShareValuesBucket> valueEvents;
1000fbfc30aSopenharmony_ci    for (const auto &event : events) {
1010fbfc30aSopenharmony_ci        valueEvents.emplace_back(BuildValueEvent(event));
1020fbfc30aSopenharmony_ci    }
1030fbfc30aSopenharmony_ci    auto count = DataShareHelperManager::GetInstance().BatchInsert(*(m_eventUri.get()), valueEvents);
1040fbfc30aSopenharmony_ci    LOG_INFO("BatchInsert count %{private}d", count);
1050fbfc30aSopenharmony_ci    return count;
1060fbfc30aSopenharmony_ci}
1070fbfc30aSopenharmony_ci#else
1080fbfc30aSopenharmony_ciint Calendar::AddEvents(const std::vector<Event>& events)
1090fbfc30aSopenharmony_ci{
1100fbfc30aSopenharmony_ci    int count = 0;
1110fbfc30aSopenharmony_ci    int channelId = 0;
1120fbfc30aSopenharmony_ci    for (const auto &event : events) {
1130fbfc30aSopenharmony_ci        auto index = Calendar::AddEventInfo(event, channelId);
1140fbfc30aSopenharmony_ci        if (index > 0) {
1150fbfc30aSopenharmony_ci            count++;
1160fbfc30aSopenharmony_ci        }
1170fbfc30aSopenharmony_ci        channelId++;
1180fbfc30aSopenharmony_ci    }
1190fbfc30aSopenharmony_ci    LOG_INFO("AddEvents count %{private}d", count);
1200fbfc30aSopenharmony_ci    return count;
1210fbfc30aSopenharmony_ci}
1220fbfc30aSopenharmony_ci#endif
1230fbfc30aSopenharmony_ci
1240fbfc30aSopenharmony_ci
1250fbfc30aSopenharmony_cibool Calendar::DeleteEvent(int id)
1260fbfc30aSopenharmony_ci{
1270fbfc30aSopenharmony_ci    DataShare::DataSharePredicates predicates;
1280fbfc30aSopenharmony_ci    predicates.EqualTo("_id", id);
1290fbfc30aSopenharmony_ci    predicates.EqualTo("calendar_id", GetId());
1300fbfc30aSopenharmony_ci    auto ret = DataShareHelperManager::GetInstance().Delete(*(m_eventUri.get()), predicates);
1310fbfc30aSopenharmony_ci    LOG_INFO("DeleteEvent number %{public}d", ret);
1320fbfc30aSopenharmony_ci    {
1330fbfc30aSopenharmony_ci        // delete attendee
1340fbfc30aSopenharmony_ci        DataShare::DataSharePredicates predicates;
1350fbfc30aSopenharmony_ci        predicates.EqualTo("event_id", id);
1360fbfc30aSopenharmony_ci        auto ret = DataShareHelperManager::GetInstance().Delete(*(m_attendeeUri.get()), predicates);
1370fbfc30aSopenharmony_ci        LOG_INFO("Delete attendee num %{public}d", ret);
1380fbfc30aSopenharmony_ci    }
1390fbfc30aSopenharmony_ci    {
1400fbfc30aSopenharmony_ci        // delete reminder
1410fbfc30aSopenharmony_ci        DataShare::DataSharePredicates predicates;
1420fbfc30aSopenharmony_ci        predicates.EqualTo("event_id", id);
1430fbfc30aSopenharmony_ci        auto ret = DataShareHelperManager::GetInstance().Delete(*(m_reminderUrl.get()), predicates);
1440fbfc30aSopenharmony_ci        LOG_INFO("Delete reminder num %{public}d", ret);
1450fbfc30aSopenharmony_ci    }
1460fbfc30aSopenharmony_ci    return ret == 1;
1470fbfc30aSopenharmony_ci}
1480fbfc30aSopenharmony_ci
1490fbfc30aSopenharmony_civoid Calendar::DeleteAllEvents()
1500fbfc30aSopenharmony_ci{
1510fbfc30aSopenharmony_ci    DataShare::DataSharePredicates predicates;
1520fbfc30aSopenharmony_ci    predicates.EqualTo("_id", GetId());
1530fbfc30aSopenharmony_ci    auto ret = DataShareHelperManager::GetInstance().Delete(*(m_eventUri.get()), predicates);
1540fbfc30aSopenharmony_ci    LOG_INFO("DeleteEvent number %{public}d", ret);
1550fbfc30aSopenharmony_ci    return;
1560fbfc30aSopenharmony_ci}
1570fbfc30aSopenharmony_ci
1580fbfc30aSopenharmony_ciint Calendar::DeleteEvents(const std::vector<int>& ids)
1590fbfc30aSopenharmony_ci{
1600fbfc30aSopenharmony_ci    int count = 0;
1610fbfc30aSopenharmony_ci    for (const auto &id : ids) {
1620fbfc30aSopenharmony_ci        if (DeleteEvent(id)) {
1630fbfc30aSopenharmony_ci            count +=1;
1640fbfc30aSopenharmony_ci        }
1650fbfc30aSopenharmony_ci    }
1660fbfc30aSopenharmony_ci    LOG_INFO("DeleteEvents %{public}d", count);
1670fbfc30aSopenharmony_ci    return count;
1680fbfc30aSopenharmony_ci}
1690fbfc30aSopenharmony_ci
1700fbfc30aSopenharmony_cibool Calendar::UpdateEvent(const Event& event)
1710fbfc30aSopenharmony_ci{
1720fbfc30aSopenharmony_ci    if (!event.id) {
1730fbfc30aSopenharmony_ci        LOG_ERROR("event id not exist");
1740fbfc30aSopenharmony_ci        return false;
1750fbfc30aSopenharmony_ci    }
1760fbfc30aSopenharmony_ci    const auto eventId = event.id.value();
1770fbfc30aSopenharmony_ci    DataShare::DataSharePredicates m_predicates;
1780fbfc30aSopenharmony_ci    m_predicates.EqualTo("_id", eventId);
1790fbfc30aSopenharmony_ci    auto valueEvent = BuildValueEvent(event, m_id, 0);
1800fbfc30aSopenharmony_ci    auto ret = DataShareHelperManager::GetInstance().Update(*(m_eventUri.get()), m_predicates, valueEvent);
1810fbfc30aSopenharmony_ci    LOG_INFO(" Update code %{public}d", ret);
1820fbfc30aSopenharmony_ci    {
1830fbfc30aSopenharmony_ci        // delete attendee
1840fbfc30aSopenharmony_ci        DataShare::DataSharePredicates predicates;
1850fbfc30aSopenharmony_ci        predicates.EqualTo("event_id", eventId);
1860fbfc30aSopenharmony_ci        auto ret = DataShareHelperManager::GetInstance().Delete(*(m_attendeeUri.get()), predicates);
1870fbfc30aSopenharmony_ci        LOG_INFO("Delete attendee num %{public}d", ret);
1880fbfc30aSopenharmony_ci    }
1890fbfc30aSopenharmony_ci    auto valueAttendees = std::vector<DataShare::DataShareValuesBucket>();
1900fbfc30aSopenharmony_ci    for (const auto &attendee : event.attendees) {
1910fbfc30aSopenharmony_ci        auto valueAttendee = BuildAttendeeValue(attendee, eventId);
1920fbfc30aSopenharmony_ci        valueAttendees.emplace_back(valueAttendee);
1930fbfc30aSopenharmony_ci    }
1940fbfc30aSopenharmony_ci    if (valueAttendees.size() > 0) {
1950fbfc30aSopenharmony_ci        auto count = DataShareHelperManager::GetInstance().BatchInsert(*(m_attendeeUri.get()), valueAttendees);
1960fbfc30aSopenharmony_ci        LOG_INFO("batchInsert attendees count %{public}d", count);
1970fbfc30aSopenharmony_ci    }
1980fbfc30aSopenharmony_ci
1990fbfc30aSopenharmony_ci    {
2000fbfc30aSopenharmony_ci        // delete reminder
2010fbfc30aSopenharmony_ci        DataShare::DataSharePredicates predicates;
2020fbfc30aSopenharmony_ci        predicates.EqualTo("event_id", eventId);
2030fbfc30aSopenharmony_ci        auto ret = DataShareHelperManager::GetInstance().Delete(*(m_reminderUrl.get()), predicates);
2040fbfc30aSopenharmony_ci        LOG_INFO("Delete reminder num %{public}d", ret);
2050fbfc30aSopenharmony_ci    }
2060fbfc30aSopenharmony_ci    if (event.reminderTime.has_value()) {
2070fbfc30aSopenharmony_ci        InsertReminders(eventId, event.reminderTime.value());
2080fbfc30aSopenharmony_ci    }
2090fbfc30aSopenharmony_ci
2100fbfc30aSopenharmony_ci    return ret == 1;
2110fbfc30aSopenharmony_ci}
2120fbfc30aSopenharmony_ci
2130fbfc30aSopenharmony_ciint Calendar::UpdateEvents(const std::vector<Event>& events)
2140fbfc30aSopenharmony_ci{
2150fbfc30aSopenharmony_ci    int count = 0;
2160fbfc30aSopenharmony_ci    for (const auto &event : events) {
2170fbfc30aSopenharmony_ci        if (UpdateEvent(event)) {
2180fbfc30aSopenharmony_ci            count +=1;
2190fbfc30aSopenharmony_ci        }
2200fbfc30aSopenharmony_ci    }
2210fbfc30aSopenharmony_ci    LOG_INFO("UpdateEvents %{public}d", count);
2220fbfc30aSopenharmony_ci    return count;
2230fbfc30aSopenharmony_ci}
2240fbfc30aSopenharmony_ci
2250fbfc30aSopenharmony_cistd::vector<Attendee> Calendar::GetAttendeesByEventId(int id)
2260fbfc30aSopenharmony_ci{
2270fbfc30aSopenharmony_ci    DataShare::DataSharePredicates predicates;
2280fbfc30aSopenharmony_ci    predicates.EqualTo("event_id", id);
2290fbfc30aSopenharmony_ci    std::vector<std::string> columns = {"attendeeName", "attendeeEmail", "attendeeRelationship"};
2300fbfc30aSopenharmony_ci    DataShare::DatashareBusinessError error;
2310fbfc30aSopenharmony_ci    auto result = DataShareHelperManager::GetInstance().Query(*(m_attendeeUri.get()), predicates, columns, &error);
2320fbfc30aSopenharmony_ci    std::vector<Attendee> attendees;
2330fbfc30aSopenharmony_ci    if (result != nullptr) {
2340fbfc30aSopenharmony_ci        ResultSetToAttendees(attendees, result);
2350fbfc30aSopenharmony_ci    }
2360fbfc30aSopenharmony_ci    LOG_INFO(" query attendee finished");
2370fbfc30aSopenharmony_ci    return attendees;
2380fbfc30aSopenharmony_ci}
2390fbfc30aSopenharmony_ci
2400fbfc30aSopenharmony_cistd::optional<std::vector<int>> Calendar::GetRemindersByEventId(int id)
2410fbfc30aSopenharmony_ci{
2420fbfc30aSopenharmony_ci    DataShare::DataSharePredicates predicates;
2430fbfc30aSopenharmony_ci    predicates.EqualTo("event_id", id);
2440fbfc30aSopenharmony_ci    std::vector<std::string> columns = {"event_id", "minutes"};
2450fbfc30aSopenharmony_ci    DataShare::DatashareBusinessError error;
2460fbfc30aSopenharmony_ci    auto result = DataShareHelperManager::GetInstance().Query(*(m_reminderUrl.get()), predicates, columns, &error);
2470fbfc30aSopenharmony_ci    if (result == nullptr) {
2480fbfc30aSopenharmony_ci        return std::nullopt;
2490fbfc30aSopenharmony_ci    }
2500fbfc30aSopenharmony_ci    std::vector<int> reminders;
2510fbfc30aSopenharmony_ci    auto ret = ResultSetToReminders(reminders, result);
2520fbfc30aSopenharmony_ci    if (ret != DataShare::E_OK) {
2530fbfc30aSopenharmony_ci        return std::nullopt;
2540fbfc30aSopenharmony_ci    }
2550fbfc30aSopenharmony_ci    LOG_INFO("query reminder finished");
2560fbfc30aSopenharmony_ci    return reminders;
2570fbfc30aSopenharmony_ci}
2580fbfc30aSopenharmony_ci
2590fbfc30aSopenharmony_cistd::vector<Event> Calendar::GetEvents(std::shared_ptr<EventFilter> filter, const std::vector<string>& eventKey)
2600fbfc30aSopenharmony_ci{
2610fbfc30aSopenharmony_ci    std::vector<Event> events;
2620fbfc30aSopenharmony_ci    std::shared_ptr<DataShare::DataSharePredicates> predicates = nullptr;
2630fbfc30aSopenharmony_ci    if (filter) {
2640fbfc30aSopenharmony_ci        predicates = filter->GetFilterPrediacates();
2650fbfc30aSopenharmony_ci        if (!predicates) {
2660fbfc30aSopenharmony_ci            LOG_ERROR("predicates null");
2670fbfc30aSopenharmony_ci            return events;
2680fbfc30aSopenharmony_ci        }
2690fbfc30aSopenharmony_ci    } else {
2700fbfc30aSopenharmony_ci        predicates = std::make_shared<DataShare::DataSharePredicates>();
2710fbfc30aSopenharmony_ci    }
2720fbfc30aSopenharmony_ci    predicates->EqualTo("calendar_id", GetId());
2730fbfc30aSopenharmony_ci    std::vector<string> queryField = {};
2740fbfc30aSopenharmony_ci    std::set<string> resultSetField;
2750fbfc30aSopenharmony_ci    if (eventKey.size() > 0) {
2760fbfc30aSopenharmony_ci        queryField.emplace_back("_id");
2770fbfc30aSopenharmony_ci        SetField(eventKey, queryField, resultSetField);
2780fbfc30aSopenharmony_ci    } else {
2790fbfc30aSopenharmony_ci        resultSetField = {"type", "title", "startTime", "endTime", "isAllDay", "description",
2800fbfc30aSopenharmony_ci        "timeZone", "location", "service", "attendee", "reminderTime"};
2810fbfc30aSopenharmony_ci    }
2820fbfc30aSopenharmony_ci    DataShare::DatashareBusinessError error;
2830fbfc30aSopenharmony_ci    auto result = DataShareHelperManager::GetInstance().Query(*(m_eventUri.get()),
2840fbfc30aSopenharmony_ci        *(predicates.get()), queryField, &error);
2850fbfc30aSopenharmony_ci    if (!result) {
2860fbfc30aSopenharmony_ci        LOG_ERROR("query failed");
2870fbfc30aSopenharmony_ci        return events;
2880fbfc30aSopenharmony_ci    }
2890fbfc30aSopenharmony_ci    ResultSetToEvents(events, result, resultSetField);
2900fbfc30aSopenharmony_ci    for (auto &event : events) {
2910fbfc30aSopenharmony_ci        if (!event.id.has_value()) {
2920fbfc30aSopenharmony_ci            continue;
2930fbfc30aSopenharmony_ci        }
2940fbfc30aSopenharmony_ci        const auto eventId = event.id.value();
2950fbfc30aSopenharmony_ci        if (resultSetField.count("attendee")) {
2960fbfc30aSopenharmony_ci            event.attendees = GetAttendeesByEventId(eventId);
2970fbfc30aSopenharmony_ci        }
2980fbfc30aSopenharmony_ci        if (resultSetField.count("reminderTime")) {
2990fbfc30aSopenharmony_ci            event.reminderTime = GetRemindersByEventId(eventId);
3000fbfc30aSopenharmony_ci        }
3010fbfc30aSopenharmony_ci        DumpEvent(event);
3020fbfc30aSopenharmony_ci    }
3030fbfc30aSopenharmony_ci    LOG_INFO("query finished");
3040fbfc30aSopenharmony_ci    return events;
3050fbfc30aSopenharmony_ci}
3060fbfc30aSopenharmony_ci
3070fbfc30aSopenharmony_ciCalendarConfig Calendar::GetConfig()
3080fbfc30aSopenharmony_ci{
3090fbfc30aSopenharmony_ci    return m_config;
3100fbfc30aSopenharmony_ci}
3110fbfc30aSopenharmony_ci
3120fbfc30aSopenharmony_cibool Calendar::SetConfig(const CalendarConfig& config)
3130fbfc30aSopenharmony_ci{
3140fbfc30aSopenharmony_ci    DataShare::DataSharePredicates m_predicates;
3150fbfc30aSopenharmony_ci    m_predicates.EqualTo("_id", m_id);
3160fbfc30aSopenharmony_ci    DataShare::DataShareValuesBucket valuesBucket;
3170fbfc30aSopenharmony_ci    if (std::get_if<1>(&config.color)) {
3180fbfc30aSopenharmony_ci        valuesBucket.Put("calendar_color", std::get<1>(config.color));
3190fbfc30aSopenharmony_ci    }
3200fbfc30aSopenharmony_ci    if (config.enableReminder) {
3210fbfc30aSopenharmony_ci        valuesBucket.Put("canReminder", config.enableReminder.value());
3220fbfc30aSopenharmony_ci    }
3230fbfc30aSopenharmony_ci    if (valuesBucket.IsEmpty()) {
3240fbfc30aSopenharmony_ci        LOG_INFO("no need update");
3250fbfc30aSopenharmony_ci        return true;
3260fbfc30aSopenharmony_ci    }
3270fbfc30aSopenharmony_ci
3280fbfc30aSopenharmony_ci    // dataShareHelper 需要提到event_handler基类里面去
3290fbfc30aSopenharmony_ci    auto ret = DataShareHelperManager::GetInstance().Update(*(m_calendarUri.get()), m_predicates, valuesBucket) == 1;
3300fbfc30aSopenharmony_ci    LOG_INFO("SetConfig %{public}d", ret);
3310fbfc30aSopenharmony_ci    if (ret) {
3320fbfc30aSopenharmony_ci        m_config = config;
3330fbfc30aSopenharmony_ci    }
3340fbfc30aSopenharmony_ci    return ret;
3350fbfc30aSopenharmony_ci}
3360fbfc30aSopenharmony_ci}