mirror of
https://github.com/openharmony/ability_ability_runtime.git
synced 2026-08-25 12:23:20 -04:00
!14616 ani add ExtensionContext回合
Merge pull request !14616 from zhangzezhong/sts_ExtensionContext
This commit is contained in:
@@ -144,6 +144,23 @@ ohos_prebuilt_etc("ability_runtime_want_constant_abc_etc") {
|
||||
deps = [ ":ability_runtime_want_constant_abc" ]
|
||||
}
|
||||
|
||||
generate_static_abc("ability_runtime_extension_context_abc") {
|
||||
base_url = "./"
|
||||
files = [ "./application/ExtensionContext.ets" ]
|
||||
|
||||
is_boot_abc = "True"
|
||||
device_dst_file =
|
||||
"/system/framework/ability_runtime_extension_context_abc.abc"
|
||||
}
|
||||
|
||||
ohos_prebuilt_etc("ability_runtime_extension_context_abc_etc") {
|
||||
source = "$target_out_dir/ability_runtime_extension_context_abc.abc"
|
||||
module_install_dir = "framework"
|
||||
subsystem_name = "ability"
|
||||
part_name = "ability_runtime"
|
||||
deps = [ ":ability_runtime_extension_context_abc" ]
|
||||
}
|
||||
|
||||
group("ets_packages") {
|
||||
deps = [
|
||||
":ability_runtime_ability_constant_abc_etc",
|
||||
@@ -154,5 +171,6 @@ group("ets_packages") {
|
||||
":ability_runtime_start_options_abc_etc",
|
||||
":ability_runtime_want_abc_etc",
|
||||
":ability_runtime_want_constant_abc_etc",
|
||||
":ability_runtime_extension_context_abc_etc",
|
||||
]
|
||||
}
|
||||
|
||||
@@ -17,9 +17,6 @@ import Context from 'application.Context'
|
||||
import {ExtensionAbilityInfo} from 'bundleManager.ExtensionAbilityInfo'
|
||||
|
||||
export default class ExtensionContext extends Context {
|
||||
static {
|
||||
loadLibrary("context_ani");
|
||||
}
|
||||
extensionAbilityInfo: ExtensionAbilityInfo;
|
||||
native constructor();
|
||||
constructor(extensionAbilityInfo: ExtensionAbilityInfo) {
|
||||
|
||||
@@ -59,6 +59,7 @@ ohos_shared_library("ability_context_native") {
|
||||
"ability_runtime/connection_manager.cpp",
|
||||
"ability_runtime/dialog_request_callback_impl.cpp",
|
||||
"ability_runtime/dialog_ui_extension_callback.cpp",
|
||||
"ability_runtime/ets_extension_context.cpp",
|
||||
"ability_runtime/js_extension_context.cpp",
|
||||
"ability_runtime/local_call_container.cpp",
|
||||
"ability_runtime/local_call_record.cpp",
|
||||
@@ -92,6 +93,8 @@ ohos_shared_library("ability_context_native") {
|
||||
"image_framework:image_native",
|
||||
"ipc:ipc_core",
|
||||
"napi:ace_napi",
|
||||
"runtime_core:ani",
|
||||
"bundle_framework:bms_ani_common",
|
||||
]
|
||||
public_external_deps = [
|
||||
"ability_base:extractortool",
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* Copyright (c) 2025 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ets_extension_context.h"
|
||||
|
||||
#include "common_fun_ani.h"
|
||||
#include "hilog_tag_wrapper.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
|
||||
bool SetExtensionAbilityInfo(ani_env *aniEnv, ani_class contextClass, ani_object contextObj,
|
||||
std::shared_ptr<Context> context, std::shared_ptr<AppExecFwk::AbilityInfo> abilityInfo)
|
||||
{
|
||||
bool iRet = false;
|
||||
if (aniEnv == nullptr || context == nullptr || abilityInfo == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::CONTEXT, "aniEnv or context or abilityInfo is nullptr");
|
||||
return iRet;
|
||||
}
|
||||
auto hapModuleInfo = context->GetHapModuleInfo();
|
||||
ani_status status = ANI_OK;
|
||||
if (abilityInfo && hapModuleInfo) {
|
||||
auto isExist = [&abilityInfo](const AppExecFwk::ExtensionAbilityInfo &info) {
|
||||
TAG_LOGD(AAFwkTag::CONTEXT, "%{public}s, %{public}s", info.bundleName.c_str(), info.name.c_str());
|
||||
return info.bundleName == abilityInfo->bundleName && info.name == abilityInfo->name;
|
||||
};
|
||||
auto infoIter =
|
||||
std::find_if(hapModuleInfo->extensionInfos.begin(), hapModuleInfo->extensionInfos.end(), isExist);
|
||||
if (infoIter == hapModuleInfo->extensionInfos.end()) {
|
||||
TAG_LOGE(AAFwkTag::CONTEXT, "set extensionAbilityInfo fail");
|
||||
return iRet;
|
||||
}
|
||||
ani_field extensionAbilityInfoField;
|
||||
status = aniEnv->Class_FindField(contextClass, "extensionAbilityInfo", &extensionAbilityInfoField);
|
||||
if (status != ANI_OK) {
|
||||
TAG_LOGE(AAFwkTag::CONTEXT, "status: %{public}d", status);
|
||||
return iRet;
|
||||
}
|
||||
ani_object extAbilityInfoObj = AppExecFwk::CommonFunAni::ConvertExtensionInfo(aniEnv, *infoIter);
|
||||
status = aniEnv->Object_SetField_Ref(
|
||||
contextObj, extensionAbilityInfoField, reinterpret_cast<ani_ref>(extAbilityInfoObj));
|
||||
if (status != ANI_OK) {
|
||||
TAG_LOGE(AAFwkTag::CONTEXT, "status: %{public}d", status);
|
||||
return iRet;
|
||||
}
|
||||
iRet = true;
|
||||
}
|
||||
return iRet;
|
||||
}
|
||||
|
||||
void CreatEtsExtensionContext(ani_env *aniEnv, ani_class contextClass, ani_object contextObj,
|
||||
std::shared_ptr<ExtensionContext> context, std::shared_ptr<AppExecFwk::AbilityInfo> abilityInfo)
|
||||
{
|
||||
TAG_LOGD(AAFwkTag::CONTEXT, "CreatEtsExtensionContext Call");
|
||||
if (aniEnv == nullptr || context == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::CONTEXT, "aniEnv or context is nullptr");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!SetExtensionAbilityInfo(aniEnv, contextClass, contextObj, context, abilityInfo)) {
|
||||
TAG_LOGE(AAFwkTag::CONTEXT, "SetExtensionAbilityInfo fail");
|
||||
return;
|
||||
}
|
||||
}
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright (c) 2025 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_ABILITY_RUNTIME_STS_EXTENSION_CONTEXT_H
|
||||
#define OHOS_ABILITY_RUNTIME_STS_EXTENSION_CONTEXT_H
|
||||
|
||||
#include "extension_context.h"
|
||||
#include "ani.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
void CreatEtsExtensionContext(ani_env* aniEnv, ani_class contextClass, ani_object contextObj,
|
||||
std::shared_ptr<ExtensionContext> context,
|
||||
std::shared_ptr<AppExecFwk::AbilityInfo> abilityInfo);
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_ABILITY_RUNTIME_STS_EXTENSION_CONTEXT_H
|
||||
Reference in New Issue
Block a user