• 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_local_live_view.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 {
AniTriggerSystemLiveView(ani_env * env,ani_object bundleOptionObj,ani_double notificationId,ani_object buttonOptionsObj)26 void AniTriggerSystemLiveView(
27     ani_env *env, ani_object bundleOptionObj, ani_double notificationId, ani_object buttonOptionsObj)
28 {
29     ANS_LOGD("AniTriggerSystemLiveView call");
30     BundleOption bundleOption;
31     if (!NotificationSts::UnwrapBundleOption(env, bundleOptionObj, bundleOption)) {
32         OHOS::NotificationSts::ThrowError(env, OHOS::Notification::ERROR_INTERNAL_ERROR,
33             NotificationSts::FindAnsErrMsg(OHOS::Notification::ERROR_INTERNAL_ERROR));
34         ANS_LOGE("AniTriggerSystemLiveView bundleOption ERROR_INTERNAL_ERROR");
35         return;
36     }
37     NotificationSts::ButtonOption buttonOption;
38     if (NotificationSts::UnWarpNotificationButtonOption(env, buttonOptionsObj, buttonOption) != ANI_OK) {
39         OHOS::NotificationSts::ThrowError(env, OHOS::Notification::ERROR_INTERNAL_ERROR,
40             NotificationSts::FindAnsErrMsg(OHOS::Notification::ERROR_INTERNAL_ERROR));
41         ANS_LOGE("AniTriggerSystemLiveView buttonOption ERROR_INTERNAL_ERROR");
42         return;
43     }
44     int returncode = OHOS::Notification::NotificationHelper::TriggerLocalLiveView(bundleOption,
45         static_cast<int32_t>(notificationId), buttonOption);
46     if (returncode != ERR_OK) {
47         int externalCode = NotificationSts::GetExternalCode(returncode);
48         OHOS::NotificationSts::ThrowError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode));
49         ANS_LOGE("AniTriggerSystemLiveView error, errorCode: %{public}d", externalCode);
50     }
51     ANS_LOGD("AniTriggerSystemLiveView end");
52 }
53 
AniSubscribeSystemLiveView(ani_env * env,ani_object subscriberObj)54 void AniSubscribeSystemLiveView(ani_env *env, ani_object subscriberObj)
55 {
56     ANS_LOGD("AniSubscribeSystemLiveView call");
57     NotificationSts::StsNotificationLocalLiveViewSubscriber *localLiveViewSubscriber
58         = new (std::nothrow)NotificationSts::StsNotificationLocalLiveViewSubscriber();
59     localLiveViewSubscriber->SetStsNotificationLocalLiveViewSubscriber(env, subscriberObj);
60     int returncode
61         = OHOS::Notification::NotificationHelper::SubscribeLocalLiveViewNotification(*localLiveViewSubscriber, false);
62     if (returncode != ERR_OK) {
63         int externalCode = NotificationSts::GetExternalCode(returncode);
64         OHOS::NotificationSts::ThrowError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode));
65         ANS_LOGE("AniSubscribeSystemLiveView error, errorCode: %{public}d", externalCode);
66     }
67     ANS_LOGD("AniSubscribeSystemLiveView end");
68 }
69 } // namespace NotificationManagerSts
70 } // namespace OHOS