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 }; 53 void to_json(nlohmann::json &jsonNotice, const WidgetNotice ¬ice); 54 void from_json(const nlohmann::json &jsonNotice, WidgetNotice ¬ice); 55 56 // WidgetCommand 57 struct WidgetCommand { 58 struct ExtraInfo { 59 std::string callingBundleName {""}; 60 std::vector<uint8_t> challenge {}; 61 }; 62 63 struct Cmd { 64 std::string event {""}; 65 std::string version {""}; 66 std::string type {""}; 67 68 int32_t result = -1; 69 int32_t lockoutDuration = -1; 70 int32_t remainAttempts = -1; 71 std::string sensorInfo {""}; 72 73 int32_t tipType = -1; 74 std::vector<uint8_t> tipInfo; 75 76 ExtraInfo extraInfo; 77 }; 78 79 uint64_t widgetContextId {0}; 80 std::vector<std::string> typeList {}; 81 std::string title {""}; 82 std::string pinSubType {""}; 83 std::string windowModeType {""}; 84 std::string navigationButtonText {""}; 85 std::vector<Cmd> cmdList {}; 86 int32_t isReload {0}; 87 std::string rotateAuthType {""}; 88 std::string callingAppID {""}; 89 }; 90 91 void to_json(nlohmann::json &jsonCommand, const WidgetCommand &command); 92 93 // WidgetCmdParameters 94 struct WidgetCmdParameters { 95 std::string uiExtensionType {""}; 96 WidgetCommand useriamCmdData {}; 97 std::string uiExtNodeAngle {""}; 98 uint32_t sysDialogZOrder {0}; 99 }; 100 101 void to_json(nlohmann::json &jsonWidgetCmdParams, const WidgetCmdParameters &widgetCmdParameters); 102 } // namespace UserAuth 103 } // namespace UserIam 104 } // namespace OHOS 105 #endif // IAM_WIDGET_JSON_H