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 void CreateExtension(AsyncCallbackInfoOpenSettings* asynccallbackinfo); 47 48 class SettingsModalExtensionCallback { 49 public: 50 SettingsModalExtensionCallback(); 51 ~SettingsModalExtensionCallback(); 52 void OnRelease(int32_t releaseCode); 53 void OnResult(int32_t resultCode, const OHOS::AAFwk::Want& result); 54 void OnReceive(const OHOS::AAFwk::WantParams& request); 55 void OnError(int32_t code, const std::string& name, const std::string &message); 56 void OnRemoteReady(const std::shared_ptr<OHOS::Ace::ModalUIExtensionProxy> &uiProxy); 57 void OnDestroy(); 58 void SetSessionId(int32_t sessionId); 59 void SetBundleName(std::string bundleName); 60 void SetAbilityContext(std::shared_ptr<OHOS::AbilityRuntime::AbilityContext> abilityContext); 61 void ReleaseOrErrorHandle(int32_t code); 62 63 private: 64 int32_t sessionId_ = 0; 65 std::string bundleName_; 66 std::shared_ptr<OHOS::AbilityRuntime::AbilityContext> abilityContext_; 67 }; 68 } // namespace NotificationNapi 69 } // namespace OHOS 70 #endif // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_FRAMEWORKS_JS_NAPI_OPEN_SETTINGS_H