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