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 "widget_callback_interface.h" 26 #include "widget_json.h" 27 #include "widget_schedule_node.h" 28 29 namespace OHOS { 30 namespace UserIam { 31 namespace UserAuth { 32 class WidgetClient { 33 public: 34 static WidgetClient &Instance(); 35 ~WidgetClient() = default; 36 // sets 37 void SetWidgetSchedule(const std::shared_ptr<WidgetScheduleNode> &schedule); 38 void SetWidgetContextId(uint64_t contextId); 39 void SetWidgetParam(const WidgetParam ¶m); 40 void SetAuthTypeList(const std::vector<AuthType> &authTypeList); 41 void SetWidgetCallback(const sptr<WidgetCallbackInterface> &callback); 42 void SetAuthTokenId(uint32_t tokenId); 43 uint32_t GetAuthTokenId() const; 44 45 // interaction with widget 46 ResultCode OnNotice(NoticeType type, const std::string &eventData); 47 void ReportWidgetResult(int32_t result, AuthType authType, 48 int32_t lockoutDuration, int32_t remainAttempts); 49 void ReportWidgetTip(int32_t tipType, AuthType authType, std::vector<uint8_t> tipInfo); 50 51 // others 52 void SetPinSubType(const PinSubType &subType); 53 void SetSensorInfo(const std::string &info); 54 void Reset(); 55 void ForceStopAuth(); 56 57 // extra info 58 void SetChallenge(const std::vector<uint8_t> &challenge); 59 void SetCallingBundleName(const std::string &callingBundleName); 60 61 private: 62 WidgetClient() = default; 63 void SendCommand(const WidgetCommand &command); 64 bool GetAuthTypeList(const WidgetNotice ¬ice, std::vector<AuthType> &authTypeList); 65 bool IsValidNoticeType(const WidgetNotice ¬ice); 66 void ProcessNotice(const WidgetNotice ¬ice, std::vector<AuthType> &authTypeList); 67 68 private: 69 std::shared_ptr<WidgetScheduleNode> schedule_ {nullptr}; 70 uint64_t widgetContextId_ {0}; 71 WidgetParam widgetParam_ {}; 72 std::vector<AuthType> authTypeList_ {}; 73 sptr<WidgetCallbackInterface> widgetCallback_ {nullptr}; 74 std::string pinSubType_ {""}; 75 std::string sensorInfo_ {""}; 76 uint32_t authTokenId_ {0}; 77 std::vector<uint8_t> challenge_ {}; 78 std::string callingBundleName_ {""}; 79 }; 80 } // namespace UserAuth 81 } // namespace UserIam 82 } // namespace OHOS 83 #endif // IAM_WIDGET_CLIENT_H