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_H
17 #define IAM_WIDGET_SCHEDULE_NODE_H
18 
19 #include <cstdint>
20 #include <memory>
21 #include <optional>
22 
23 #include "finite_state_machine.h"
24 #include "iam_common_defines.h"
25 #include "resource_node.h"
26 #include "widget_schedule_node_callback.h"
27 #include "thread_handler.h"
28 #include "user_auth_common_defines.h"
29 
30 namespace OHOS {
31 namespace UserIam {
32 namespace UserAuth {
33 class Context;
34 class WidgetScheduleNode {
35 public:
36     enum State : uint32_t {
37         S_WIDGET_INIT = 0,
38         S_WIDGET_WAITING = 1,
39         S_WIDGET_AUTH_RUNNING = 2,
40         S_WIDGET_AUTH_FINISHED = 3,
41         S_WIDGET_RELOAD_WAITING = 4
42     };
43 
44     enum Event : uint32_t {
45         E_START_WIDGET = 0,
46         E_START_AUTH = 1,
47         E_UPDATE_AUTH = 2,
48         E_CANCEL_AUTH = 3,
49         E_COMPLETE_AUTH = 4,
50         E_NAVI_PIN_AUTH = 5,
51         E_WIDGET_PARA_INVALID = 6,
52         E_WIDGET_RELOAD = 7
53     };
54 
55     virtual ~WidgetScheduleNode() = default;
56     virtual bool StartSchedule() = 0;
57     virtual bool StopSchedule() = 0;
58     virtual bool StartAuthList(const std::vector<AuthType> &authTypeList, bool endAfterFirstFail,
59         AuthIntent authIntent) = 0;
60     virtual bool StopAuthList(const std::vector<AuthType> &authTypeList) = 0;
61     virtual bool SuccessAuth(AuthType authType) = 0;
62     virtual bool NaviPinAuth() = 0;
63     virtual bool WidgetParaInvalid() = 0;
64     virtual bool WidgetReload(uint32_t orientation, uint32_t needRotate, uint32_t alreadyLoad,
65         AuthType &rotateAuthType) = 0;
66     virtual void SetCallback(std::shared_ptr<WidgetScheduleNodeCallback> callback) = 0;
67 };
68 } // namespace UserAuth
69 } // namespace UserIam
70 } // namespace OHOS
71 #endif // IAM_WIDGET_SCHEDULE_NODE_H