• 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 IAM_WIDGET_SCHEDULE_NODE_IMPL_H
17 #define IAM_WIDGET_SCHEDULE_NODE_IMPL_H
18 
19 #include <cstdint>
20 #include <memory>
21 #include <mutex>
22 #include <optional>
23 #include <set>
24 
25 #include "iam_hitrace_helper.h"
26 
27 #include "finite_state_machine.h"
28 #include "resource_node.h"
29 #include "widget_schedule_node.h"
30 
31 namespace OHOS {
32 namespace UserIam {
33 namespace UserAuth {
34 class WidgetScheduleNodeImpl final : public WidgetScheduleNode,
35                                public std::enable_shared_from_this<WidgetScheduleNodeImpl>,
36                                public NoCopyable {
37 public:
38     WidgetScheduleNodeImpl();
39     ~WidgetScheduleNodeImpl() override = default;
40     bool StartSchedule() override;
41     bool StopSchedule() override;
42     bool StartAuthList(const std::vector<AuthType> &authTypeList) override;
43     bool StopAuthList(const std::vector<AuthType> &authTypeList) override;
44     bool SuccessAuth(AuthType authType) override;
45     bool NaviPinAuth() override;
46     bool WidgetParaInvalid() override;
47     void SetCallback(std::shared_ptr<WidgetScheduleNodeCallback> callback) override;
48 
49 protected:
50     void OnStartSchedule(FiniteStateMachine &machine, uint32_t event);
51     void OnStopSchedule(FiniteStateMachine &machine, uint32_t event);
52     void OnStartAuth(FiniteStateMachine &machine, uint32_t event);
53     void OnStopAuthList(FiniteStateMachine &machine, uint32_t event);
54     void OnSuccessAuth(FiniteStateMachine &machine, uint32_t event);
55     void OnNaviPinAuth(FiniteStateMachine &machine, uint32_t event);
56     void OnWidgetParaInvalid(FiniteStateMachine &machine, uint32_t event);
57 
58 private:
59     std::shared_ptr<FiniteStateMachine> MakeFiniteStateMachine();
60     bool TryKickMachine(Event event);
61 
62 private:
63     std::shared_ptr<ThreadHandler> threadHandler_ {nullptr};
64     std::shared_ptr<FiniteStateMachine> machine_ {nullptr};
65     std::mutex mutex_;
66     std::shared_ptr<IamHitraceHelper> iamHitraceHelper_ {nullptr};
67     std::weak_ptr<WidgetScheduleNodeCallback> callback_;
68     AuthType successAuthType_ {0};
69     std::vector<AuthType> startAuthTypeList_;
70     std::vector<AuthType> stopAuthTypeList_;
71     std::set<AuthType> runningAuthTypeSet_;
72 };
73 } // namespace UserAuth
74 } // namespace UserIam
75 } // namespace OHOS
76 #endif // IAM_WIDGET_SCHEDULE_NODE_IMPL_H