• 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_support_template.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 {
AniIsSupportTemplate(ani_env * env,ani_string templateName)26 ani_boolean AniIsSupportTemplate(ani_env* env, ani_string templateName)
27 {
28     ANS_LOGD("AniIsSupportTemplate call");
29     std::string tempStr;
30     if (NotificationSts::GetStringByAniString(env, templateName, tempStr) != ANI_OK) {
31         NotificationSts::ThrowErrorWithMsg(env, "templateName parse failed!");
32         return NotificationSts::BoolToAniBoolean(false);
33     }
34     std::string templateNameStr = NotificationSts::GetResizeStr(tempStr, NotificationSts::STR_MAX_SIZE);
35     ANS_LOGD("AniIsSupportTemplate by templateName:%{public}s", templateNameStr.c_str());
36     bool support = false;
37     int returncode = Notification::NotificationHelper::IsSupportTemplate(templateNameStr, support);
38     if (returncode != ERR_OK) {
39         int externalCode = NotificationSts::GetExternalCode(returncode);
40         ANS_LOGE("AniIsSupportTemplate -> error, errorCode: %{public}d", externalCode);
41         OHOS::NotificationSts::ThrowError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode));
42         return NotificationSts::BoolToAniBoolean(false);
43     }
44     ANS_LOGD("AniIsSupportTemplate end, support: %{public}d, returncode: %{public}d", support, returncode);
45     return NotificationSts::BoolToAniBoolean(support);
46 }
47 
AniGetDeviceRemindType(ani_env * env)48 ani_object AniGetDeviceRemindType(ani_env *env)
49 {
50     ANS_LOGD("AniGetDeviceRemindType enter");
51     Notification::NotificationConstant::RemindType remindType =
52         Notification::NotificationConstant::RemindType::DEVICE_IDLE_REMIND;
53     int returncode = Notification::NotificationHelper::GetDeviceRemindType(remindType);
54     if (returncode != ERR_OK) {
55         int externalCode = NotificationSts::GetExternalCode(returncode);
56         ANS_LOGE("AniGetDeviceRemindType error, errorCode: %{public}d", externalCode);
57         OHOS::NotificationSts::ThrowError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode));
58         return nullptr;
59     }
60     ani_enum_item remindTypeItem {};
61     if (!NotificationSts::DeviceRemindTypeCToEts(env, remindType, remindTypeItem)) {
62         NotificationSts::ThrowErrorWithMsg(env, "AniGetDeviceRemindType:failed to WrapNotificationSlotArray");
63         return nullptr;
64     }
65     ANS_LOGD("AniGetDeviceRemindType end, ret: %{public}d", returncode);
66     return remindTypeItem;
67 }
68 }
69 }