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 #ifndef BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_FRAMEWORKS_JS_NAPI_OPEN_SETTINGS_H 16 #define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_FRAMEWORKS_JS_NAPI_OPEN_SETTINGS_H 17 18 #include "common.h" 19 #include <mutex> 20 #include "ui_content.h" 21 #include "ability.h" 22 #include "ability_context.h" 23 24 namespace OHOS { 25 namespace NotificationNapi { 26 using namespace OHOS::Notification; 27 using JsAnsCallbackComplete = void(napi_env, void*); 28 29 struct OpenSettingsParams { 30 std::shared_ptr<OHOS::AbilityRuntime::Context> context; 31 }; 32 33 struct AsyncCallbackInfoOpenSettings { 34 napi_env env = nullptr; 35 napi_async_work asyncWork = nullptr; 36 OpenSettingsParams params; 37 CallbackPromiseInfo info; 38 }; 39 40 void NapiAsyncCompleteCallbackOpenSettings(napi_env env, void *data); 41 napi_value NapiOpenNotificationSettings(napi_env env, napi_callback_info info); 42 napi_value ParseOpenSettingsParameters(const napi_env &env, const napi_callback_info &info, OpenSettingsParams ¶ms); 43 bool CreateSettingsUIExtension(std::shared_ptr<OHOS::AbilityRuntime::Context> context, std::string &bundleName); 44 bool Init(napi_env env, AsyncCallbackInfoOpenSettings* callbackInfo, JsAnsCallbackComplete complete); 45 void ProcessStatusChanged(int32_t code); 46 47 class SettingsModalExtensionCallback { 48 public: 49 SettingsModalExtensionCallback(); 50 ~SettingsModalExtensionCallback(); 51 void OnRelease(int32_t releaseCode); 52 void OnResult(int32_t resultCode, const OHOS::AAFwk::Want& result); 53 void OnReceive(const OHOS::AAFwk::WantParams& request); 54 void OnError(int32_t code, const std::string& name, const std::string &message); 55 void OnRemoteReady(const std::shared_ptr<OHOS::Ace::ModalUIExtensionProxy> &uiProxy); 56 void OnDestroy(); 57 void SetSessionId(int32_t sessionId); 58 void SetBundleName(std::string bundleName); 59 void SetAbilityContext(std::shared_ptr<OHOS::AbilityRuntime::AbilityContext> abilityContext); 60 void ReleaseOrErrorHandle(int32_t code); 61 62 private: 63 int32_t sessionId_ = 0; 64 std::string bundleName_; 65 std::shared_ptr<OHOS::AbilityRuntime::AbilityContext> abilityContext_; 66 }; 67 } // namespace NotificationNapi 68 } // namespace OHOS 69 #endif // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_FRAMEWORKS_JS_NAPI_OPEN_SETTINGS_H