• 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, bool endAfterFirstFail,
43         AuthIntent authIntent) override;
44     bool StopAuthList(const std::vector<AuthType> &authTypeList) override;
45     bool SuccessAuth(AuthType authType) override;
46     bool FailAuth(AuthType authType) override;
47     bool NaviPinAuth() override;
48     bool WidgetParaInvalid() override;
49     bool WidgetReload(uint32_t orientation, uint32_t needRotate, uint32_t alreadyLoad,
50         AuthType &rotateAuthType) override;
51     void SetCallback(std::shared_ptr<WidgetScheduleNodeCallback> callback) override;
52     void SendAuthTipInfo(const std::vector<AuthType> &authTypeList, int32_t tipCode) override;
53     bool ClearSchedule() override;
54 
55 protected:
56     void OnStartSchedule(FiniteStateMachine &machine, uint32_t event);
57     void OnStopSchedule(FiniteStateMachine &machine, uint32_t event);
58     void OnStartAuth(FiniteStateMachine &machine, uint32_t event);
59     void OnStopAuthList(FiniteStateMachine &machine, uint32_t event);
60     void OnSuccessAuth(FiniteStateMachine &machine, uint32_t event);
61     void OnNaviPinAuth(FiniteStateMachine &machine, uint32_t event);
62     void OnWidgetParaInvalid(FiniteStateMachine &machine, uint32_t event);
63     void OnWidgetReload(FiniteStateMachine &machine, uint32_t event);
64     void OnWidgetReloadInit(FiniteStateMachine &machine, uint32_t event);
65     void OnFailAuth(FiniteStateMachine &machine, uint32_t event);
66     void OnWidgetRelease(FiniteStateMachine &machine, uint32_t event);
67 
68 private:
69     std::shared_ptr<FiniteStateMachine> MakeFiniteStateMachine();
70     bool TryKickMachine(Event event);
71 
72 private:
73     std::shared_ptr<ThreadHandler> threadHandler_ {nullptr};
74     std::shared_ptr<FiniteStateMachine> machine_ {nullptr};
75     std::mutex mutex_;
76     std::shared_ptr<IamHitraceHelper> iamHitraceHelper_ {nullptr};
77     std::weak_ptr<WidgetScheduleNodeCallback> callback_;
78     AuthType successAuthType_ {0};
79     AuthType failAuthType_ {0};
80     std::vector<AuthType> startAuthTypeList_;
81     bool endAfterFirstFail_ {false};
82     std::vector<AuthType> stopAuthTypeList_;
83     std::set<AuthType> runningAuthTypeSet_;
84     uint32_t orientation_ {0};
85     uint32_t needRotate_ {0};
86     uint32_t alreadyLoad_ {0};
87     AuthType rotateAuthType_ {0};
88     AuthIntent authIntent_ {AuthIntent::DEFAULT};
89 };
90 } // namespace UserAuth
91 } // namespace UserIam
92 } // namespace OHOS
93 #endif // IAM_WIDGET_SCHEDULE_NODE_IMPL_H
94