handle issue

Signed-off-by: chenxinzhan <chenxinzhan@huawei.com>
This commit is contained in:
chenxinzhan 2024-08-08 18:24:43 +08:00
parent 02fdf47a8e
commit 40d2d37fbe
6 changed files with 40 additions and 31 deletions

View File

@ -360,6 +360,7 @@ napi_value PromiseCallback(napi_env env, napi_callback_info info)
auto *callbackInfo = static_cast<AppExecFwk::AbilityTransactionCallbackInfo<> *>(data);
if (callbackInfo == nullptr) {
TAG_LOGD(AAFwkTag::UI_EXT, "Invalid input info");
data = nullptr;
return nullptr;
}
callbackInfo->Call();
@ -431,8 +432,7 @@ void JsUIExtension::OnCommandWindow(const AAFwk::Want &want, const sptr<AAFwk::S
sessionInfo->persistentId, winCmd);
Extension::OnCommandWindow(want, sessionInfo, winCmd);
if (InsightIntentExecuteParam::IsInsightIntentExecute(want) && winCmd == AAFwk::WIN_CMD_FOREGROUND) {
bool finish = ForegroundWindowWithInsightIntent(want, sessionInfo, false);
if (finish) {
if (ForegroundWindowWithInsightIntent(want, sessionInfo, false)) {
return;
}
}
@ -698,11 +698,15 @@ bool JsUIExtension::HandleSessionCreate(const AAFwk::Want &want, const sptr<AAFw
sptr<Rosen::Window> JsUIExtension::CreateUIWindow(const std::shared_ptr<UIExtensionContext> context,
const sptr<AAFwk::SessionInfo> &sessionInfo)
{
sptr<Rosen::WindowOption> option = new (std::nothrow) Rosen::WindowOption();
if (context == nullptr || context->GetAbilityInfo() == nullptr) {
TAG_LOGE(AAFwkTag::UI_EXT, "Failed to get context");
return nullptr;
}
sptr<Rosen::WindowOption> option = new (std::nothrow) Rosen::WindowOption();
if (option == nullptr) {
TAG_LOGE(AAFwkTag::UI_EXT, "make option failed");
return nullptr;
}
option->SetWindowName(context->GetBundleName() + context->GetAbilityInfo()->name);
option->SetWindowType(Rosen::WindowType::WINDOW_TYPE_UI_EXTENSION);
option->SetWindowSessionType(Rosen::WindowSessionType::EXTENSION_SESSION);

View File

@ -493,11 +493,15 @@ bool JsUIExtensionBase::HandleSessionCreate(const AAFwk::Want &want, const sptr<
}
auto componentId = sessionInfo->uiExtensionComponentId;
if (uiWindowMap_.find(componentId) == uiWindowMap_.end()) {
sptr<Rosen::WindowOption> option = new Rosen::WindowOption();
if (context_ == nullptr || context_->GetAbilityInfo() == nullptr) {
TAG_LOGE(AAFwkTag::UI_EXT, "Failed to get context");
return false;
}
sptr<Rosen::WindowOption> option = new Rosen::WindowOption();
if (option == nullptr) {
TAG_LOGE(AAFwkTag::UI_EXT, "make option failed");
return false;
}
option->SetWindowName(context_->GetBundleName() + context_->GetAbilityInfo()->name);
option->SetWindowType(Rosen::WindowType::WINDOW_TYPE_UI_EXTENSION);
option->SetWindowSessionType(Rosen::WindowSessionType::EXTENSION_SESSION);

View File

@ -25,12 +25,12 @@
#include "js_extension_window.h"
#include "js_runtime_utils.h"
#include "js_ui_extension_context.h"
#include "string_wrapper.h"
#include "napi_common_start_options.h"
#include "napi_common_util.h"
#include "napi_common_want.h"
#include "native_engine.h"
#include "native_value.h"
#include "string_wrapper.h"
#include "tokenid_kit.h"
#ifdef SUPPORT_SCREEN
#include "ui_content.h"
@ -83,7 +83,7 @@ void AbilityResultListeners::RemoveListener(const uint64_t &uiExtensionComponent
void AbilityResultListeners::OnAbilityResult(int requestCode, int resultCode, const Want &resultData)
{
for (auto item:listeners_) {
for (auto &item : listeners_) {
if (item.second && item.second->IsMatch(requestCode)) {
item.second->OnAbilityResult(requestCode, resultCode, resultData);
return;

View File

@ -21,6 +21,7 @@
#include "ability_manager_errors.h"
#include "event_handler.h"
#include "hilog_tag_wrapper.h"
#include "hitrace_meter.h"
#include "js_extension_context.h"
#include "js_error_utils.h"
#include "js_data_struct_converter.h"
@ -37,7 +38,6 @@
#include "open_link_options.h"
#include "open_link/napi_common_open_link_options.h"
#include "start_options.h"
#include "hitrace_meter.h"
#include "uri.h"
#include "ui_extension_servicehost_stub_impl.h"
#include "ui_service_extension_connection_constants.h"
@ -51,9 +51,9 @@ constexpr int32_t INDEX_TWO = 2;
constexpr size_t ARGC_ZERO = 0;
constexpr size_t ARGC_ONE = 1;
constexpr size_t ARGC_TWO = 2;
constexpr size_t ARGC_THREE = 3;
const std::string ATOMIC_SERVICE_PREFIX = "com.atomicservice.";
constexpr size_t ARGC_THREE = 3;
} // namespace
static std::map<UIExtensionConnectionKey, sptr<JSUIExtensionConnection>, key_compare> g_connects;
@ -65,19 +65,19 @@ void RemoveConnection(int64_t connectId)
return connectId == obj.first.id;
});
if (item != g_connects.end()) {
TAG_LOGD(AAFwkTag::UI_EXT, "remove conn ability exist");
TAG_LOGD(AAFwkTag::UI_EXT, "conn ability to be removed exists");
if (item->second) {
item->second->RemoveConnectionObject();
}
g_connects.erase(item);
} else {
TAG_LOGD(AAFwkTag::UI_EXT, "remove conn ability not exist");
TAG_LOGD(AAFwkTag::UI_EXT, "conn ability to be removed not exists");
}
}
void FindConnection(AAFwk::Want& want, sptr<JSUIExtensionConnection>& connection, int64_t& connectId)
{
TAG_LOGD(AAFwkTag::UI_EXT, "Disconnect ability enter, connection:%{public}d", static_cast<int32_t>(connectId));
TAG_LOGD(AAFwkTag::UI_EXT, "Disconnect ability enter, connection:%{public}" PRId64, connectId);
auto item = std::find_if(g_connects.begin(),
g_connects.end(),
[&connectId](const auto &obj) {
@ -213,9 +213,8 @@ napi_value JsUIExtensionContext::OnStartAbility(napi_env env, NapiCallbackInfo&
return;
}
ErrCode innerErrorCode = ERR_OK;
(unwrapArgc == 1) ? innerErrorCode = context->StartAbility(want) :
innerErrorCode = context->StartAbility(want, startOptions);
ErrCode innerErrorCode = (unwrapArgc == 1) ? context->StartAbility(want) :
context->StartAbility(want, startOptions);
if (innerErrorCode == 0) {
task.Resolve(env, CreateJsUndefined(env));
} else {
@ -546,6 +545,10 @@ napi_value JsUIExtensionContext::OnConnectAbility(napi_env env, NapiCallbackInfo
// Unwrap want and connection
AAFwk::Want want;
sptr<JSUIExtensionConnection> connection = new JSUIExtensionConnection(env);
if (connection == nullptr) {
TAG_LOGE(AAFwkTag::UI_EXT, "make conn failed");
return CreateJsUndefined(env);
}
if (!AppExecFwk::UnwrapWant(env, info.argv[0], want) ||
!CheckConnectionParam(env, info.argv[1], connection, want)) {
ThrowInvalidParamError(env,
@ -945,6 +948,12 @@ napi_value JsUIExtensionContext::OpenAtomicServiceInner(napi_env env, NapiCallba
system_clock::now().time_since_epoch()).count());
want.SetParam(Want::PARAM_RESV_START_TIME, startTime);
napi_value result = nullptr;
auto context = context_.lock();
if (context == nullptr) {
TAG_LOGW(AAFwkTag::UI_EXT, "context is released");
ThrowError(env, AbilityErrorCode::ERROR_CODE_INVALID_CONTEXT);
return CreateJsUndefined(env);
}
AddFreeInstallObserver(env, want, nullptr, &result, true);
RuntimeTask task = [env, element = want.GetElement(), startTime, &observer = freeInstallObserver_](
int resultCode, const AAFwk::Want& want, bool isInner) {
@ -968,16 +977,9 @@ napi_value JsUIExtensionContext::OpenAtomicServiceInner(napi_env env, NapiCallba
observer->OnInstallFinished(bundleName, abilityName, startTime, abilityResult);
}
};
auto context = context_.lock();
if (context == nullptr) {
TAG_LOGW(AAFwkTag::UI_EXT, "context is released");
ThrowError(env, AbilityErrorCode::ERROR_CODE_INVALID_CONTEXT);
return CreateJsUndefined(env);
} else {
want.SetParam(Want::PARAM_RESV_FOR_RESULT, true);
auto curRequestCode = context->GenerateCurRequestCode();
context->OpenAtomicService(want, options, curRequestCode, std::move(task));
}
want.SetParam(Want::PARAM_RESV_FOR_RESULT, true);
auto curRequestCode = context->GenerateCurRequestCode();
context->OpenAtomicService(want, options, curRequestCode, std::move(task));
TAG_LOGD(AAFwkTag::UI_EXT, "end");
return result;
}

View File

@ -57,7 +57,6 @@ std::shared_ptr<UIExtensionContext> UIExtension::CreateAndInitContext(
ExtensionBase<UIExtensionContext>::CreateAndInitContext(record, application, handler, token);
if (context == nullptr) {
TAG_LOGE(AAFwkTag::UI_EXT, "UIExtension CreateAndInitContext context is nullptr");
return context;
}
return context;
}

View File

@ -27,12 +27,12 @@ Extension *UIExtensionModuleLoader::Create(const std::unique_ptr<Runtime>& runti
std::map<std::string, std::string> UIExtensionModuleLoader::GetParams()
{
std::map<std::string, std::string> params;
// type means extension type in ExtensionAbilityType of extension_ability_info.h, 256 means uiextension.
params.insert(std::pair<std::string, std::string>("type", "256"));
// extension name
params.insert(std::pair<std::string, std::string>("name", "UIExtensionAbility"));
return params;
return {
// type means extension type in ExtensionAbilityType of extension_ability_info.h, 256 means uiextension.
{"type", "256"},
// extension name
{"name", "UIExtensionAbility"}
};
}
extern "C" __attribute__((visibility("default"))) void* OHOS_EXTENSION_GetExtensionModule()