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_ANS_DIALOG_CALLBACK_H 17 #define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_FRAMEWORKS_ETS_ANI_INCLUDE_ANI_ANS_DIALOG_CALLBACK_H 18 #include <string> 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 using namespace Notification; 29 30 struct EnableNotificationInfo { 31 int32_t errorCode = ANI_OK; 32 std::string bundleName {""}; 33 bool stageMode = false; 34 ani_resolver resolver {}; 35 std::shared_ptr<OHOS::AbilityRuntime::Context> context = nullptr; 36 sptr<IRemoteObject> callerToken = nullptr; 37 }; 38 39 using StsAnsDialogCallbackComplete = void(ani_env *env, std::shared_ptr<EnableNotificationInfo> info); 40 class StsAnsDialogCallback final : public AnsDialogCallbackNativeInterface { 41 public: 42 StsAnsDialogCallback() = default; 43 ~StsAnsDialogCallback() override = default; 44 DISALLOW_COPY_AND_MOVE(StsAnsDialogCallback); 45 46 bool Init(ani_env *env, 47 std::shared_ptr<EnableNotificationInfo> info, 48 StsAnsDialogCallbackComplete *complete); 49 void ProcessDialogStatusChanged(const DialogStatusData& data) override; 50 51 private: 52 ani_vm *vm_ = nullptr; 53 std::shared_ptr<EnableNotificationInfo> info_ = nullptr; 54 StsAnsDialogCallbackComplete *complete_ = nullptr; 55 static int32_t GetErrCodeFromStatus(EnabledDialogStatus status); 56 }; 57 58 class ModalExtensionCallback { 59 public: 60 ModalExtensionCallback(); 61 ~ModalExtensionCallback(); 62 void OnRelease(int32_t releaseCode); 63 void OnResult(int32_t resultCode, const OHOS::AAFwk::Want& result); 64 void OnReceive(const OHOS::AAFwk::WantParams& request); 65 void OnError(int32_t code, const std::string& name, const std::string &message); 66 void OnRemoteReady(const std::shared_ptr<OHOS::Ace::ModalUIExtensionProxy> &uiProxy); 67 void OnDestroy(); 68 void SetSessionId(int32_t sessionId); 69 void SetBundleName(std::string bundleName); 70 void SetAbilityContext(std::shared_ptr<OHOS::AbilityRuntime::AbilityContext> abilityContext); 71 void ReleaseOrErrorHandle(int32_t code); 72 73 private: 74 int32_t sessionId_ = 0; 75 std::string bundleName_; 76 std::shared_ptr<OHOS::AbilityRuntime::AbilityContext> abilityContext_; 77 }; 78 79 } 80 } 81 82 #endif // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_FRAMEWORKS_ETS_ANI_INCLUDE_ANI_ANS_DIALOG_CALLBACK_H