From 24034e49a95680efb923b86842025ba279dfde43 Mon Sep 17 00:00:00 2001 From: zhangzezhong Date: Wed, 18 Jun 2025 09:44:49 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9stageMode=E9=BB=98=E8=AE=A4?= =?UTF-8?q?=E5=80=BC=E6=9C=89=E8=AF=AF=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhangzezhong --- frameworks/ets/ani/BUILD.gn | 1 - .../ets/ani/native_constructor/BUILD.gn | 41 ------- .../context_native_constructor.cpp | 115 ------------------ .../ets/application/AbilityStageContext.ets | 10 +- .../ets/ets/application/BaseContext.ets | 4 +- frameworks/ets/ets/application/Context.ets | 13 +- .../ets/ets/application/ExtensionContext.ets | 16 +-- .../ets/ets/application/UIAbilityContext.ets | 21 +--- 8 files changed, 12 insertions(+), 209 deletions(-) delete mode 100644 frameworks/ets/ani/native_constructor/BUILD.gn delete mode 100644 frameworks/ets/ani/native_constructor/context_native_constructor.cpp diff --git a/frameworks/ets/ani/BUILD.gn b/frameworks/ets/ani/BUILD.gn index f487ec8a122..ea1f0d27eaa 100644 --- a/frameworks/ets/ani/BUILD.gn +++ b/frameworks/ets/ani/BUILD.gn @@ -23,7 +23,6 @@ group("ani_packages") { "${ability_runtime_path}/frameworks/ets/ani/app_manager:ability_app_manager_ani_kit", "${ability_runtime_path}/frameworks/ets/ani/form_extension_ability:form_extension_ability_etc", "${ability_runtime_path}/frameworks/ets/ani/insight_intent/insight_intent_driver:insight_intent_driver_ani_kit", - "${ability_runtime_path}/frameworks/ets/ani/native_constructor:context_ani", "${ability_runtime_path}/frameworks/ets/ani/uri_permission_manager:uri_permission_manager_abc_etc", "${ability_runtime_path}/frameworks/ets/ani/uri_permission_manager:uri_permission_manager_ani_kit", "${ability_runtime_path}/frameworks/ets/ani/wantagent:aniwantagent", diff --git a/frameworks/ets/ani/native_constructor/BUILD.gn b/frameworks/ets/ani/native_constructor/BUILD.gn deleted file mode 100644 index 3637f8a2acd..00000000000 --- a/frameworks/ets/ani/native_constructor/BUILD.gn +++ /dev/null @@ -1,41 +0,0 @@ -# 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. - -import("//build/ohos.gni") -import("//foundation/ability/ability_runtime/ability_runtime.gni") - -ohos_shared_library("context_ani") { - branch_protector_ret = "pac_ret" - sanitize = { - cfi = true - cfi_cross_dso = true - cfi_vcall_icall_only = true - debug = false - } - - sources = [ - "context_native_constructor.cpp", - ] - - include_dirs = [ - "${ability_runtime_services_path}/common/include", - ] - - external_deps = [ - "hilog:libhilog", - "runtime_core:ani", - ] - subsystem_name = "ability" - part_name = "ability_runtime" - output_extension = "so" -} diff --git a/frameworks/ets/ani/native_constructor/context_native_constructor.cpp b/frameworks/ets/ani/native_constructor/context_native_constructor.cpp deleted file mode 100644 index b402dad70d5..00000000000 --- a/frameworks/ets/ani/native_constructor/context_native_constructor.cpp +++ /dev/null @@ -1,115 +0,0 @@ -/* - * 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 -#include -#include "hilog_tag_wrapper.h" - -namespace OHOS { -namespace AbilityRuntime { -void ContextConstructor() -{ -} - -void AbilityStageContextConstructor() -{ -} - -void ExtensionContextConstructor() -{ -} - -void UIAbilityContextConstructor() -{ -} - -extern "C" { -ANI_EXPORT ani_status ANI_Constructor(ani_vm *vm, uint32_t *result) -{ - ani_env *env; - if (vm == nullptr || result == nullptr) { - TAG_LOGE(AAFwkTag::STSRUNTIME, "Illegal VM or result"); - return ANI_ERROR; - } - if (ANI_OK != vm->GetEnv(ANI_VERSION_1, &env)) { - TAG_LOGE(AAFwkTag::STSRUNTIME, "Unsupported ANI_VERSION_1"); - return ANI_ERROR; - } - // class Context - ani_class contextClass; - static const char *contextClassName = "Lapplication/Context/Context;"; - if (ANI_OK != env->FindClass(contextClassName, &contextClass)) { - TAG_LOGE(AAFwkTag::STSRUNTIME, "Not found class %{public}s.", contextClassName); - return ANI_NOT_FOUND; - } - std::array classMethods_context = { - ani_native_function {"", ":V", reinterpret_cast(ContextConstructor)}, - }; - if (ANI_OK != env->Class_BindNativeMethods(contextClass, classMethods_context.data(), - classMethods_context.size())) { - TAG_LOGE(AAFwkTag::STSRUNTIME, "Cannot bind native ctor to class %{public}s.", contextClassName); - return ANI_ERROR; - }; - // class ExtensionContext - ani_class extensionContextClass; - static const char *extensionContextClassName = "Lapplication/ExtensionContext/ExtensionContext;"; - if (ANI_OK != env->FindClass(extensionContextClassName, &extensionContextClass)) { - TAG_LOGE(AAFwkTag::STSRUNTIME, "Not found class %{public}s.", extensionContextClassName); - return ANI_NOT_FOUND; - } - std::array classMethods_extensionContext = { - ani_native_function {"", ":V", reinterpret_cast(ExtensionContextConstructor)}, - }; - if (ANI_OK != env->Class_BindNativeMethods(extensionContextClass, classMethods_extensionContext.data(), - classMethods_extensionContext.size())) { - TAG_LOGE(AAFwkTag::STSRUNTIME, "Cannot bind native ctor to class %{public}s.", extensionContextClassName); - return ANI_ERROR; - }; - // class UIAbilityContext - ani_class uiAbilityClass; - static const char *uiAbilityClassName = "Lapplication/UIAbilityContext/UIAbilityContext;"; - if (ANI_OK != env->FindClass(uiAbilityClassName, &uiAbilityClass)) { - TAG_LOGE(AAFwkTag::STSRUNTIME, "Not found class %{public}s.", uiAbilityClassName); - return ANI_NOT_FOUND; - } - std::array classMethods_uiAbility = { - ani_native_function {"", ":V", reinterpret_cast(UIAbilityContextConstructor)}, - }; - if (ANI_OK != env->Class_BindNativeMethods(uiAbilityClass, classMethods_uiAbility.data(), - classMethods_uiAbility.size())) { - TAG_LOGE(AAFwkTag::STSRUNTIME, "Cannot bind native ctor to class %{public}s.", uiAbilityClassName); - return ANI_ERROR; - }; - // class AbilityStageContext - ani_class abilityStageContextClass; - static const char *abilityStageContextClassName = "Lapplication/AbilityStageContext/AbilityStageContext;"; - if (ANI_OK != env->FindClass(abilityStageContextClassName, &abilityStageContextClass)) { - TAG_LOGE(AAFwkTag::STSRUNTIME, "Not found class %{public}s.", abilityStageContextClassName); - return ANI_NOT_FOUND; - } - std::array classMethods_abilityStage = { - ani_native_function {"", ":V", reinterpret_cast(AbilityStageContextConstructor)}, - }; - if (ANI_OK != env->Class_BindNativeMethods(abilityStageContextClass, classMethods_abilityStage.data(), - classMethods_abilityStage.size())) { - TAG_LOGE(AAFwkTag::STSRUNTIME, "Cannot bind native ctor to class %{public}s.", abilityStageContextClassName); - return ANI_ERROR; - }; - - *result = ANI_VERSION_1; - return ANI_OK; -} -} -} // namespace AbilityRuntime -} // namespace OHOS \ No newline at end of file diff --git a/frameworks/ets/ets/application/AbilityStageContext.ets b/frameworks/ets/ets/application/AbilityStageContext.ets index 5fe7eafea1e..a1ac3ade044 100644 --- a/frameworks/ets/ets/application/AbilityStageContext.ets +++ b/frameworks/ets/ets/application/AbilityStageContext.ets @@ -18,14 +18,6 @@ import { Configuration } from '@ohos.app.ability.Configuration' import { HapModuleInfo } from 'bundleManager.HapModuleInfo'; export default class AbilityStageContext extends Context { - static { - loadLibrary("context_ani"); - } config?: Configuration; - currentHapModuleInfo: HapModuleInfo; - native constructor(); - constructor(currentHapModuleInfo: HapModuleInfo) { - super(); - this.currentHapModuleInfo = currentHapModuleInfo; - } + currentHapModuleInfo!: HapModuleInfo; } \ No newline at end of file diff --git a/frameworks/ets/ets/application/BaseContext.ets b/frameworks/ets/ets/application/BaseContext.ets index 2e9e42158db..9c11325513c 100644 --- a/frameworks/ets/ets/application/BaseContext.ets +++ b/frameworks/ets/ets/application/BaseContext.ets @@ -14,6 +14,6 @@ */ export default class BaseContext { - public nativeContext : long = 0; - public stageMode: boolean; + public nativeContext: long = 0; + public stageMode: boolean = true; } \ No newline at end of file diff --git a/frameworks/ets/ets/application/Context.ets b/frameworks/ets/ets/application/Context.ets index 29dd7bdd7a5..0a441fb4944 100644 --- a/frameworks/ets/ets/application/Context.ets +++ b/frameworks/ets/ets/application/Context.ets @@ -24,25 +24,16 @@ import { BusinessError } from '@ohos.base'; import AsyncCallbackWrapper from '../utils/AbilityUtils'; export class Context extends BaseContext { - static { - loadLibrary("context_ani"); - } area: contextConstant.AreaMode = contextConstant.AreaMode.EL1; filesDir: string = ""; tempDir: string = ""; preferencesDir: string = ""; databaseDir: string = ""; cacheDir: string = ""; - applicationInfo: ApplicationInfo; + applicationInfo!: ApplicationInfo; eventHub: EventHub = new EventHub(); - resourceManager: resmgr.ResourceManager; + resourceManager!: resmgr.ResourceManager; processName: string = ""; - native constructor(); - constructor(applicationInfo: ApplicationInfo, resourceManager: resmgr.ResourceManager) { - super(); - this.applicationInfo = applicationInfo; - this.resourceManager = resourceManager; - } public native getApplicationContextSync(): ApplicationContext; public native createModuleResourceManagerSync(bundleName: string, moduleName: string): resmgr.ResourceManager; diff --git a/frameworks/ets/ets/application/ExtensionContext.ets b/frameworks/ets/ets/application/ExtensionContext.ets index 593e3575627..fa9e0f5c446 100644 --- a/frameworks/ets/ets/application/ExtensionContext.ets +++ b/frameworks/ets/ets/application/ExtensionContext.ets @@ -19,17 +19,7 @@ import { Configuration } from '@ohos.app.ability.Configuration'; import { HapModuleInfo } from 'bundleManager.HapModuleInfo'; export default class ExtensionContext extends Context { - static { - loadLibrary("context_ani"); - } - extensionAbilityInfo: ExtensionAbilityInfo; - config: Configuration; - currentHapModuleInfo: HapModuleInfo; - native constructor(); - constructor(config: Configuration, extensionAbilityInfo: ExtensionAbilityInfo, currentHapModuleInfo: HapModuleInfo) { - super(); - this.config = config; - this.extensionAbilityInfo = extensionAbilityInfo; - this.currentHapModuleInfo = currentHapModuleInfo; - } + extensionAbilityInfo!: ExtensionAbilityInfo; + config!: Configuration; + currentHapModuleInfo!: HapModuleInfo; } \ No newline at end of file diff --git a/frameworks/ets/ets/application/UIAbilityContext.ets b/frameworks/ets/ets/application/UIAbilityContext.ets index 6cd38d8892b..52818f2ce39 100644 --- a/frameworks/ets/ets/application/UIAbilityContext.ets +++ b/frameworks/ets/ets/application/UIAbilityContext.ets @@ -32,23 +32,10 @@ import { LocalStorage } from '@ohos.arkui.stateManagement'; type Any = Object | null | undefined export default class UIAbilityContext extends Context { - static { - loadLibrary("context_ani"); - } - - config: Configuration; - abilityInfo: AbilityInfo; - windowStage: window.WindowStage; - currentHapModuleInfo: HapModuleInfo; - - native constructor(); - constructor(config: Configuration, abilityInfo: AbilityInfo, windowStage: window.WindowStage, currentHapModuleInfo: HapModuleInfo) { - super(); - this.config = config; - this.abilityInfo = abilityInfo; - this.windowStage = windowStage; - this.currentHapModuleInfo = currentHapModuleInfo; - } + config!: Configuration; + abilityInfo!: AbilityInfo; + windowStage!: window.WindowStage; + currentHapModuleInfo!: HapModuleInfo; private static native nativeTransferStatic(input: ESValue): Object; private static native nativeTransferDynamic(input: Object): ESValue; -- Gitee