• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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_UNLOCK_LISTENER_TIMER_INFO_H
17 #define BASE_NOTIFICATION_UNLOCK_LISTENER_TIMER_INFO_H
18 #ifdef DISTRIBUTED_FEATURE_MASTER
19 
20 #include <functional>
21 
22 #include "ffrt.h"
23 #include "itimer_info.h"
24 
25 namespace OHOS {
26 namespace Notification {
27 struct UnlockListenerWant {
28     uint64_t timer;
29     std::shared_ptr<AbilityRuntime::WantAgent::WantAgent> wantAgentPtr = nullptr;
30 };
31 
32 class UnlockListenerTimerInfo : public MiscServices::ITimerInfo {
33 public:
UnlockListenerTimerInfo(std::string timerHashCode)34     UnlockListenerTimerInfo(std::string timerHashCode) : timerHashCode_(timerHashCode) {};
~UnlockListenerTimerInfo()35     virtual ~UnlockListenerTimerInfo() {};
36     /**
37      * When timing is up, this function will execute as call back.
38      */
39     void OnTrigger() override;
40 
41     /**
42      * Indicates the timing type.
43      */
SetType(const int32_t & type)44     void SetType(const int32_t &type) override {};
45 
46     /**
47      * Indicates the repeat policy.
48      */
SetRepeat(bool repeat)49     void SetRepeat(bool repeat) override {};
50 
51     /**
52      * Indicates the interval time for repeat timing.
53      */
SetInterval(const uint64_t & interval)54     void SetInterval(const uint64_t &interval) override {};
55 
56     /**
57      * Indicates the want agent information.
58      */
SetWantAgent(std::shared_ptr<OHOS::AbilityRuntime::WantAgent::WantAgent> wantAgent)59     void SetWantAgent(std::shared_ptr<OHOS::AbilityRuntime::WantAgent::WantAgent> wantAgent) override {};
60 
61 private:
62     std::string timerHashCode_;
63 };
64 
65 struct NotifictionJumpInfo {
66 public:
NotifictionJumpInfoNotifictionJumpInfo67     NotifictionJumpInfo() {}
NotifictionJumpInfoNotifictionJumpInfo68     NotifictionJumpInfo(int32_t jump, int32_t index, int32_t typeId, int64_t time)
69         : jumpType(jump), btnIndex(index), deviceTypeId(typeId), timeStamp(time) {}
70     int32_t jumpType;
71     int32_t btnIndex;
72     int32_t deviceTypeId;
73     int64_t timeStamp;
74 };
75 
76 class UnlockListenerOperService {
77 public:
78     static UnlockListenerOperService& GetInstance();
79     void AddDelayTask(const std::string& hashCode, const int32_t jumpType, const int32_t deviceType,
80         const int32_t btnIndex);
81     void ReplyOperationResponse();
82     void HandleOperationTimeOut(const std::string& hashCode);
83     void RemoveOperationResponse(const std::string& hashCode);
84     void TriggerByJumpType(const std::string& hashCode, const int32_t jumpType,
85         const int32_t deviceType, const int32_t btnIndex);
86 
87 private:
88     UnlockListenerOperService();
89     ~UnlockListenerOperService() = default;
90 
91     int64_t GetCurrentTime();
92     std::shared_ptr<AbilityRuntime::WantAgent::WantAgent> GetNtfWantAgentPtr(const std::string& hashCode);
93     ErrCode LaunchWantAgent(const std::shared_ptr<AbilityRuntime::WantAgent::WantAgent> wantAgentPtr);
94     ErrCode GetNtfBtnWantAgentPtr(const std::string& hashCode,
95         const int32_t btnIndex, std::shared_ptr<AbilityRuntime::WantAgent::WantAgent>& wantAgentPtr);
96 
97 private:
98     ffrt::mutex mapLock_;
99     std::shared_ptr<ffrt::queue> operationQueue_ = nullptr;
100     std::vector<std::string> hashCodeOrder_;
101     std::map<std::string, uint64_t> timerMap_;
102     std::map<std::string, NotifictionJumpInfo> delayTaskMap_;
103 };
104 } // namespace OHOS
105 } // namespace Notification
106 #endif  // DISTRIBUTED_FEATURE_MASTER
107 #endif  // BASE_NOTIFICATION_UNLOCK_LISTENER_TIMER_INFO_H
108