1 /* 2 * Copyright (c) 2024-2024 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_SERVICES_ANS_INCLUDE_SMART_REMINDER_CENTER_H 17 #define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_ANS_INCLUDE_SMART_REMINDER_CENTER_H 18 #ifdef NOTIFICATION_SMART_REMINDER_SUPPORTED 19 20 #include <bitset> 21 #include <cstring> 22 #include <map> 23 #include <memory> 24 #include <set> 25 #include <singleton.h> 26 27 #include "advanced_notification_service.h" 28 29 #include "distributed_device_status.h" 30 #include "file_utils.h" 31 #include "nlohmann/json.hpp" 32 #include "notification_constant.h" 33 #include "notification_content.h" 34 #include "notification_flags.h" 35 #include "notification_request.h" 36 #include "reminder_affected.h" 37 #include "singleton.h" 38 39 namespace OHOS { 40 namespace Notification { 41 using namespace std; 42 class SmartReminderCenter : public DelayedSingleton<SmartReminderCenter> { 43 public: 44 SmartReminderCenter(); 45 ~SmartReminderCenter() = default; 46 47 void ReminderDecisionProcess(const sptr<NotificationRequest> &request) const; 48 bool CompareStatus(const string &status, const bitset<DistributedDeviceStatus::STATUS_SIZE> &bitStatus) const; 49 50 private: 51 void GetMultiDeviceReminder(); 52 void ParseReminderFilterDevice(const nlohmann::json &root, const string &deviceType); 53 void ParseReminderFilterSlot( 54 const nlohmann::json &root, 55 const string ¬ificationType, 56 map<string, vector<shared_ptr<ReminderAffected>>> &reminderFilterDevice) const; 57 void ParseReminderFilterContent( 58 const nlohmann::json &root, 59 const string ¬ificationType, 60 map<string, vector<shared_ptr<ReminderAffected>>> &reminderFilterDevice) const; 61 void ParseReminderFilterCode( 62 const nlohmann::json &root, 63 const string ¬ificationType, 64 map<string, vector<shared_ptr<ReminderAffected>>> &reminderFilterDevice) const; 65 void HandleReminderMethods( 66 const string &deviceType, 67 const map<string, vector<shared_ptr<ReminderAffected>>> &reminderFilterDevice, 68 const sptr<NotificationRequest> &request, 69 set<string> &validDevices, 70 shared_ptr<map<string, shared_ptr<NotificationFlags>>> notificationFlagsOfDevices) const; 71 bool HandleAffectedReminder( 72 const string &deviceType, 73 const shared_ptr<ReminderAffected> &reminderAffected, 74 const set<string> &validDevices, 75 shared_ptr<map<string, shared_ptr<NotificationFlags>>> notificationFlagsOfDevices) const; 76 void GetReminderAffecteds( 77 const map<string, vector<shared_ptr<ReminderAffected>>> &reminderFilterDevice, 78 const sptr<NotificationRequest> &request, 79 vector<shared_ptr<ReminderAffected>> &reminderAffecteds) const; 80 void GetDeviceStatusByType(const string &deviceType, bitset<DistributedDeviceStatus::STATUS_SIZE> &bitStatus) const; 81 bool IsNeedSynergy(const string &deviceType, const string &ownerBundleName, int32_t ownerUid) const; 82 83 map<NotificationConstant::SlotType, shared_ptr<NotificationFlags>> currentReminderMethods_; 84 map<string, map<string, vector<shared_ptr<ReminderAffected>>>> reminderMethods_; 85 86 constexpr static const char* MULTI_DEVICE_REMINDER = "multiDeviceReminder"; 87 constexpr static const char* REMINDER_FILTER_DEVICE = "reminderFilterDevice"; 88 constexpr static const char* SLOT_TYPE = "slotType"; 89 constexpr static const char* REMINDER_FILTER_SLOT = "reminderFilterSlot"; 90 constexpr static const char* CONTENT_TYPE = "contentType"; 91 constexpr static const char* REMINDER_FILTER_CONTENT = "reminderFilterContent"; 92 constexpr static const char* TYPE_CODE = "typeCode"; 93 constexpr static const char* REMINDER_FILTER_CODE = "reminderFilterCode"; 94 constexpr static const char* SPLIT_FLAG = "|"; 95 }; 96 } // namespace Notification 97 } // namespace OHOS 98 99 #endif // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_ANS_INCLUDE_SMART_REMINDER_CENTER_H 100 #endif 101