• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 &notificationType,
56         map<string, vector<shared_ptr<ReminderAffected>>> &reminderFilterDevice) const;
57     void ParseReminderFilterContent(
58         const nlohmann::json &root,
59         const string &notificationType,
60         map<string, vector<shared_ptr<ReminderAffected>>> &reminderFilterDevice) const;
61     void ParseReminderFilterCode(
62         const nlohmann::json &root,
63         const string &notificationType,
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> &syncDevices,
70         set<string> &smartDevices,
71         shared_ptr<NotificationFlags> defaultFlag,
72         map<string, bitset<DistributedDeviceStatus::STATUS_SIZE>> &statusMap,
73         shared_ptr<map<string, shared_ptr<NotificationFlags>>> notificationFlagsOfDevices) const;
74     bool HandleAffectedReminder(
75         const string &deviceType,
76         const shared_ptr<ReminderAffected> &reminderAffected,
77         const set<string> &smartDevices,
78         map<string, bitset<DistributedDeviceStatus::STATUS_SIZE>> &statusMap,
79         shared_ptr<map<string, shared_ptr<NotificationFlags>>> notificationFlagsOfDevices) const;
80     void GetReminderAffecteds(
81         const map<string, vector<shared_ptr<ReminderAffected>>> &reminderFilterDevice,
82         const sptr<NotificationRequest> &request,
83         vector<shared_ptr<ReminderAffected>> &reminderAffecteds) const;
84     void GetDeviceStatusByType(const string &deviceType, bitset<DistributedDeviceStatus::STATUS_SIZE> &bitStatus) const;
85     bool IsNeedSynergy(const NotificationConstant::SlotType &slotType,
86         const string &deviceType, const string &ownerBundleName, int32_t ownerUid) const;
87     bool GetAppSwitch(const string &deviceType, const string &ownerBundleName, int32_t ownerUid) const;
88     bool GetSmartSwitch(const string &deviceType) const;
89     bool GetDistributedSwitch(const string &deviceType) const;
90     void InitValidDevices(set<string> &syncDevices, set<string> &smartDevices,
91         map<string, bitset<DistributedDeviceStatus::STATUS_SIZE>> &statusMap,
92         const sptr<NotificationRequest> &request) const;
93 #ifdef ALL_SCENARIO_COLLABORATION
94     void InitPcPadDevices(const string &deviceType,
95         set<string> &syncDevices, set<string> &smartDevices,
96         map<string, bitset<DistributedDeviceStatus::STATUS_SIZE>> &statusMap,
97         const sptr<NotificationRequest> &request) const;
98 #endif
99     void FillRequestExtendInfo(const string &deviceType, DeviceStatus &deviceStatus,
100         const sptr<NotificationRequest> &request,
101         const AppExecFwk::ApplicationInfo &appInfo,
102         const AppExecFwk::BundleResourceInfo &bundleResourceInfo) const;
103     bool IsCollaborationAllowed(const sptr<NotificationRequest> &request) const;
104     map<NotificationConstant::SlotType, shared_ptr<NotificationFlags>> currentReminderMethods_;
105     map<string, map<string, vector<shared_ptr<ReminderAffected>>>> reminderMethods_;
106 
107     constexpr static const char* MULTI_DEVICE_REMINDER = "multiDeviceReminder";
108     constexpr static const char* REMINDER_FILTER_DEVICE = "reminderFilterDevice";
109     constexpr static const char* SLOT_TYPE = "slotType";
110     constexpr static const char* REMINDER_FILTER_SLOT = "reminderFilterSlot";
111     constexpr static const char* CONTENT_TYPE = "contentType";
112     constexpr static const char* REMINDER_FILTER_CONTENT = "reminderFilterContent";
113     constexpr static const char* TYPE_CODE = "typeCode";
114     constexpr static const char* REMINDER_FILTER_CODE = "reminderFilterCode";
115     constexpr static const char* SPLIT_FLAG = "|";
116     constexpr static const char* STATUS_UNUSED = "xxx0";
117     constexpr static const char* STATUS_UNLOCK_OWNER = "x01x";
118     constexpr static const uint32_t STATUS_UNLOCKED_USED_FLAG = 3;
119     const std::string EXTEND_INFO_PRE = "notification_collaboration";
120     const std::string EXTEND_INFO_APP_NAME = "app_name";
121     const std::string EXTEND_INFO_APP_LABEL = "app_label";
122     const std::string EXTEND_INFO_APP_INDEX = "app_index";
123     const std::string EXTEND_INFO_DEVICE_ID = "deviceId";
124     const std::string EXTEND_INFO_USER_ID = "userId";
125 };
126 }  // namespace Notification
127 }  // namespace OHOS
128 
129 #endif // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_ANS_INCLUDE_SMART_REMINDER_CENTER_H
130 #endif
131