• 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_JSON_H
17 #define IAM_WIDGET_JSON_H
18 
19 #include <cstdint>
20 #include <memory>
21 
22 #include <string>
23 #include <vector>
24 
25 #include "nlohmann/json.hpp"
26 #include "iam_common_defines.h"
27 #include "user_auth_common_defines.h"
28 
29 namespace OHOS {
30 namespace UserIam {
31 namespace UserAuth {
32 // utils
33 AuthType Str2AuthType(const std::string &strAuthType);
34 std::string AuthType2Str(const AuthType &authType);
35 std::string WinModeType2Str(const WindowModeType &winModeType);
36 std::string PinSubType2Str(const PinSubType &subType);
37 
38 // WidgetNotice
39 struct WidgetNotice {
40     std::vector<AuthType> AuthTypeList() const;
41 
42     // members
43     uint64_t widgetContextId {0};
44     std::string event {""};
45     std::string version {""};
46     std::vector<std::string> typeList {};
47 };
48 void to_json(nlohmann::json &jsonNotice, const WidgetNotice &notice);
49 void from_json(const nlohmann::json &jsonNotice, WidgetNotice &notice);
50 
51 // WidgetCommand
52 struct WidgetCommand {
53     struct Cmd {
54         std::string event {""};
55         std::string version {""};
56         std::string type {""};
57 
58         int32_t result = -1;
59         int32_t lockoutDuration = -1;
60         int32_t remainAttempts = -1;
61         std::string tip = {""};
62         std::string sensorInfo {""};
63     };
64 
65     uint64_t widgetContextId {0};
66     std::vector<std::string> typeList {};
67     std::string title {""};
68     std::string pinSubType {""};
69     std::string windowModeType {""};
70     std::string navigationButtonText {""};
71     std::vector<Cmd> cmdList {};
72 };
73 
74 void to_json(nlohmann::json &jsonCommand, const WidgetCommand &command);
75 
76 // WidgetCmdParameters
77 struct WidgetCmdParameters {
78     std::string uiExtensionType {""};
79     WidgetCommand useriamCmdData {};
80 };
81 
82 void to_json(nlohmann::json &jsonWidgetCmdParams, const WidgetCmdParameters &widgetCmdParameters);
83 } // namespace UserAuth
84 } // namespace UserIam
85 } // namespace OHOS
86 #endif // IAM_WIDGET_JSON_H