• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023-2024 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 "modal_callback_interface.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 WidgetParamInner &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     void ReportWidgetTip(int32_t tipType, AuthType authType, std::vector<uint8_t> tipInfo);
51 
52     // others
53     void SetPinSubType(const PinSubType &subType);
54     void SetSensorInfo(const std::string &info);
55     void Reset();
56     void ForceStopAuth();
57     void CancelAuth();
58 
59     // extra info
60     void SetChallenge(const std::vector<uint8_t> &challenge);
61     void SetCallingBundleName(const std::string &callingBundleName);
62 
63     void SetModalCallback(const sptr<ModalCallbackInterface> &callback);
64     void LaunchModal(const std::string &commandData);
65     void ReleaseModal();
66 
67 private:
68     WidgetClient() = default;
69     void SendCommand(const WidgetCommand &command);
70     bool GetAuthTypeList(const WidgetNotice &notice, std::vector<AuthType> &authTypeList);
71     bool IsValidNoticeType(const WidgetNotice &notice);
72     void ProcessNotice(const WidgetNotice &notice, std::vector<AuthType> &authTypeList);
73 
74 private:
75     std::shared_ptr<WidgetScheduleNode> schedule_ {nullptr};
76     uint64_t widgetContextId_ {0};
77     WidgetParamInner widgetParam_ {};
78     std::vector<AuthType> authTypeList_ {};
79     sptr<WidgetCallbackInterface> widgetCallback_ {nullptr};
80     std::string pinSubType_ {""};
81     std::string sensorInfo_ {""};
82     uint32_t authTokenId_ {0};
83     std::vector<uint8_t> challenge_ {};
84     std::string callingBundleName_ {""};
85     sptr<ModalCallbackInterface> modalCallback_ {nullptr};
86 };
87 } // namespace UserAuth
88 } // namespace UserIam
89 } // namespace OHOS
90 #endif // IAM_WIDGET_CLIENT_H