• 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     uint32_t orientation {0};
46     uint32_t needRotate {0};
47     uint32_t alreadyLoad {0};
48     std::string version {""};
49     std::vector<std::string> typeList {};
50     bool endAfterFirstFail {false};
51     AuthIntent authIntent {AuthIntent::DEFAULT};
52     int32_t tipCode {0};
53 };
54 void to_json(nlohmann::json &jsonNotice, const WidgetNotice &notice);
55 void from_json(const nlohmann::json &jsonNotice, WidgetNotice &notice);
56 void LoadConfigJsonBuffer(nlohmann::json &jsonBuf);
57 bool GetProcessName(nlohmann::json &jsonBuf, std::vector<std::string> &processName);
58 bool GetFollowCallerList(nlohmann::json &jsonBuf, std::vector<std::string> &processName);
59 bool GetSceneboardBundleName(nlohmann::json &jsonBuf, std::string &processName);
60 bool GetSceneboardAbilityName(nlohmann::json &jsonBuf, std::string &processName);
61 
62 // WidgetCommand
63 struct WidgetCommand {
64     struct ExtraInfo {
65         std::string callingBundleName {""};
66         std::vector<uint8_t> challenge {};
67     };
68 
69     struct Cmd {
70         std::string event {""};
71         std::string version {""};
72         std::string type {""};
73 
74         int32_t result = -1;
75         int32_t lockoutDuration = -1;
76         int32_t remainAttempts = -1;
77         std::string sensorInfo {""};
78 
79         int32_t tipType = -1;
80         std::vector<uint8_t> tipInfo;
81 
82         ExtraInfo extraInfo;
83     };
84 
85     uint64_t widgetContextId {0};
86     std::vector<std::string> typeList {};
87     std::string title {""};
88     std::string pinSubType {""};
89     std::string windowModeType {""};
90     std::string navigationButtonText {""};
91     std::vector<Cmd> cmdList {};
92     int32_t isReload {0};
93     std::string rotateAuthType {""};
94     std::string callingAppID {""};
95     std::string callingProcessName {""};
96     std::string widgetContextIdStr {""};
97     int32_t userId {-1};
98     bool skipLockedBiometricAuth {false};
99 };
100 
101 void to_json(nlohmann::json &jsonCommand, const WidgetCommand &command);
102 
103 // WidgetCmdParameters
104 struct WidgetCmdParameters {
105     std::string uiExtensionType {""};
106     WidgetCommand useriamCmdData {};
107     std::string uiExtNodeAngle {""};
108     uint32_t sysDialogZOrder {0};
109 };
110 
111 void to_json(nlohmann::json &jsonWidgetCmdParams, const WidgetCmdParameters &widgetCmdParameters);
112 } // namespace UserAuth
113 } // namespace UserIam
114 } // namespace OHOS
115 #endif // IAM_WIDGET_JSON_H