• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 #include "sts_user_input.h"
16 
17 #include "sts_common.h"
18 
19 namespace OHOS {
20 namespace NotificationSts {
UnwrapNotificationUserInput(ani_env * env,ani_object param,std::shared_ptr<Notification::NotificationUserInput> & userInput)21 ani_status UnwrapNotificationUserInput(ani_env *env, ani_object param,
22     std::shared_ptr<Notification::NotificationUserInput> &userInput)
23 {
24     if (env == nullptr || param == nullptr) {
25         ANS_LOGE("invalid parameter value");
26         return ANI_ERROR;
27     }
28     ani_status status = ANI_ERROR;
29     std::string inputKey;
30     ani_boolean isUndefined = ANI_TRUE;
31     if ((status = GetPropertyString(env, param, "inputKey", isUndefined, inputKey)) != ANI_OK
32         || isUndefined == ANI_TRUE) {
33             ANS_LOGE("GetPropertyString 'inputKey' faild");
34             return ANI_INVALID_ARGS;
35         }
36     userInput = Notification::NotificationUserInput::Create(GetResizeStr(inputKey, STR_MAX_SIZE));
37     return status;
38 }
39 
WarpUserInput(ani_env * env,std::shared_ptr<Notification::NotificationUserInput> userInput)40 ani_object WarpUserInput(ani_env *env, std::shared_ptr<Notification::NotificationUserInput> userInput)
41 {
42     if (env == nullptr || userInput == nullptr) {
43         ANS_LOGE("invalid parameter value");
44         return nullptr;
45     }
46     ani_class userInputCls = nullptr;
47     ani_object userInputObject = nullptr;
48     ani_status status = ANI_OK;
49     if (!CreateClassObjByClassName(env,
50         "Lnotification/notificationUserInput/NotificationUserInputInner;", userInputCls, userInputObject)) {
51             ANS_LOGE("Create faild");
52             return nullptr;
53         }
54     ani_string stringValue;
55     if (ANI_OK != (status = GetAniStringByString(env, userInput->GetInputKey(), stringValue))) {
56         ANS_LOGE("GetAniStringByString faild. status %{public}d", status);
57         return nullptr;
58     }
59     if (!CallSetter(env, userInputCls, userInputObject, "inputKey", stringValue)) {
60         ANS_LOGE("set inputKey");
61         return nullptr;
62     }
63     return userInputObject;
64 }
65 }
66 }
67