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 16 #ifndef BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_FRAMEWORKS_ETS_ANI_INCLUDE_ANI_OPEN_SETTINGS_H 17 #define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_FRAMEWORKS_ETS_ANI_INCLUDE_ANI_OPEN_SETTINGS_H 18 19 #include "ani.h" 20 #include "ani_base_context.h" 21 #include "ans_dialog_host_client.h" 22 #include "ability.h" 23 #include "ability_context.h" 24 #include "ui_content.h" 25 26 namespace OHOS { 27 namespace NotificationManagerSts { 28 class SettingsModalExtensionCallback; 29 struct OpenSettingsInfo { 30 int32_t errorCode = ANI_OK; 31 std::shared_ptr<OHOS::AbilityRuntime::Context> context = nullptr; 32 ani_resolver resolver {}; 33 }; 34 35 ani_object AniOpenNotificationSettings(ani_env *env, ani_object content); 36 bool GetOpenSettingsInfo(ani_env *env, ani_object content, std::shared_ptr<OpenSettingsInfo> &info); 37 bool CreateSettingsUIExtension(std::shared_ptr<OHOS::AbilityRuntime::Context> context, std::string &bundleName, 38 ani_env *env, std::shared_ptr<OpenSettingsInfo> &info); 39 void StsAsyncCompleteCallbackOpenSettings(ani_env *env, std::shared_ptr<OpenSettingsInfo> info); 40 41 using StsSettingsModalExtensionCallbackComplete = void(ani_env *env, std::shared_ptr<OpenSettingsInfo> info); 42 void ProcessStatusChanged(int32_t code); 43 bool CreateUiExtCallback(ani_env *env, std::shared_ptr<SettingsModalExtensionCallback>& uiExtCallback, 44 Ace::ModalUIExtensionCallbacks& uiExtensionCallbacks, std::shared_ptr<OpenSettingsInfo> &info, 45 std::shared_ptr<OHOS::AbilityRuntime::AbilityContext>& abilityContext, std::string &bundleName); 46 class SettingsModalExtensionCallback { 47 public: 48 SettingsModalExtensionCallback(); 49 ~SettingsModalExtensionCallback(); 50 void OnRelease(int32_t releaseCode); 51 void OnResult(int32_t resultCode, const OHOS::AAFwk::Want& result); 52 void OnReceive(const OHOS::AAFwk::WantParams& request); 53 void OnError(int32_t code, const std::string& name, const std::string &message); 54 void OnRemoteReady(const std::shared_ptr<OHOS::Ace::ModalUIExtensionProxy> &uiProxy); 55 void OnDestroy(); 56 void SetSessionId(int32_t sessionId); 57 void SetBundleName(std::string bundleName); 58 void SetAbilityContext(std::shared_ptr<OHOS::AbilityRuntime::AbilityContext> abilityContext); 59 void ReleaseOrErrorHandle(int32_t code); 60 bool Init(ani_env *env, std::shared_ptr<OpenSettingsInfo> info, 61 StsSettingsModalExtensionCallbackComplete *complete); 62 void ProcessStatusChanged(int32_t code, bool isAsync); 63 private: 64 int32_t sessionId_ = 0; 65 std::string bundleName_; 66 std::shared_ptr<OHOS::AbilityRuntime::AbilityContext> abilityContext_; 67 ani_vm *vm_ = nullptr; 68 std::shared_ptr<OpenSettingsInfo> info_ = nullptr; 69 StsSettingsModalExtensionCallbackComplete *complete_ = nullptr; 70 }; 71 } // namespace NotificationManagerSts 72 } // namespace OHOS 73 #endif