• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 
16 #include "napi_disable_notification.h"
17 
18 #include "ans_inner_errors.h"
19 #include "disable_notification.h"
20 
21 namespace OHOS {
22 namespace NotificationNapi {
NapiDisableNotificationFeature(napi_env env,napi_callback_info info)23 napi_value NapiDisableNotificationFeature(napi_env env, napi_callback_info info)
24 {
25 #ifdef DISABLE_NOTIFICATION_FEATURE_ENABLE
26     ANS_LOGD("called");
27     NotificationDisable paras;
28     if (!ParseDisableNotificationParameters(env, info, paras)) {
29         Common::NapiThrow(env, ERROR_PARAM_INVALID);
30         return Common::NapiGetUndefined(env);
31     }
32 
33     AsyncCallbackInfoDisableNotification *asynccallbackinfo = new (std::nothrow) AsyncCallbackInfoDisableNotification {
34         .env = env, .asyncWork = nullptr, .disableNotification = paras
35     };
36     if (!asynccallbackinfo) {
37         Common::NapiThrow(env, ERROR_INTERNAL_ERROR);
38         return Common::JSParaError(env, nullptr);
39     }
40     napi_value promise = nullptr;
41     Common::PaddingCallbackPromiseInfo(env, nullptr, asynccallbackinfo->info, promise);
42 
43     napi_value resourceName = nullptr;
44     napi_create_string_latin1(env, "disableNotificationFeature", NAPI_AUTO_LENGTH, &resourceName);
45     // Asynchronous function call
46     napi_create_async_work(env,
47         nullptr, resourceName, [](napi_env env, void *data) {
48             ANS_LOGD("Napi disable notification Feature work excute.");
49             AsyncCallbackInfoDisableNotification *asynccallbackinfo =
50                 static_cast<AsyncCallbackInfoDisableNotification *>(data);
51             if (asynccallbackinfo) {
52                 asynccallbackinfo->info.errorCode =
53                     NotificationHelper::DisableNotificationFeature(asynccallbackinfo->disableNotification);
54             }
55         },
56         [](napi_env env, napi_status status, void *data) {
57             ANS_LOGD("Napi disable notification Feature work complete.");
58             AsyncCallbackInfoDisableNotification *asynccallbackinfo =
59                 static_cast<AsyncCallbackInfoDisableNotification *>(data);
60             if (asynccallbackinfo) {
61                 Common::CreateReturnValue(env, asynccallbackinfo->info, Common::NapiGetNull(env));
62                 napi_delete_async_work(env, asynccallbackinfo->asyncWork);
63                 delete asynccallbackinfo;
64                 asynccallbackinfo = nullptr;
65             }
66         },
67         (void *)asynccallbackinfo,
68         &asynccallbackinfo->asyncWork);
69     napi_queue_async_work_with_qos(env, asynccallbackinfo->asyncWork, napi_qos_user_initiated);
70     return promise;
71 #else
72     Common::NapiThrow(env, ERROR_SYSTEM_CAP_ERROR);
73     return Common::NapiGetUndefined(env);
74 #endif
75 }
76 }
77 }