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_notification_flag.h"
16 #include "sts_common.h"
17
18 namespace OHOS {
19 namespace NotificationSts {
WarpNotificationFlags(ani_env * env,const std::shared_ptr<NotificationFlags> & flags,ani_object & flagsObject)20 bool WarpNotificationFlags(ani_env* env, const std::shared_ptr<NotificationFlags> &flags,
21 ani_object &flagsObject)
22 {
23 ANS_LOGD("WarpNotificationFlags call");
24 if (flags == nullptr) {
25 ANS_LOGE("flags is null");
26 return false;
27 }
28 ani_class flagsCls = nullptr;
29 if (!CreateClassObjByClassName(env,
30 "Lnotification/notificationFlags/NotificationFlagsInner;", flagsCls, flagsObject) ||
31 flagsObject == nullptr) {
32 ANS_LOGE("Create faild");
33 return false;
34 }
35 // readonly soundEnabled?: NotificationFlagStatus;
36 int32_t soundEnabled = static_cast<int32_t>(flags->IsSoundEnabled());
37 ani_enum_item enumItem = nullptr;
38 if (!EnumConvertNativeToAni(env, "Lnotification/notificationFlags/NotificationFlagStatus;",
39 soundEnabled, enumItem)) {
40 ANS_LOGE("EnumConvertNativeToAni 'soundEnabled' faild");
41 return false;
42 }
43 if (!SetPropertyByRef(env, flagsObject, "soundEnabled", enumItem)) {
44 ANS_LOGE("WarpNotificationFlags set 'soundEnabled' faild");
45 return false;
46 }
47 // readonly vibrationEnabled?: NotificationFlagStatus;
48 int32_t vibrationEnabled = static_cast<int32_t>(flags->IsVibrationEnabled());
49 if (!EnumConvertNativeToAni(env, "Lnotification/notificationFlags/NotificationFlagStatus;",
50 vibrationEnabled, enumItem)) {
51 ANS_LOGE("EnumConvertNativeToAni 'vibrationEnabled' faild");
52 return false;
53 }
54 if (!SetPropertyByRef(env, flagsObject, "vibrationEnabled", enumItem)) {
55 ANS_LOGE("WarpNotificationFlags set 'vibrationEnabled' faild");
56 return false;
57 }
58 // readonly reminderFlags?: number;
59 uint32_t reminderFlags = flags->GetReminderFlags();
60 if (!SetPropertyOptionalByDouble(env, flagsObject, "reminderFlags", reminderFlags)) {
61 ANS_LOGD("WarpNotificationFlags set 'reminderFlags' faild");
62 }
63 return true;
64 }
65 } // namespace NotificationSts
66 } // OHOS