• 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_CLIENT_H
17 #define IAM_WIDGET_CLIENT_H
18 
19 #include <cstdint>
20 #include <memory>
21 #include <set>
22 #include <vector>
23 
24 #include "authentication_impl.h"
25 #include "base_context.h"
26 #include "widget_callback_interface.h"
27 #include "widget_json.h"
28 #include "widget_schedule_node.h"
29 
30 namespace OHOS {
31 namespace UserIam {
32 namespace UserAuth {
33 class WidgetClient {
34 public:
35     static WidgetClient &Instance();
36     ~WidgetClient() = default;
37     // sets
38     void SetWidgetSchedule(const std::shared_ptr<WidgetScheduleNode> &schedule);
39     void SetWidgetContextId(uint64_t contextId);
40     void SetWidgetParam(const WidgetParam &param);
41     void SetAuthTypeList(const std::vector<AuthType> &authTypeList);
42     void SetWidgetCallback(const sptr<WidgetCallbackInterface> &callback);
43     void SetAuthTokenId(uint32_t tokenId);
44     uint32_t GetAuthTokenId() const;
45 
46     // interaction with widget
47     ResultCode OnNotice(NoticeType type, const std::string &eventData);
48     void ReportWidgetResult(int32_t result, AuthType authType,
49         int32_t lockoutDuration, int32_t remainAttempts);
50 
51     // others
52     void SetPinSubType(const PinSubType &subType);
53     void SetSensorInfo(const std::string &info);
54     void Reset();
55     void ForceStopAuth();
56 
57 private:
58     WidgetClient() = default;
59     void SendCommand(const WidgetCommand &command);
60     bool GetAuthTypeList(const WidgetNotice &notice, std::vector<AuthType> &authTypeList);
61     bool IsValidNoticeType(const WidgetNotice &notice);
62 
63 private:
64     std::shared_ptr<WidgetScheduleNode> schedule_ {nullptr};
65     uint64_t widgetContextId_ {0};
66     WidgetParam widgetParam_ {};
67     std::vector<AuthType> authTypeList_ {};
68     sptr<WidgetCallbackInterface> widgetCallback_ {nullptr};
69     std::string pinSubType_ {""};
70     std::string sensorInfo_ {""};
71     uint32_t authTokenId_ {0};
72 };
73 } // namespace UserAuth
74 } // namespace UserIam
75 } // namespace OHOS
76 #endif // IAM_WIDGET_CLIENT_H