• 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 "ani_sync_config.h"
16 
17 #include "notification_helper.h"
18 #include "ans_log_wrapper.h"
19 #include "sts_throw_erro.h"
20 #include "sts_common.h"
21 #include "sts_bundle_option.h"
22 #include "sts_notification_manager.h"
23 
24 namespace OHOS {
25 namespace NotificationManagerSts {
26 const double RESULT_OK = 0.0;
27 const double RESULT_FAILED = 1.0;
28 
AniSetAdditionalConfig(ani_env * env,ani_string key,ani_string value)29 ani_double AniSetAdditionalConfig(ani_env *env, ani_string key, ani_string value)
30 {
31     ANS_LOGD("sts setAdditionalConfig call");
32     if (env == nullptr || key == nullptr) {
33         ANS_LOGE("Invalid env or key is null");
34         return RESULT_FAILED;
35     }
36     std::string keyStr;
37     if (NotificationSts::GetStringByAniString(env, key, keyStr) != ANI_OK) {
38         std::string msg = "Parameter verification failed";
39         ANS_LOGE("GetStringByAniString failed. msg: %{public}s", msg.c_str());
40         OHOS::NotificationSts::ThrowError(env, Notification::ERROR_PARAM_INVALID, msg);
41         return RESULT_FAILED;
42     }
43     std::string valueStr;
44     if (NotificationSts::GetStringByAniString(env, value, valueStr) != ANI_OK) {
45         std::string msg = "Parameter verification failed";
46         ANS_LOGE("GetStringByAniString failed. msg: %{public}s", msg.c_str());
47         OHOS::NotificationSts::ThrowError(env, Notification::ERROR_PARAM_INVALID, msg);
48         return RESULT_FAILED;
49     }
50     int returncode = Notification::NotificationHelper::SetAdditionConfig(keyStr, valueStr);
51     if (returncode != ERR_OK) {
52         int externalCode = NotificationSts::GetExternalCode(returncode);
53         ANS_LOGE("setAdditionalConfig -> error, errorCode: %{public}d", externalCode);
54         NotificationSts::ThrowError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode));
55         return RESULT_FAILED;
56     }
57     return RESULT_OK;
58 }
59 } // namespace NotificationManagerSts
60 } // namespace OHOS