diff --git a/frameworks/ets/ani/ani_common/src/ani_common_configuration.cpp b/frameworks/ets/ani/ani_common/src/ani_common_configuration.cpp index f925bdf886e7e2cde39367f63d2e5ef51b673d1e..c2324ca79ca94fd173422c1d08835b9e4bc2a5af 100644 --- a/frameworks/ets/ani/ani_common/src/ani_common_configuration.cpp +++ b/frameworks/ets/ani/ani_common/src/ani_common_configuration.cpp @@ -36,6 +36,10 @@ constexpr const char* CONFIGURATION_IMPL_CLASS_NAME = "L@ohos/app/ability/Config void SetBasicConfiguration(ani_env *env, ani_object object, const AppExecFwk::Configuration &configuration) { + if (env == nullptr || object == nullptr) { + TAG_LOGE(AAFwkTag::ANI, "null env or object"); + return; + } std::string str = configuration.GetItem(AAFwk::GlobalConfigurationKey::SYSTEM_LANGUAGE); env->Object_SetPropertyByName_Ref(object, "language", GetAniString(env, str)); diff --git a/frameworks/ets/ani/ani_common/src/ani_common_util.cpp b/frameworks/ets/ani/ani_common/src/ani_common_util.cpp index fdadf71591c3e477d001f3a85ad5fb369428958c..9af633224bec52bb52c8f152e66c924b6b998b1e 100644 --- a/frameworks/ets/ani/ani_common/src/ani_common_util.cpp +++ b/frameworks/ets/ani/ani_common/src/ani_common_util.cpp @@ -459,13 +459,13 @@ bool AsyncCallback(ani_env *env, ani_object call, ani_object error, ani_object r ani_class clsCall {}; if ((status = env->FindClass(CLASSNAME_ASYNC_CALLBACK_WRAPPER, &clsCall)) != ANI_OK) { - TAG_LOGE(AAFwkTag::JSNAPI, "status: %{public}d", status); + TAG_LOGE(AAFwkTag::ANI, "status: %{public}d", status); return false; } ani_method method {}; if ((status = env->Class_FindMethod( clsCall, "invoke", "L@ohos/base/BusinessError;Lstd/core/Object;:V", &method)) != ANI_OK) { - TAG_LOGE(AAFwkTag::JSNAPI, "status: %{public}d", status); + TAG_LOGE(AAFwkTag::ANI, "status: %{public}d", status); return false; } if (result == nullptr) { @@ -474,7 +474,7 @@ bool AsyncCallback(ani_env *env, ani_object call, ani_object error, ani_object r result = reinterpret_cast(nullRef); } if ((status = env->Object_CallMethod_Void(call, method, error, result)) != ANI_OK) { - TAG_LOGE(AAFwkTag::JSNAPI, "status: %{public}d", status); + TAG_LOGE(AAFwkTag::ANI, "status: %{public}d", status); return false; } return true; @@ -486,21 +486,26 @@ bool GetDoubleOrUndefined(ani_env *env, ani_object param, const char *name, ani_ ani_boolean isUndefined = true; ani_status status = ANI_ERROR; + if (env == nullptr || param == nullptr || name == nullptr) { + TAG_LOGE(AAFwkTag::ANI, "null env or param or name"); + return false; + } + if ((status = env->Object_GetFieldByName_Ref(param, name, &obj)) != ANI_OK) { - TAG_LOGE(AAFwkTag::JSNAPI, "status : %{public}d", status); + TAG_LOGE(AAFwkTag::ANI, "status : %{public}d", status); return false; } if ((status = env->Reference_IsUndefined(obj, &isUndefined)) != ANI_OK) { - TAG_LOGE(AAFwkTag::JSNAPI, "status : %{public}d", status); + TAG_LOGE(AAFwkTag::ANI, "status : %{public}d", status); return false; } if (isUndefined) { - TAG_LOGE(AAFwkTag::JSNAPI, "%{public}s : undefined", name); + TAG_LOGE(AAFwkTag::ANI, "%{public}s : undefined", name); return false; } if ((status = env->Object_CallMethodByName_Double( reinterpret_cast(obj), "doubleValue", nullptr, &value)) != ANI_OK) { - TAG_LOGE(AAFwkTag::JSNAPI, "status : %{public}d", status); + TAG_LOGE(AAFwkTag::ANI, "status : %{public}d", status); return false; } return true; @@ -512,20 +517,25 @@ bool GetStringOrUndefined(ani_env *env, ani_object param, const char *name, std: ani_boolean isUndefined = true; ani_status status = ANI_ERROR; + if (env == nullptr || param == nullptr || name == nullptr) { + TAG_LOGE(AAFwkTag::ANI, "null env or param or name"); + return false; + } + if ((status = env->Object_GetFieldByName_Ref(param, name, &obj)) != ANI_OK) { - TAG_LOGE(AAFwkTag::JSNAPI, "status : %{public}d", status); + TAG_LOGE(AAFwkTag::ANI, "status : %{public}d", status); return false; } if ((status = env->Reference_IsUndefined(obj, &isUndefined)) != ANI_OK) { - TAG_LOGE(AAFwkTag::JSNAPI, "status : %{public}d", status); + TAG_LOGE(AAFwkTag::ANI, "status : %{public}d", status); return false; } if (isUndefined) { - TAG_LOGE(AAFwkTag::JSNAPI, "%{public}s : undefined", name); + TAG_LOGE(AAFwkTag::ANI, "%{public}s : undefined", name); return false; } if (!GetStdString(env, reinterpret_cast(obj), res)) { - TAG_LOGE(AAFwkTag::JSNAPI, "GetStdString failed"); + TAG_LOGE(AAFwkTag::ANI, "GetStdString failed"); return false; } return true; diff --git a/frameworks/ets/ani/ui_extension_ability/include/ets_ui_extension.h b/frameworks/ets/ani/ui_extension_ability/include/ets_ui_extension.h index 09458863ad71f79362b2736513b67c2234bc0e49..ce7cd0790c1f4b8de8fd603f72219e5e53f673aa 100644 --- a/frameworks/ets/ani/ui_extension_ability/include/ets_ui_extension.h +++ b/frameworks/ets/ani/ui_extension_ability/include/ets_ui_extension.h @@ -18,16 +18,14 @@ #include "ability_handler.h" #include "configuration.h" +#include "ets_runtime.h" +#include "ets_ui_extension_content_session.h" +#include "ui_extension.h" +#include "ui_extension_context.h" #ifdef SUPPORT_GRAPHICS #include "display_manager.h" #include "window_manager.h" #endif // SUPPORT_GRAPHICS -#include "ui_extension.h" -#include "ui_extension_context.h" -#include -#include -#include "ets_runtime.h" -#include "ets_ui_extension_content_session.h" class ETSNativeReference; @@ -41,7 +39,7 @@ class UIExtensionContext; */ class EtsUIExtension : public UIExtension { public: - explicit EtsUIExtension(ETSRuntime& etsRuntime); + explicit EtsUIExtension(ETSRuntime &etsRuntime); virtual ~EtsUIExtension() override; /** @@ -50,7 +48,7 @@ public: * @param runtime The runtime. * @return The EtsUIExtension instance. */ - static EtsUIExtension* Create(const std::unique_ptr& etsRuntime); + static EtsUIExtension* Create(const std::unique_ptr &etsRuntime); /** * @brief Init the ui extension. @@ -60,7 +58,7 @@ public: * @param handler the ui extension handler. * @param token the remote token. */ - virtual void Init(const std::shared_ptr &record, + void Init(const std::shared_ptr &record, const std::shared_ptr &application, std::shared_ptr &handler, const sptr &token) override; @@ -74,43 +72,9 @@ public: * @param Want Indicates the {@link Want} structure containing startup information about the ui extension. * @param sessionInfo The session info of the ability. */ - virtual void OnStart(const AAFwk::Want &want, sptr sessionInfo) override; + void OnStart(const AAFwk::Want &want, sptr sessionInfo) override; - /** - * @brief Called when this ui extension is connected for the first time. - * - * You can override this function to implement your own processing logic. - * - * @param want Indicates the {@link Want} structure containing connection information about the ui extension. - * @return Returns a pointer to the sid of the connected ui extension. - */ - virtual sptr OnConnect(const AAFwk::Want &want) override; - - /** - * @brief Called when all abilities connected to this ui extension are disconnected. - * - * You can override this function to implement your own processing logic. - * - */ - virtual void OnDisconnect(const AAFwk::Want &want) override; - - /** - * @brief Called back when ui extension is started. - * - * This method can be called only by ui extension. You can use the StartAbility(Want) method to start - * ui extension. Then the system calls back the current method to use the transferred want parameter to - * execute its own logic. - * - * @param want Indicates the want of ui extension to start. - * @param restart Indicates the startup mode. The value true indicates that ui extension is restarted after being - * destroyed, and the value false indicates a normal startup. - * @param startId Indicates the number of times the ui extension has been started. The startId is incremented - * by 1 every time the ui extension is started. For example, if the ui extension has been started for six times, the - * value of startId is 6. - */ - virtual void OnCommand(const AAFwk::Want &want, bool restart, int startId) override; - - virtual void OnCommandWindow(const AAFwk::Want &want, const sptr &sessionInfo, + void OnCommandWindow(const AAFwk::Want &want, const sptr &sessionInfo, AAFwk::WindowCommand winCmd) override; /** @@ -119,19 +83,15 @@ public: * The ui extension in the STATE_STOP is being destroyed. * You can override this function to implement your own processing logic. */ - virtual void OnStop() override; - virtual void OnStop(AppExecFwk::AbilityTransactionCallbackInfo<> *callbackInfo, bool &isAsyncCallback) override; - /** - * @brief The callback of OnStop. - */ - virtual void OnStopCallBack() override; + void OnStop() override; + void OnStop(AppExecFwk::AbilityTransactionCallbackInfo<> *callbackInfo, bool &isAsyncCallback) override; /** * @brief Called when the system configuration is updated. * * @param configuration Indicates the updated configuration information. */ - virtual void OnConfigurationUpdated(const AppExecFwk::Configuration& configuration) override; + void OnConfigurationUpdated(const AppExecFwk::Configuration &configuration) override; /** * @brief Called when this extension enters the STATE_FOREGROUND state. @@ -140,7 +100,7 @@ public: * The extension in the STATE_FOREGROUND state is visible. * You can override this function to implement your own processing logic. */ - virtual void OnForeground(const Want &want, sptr sessionInfo) override; + void OnForeground(const Want &want, sptr sessionInfo) override; /** * @brief Called when this extension enters the STATE_BACKGROUND state. @@ -149,7 +109,7 @@ public: * The extension in the STATE_BACKGROUND state is invisible. * You can override this function to implement your own processing logic. */ - virtual void OnBackground() override; + void OnBackground() override; /** * @brief Called when ui extension need dump info. @@ -157,7 +117,7 @@ public: * @param params The params from ui extension. * @param info The dump info to show. */ - virtual void Dump(const std::vector ¶ms, std::vector &info) override; + void Dump(const std::vector ¶ms, std::vector &info) override; /** * @brief Called when startAbilityForResult(ohos.aafwk.content.Want,int) is called to start an extension ability @@ -179,42 +139,28 @@ public: private: virtual void BindContext(ani_env *env, std::shared_ptr want); ani_object CreateETSContext(ani_env *env, std::shared_ptr context, int32_t screenMode); - - bool CallObjectMethod(bool withResult, const char* name, const char* signature, ...); - - ani_status CallOnDisconnect(const AAFwk::Want &want, bool withResult = false); - - void ForegroundWindow(const AAFwk::Want &want, const sptr &sessionInfo); - void BackgroundWindow(const sptr &sessionInfo); - void DestroyWindow(const sptr &sessionInfo); - - void OnCommandWindowDone(const sptr &sessionInfo, AAFwk::WindowCommand winCmd) override; + bool CallObjectMethod(bool withResult, const char *name, const char *signature, ...); + void DestroyWindow(const sptr &sessionInfo) override; bool ForegroundWindowWithInsightIntent(const AAFwk::Want &want, const sptr &sessionInfo, - bool needForeground); - bool HandleSessionCreate(const AAFwk::Want &want, const sptr &sessionInfo); - void OnInsightIntentExecuteDone(const sptr &sessionInfo, - const AppExecFwk::InsightIntentExecuteResult &result) override; + bool needForeground) override; + bool HandleSessionCreate(const AAFwk::Want &want, const sptr &sessionInfo) override; void PostInsightIntentExecuted(const sptr &sessionInfo, const AppExecFwk::InsightIntentExecuteResult &result, bool needForeground); std::unique_ptr CreateAppWindowStage(sptr uiWindow, sptr sessionInfo); sptr CreateUIWindow(const std::shared_ptr context, const sptr &sessionInfo); - static void PromiseCallback(ani_env* env, ani_object aniObj); + static void PromiseCallback(ani_env *env, ani_object aniObj); + bool IsEmbeddableStart(int32_t screenMode); ETSRuntime& etsRuntime_; std::shared_ptr etsObj_ = nullptr; std::shared_ptr shellContextRef_ = nullptr; - std::mutex uiWindowMutex_; - std::map> uiWindowMap_; - std::set foregroundWindows_; - std::map> contentSessions_; - int32_t screenMode_ = AAFwk::IDLE_SCREEN_MODE; + std::map contentSessions_; std::shared_ptr screenModePtr_; sptr token_ = nullptr; std::shared_ptr handler_ = nullptr; std::shared_ptr abilityResultListeners_ = nullptr; - ani_ref contentSession_ = nullptr; std::shared_ptr etsUiExtContentSession_; #ifdef SUPPORT_GRAPHICS diff --git a/frameworks/ets/ani/ui_extension_ability/include/ets_ui_extension_content_session.h b/frameworks/ets/ani/ui_extension_ability/include/ets_ui_extension_content_session.h index a7828e853b5fe8815f3fd0d910852d7e0a43071e..9e6dabe7320af69e9ac037dee46d60ad4c0848c9 100644 --- a/frameworks/ets/ani/ui_extension_ability/include/ets_ui_extension_content_session.h +++ b/frameworks/ets/ani/ui_extension_ability/include/ets_ui_extension_content_session.h @@ -16,10 +16,10 @@ #ifndef OHOS_ABILITY_RUNTIME_ETS_UI_EXTENSION_CONTENT_SESSION_H #define OHOS_ABILITY_RUNTIME_ETS_UI_EXTENSION_CONTENT_SESSION_H +#include "ets_runtime.h" #include "session_info.h" #include "start_options.h" #include "window.h" -#include "ets_runtime.h" namespace OHOS { namespace AbilityRuntime { @@ -50,7 +50,7 @@ public: virtual void OnAbilityResult(int requestCode, int resultCode, const AAFwk::Want &resultData) {} virtual bool IsMatch(int requestCode) {return true;} void OnAbilityResultInner(int requestCode, int resultCode, const AAFwk::Want &resultData) {} - void SaveResultCallbacks(int requestCode, RuntimeTask&& task) {} + void SaveResultCallbacks(int requestCode, RuntimeTask &&task) {} private: std::map resultCallbacks_; }; @@ -60,43 +60,39 @@ private: class CallbackWrapper; public: EtsUIExtensionContentSession(sptr sessionInfo, - sptr uiWindow, std::weak_ptr& context, - std::shared_ptr& abilityResultListeners); + sptr uiWindow, std::weak_ptr &context, + std::shared_ptr &abilityResultListeners); EtsUIExtensionContentSession(sptr sessionInfo, sptr uiWindow); virtual ~EtsUIExtensionContentSession() = default; - static EtsUIExtensionContentSession* GetEtsContentSession(ani_env* env, ani_object obj); - static ani_object CreateEtsUIExtensionContentSession(ani_env* env, + static EtsUIExtensionContentSession* GetEtsContentSession(ani_env *env, ani_object obj); + static ani_object CreateEtsUIExtensionContentSession(ani_env *env, sptr sessionInfo, sptr uiWindow, std::weak_ptr context, - std::shared_ptr& abilityResultListeners, + std::shared_ptr &abilityResultListeners, std::shared_ptr contentSessionPtr); - static void NativeSendData(ani_env* env, ani_object obj, ani_object data); - static void NativeLoadContent(ani_env* env, ani_object obj, ani_string path, ani_object storage); - static void NativeTerminateSelf(ani_env* env, ani_object obj, ani_object callback); - static void NativeSetWindowBackgroundColor(ani_env* env, ani_object obj, ani_string color); - static int NativeTerminateSelfWithResult(ani_env* env, ani_object obj, + static void NativeSendData(ani_env *env, ani_object obj, ani_object data); + static void NativeLoadContent(ani_env *env, ani_object obj, ani_string path, ani_object storage); + static void NativeTerminateSelf(ani_env *env, ani_object obj, ani_object callback); + static void NativeSetWindowBackgroundColor(ani_env *env, ani_object obj, ani_string color); + static int NativeTerminateSelfWithResult(ani_env *env, ani_object obj, ani_object abilityResult, ani_object callback); - static ani_object NativeSetReceiveDataCallback(ani_env* env, ani_object obj); - static ani_object NativeGetUIExtensionHostWindowProxy(ani_env* env, ani_object obj); + static ani_object NativeSetReceiveDataCallback(ani_env *env, ani_object obj); + static ani_object NativeGetUIExtensionHostWindowProxy(ani_env *env, ani_object obj); - void SendData(ani_env* env, ani_object object, ani_object data); - void LoadContent(ani_env* env, ani_object object, ani_string path, ani_object storage); + void SendData(ani_env *env, ani_object object, ani_object data); + void LoadContent(ani_env *env, ani_object object, ani_string path, ani_object storage); void TerminateSelf(); int32_t TerminateSelfWithResult(); - void SetWindowBackgroundColor(ani_env* env, ani_string color); - ani_object GetUIExtensionHostWindowProxy(ani_env* env, ani_object object); - ani_object SetReceiveDataCallback(ani_env* env, ani_object object); + void SetWindowBackgroundColor(ani_env *env, ani_string color); + ani_object GetUIExtensionHostWindowProxy(ani_env *env, ani_object object); + ani_object SetReceiveDataCallback(ani_env *env, ani_object object); private: sptr sessionInfo_; sptr uiWindow_; std::weak_ptr context_; - std::shared_ptr receiveDataCallback_; - bool isRegistered = false; - std::shared_ptr receiveDataForResultCallback_; - bool isSyncRegistered = false; std::shared_ptr listener_; bool isFirstTriggerBindModal_ = true; }; diff --git a/frameworks/ets/ani/ui_extension_ability/include/ets_ui_extension_context.h b/frameworks/ets/ani/ui_extension_ability/include/ets_ui_extension_context.h index 802402b7b05b4777f377a255a2b09c4ad07c1410..10772d98e845293d0230ab53428ea26c49899d97 100644 --- a/frameworks/ets/ani/ui_extension_ability/include/ets_ui_extension_context.h +++ b/frameworks/ets/ani/ui_extension_ability/include/ets_ui_extension_context.h @@ -15,30 +15,31 @@ #ifndef OHOS_ABILITY_RUNTIME_ETS_UI_EXTENSION_CONTEXT_H #define OHOS_ABILITY_RUNTIME_ETS_UI_EXTENSION_CONTEXT_H -#include "ets_runtime.h" #include #include #include -#include "ui_extension_context.h" + +#include "ets_runtime.h" #include "hilog_tag_wrapper.h" #include "hitrace_meter.h" #include "ohos_application.h" +#include "ui_extension_context.h" ani_object CreateEtsUIExtensionContext(ani_env *env, std::shared_ptr context); class EtsUIExtensionContext final { public: - explicit EtsUIExtensionContext(const std::shared_ptr& context) + explicit EtsUIExtensionContext(const std::shared_ptr &context) : context_(context) {} virtual ~EtsUIExtensionContext() = default; static void TerminateSelfSync(ani_env *env, ani_object obj, ani_object callback); static void TerminateSelfWithResultSync(ani_env *env, ani_object obj, ani_object abilityResult, ani_object callback); - static void EtsCreatExtensionContext(ani_env* aniEnv, ani_class contextClass, ani_object contextObj, + static void EtsCreatExtensionContext(ani_env *aniEnv, ani_class contextClass, ani_object contextObj, std::shared_ptr context); private: - static void BindExtensionInfo(ani_env* aniEnv, ani_class contextClass, ani_object contextObj, + static void BindExtensionInfo(ani_env *aniEnv, ani_class contextClass, ani_object contextObj, std::shared_ptr context, std::shared_ptr abilityInfo); protected: diff --git a/frameworks/ets/ani/ui_extension_ability/src/ets_ui_extension.cpp b/frameworks/ets/ani/ui_extension_ability/src/ets_ui_extension.cpp index 9be157d10695b7ea2dc3a834d21889f5f738aa94..e05fe22d01713061a6cca342beb023f9c3475105 100644 --- a/frameworks/ets/ani/ui_extension_ability/src/ets_ui_extension.cpp +++ b/frameworks/ets/ani/ui_extension_ability/src/ets_ui_extension.cpp @@ -12,33 +12,33 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - #include "ets_ui_extension.h" + #include "ability_context.h" #include "ability_delegator_registry.h" #include "ability_info.h" #include "ability_manager_client.h" #include "ability_start_setting.h" +#include "ani_common_want.h" #include "configuration_utils.h" #include "connection_manager.h" #include "context.h" +#include "ets_data_struct_converter.h" +#include "ets_runtime.h" +#include "ets_ui_extension_context.h" #include "hitrace_meter.h" #include "hilog_tag_wrapper.h" #include "insight_intent_executor_info.h" #include "insight_intent_executor_mgr.h" #include "int_wrapper.h" -#include "ets_runtime.h" -#include "ani_common_want.h" #include "ui_extension_window_command.h" #include "want_params_wrapper.h" -#include "ets_data_struct_converter.h" -#include "ets_ui_extension_context.h" namespace OHOS { namespace AbilityRuntime { using namespace OHOS::AppExecFwk; -EtsUIExtension* EtsUIExtension::Create(const std::unique_ptr& runtime) +EtsUIExtension *EtsUIExtension::Create(const std::unique_ptr &runtime) { return new (std::nothrow) EtsUIExtension(static_cast(*runtime)); } @@ -56,7 +56,7 @@ EtsUIExtension::~EtsUIExtension() contentSessions_.clear(); } -void EtsUIExtension::PromiseCallback(ani_env* env, ani_object aniObj) +void EtsUIExtension::PromiseCallback(ani_env *env, ani_object aniObj) { if (env == nullptr || aniObj == nullptr) { TAG_LOGE(AAFwkTag::UI_EXT, "null env or null aniObj"); @@ -136,14 +136,14 @@ void EtsUIExtension::Init(const std::shared_ptr &record, RegisterDisplayInfoChangedListener(); } -ani_object EtsUIExtension::CreateETSContext(ani_env* env, - std::shared_ptr context, int32_t screenMode) +ani_object EtsUIExtension::CreateETSContext( + ani_env *env, std::shared_ptr context, int32_t screenMode) { ani_object obj = CreateEtsUIExtensionContext(env, context); return obj; } -void EtsUIExtension::BindContext(ani_env*env, std::shared_ptr want) +void EtsUIExtension::BindContext(ani_env *env, std::shared_ptr want) { if (env == nullptr || want == nullptr) { TAG_LOGE(AAFwkTag::UI_EXT, "Want info is null or env is null"); @@ -163,7 +163,7 @@ void EtsUIExtension::BindContext(ani_env*env, std::shared_ptr want) return; } - ani_field contextField; + ani_field contextField = nullptr; auto status = env->Class_FindField(etsObj_->aniCls, "context", &contextField); if (status != ANI_OK) { TAG_LOGE(AAFwkTag::ETSRUNTIME, "status: %{public}d", status); @@ -184,8 +184,8 @@ void EtsUIExtension::BindContext(ani_env*env, std::shared_ptr want) void EtsUIExtension::OnStart(const AAFwk::Want &want, sptr sessionInfo) { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); - auto context = GetContext(); #ifdef SUPPORT_GRAPHICS + auto context = GetContext(); if (context != nullptr && sessionInfo != nullptr) { auto configUtils = std::make_shared(); configUtils->InitDisplayConfig(context->GetConfiguration(), context->GetResourceManager(), @@ -210,17 +210,33 @@ void EtsUIExtension::OnStart(const AAFwk::Want &want, sptr s TAG_LOGE(AAFwkTag::UI_EXT, "WrapLaunchParam failed"); return; } - CallObjectMethod(false, "onCreate", signature, launchParamObj); + int32_t screenMode = want.GetIntParam(AAFwk::SCREEN_MODE_KEY, AAFwk::IDLE_SCREEN_MODE); + if (!IsEmbeddableStart(screenMode)) { + CallObjectMethod(false, "onCreate", signature, launchParamObj); + } } void EtsUIExtension::OnStop() { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); + UIExtension::OnStop(); + TAG_LOGD(AAFwkTag::UI_EXT, "begin"); + auto context = GetContext(); + if (context) { + TAG_LOGD(AAFwkTag::UI_EXT, "set terminating true"); + context->SetTerminating(true); + } + AbilityRuntime::ApplicationConfigurationManager::GetInstance().DeleteIgnoreContext(GetContext()); + TAG_LOGD(AAFwkTag::UI_EXT, "GetIgnoreContext size %{public}zu", + AbilityRuntime::ApplicationConfigurationManager::GetInstance().GetIgnoreContext().size()); + CallObjectMethod(false, "onDestroy", nullptr); + #ifdef SUPPORT_GRAPHICS UnregisterDisplayInfoChangedListener(); #endif // SUPPORT_GRAPHICS OnStopCallBack(); + TAG_LOGD(AAFwkTag::UI_EXT, "end"); } void EtsUIExtension::OnStop(AppExecFwk::AbilityTransactionCallbackInfo<> *callbackInfo, bool &isAsyncCallback) @@ -269,37 +285,6 @@ void EtsUIExtension::OnStop(AppExecFwk::AbilityTransactionCallbackInfo<> *callba } } -void EtsUIExtension::OnStopCallBack() -{ - auto context = GetContext(); - if (context == nullptr) { - TAG_LOGE(AAFwkTag::UI_EXT, "context null"); - return; - } - bool ret = ConnectionManager::GetInstance().DisconnectCaller(context->GetToken()); - if (ret) { - ConnectionManager::GetInstance().ReportConnectionLeakEvent(getpid(), gettid()); - } -} - -sptr EtsUIExtension::OnConnect(const AAFwk::Want &want) -{ - sptr remoteObj = nullptr; - return remoteObj; -} - -void EtsUIExtension::OnDisconnect(const AAFwk::Want &want) -{ - HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); - Extension::OnDisconnect(want); -} - -ani_status EtsUIExtension::CallOnDisconnect(const AAFwk::Want &want, bool withResult) -{ - TAG_LOGD(AAFwkTag::UI_EXT, "called"); - return ANI_OK; -} - void EtsUIExtension::OnCommandWindow(const AAFwk::Want &want, const sptr &sessionInfo, AAFwk::WindowCommand winCmd) { @@ -369,7 +354,6 @@ bool EtsUIExtension::ForegroundWindowWithInsightIntent(const AAFwk::Want &want, executorInfo.windowMode = abilityInfo->compileMode == AppExecFwk::CompileMode::ES_MODULE; } executorInfo.token = context->GetToken(); - executorInfo.pageLoader = contentSessions_[sessionInfo->uiExtensionComponentId]; executorInfo.executeParam = std::make_shared(); InsightIntentExecuteParam::GenerateFromWant(want, *executorInfo.executeParam); executorInfo.executeParam->executeMode_ = UI_EXTENSION_ABILITY; @@ -399,69 +383,6 @@ void EtsUIExtension::PostInsightIntentExecuted(const sptr &s } } -void EtsUIExtension::OnCommandWindowDone(const sptr &sessionInfo, AAFwk::WindowCommand winCmd) -{ - HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); - auto context = GetContext(); - if (context == nullptr) { - TAG_LOGE(AAFwkTag::UI_EXT, "context null"); - return; - } - AAFwk::AbilityCommand abilityCmd; - std::lock_guard lock(uiWindowMutex_); - if (uiWindowMap_.empty()) { - abilityCmd = AAFwk::ABILITY_CMD_DESTROY; - } else if (foregroundWindows_.empty()) { - abilityCmd = AAFwk::ABILITY_CMD_BACKGROUND; - } else { - abilityCmd = AAFwk::ABILITY_CMD_FOREGROUND; - } - AAFwk::AbilityManagerClient::GetInstance()->ScheduleCommandAbilityWindowDone( - context->GetToken(), sessionInfo, winCmd, abilityCmd); -} - -void EtsUIExtension::OnInsightIntentExecuteDone(const sptr &sessionInfo, - const AppExecFwk::InsightIntentExecuteResult &result) -{ - HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); - if (sessionInfo == nullptr) { - TAG_LOGE(AAFwkTag::UI_EXT, "sessionInfo null"); - return; - } - std::lock_guard lock(uiWindowMutex_); - auto componentId = sessionInfo->uiExtensionComponentId; - auto res = uiWindowMap_.find(componentId); - if (res != uiWindowMap_.end() && res->second != nullptr) { - WantParams params; - params.SetParam(INSIGHT_INTENT_EXECUTE_RESULT_CODE, Integer::Box(result.innerErr)); - WantParams resultParams; - resultParams.SetParam("code", Integer::Box(result.code)); - if (result.result != nullptr) { - sptr pWantParams = WantParamWrapper::Box(*result.result); - if (pWantParams != nullptr) { - resultParams.SetParam("result", pWantParams); - } - } - sptr pWantParams = WantParamWrapper::Box(resultParams); - if (pWantParams != nullptr) { - params.SetParam(INSIGHT_INTENT_EXECUTE_RESULT, pWantParams); - } - - Rosen::WMError ret = res->second->TransferExtensionData(params); - if (ret != Rosen::WMError::WM_OK) { - TAG_LOGE(AAFwkTag::UI_EXT, "TransferExtensionData failed, ret=%{public}d", ret); - } - - res->second->Show(); - foregroundWindows_.emplace(componentId); - } -} - -void EtsUIExtension::OnCommand(const AAFwk::Want &want, bool restart, int startId) -{ - TAG_LOGD(AAFwkTag::UI_EXT, "called"); -} - void EtsUIExtension::OnForeground(const Want &want, sptr sessionInfo) { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); @@ -485,6 +406,12 @@ void EtsUIExtension::OnBackground() CallObjectMethod(false, "onBackground", nullptr); } +bool EtsUIExtension::IsEmbeddableStart(int32_t screenMode) +{ + return screenMode == AAFwk::EMBEDDED_FULL_SCREEN_MODE || + screenMode == AAFwk::EMBEDDED_HALF_SCREEN_MODE; +} + bool EtsUIExtension::HandleSessionCreate(const AAFwk::Want &want, const sptr &sessionInfo) { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); @@ -493,6 +420,7 @@ bool EtsUIExtension::HandleSessionCreate(const AAFwk::Want &want, const sptr lock(uiWindowMutex_); + std::shared_ptr sharedWant = std::make_shared(want); auto compId = sessionInfo->uiExtensionComponentId; if (uiWindowMap_.find(compId) == uiWindowMap_.end()) { auto context = GetContext(); @@ -501,6 +429,7 @@ bool EtsUIExtension::HandleSessionCreate(const AAFwk::Want &want, const sptrUpdateExtensionConfig(sharedWant); auto env = etsRuntime_.GetAniEnv(); ani_ref wantObj = OHOS::AppExecFwk::WrapWant(env, want); if (wantObj == nullptr) { @@ -511,24 +440,21 @@ bool EtsUIExtension::HandleSessionCreate(const AAFwk::Want &want, const sptrGlobalReference_Create(wantObj, &wantRef)) != ANI_OK) { TAG_LOGE(AAFwkTag::UI_EXT, "status: %{public}d", status); + return false; } std::weak_ptr wkctx = context; etsUiExtContentSession_ = std::make_shared(sessionInfo, uiWindow, wkctx, abilityResultListeners_); ani_object sessonObj = EtsUIExtensionContentSession::CreateEtsUIExtensionContentSession(env, sessionInfo, uiWindow, context, abilityResultListeners_, etsUiExtContentSession_); - if ((status = env->GlobalReference_Create(sessonObj, &contentSession_)) != ANI_OK) { + ani_ref sessonObjRef = nullptr; + if ((status = env->GlobalReference_Create(sessonObj, &sessonObjRef)) != ANI_OK) { TAG_LOGE(AAFwkTag::UI_EXT, "status: %{public}d", status); + return false; } + contentSessions_.emplace(compId, sessonObjRef); int32_t screenMode = want.GetIntParam(AAFwk::SCREEN_MODE_KEY, AAFwk::IDLE_SCREEN_MODE); - if (screenMode == AAFwk::EMBEDDED_FULL_SCREEN_MODE) { - screenMode_ = AAFwk::EMBEDDED_FULL_SCREEN_MODE; - auto jsAppWindowStage = CreateAppWindowStage(uiWindow, sessionInfo); - if (jsAppWindowStage == nullptr) { - TAG_LOGE(AAFwkTag::UI_EXT, "JsAppWindowStage is nullptr"); - return false; - } - } else { + if (!IsEmbeddableStart(screenMode)) { CallObjectMethod(false, "onSessionCreate", nullptr, wantObj, sessonObj); } uiWindowMap_[compId] = uiWindow; @@ -537,6 +463,13 @@ bool EtsUIExtension::HandleSessionCreate(const AAFwk::Want &want, const sptrSetWindow(uiWindow); } #endif // SUPPORT_GRAPHICS + } else { + auto uiWindow = uiWindowMap_[compId]; + if (uiWindow == nullptr) { + TAG_LOGE(AAFwkTag::UI_EXT, "null uiWindow"); + return false; + } + uiWindow->UpdateExtensionConfig(sharedWant); } return true; } @@ -571,44 +504,6 @@ std::unique_ptr EtsUIExtension::CreateAppWindowStage(sptr(); } -void EtsUIExtension::ForegroundWindow(const AAFwk::Want &want, const sptr &sessionInfo) -{ - TAG_LOGD(AAFwkTag::UI_EXT, "called"); - HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); - if (!HandleSessionCreate(want, sessionInfo)) { - TAG_LOGE(AAFwkTag::UI_EXT, "HandleSessionCreate failed"); - return; - } - std::lock_guard lock(uiWindowMutex_); - auto componentId = sessionInfo->uiExtensionComponentId; - auto& uiWindow = uiWindowMap_[componentId]; - if (uiWindow) { - HITRACE_METER_NAME(HITRACE_TAG_APP, "Rosen::Window::show"); - uiWindow->Show(); - foregroundWindows_.emplace(componentId); - } -} - -void EtsUIExtension::BackgroundWindow(const sptr &sessionInfo) -{ - HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); - if (sessionInfo == nullptr) { - TAG_LOGE(AAFwkTag::UI_EXT, "Invalid sessionInfo"); - return; - } - std::lock_guard lock(uiWindowMutex_); - auto componentId = sessionInfo->uiExtensionComponentId; - if (uiWindowMap_.find(componentId) == uiWindowMap_.end()) { - TAG_LOGE(AAFwkTag::UI_EXT, "Fail to find uiWindow"); - return; - } - auto& uiWindow = uiWindowMap_[componentId]; - if (uiWindow) { - uiWindow->Hide(); - foregroundWindows_.erase(componentId); - } -} - void EtsUIExtension::DestroyWindow(const sptr &sessionInfo) { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); @@ -622,10 +517,12 @@ void EtsUIExtension::DestroyWindow(const sptr &sessionInfo) TAG_LOGE(AAFwkTag::UI_EXT, "Wrong to find uiWindow"); return; } - ani_object contenSessionObj = static_cast(contentSession_); - if (contenSessionObj == nullptr) { - TAG_LOGE(AAFwkTag::UI_EXT, "contenSessionObj null ptr"); - } else { + if (contentSessions_.find(componentId) != contentSessions_.end() && contentSessions_[componentId] != nullptr) { + ani_object contenSessionObj = reinterpret_cast(contentSessions_[componentId]); + if (contenSessionObj == nullptr) { + TAG_LOGE(AAFwkTag::UI_EXT, "contenSessionObj null ptr"); + return; + } CallObjectMethod(false, "onSessionDestroy", nullptr, contenSessionObj); } auto uiWindow = uiWindowMap_[componentId]; @@ -688,7 +585,7 @@ bool EtsUIExtension::CallObjectMethod(bool withResult, const char *name, const c return false; } -void EtsUIExtension::OnConfigurationUpdated(const AppExecFwk::Configuration& configuration) +void EtsUIExtension::OnConfigurationUpdated(const AppExecFwk::Configuration &configuration) { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); Extension::OnConfigurationUpdated(configuration); diff --git a/frameworks/ets/ani/ui_extension_ability/src/ets_ui_extension_content_session.cpp b/frameworks/ets/ani/ui_extension_ability/src/ets_ui_extension_content_session.cpp index 140521d91f5073a6173bb03174af775871bd1506..6167c4018b5717d499dd27d307b469a8769f773c 100644 --- a/frameworks/ets/ani/ui_extension_ability/src/ets_ui_extension_content_session.cpp +++ b/frameworks/ets/ani/ui_extension_ability/src/ets_ui_extension_content_session.cpp @@ -12,33 +12,34 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include #include "ets_ui_extension_content_session.h" -#include "ets_ui_extension_context.h" -#include "hilog_tag_wrapper.h" -#ifdef SUPPORT_SCREEN -#include "ui_content.h" -#endif // SUPPORT_SCREEN -#include "want.h" -#include "window.h" -#include "ability_manager_client.h" -#include "ani_common_want.h" +#include + +#include "ability_manager_client.h" #include "ani_common_util.h" +#include "ani_common_want.h" #include "ani_extension_window.h" +#include "ets_error_utils.h" +#include "ets_ui_extension_context.h" #include "hilog_tag_wrapper.h" #include "ipc_skeleton.h" #include "remote_object_wrapper.h" #include "tokenid_kit.h" +#include "want.h" #include "want_params_wrapper.h" -#include "ets_error_utils.h" +#include "window.h" +#ifdef SUPPORT_SCREEN +#include "ui_content.h" +#endif // SUPPORT_SCREEN + namespace OHOS { namespace AbilityRuntime { const char* UI_EXTENSION_CONTENT_SESSION_CLASS_NAME = "L@ohos/app/ability/UIExtensionContentSession/UIExtensionContentSession;"; -EtsUIExtensionContentSession* EtsUIExtensionContentSession::GetEtsContentSession(ani_env* env, ani_object obj) +EtsUIExtensionContentSession* EtsUIExtensionContentSession::GetEtsContentSession(ani_env *env, ani_object obj) { if (env == nullptr) { TAG_LOGE(AAFwkTag::UI_EXT, "null env"); @@ -75,7 +76,7 @@ EtsUIExtensionContentSession* EtsUIExtensionContentSession::GetEtsContentSession return etsContentSession; } -ani_object EtsUIExtensionContentSession::NativeSetReceiveDataCallback(ani_env* env, ani_object obj) +ani_object EtsUIExtensionContentSession::NativeSetReceiveDataCallback(ani_env *env, ani_object obj) { auto etsContentSession = EtsUIExtensionContentSession::GetEtsContentSession(env, obj); ani_object object = nullptr; @@ -85,7 +86,7 @@ ani_object EtsUIExtensionContentSession::NativeSetReceiveDataCallback(ani_env* e return object; } -void EtsUIExtensionContentSession::NativeSendData(ani_env* env, ani_object obj, ani_object data) +void EtsUIExtensionContentSession::NativeSendData(ani_env *env, ani_object obj, ani_object data) { auto etsContentSession =EtsUIExtensionContentSession::GetEtsContentSession(env, obj); if (etsContentSession != nullptr) { @@ -93,7 +94,7 @@ void EtsUIExtensionContentSession::NativeSendData(ani_env* env, ani_object obj, } } -void EtsUIExtensionContentSession::NativeLoadContent(ani_env* env, ani_object obj, ani_string path, ani_object storage) +void EtsUIExtensionContentSession::NativeLoadContent(ani_env *env, ani_object obj, ani_string path, ani_object storage) { auto etsContentSession = EtsUIExtensionContentSession::GetEtsContentSession(env, obj); if (etsContentSession != nullptr) { @@ -101,7 +102,7 @@ void EtsUIExtensionContentSession::NativeLoadContent(ani_env* env, ani_object ob } } -void EtsUIExtensionContentSession::NativeTerminateSelf(ani_env* env, ani_object obj, ani_object callback) +void EtsUIExtensionContentSession::NativeTerminateSelf(ani_env *env, ani_object obj, ani_object callback) { auto etsContentSession = EtsUIExtensionContentSession::GetEtsContentSession(env, obj); if (etsContentSession != nullptr) { @@ -111,7 +112,7 @@ void EtsUIExtensionContentSession::NativeTerminateSelf(ani_env* env, ani_object } } -int EtsUIExtensionContentSession::NativeTerminateSelfWithResult(ani_env* env, ani_object obj, +int EtsUIExtensionContentSession::NativeTerminateSelfWithResult(ani_env *env, ani_object obj, ani_object abilityResult, ani_object callback) { TAG_LOGD(AAFwkTag::UI_EXT, "NativeTerminateSelfWithResult called"); @@ -125,7 +126,7 @@ int EtsUIExtensionContentSession::NativeTerminateSelfWithResult(ani_env* env, an return ret; } -void EtsUIExtensionContentSession::NativeSetWindowBackgroundColor(ani_env* env, ani_object obj, ani_string color) +void EtsUIExtensionContentSession::NativeSetWindowBackgroundColor(ani_env *env, ani_object obj, ani_string color) { auto etsContentSession = EtsUIExtensionContentSession::GetEtsContentSession(env, obj); if (etsContentSession != nullptr) { @@ -133,7 +134,7 @@ void EtsUIExtensionContentSession::NativeSetWindowBackgroundColor(ani_env* env, } } -ani_object EtsUIExtensionContentSession::NativeGetUIExtensionHostWindowProxy(ani_env* env, ani_object obj) +ani_object EtsUIExtensionContentSession::NativeGetUIExtensionHostWindowProxy(ani_env *env, ani_object obj) { auto etsContentSession = EtsUIExtensionContentSession::GetEtsContentSession(env, obj); ani_object object = nullptr; @@ -162,10 +163,10 @@ EtsUIExtensionContentSession::EtsUIExtensionContentSession(sptr sessionInfo, sptr uiWindow, std::weak_ptr context, - std::shared_ptr& abilityResultListeners, + std::shared_ptr &abilityResultListeners, std::shared_ptr contentSessionPtr) { ani_object object = nullptr; @@ -221,7 +222,7 @@ ani_object EtsUIExtensionContentSession::CreateEtsUIExtensionContentSession(ani_ return object; } -void EtsUIExtensionContentSession::SendData(ani_env* env, ani_object object, ani_object data) +void EtsUIExtensionContentSession::SendData(ani_env *env, ani_object object, ani_object data) { TAG_LOGD(AAFwkTag::UI_EXT, "called"); AAFwk::WantParams params; @@ -242,7 +243,7 @@ void EtsUIExtensionContentSession::SendData(ani_env* env, ani_object object, ani } } -void EtsUIExtensionContentSession::LoadContent(ani_env* env, ani_object object, ani_string path, ani_object storage) +void EtsUIExtensionContentSession::LoadContent(ani_env *env, ani_object object, ani_string path, ani_object storage) { TAG_LOGD(AAFwkTag::UI_EXT, "called"); std::string contextPath; @@ -283,7 +284,7 @@ int32_t EtsUIExtensionContentSession::TerminateSelfWithResult() return AAFwk::AbilityManagerClient::GetInstance()->TerminateUIExtensionAbility(sessionInfo_); } -void EtsUIExtensionContentSession::SetWindowBackgroundColor(ani_env* env, ani_string color) +void EtsUIExtensionContentSession::SetWindowBackgroundColor(ani_env *env, ani_string color) { TAG_LOGD(AAFwkTag::UI_EXT, "SetWindowBackgroundColor call"); std::string strColor; @@ -303,7 +304,7 @@ void EtsUIExtensionContentSession::SetWindowBackgroundColor(ani_env* env, ani_st } } -ani_object EtsUIExtensionContentSession::GetUIExtensionHostWindowProxy(ani_env* env, ani_object object) +ani_object EtsUIExtensionContentSession::GetUIExtensionHostWindowProxy(ani_env *env, ani_object object) { TAG_LOGD(AAFwkTag::UI_EXT, "called"); if (sessionInfo_ == nullptr) { @@ -326,7 +327,7 @@ ani_object EtsUIExtensionContentSession::GetUIExtensionHostWindowProxy(ani_env* return reinterpret_cast(resultRef); } -ani_object EtsUIExtensionContentSession::SetReceiveDataCallback(ani_env* env, ani_object object) +ani_object EtsUIExtensionContentSession::SetReceiveDataCallback(ani_env *env, ani_object object) { TAG_LOGD(AAFwkTag::UI_EXT, "called"); return nullptr; diff --git a/frameworks/ets/ani/ui_extension_ability/src/ets_ui_extension_context.cpp b/frameworks/ets/ani/ui_extension_ability/src/ets_ui_extension_context.cpp index 7ac532facae43403ccd99f73758dccecc5b54064..f899fa928b617f770c40298db9128240a4ec9975 100644 --- a/frameworks/ets/ani/ui_extension_ability/src/ets_ui_extension_context.cpp +++ b/frameworks/ets/ani/ui_extension_ability/src/ets_ui_extension_context.cpp @@ -12,13 +12,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "common_fun_ani.h" #include "ets_ui_extension_context.h" -#include "ui_extension_context.h" -#include "ani_common_want.h" + #include "ability_manager_client.h" +#include "ani_common_want.h" +#include "common_fun_ani.h" #include "ets_context_utils.h" #include "ets_error_utils.h" +#include "ui_extension_context.h" const char *INVOKE_METHOD_NAME = "invoke"; const char *UI_EXTENSION_CONTEXT_CLASS_NAME = "Lapplication/UIExtensionContext/UIExtensionContext;"; @@ -89,7 +90,7 @@ void EtsUIExtensionContext::TerminateSelfWithResultSync(ani_env *env, ani_objec OHOS::AbilityRuntime::CreateEtsErrorByNativeErr(env, static_cast(ret)), nullptr); } -void EtsUIExtensionContext::BindExtensionInfo(ani_env* aniEnv, ani_class contextClass, ani_object contextObj, +void EtsUIExtensionContext::BindExtensionInfo(ani_env *aniEnv, ani_class contextClass, ani_object contextObj, std::shared_ptr context, std::shared_ptr abilityInfo) { TAG_LOGD(AAFwkTag::UI_EXT, "called"); @@ -122,7 +123,7 @@ void EtsUIExtensionContext::BindExtensionInfo(ani_env* aniEnv, ani_class context } } -void EtsUIExtensionContext::EtsCreatExtensionContext(ani_env* aniEnv, ani_class contextClass, ani_object contextObj, +void EtsUIExtensionContext::EtsCreatExtensionContext(ani_env *aniEnv, ani_class contextClass, ani_object contextObj, std::shared_ptr context) { OHOS::AbilityRuntime::ContextUtil::CreateEtsBaseContext(aniEnv, contextClass, contextObj, context); diff --git a/frameworks/native/ability/native/ui_extension_ability/js_ui_extension.cpp b/frameworks/native/ability/native/ui_extension_ability/js_ui_extension.cpp index 6071ca92bfd750e6a87b86e67fb60f1f6539a24b..e45b8daa2c6b61bc32d4707936efebce2026b119 100755 --- a/frameworks/native/ability/native/ui_extension_ability/js_ui_extension.cpp +++ b/frameworks/native/ability/native/ui_extension_ability/js_ui_extension.cpp @@ -405,16 +405,7 @@ void JsUIExtension::OnStop(AppExecFwk::AbilityTransactionCallbackInfo<> *callbac void JsUIExtension::OnStopCallBack() { - auto context = GetContext(); - if (context == nullptr) { - TAG_LOGE(AAFwkTag::UI_EXT, "null context"); - return; - } - bool ret = ConnectionManager::GetInstance().DisconnectCaller(context->GetToken()); - if (ret) { - ConnectionManager::GetInstance().ReportConnectionLeakEvent(getpid(), gettid()); - TAG_LOGD(AAFwkTag::UI_EXT, "The service connection is not disconnected"); - } + UIExtension::OnStopCallBack(); auto applicationContext = Context::GetApplicationContext(); if (applicationContext != nullptr) { @@ -506,39 +497,6 @@ void JsUIExtension::OnDisconnect(const AAFwk::Want &want) TAG_LOGD(AAFwkTag::UI_EXT, "JsUIExtension OnDisconnect end"); } -void JsUIExtension::OnCommandWindow(const AAFwk::Want &want, const sptr &sessionInfo, - AAFwk::WindowCommand winCmd) -{ - HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); - if (sessionInfo == nullptr) { - TAG_LOGE(AAFwkTag::UI_EXT, "null sessionInfo"); - return; - } - TAG_LOGD(AAFwkTag::UI_EXT, "begin. persistentId: %{private}d, winCmd: %{public}d", - sessionInfo->persistentId, winCmd); - Extension::OnCommandWindow(want, sessionInfo, winCmd); - if (InsightIntentExecuteParam::IsInsightIntentExecute(want) && winCmd == AAFwk::WIN_CMD_FOREGROUND) { - if (ForegroundWindowWithInsightIntent(want, sessionInfo, false)) { - return; - } - } - switch (winCmd) { - case AAFwk::WIN_CMD_FOREGROUND: - ForegroundWindow(want, sessionInfo); - break; - case AAFwk::WIN_CMD_BACKGROUND: - BackgroundWindow(sessionInfo); - break; - case AAFwk::WIN_CMD_DESTROY: - DestroyWindow(sessionInfo); - break; - default: - TAG_LOGD(AAFwkTag::UI_EXT, "unsupported cmd"); - break; - } - OnCommandWindowDone(sessionInfo, winCmd); -} - bool JsUIExtension::ForegroundWindowInitInsightIntentExecutorInfo(const AAFwk::Want &want, const sptr &sessionInfo, InsightIntentExecutorInfo &executorInfo) { @@ -650,85 +608,9 @@ void JsUIExtension::PostInsightIntentExecuted(const sptr &se } } -void JsUIExtension::OnCommandWindowDone(const sptr &sessionInfo, AAFwk::WindowCommand winCmd) -{ - HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); - TAG_LOGD(AAFwkTag::UI_EXT, "called"); - auto context = GetContext(); - if (context == nullptr) { - TAG_LOGE(AAFwkTag::UI_EXT, "null context"); - return; - } - AAFwk::AbilityCommand abilityCmd; - std::lock_guard lock(uiWindowMutex_); - if (uiWindowMap_.empty()) { - abilityCmd = AAFwk::ABILITY_CMD_DESTROY; - } else if (foregroundWindows_.empty()) { - abilityCmd = AAFwk::ABILITY_CMD_BACKGROUND; - } else { - abilityCmd = AAFwk::ABILITY_CMD_FOREGROUND; - } - AAFwk::AbilityManagerClient::GetInstance()->ScheduleCommandAbilityWindowDone( - context->GetToken(), sessionInfo, winCmd, abilityCmd); - TAG_LOGD(AAFwkTag::UI_EXT, "end"); -} - -void JsUIExtension::OnInsightIntentExecuteDone(const sptr &sessionInfo, - const AppExecFwk::InsightIntentExecuteResult &result) -{ - HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); - if (sessionInfo == nullptr) { - TAG_LOGE(AAFwkTag::UI_EXT, "Invalid sessionInfo"); - return; - } - std::lock_guard lock(uiWindowMutex_); - TAG_LOGD(AAFwkTag::UI_EXT, "UIExtension component id: %{public}" PRId64, sessionInfo->uiExtensionComponentId); - auto componentId = sessionInfo->uiExtensionComponentId; - auto res = uiWindowMap_.find(componentId); - if (res != uiWindowMap_.end() && res->second != nullptr) { - WantParams params; - params.SetParam(INSIGHT_INTENT_EXECUTE_RESULT_CODE, Integer::Box(result.innerErr)); - WantParams resultParams; - resultParams.SetParam("code", Integer::Box(result.code)); - if (result.result != nullptr) { - sptr pWantParams = WantParamWrapper::Box(*result.result); - if (pWantParams != nullptr) { - resultParams.SetParam("result", pWantParams); - } - } - - auto size = result.uris.size(); - sptr uriArray = new (std::nothrow) Array(size, g_IID_IString); - if (uriArray == nullptr) { - TAG_LOGE(AAFwkTag::UI_EXT, "new uriArray failed"); - return; - } - for (std::size_t i = 0; i < size; i++) { - uriArray->Set(i, String::Box(result.uris[i])); - } - resultParams.SetParam("uris", uriArray); - resultParams.SetParam("flags", Integer::Box(result.flags)); - sptr pWantParams = WantParamWrapper::Box(resultParams); - if (pWantParams != nullptr) { - params.SetParam(INSIGHT_INTENT_EXECUTE_RESULT, pWantParams); - } - - Rosen::WMError ret = res->second->TransferExtensionData(params); - if (ret == Rosen::WMError::WM_OK) { - TAG_LOGD(AAFwkTag::UI_EXT, "TransferExtensionData success"); - } else { - TAG_LOGE(AAFwkTag::UI_EXT, "TransferExtensionData failed, ret=%{public}d", ret); - } - - res->second->Show(); - foregroundWindows_.emplace(componentId); - } - TAG_LOGD(AAFwkTag::UI_EXT, "end"); -} - void JsUIExtension::OnCommand(const AAFwk::Want &want, bool restart, int startId) { - Extension::OnCommand(want, restart, startId); + UIExtension::OnCommand(want, restart, startId); TAG_LOGD(AAFwkTag::UI_EXT, "restart=%{public}s, startId=%{public}d", restart ? "true" : "false", startId); // wrap want @@ -876,49 +758,6 @@ std::unique_ptr JsUIExtension::CreateAppWindowStage(sptr &sessionInfo) -{ - HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); - if (!HandleSessionCreate(want, sessionInfo)) { - TAG_LOGE(AAFwkTag::UI_EXT, "HandleSessionCreate failed"); - return; - } - std::lock_guard lock(uiWindowMutex_); - TAG_LOGI(AAFwkTag::UI_EXT, "Before window show UIExtcomponent id: %{public}" PRId64, - sessionInfo->uiExtensionComponentId); - auto componentId = sessionInfo->uiExtensionComponentId; - auto& uiWindow = uiWindowMap_[componentId]; - if (uiWindow) { - HITRACE_METER_NAME(HITRACE_TAG_APP, "Rosen::Window::show"); - uiWindow->Show(); - foregroundWindows_.emplace(componentId); - } - TAG_LOGD(AAFwkTag::UI_EXT, "end"); -} - -void JsUIExtension::BackgroundWindow(const sptr &sessionInfo) -{ - HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); - if (sessionInfo == nullptr) { - TAG_LOGE(AAFwkTag::UI_EXT, "Invalid sessionInfo"); - return; - } - std::lock_guard lock(uiWindowMutex_); - auto componentId = sessionInfo->uiExtensionComponentId; - if (uiWindowMap_.find(componentId) == uiWindowMap_.end()) { - TAG_LOGE(AAFwkTag::UI_EXT, "find uiWindow failed"); - return; - } - auto& uiWindow = uiWindowMap_[componentId]; - TAG_LOGI(AAFwkTag::UI_EXT, "Befor window hide UIExtcomponent id: %{public}" PRId64, - sessionInfo->uiExtensionComponentId); - if (uiWindow) { - uiWindow->Hide(); - foregroundWindows_.erase(componentId); - } - TAG_LOGD(AAFwkTag::UI_EXT, "end"); -} - void JsUIExtension::DestroyWindow(const sptr &sessionInfo) { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); diff --git a/frameworks/native/ability/native/ui_extension_ability/ui_extension.cpp b/frameworks/native/ability/native/ui_extension_ability/ui_extension.cpp index 89cbb5e312e9b5bf45730ef4d651c197960281ba..3ee3b06b27d973935be084586fd776384e6e220f 100755 --- a/frameworks/native/ability/native/ui_extension_ability/ui_extension.cpp +++ b/frameworks/native/ability/native/ui_extension_ability/ui_extension.cpp @@ -12,14 +12,20 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - #include "ui_extension.h" +#include "ability_manager_client.h" +#include "array_wrapper.h" +#include "connection_manager.h" #include "ets_ui_extension.h" #include "hilog_tag_wrapper.h" +#include "hitrace_meter.h" +#include "int_wrapper.h" #include "js_ui_extension.h" #include "runtime.h" +#include "string_wrapper.h" #include "ui_extension_context.h" +#include "want_params_wrapper.h" namespace OHOS { namespace AbilityRuntime { @@ -35,7 +41,6 @@ UIExtension* UIExtension::Create(const std::unique_ptr& runtime) return JsUIExtension::Create(runtime); case Runtime::Language::ETS: return EtsUIExtension::Create(runtime); - default: return new UIExtension(); } @@ -63,5 +68,194 @@ std::shared_ptr UIExtension::CreateAndInitContext( } return context; } + +bool UIExtension::HandleSessionCreate(const AAFwk::Want &want, const sptr &sessionInfo) +{ + TAG_LOGD(AAFwkTag::UI_EXT, "HandleSessionCreate called"); + return true; +} + +void UIExtension::ForegroundWindow(const AAFwk::Want &want, const sptr &sessionInfo) +{ + TAG_LOGD(AAFwkTag::UI_EXT, "ForegroundWindow called"); + HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); + if (!HandleSessionCreate(want, sessionInfo)) { + TAG_LOGE(AAFwkTag::UI_EXT, "HandleSessionCreate failed"); + return; + } + std::lock_guard lock(uiWindowMutex_); + TAG_LOGI(AAFwkTag::UI_EXT, "Before window show UIExtcomponent id: %{public}" PRId64, + sessionInfo->uiExtensionComponentId); + auto componentId = sessionInfo->uiExtensionComponentId; + auto& uiWindow = uiWindowMap_[componentId]; + if (uiWindow) { + HITRACE_METER_NAME(HITRACE_TAG_APP, "Rosen::Window::show"); + uiWindow->Show(); + foregroundWindows_.emplace(componentId); + } + TAG_LOGD(AAFwkTag::UI_EXT, "end"); +} + +void UIExtension::BackgroundWindow(const sptr &sessionInfo) +{ + TAG_LOGD(AAFwkTag::UI_EXT, "BackgroundWindow called"); + HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); + if (sessionInfo == nullptr) { + TAG_LOGE(AAFwkTag::UI_EXT, "Invalid sessionInfo"); + return; + } + std::lock_guard lock(uiWindowMutex_); + auto componentId = sessionInfo->uiExtensionComponentId; + if (uiWindowMap_.find(componentId) == uiWindowMap_.end()) { + TAG_LOGE(AAFwkTag::UI_EXT, "find uiWindow failed"); + return; + } + auto& uiWindow = uiWindowMap_[componentId]; + TAG_LOGI(AAFwkTag::UI_EXT, "Befor window hide UIExtcomponent id: %{public}" PRId64, + sessionInfo->uiExtensionComponentId); + if (uiWindow) { + uiWindow->Hide(); + foregroundWindows_.erase(componentId); + } + TAG_LOGD(AAFwkTag::UI_EXT, "end"); +} + +void UIExtension::DestroyWindow(const sptr &sessionInfo) +{ + TAG_LOGD(AAFwkTag::UI_EXT, "DestroyWindow called"); +} + +bool UIExtension::ForegroundWindowWithInsightIntent( + const AAFwk::Want &want, const sptr &sessionInfo, bool needForeground) +{ + TAG_LOGD(AAFwkTag::UI_EXT, "ForegroundWindowWithInsightIntent called"); + return true; +} + +void UIExtension::OnStopCallBack() +{ + auto context = GetContext(); + if (context == nullptr) { + TAG_LOGE(AAFwkTag::UI_EXT, "null context"); + return; + } + bool ret = ConnectionManager::GetInstance().DisconnectCaller(context->GetToken()); + if (ret) { + ConnectionManager::GetInstance().ReportConnectionLeakEvent(getpid(), gettid()); + TAG_LOGD(AAFwkTag::UI_EXT, "The service connection is not disconnected"); + } +} + +void UIExtension::OnCommand(const AAFwk::Want &want, bool restart, int startId) +{ + TAG_LOGD(AAFwkTag::UI_EXT, "called"); + Extension::OnCommand(want, restart, startId); +} + +void UIExtension::OnCommandWindow(const AAFwk::Want &want, const sptr &sessionInfo, + AAFwk::WindowCommand winCmd) +{ + HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); + if (sessionInfo == nullptr) { + TAG_LOGE(AAFwkTag::UI_EXT, "null sessionInfo"); + return; + } + TAG_LOGD(AAFwkTag::UI_EXT, "begin. persistentId: %{private}d, winCmd: %{public}d", + sessionInfo->persistentId, winCmd); + Extension::OnCommandWindow(want, sessionInfo, winCmd); + if (InsightIntentExecuteParam::IsInsightIntentExecute(want) && winCmd == AAFwk::WIN_CMD_FOREGROUND) { + if (ForegroundWindowWithInsightIntent(want, sessionInfo, false)) { + return; + } + } + switch (winCmd) { + case AAFwk::WIN_CMD_FOREGROUND: + ForegroundWindow(want, sessionInfo); + break; + case AAFwk::WIN_CMD_BACKGROUND: + BackgroundWindow(sessionInfo); + break; + case AAFwk::WIN_CMD_DESTROY: + DestroyWindow(sessionInfo); + break; + default: + TAG_LOGD(AAFwkTag::UI_EXT, "unsupported cmd"); + break; + } + OnCommandWindowDone(sessionInfo, winCmd); +} + +void UIExtension::OnCommandWindowDone(const sptr &sessionInfo, AAFwk::WindowCommand winCmd) +{ + HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); + TAG_LOGD(AAFwkTag::UI_EXT, "called"); + auto context = GetContext(); + if (context == nullptr) { + TAG_LOGE(AAFwkTag::UI_EXT, "null context"); + return; + } + AAFwk::AbilityCommand abilityCmd; + std::lock_guard lock(uiWindowMutex_); + if (uiWindowMap_.empty()) { + abilityCmd = AAFwk::ABILITY_CMD_DESTROY; + } else if (foregroundWindows_.empty()) { + abilityCmd = AAFwk::ABILITY_CMD_BACKGROUND; + } else { + abilityCmd = AAFwk::ABILITY_CMD_FOREGROUND; + } + AAFwk::AbilityManagerClient::GetInstance()->ScheduleCommandAbilityWindowDone( + context->GetToken(), sessionInfo, winCmd, abilityCmd); + TAG_LOGD(AAFwkTag::UI_EXT, "end"); +} + +void UIExtension::OnInsightIntentExecuteDone(const sptr &sessionInfo, + const AppExecFwk::InsightIntentExecuteResult &result) +{ + HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); + if (sessionInfo == nullptr) { + TAG_LOGE(AAFwkTag::UI_EXT, "Invalid sessionInfo"); + return; + } + std::lock_guard lock(uiWindowMutex_); + TAG_LOGD(AAFwkTag::UI_EXT, "UIExtension component id: %{public}" PRId64, sessionInfo->uiExtensionComponentId); + auto componentId = sessionInfo->uiExtensionComponentId; + auto res = uiWindowMap_.find(componentId); + if (res != uiWindowMap_.end() && res->second != nullptr) { + WantParams params; + params.SetParam(INSIGHT_INTENT_EXECUTE_RESULT_CODE, AAFwk::Integer::Box(result.innerErr)); + WantParams resultParams; + resultParams.SetParam("code", AAFwk::Integer::Box(result.code)); + if (result.result != nullptr) { + sptr pWantParams = WantParamWrapper::Box(*result.result); + if (pWantParams != nullptr) { + resultParams.SetParam("result", pWantParams); + } + } + auto size = result.uris.size(); + sptr uriArray = new (std::nothrow) Array(size, g_IID_IString); + if (uriArray == nullptr) { + TAG_LOGE(AAFwkTag::UI_EXT, "new uriArray failed"); + return; + } + for (std::size_t i = 0; i < size; i++) { + uriArray->Set(i, String::Box(result.uris[i])); + } + resultParams.SetParam("uris", uriArray); + resultParams.SetParam("flags", AAFwk::Integer::Box(result.flags)); + sptr pWantParams = WantParamWrapper::Box(resultParams); + if (pWantParams != nullptr) { + params.SetParam(INSIGHT_INTENT_EXECUTE_RESULT, pWantParams); + } + Rosen::WMError ret = res->second->TransferExtensionData(params); + if (ret == Rosen::WMError::WM_OK) { + TAG_LOGD(AAFwkTag::UI_EXT, "TransferExtensionData success"); + } else { + TAG_LOGE(AAFwkTag::UI_EXT, "TransferExtensionData failed, ret=%{public}d", ret); + } + res->second->Show(); + foregroundWindows_.emplace(componentId); + } + TAG_LOGD(AAFwkTag::UI_EXT, "end"); +} } } diff --git a/frameworks/native/appkit/ability_runtime/app/ets_ability_stage.cpp b/frameworks/native/appkit/ability_runtime/app/ets_ability_stage.cpp index e7a8472474d139181a6bd8321578042b8592dfcb..f019b9b0ab21164055fa4b9782877c2a59894ac0 100644 --- a/frameworks/native/appkit/ability_runtime/app/ets_ability_stage.cpp +++ b/frameworks/native/appkit/ability_runtime/app/ets_ability_stage.cpp @@ -12,17 +12,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - #include "ets_ability_stage.h" -#include "ability_delegator_registry.h" -#include "freeze_util.h" -#include "hilog_tag_wrapper.h" -#include "configuration_convertor.h" -#include "ets_ability_stage_context.h" -#include "ani_common_configuration.h" -#include "ohos_application.h" -#include "startup_manager.h" -#include "hitrace_meter.h" + #include #include #include @@ -31,25 +22,20 @@ #include #include +#include "ability_delegator_registry.h" +#include "ani_common_configuration.h" +#include "configuration_convertor.h" +#include "ets_ability_stage_context.h" +#include "freeze_util.h" +#include "hilog_tag_wrapper.h" +#include "hitrace_meter.h" +#include "ohos_application.h" +#include "startup_manager.h" + namespace OHOS { namespace AbilityRuntime { - -bool ETSAbilityStage::UseCommonChunk(const AppExecFwk::HapModuleInfo& hapModuleInfo) -{ - for (auto &md: hapModuleInfo.metadata) { - if (md.name == "USE_COMMON_CHUNK") { - if (md.value != "true") { - TAG_LOGE(AAFwkTag::APPKIT, "USE_COMMON_CHUNK = %s{public}s", md.value.c_str()); - return false; - } - return true; - } - } - return false; -} - std::shared_ptr ETSAbilityStage::Create( - const std::unique_ptr& runtime, const AppExecFwk::HapModuleInfo& hapModuleInfo) + const std::unique_ptr &runtime, const AppExecFwk::HapModuleInfo &hapModuleInfo) { if (runtime == nullptr) { TAG_LOGE(AAFwkTag::APPKIT, "null runtime"); @@ -62,7 +48,6 @@ std::shared_ptr ETSAbilityStage::Create( std::string srcPath(hapModuleInfo.name); std::string moduleName(hapModuleInfo.moduleName); moduleName.append("::").append("AbilityStage"); - bool commonChunkFlag = UseCommonChunk(hapModuleInfo); srcPath.append("/"); if (!hapModuleInfo.srcEntrance.empty()) { @@ -73,24 +58,19 @@ std::shared_ptr ETSAbilityStage::Create( srcPath.append(".abc"); } } - std::unique_ptr moduleObj; + std::unique_ptr moduleObj = nullptr; if (!hapModuleInfo.srcEntrance.empty()) { TAG_LOGD(AAFwkTag::APPKIT, "entry path: %{public}s", hapModuleInfo.srcEntrance.c_str()); - moduleObj = etsRuntime.LoadModule(moduleName, srcPath, hapModuleInfo.hapPath, - hapModuleInfo.compileMode == AppExecFwk::CompileMode::ES_MODULE, commonChunkFlag, - hapModuleInfo.srcEntrance); + moduleObj = etsRuntime.LoadModule(moduleName, srcPath, + hapModuleInfo.hapPath, false, false, hapModuleInfo.srcEntrance); } return std::make_shared(etsRuntime, std::move(moduleObj)); } -ETSAbilityStage::ETSAbilityStage(ETSRuntime & etsRuntime, std::unique_ptr&& etsAbilityStageObj) +ETSAbilityStage::ETSAbilityStage(ETSRuntime &etsRuntime, std::unique_ptr &&etsAbilityStageObj) : etsRuntime_(etsRuntime), etsAbilityStageObj_(std::move(etsAbilityStageObj)) {} -ETSAbilityStage::~ETSAbilityStage() -{ -} - void ETSAbilityStage::Init(const std::shared_ptr &context, const std::weak_ptr application) { @@ -129,7 +109,7 @@ void ETSAbilityStage::OnDestroy() const CallObjectMethod(false, "onDestroy", ":V"); } -void ETSAbilityStage::OnConfigurationUpdated(const AppExecFwk::Configuration& configuration) +void ETSAbilityStage::OnConfigurationUpdated(const AppExecFwk::Configuration &configuration) { TAG_LOGD(AAFwkTag::APPKIT, "OnConfigurationUpdated called"); AbilityStage::OnConfigurationUpdated(configuration); diff --git a/frameworks/native/appkit/ability_runtime/app/ets_ability_stage_context.cpp b/frameworks/native/appkit/ability_runtime/app/ets_ability_stage_context.cpp index af8cb7362cd5dc64030e5849b1067a1d625ee1e7..29d027aeb71f821c5566394ba7d9344ce7be3425 100644 --- a/frameworks/native/appkit/ability_runtime/app/ets_ability_stage_context.cpp +++ b/frameworks/native/appkit/ability_runtime/app/ets_ability_stage_context.cpp @@ -12,21 +12,22 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "ability_runtime/context/context.h" #include "ets_ability_stage_context.h" -#include "hilog_tag_wrapper.h" -#include "ets_runtime.h" -#include "configuration_convertor.h" -#include "ohos_application.h" + +#include "ability_runtime/context/context.h" #include "ani_common_configuration.h" +#include "configuration_convertor.h" #include "ets_context_utils.h" +#include "ets_runtime.h" +#include "hilog_tag_wrapper.h" +#include "ohos_application.h" namespace OHOS { namespace AbilityRuntime { ani_ref ETSAbilityStageContext::etsAbilityStageContextObj_ = nullptr; -ani_object ETSAbilityStageContext::CreateEtsAbilityStageContext(ani_env* env, std::shared_ptr context) +ani_object ETSAbilityStageContext::CreateEtsAbilityStageContext(ani_env *env, std::shared_ptr context) { if (env == nullptr || context == nullptr) { TAG_LOGE(AAFwkTag::ABILITY, "env nullptr or context nullptr"); @@ -55,7 +56,7 @@ ani_object ETSAbilityStageContext::CreateEtsAbilityStageContext(ani_env* env, st } etsAbilityStageContextObj_ = reinterpret_cast(obj); - //bind context + // bind context auto workContext = new (std::nothrow) std::weak_ptr(context); if (workContext == nullptr) { TAG_LOGE(AAFwkTag::ABILITY, "workContext nullptr"); @@ -75,18 +76,14 @@ ani_object ETSAbilityStageContext::CreateEtsAbilityStageContext(ani_env* env, st } ContextUtil::CreateEtsBaseContext(env, abilityStageCtxCls, obj, context); - //set Config class + // set Config class SetConfiguration(env, abilityStageCtxCls, obj, context); return obj; } -void ETSAbilityStageContext::SetConfiguration(ani_env* env, ani_class stageCls, ani_object stageCtxObj, +void ETSAbilityStageContext::SetConfiguration(ani_env *env, ani_class stageCls, ani_object stageCtxObj, std::shared_ptr &context) { - if (context == nullptr || env == nullptr) { - TAG_LOGE(AAFwkTag::ABILITY, "env or context null ptr"); - return; - } auto configuration = context->GetConfiguration(); if (configuration == nullptr) { TAG_LOGE(AAFwkTag::ABILITY, "configuration null ptr"); diff --git a/interfaces/kits/native/ability/native/ui_extension_ability/js_ui_extension.h b/interfaces/kits/native/ability/native/ui_extension_ability/js_ui_extension.h index f748657bd6616f39f28d6953bd43a82764d7ab98..606c423011b067b2d94b798a0ffd1145218e4564 100755 --- a/interfaces/kits/native/ability/native/ui_extension_ability/js_ui_extension.h +++ b/interfaces/kits/native/ability/native/ui_extension_ability/js_ui_extension.h @@ -25,8 +25,6 @@ #include "insight_intent_executor_info.h" #include "js_ui_extension_content_session.h" #include "ui_extension.h" -#include -#include class NativeReference; @@ -108,9 +106,6 @@ public: */ virtual void OnCommand(const AAFwk::Want &want, bool restart, int startId) override; - virtual void OnCommandWindow(const AAFwk::Want &want, const sptr &sessionInfo, - AAFwk::WindowCommand winCmd) override; - /** * @brief Called when this ui extension enters the STATE_STOP state. * @@ -192,18 +187,13 @@ private: napi_value CallOnDisconnect(const AAFwk::Want &want, bool withResult = false); - void ForegroundWindow(const AAFwk::Want &want, const sptr &sessionInfo); - void BackgroundWindow(const sptr &sessionInfo); - void DestroyWindow(const sptr &sessionInfo); + void DestroyWindow(const sptr &sessionInfo) override; - void OnCommandWindowDone(const sptr &sessionInfo, AAFwk::WindowCommand winCmd) override; bool ForegroundWindowInitInsightIntentExecutorInfo(const AAFwk::Want &want, const sptr &sessionInfo, InsightIntentExecutorInfo &executorInfo); - bool ForegroundWindowWithInsightIntent(const AAFwk::Want &want, const sptr &sessionInfo, - bool needForeground); - bool HandleSessionCreate(const AAFwk::Want &want, const sptr &sessionInfo); - void OnInsightIntentExecuteDone(const sptr &sessionInfo, - const AppExecFwk::InsightIntentExecuteResult &result) override; + bool ForegroundWindowWithInsightIntent( + const AAFwk::Want &want, const sptr &sessionInfo, bool needForeground) override; + bool HandleSessionCreate(const AAFwk::Want &want, const sptr &sessionInfo) override; void PostInsightIntentExecuted(const sptr &sessionInfo, const AppExecFwk::InsightIntentExecuteResult &result, bool needForeground); std::unique_ptr CreateAppWindowStage(sptr uiWindow, @@ -215,9 +205,6 @@ private: JsRuntime& jsRuntime_; std::shared_ptr jsObj_ = nullptr; std::shared_ptr shellContextRef_ = nullptr; - std::mutex uiWindowMutex_; - std::map> uiWindowMap_; - std::set foregroundWindows_; std::map> contentSessions_; std::shared_ptr abilityResultListeners_ = nullptr; int32_t screenMode_ = AAFwk::IDLE_SCREEN_MODE; diff --git a/interfaces/kits/native/ability/native/ui_extension_ability/ui_extension.h b/interfaces/kits/native/ability/native/ui_extension_ability/ui_extension.h index 5f14369e4d6d99aef78663546121de36ab9465fc..6274ded001ba873f45d9d54b013c2a61be39906d 100755 --- a/interfaces/kits/native/ability/native/ui_extension_ability/ui_extension.h +++ b/interfaces/kits/native/ability/native/ui_extension_ability/ui_extension.h @@ -16,6 +16,9 @@ #ifndef OHOS_ABILITY_RUNTIME_UI_EXTENSION_H #define OHOS_ABILITY_RUNTIME_UI_EXTENSION_H +#include +#include + #include "extension_base.h" namespace OHOS { @@ -65,6 +68,30 @@ public: * @return The ui extension instance. */ static UIExtension* Create(const std::unique_ptr& runtime); + + virtual void OnStopCallBack() override; + + virtual void OnCommand(const AAFwk::Want &want, bool restart, int startId) override; + + virtual void OnCommandWindow( + const AAFwk::Want &want, const sptr &sessionInfo, AAFwk::WindowCommand winCmd) override; + + virtual void OnCommandWindowDone(const sptr &sessionInfo, AAFwk::WindowCommand winCmd) override; + + virtual void OnInsightIntentExecuteDone(const sptr &sessionInfo, + const AppExecFwk::InsightIntentExecuteResult &result) override; + +protected: + virtual void ForegroundWindow(const AAFwk::Want &want, const sptr &sessionInfo); + virtual void BackgroundWindow(const sptr &sessionInfo); + virtual void DestroyWindow(const sptr &sessionInfo); + virtual bool ForegroundWindowWithInsightIntent( + const AAFwk::Want &want, const sptr &sessionInfo, bool needForeground); + virtual bool HandleSessionCreate(const AAFwk::Want &want, const sptr &sessionInfo); +protected: + std::mutex uiWindowMutex_; + std::map> uiWindowMap_; + std::set foregroundWindows_; }; } // namespace AbilityRuntime } // namespace OHOS diff --git a/interfaces/kits/native/appkit/ability_runtime/app/ets_ability_stage.h b/interfaces/kits/native/appkit/ability_runtime/app/ets_ability_stage.h index 8d56d08942fa6d6a53cc894432c76b96b2706792..f6dc4dcca1f12e09eafa3f78d33c951de22ced6c 100644 --- a/interfaces/kits/native/appkit/ability_runtime/app/ets_ability_stage.h +++ b/interfaces/kits/native/appkit/ability_runtime/app/ets_ability_stage.h @@ -16,26 +16,25 @@ #ifndef OHOS_ABILITY_RUNTIME_ETS_ABILITY_STAGE_H #define OHOS_ABILITY_RUNTIME_ETS_ABILITY_STAGE_H -#include "ability_delegator_infos.h" - #include #include +#include "ability_delegator_infos.h" #include "ability_stage.h" #include "configuration.h" -#include "resource_manager.h" -#include "native_engine/native_value.h" #include "ets_runtime.h" +#include "native_engine/native_value.h" +#include "resource_manager.h" namespace OHOS { namespace AbilityRuntime { class ETSAbilityStage : public AbilityStage { public: static std::shared_ptr Create( - const std::unique_ptr& runtime, const AppExecFwk::HapModuleInfo& hapModuleInfo); + const std::unique_ptr &runtime, const AppExecFwk::HapModuleInfo &hapModuleInfo); - ETSAbilityStage(ETSRuntime& etsRuntime, std::unique_ptr&& ETSAbilityStageObj); - ~ETSAbilityStage() override; + ETSAbilityStage(ETSRuntime &etsRuntime, std::unique_ptr &&ETSAbilityStageObj); + ~ETSAbilityStage() override {} void Init(const std::shared_ptr &context, const std::weak_ptr application) override; @@ -44,17 +43,15 @@ public: void OnDestroy() const override; - void OnConfigurationUpdated(const AppExecFwk::Configuration& configuration) override; + void OnConfigurationUpdated(const AppExecFwk::Configuration &configuration) override; private: - bool CallObjectMethod(bool withResult, const char* name, const char* signature, ...) const; + bool CallObjectMethod(bool withResult, const char *name, const char *signature, ...) const; std::shared_ptr CreateStageProperty() const; std::string GetHapModuleProp(const std::string &propName) const; - static bool UseCommonChunk(const AppExecFwk::HapModuleInfo& hapModuleInfo); - void SetEtsAbilityStage(const std::shared_ptr &context); ETSRuntime& etsRuntime_; diff --git a/interfaces/kits/native/appkit/ability_runtime/app/ets_ability_stage_context.h b/interfaces/kits/native/appkit/ability_runtime/app/ets_ability_stage_context.h index c88a608735adef6c990485b47be03c54b9fe45bd..603bac7373af617a981483f9e3a270367b190f4a 100644 --- a/interfaces/kits/native/appkit/ability_runtime/app/ets_ability_stage_context.h +++ b/interfaces/kits/native/appkit/ability_runtime/app/ets_ability_stage_context.h @@ -31,18 +31,18 @@ constexpr const char* ETS_HAPMODULEINFO_CLASS_NAME = "LbundleManager/HapModuleIn class Context; class ETSAbilityStageContext final { public: - explicit ETSAbilityStageContext(const std::shared_ptr& context) : context_(context) {} + explicit ETSAbilityStageContext(const std::shared_ptr &context) : context_(context) {} ~ETSAbilityStageContext() = default; - static void ConfigurationUpdated(ani_env* env, const std::shared_ptr &config); + static void ConfigurationUpdated(ani_env *env, const std::shared_ptr &config); std::shared_ptr GetContext() { return context_.lock(); } - static ani_object CreateEtsAbilityStageContext(ani_env* env, std::shared_ptr context); + static ani_object CreateEtsAbilityStageContext(ani_env *env, std::shared_ptr context); private: - static void SetConfiguration(ani_env* env, ani_class stageCls, ani_object stageCtxObj, + static void SetConfiguration(ani_env *env, ani_class stageCls, ani_object stageCtxObj, std::shared_ptr &context); private: std::weak_ptr context_;