mirror of
https://github.com/openharmony/ability_ability_runtime.git
synced 2026-08-24 12:43:16 -04:00
fix cj abilityStageContext
Signed-off-by: wentao <wentao0301@sina.com> Change-Id: Ia1d5409ba5f1a5494f817657ee7086cc4fb76206 Signed-off-by: wentao <wentao0301@sina.com>
This commit is contained in:
@@ -80,34 +80,45 @@ std::shared_ptr<CJAbilityStage> CJAbilityStage::Create(
|
||||
const std::unique_ptr<Runtime>& runtime, const AppExecFwk::HapModuleInfo& hapModuleInfo)
|
||||
{
|
||||
if (!runtime) {
|
||||
HILOG_ERROR("Runtime does not exist.");
|
||||
TAG_LOGE(AAFwkTag::APPKIT, "Runtime does not exist.");
|
||||
return nullptr;
|
||||
}
|
||||
auto& cjRuntime = static_cast<CJRuntime&>(*runtime);
|
||||
// Load cj app library.
|
||||
if (!cjRuntime.IsAppLibLoaded()) {
|
||||
HILOG_ERROR("Failed to create CJAbilityStage, applib not loaded.");
|
||||
TAG_LOGE(AAFwkTag::APPKIT, "Failed to create CJAbilityStage, applib not loaded.");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto cjAbilityStageObject = CJAbilityStageObject::LoadModule(hapModuleInfo.moduleName);
|
||||
if (cjAbilityStageObject == nullptr) {
|
||||
cjRuntime.UnLoadCJAppLibrary();
|
||||
HILOG_ERROR("Failed to create CJAbilityStage.");
|
||||
TAG_LOGE(AAFwkTag::APPKIT, "Failed to create CJAbilityStage.");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return std::make_shared<CJAbilityStage>(cjAbilityStageObject);
|
||||
}
|
||||
|
||||
void CJAbilityStage::Init(const std::shared_ptr<Context> &context,
|
||||
const std::weak_ptr<AppExecFwk::OHOSApplication> application)
|
||||
{
|
||||
AbilityStage::Init(context, application);
|
||||
if (!cjAbilityStageObject_) {
|
||||
TAG_LOGE(AAFwkTag::APPKIT, "Failed to create CJAbilityStage.");
|
||||
return;
|
||||
}
|
||||
cjAbilityStageObject_->Init(this);
|
||||
}
|
||||
|
||||
void CJAbilityStage::OnCreate(const AAFwk::Want& want) const
|
||||
{
|
||||
AbilityStage::OnCreate(want);
|
||||
if (!cjAbilityStageObject_) {
|
||||
HILOG_ERROR("CJAbilityStage is not loaded.");
|
||||
TAG_LOGE(AAFwkTag::APPKIT, "CJAbilityStage is not loaded.");
|
||||
return;
|
||||
}
|
||||
HILOG_DEBUG("CJAbilityStage::OnCreate");
|
||||
TAG_LOGD(AAFwkTag::APPKIT, "CJAbilityStage::OnCreate");
|
||||
cjAbilityStageObject_->OnCreate();
|
||||
}
|
||||
|
||||
@@ -115,7 +126,7 @@ std::string CJAbilityStage::OnAcceptWant(const AAFwk::Want& want)
|
||||
{
|
||||
AbilityStage::OnAcceptWant(want);
|
||||
if (!cjAbilityStageObject_) {
|
||||
HILOG_ERROR("CJAbilityStage is not loaded.");
|
||||
TAG_LOGE(AAFwkTag::APPKIT, "CJAbilityStage is not loaded.");
|
||||
return "";
|
||||
}
|
||||
return cjAbilityStageObject_->OnAcceptWant(want);
|
||||
@@ -126,12 +137,12 @@ void CJAbilityStage::OnConfigurationUpdated(const AppExecFwk::Configuration& con
|
||||
AbilityStage::OnConfigurationUpdated(configuration);
|
||||
auto fullConfig = GetContext()->GetConfiguration();
|
||||
if (!fullConfig) {
|
||||
HILOG_ERROR("configuration is nullptr.");
|
||||
TAG_LOGE(AAFwkTag::APPKIT, "configuration is nullptr.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!cjAbilityStageObject_) {
|
||||
HILOG_ERROR("CJAbilityStage is not loaded.");
|
||||
TAG_LOGE(AAFwkTag::APPKIT, "CJAbilityStage is not loaded.");
|
||||
return;
|
||||
}
|
||||
cjAbilityStageObject_->OnConfigurationUpdated(fullConfig);
|
||||
@@ -141,7 +152,7 @@ void CJAbilityStage::OnMemoryLevel(int level)
|
||||
{
|
||||
AbilityStage::OnMemoryLevel(level);
|
||||
if (!cjAbilityStageObject_) {
|
||||
HILOG_ERROR("CJAbilityStage is not loaded.");
|
||||
TAG_LOGE(AAFwkTag::APPKIT, "CJAbilityStage is not loaded.");
|
||||
return;
|
||||
}
|
||||
cjAbilityStageObject_->OnMemoryLevel(level);
|
||||
|
||||
@@ -67,6 +67,15 @@ CJAbilityStageObject::~CJAbilityStageObject()
|
||||
id_ = 0;
|
||||
}
|
||||
|
||||
void CJAbilityStageObject::Init(AbilityStageHandle abilityStage) const
|
||||
{
|
||||
if (g_cjAbilityStageFuncs == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::APPKIT, "cj functions for CJAbilityStage are not registered");
|
||||
return;
|
||||
}
|
||||
g_cjAbilityStageFuncs->AbilityStageInit(id_, abilityStage);
|
||||
}
|
||||
|
||||
void CJAbilityStageObject::OnCreate() const
|
||||
{
|
||||
if (g_cjAbilityStageFuncs == nullptr) {
|
||||
|
||||
@@ -87,7 +87,7 @@ bool CJRuntime::Initialize(const Options& options)
|
||||
|
||||
void CJRuntime::RegisterUncaughtExceptionHandler(const CJUncaughtExceptionInfo& uncaughtExceptionInfo)
|
||||
{
|
||||
HILOG_INFO("RegisterUncaughtExceptionHandler not support yet");
|
||||
OHOS::CJEnvironment::GetInstance()->RegisterCJUncaughtExceptionHandler(uncaughtExceptionInfo);
|
||||
}
|
||||
|
||||
bool CJRuntime::LoadCJAppLibrary(const AppLibPathVec& appLibPaths)
|
||||
|
||||
@@ -57,6 +57,8 @@ public:
|
||||
std::shared_ptr<CJAbilityStageObject> cjStage) : cjAbilityStageObject_(std::move(cjStage)) {}
|
||||
~CJAbilityStage() override = default;
|
||||
|
||||
void Init(const std::shared_ptr<Context> &context,
|
||||
const std::weak_ptr<AppExecFwk::OHOSApplication> application) override;
|
||||
void OnCreate(const AAFwk::Want& want) const override;
|
||||
std::string OnAcceptWant(const AAFwk::Want& want) override;
|
||||
void OnConfigurationUpdated(const AppExecFwk::Configuration& configuration) override;
|
||||
|
||||
@@ -46,6 +46,7 @@ struct CJAbilityStageFuncs {
|
||||
char* (*AbilityStageOnAcceptWant)(int64_t handle, OHOS::AAFwk::Want* want);
|
||||
void (*AbilityStageOnConfigurationUpdated)(int64_t id, CJConfiguration configuration);
|
||||
void (*AbilityStageOnMemoryLevel)(int64_t id, int32_t level);
|
||||
void (*AbilityStageInit)(int64_t id, void* abilityStage);
|
||||
};
|
||||
|
||||
CJ_EXPORT void RegisterCJAbilityStageFuncs(void (*registerFunc)(CJAbilityStageFuncs* result));
|
||||
@@ -60,6 +61,7 @@ public:
|
||||
explicit CJAbilityStageObject(int64_t id) : id_(id) {}
|
||||
~CJAbilityStageObject();
|
||||
|
||||
void Init(AbilityStageHandle abilityStage) const;
|
||||
void OnCreate() const;
|
||||
std::string OnAcceptWant(const AAFwk::Want& want) const;
|
||||
void OnConfigurationUpdated(const std::shared_ptr<AppExecFwk::Configuration>& configuration) const;
|
||||
|
||||
Reference in New Issue
Block a user