• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024-2025 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_ANS_SERVICES_ANS_INCLUDE_DISTURB_MANAGER_H
17 #define BASE_NOTIFICATION_ANS_SERVICES_ANS_INCLUDE_DISTURB_MANAGER_H
18 
19 #include <functional>
20 #include <map>
21 
22 #include "ans_manager_interface.h"
23 #include "ans_subscriber_local_live_view_interface.h"
24 #include "base_manager.h"
25 #include "distributed_notification_service_ipc_interface_code.h"
26 #include "iremote_stub.h"
27 #include "singleton.h"
28 
29 namespace OHOS {
30 namespace Notification {
31 class DisturbManager final : protected BaseManager, public DelayedSingleton<DisturbManager> {
32 public:
33     DisturbManager();
34     ~DisturbManager() = default;
35     using ExecutionType = std::function<ErrCode(MessageParcel &data, MessageParcel &reply)>;
36 public:
37     /**
38      * @brief Handle remote request.
39      *
40      * @param data Indicates the input parcel.
41      * @param reply Indicates the output parcel.
42      * @param option Indicates the message option.
43      * @return Returns ERR_OK on success, others on failure.
44      */
45     int OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply);
46 private:
47     ErrCode HandleRemoveDoNotDisturbProfiles(MessageParcel &data, MessageParcel &reply);
48     ErrCode HandleSetDoNotDisturbDate(MessageParcel &data, MessageParcel &reply);
49     ErrCode HandleSetDoNotDisturbDateByUser(MessageParcel &data, MessageParcel &reply);
50     ErrCode HandleGetDoNotDisturbDate(MessageParcel &data, MessageParcel &reply);
51     ErrCode HandleGetDoNotDisturbDateByUser(MessageParcel &data, MessageParcel &reply);
52     ErrCode HandleAddDoNotDisturbProfiles(MessageParcel &data, MessageParcel &reply);
53     ErrCode HandleGetDoNotDisturbProfile(MessageParcel &data, MessageParcel &reply);
54     ErrCode HandleDoesSupportDoNotDisturbMode(MessageParcel &data, MessageParcel &reply);
55 
56 private:
57     int32_t CheckSystemAndControllerPermission();
58     void AdjustDateForDndTypeOnce(int64_t &beginDate, int64_t &endDate);
59     ErrCode SetDoNotDisturbDate(const sptr<NotificationDoNotDisturbDate> &date);
60 
61     ErrCode RemoveDoNotDisturbProfilesSyncQueue(const std::vector<sptr<NotificationDoNotDisturbProfile>> &profiles);
62     ErrCode GetDoNotDisturbDateSyncQueue(sptr<NotificationDoNotDisturbDate> &date);
63     ErrCode GetDoNotDisturbDateByUserSyncQueue(const int32_t &userId, sptr<NotificationDoNotDisturbDate> &date);
64     ErrCode SetDoNotDisturbDateByUserSyncQueue(const int32_t &userId, const sptr<NotificationDoNotDisturbDate> &date);
65     ErrCode AddDoNotDisturbProfilesSyncQueue(const std::vector<sptr<NotificationDoNotDisturbProfile>> &profiles);
66 
67     ErrCode SetDoNotDisturbDateByUserInner(const int32_t &userId, const sptr<NotificationDoNotDisturbDate> &date);
68     ErrCode GetDoNotDisturbDateByUserInner(const int32_t &userId, sptr<NotificationDoNotDisturbDate> &date);
69     ErrCode GetDoNotDisturbProfileInner(int64_t id, sptr<NotificationDoNotDisturbProfile> &profile);
70     ErrCode DoesSupportDoNotDisturbModeInner(bool &doesSupport);
71 private:
72     std::map<uint32_t, ExecutionType> codeAndExecuteFuncMap_;
73     std::map<uint32_t, std::function<ErrCode()>> codeAndPermissionFuncMap_;
74 };
75 }  // namespace Notification
76 }  // namespace OHOS
77 
78 #endif  // BASE_NOTIFICATION_ANS_SERVICES_ANS_INCLUDE_DISTURB_MANAGER_H
79