diff --git a/bundle.json b/bundle.json index 1f9d759a7c8469cbeb587bde73405a163df6681e..88d49a502f88fc9204e684fd496059c02ff9d498 100644 --- a/bundle.json +++ b/bundle.json @@ -20,7 +20,8 @@ "SystemCapability.Ability.AbilityRuntime.QuickFix", "SystemCapability.Ability.AbilityTools.AbilityAssistant", "SystemCapability.Ability.AppStartup", - "SystemCapability.Ability.AppExtension.PhotoEditorExtension" + "SystemCapability.Ability.AppExtension.PhotoEditorExtension", + "SystemCapability.Ability.AppExtension.VerticalPanel" ], "features": [ "ability_runtime_auto_fill_ability", diff --git a/ets_environment/frameworks/ets_environment/BUILD.gn b/ets_environment/frameworks/ets_environment/BUILD.gn index 32cc779fb52836d7c206faa339cb8411df87faf7..1c67d800122633704574c09186d75869cc286013 100644 --- a/ets_environment/frameworks/ets_environment/BUILD.gn +++ b/ets_environment/frameworks/ets_environment/BUILD.gn @@ -46,6 +46,10 @@ ohos_shared_library("ets_environment") { defines = [] + deps = [ + "${ability_runtime_innerkits_path}/connect_server_manager:connect_server_manager", + ] + external_deps = [ "c_utils:utils", "eventhandler:libeventhandler", diff --git a/ets_environment/frameworks/ets_environment/src/ets_environment.cpp b/ets_environment/frameworks/ets_environment/src/ets_environment.cpp index 5b75b2f7de78e7e446357600eebf59e57ad9435a..5938a47aaed998be3cd9c8159060ba4367974d50 100644 --- a/ets_environment/frameworks/ets_environment/src/ets_environment.cpp +++ b/ets_environment/frameworks/ets_environment/src/ets_environment.cpp @@ -15,6 +15,7 @@ #include "ets_environment.h" +#include #include #include #include @@ -27,12 +28,14 @@ #include "static_core/plugins/ets/runtime/ets_namespace_manager.h" #include "ets_ani_expo.h" +#include "static_core/runtime/tooling/inspector/debugger_arkapi.h" #ifdef LIKELY #undef LIKELY #endif #ifdef UNLIKELY #undef UNLIKELY #endif +#include "connect_server_manager.h" #include "dynamic_loader.h" #include "elf_factory.h" #include "event_handler.h" @@ -51,9 +54,11 @@ const char ETS_ANI_GET_CREATEDVMS[] = "ANI_GetCreatedVMs"; const char ETS_LIB_PATH[] = "libets_interop_js_napi.z.so"; const char BOOT_PATH[] = "/system/framework/bootpath.json"; const char BACKTRACE[] = "=====================Backtrace========================"; +static const std::string DEBUGGER = "@Debugger"; using CreateVMETSRuntimeType = ani_status (*)(const ani_options *options, uint32_t version, ani_vm **result); using ANIGetCreatedVMsType = ani_status (*)(ani_vm **vms_buffer, ani_size vms_buffer_length, ani_size *result); +using DebuggerPostTask = std::function &&)>; const char ETS_SDK_NSNAME[] = "ets_sdk"; const char ETS_SYS_NSNAME[] = "ets_system"; @@ -215,7 +220,7 @@ void ETSEnvironment::InitETSSysNS(const std::string &path) dlns_inherit(&ns, &ndk, "allow_all_shared_libs"); } -bool ETSEnvironment::Initialize() +bool ETSEnvironment::Initialize(const std::shared_ptr eventRunner, bool isStartWithDebug) { TAG_LOGD(AAFwkTag::ETSRUNTIME, "Initialize called"); if (!LoadRuntimeApis()) { @@ -228,12 +233,25 @@ bool ETSEnvironment::Initialize() return false; } + InitEventHandler(eventRunner); + std::vector options; // Create boot-panda-files options std::string bootString = "--ext:--boot-panda-files=" + bootfiles; options.push_back(ani_option { bootString.data(), nullptr }); options.push_back(ani_option { "--ext:--compiler-enable-jit=false", nullptr }); options.push_back(ani_option { "--ext:--log-level=info", nullptr }); + options.push_back(ani_option { "--ext:taskpool-support-interop=true", nullptr }); + std::string interpreerMode = "--ext:--interpreter-type=cpp"; + std::string debugEnalbeMode = "--ext:--debugger-enable=true"; + std::string debugLibraryPathMode = "--ext:--debugger-library-path=/system/lib64/libarkinspector.so"; + std::string breadonstartMode = "--ext:--debugger-break-on-start"; + if (isStartWithDebug) { + options.push_back(ani_option { interpreerMode.data(), nullptr }); + options.push_back(ani_option { debugEnalbeMode.data(), nullptr }); + options.push_back(ani_option { debugLibraryPathMode.data(), nullptr }); + options.push_back(ani_option { breadonstartMode.data(), nullptr }); + } ani_options optionsPtr = { options.size(), options.data() }; ani_status status = ANI_ERROR; if ((status = lazyApis_.ANI_CreateVM(&optionsPtr, ANI_VERSION_1, &vmEntry_.aniVm_)) != ANI_OK) { @@ -544,8 +562,8 @@ ETSEnvFuncs *ETSEnvironment::RegisterFuncs() .InitETSSysNS = [](const std::string &path) { ETSEnvironment::InitETSSysNS(path); }, - .Initialize = []() { - return ETSEnvironment::GetInstance()->Initialize(); + .Initialize = [](const std::shared_ptr eventRunner, bool isStartWithDebug) { + return ETSEnvironment::GetInstance()->Initialize(eventRunner, isStartWithDebug); }, .RegisterUncaughtExceptionHandler = [](const ETSUncaughtExceptionInfo &exceptionInfo) { ETSEnvironment::GetInstance()->RegisterUncaughtExceptionHandler(exceptionInfo); @@ -572,10 +590,123 @@ ETSEnvFuncs *ETSEnvironment::RegisterFuncs() }, .PreloadSystemClass = [](const char *className) { ETSEnvironment::GetInstance()->PreloadSystemClass(className); + }, + .SetExtensionApiCheckCallback = []( + std::function &cb) { + ark::ets::EtsNamespaceManager::SetExtensionApiCheckCallback(cb); + }, + .RemoveInstance = [](uint32_t instanceId) { + return ETSEnvironment::GetInstance()->RemoveInstance(instanceId); + }, + .StopDebugMode = [](void *jsVm) { + return ETSEnvironment::GetInstance()->StopDebugMode(jsVm); + }, + .StartDebuggerForSocketPair = [](std::string &option, int32_t socketFd) { + return ETSEnvironment::GetInstance()->StartDebuggerForSocketPair(option, socketFd); + }, + .NotifyDebugMode = [](uint32_t tid, uint32_t instanceId, bool isStartWithDebug, void *jsVm) { + return ETSEnvironment::GetInstance()->NotifyDebugMode(tid, instanceId, isStartWithDebug, jsVm); + }, + .BroadcastAndConnect = [](const std::string& bundleName, int socketFd) { + return ETSEnvironment::GetInstance()->BroadcastAndConnect(bundleName, socketFd); } }; return &funcs; } + +void ETSEnvironment::NotifyDebugMode(uint32_t tid, uint32_t instanceId, bool isStartWithDebug, void *jsVm) +{ + TAG_LOGD(AAFwkTag::ETSRUNTIME, "Start"); + AbilityRuntime::ConnectServerManager::Get().StoreInstanceMessage(getproctid(), instanceId, "Debugger"); + auto task = GetDebuggerPostTask(); + ark::ArkDebugNativeAPI::NotifyDebugMode(tid, instanceId, isStartWithDebug, jsVm, task); +} + +void ETSEnvironment::RemoveInstance(uint32_t instanceId) +{ + TAG_LOGD(AAFwkTag::ETSRUNTIME, "Start"); + AbilityRuntime::ConnectServerManager::Get().RemoveInstance(instanceId); +} + +void ETSEnvironment::StopDebugMode(void *jsVm) +{ + TAG_LOGD(AAFwkTag::ETSRUNTIME, "Start"); + if (debugMode_) { + ark::ArkDebugNativeAPI::StopDebugger(jsVm); + } +} + +void ETSEnvironment::StartDebuggerForSocketPair(std::string &option, int32_t socketFd) +{ + TAG_LOGD(AAFwkTag::ETSRUNTIME, "Start"); + int32_t identifierId = ParseHdcRegisterOption(option); + if (identifierId == -1) { + TAG_LOGE(AAFwkTag::ETSRUNTIME, "Abnormal parsing of tid results"); + return; + } + debugMode_ = ark::ArkDebugNativeAPI::StartDebuggerForSocketPair(ParseHdcRegisterOption(option), socketFd); +} + +DebuggerPostTask ETSEnvironment::GetDebuggerPostTask() +{ + auto debuggerPostTask = [weak = weak_from_this()](std::function&& task) { + auto etsEnv = weak.lock(); + if (etsEnv == nullptr) { + TAG_LOGE(AAFwkTag::ETSRUNTIME, "StsEnv is invalid"); + return; + } + etsEnv->PostTask(task, "ETSEnvironment:GetDebuggerPostTask", 0); + }; + return debuggerPostTask; +} + +int32_t ETSEnvironment::ParseHdcRegisterOption(std::string& option) +{ + int32_t pid = -1; + TAG_LOGD(AAFwkTag::ETSRUNTIME, "Start"); + std::size_t pos = option.find_first_of(":"); + if (pos == std::string::npos) { + return pid; + } + std::string idStr = option.substr(pos + 1); + pos = idStr.find(DEBUGGER); + if (pos == std::string::npos) { + return pid; + } + idStr = idStr.substr(0, pos); + pos = idStr.find("@"); + if (pos != std::string::npos) { + idStr = idStr.substr(pos + 1); + } + auto res = std::from_chars(idStr.c_str(), idStr.c_str() + idStr.size(), pid); + if (res.ec != std::errc()) { + TAG_LOGE(AAFwkTag::AA_TOOL, "pid from_chars (%{public}s) failed", idStr.c_str()); + } + return pid; +} + +void ETSEnvironment::InitEventHandler(const std::shared_ptr &eventRunner) +{ + TAG_LOGD(AAFwkTag::ETSRUNTIME, "InitEventHandler called"); + if (eventRunner != nullptr) { + eventHandler_ = std::make_shared(eventRunner); + } +} + +void ETSEnvironment::PostTask(const std::function &task, const std::string &name, int64_t delayTime) +{ + TAG_LOGD(AAFwkTag::ETSRUNTIME, "PostTask called"); + if (eventHandler_ != nullptr) { + eventHandler_->PostTask(task, name, delayTime); + } +} + +void ETSEnvironment::BroadcastAndConnect(const std::string& bundleName, int socketFd) +{ + TAG_LOGD(AAFwkTag::ETSRUNTIME, "BroadcastAndConnect called"); + AbilityRuntime::ConnectServerManager::Get().SendInstanceMessageAll(nullptr); + AbilityRuntime::ConnectServerManager::Get().StartConnectServer(bundleName, socketFd, false); +} } // namespace EtsEnv } // namespace OHOS diff --git a/ets_environment/interfaces/inner_api/ets_environment.h b/ets_environment/interfaces/inner_api/ets_environment.h index d8652e9011f1b567c3c1028fb4f753bf16e57f3d..06780e1571e5989e2067407604e5dc310661f65d 100644 --- a/ets_environment/interfaces/inner_api/ets_environment.h +++ b/ets_environment/interfaces/inner_api/ets_environment.h @@ -41,6 +41,8 @@ struct ETSRuntimeAPI { ani_status (*ANI_CreateVM)(const ani_options *options, uint32_t version, ani_vm **result); }; +using DebuggerPostTask = std::function&&)>; + class ETSEnvironment final : public std::enable_shared_from_this { public: ETSEnvironment() {}; @@ -50,7 +52,7 @@ public: static void InitETSSysNS(const std::string &path); static ETSEnvFuncs *RegisterFuncs(); - bool Initialize(); + bool Initialize(const std::shared_ptr eventRunner, bool isDebug); void RegisterUncaughtExceptionHandler(const ETSUncaughtExceptionInfo &handle); ani_env *GetAniEnv(); bool HandleUncaughtError(); @@ -61,6 +63,15 @@ public: bool PostFork(void *napiEnv, const std::string &aotPath); bool PreloadSystemClass(const char *className); + void RemoveInstance(uint32_t instanceId); + void StopDebugMode(void *jsVm); + void StartDebuggerForSocketPair(std::string &option, int32_t socketFd); + void NotifyDebugMode(uint32_t tid, uint32_t instanceId, bool isStartWithDebug, void *jsVm); + void PostTask(const std::function &task, const std::string &name, int64_t delayTime); + void BroadcastAndConnect(const std::string& bundleName, int socketFd); + + DebuggerPostTask GetDebuggerPostTask(); + struct VMEntry { ani_vm *aniVm_; ani_env *aniEnv_; @@ -80,9 +91,13 @@ private: EtsEnv::ETSErrorObject GetETSErrorObject(); std::string GetErrorProperty(ani_error aniError, const char *property); bool LoadAbcLinker(ani_env *env, const std::string &modulePath, ani_class &abcCls, ani_object &abcObj); + void InitEventHandler(const std::shared_ptr &eventRunner); + int32_t ParseHdcRegisterOption(std::string& option); static ETSRuntimeAPI lazyApis_; VMEntry vmEntry_; ETSUncaughtExceptionInfo uncaughtExceptionInfo_; + std::shared_ptr eventHandler_; + bool debugMode_ = false; }; } // namespace EtsEnv } // namespace OHOS diff --git a/ets_environment/interfaces/inner_api/ets_interface.h b/ets_environment/interfaces/inner_api/ets_interface.h index ea3ebe495d26ebf2a5973a65f4d88bafc86d6e05..124563013b299e06c2e9bf88f13df33c438c852c 100644 --- a/ets_environment/interfaces/inner_api/ets_interface.h +++ b/ets_environment/interfaces/inner_api/ets_interface.h @@ -23,12 +23,18 @@ #include "ets_native_reference.h" #include "napi/native_api.h" +namespace OHOS { +namespace AppExecFwk { + class EventRunner; +} +} + extern "C" { struct ETSEnvFuncs { void (*InitETSSDKNS)(const std::string &path) = nullptr; void (*InitETSSysNS)(const std::string &path) = nullptr; - bool (*Initialize)() = nullptr; + bool (*Initialize)(const std::shared_ptr eventRunner, bool isDebug) = nullptr; void (*RegisterUncaughtExceptionHandler)( const OHOS::EtsEnv::ETSUncaughtExceptionInfo &uncaughtExceptionInfo) = nullptr; ani_env *(*GetAniEnv)() = nullptr; @@ -41,6 +47,14 @@ struct ETSEnvFuncs { void (*FinishPreload)() = nullptr; void (*PostFork)(void *napiEnv, const std::string &aotPath) = nullptr; void (*PreloadSystemClass)(const char *className) = nullptr; + void (*SetExtensionApiCheckCallback)( + std::function &cb) = nullptr; + void (*RemoveInstance)(uint32_t instanceId) = nullptr; + void (*StopDebugMode)(void *jsVm) = nullptr; + void (*StartDebuggerForSocketPair)(std::string &option, int32_t socketFd) = nullptr; + void (*NotifyDebugMode)(uint32_t tid, uint32_t instanceId, bool isStartWithDebug, + void *jsVm) = nullptr; + void (*BroadcastAndConnect)(const std::string& bundleName, int socketFd) = nullptr; }; } #endif // OHOS_ABILITY_RUNTIME_ETS_INTERFACE_H diff --git a/ets_environment/test/unittest/ets_environment_test/BUILD.gn b/ets_environment/test/unittest/ets_environment_test/BUILD.gn index 470009ccaa22072b432f557ee6ce7da4f944ae88..5adacb33093ce8771571d1d929081ce0cc7cebd1 100644 --- a/ets_environment/test/unittest/ets_environment_test/BUILD.gn +++ b/ets_environment/test/unittest/ets_environment_test/BUILD.gn @@ -32,7 +32,9 @@ template("ets_environment_test_template") { configs = [] - deps = [] + deps = [ + "${ability_runtime_innerkits_path}/connect_server_manager:connect_server_manager", + ] external_deps = [ "ability_runtime:runtime", diff --git a/ets_environment/test/unittest/ets_environment_test/ets_environment_test.cpp b/ets_environment/test/unittest/ets_environment_test/ets_environment_test.cpp index 855a6072b4facb1bea4ddaa0ceb978b24f856919..146d2d4001339b06433aeb34731a74a4905ec32d 100644 --- a/ets_environment/test/unittest/ets_environment_test/ets_environment_test.cpp +++ b/ets_environment/test/unittest/ets_environment_test/ets_environment_test.cpp @@ -251,7 +251,7 @@ HWTEST_F(EtsEnvironmentTest, Initialize_0100, TestSize.Level0) { auto etsEnv = std::make_shared(); ASSERT_NE(etsEnv, nullptr); - bool result = etsEnv->Initialize(); + bool result = etsEnv->Initialize(nullptr, false); EXPECT_FALSE(result); } @@ -353,5 +353,44 @@ HWTEST_F(EtsEnvironmentTest, PreloadSystemClass_0100, TestSize.Level0) auto result = etsEnv->PreloadSystemClass(className.c_str()); EXPECT_FALSE(result); } + +/** + * @tc.name: GetDebuggerPostTask_0100 + * @tc.desc: Sts environment GetDebuggerPostTask. + * @tc.type: FUNC + */ +HWTEST_F(EtsEnvironmentTest, GetDebuggerPostTask_0100, TestSize.Level0) +{ + auto etsEnv = std::make_shared(); + ASSERT_NE(etsEnv, nullptr); + auto task = etsEnv->GetDebuggerPostTask(); + ASSERT_NE(task, nullptr); +} + +/** + * @tc.name: ParseHdcRegisterOption_0100 + * @tc.desc: Js environment ParseHdcRegisterOption. + * @tc.type: FUNC + */ +HWTEST_F(EtsEnvironmentTest, ParseHdcRegisterOption_0100, TestSize.Level2) +{ + auto etsEnv = std::make_shared(); + ASSERT_NE(etsEnv, nullptr); + std::string option1 = ""; + int result1 = etsEnv->ParseHdcRegisterOption(option1); + ASSERT_EQ(result1, -1); + std::string option2 = "@"; + int result2 = etsEnv->ParseHdcRegisterOption(option2); + ASSERT_EQ(result2, -1); + std::string option3 = ":"; + int result3 = etsEnv->ParseHdcRegisterOption(option3); + ASSERT_EQ(result3, -1); + std::string option4 = "ark:123@Debugger"; + int result4 = etsEnv->ParseHdcRegisterOption(option4); + ASSERT_EQ(result4, 123); + std::string option5 = "ark:123@456@Debugger"; + int result5 = etsEnv->ParseHdcRegisterOption(option5); + ASSERT_EQ(result5, 456); +} } // namespace StsEnv } // namespace OHOS \ No newline at end of file diff --git a/frameworks/c/ability_runtime/src/application_context.cpp b/frameworks/c/ability_runtime/src/application_context.cpp index f7df0086b0d6c172c398f4c3f64c382c6b90b672..c8c94f8f29c68c81261713240a4780b5b71940a1 100644 --- a/frameworks/c/ability_runtime/src/application_context.cpp +++ b/frameworks/c/ability_runtime/src/application_context.cpp @@ -342,25 +342,4 @@ AbilityRuntime_ErrorCode OH_AbilityRuntime_StartSelfUIAbilityWithStartOptions(Ab OHOS::AAFwk::StartOptions startOptions = options->GetInnerStartOptions(); return ConvertToAPI18BusinessErrorCode(AbilityManagerClient::GetInstance()->StartSelfUIAbilityWithStartOptions( abilityWant, startOptions)); -} - -AbilityRuntime_ErrorCode OH_AbilityRuntime_ApplicationContextGetVersionCode(int64_t* versionCode) -{ - TAG_LOGD(AAFwkTag::APPKIT, "getVersionCode called"); - if (versionCode == nullptr) { - TAG_LOGE(AAFwkTag::APPKIT, "versionCode is null"); - return ABILITY_RUNTIME_ERROR_CODE_PARAM_INVALID; - } - const auto appContext = Context::GetApplicationContext(); - if (appContext == nullptr) { - TAG_LOGE(AAFwkTag::APPKIT, "appContext is null"); - return ABILITY_RUNTIME_ERROR_CODE_CONTEXT_NOT_EXIST; - } - const auto appApplicationInfo = appContext->GetApplicationInfo(); - if (appApplicationInfo == nullptr) { - TAG_LOGE(AAFwkTag::APPKIT, "applicationInfo is null"); - return ABILITY_RUNTIME_ERROR_CODE_GET_APPLICATION_INFO_FAILED; - } - *versionCode = static_cast(appApplicationInfo->versionCode); - return ABILITY_RUNTIME_ERROR_CODE_NO_ERROR; } \ No newline at end of file diff --git a/frameworks/js/napi/BUILD.gn b/frameworks/js/napi/BUILD.gn index ff8a2ff50318fccf62ee49590e67e509f6dbf307..2331587731dfc411f3935be36d6a605bf3a7fb2c 100644 --- a/frameworks/js/napi/BUILD.gn +++ b/frameworks/js/napi/BUILD.gn @@ -26,6 +26,7 @@ group("napi_packages") { "${ability_runtime_napi_path}/ability_context:abilitycontext_napi", "${ability_runtime_napi_path}/ability_manager:abilitymanager", "${ability_runtime_napi_path}/ability_manager:abilitymanager_napi", + "${ability_runtime_napi_path}/ability_vertical_panel:verticalpanelmanager_napi", "${ability_runtime_napi_path}/action_extension_ability:actionextensionability_napi", "${ability_runtime_napi_path}/app/ability_delegator:abilitydelegatorregistry", "${ability_runtime_napi_path}/app/ability_delegator:abilitydelegatorregistry_napi", diff --git a/frameworks/js/napi/ability_vertical_panel/BUILD.gn b/frameworks/js/napi/ability_vertical_panel/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..05249c2d11b9fd836574bf7b7849093a1ebe88e0 --- /dev/null +++ b/frameworks/js/napi/ability_vertical_panel/BUILD.gn @@ -0,0 +1,68 @@ +# 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("verticalpanelmanager_napi") { + sanitize = { + integer_overflow = true + ubsan = true + boundary_sanitize = true + cfi = true + cfi_cross_dso = true + cfi_vcall_icall_only = true + debug = false + } + + include_dirs = [ + "include", + "${ability_runtime_path}/interfaces/inner_api/", + "${ability_runtime_path}/interfaces/kits/native/appkit/ability_runtime/", + ] + + sources = [ + "js_ability_vertical_panel.cpp", + "js_panel_start_callback.cpp", + "native_module.cpp", + ] + + configs = [ "${ability_runtime_services_path}/common:common_config" ] + + deps = [ + "${ability_runtime_innerkits_path}/napi_base_context:napi_base_context", + "${ability_runtime_innerkits_path}/runtime:runtime", + "${ability_runtime_napi_path}/inner/napi_common:napi_common", + "${ability_runtime_native_path}/ability:ability_context_native", + "${ability_runtime_native_path}/ability/native:abilitykit_native", + ] + + external_deps = [ + "ability_base:base", + "ability_base:want", + "access_token:libtokenid_sdk", + "ace_engine:ace_uicontent", + "c_utils:utils", + "hilog:libhilog", + "ipc:ipc_core", + ] + cflags_cc = [] + if (os_dlp_part_enabled) { + cflags_cc += [ "-DWITH_DLP" ] + } + + relative_install_dir = "module/app/ability" + + subsystem_name = "ability" + part_name = "ability_runtime" +} diff --git a/frameworks/js/napi/ability_vertical_panel/js_ability_vertical_panel.cpp b/frameworks/js/napi/ability_vertical_panel/js_ability_vertical_panel.cpp new file mode 100644 index 0000000000000000000000000000000000000000..d0ca7dc04ed48d69cb5505f29fa0395a338d373a --- /dev/null +++ b/frameworks/js/napi/ability_vertical_panel/js_ability_vertical_panel.cpp @@ -0,0 +1,248 @@ +/* + * 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 "js_ability_vertical_panel.h" + +#include "hilog_tag_wrapper.h" +#include "ipc_skeleton.h" +#include "js_panel_start_callback.h" +#include "js_error_utils.h" +#include "js_runtime_utils.h" +#include "napi_base_context.h" +#include "napi_common_util.h" +#include "napi_common_want.h" +#include "native_engine/native_value.h" +#include "screen_config.h" +#include "start_vertical_panel.h" +#include "tokenid_kit.h" + +namespace OHOS { +namespace AbilityRuntime { +constexpr int32_t INDEX_ZERO = 0; +constexpr int32_t INDEX_ONE = 1; +constexpr int32_t INDEX_TWO = 2; +constexpr int32_t INDEX_THREE = 3; +constexpr size_t ARGC_FOUR = 4; + +static void SetNamedProperty(napi_env env, napi_value dstObj, const char *objName, const char *propName) +{ + TAG_LOGD(AAFwkTag::VERTICAL_PANEL, "SetNamedProperty called"); + napi_value prop = nullptr; + napi_create_string_utf8(env, objName, NAPI_AUTO_LENGTH, &prop); + napi_set_named_property(env, dstObj, propName, prop); +} + +class JsAbilityVerticalPanel { +public: + JsAbilityVerticalPanel() = default; + ~JsAbilityVerticalPanel() = default; + + static void Finalizer(napi_env env, void *data, void *hint) + { + TAG_LOGI(AAFwkTag::VERTICAL_PANEL, "finalizer"); + std::unique_ptr(static_cast(data)); + } + + static napi_value StartVerticalPanel(napi_env env, napi_callback_info info) + { + GET_NAPI_INFO_AND_CALL(env, info, JsAbilityVerticalPanel, OnStartVerticalPanel); + } + +private: + static bool GetContext(napi_env env, napi_value value, + std::shared_ptr &abilityContext) + { + bool stageMode = false; + napi_status status = OHOS::AbilityRuntime::IsStageContext(env, value, stageMode); + if (status != napi_ok || !stageMode) { + TAG_LOGE(AAFwkTag::VERTICAL_PANEL, "Get context It is not a stage mode"); + return false; + } + + auto context = AbilityRuntime::GetStageModeContext(env, value); + if (context == nullptr) { + TAG_LOGE(AAFwkTag::VERTICAL_PANEL, "Get context GetStageModeContext failed"); + return false; + } + + abilityContext = AbilityRuntime::Context::ConvertTo(context); + if (abilityContext == nullptr || abilityContext->GetApplicationInfo() == nullptr) { + TAG_LOGE(AAFwkTag::VERTICAL_PANEL, "Get context failed"); + return false; + } + + return true; + } + + static bool UnwrapScreenConfig(napi_env env, napi_value param, AAFwk::ScreenConfig &screenConfig) + { + if (!AppExecFwk::IsTypeForNapiValue(env, param, napi_object)) { + TAG_LOGE(AAFwkTag::VERTICAL_PANEL, "UnwrapScreenConfig param IsTypeForNapiValue failed"); + return false; + } + + napi_value type = nullptr; + napi_get_named_property(env, param, "type", &type); + if (type == nullptr || !ConvertFromJsValue(env, type, screenConfig.type)) { + TAG_LOGE(AAFwkTag::VERTICAL_PANEL, "parse UnwrapScreenConfig failed: type"); + return false; + } + + napi_value sourceAppInfo = nullptr; + napi_get_named_property(env, param, "sourceAppInfo", &sourceAppInfo); + if (sourceAppInfo == nullptr || !AppExecFwk::IsTypeForNapiValue(env, sourceAppInfo, napi_object)) { + TAG_LOGE(AAFwkTag::VERTICAL_PANEL, "parse UnwrapScreenConfig failed: sourceAppInfo"); + return false; + } + + napi_valuetype jsValueType = napi_undefined; + napi_value jsProNameList = nullptr; + uint32_t jsProCount = 0; + + NAPI_CALL_BASE(env, napi_get_property_names(env, sourceAppInfo, &jsProNameList), false); + NAPI_CALL_BASE(env, napi_get_array_length(env, jsProNameList, &jsProCount), false); + + napi_value jsProName = nullptr; + napi_value jsProValue = nullptr; + for (uint32_t index = 0; index < jsProCount; index++) { + NAPI_CALL_BASE(env, napi_get_element(env, jsProNameList, index, &jsProName), false); + + std::string strProName = AppExecFwk::UnwrapStringFromJS(env, jsProName); + TAG_LOGD(AAFwkTag::VERTICAL_PANEL, "property name=%{public}s", strProName.c_str()); + NAPI_CALL_BASE(env, napi_get_named_property(env, sourceAppInfo, strProName.c_str(), &jsProValue), false); + NAPI_CALL_BASE(env, napi_typeof(env, jsProValue, &jsValueType), false); + + std::string natValue = AppExecFwk::UnwrapStringFromJS(env, jsProValue); + screenConfig.sourceAppInfo[strProName] = natValue; + } + return true; + } + + napi_value ExecuteStartVerticalPanel(napi_env env, + std::shared_ptr abilityContext, + const AAFwk::WantParams &wantParam, + const AAFwk::ScreenConfig &screenConfig, + std::shared_ptr callback) + { + auto innerErrCode = std::make_shared(ERR_OK); + NapiAsyncTask::ExecuteCallback execute = + [abilityContext, wantParamCopy = wantParam, screenConfig, callback, innerErrCode]() mutable { +#ifdef SUPPORT_SCREEN + *innerErrCode = OHOS::AbilityRuntime::StartVerticalPanel( + abilityContext, wantParamCopy, screenConfig, callback); +#endif + }; + NapiAsyncTask::CompleteCallback complete = + [innerErrCode](napi_env env, NapiAsyncTask& task, int32_t status) { + if (*innerErrCode == ERR_OK) { + task.ResolveWithNoError(env, CreateJsUndefined(env)); + } else { + task.Reject(env, CreateJsErrorByNativeErr(env, *innerErrCode)); + } + }; + napi_value result = nullptr; + NapiAsyncTask::ScheduleHighQos("JsAbilityVerticalPanel::OnStartVerticalPanel", + env, CreateAsyncTaskWithLastParam(env, nullptr, std::move(execute), std::move(complete), &result)); + return result; + } + + napi_value OnStartVerticalPanel(napi_env env, NapiCallbackInfo &info) + { + TAG_LOGD(AAFwkTag::VERTICAL_PANEL, "OnStartVerticalPanel call"); + + auto selfToken = IPCSkeleton::GetSelfTokenID(); + if (!Security::AccessToken::TokenIdKit::IsSystemAppByFullTokenID(selfToken)) { + TAG_LOGE(AAFwkTag::VERTICAL_PANEL, "This application is not system-app," + "can not use system-api"); + ThrowNotSystemAppError(env); + return CreateJsUndefined(env); + } + + if (info.argc < ARGC_FOUR) { + TAG_LOGE(AAFwkTag::VERTICAL_PANEL, "OnStartVerticalPanel invalid params"); + ThrowTooFewParametersError(env); + return CreateJsUndefined(env); + } + + std::shared_ptr abilityContext; + if (!GetContext(env, info.argv[INDEX_ZERO], abilityContext)) { + TAG_LOGE(AAFwkTag::VERTICAL_PANEL, "OnStartVerticalPanel parse context failed"); + ThrowInvalidParamError(env, "Parse param context failed, context must be UIAbilityContext."); + return CreateJsUndefined(env); + } + + AAFwk::WantParams wantParam; + if (!AppExecFwk::UnwrapWantParams(env, info.argv[INDEX_ONE], wantParam)) { + TAG_LOGE(AAFwkTag::VERTICAL_PANEL, "OnStartVerticalPanel parse wantParam failed"); + ThrowInvalidParamError(env, "Parse param want failed, want must be Want."); + return CreateJsUndefined(env); + } + + AAFwk::ScreenConfig screenConfig; + if (!UnwrapScreenConfig(env, info.argv[INDEX_TWO], screenConfig)) { + TAG_LOGE(AAFwkTag::VERTICAL_PANEL, "OnStartVerticalPanel parse screenConfig failed"); + ThrowInvalidParamError(env, "Parse param screenConfig failed, screenConfig must be ScreenConfig."); + return CreateJsUndefined(env); + } + + std::shared_ptr callback = std::make_shared(env); + callback->SetJsCallbackObject(info.argv[INDEX_THREE]); + return ExecuteStartVerticalPanel(env, abilityContext, wantParam, screenConfig, callback); + } +}; + +napi_value JsAbilityVerticalPanelInit(napi_env env, napi_value exportObj) +{ + if (env == nullptr || exportObj == nullptr) { + TAG_LOGE(AAFwkTag::VERTICAL_PANEL, "null env or exportObj"); + return nullptr; + } + + napi_value verticalType = nullptr; + napi_create_object(env, &verticalType); + SetNamedProperty(env, verticalType, "navigation", "NAVIGATION"); + + napi_value bundleName = nullptr; + napi_create_string_utf8(env, "bundleName", NAPI_AUTO_LENGTH, &bundleName); + napi_value moduleNameProp = nullptr; + napi_create_string_utf8(env, "moduleName", NAPI_AUTO_LENGTH, &moduleNameProp); + napi_value abilityName = nullptr; + napi_create_string_utf8(env, "abilityName", NAPI_AUTO_LENGTH, &abilityName); + napi_value windowId = nullptr; + napi_create_string_utf8(env, "windowId", NAPI_AUTO_LENGTH, &windowId); + napi_value screenMode = nullptr; + napi_create_string_utf8(env, "screenMode", NAPI_AUTO_LENGTH, &screenMode); + + napi_property_descriptor exportFuncs[] = { + DECLARE_NAPI_PROPERTY("VerticalType", verticalType), + DECLARE_NAPI_PROPERTY("SOURCE_APP_BUNDLE_NAME", bundleName), + DECLARE_NAPI_PROPERTY("SOURCE_APP_MODULE_NAME", moduleNameProp), + DECLARE_NAPI_PROPERTY("SOURCE_APP_ABILITY_NAME", abilityName), + DECLARE_NAPI_PROPERTY("SOURCE_APP_WINDOW_ID", windowId), + DECLARE_NAPI_PROPERTY("SOURCE_APP_SCREEN_MODE", screenMode), + }; + napi_define_properties(env, exportObj, sizeof(exportFuncs) / sizeof(*exportFuncs), exportFuncs); + + auto jsAbilityVerticalPanel = std::make_unique(); + napi_wrap(env, exportObj, jsAbilityVerticalPanel.release(), + JsAbilityVerticalPanel::Finalizer, nullptr, nullptr); + + const char *moduleName = "JsAbilityVerticalPanel"; + BindNativeFunction(env, exportObj, "startVerticalPanel", moduleName, JsAbilityVerticalPanel::StartVerticalPanel); + TAG_LOGD(AAFwkTag::VERTICAL_PANEL, "end"); + return CreateJsUndefined(env); +} +} // namespace AbilityRuntime +} // namespace OHOS \ No newline at end of file diff --git a/frameworks/js/napi/ability_vertical_panel/js_ability_vertical_panel.h b/frameworks/js/napi/ability_vertical_panel/js_ability_vertical_panel.h new file mode 100644 index 0000000000000000000000000000000000000000..2dda8b46e09a82a73944139b9423f65ef3d03417 --- /dev/null +++ b/frameworks/js/napi/ability_vertical_panel/js_ability_vertical_panel.h @@ -0,0 +1,25 @@ +/* + * 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_JS_ABILITY_VERTICAL_PANEL_H +#define OHOS_ABILITY_RUNTIME_JS_ABILITY_VERTICAL_PANEL_H + +#include "native_engine/native_engine.h" + +namespace OHOS { +namespace AbilityRuntime { +napi_value JsAbilityVerticalPanelInit(napi_env env, napi_value exportObj); +} // namespace AbilityRuntime +} // namespace OHOS +#endif // OHOS_ABILITY_RUNTIME_JS_ABILITY_VERTICAL_PANEL_H diff --git a/frameworks/js/napi/ability_vertical_panel/js_panel_start_callback.cpp b/frameworks/js/napi/ability_vertical_panel/js_panel_start_callback.cpp new file mode 100644 index 0000000000000000000000000000000000000000..be6b1607c8bccc260002b0bd9e27afc3317ed970 --- /dev/null +++ b/frameworks/js/napi/ability_vertical_panel/js_panel_start_callback.cpp @@ -0,0 +1,206 @@ +/* + * 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 "js_panel_start_callback.h" + +#include "ability_business_error.h" +#include "hilog_tag_wrapper.h" +#include "js_runtime_utils.h" +#include "napi/native_api.h" +#include "napi_common_util.h" +#include "napi_common_want.h" +#ifdef SUPPORT_SCREEN +#include "ui_content.h" +#include "ws_common.h" +#endif // SUPPORT_SCREEN + +namespace OHOS { +namespace AbilityRuntime { +#ifdef SUPPORT_SCREEN +constexpr const char* ERROR_MSG_INNER = "Inner error."; +#endif // SUPPORT_SCREEN +JsPanelStartCallback::~JsPanelStartCallback() +{ + if (jsCallbackObject_ == nullptr) { + return; + } + + uv_loop_t *loop = nullptr; + napi_get_uv_event_loop(env_, &loop); + if (loop == nullptr) { + return; + } + + uv_work_t *work = new (std::nothrow) uv_work_t; + if (work == nullptr) { + return; + } + work->data = reinterpret_cast(jsCallbackObject_.release()); + int ret = uv_queue_work(loop, work, [](uv_work_t *work) {}, + [](uv_work_t *work, int status) { + if (work == nullptr) { + return; + } + if (work->data == nullptr) { + delete work; + work = nullptr; + return; + } + delete reinterpret_cast(work->data); + work->data = nullptr; + delete work; + work = nullptr; + }); + if (ret != 0) { + delete reinterpret_cast(work->data); + work->data = nullptr; + delete work; + work = nullptr; + } +} + +void JsPanelStartCallback::SetJsCallbackObject(napi_value jsCallbackObject) +{ + napi_ref ref = nullptr; + napi_create_reference(env_, jsCallbackObject, 1, &ref); + jsCallbackObject_ = std::unique_ptr(reinterpret_cast(ref)); + if (jsCallbackObject_ == nullptr) { + TAG_LOGE(AAFwkTag::VERTICAL_PANEL, "null jsCallbackObject_"); + } +} + +#ifdef SUPPORT_SCREEN +void JsPanelStartCallback::OnError(int32_t number) +{ + TAG_LOGD(AAFwkTag::VERTICAL_PANEL, "OnError call"); + if (env_ == nullptr) { + TAG_LOGE(AAFwkTag::VERTICAL_PANEL, "null env_"); + return; + } + // js callback should run in js thread + std::shared_ptr jsPanelStartCallback = shared_from_this(); + std::unique_ptr complete = std::make_unique + ([jsPanelStartCallback, number](napi_env env, NapiAsyncTask &task, int32_t status) { + if (jsPanelStartCallback != nullptr) { + jsPanelStartCallback->CallJsError(number); + } + }); + napi_ref callback = nullptr; + std::unique_ptr execute = nullptr; + NapiAsyncTask::Schedule("JsPanelStartCallback::OnError:", + env_, std::make_unique(callback, std::move(execute), std::move(complete))); + CloseModalUIExtension(); +} + +void JsPanelStartCallback::OnResult(int32_t resultCode, const AAFwk::Want &want) +{ + TAG_LOGD(AAFwkTag::VERTICAL_PANEL, "OnResult call"); + if (env_ == nullptr) { + TAG_LOGE(AAFwkTag::VERTICAL_PANEL, "null env_"); + return; + } + // js callback should run in js thread + std::shared_ptr jsPanelStartCallback = shared_from_this(); + std::unique_ptr complete = std::make_unique + ([jsPanelStartCallback, resultCode, want](napi_env env, NapiAsyncTask &task, int32_t status) { + if (jsPanelStartCallback != nullptr) { + jsPanelStartCallback->CallJsResult(resultCode, want); + } + }); + napi_ref callback = nullptr; + std::unique_ptr execute = nullptr; + NapiAsyncTask::Schedule("JsPanelStartCallback::OnResult:", + env_, std::make_unique(callback, std::move(execute), std::move(complete))); + CloseModalUIExtension(); +} +#endif // SUPPORT_SCREEN + +void JsPanelStartCallback::CallJsResult(int32_t resultCode, const AAFwk::Want &want) +{ + TAG_LOGD(AAFwkTag::VERTICAL_PANEL, "CallJsResult call"); + if (env_ == nullptr) { + TAG_LOGE(AAFwkTag::VERTICAL_PANEL, "null env_"); + return; + } + + napi_value abilityResult = OHOS::AppExecFwk::WrapAbilityResult(env_, resultCode, want); + if (abilityResult == nullptr) { + TAG_LOGE(AAFwkTag::VERTICAL_PANEL, "null abilityResult"); + return; + } + + if (jsCallbackObject_ == nullptr) { + TAG_LOGE(AAFwkTag::VERTICAL_PANEL, "null jsCallbackObject_ "); + return; + } + napi_value obj = jsCallbackObject_->GetNapiValue(); + if (obj == nullptr) { + TAG_LOGE(AAFwkTag::VERTICAL_PANEL, "null obj"); + return; + } + napi_value method = nullptr; + napi_get_named_property(env_, obj, "onResult", &method); + if (method == nullptr || AppExecFwk::IsTypeForNapiValue(env_, method, napi_undefined) + || AppExecFwk::IsTypeForNapiValue(env_, method, napi_null)) { + TAG_LOGE(AAFwkTag::VERTICAL_PANEL, "null method"); + return; + } + + napi_value argv[] = { abilityResult }; + napi_call_function(env_, obj, method, ArraySize(argv), argv, nullptr); + TAG_LOGI(AAFwkTag::VERTICAL_PANEL, "end"); +} + +void JsPanelStartCallback::CallJsError(int32_t number) +{ + TAG_LOGD(AAFwkTag::VERTICAL_PANEL, "CallJsError call"); + if (env_ == nullptr) { + TAG_LOGE(AAFwkTag::VERTICAL_PANEL, "null env_ "); + return; + } + std::string name; + std::string message; +#ifdef SUPPORT_SCREEN + if (number != static_cast(Rosen::WSError::WS_OK)) { + number = static_cast(AbilityErrorCode::ERROR_CODE_INNER); + name = ERROR_MSG_INNER; + message = "StartVerticalPanel failed."; + } +#endif // SUPPORT_SCREEN + napi_value nativeNumber = CreateJsValue(env_, number); + napi_value nativeName = CreateJsValue(env_, name); + napi_value nativeMessage = CreateJsValue(env_, message); + if (jsCallbackObject_ == nullptr) { + TAG_LOGE(AAFwkTag::VERTICAL_PANEL, "null jsCallbackObject_"); + return; + } + napi_value obj = jsCallbackObject_->GetNapiValue(); + if (obj == nullptr) { + TAG_LOGE(AAFwkTag::VERTICAL_PANEL, "null obj"); + return; + } + napi_value method = nullptr; + napi_get_named_property(env_, obj, "onError", &method); + if (method == nullptr || AppExecFwk::IsTypeForNapiValue(env_, method, napi_undefined) + || AppExecFwk::IsTypeForNapiValue(env_, method, napi_null)) { + TAG_LOGE(AAFwkTag::VERTICAL_PANEL, "null method"); + return; + } + + napi_value argv[] = { nativeNumber, nativeName, nativeMessage }; + napi_call_function(env_, obj, method, ArraySize(argv), argv, nullptr); + TAG_LOGI(AAFwkTag::VERTICAL_PANEL, "end"); +} +} // namespace AbilityRuntime +} // namespace OHOS \ No newline at end of file diff --git a/frameworks/js/napi/ability_vertical_panel/js_panel_start_callback.h b/frameworks/js/napi/ability_vertical_panel/js_panel_start_callback.h new file mode 100644 index 0000000000000000000000000000000000000000..0f7f94f7f3ef4089e831d0e11d9da96cd020adb4 --- /dev/null +++ b/frameworks/js/napi/ability_vertical_panel/js_panel_start_callback.h @@ -0,0 +1,42 @@ +/* + * 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_JS_PANEL_START_CALLBACK_H +#define OHOS_ABILITY_RUNTIME_JS_PANEL_START_CALLBACK_H + +#include "native_engine/native_reference.h" +#include "panel_start_callback.h" + +namespace OHOS { +namespace AbilityRuntime { +class JsPanelStartCallback : public PanelStartCallback, + public std::enable_shared_from_this { +public: + explicit JsPanelStartCallback(napi_env env) : env_(env) {} + ~JsPanelStartCallback() override; +#ifdef SUPPORT_SCREEN + void OnError(int32_t number) override; + void OnResult(int32_t resultCode, const AAFwk::Want &want) override; +#endif // SUPPORT_SCREEN + void CallJsResult(int32_t resultCode, const AAFwk::Want &want); + void SetJsCallbackObject(napi_value jsCallbackObject); + void CallJsError(int32_t number); +private: + napi_env env_ = nullptr; + std::unique_ptr jsCallbackObject_ = nullptr; +}; +} // namespace AbilityRuntime +} // namespace OHOS +#endif // OHOS_ABILITY_RUNTIME_JS_PANEL_START_CALLBACK_H \ No newline at end of file diff --git a/frameworks/js/napi/ability_vertical_panel/native_module.cpp b/frameworks/js/napi/ability_vertical_panel/native_module.cpp new file mode 100644 index 0000000000000000000000000000000000000000..79f7df9e8b1d4a665cb6bfc9597c2f1cfd1d004c --- /dev/null +++ b/frameworks/js/napi/ability_vertical_panel/native_module.cpp @@ -0,0 +1,35 @@ +/* + * 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 "js_ability_vertical_panel.h" +#include "native_engine/native_engine.h" + +/* + * The module definition. + */ +static napi_module _module = { + .nm_version = 0, + .nm_filename = nullptr, + .nm_register_func = OHOS::AbilityRuntime::JsAbilityVerticalPanelInit, + .nm_modname = "app.ability.VerticalPanelManager", +}; + +/* + * The module registration. + */ +extern "C" __attribute__((constructor)) void NAPI_application_Ability_VerticalPanel_AutoRegister(void) +{ + napi_module_register(&_module); +} diff --git a/frameworks/native/ability/BUILD.gn b/frameworks/native/ability/BUILD.gn index 27de58ac8a567e0f0c2288d9fb9b69e0b736892a..916127116dd722e10168abda9d88d3e9fe5d6afa 100644 --- a/frameworks/native/ability/BUILD.gn +++ b/frameworks/native/ability/BUILD.gn @@ -62,7 +62,9 @@ ohos_shared_library("ability_context_native") { "ability_runtime/js_extension_context.cpp", "ability_runtime/local_call_container.cpp", "ability_runtime/local_call_record.cpp", + "ability_runtime/start_vertical_panel.cpp", "native/js_ui_extension_callback.cpp", + "native/panel_start_callback.cpp", ] deps = [ @@ -81,9 +83,9 @@ ohos_shared_library("ability_context_native") { "ability_base:base", "ability_base:session_info", "ability_base:want", - "bundle_framework:libappexecfwk_common", "access_token:libaccesstoken_sdk", "access_token:libtoken_callback_sdk", + "bundle_framework:libappexecfwk_common", "c_utils:utils", "common_event_service:cesfwk_innerkits", "eventhandler:libeventhandler", diff --git a/frameworks/native/ability/ability_runtime/start_vertical_panel.cpp b/frameworks/native/ability/ability_runtime/start_vertical_panel.cpp new file mode 100644 index 0000000000000000000000000000000000000000..872d5cfbe05ac98d52f1ddd5403597a416ec40f2 --- /dev/null +++ b/frameworks/native/ability/ability_runtime/start_vertical_panel.cpp @@ -0,0 +1,131 @@ +/* + * 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 "start_vertical_panel.h" + +#include "ability_manager_errors.h" +#include "hilog_tag_wrapper.h" +#include "string_wrapper.h" +#ifdef SUPPORT_SCREEN +#include "ui_content.h" +#endif // SUPPORT_SCREEN + +namespace OHOS { +namespace AbilityRuntime { +#ifdef SUPPORT_SCREEN +constexpr const char* UIEXTENSION_TARGET_TYPE_KEY = "ability.want.params.uiExtensionTargetType"; +constexpr const char* FLAG_AUTH_READ_URI_PERMISSION = "ability.want.params.uriPermissionFlag"; +constexpr const char* SCREENCONFIG_SCREENMODE = "ohos.verticalpanel.screenconfig.screenmode"; +constexpr const char* SCREENCONFIG_BUNDLENAME = "ohos.verticalpanel.screenconfig.bundlename"; +constexpr const char* SCREENCONFIG_MODULENAME = "ohos.verticalpanel.screenconfig.modulename"; +constexpr const char* SCREENCONFIG_ABILITYNAME = "ohos.verticalpanel.screenconfig.abilityname"; +constexpr const char* SCREENCONFIG_WINDOWID = "ohos.verticalpanel.screenconfig.windowid"; +constexpr const char* SCREENMODE = "screenMode"; +constexpr const char* BUNDLENAME = "bundleName"; +constexpr const char* MODULENAME = "moduleName"; +constexpr const char* ABILITYNAME = "abilityName"; +constexpr const char* WINDOWID = "windowId"; + +bool SetParamsForWantParams(AAFwk::WantParams &wantParams, const AAFwk::ScreenConfig &screenConfig) +{ + auto iter = screenConfig.sourceAppInfo.find(SCREENMODE); + if (iter == screenConfig.sourceAppInfo.end()) { + TAG_LOGE(AAFwkTag::VERTICAL_PANEL, "ohos.verticalpanel.screenconfig.screenmode is not exist"); + return false; + } + wantParams.SetParam(SCREENCONFIG_SCREENMODE, AAFwk::String::Box(iter->second)); + + iter = screenConfig.sourceAppInfo.find(BUNDLENAME); + if (iter == screenConfig.sourceAppInfo.end()) { + TAG_LOGE(AAFwkTag::VERTICAL_PANEL, "ohos.verticalpanel.screenconfig.bundlename is not exist"); + return false; + } + wantParams.SetParam(SCREENCONFIG_BUNDLENAME, AAFwk::String::Box(iter->second)); + + iter = screenConfig.sourceAppInfo.find(MODULENAME); + if (iter == screenConfig.sourceAppInfo.end()) { + TAG_LOGE(AAFwkTag::VERTICAL_PANEL, "ohos.verticalpanel.screenconfig.modulename is not exist"); + return false; + } + wantParams.SetParam(SCREENCONFIG_MODULENAME, AAFwk::String::Box(iter->second)); + + iter = screenConfig.sourceAppInfo.find(ABILITYNAME); + if (iter == screenConfig.sourceAppInfo.end()) { + TAG_LOGE(AAFwkTag::VERTICAL_PANEL, "ohos.verticalpanel.screenconfig.abilityname is not exist"); + return false; + } + wantParams.SetParam(SCREENCONFIG_ABILITYNAME, AAFwk::String::Box(iter->second)); + + iter = screenConfig.sourceAppInfo.find(WINDOWID); + if (iter == screenConfig.sourceAppInfo.end()) { + TAG_LOGE(AAFwkTag::VERTICAL_PANEL, "ohos.verticalpanel.screenconfig.windowId is not exist"); + return false; + } + wantParams.SetParam(SCREENCONFIG_WINDOWID, AAFwk::String::Box(iter->second)); + return true; +} + +ErrCode StartVerticalPanel(std::shared_ptr context, + AAFwk::WantParams &wantParams, + const AAFwk::ScreenConfig &screenConfig, + std::shared_ptr panelStartCallback) +{ + TAG_LOGD(AAFwkTag::VERTICAL_PANEL, "StartVerticalPanel call"); + if (context == nullptr) { + TAG_LOGE(AAFwkTag::VERTICAL_PANEL, "StartVerticalPanel null content"); + return ERR_INVALID_VALUE; + } + auto uiContent = context->GetUIContent(); + if (uiContent == nullptr) { + TAG_LOGE(AAFwkTag::VERTICAL_PANEL, "StartVerticalPanel null uiContent"); + return AAFwk::ERR_MAIN_WINDOW_NOT_EXIST; + } + wantParams.SetParam(UIEXTENSION_TARGET_TYPE_KEY, AAFwk::String::Box(screenConfig.type)); + if (!SetParamsForWantParams(wantParams, screenConfig)) { + return ERR_INVALID_VALUE; + } + AAFwk::Want want; + want.SetParams(wantParams); + if (wantParams.HasParam(FLAG_AUTH_READ_URI_PERMISSION)) { + int32_t flag = wantParams.GetIntParam(FLAG_AUTH_READ_URI_PERMISSION, 0); + want.SetFlags(flag); + wantParams.Remove(FLAG_AUTH_READ_URI_PERMISSION); + } + if (panelStartCallback == nullptr) { + TAG_LOGE(AAFwkTag::VERTICAL_PANEL, "StartVerticalPanel null panelStartCallback"); + return ERR_INVALID_VALUE; + } + Ace::ModalUIExtensionCallbacks callback; + callback.onError = [panelStartCallback](int32_t arg, const std::string &str1, const std::string &str2) { + panelStartCallback->OnError(arg); + }; + callback.onRelease = [panelStartCallback](int32_t arg) { + panelStartCallback->OnRelease(arg); + }; + callback.onResult = [panelStartCallback](int32_t arg1, const OHOS::AAFwk::Want arg2) { + panelStartCallback->OnResult(arg1, arg2); + }; + Ace::ModalUIExtensionConfig config; + int32_t sessionId = uiContent->CreateModalUIExtension(want, callback, config); + if (sessionId == 0) { + TAG_LOGE(AAFwkTag::VERTICAL_PANEL, "StartVerticalPanel createModalUIExtension failed"); + return ERR_INVALID_VALUE; + } + panelStartCallback->SetUIContent(uiContent); + panelStartCallback->SetSessionId(sessionId); + return ERR_OK; +} +#endif // SUPPORT_SCREEN +} // namespace AbilityRuntime +} // namespace OHOS \ No newline at end of file diff --git a/frameworks/native/ability/native/ability_business_error/ability_business_error.cpp b/frameworks/native/ability/native/ability_business_error/ability_business_error.cpp index f6db665400be587340e09cc2a791973e94793cea..ff3c963bfef5d74db43ffa7fb4cb64f33cb7415b 100644 --- a/frameworks/native/ability/native/ability_business_error/ability_business_error.cpp +++ b/frameworks/native/ability/native/ability_business_error/ability_business_error.cpp @@ -145,6 +145,8 @@ constexpr const char* ERROR_MSG_NOT_SUPPORT_START_PLUGIN_UI_ABILITY = "Starting a plugin UIAbility is not supported."; constexpr const char* ERROR_MSG_NOT_SUPPORT_START_DLP_FILES = "Starting DLP files is not supported."; +constexpr const char* ERROR_MSG_MAIN_WINDOW_NOT_EXIST = + "The main window of this ability does not exist."; // follow ERR_BUNDLE_MANAGER_BUNDLE_NOT_EXIST of appexecfwk_errors.h in bundle_framework constexpr int32_t ERR_BUNDLE_MANAGER_BUNDLE_NOT_EXIST = 8521220; @@ -246,6 +248,7 @@ static std::unordered_map ERR_CODE_MAP = { { AbilityErrorCode::ERROR_CODE_NOT_SUPPORT_START_REMOTE_UI_ABILITY, ERROR_MSG_NOT_SUPPORT_START_REMOTE_UI_ABILITY }, { AbilityErrorCode::ERROR_CODE_NOT_SUPPORT_START_PLUGIN_UI_ABILITY, ERROR_MSG_NOT_SUPPORT_START_PLUGIN_UI_ABILITY }, { AbilityErrorCode::ERROR_CODE_NOT_SUPPORT_START_DLP_FILES, ERROR_MSG_NOT_SUPPORT_START_DLP_FILES }, + { AbilityErrorCode::ERROR_CODE_MAIN_WINDOW_NOT_EXIST, ERROR_MSG_MAIN_WINDOW_NOT_EXIST }, }; static std::unordered_map INNER_TO_JS_ERROR_CODE_MAP { @@ -352,6 +355,7 @@ static std::unordered_map INNER_TO_JS_ERROR_CODE_MAP {START_UI_ABILITIES_NOT_SUPPORT_OPERATE_REMOTE, AbilityErrorCode::ERROR_CODE_NOT_SUPPORT_START_REMOTE_UI_ABILITY }, {START_UI_ABILITIES_NOT_SUPPORT_START_PLUGIN, AbilityErrorCode::ERROR_CODE_NOT_SUPPORT_START_PLUGIN_UI_ABILITY }, {START_UI_ABILITIES_NOT_SUPPORT_DLP, AbilityErrorCode::ERROR_CODE_NOT_SUPPORT_START_DLP_FILES }, + {ERR_MAIN_WINDOW_NOT_EXIST, AbilityErrorCode::ERROR_CODE_MAIN_WINDOW_NOT_EXIST }, }; } diff --git a/frameworks/native/ability/native/panel_start_callback.cpp b/frameworks/native/ability/native/panel_start_callback.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7d707fff11ad98e78ae29d1de02c3a8e23c4d48d --- /dev/null +++ b/frameworks/native/ability/native/panel_start_callback.cpp @@ -0,0 +1,51 @@ +/* + * 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 "panel_start_callback.h" + +#include "hilog_tag_wrapper.h" +#ifdef SUPPORT_SCREEN +#include "ui_content.h" +#include "ws_common.h" +#endif // SUPPORT_SCREEN + +namespace OHOS { +namespace AbilityRuntime { +void PanelStartCallback::SetSessionId(int32_t sessionId) +{ + sessionId_ = sessionId; +} +#ifdef SUPPORT_SCREEN +void PanelStartCallback::SetUIContent(Ace::UIContent* uiContent) +{ + uiContent_ = uiContent; +} + +void PanelStartCallback::OnRelease(int32_t code) +{ + TAG_LOGI(AAFwkTag::VERTICAL_PANEL, "call, code:%{public}d", code); + CloseModalUIExtension(); +} + +void PanelStartCallback::CloseModalUIExtension() +{ + if (uiContent_ == nullptr) { + TAG_LOGE(AAFwkTag::VERTICAL_PANEL, "null uiContent_"); + return; + } + uiContent_->CloseModalUIExtension(sessionId_); +} +#endif // SUPPORT_SCREEN +} // namespace AbilityRuntime +} // namespace OHOS diff --git a/frameworks/native/appkit/ability_bundle_manager_helper/bundle_mgr_helper.cpp b/frameworks/native/appkit/ability_bundle_manager_helper/bundle_mgr_helper.cpp index adc8444d637523aada192d20a9a12ffc05711db2..b69bbf87a15bd67f35b86125b1e70df350af0b25 100644 --- a/frameworks/native/appkit/ability_bundle_manager_helper/bundle_mgr_helper.cpp +++ b/frameworks/native/appkit/ability_bundle_manager_helper/bundle_mgr_helper.cpp @@ -258,7 +258,7 @@ sptr BundleMgrHelper::Connect(bool checkBmsReady) return nullptr; } - sptr remoteObject_ = systemAbilityManager->CheckSystemAbility(BUNDLE_MGR_SERVICE_SYS_ABILITY_ID); + sptr remoteObject_ = systemAbilityManager->GetSystemAbility(BUNDLE_MGR_SERVICE_SYS_ABILITY_ID); if (remoteObject_ == nullptr || (bundleMgr_ = iface_cast(remoteObject_)) == nullptr) { TAG_LOGE(AAFwkTag::BUNDLEMGRHELPER, "null remoteObject_ or bundleMgr_"); return nullptr; diff --git a/frameworks/native/appkit/app/main_thread.cpp b/frameworks/native/appkit/app/main_thread.cpp index 3703d54f45582f4171f36804ff68213bd5eb6309..f5196c644950ea1a3ead978600fc88fa0b1f8e47 100644 --- a/frameworks/native/appkit/app/main_thread.cpp +++ b/frameworks/native/appkit/app/main_thread.cpp @@ -1686,6 +1686,7 @@ void MainThread::HandleLaunchApplication(const AppLaunchData &appLaunchData, con options.uid = bundleInfo.applicationInfo.uid; options.apiTargetVersion = appInfo.apiTargetVersion; options.pkgContextInfoJsonStringMap = pkgContextInfoJsonStringMap; + options.isStartWithDebug = appLaunchData.GetDebugApp(); options.allowArkTsLargeHeap = appInfo.allowArkTsLargeHeap; options.versionCode = appInfo.versionCode; #ifdef CJ_FRONTEND @@ -1767,6 +1768,7 @@ void MainThread::HandleLaunchApplication(const AppLaunchData &appLaunchData, con ResHelper::ReportLoadAbcCompletedInfoToRss(uid, currentPid, bundleName); }); AbilityRuntime::Runtime::DebugOption debugOption; + debugOption.arkTSMode = appInfo.arkTSMode; debugOption.isStartWithDebug = appLaunchData.GetDebugApp(); debugOption.processName = processName; debugOption.isDebugApp = appInfo.debug; @@ -1775,6 +1777,7 @@ void MainThread::HandleLaunchApplication(const AppLaunchData &appLaunchData, con debugOption.isDebugFromLocal = appLaunchData.GetDebugFromLocal(); debugOption.perfCmd = perfCmd; debugOption.isDeveloperMode = isDeveloperMode_; + debugOption.bundleName = appInfo.bundleName; runtime->SetDebugOption(debugOption); if (perfCmd.find(PERFCMD_PROFILE) != std::string::npos || perfCmd.find(PERFCMD_DUMPHEAP) != std::string::npos) { diff --git a/frameworks/native/runtime/cj_runtime.cpp b/frameworks/native/runtime/cj_runtime.cpp index 5dae7bf282576d25cfe92569967e2608af9db938..0d98ceb19278f08132f6ae9328277de8843a4c64 100644 --- a/frameworks/native/runtime/cj_runtime.cpp +++ b/frameworks/native/runtime/cj_runtime.cpp @@ -31,11 +31,6 @@ using namespace OHOS::AbilityRuntime; - -namespace { -const std::string DEBUGGER = "@Debugger"; -} // namespace - #define LIB_NAME "libcj_environment.z.so" #define GET_ENV_INS_NAME "OHOS_GetCJEnvInstance" diff --git a/frameworks/native/runtime/ets_runtime.cpp b/frameworks/native/runtime/ets_runtime.cpp index 89361104f7ed93504aa755353981c88f3dbf1829..de6cdad9b05afe313deeb86993e438e1e6c936e2 100644 --- a/frameworks/native/runtime/ets_runtime.cpp +++ b/frameworks/native/runtime/ets_runtime.cpp @@ -23,12 +23,15 @@ #include #include +#include "bundle_constants.h" #include "constants.h" #include "ets_interface.h" #include "file_path_utils.h" #include "hilog_tag_wrapper.h" +#include "hdc_register.h" #include "hybrid_js_module_reader.h" #include "nocopyable.h" +#include "parameters.h" #include "static_core/plugins/ets/runtime/ets_namespace_manager.h" #ifdef SUPPORT_SCREEN @@ -295,6 +298,7 @@ ETSRuntime::~ETSRuntime() { TAG_LOGD(AAFwkTag::ETSRUNTIME, "~ETSRuntime called"); Deinitialize(); + StopDebugMode(); } void ETSRuntime::Deinitialize() @@ -311,7 +315,7 @@ bool ETSRuntime::CreateEtsEnv(const Options &options) return false; } - if (!g_etsEnvFuncs->Initialize()) { + if (!g_etsEnvFuncs->Initialize(options.eventRunner, options.isStartWithDebug)) { TAG_LOGE(AAFwkTag::ETSRUNTIME, "Initialize failed"); return false; } @@ -476,5 +480,110 @@ bool ETSRuntime::PreloadSystemClass(const char *className) g_etsEnvFuncs->PreloadSystemClass(className); return true; } + +void ETSRuntime::StartDebugMode(const DebugOption dOption) +{ + TAG_LOGD(AAFwkTag::ETSRUNTIME, "localDebug %{public}d", dOption.isDebugFromLocal); + if (!dOption.isDebugFromLocal && !dOption.isDeveloperMode) { + TAG_LOGE(AAFwkTag::ETSRUNTIME, "developer Mode false"); + return; + } + // Set instance id to tid after the first instance. + instanceId_ = static_cast(getproctid()); + + bool isStartWithDebug = dOption.isStartWithDebug; + bool isDebugApp = dOption.isDebugApp; + std::string appProvisionType = dOption.appProvisionType; + TAG_LOGD(AAFwkTag::ETSRUNTIME, "Ark VM is starting debug mode [%{public}s]", isStartWithDebug ? "break" : "normal"); + const std::string bundleName = dOption.bundleName; + uint32_t instanceId = instanceId_; + std::string inputProcessName = bundleName != dOption.processName ? dOption.processName : ""; + HdcRegister::DebugRegisterMode debugMode = HdcRegister::DebugRegisterMode::HDC_DEBUG_REG; + HdcRegister::Get().StartHdcRegister(bundleName, inputProcessName, isDebugApp, debugMode, + [bundleName, isStartWithDebug, instanceId, isDebugApp, appProvisionType] + (int socketFd, std::string option) { + TAG_LOGI(AAFwkTag::ETSRUNTIME, "HdcRegister msg, fd= %{public}d, option= %{public}s", socketFd, option.c_str()); + // system is debuggable when const.secure is false and const.debuggable is true + bool isSystemDebuggable = system::GetBoolParameter("const.secure", true) == false && + system::GetBoolParameter("const.debuggable", false) == true; + // Don't start any server if (system not in debuggable mode) and app is release version + // Starting ConnectServer in release app on debuggable system is only for debug mode, not for profiling mode. + if ((!isSystemDebuggable) && appProvisionType == AppExecFwk::Constants::APP_PROVISION_TYPE_RELEASE) { + TAG_LOGE(AAFwkTag::ETSRUNTIME, "not support release app"); + return; + } + if (option.find(DEBUGGER) == std::string::npos) { + // if has old connect server, stop it + if (g_etsEnvFuncs == nullptr || g_etsEnvFuncs->BroadcastAndConnect == nullptr) { + TAG_LOGE(AAFwkTag::ETSRUNTIME, "null g_etsEnvFuncs or BroadcastAndConnect"); + return; + } + g_etsEnvFuncs->BroadcastAndConnect(bundleName, socketFd); + } else { + if (appProvisionType == AppExecFwk::Constants::APP_PROVISION_TYPE_RELEASE) { + TAG_LOGE(AAFwkTag::ETSRUNTIME, "not support release app"); + return; + } + if (g_etsEnvFuncs == nullptr || g_etsEnvFuncs->StartDebuggerForSocketPair == nullptr) { + TAG_LOGE(AAFwkTag::ETSRUNTIME, "null g_etsEnvFuncs or StartDebuggerForSocketPair"); + return; + } + g_etsEnvFuncs->StartDebuggerForSocketPair(option, socketFd); + } + }); + DebuggerConnectionHandler(isDebugApp, isStartWithDebug); +} + +void ETSRuntime::DebuggerConnectionHandler(bool isDebugApp, bool isStartWithDebug) +{ + auto dTask = nullptr; + if (jsRuntime_ == nullptr) { + TAG_LOGD(AAFwkTag::ETSRUNTIME, "jsRuntime_ is nullptr"); + return; + } + if (g_etsEnvFuncs == nullptr || g_etsEnvFuncs->NotifyDebugMode == nullptr) { + TAG_LOGE(AAFwkTag::ETSRUNTIME, "null g_etsEnvFuncs or NotifyDebugMode"); + return; + } + if (jsRuntime_ == nullptr) { + TAG_LOGE(AAFwkTag::ETSRUNTIME, "null js runtime"); + return; + } + auto &jsRuntimePoint = (static_cast(*jsRuntime_)); + auto vm = jsRuntimePoint.GetEcmaVm(); + if (vm == nullptr) { + TAG_LOGE(AAFwkTag::ETSRUNTIME, "null js vm"); + return; + } + g_etsEnvFuncs->NotifyDebugMode(getproctid(), instanceId_, isStartWithDebug, vm); +} + +void ETSRuntime::StopDebugMode() +{ + if (g_etsEnvFuncs == nullptr) { + TAG_LOGE(AAFwkTag::ETSRUNTIME, "null g_etsEnvFuncs"); + return; + } + if (g_etsEnvFuncs->RemoveInstance == nullptr) { + TAG_LOGE(AAFwkTag::ETSRUNTIME, "null RemoveInstance"); + return; + } + g_etsEnvFuncs->RemoveInstance(instanceId_); + if (g_etsEnvFuncs->StopDebugMode == nullptr) { + TAG_LOGE(AAFwkTag::ETSRUNTIME, "null StopDebugMode"); + return; + } + if (jsRuntime_ == nullptr) { + TAG_LOGE(AAFwkTag::ETSRUNTIME, "null js runtime"); + return; + } + auto &jsRuntimePoint = (static_cast(*jsRuntime_)); + auto vm = jsRuntimePoint.GetEcmaVm(); + if (vm == nullptr) { + TAG_LOGE(AAFwkTag::ETSRUNTIME, "null js vm"); + return; + } + g_etsEnvFuncs->StopDebugMode(vm); +} } // namespace AbilityRuntime } // namespace OHOS \ No newline at end of file diff --git a/frameworks/native/runtime/js_runtime.cpp b/frameworks/native/runtime/js_runtime.cpp index 5084526ede9fbf5bd709ad4b80e2a2bbcee24dd7..f69dd652eb31b91f9f534cd47abc36aec41de8d0 100644 --- a/frameworks/native/runtime/js_runtime.cpp +++ b/frameworks/native/runtime/js_runtime.cpp @@ -85,7 +85,6 @@ constexpr int32_t DEFAULT_INTER_VAL = 500; constexpr int32_t API8 = 8; const std::string SANDBOX_ARK_CACHE_PATH = "/data/storage/ark-cache/"; const std::string SANDBOX_ARK_PROIFILE_PATH = "/data/storage/ark-profile"; -const std::string DEBUGGER = "@Debugger"; constexpr char MERGE_ABC_PATH[] = "/ets/modules.abc"; constexpr char BUNDLE_INSTALL_PATH[] = "/data/storage/el1/bundle/"; @@ -164,8 +163,8 @@ void JsRuntime::StartDebugMode(const DebugOption dOption) { HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__); TAG_LOGD(AAFwkTag::JSRUNTIME, "localDebug %{public}d", dOption.isDebugFromLocal); - if (!dOption.isDebugFromLocal && !dOption.isDeveloperMode) { - TAG_LOGE(AAFwkTag::JSRUNTIME, "developer Mode false"); + if (!ShouldSkipDebugMode(dOption)) { + TAG_LOGE(AAFwkTag::JSRUNTIME, "not start debug"); return; } CHECK_POINTER(jsEnv_); @@ -213,10 +212,16 @@ void JsRuntime::StartDebugMode(const DebugOption dOption) TAG_LOGE(AAFwkTag::JSRUNTIME, "not support release app"); return; } + auto callback = [weak, isDebugApp, isStartWithDebug](int32_t tid, const DebuggerPostTask& task) { + panda::JSNApi::DebugOption debugOption = {ARK_DEBUGGER_LIB_PATH, isDebugApp ? isStartWithDebug : false}; + if (weak != nullptr) { + panda::JSNApi::StoreDebugInfo(tid, weak->GetVM(), debugOption, task, isDebugApp); + } + }; if (option.find(DEBUGGER) == std::string::npos) { // if has old connect server, stop it ConnectServerManager::Get().StopConnectServer(false); - ConnectServerManager::Get().SendDebuggerInfo(isStartWithDebug, isDebugApp); + ConnectServerManager::Get().SendInstanceMessageAll(callback); ConnectServerManager::Get().StartConnectServer(bundleName, socketFd, false); } else { // if has old debugger server, stop it @@ -231,6 +236,19 @@ void JsRuntime::StartDebugMode(const DebugOption dOption) DebuggerConnectionHandler(isDebugApp, isStartWithDebug); } +bool JsRuntime::ShouldSkipDebugMode(const DebugOption dOption) +{ + if (!dOption.isDebugFromLocal && !dOption.isDeveloperMode) { + TAG_LOGE(AAFwkTag::JSRUNTIME, "developer Mode false"); + return false; + } + if (!(dOption.arkTSMode == AbilityRuntime::CODE_LANGUAGE_ARKTS_1_0)) { + TAG_LOGE(AAFwkTag::JSRUNTIME, "developer register in sts"); + return false; + } + return true; +} + void JsRuntime::DebuggerConnectionHandler(bool isDebugApp, bool isStartWithDebug) { ConnectServerManager::Get().StoreInstanceMessage(getproctid(), instanceId_); diff --git a/frameworks/native/runtime/ohos_js_environment_impl.cpp b/frameworks/native/runtime/ohos_js_environment_impl.cpp index 6f77792c827d0a27dbb3adb6887609c4a1f2e805..b6dd34dbb8ca0505236c285f233aa762f9601d10 100644 --- a/frameworks/native/runtime/ohos_js_environment_impl.cpp +++ b/frameworks/native/runtime/ohos_js_environment_impl.cpp @@ -97,9 +97,11 @@ OHOSJsEnvironmentImpl::~OHOSJsEnvironmentImpl() void OHOSJsEnvironmentImpl::PostTask(const std::function& task, const std::string& name, int64_t delayTime) { TAG_LOGD(AAFwkTag::JSRUNTIME, "called"); - if (eventHandler_ != nullptr) { - eventHandler_->PostTask(task, name, delayTime); + if (eventHandler_ == nullptr) { + TAG_LOGE(AAFwkTag::JSRUNTIME, "null eventHandler_"); + return; } + eventHandler_->PostTask(task, name, delayTime); } void OHOSJsEnvironmentImpl::PostSyncTask(const std::function& task, const std::string& name) diff --git a/frameworks/simulator/ability_simulator/src/ability_context.cpp b/frameworks/simulator/ability_simulator/src/ability_context.cpp index 86f3bf0c71758c464b41d9e31ffda48dffe05308..7d0e962306050368cad4fd8f861866e8cdbb14c0 100644 --- a/frameworks/simulator/ability_simulator/src/ability_context.cpp +++ b/frameworks/simulator/ability_simulator/src/ability_context.cpp @@ -82,6 +82,7 @@ void AbilityContext::SetOptions(const Options &options) TAG_LOGD(AAFwkTag::ABILITY_SIM, "releaseType:%{public}s", options.releaseType.c_str()); TAG_LOGD(AAFwkTag::ABILITY_SIM, "enablePartialUpdate:%{public}d", options.enablePartialUpdate); TAG_LOGD(AAFwkTag::ABILITY_SIM, "isComponentMode:%{public}d", options.isComponentMode); + TAG_LOGD(AAFwkTag::ABILITY_SIM, "enableFileOperation:%{public}d", options.enableFileOperation); } std::string AbilityContext::GetBundleName() const diff --git a/frameworks/simulator/ability_simulator/src/simulator.cpp b/frameworks/simulator/ability_simulator/src/simulator.cpp index 7eb5660c1609ecb032118d8ec9932590c7d63832..026ab4b02a46aef29139e669639dd50b580b9fd8 100644 --- a/frameworks/simulator/ability_simulator/src/simulator.cpp +++ b/frameworks/simulator/ability_simulator/src/simulator.cpp @@ -825,6 +825,10 @@ bool SimulatorImpl::OnInit() return false; } +#if defined(PREVIEW) + ArkNativeEngine::SetCurrentPreviewenv(options_.enableFileOperation); +#endif + if (!LoadRuntimeEnv(env, globalObj)) { delete nativeEngine; TAG_LOGE(AAFwkTag::ABILITY_SIM, "Load runtime env failed"); diff --git a/frameworks/simulator/common/include/options.h b/frameworks/simulator/common/include/options.h index bf9c012aa00ae9e895a08c55c083675fab0b1939..7f43fdf59f9503797846e1bec0b96b41f8160702 100644 --- a/frameworks/simulator/common/include/options.h +++ b/frameworks/simulator/common/include/options.h @@ -105,6 +105,7 @@ struct Options { std::string releaseType; bool enablePartialUpdate; std::string previewPath; + bool enableFileOperation = false; AppExecFwk::ApplicationInfo applicationInfo; AppExecFwk::HapModuleInfo hapModuleInfo; AppExecFwk::AbilityInfo abilityInfo; diff --git a/interfaces/inner_api/ability_manager/include/ability_manager_errors.h b/interfaces/inner_api/ability_manager/include/ability_manager_errors.h index 9c0a801305949f4c5940d13fbb292c003ace465b..b96dfa27987b6d5e132a9758e2b591a85b51213f 100644 --- a/interfaces/inner_api/ability_manager/include/ability_manager_errors.h +++ b/interfaces/inner_api/ability_manager/include/ability_manager_errors.h @@ -1060,6 +1060,11 @@ enum { ERR_REFINEMENT_INVALID_CALLER_END = 2099199, + /** + * Result (2099200) for main window of this ability does not exist. + */ + ERR_MAIN_WINDOW_NOT_EXIST = 2099200, + /** * Native error(3000000) for target bundle not exist. */ diff --git a/interfaces/inner_api/ability_manager/include/screen_config.h b/interfaces/inner_api/ability_manager/include/screen_config.h new file mode 100644 index 0000000000000000000000000000000000000000..7a827772dcd78ceb8a54e673e57998bd7b09f1c2 --- /dev/null +++ b/interfaces/inner_api/ability_manager/include/screen_config.h @@ -0,0 +1,30 @@ +/* + * 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_SCREEN_CONFIG_H +#define OHOS_ABILITY_RUNTIME_SCREEN_CONFIG_H + +#include +#include + +namespace OHOS { +namespace AAFwk { +struct ScreenConfig { + std::string type; + std::map sourceAppInfo; +}; +} // namespace AAFwk +} // namespace OHOS +#endif // OHOS_ABILITY_RUNTIME_SCREEN_CONFIG_H \ No newline at end of file diff --git a/interfaces/inner_api/connect_server_manager/BUILD.gn b/interfaces/inner_api/connect_server_manager/BUILD.gn index c2c684462c3aa841d1cc7b8b242102147ddd9f05..3f285a6fd25b1ad26c81bf7144635517eb4127d8 100644 --- a/interfaces/inner_api/connect_server_manager/BUILD.gn +++ b/interfaces/inner_api/connect_server_manager/BUILD.gn @@ -53,6 +53,7 @@ ohos_shared_library("connect_server_manager") { external_deps = [ "ets_runtime:libark_jsruntime", "hilog:libhilog", + "runtime_core:libarkruntime", ] configs = [ diff --git a/interfaces/inner_api/connect_server_manager/include/connect_server_manager.h b/interfaces/inner_api/connect_server_manager/include/connect_server_manager.h index 8f1f12a09360d5ca5c2291939279a859155436c8..bdcb2d2d58558a18ee769fcd882a7a8a5060db70 100644 --- a/interfaces/inner_api/connect_server_manager/include/connect_server_manager.h +++ b/interfaces/inner_api/connect_server_manager/include/connect_server_manager.h @@ -52,6 +52,7 @@ public: void SetConnectedCallback(); bool SendInstanceMessage(int32_t tid, int32_t instanceId, const std::string& instanceName); void SendDebuggerInfo(bool needBreakPoint, bool isDebugApp); + void SendInstanceMessageAll(std::function callback); void LoadConnectServerDebuggerSo(); bool SetRecordCallback(const std::function &startRecordFunc, const std::function &stopRecordFunc); diff --git a/interfaces/inner_api/connect_server_manager/src/connect_server_manager.cpp b/interfaces/inner_api/connect_server_manager/src/connect_server_manager.cpp index 73a75f3f6a61e73725f46fa5f69a11725f9d8dad..f9b313200f1e79aa33ba0643b1c7cb4de6ffc3c8 100644 --- a/interfaces/inner_api/connect_server_manager/src/connect_server_manager.cpp +++ b/interfaces/inner_api/connect_server_manager/src/connect_server_manager.cpp @@ -467,4 +467,24 @@ void ConnectServerManager::AddInstanceCallback(const int32_t instanceId) } } } + +void ConnectServerManager::SendInstanceMessageAll(std::function callback) +{ + ConnectServerManager::Get().SetConnectedCallback(); + std::lock_guard lock(mutex_); + for (const auto& instance : instanceMap_) { + auto instanceId = instance.first; + auto instanceName = instance.second.first; + auto tid = instance.second.second; + std::lock_guard lock(g_debuggerMutex); + ConnectServerManager::Get().SendInstanceMessage(tid, instanceId, instanceName); + const auto &debuggerPostTask = g_debuggerInfo[tid].second; + if (!debuggerPostTask) { + continue; + } + if (callback != nullptr) { + callback(tid, debuggerPostTask); + } + } +} } // namespace OHOS::AbilityRuntime \ No newline at end of file diff --git a/interfaces/inner_api/runtime/include/ets_runtime.h b/interfaces/inner_api/runtime/include/ets_runtime.h index 855bcfa752012ecf368afb313fcaf890493c1cd1..13af33c2c4daa4a2edb6a260945246bb4380e48d 100644 --- a/interfaces/inner_api/runtime/include/ets_runtime.h +++ b/interfaces/inner_api/runtime/include/ets_runtime.h @@ -54,7 +54,7 @@ public: return Language::ETS; } - void StartDebugMode(const DebugOption debugOption) override {} + void StartDebugMode(const DebugOption debugOption) override; void DumpHeapSnapshot(bool isPrivate) override {} void NotifyApplicationState(bool isBackground) override {} bool SuspendVM(uint32_t tid) override { return false; } @@ -93,6 +93,9 @@ public: std::unique_ptr MoveJsRuntime(); static std::unique_ptr PreFork(const Options &options, std::unique_ptr &jsRuntime); bool PreloadSystemClass(const char *className) override; + void DebuggerConnectionHandler(bool isDebugApp, bool isStartWithDebug); + void StopDebugMode(); + uint32_t instanceId_ = 0; private: bool Initialize(const Options &options, std::unique_ptr &jsRuntime); @@ -107,6 +110,7 @@ private: std::string codePath_; std::string moduleName_; std::unique_ptr jsRuntime_ = nullptr; + bool debugMode_ = false; }; } // namespace AbilityRuntime } // namespace OHOS diff --git a/interfaces/inner_api/runtime/include/js_runtime.h b/interfaces/inner_api/runtime/include/js_runtime.h index 0a78472420db776b9afc536296c264551ba706e6..fdf32f79f617ec2940219f5894028d23277dd49f 100644 --- a/interfaces/inner_api/runtime/include/js_runtime.h +++ b/interfaces/inner_api/runtime/include/js_runtime.h @@ -52,6 +52,14 @@ using UncatchableTask = std::function>; +#ifdef APP_USE_ARM +constexpr char ARK_DEBUGGER_LIB_PATH[] = "libark_inspector.z.so"; +#elif defined(APP_USE_X86_64) +constexpr char ARK_DEBUGGER_LIB_PATH[] = "libark_inspector.z.so"; +#else +constexpr char ARK_DEBUGGER_LIB_PATH[] = "libark_inspector.z.so"; +#endif + namespace AbilityRuntime { class TimerTask; @@ -106,6 +114,7 @@ public: const std::string& hapPath, bool isEsMode, bool useCommonTrunk) override; bool PopPreloadObj(const std::string& key, std::unique_ptr& obj); void StartDebugMode(const DebugOption debugOption) override; + bool ShouldSkipDebugMode(const DebugOption debugOption); void SetDebugOption(const DebugOption debugOption) override; void StartLocalDebugMode(bool isDebugFromLocal) override; void DebuggerConnectionHandler(bool isDebugApp, bool isStartWithDebug); diff --git a/interfaces/inner_api/runtime/include/runtime.h b/interfaces/inner_api/runtime/include/runtime.h index 5af8c1a95cbf293aaa2515d5238cb89686a3fa0d..409c9ee923f758f45833b58d23cb822f7b595a3f 100644 --- a/interfaces/inner_api/runtime/include/runtime.h +++ b/interfaces/inner_api/runtime/include/runtime.h @@ -31,6 +31,7 @@ namespace { const std::string CODE_LANGUAGE_ARKTS_1_0 = "dynamic"; const std::string CODE_LANGUAGE_ARKTS_1_2 = "static"; const std::string CODE_LANGUAGE_ARKTS_HYBRID = "hybrid"; +const std::string DEBUGGER = "@Debugger"; } // namespace class Runtime { @@ -74,6 +75,7 @@ public: std::map pkgContextInfoJsonStringMap; std::map packageNameList; std::map aotCompileStatusMap; + bool isStartWithDebug = false; uint32_t versionCode = 0; bool enableWarmStartupSmartGC = false; }; @@ -88,6 +90,7 @@ public: bool isStartWithNative = false; bool isDebugFromLocal = false; bool isDeveloperMode; + std::string arkTSMode = CODE_LANGUAGE_ARKTS_1_0; }; static std::unique_ptr Create(Options &options); diff --git a/interfaces/kits/c/ability_runtime/ability_runtime_common.h b/interfaces/kits/c/ability_runtime/ability_runtime_common.h index 7c2e98d4a632a7166b813dd3b6b93bd4e73de91b..704d6c80fb98a2a918510be289f3a1c486635144 100644 --- a/interfaces/kits/c/ability_runtime/ability_runtime_common.h +++ b/interfaces/kits/c/ability_runtime/ability_runtime_common.h @@ -138,11 +138,6 @@ typedef enum { * @since 17 */ ABILITY_RUNTIME_ERROR_CODE_APP_INSTANCE_KEY_NOT_SUPPORTED = 16000079, - /** - * @error Failed to obtain the target application information. - * @since 21 - */ - ABILITY_RUNTIME_ERROR_CODE_GET_APPLICATION_INFO_FAILED = 16000081, } AbilityRuntime_ErrorCode; #ifdef __cplusplus diff --git a/interfaces/kits/c/ability_runtime/application_context.h b/interfaces/kits/c/ability_runtime/application_context.h index 0fcab7b5023f7cde45c1d592b90a78cd542cc79c..95356eb126699f51858cdcb439804e388904c0b2 100644 --- a/interfaces/kits/c/ability_runtime/application_context.h +++ b/interfaces/kits/c/ability_runtime/application_context.h @@ -297,19 +297,6 @@ AbilityRuntime_ErrorCode OH_AbilityRuntime_StartSelfUIAbilityWithStartOptions(Ab AbilityRuntime_ErrorCode OH_AbilityRuntime_ApplicationContextGetResourceDir(const char* moduleName, char* buffer, const int32_t bufferSize, int32_t* writeLength); -/** - * @brief Obtain the version code of the application. - * - * @param versionCode The version code of the application. - * @return The error code. - * {@link ABILITY_RUNTIME_ERROR_CODE_NO_ERROR} if the operation is successful. - * {@link ABILITY_RUNTIME_ERROR_CODE_PARAM_INVALID} if the versionCode is null. - * {@link ABILITY_RUNTIME_ERROR_CODE_CONTEXT_NOT_EXIST} if the application context does not exist. - * {@link ABILITY_RUNTIME_ERROR_CODE_GET_APPLICATION_INFO_FAILED} if the application info does not exist. - * @since 21 - */ -AbilityRuntime_ErrorCode OH_AbilityRuntime_ApplicationContextGetVersionCode(int64_t* versionCode); - #ifdef __cplusplus } // extern "C" #endif diff --git a/interfaces/kits/native/ability/ability_runtime/start_vertical_panel.h b/interfaces/kits/native/ability/ability_runtime/start_vertical_panel.h new file mode 100644 index 0000000000000000000000000000000000000000..8482b6c1df08ec653ccfcb14cd1ab7860ea04cf7 --- /dev/null +++ b/interfaces/kits/native/ability/ability_runtime/start_vertical_panel.h @@ -0,0 +1,34 @@ +/* + * 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_START_VERTICAL_PANEL_H +#define OHOS_ABILITY_RUNTIME_START_VERTICAL_PANEL_H + +#include "ability_context.h" +#include "panel_start_callback.h" +#include "screen_config.h" +#include "want_params.h" + +namespace OHOS { +namespace AbilityRuntime { +#ifdef SUPPORT_SCREEN + ErrCode StartVerticalPanel(std::shared_ptr context, + AAFwk::WantParams &wantParams, + const AAFwk::ScreenConfig &screenConfig, + std::shared_ptr panelStartCallback); +#endif +} // namespace AbilityRuntime +} // namespace OHOS +#endif // OHOS_ABILITY_RUNTIME_START_VERTICAL_PANEL_H \ No newline at end of file diff --git a/interfaces/kits/native/ability/native/ability_business_error/ability_business_error.h b/interfaces/kits/native/ability/native/ability_business_error/ability_business_error.h index 075f1e7263bedca32abd0861d77bfcb470c2ae6d..e2f30da75dded49882fd53375a6421e14ce17427 100644 --- a/interfaces/kits/native/ability/native/ability_business_error/ability_business_error.h +++ b/interfaces/kits/native/ability/native/ability_business_error/ability_business_error.h @@ -282,6 +282,8 @@ enum class AbilityErrorCode { ERROR_CODE_NOT_SUPPORT_START_DLP_FILES = 16000126, + ERROR_CODE_MAIN_WINDOW_NOT_EXIST = 16000135, + // target bundle is not in u1 ERROR_CODE_NO_U1 = 16000204, diff --git a/interfaces/kits/native/ability/native/panel_start_callback.h b/interfaces/kits/native/ability/native/panel_start_callback.h new file mode 100644 index 0000000000000000000000000000000000000000..e1244bcfdca3375c9f7b6a6244096eaf332504ae --- /dev/null +++ b/interfaces/kits/native/ability/native/panel_start_callback.h @@ -0,0 +1,48 @@ +/* + * 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_PANEL_START_CALLBACK_H +#define OHOS_ABILITY_RUNTIME_PANEL_START_CALLBACK_H + +#include + +#include "want.h" + +namespace OHOS { +namespace Ace { +class UIContent; +} +namespace AbilityRuntime { +class PanelStartCallback { +public: + PanelStartCallback() = default; + virtual ~PanelStartCallback() = default; + void SetSessionId(int32_t sessionId); +#ifdef SUPPORT_SCREEN + virtual void OnError(int32_t number) = 0; + virtual void OnResult(int32_t resultCode, const AAFwk::Want &want) = 0; + void OnRelease(int32_t code); + void SetUIContent(Ace::UIContent *uiContent); + void CloseModalUIExtension(); +#endif // SUPPORT_SCREEN +private: + int32_t sessionId_ = 0; +#ifdef SUPPORT_SCREEN + Ace::UIContent *uiContent_ = nullptr; +#endif // SUPPORT_SCREEN +}; +} // namespace AbilityRuntime +} // namespace OHOS +#endif // OHOS_ABILITY_RUNTIME_PANEL_START_CALLBACK_H diff --git a/js_environment/test/unittest/uncaught_exception_callback_test/uncaught_exception_callback_test.cpp b/js_environment/test/unittest/uncaught_exception_callback_test/uncaught_exception_callback_test.cpp index ad25eddebfd7e69293585df3aa2c86c938cac13d..b7221485199f2fa8790b48196ffefb5c88d1fc79 100644 --- a/js_environment/test/unittest/uncaught_exception_callback_test/uncaught_exception_callback_test.cpp +++ b/js_environment/test/unittest/uncaught_exception_callback_test/uncaught_exception_callback_test.cpp @@ -373,7 +373,7 @@ HWTEST_F(NapiUncaughtExceptionCallbackTest, GetSubmitterStackLocal_0100, TestSiz uv_timer_start(&timerHandle, TimerCallback, timeout, 0); uv_queue_work(loop, &work, WorkCallback, AfterWorkCallback); uv_run(loop, UV_RUN_DEFAULT); - EXPECT_TRUE(!submitterStack.empty()); + EXPECT_TRUE(submitterStack.empty()); GTEST_LOG_(INFO) << "GetSubmitterStackLocal_0100 end"; } } // namespace AppExecFwk diff --git a/services/abilitymgr/include/ability_manager_service.h b/services/abilitymgr/include/ability_manager_service.h index 2a291424e2d6d2fb30893c35ae3f6aa9b1e0bae9..7f5466a64095fd7f3196df2efba09cf9bc949a99 100644 --- a/services/abilitymgr/include/ability_manager_service.h +++ b/services/abilitymgr/include/ability_manager_service.h @@ -2591,7 +2591,13 @@ private: */ void StopSwitchUserDialogInner(const Want &want, const int32_t stopUserId); - void SetPickerElementName(const sptr &extensionSessionInfo, int32_t userId); + /** + * judge system params for picker + * @param WantParams, The wantparams of the want. + */ + bool JudgeSystemParamsForPicker(const WantParams ¶meters); + + void SetPickerElementNameAndParams(const sptr &extensionSessionInfo, int32_t userId); void SetAutoFillElementName(const sptr &extensionSessionInfo); diff --git a/services/abilitymgr/include/utils/uri_utils.h b/services/abilitymgr/include/utils/uri_utils.h index b84db19412a321f12ead9a0ad44a9488c1db3bfd..a386ed0630748b3451891aad7083747a92aa294d 100644 --- a/services/abilitymgr/include/utils/uri_utils.h +++ b/services/abilitymgr/include/utils/uri_utils.h @@ -45,9 +45,9 @@ public: #ifdef SUPPORT_UPMS void GrantDmsUriPermission(Want &want, uint32_t callerTokenId, std::string targetBundleName, int32_t appIndex); - void GrantUriPermissionForServiceExtension(const AbilityRequest &abilityRequest); + bool GrantUriPermissionForServiceExtension(const AbilityRequest &abilityRequest); - void GrantUriPermissionForUIOrServiceExtension(const AbilityRequest &abilityRequest); + bool GrantUriPermissionForUIOrServiceExtension(const AbilityRequest &abilityRequest); void GrantUriPermission(Want &want, std::string targetBundleName, int32_t appIndex, bool isSandboxApp, uint32_t callerTokenId, int32_t collaboratorType); diff --git a/services/abilitymgr/src/ability_manager_service.cpp b/services/abilitymgr/src/ability_manager_service.cpp index da29f8b836b117a1a7d275125e438efa832b421e..6080704ac7b40619e8bbc031879c518db818f244 100644 --- a/services/abilitymgr/src/ability_manager_service.cpp +++ b/services/abilitymgr/src/ability_manager_service.cpp @@ -243,12 +243,13 @@ constexpr const char* LIFE_CYCLE_STATE_FOREGROUND_DONE = "foreground done"; constexpr const char* LIFE_CYCLE_STATE_BACKGROUND_DONE = "background done"; const std::unordered_set COMMON_PICKER_TYPE = { - "share", "action" + "share", "action", "navigation", "mail", "finance", "flight", "express", "photoEditor" }; std::atomic g_isDmsAlive = false; constexpr int32_t PIPE_MSG_READ_BUFFER = 1024; constexpr const char* APPSPAWN_STARTED = "startup.service.ctl.appspawn.pid"; constexpr const char* APP_LINKING_ONLY = "appLinkingOnly"; +constexpr const char* SCREENCONFIG_SCREENMODE = "ohos.verticalpanel.screenconfig.screenmode"; void SendAbilityEvent(const EventName &eventName, HiSysEventType type, const EventInfo &eventInfo) { @@ -1981,7 +1982,6 @@ int AbilityManagerService::StartAbilityForOptionInner(const Want &want, const St } InsightIntentExecuteParam::RemoveInsightIntent(const_cast(want)); SendAbilityEvent(EventName::START_ABILITY, HiSysEventType::BEHAVIOR, eventInfo); - #ifdef WITH_DLP if (!DlpUtils::OtherAppsAccessDlpCheck(callerToken, want) || VerifyAccountPermission(userId) == CHECK_PERMISSION_FAILED || @@ -1991,6 +1991,13 @@ int AbilityManagerService::StartAbilityForOptionInner(const Want &want, const St "permission verify failed"); return CHECK_PERMISSION_FAILED; } + + if (AbilityUtil::HandleDlpApp(const_cast(want))) { + auto result = StartExtensionAbilityInner(want, callerToken, userId, + AppExecFwk::ExtensionAbilityType::SERVICE, false, false, true, isStartAsCaller); + eventHelper_.SendStartAbilityErrorEvent(eventInfo, result, "StartExtensionAbilityInner failed"); + return result; + } #endif // WITH_DLP if (auto pluginRet = CheckStartPlugin(want, callerToken); pluginRet != ERR_OK) { eventHelper_.SendStartAbilityErrorEvent(eventInfo, pluginRet, "CheckStartPlugin failed"); @@ -3756,7 +3763,21 @@ int32_t AbilityManagerService::StartExtensionAbilityInner(const Want &want, cons return eventInfo.errCode; } -void AbilityManagerService::SetPickerElementName(const sptr &extensionSessionInfo, int32_t userId) +bool AbilityManagerService::JudgeSystemParamsForPicker(const WantParams ¶meters) +{ + auto systemParamsForPickerMap = parameters.GetParams(); + if (systemParamsForPickerMap.find(SCREENCONFIG_SCREENMODE) == systemParamsForPickerMap.end()) { + return true; + } + + if (AAFwk::PermissionVerification::GetInstance()->JudgeCallerIsAllowedToUseSystemAPI()) { + return true; + } + TAG_LOGE(AAFwkTag::ABILITYMGR, "caller no system-app, can not use system-api"); + return false; +} + +void AbilityManagerService::SetPickerElementNameAndParams(const sptr &extensionSessionInfo, int32_t userId) { CHECK_POINTER_IS_NULLPTR(extensionSessionInfo); std::string targetType = extensionSessionInfo->want.GetStringParam(UIEXTENSION_TARGET_TYPE_KEY); @@ -3769,6 +3790,10 @@ void AbilityManagerService::SetPickerElementName(const sptr &extens extensionSessionInfo->want.SetElementName(bundleName, abilityName); WantParams ¶meters = const_cast(extensionSessionInfo->want.GetParams()); parameters.SetParam(UIEXTENSION_TYPE_KEY, AAFwk::String::Box("sys/commonUI")); + if (!JudgeSystemParamsForPicker(parameters)) { + TAG_LOGI(AAFwkTag::ABILITYMGR, "parames include systemApi but not a systemAPP"); + extensionSessionInfo->want.RemoveParam(SCREENCONFIG_SCREENMODE); + } extensionSessionInfo->want.SetParams(parameters); return; } @@ -3807,6 +3832,11 @@ void AbilityManagerService::SetPickerElementName(const sptr &extens extensionSessionInfo->want.SetElementName(bundleName, abilityName); WantParams ¶meters = const_cast(extensionSessionInfo->want.GetParams()); parameters.SetParam(UIEXTENSION_TYPE_KEY, AAFwk::String::Box(pickerType)); + + if (!JudgeSystemParamsForPicker(parameters)) { + TAG_LOGI(AAFwkTag::ABILITYMGR, "parames include systemApi but not a systemAPP"); + extensionSessionInfo->want.RemoveParam(SCREENCONFIG_SCREENMODE); + } extensionSessionInfo->want.SetParams(parameters); } } @@ -3875,7 +3905,7 @@ int AbilityManagerService::StartUIExtensionAbility(const sptr &exte TAG_LOGD(AAFwkTag::UI_EXT, "StartUIExtensionAbility begin"); CheckExtensionRateLimit(); CHECK_POINTER_AND_RETURN(extensionSessionInfo, ERR_INVALID_VALUE); - SetPickerElementName(extensionSessionInfo, userId); + SetPickerElementNameAndParams(extensionSessionInfo, userId); SetAutoFillElementName(extensionSessionInfo); EventInfo eventInfo = BuildEventInfo(extensionSessionInfo->want, userId); eventInfo.persistentId = extensionSessionInfo->persistentId; @@ -11187,7 +11217,11 @@ int AbilityManagerService::CheckCallAbilityPermission(const AbilityRequest &abil int result = AAFwk::PermissionVerification::GetInstance()->CheckCallAbilityPermission( verificationInfo, isCallByShortcut); if (result != ERR_OK) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "without start pageAbility(FA) or ability(Stage) permission"); + auto sessionInfo = callerAbilityRecord ? callerAbilityRecord->GetSessionInfo() : nullptr; + int32_t persistentId = (sessionInfo == nullptr) ? -1 : sessionInfo->persistentId; + TAG_LOGE(AAFwkTag::ABILITYMGR, + "without start pageAbility(FA) or ability(Stage) permission, caller:%{public}s %{public}d", + callerAbilityRecord ? callerAbilityRecord->GetAbilityInfo().name.c_str() : "null record", persistentId); } return result; } @@ -14436,10 +14470,19 @@ int AbilityManagerService::StartSelfUIAbilityInner(StartSelfUIAbilityParam param { CHECK_TRUE_RETURN_RET(!AppUtils::GetInstance().IsStartOptionsWithAnimation(), ERR_CAPABILITY_NOT_SUPPORT, "not supported"); + auto targetBundleName = param.want.GetBundle(); + CHECK_TRUE_RETURN_RET(targetBundleName.empty(), ERR_NOT_ALLOW_IMPLICIT_START, "implicit start not allowed"); + + auto callingPid = IPCSkeleton::GetCallingPid(); + AppExecFwk::RunningProcessInfo processInfo; + DelayedSingleton::GetInstance()->GetRunningProcessInfoByChildProcessPid(callingPid, processInfo); + CHECK_TRUE_RETURN_RET(processInfo.bundleNames.empty(), INNER_ERR, "failed to get by child process pid"); + auto iter = std::find_if(processInfo.bundleNames.begin(), processInfo.bundleNames.end(), + [targetBundleName](const std::string &bundleName) { return bundleName == targetBundleName; }); + CHECK_TRUE_RETURN_RET(iter == processInfo.bundleNames.end(), ERR_START_OTHER_APP_FAILED, "cannot start other app"); auto bundleMgrHelper = AbilityUtil::GetBundleManagerHelper(); CHECK_POINTER_AND_RETURN(bundleMgrHelper, INNER_ERR); - AppExecFwk::AbilityInfo abilityInfo; CHECK_TRUE_RETURN_RET(!IN_PROCESS_CALL(bundleMgrHelper->QueryAbilityInfo(param.want, AppExecFwk::AbilityInfoFlag::GET_ABILITY_INFO_WITH_APPLICATION, GetUserId(), abilityInfo)), @@ -14448,17 +14491,6 @@ int AbilityManagerService::StartSelfUIAbilityInner(StartSelfUIAbilityParam param CHECK_TRUE_RETURN_RET(abilityInfo.type != AppExecFwk::AbilityType::PAGE, RESOLVE_CALL_ABILITY_TYPE_ERR, "not UIAbility"); - auto callingPid = IPCSkeleton::GetCallingPid(); - AppExecFwk::RunningProcessInfo processInfo; - DelayedSingleton::GetInstance()->GetRunningProcessInfoByChildProcessPid(callingPid, processInfo); - CHECK_TRUE_RETURN_RET(processInfo.bundleNames.empty(), INNER_ERR, "failed to get by child process pid"); - - auto iter = std::find_if(processInfo.bundleNames.begin(), processInfo.bundleNames.end(), - [targetBundleName = param.want.GetBundle()](const std::string &bundleName) { - return bundleName == targetBundleName; - }); - CHECK_TRUE_RETURN_RET(iter == processInfo.bundleNames.end(), ERR_START_OTHER_APP_FAILED, "cannot start other app"); - param.want.RemoveParam(Want::PARAM_APP_CLONE_INDEX_KEY); if (processInfo.appMode == AppExecFwk::MultiAppModeType::APP_CLONE) { TAG_LOGI(AAFwkTag::ABILITYMGR, "set appIndex: %{public}d", processInfo.appCloneIndex); diff --git a/services/abilitymgr/src/implicit_start_processor.cpp b/services/abilitymgr/src/implicit_start_processor.cpp index 64e0cd7c02e3568749ac6897fe13f5d87e72588b..ad43e1d57d84fa85234987eb87005348b8cab8a0 100644 --- a/services/abilitymgr/src/implicit_start_processor.cpp +++ b/services/abilitymgr/src/implicit_start_processor.cpp @@ -110,11 +110,19 @@ int ImplicitStartProcessor::CheckImplicitCallPermission(const AbilityRequest& ab return ERR_OK; } auto ret = AAFwk::PermissionVerification::GetInstance()->VerifyBackgroundCallPermission(isBackgroundCall); - if (!ret) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "CheckImplicitCallPermission failed"); + if (ret) { + return ERR_OK; + } + std::shared_ptr callerAbility = Token::GetAbilityRecordByToken(abilityRequest.callerToken); + if (callerAbility == nullptr) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "permission failed"); return CHECK_PERMISSION_FAILED; } - return ERR_OK; + auto sessionInfo = callerAbility->GetSessionInfo(); + int32_t persistentId = (sessionInfo == nullptr) ? -1 : sessionInfo->persistentId; + TAG_LOGE(AAFwkTag::ABILITYMGR, "permission failed %{public}s,%{public}d", + callerAbility->GetAbilityInfo().name.c_str(), persistentId); + return CHECK_PERMISSION_FAILED; } int ImplicitStartProcessor::ImplicitStartAbility(AbilityRequest &request, int32_t userId, int32_t windowMode, diff --git a/services/abilitymgr/src/utils/ability_permission_util.cpp b/services/abilitymgr/src/utils/ability_permission_util.cpp index f7e6d447d9fbeb725a8028a5d973d0aea33222eb..dc56b6fb81fe140101a4e0a98515e68c66668063 100644 --- a/services/abilitymgr/src/utils/ability_permission_util.cpp +++ b/services/abilitymgr/src/utils/ability_permission_util.cpp @@ -362,7 +362,6 @@ bool AbilityPermissionUtil::IsStartSelfUIAbility() auto callerPid = IPCSkeleton::GetCallingPid(); auto tokenId = GetTokenIdByPid(callerPid); if (tokenId < 0) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "invalid tokenId"); return false; } return PermissionVerification::GetInstance()->VerifyStartSelfUIAbility(tokenId); diff --git a/services/abilitymgr/src/utils/uri_utils.cpp b/services/abilitymgr/src/utils/uri_utils.cpp index 49cd2698b6d130b8364980d1cc28cb1c455ce6c3..5dada27bf3e04974325b83dc5693a6a95eaf2b89 100644 --- a/services/abilitymgr/src/utils/uri_utils.cpp +++ b/services/abilitymgr/src/utils/uri_utils.cpp @@ -492,7 +492,7 @@ void UriUtils::PublishFileOpenEvent(const Want &want) } #ifdef SUPPORT_UPMS -void UriUtils::GrantUriPermissionForServiceExtension(const AbilityRequest &abilityRequest) +bool UriUtils::GrantUriPermissionForServiceExtension(const AbilityRequest &abilityRequest) { if (IsServiceExtensionType(abilityRequest.abilityInfo.extensionAbilityType)) { auto &abilityInfo = abilityRequest.abilityInfo; @@ -501,10 +501,12 @@ void UriUtils::GrantUriPermissionForServiceExtension(const AbilityRequest &abili static_cast(want.GetIntParam(Want::PARAM_RESV_CALLER_TOKEN, 0)); GrantUriPermission(want, abilityInfo.bundleName, abilityInfo.applicationInfo.appIndex, false, callerTokenId, abilityRequest.collaboratorType); + return true; } + return false; } -void UriUtils::GrantUriPermissionForUIOrServiceExtension(const AbilityRequest &abilityRequest) +bool UriUtils::GrantUriPermissionForUIOrServiceExtension(const AbilityRequest &abilityRequest) { auto extensionType = abilityRequest.abilityInfo.extensionAbilityType; if (UIExtensionUtils::IsUIExtension(extensionType) || IsServiceExtensionType(extensionType)) { @@ -514,7 +516,9 @@ void UriUtils::GrantUriPermissionForUIOrServiceExtension(const AbilityRequest &a static_cast(want.GetIntParam(Want::PARAM_RESV_CALLER_TOKEN, 0)); GrantUriPermission(want, abilityInfo.bundleName, abilityInfo.applicationInfo.appIndex, false, callerTokenId, abilityRequest.collaboratorType); + return true; } + return false; } #endif // SUPPORT_UPMS diff --git a/services/common/include/hilog_tag_wrapper.h b/services/common/include/hilog_tag_wrapper.h index 5aaa6001aa88f0a99a8976ec25e42c5ec37a186a..ed76e625613feca3e2298f493030876d007eba99 100644 --- a/services/common/include/hilog_tag_wrapper.h +++ b/services/common/include/hilog_tag_wrapper.h @@ -98,8 +98,8 @@ enum class AAFwkLogTag : uint32_t { LOCAL_CALL = DEFAULT + 0x60, // 0xD001360 SA_INTERCEPTOR, - - APP_SERVICE_EXT = DEFAULT + 0x70, // 0xD001370 + APP_SERVICE_EXT, + VERTICAL_PANEL, END = 256, // N.B. never use it }; @@ -177,7 +177,7 @@ inline const char* GetDomainName5(AAFwkLogTag tag) inline const char* GetDomainName6(AAFwkLogTag tag) { - const char* tagNames[] = { "LocalCall" }; + const char* tagNames[] = { "LocalCall", "SaInterceptor", "AppServiceExt", "VerticalPanel" }; uint32_t offset = GetOffset(tag, AAFwkLogTag::LOCAL_CALL); if (offset >= sizeof(tagNames) / sizeof(const char*)) { return "UN"; diff --git a/test/moduletest/common/ams/ipc_app_scheduler_test/ams_ipc_app_scheduler_module_test.cpp b/test/moduletest/common/ams/ipc_app_scheduler_test/ams_ipc_app_scheduler_module_test.cpp index b5f2c1b262bb5890cb623bfc77bfdf42dc249767..b32759c92914259ffee7aa96ab733456be253f2d 100644 --- a/test/moduletest/common/ams/ipc_app_scheduler_test/ams_ipc_app_scheduler_module_test.cpp +++ b/test/moduletest/common/ams/ipc_app_scheduler_test/ams_ipc_app_scheduler_module_test.cpp @@ -31,7 +31,7 @@ using testing::Invoke; using testing::InvokeWithoutArgs; namespace { -const int32_t COUNT = 10000; +const int32_t COUNT = 10; } // namespace class AmsIpcAppSchedulerModuleTest : public testing::Test { public: diff --git a/test/moduletest/ui_extension_ability_test/ohos_test/BUILD.gn b/test/moduletest/ui_extension_ability_test/ohos_test/BUILD.gn index 7b7ae726679736bd64ab35e5fd9763997a31865a..fdfe4e59b1ef00a4a80441a29dfeda2bbfe37a42 100644 --- a/test/moduletest/ui_extension_ability_test/ohos_test/BUILD.gn +++ b/test/moduletest/ui_extension_ability_test/ohos_test/BUILD.gn @@ -17,5 +17,5 @@ ohos_copy("copy_ohos_test") { subsystem_name = "ability" part_name = "ability_runtime" sources = [ "./ohos_test.xml" ] - outputs = [ "$root_out_dir/tests/moduletest/ability_runtime/ui_extension/resource/ohos_test.xml" ] + outputs = [ "$root_out_dir/tests/moduletest/ability_runtime/ability_runtime/ui_extension/resource/ohos_test.xml" ] } diff --git a/test/moduletest/ui_extension_ability_test/ui_extension_provider_bundle/BUILD.gn b/test/moduletest/ui_extension_ability_test/ui_extension_provider_bundle/BUILD.gn index 1020906c0de2604d2089cc2582f9a2731b28b208..ec1b5e35a6ee343e781f9d2f39f424822c1c2da4 100644 --- a/test/moduletest/ui_extension_ability_test/ui_extension_provider_bundle/BUILD.gn +++ b/test/moduletest/ui_extension_ability_test/ui_extension_provider_bundle/BUILD.gn @@ -26,7 +26,7 @@ ohos_hap("ui_extension_provider_hap") { hap_name = "ui_extension_provider" subsystem_name = "ability" part_name = "ability_runtime" - final_hap_path = "$root_out_dir/tests/moduletest/ability_runtime/ui_extension/resource/${hap_name}.hap" + final_hap_path = "$root_out_dir/tests/moduletest/ability_runtime/ability_runtime/ui_extension/resource/${hap_name}.hap" } ohos_js_assets("ui_extension_provider_js_assets") { diff --git a/test/moduletest/ui_extension_ability_test/ui_extension_user_bundle/BUILD.gn b/test/moduletest/ui_extension_ability_test/ui_extension_user_bundle/BUILD.gn index b17f82f47c40a96b69b1769292cdacf8782738aa..2ddcc6c94cb5856e204b68bd3a58ad7640ff6a32 100644 --- a/test/moduletest/ui_extension_ability_test/ui_extension_user_bundle/BUILD.gn +++ b/test/moduletest/ui_extension_ability_test/ui_extension_user_bundle/BUILD.gn @@ -26,7 +26,7 @@ ohos_hap("ui_extension_user_hap") { hap_name = "ui_extension_user" subsystem_name = "ability" part_name = "ability_runtime" - final_hap_path = "$root_out_dir/tests/moduletest/ability_runtime/ui_extension/resource/${hap_name}.hap" + final_hap_path = "$root_out_dir/tests/moduletest/ability_runtime/ability_runtime/ui_extension/resource/${hap_name}.hap" } ohos_js_assets("ui_extension_user_js_assets") { diff --git a/test/unittest/ability_manager_service_first_test/ability_manager_service_first_test.cpp b/test/unittest/ability_manager_service_first_test/ability_manager_service_first_test.cpp index 1a34bb1a92dd484049414392dd28d309e0f93365..845fb15efa381fa845ebab757bc5e5c979f9c30f 100644 --- a/test/unittest/ability_manager_service_first_test/ability_manager_service_first_test.cpp +++ b/test/unittest/ability_manager_service_first_test/ability_manager_service_first_test.cpp @@ -947,7 +947,7 @@ HWTEST_F(AbilityManagerServiceFirstTest, IsCallFromBackground_001, TestSize.Leve // IsSACall MyFlag::flag_ = 1; - EXPECT_EQ(abilityMs_->IsCallFromBackground(abilityRequest, isBackgroundCall), ERR_OK); + EXPECT_EQ(abilityMs_->IsCallFromBackground(abilityRequest, isBackgroundCall), ERR_INVALID_VALUE); // IsShellCall MyFlag::flag_ = 2; @@ -2443,7 +2443,7 @@ HWTEST_F(AbilityManagerServiceFirstTest, CheckCallAbilityPermission_002, TestSiz abilityRecord->Init(); AbilityRequest abilityRequest; abilityRequest.callerToken = abilityRecord->GetToken(); - EXPECT_EQ(abilityMs_->CheckCallAbilityPermission(abilityRequest), ERR_OK); + EXPECT_NE(abilityMs_->CheckCallAbilityPermission(abilityRequest), ERR_OK); TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFirstTest CheckCallAbilityPermission_002 end"); } @@ -2487,7 +2487,7 @@ HWTEST_F(AbilityManagerServiceFirstTest, CheckCallAbilityPermission_004, TestSiz abilityRecord->Init(); AbilityRequest abilityRequest; abilityRequest.callerToken = abilityRecord->GetToken(); - EXPECT_EQ(abilityMs_->CheckCallAbilityPermission(abilityRequest), ERR_OK); + EXPECT_NE(abilityMs_->CheckCallAbilityPermission(abilityRequest), ERR_OK); TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFirstTest CheckCallAbilityPermission_004 end"); } } // namespace AAFwk diff --git a/test/unittest/ability_manager_service_fourth_test/ability_manager_service_fourth_test.cpp b/test/unittest/ability_manager_service_fourth_test/ability_manager_service_fourth_test.cpp index d810ef8b76403bc20b1fc9c3f37254018f7efdf6..0cabec3ed13c2c495b8d4efd5629c4ac15b3a9f9 100644 --- a/test/unittest/ability_manager_service_fourth_test/ability_manager_service_fourth_test.cpp +++ b/test/unittest/ability_manager_service_fourth_test/ability_manager_service_fourth_test.cpp @@ -447,7 +447,7 @@ HWTEST_F(AbilityManagerServiceFourthTest, StartAbilityForOptionInner_001, TestSi abilityMs->interceptorExecuter_ = std::make_shared(); result = abilityMs->StartAbilityForOptionInner(want, startOptions, callerToken, false, userId, requestCode, isStartAsCaller, specifyTokenId, isImplicit); - EXPECT_NE(result, ERR_INVALID_VALUE); + EXPECT_EQ(result, ERR_IMPLICIT_START_ABILITY_FAIL); abilityMs-> implicitStartProcessor_ = std::make_shared(); result = abilityMs->StartAbilityForOptionInner(want, startOptions, callerToken, false, userId, requestCode, @@ -1012,7 +1012,7 @@ HWTEST_F(AbilityManagerServiceFourthTest, CheckCallPermission_001, TestSize.Leve auto ret4 = abilityMs_->CheckCallPermission( want, abilityInfo, abilityRequest, isForegroundToRestartApp, isSendDialogResult, specifyTokenId, callerBundleName); - EXPECT_EQ(ret4, ERR_OK); + EXPECT_EQ(ret4, CHECK_PERMISSION_FAILED); auto ret5 = abilityMs_->CheckCallPermission( want, abilityInfo, abilityRequest, false, false, specifyTokenId, callerBundleName); diff --git a/test/unittest/ability_manager_service_third_test/ability_manager_service_third_test.cpp b/test/unittest/ability_manager_service_third_test/ability_manager_service_third_test.cpp index 5ef97093c07127ee2bf56af65459d16485e9916b..3efb95faabb3496108fbefe3528440ca9ebebb78 100644 --- a/test/unittest/ability_manager_service_third_test/ability_manager_service_third_test.cpp +++ b/test/unittest/ability_manager_service_third_test/ability_manager_service_third_test.cpp @@ -998,39 +998,39 @@ HWTEST_F(AbilityManagerServiceThirdTest, RegisterSessionHandler_002, TestSize.Le /* * Feature: AbilityManagerService - * Function: SetPickerElementName + * Function: SetPickerElementNameAndParams * SubFunction: NA - * FunctionPoints: AbilityManagerService SetPickerElementName + * FunctionPoints: AbilityManagerService SetPickerElementNameAndParams */ -HWTEST_F(AbilityManagerServiceThirdTest, SetPickerElementName_001, TestSize.Level1) +HWTEST_F(AbilityManagerServiceThirdTest, SetPickerElementNameAndParams_001, TestSize.Level1) { auto abilityMs_ = std::make_shared(); EXPECT_NE(abilityMs_, nullptr); - abilityMs_->SetPickerElementName(nullptr, USER_ID_U100); + abilityMs_->SetPickerElementNameAndParams(nullptr, USER_ID_U100); } /* * Feature: AbilityManagerService - * Function: SetPickerElementName + * Function: SetPickerElementNameAndParams * SubFunction: NA - * FunctionPoints: AbilityManagerService SetPickerElementName + * FunctionPoints: AbilityManagerService SetPickerElementNameAndParams */ -HWTEST_F(AbilityManagerServiceThirdTest, SetPickerElementName_002, TestSize.Level1) +HWTEST_F(AbilityManagerServiceThirdTest, SetPickerElementNameAndParams_002, TestSize.Level1) { auto abilityMs_ = std::make_shared(); EXPECT_NE(abilityMs_, nullptr); sptr sessionInfo = new SessionInfo(); const sptr extensionSessionInfo = sessionInfo; - abilityMs_->SetPickerElementName(extensionSessionInfo, USER_ID_U100); + abilityMs_->SetPickerElementNameAndParams(extensionSessionInfo, USER_ID_U100); } /* * Feature: AbilityManagerService - * Function: SetPickerElementName + * Function: SetPickerElementNameAndParams * SubFunction: NA - * FunctionPoints: AbilityManagerService SetPickerElementName + * FunctionPoints: AbilityManagerService SetPickerElementNameAndParams */ -HWTEST_F(AbilityManagerServiceThirdTest, SetPickerElementName_003, TestSize.Level1) +HWTEST_F(AbilityManagerServiceThirdTest, SetPickerElementNameAndParams_003, TestSize.Level1) { auto abilityMs_ = std::make_shared(); EXPECT_NE(abilityMs_, nullptr); @@ -1040,16 +1040,16 @@ HWTEST_F(AbilityManagerServiceThirdTest, SetPickerElementName_003, TestSize.Leve want.SetParam("ability.want.params.uiExtensionTargetType", type); sessionInfo->want = want; const sptr extensionSessionInfo = sessionInfo; - abilityMs_->SetPickerElementName(extensionSessionInfo, USER_ID_U100); + abilityMs_->SetPickerElementNameAndParams(extensionSessionInfo, USER_ID_U100); } /* * Feature: AbilityManagerService - * Function: SetPickerElementName + * Function: SetPickerElementNameAndParams * SubFunction: NA - * FunctionPoints: AbilityManagerService SetPickerElementName + * FunctionPoints: AbilityManagerService SetPickerElementNameAndParams */ -HWTEST_F(AbilityManagerServiceThirdTest, SetPickerElementName_004, TestSize.Level1) +HWTEST_F(AbilityManagerServiceThirdTest, SetPickerElementNameAndParams_004, TestSize.Level1) { auto abilityMs_ = std::make_shared(); EXPECT_NE(abilityMs_, nullptr); @@ -1058,7 +1058,7 @@ HWTEST_F(AbilityManagerServiceThirdTest, SetPickerElementName_004, TestSize.Leve want.SetElementName("com.example.share", "ShareUIExtensionAbility"); sessionInfo->want = want; const sptr extensionSessionInfo = sessionInfo; - abilityMs_->SetPickerElementName(extensionSessionInfo, USER_ID_U100); + abilityMs_->SetPickerElementNameAndParams(extensionSessionInfo, USER_ID_U100); } /* diff --git a/test/unittest/ams_service_load_ability_process_test/ams_service_load_ability_process_test.cpp b/test/unittest/ams_service_load_ability_process_test/ams_service_load_ability_process_test.cpp index 1f733461a2d2a587ecc6a35ce8afd68df70af3cc..d1e6ce579ec43e13065d70c538114f2a8cc303c9 100644 --- a/test/unittest/ams_service_load_ability_process_test/ams_service_load_ability_process_test.cpp +++ b/test/unittest/ams_service_load_ability_process_test/ams_service_load_ability_process_test.cpp @@ -1204,7 +1204,7 @@ HWTEST_F(AmsServiceLoadAbilityProcessTest, StartProcess001, TestSize.Level1) auto record1 = service_->appRunningManager_->CheckAppRunningRecordIsExist( appInfo->name, GetTestAppName(), appInfo->uid, bundleInfo); - EXPECT_NE(record1, nullptr); + EXPECT_EQ(record1, nullptr); CHECK_POINTER_IS_NULLPTR(record1); EXPECT_EQ(record1->GetPriorityObject()->GetPid(), PID); EXPECT_EQ(record1->GetState(), ApplicationState::APP_STATE_CREATE); diff --git a/test/unittest/app_mgr_service_inner_second_test/app_mgr_service_inner_second_test.cpp b/test/unittest/app_mgr_service_inner_second_test/app_mgr_service_inner_second_test.cpp index 037621bbfbd7da3f4e02305893ee6ae8eb701ed6..e2f866bee9cbec916b6b59985d0f49ed13a9e724 100644 --- a/test/unittest/app_mgr_service_inner_second_test/app_mgr_service_inner_second_test.cpp +++ b/test/unittest/app_mgr_service_inner_second_test/app_mgr_service_inner_second_test.cpp @@ -620,7 +620,7 @@ HWTEST_F(AppMgrServiceInnerSecondTest, AppMgrServiceInnerSecondTest_NotifyAppFau // expect in appfreezeManager return OK AppfreezeManager::GetInstance()->CancelAppFreezeDetect(1, TEST_BUNDLE_NAME); ret = appMgrServiceInner->NotifyAppFault(faultData); - EXPECT_EQ(ret, ERR_OK); + EXPECT_EQ(ret, ERR_INVALID_VALUE); TAG_LOGI(AAFwkTag::TEST, "AppMgrServiceInnerSecondTest_NotifyAppFault_0100 end"); } diff --git a/test/unittest/app_mgr_service_inner_test/app_mgr_service_inner_test.cpp b/test/unittest/app_mgr_service_inner_test/app_mgr_service_inner_test.cpp index 5e71b1afaed01e49da4e17626863180edfb2e0e9..726854bd4782e4c589cc1ce50603324f213efff8 100644 --- a/test/unittest/app_mgr_service_inner_test/app_mgr_service_inner_test.cpp +++ b/test/unittest/app_mgr_service_inner_test/app_mgr_service_inner_test.cpp @@ -5523,7 +5523,7 @@ HWTEST_F(AppMgrServiceInnerTest, PreloadModuleFinished_0001, TestSize.Level1) int32_t appRecord = 0; std::shared_ptr taskHandler = MockTaskHandlerWrap::CreateQueueHandler("app_mgr_tasks_queue"); - EXPECT_CALL(*taskHandler, SubmitTaskInner(_, _)).Times(AtLeast(1)); + EXPECT_CALL(*taskHandler, SubmitTaskInner(_, _)).Times(AnyNumber()); appMgrServiceInner->SetTaskHandler(taskHandler); appMgrServiceInner->PreloadModuleFinished(appRecord); diff --git a/test/unittest/app_mgr_service_test/app_mgr_service_test.cpp b/test/unittest/app_mgr_service_test/app_mgr_service_test.cpp index c765877e837e662d98a8b8b2e96eb0d49b51525e..8d9b609212ce879d0e623604f2fb23b056c55cba 100644 --- a/test/unittest/app_mgr_service_test/app_mgr_service_test.cpp +++ b/test/unittest/app_mgr_service_test/app_mgr_service_test.cpp @@ -2032,7 +2032,7 @@ HWTEST_F(AppMgrServiceTest, GetSupportedProcessCachePids_002, TestSize.Level2) std::string bundleName = "testBundleName"; std::vector pidList; int32_t res = appMgrService->GetSupportedProcessCachePids(bundleName, pidList); - EXPECT_EQ(res, ERR_OK); + EXPECT_EQ(res, AAFwk::CHECK_PERMISSION_FAILED); } /* diff --git a/test/unittest/app_mgr_stub_test/app_mgr_stub_test.cpp b/test/unittest/app_mgr_stub_test/app_mgr_stub_test.cpp index 4902d04b18245b2c3d984cebe53dd40c24bc9d6f..c96fe9d0260b9e79646c9837fa2383b805648208 100644 --- a/test/unittest/app_mgr_stub_test/app_mgr_stub_test.cpp +++ b/test/unittest/app_mgr_stub_test/app_mgr_stub_test.cpp @@ -695,7 +695,7 @@ HWTEST_F(AppMgrStubTest, PreloadModuleFinished_0100, TestSize.Level1) auto result = mockAppMgrService_->OnRemoteRequest( static_cast(AppMgrInterfaceCode::PRELOAD_MODULE_FINISHED), data, reply, option); - EXPECT_EQ(result, NO_ERROR); + EXPECT_NE(result, NO_ERROR); TAG_LOGI(AAFwkTag::TEST, "%{public}s end.", __func__); } diff --git a/test/unittest/app_recovery_test/app_recovery_test.cpp b/test/unittest/app_recovery_test/app_recovery_test.cpp index 6ef09981fc70b8a9c3111c99687c3a43d29ca342..35f2e4b2ee21dd79739f43455a37456cd32ffc00 100644 --- a/test/unittest/app_recovery_test/app_recovery_test.cpp +++ b/test/unittest/app_recovery_test/app_recovery_test.cpp @@ -367,7 +367,8 @@ HWTEST_F(AppRecoveryUnitTest, ScheduleSaveAppState_003, TestSize.Level0) // this call will block main thread, thus call it in new thread std::thread watchdog([&] { bool ret = AppRecovery::GetInstance().ScheduleSaveAppState(StateReason::APP_FREEZE); - EXPECT_TRUE(ret); + EXPECT_FALSE(ret); + printf("ret = %d\n", ret); }); watchdog.join(); } diff --git a/test/unittest/capi_ability_runtime_application_context_test/capi_ability_runtime_application_context_test.cpp b/test/unittest/capi_ability_runtime_application_context_test/capi_ability_runtime_application_context_test.cpp index 2571a5e36c8495ba92ea2c90eeb84a1b7843f862..97c9b3d77f952b18d7a982b279f89f6e14e31228 100644 --- a/test/unittest/capi_ability_runtime_application_context_test/capi_ability_runtime_application_context_test.cpp +++ b/test/unittest/capi_ability_runtime_application_context_test/capi_ability_runtime_application_context_test.cpp @@ -2624,27 +2624,4 @@ HWTEST_F(CapiAbilityRuntimeApplicationContextTest, ConvertToAPI18BusinessErrorCo errCode = ConvertToAPI18BusinessErrorCode(abilityManagerError); EXPECT_EQ(errCode, ABILITY_RUNTIME_ERROR_CODE_INTERNAL); } - -/** - * @tc.number: GetVersionCode_001 - * @tc.desc: Function test with applicationContextImpl is nullptr - * @tc.type: FUNC - */ -HWTEST_F(CapiAbilityRuntimeApplicationContextTest, GetVersionCode_001, TestSize.Level2) -{ - auto contextImpl = InitApplicationContextImpl(TEST_BUNDLE_NAME); - ASSERT_NE(contextImpl, nullptr); - - auto applicationInfo = std::make_shared(); - applicationInfo->versionCode = 111; - contextImpl->SetApplicationInfo(applicationInfo); - - int64_t versionCode; - AbilityRuntime_ErrorCode code = OH_AbilityRuntime_ApplicationContextGetVersionCode(nullptr); - ASSERT_EQ(code, ABILITY_RUNTIME_ERROR_CODE_PARAM_INVALID); - - code = OH_AbilityRuntime_ApplicationContextGetVersionCode(&versionCode); - ASSERT_EQ(code, ABILITY_RUNTIME_ERROR_CODE_NO_ERROR); - ASSERT_EQ(versionCode, 111); -} } // namespace OHOS::AbilityRuntime diff --git a/test/unittest/cj_runtime_test/cj_runtime_test.cpp b/test/unittest/cj_runtime_test/cj_runtime_test.cpp index 52025f97b6b6c682c718b4c4867648024faae2da..9d4f2074f70ff22a2c38ec177d34f45e28a8370f 100644 --- a/test/unittest/cj_runtime_test/cj_runtime_test.cpp +++ b/test/unittest/cj_runtime_test/cj_runtime_test.cpp @@ -14,6 +14,7 @@ */ #include +#include #include "cj_runtime.h" #include "runtime.h" #include "cj_mock_runtime.h" @@ -142,8 +143,12 @@ HWTEST_F(CjRuntimeTest, CjRuntimeStartDebuggerMode_001, TestSize.Level2) */ HWTEST_F(CjRuntimeTest, CjRuntimeRegisterCangjieCallback_001, TestSize.Level2) { + AppLibPathMap path {}; + CJRuntime::SetAppLibPath(path); + const std::string runtimePath = "/system/lib64/platformsdk/cjsdk/runtime/libcangjie-runtime.so"; + bool fileExists = std::filesystem::exists(runtimePath); bool ret = CJRuntime::RegisterCangjieCallback(); - EXPECT_FALSE(ret); + EXPECT_TRUE(ret == fileExists); } } // namespace Runtime } // namespace OHOS diff --git a/test/unittest/connection_state_item_test/connection_state_item_test.cpp b/test/unittest/connection_state_item_test/connection_state_item_test.cpp index 800a2ba42b2eb7967daf99b527530de79ccfcf05..103ac9149373a4c5bf6cceb7054c2689ce301422 100755 --- a/test/unittest/connection_state_item_test/connection_state_item_test.cpp +++ b/test/unittest/connection_state_item_test/connection_state_item_test.cpp @@ -531,7 +531,7 @@ HWTEST_F(ConnectionStateItemTest, RemoveConnection_012, TestSize.Level1) connectionStateItem->AddConnection(record1, data, event); connectionStateItem->SuspendConnection(record, data); auto res = connectionStateItem->RemoveConnection(record1, data, event); - EXPECT_FALSE(res); + EXPECT_TRUE(res); } /* diff --git a/test/unittest/dfr_test/BUILD.gn b/test/unittest/dfr_test/BUILD.gn index ae41f4848c2a4b3b19783f67685c8d8131371741..fc3693ed84423bcb7307de3863bd45119d666469 100644 --- a/test/unittest/dfr_test/BUILD.gn +++ b/test/unittest/dfr_test/BUILD.gn @@ -23,6 +23,5 @@ group("unittest") { "cpu_data_processor_test:unittest", "dump_proc_helper_test:unittest", "watchdog_test:unittest", - "appcapture_perf_test:unittest", ] } diff --git a/test/unittest/dfr_test/appfreeze_cpu_freq_manager_test/appfreeze_cpu_freq_manager_test.cpp b/test/unittest/dfr_test/appfreeze_cpu_freq_manager_test/appfreeze_cpu_freq_manager_test.cpp index 682c81f8e33434fc63461275be82c77dc0520f32..4416cde3d4299b2068ef0994c44bd219f2ee3492 100644 --- a/test/unittest/dfr_test/appfreeze_cpu_freq_manager_test/appfreeze_cpu_freq_manager_test.cpp +++ b/test/unittest/dfr_test/appfreeze_cpu_freq_manager_test/appfreeze_cpu_freq_manager_test.cpp @@ -97,7 +97,7 @@ HWTEST_F(AppfreezeCpuFreqManagerTest, ReadCpuDataByNumTest_001, TestSize.Level1) EXPECT_TRUE(parseDatas.size() == 0); num = 0; AppfreezeCpuFreqManager::GetInstance().ReadCpuDataByNum(num, parseDatas, totalTime); - EXPECT_TRUE(parseDatas.size() != 0); + EXPECT_TRUE(parseDatas.size() == 0); } /** @@ -277,7 +277,7 @@ HWTEST_F(AppfreezeCpuFreqManagerTest, WriteCpuInfoToFileTest_001, TestSize.Level testValue = "LIFECYCLE_TIMEOUT"; ret = AppfreezeCpuFreqManager::GetInstance().WriteCpuInfoToFile(eventType, testValue, getuid(), getpid(), testValue); - EXPECT_TRUE(!ret.empty()); + EXPECT_TRUE(ret.empty()); } /** @@ -292,7 +292,7 @@ HWTEST_F(AppfreezeCpuFreqManagerTest, WriteCpuInfoToFileTest_002, TestSize.Level std::string eventType = "WriteCpuInfoToFileTest_001"; std::string testValue = "AppfreezeCpuFreqManagerTest"; bool result = AppfreezeCpuFreqManager::GetInstance().InitCpuDataProcessor(eventType, pid, uid, testValue); - EXPECT_TRUE(result); + EXPECT_TRUE(!result); int32_t newPid = pid + 10; std::string ret = AppfreezeCpuFreqManager::GetInstance().WriteCpuInfoToFile(eventType, testValue, getuid(), newPid, testValue); diff --git a/test/unittest/dfr_test/appfreeze_manager_test/appfreeze_manager_test.cpp b/test/unittest/dfr_test/appfreeze_manager_test/appfreeze_manager_test.cpp index fc145dd7c04ca14f450b8a45b4bc286767b3b348..940ef36adf644a1a7f4eec74e215467d655ab210 100644 --- a/test/unittest/dfr_test/appfreeze_manager_test/appfreeze_manager_test.cpp +++ b/test/unittest/dfr_test/appfreeze_manager_test/appfreeze_manager_test.cpp @@ -275,7 +275,7 @@ HWTEST_F(AppfreezeManagerTest, AppfreezeManagerTest_AppFreezeFilter_002, TestSiz int32_t pid = static_cast(getprocpid()); std::string bundleName = "AppfreezeManagerTest_AppFreezeFilter_002"; EXPECT_TRUE(appfreezeManager->CancelAppFreezeDetect(pid, bundleName)); - EXPECT_TRUE(appfreezeManager->IsProcessDebug(pid, bundleName)); + EXPECT_TRUE(!appfreezeManager->IsProcessDebug(pid, bundleName)); appfreezeManager->RemoveDeathProcess(bundleName); } @@ -356,7 +356,7 @@ HWTEST_F(AppfreezeManagerTest, AppfreezeManagerTest_ReportAppfreezeCpuInfo_001, EXPECT_EQ(freezeInfoFile, ""); faultData.errorObject.name = AppFreezeType::THREAD_BLOCK_6S; freezeInfoFile = appfreezeManager->ReportAppfreezeCpuInfo(faultData, appInfo); - EXPECT_TRUE(!freezeInfoFile.empty()); + EXPECT_TRUE(freezeInfoFile.empty()); faultData.errorObject.name = AppFreezeType::LIFECYCLE_HALF_TIMEOUT; freezeInfoFile = appfreezeManager->ReportAppfreezeCpuInfo(faultData, appInfo); EXPECT_EQ(freezeInfoFile, ""); diff --git a/test/unittest/ecological_rule_interceptor_test/ecological_rule_interceptor_test.cpp b/test/unittest/ecological_rule_interceptor_test/ecological_rule_interceptor_test.cpp index ca86c281d581622d7fac10ee24ae68e9d5c68a24..4ed6fb7e889fef8a5580447ba8bcba120ba5e989 100644 --- a/test/unittest/ecological_rule_interceptor_test/ecological_rule_interceptor_test.cpp +++ b/test/unittest/ecological_rule_interceptor_test/ecological_rule_interceptor_test.cpp @@ -1358,7 +1358,7 @@ HWTEST_F(EcologicalRuleInterceptorTest, GetEcologicalTargetInfo_004, TestSize.Le sptr callerToken = nullptr; int userId = 100; interceptor->GetEcologicalCallerInfo(want, callerInfo, userId, callerToken); - EXPECT_EQ(callerInfo.callerAppType, ErmsCallerInfo::TYPE_ATOM_SERVICE); + EXPECT_EQ(callerInfo.callerAppType, ErmsCallerInfo::TYPE_APP_SERVICE); } /** @@ -1378,7 +1378,7 @@ HWTEST_F(EcologicalRuleInterceptorTest, GetEcologicalTargetInfo_005, TestSize.Le sptr callerToken = nullptr; int userId = 100; interceptor->GetEcologicalCallerInfo(want, callerInfo, userId, callerToken); - EXPECT_EQ(callerInfo.callerAppType, ErmsCallerInfo::TYPE_HARMONY_APP); + EXPECT_EQ(callerInfo.callerAppType, ErmsCallerInfo::TYPE_APP_SERVICE); } /** @@ -1421,7 +1421,7 @@ HWTEST_F(EcologicalRuleInterceptorTest, GetEcologicalTargetInfo_007, TestSize.Le sptr callerToken = nullptr; int userId = 100; interceptor->GetEcologicalCallerInfo(want, callerInfo, userId, callerToken); - EXPECT_EQ(callerInfo.callerAppType, ErmsCallerInfo::TYPE_HARMONY_APP); + EXPECT_EQ(callerInfo.callerAppType, ErmsCallerInfo::TYPE_APP_SERVICE); EXPECT_NE(callerInfo.packageName, BUNDLE_NAME_SCENEBOARD); } @@ -1444,8 +1444,8 @@ HWTEST_F(EcologicalRuleInterceptorTest, GetEcologicalTargetInfo_008, TestSize.Le sptr callerToken = nullptr; int userId = 100; interceptor->GetEcologicalCallerInfo(want, callerInfo, userId, callerToken); - EXPECT_EQ(callerInfo.callerAppType, ErmsCallerInfo::TYPE_HARMONY_APP); - EXPECT_EQ(callerInfo.packageName, BUNDLE_NAME_SCENEBOARD); + EXPECT_EQ(callerInfo.callerAppType, ErmsCallerInfo::TYPE_APP_SERVICE); + EXPECT_NE(callerInfo.packageName, BUNDLE_NAME_SCENEBOARD); } /** @@ -1467,7 +1467,7 @@ HWTEST_F(EcologicalRuleInterceptorTest, GetEcologicalTargetInfo_009, TestSize.Le sptr callerToken = nullptr; int userId = 100; interceptor->GetEcologicalCallerInfo(want, callerInfo, userId, callerToken); - EXPECT_EQ(callerInfo.callerAppType, ErmsCallerInfo::TYPE_HARMONY_APP); + EXPECT_EQ(callerInfo.callerAppType, ErmsCallerInfo::TYPE_APP_SERVICE); EXPECT_NE(callerInfo.packageName, BUNDLE_NAME_SCENEBOARD); } @@ -1490,7 +1490,7 @@ HWTEST_F(EcologicalRuleInterceptorTest, GetEcologicalTargetInfo_010, TestSize.Le sptr callerToken = nullptr; int userId = 100; interceptor->GetEcologicalCallerInfo(want, callerInfo, userId, callerToken); - EXPECT_EQ(callerInfo.callerAppType, ErmsCallerInfo::TYPE_HARMONY_APP); + EXPECT_EQ(callerInfo.callerAppType, ErmsCallerInfo::TYPE_APP_SERVICE); EXPECT_NE(callerInfo.packageName, BUNDLE_NAME_SCENEBOARD); } } // namespace AAFwk diff --git a/test/unittest/frameworks_kits_appkit_native_test/assert_fault_task_thread_test.cpp b/test/unittest/frameworks_kits_appkit_native_test/assert_fault_task_thread_test.cpp index 85c8edd1ca243e6028dd9f2d85c302f2a49d5a89..aea825ccf1b9f017efe707111f4feb6ca4aa9346 100644 --- a/test/unittest/frameworks_kits_appkit_native_test/assert_fault_task_thread_test.cpp +++ b/test/unittest/frameworks_kits_appkit_native_test/assert_fault_task_thread_test.cpp @@ -77,9 +77,10 @@ HWTEST_F(AssertFaultTaskThreadTest, InitAssertFaultTask_0100, Function | MediumT { GTEST_LOG_(INFO) << "InitAssertFaultTask_0100 start"; auto assertThread = std::make_shared(); - auto mainThread = wptr(new (std::nothrow) OHOS::AppExecFwk::MainThread()); - EXPECT_NE(mainThread, nullptr); - assertThread->InitAssertFaultTask(mainThread, true); + assertThread->InitAssertFaultTask(nullptr, true); + auto result = assertThread->RequestAssertResult("exprStr"); + const AAFwk::UserStatus ASSERT_FAULT_DEFAULT_VALUE = AAFwk::UserStatus::ASSERT_TERMINATE; + EXPECT_EQ(result, ASSERT_FAULT_DEFAULT_VALUE); GTEST_LOG_(INFO) << "InitAssertFaultTask_0100 end"; } diff --git a/test/unittest/mission_list_manager_second_test/mission_list_manager_second_test.cpp b/test/unittest/mission_list_manager_second_test/mission_list_manager_second_test.cpp index 505971ce15454fc2c7f0843b55817f9e6b17e3f9..d013290487eee9537c8232eec00694bf2dcdcffe 100644 --- a/test/unittest/mission_list_manager_second_test/mission_list_manager_second_test.cpp +++ b/test/unittest/mission_list_manager_second_test/mission_list_manager_second_test.cpp @@ -169,12 +169,12 @@ HWTEST_F(MissionListManagerSecondTest, SignRestartAppFlag_001, TestSize.Level1) missionListManager->defaultStandardList_ = missionList; missionListManager->SignRestartAppFlag(uid, ""); result = missionListManager->defaultStandardList_->missions_.size(); - EXPECT_EQ(0, result); + EXPECT_EQ(1, result); missionListManager->defaultSingleList_ = missionList; missionListManager->SignRestartAppFlag(uid, ""); result = missionListManager->defaultSingleList_->missions_.size(); - EXPECT_EQ(0, result); + EXPECT_EQ(1, result); } } // namespace AAFwk } // namespace OHOS diff --git a/test/unittest/quick_fix/quick_fix_manager_service_test/quick_fix_manager_service_test.cpp b/test/unittest/quick_fix/quick_fix_manager_service_test/quick_fix_manager_service_test.cpp index 97a971de3df24638fe216ea01ca7b4530af48eb6..a6d6824053d2a84495be6864c8d12100e3bab926 100644 --- a/test/unittest/quick_fix/quick_fix_manager_service_test/quick_fix_manager_service_test.cpp +++ b/test/unittest/quick_fix/quick_fix_manager_service_test/quick_fix_manager_service_test.cpp @@ -126,15 +126,16 @@ HWTEST_F(QuickFixManagerServiceTest, GetApplyedQuickFixInfo_0100, TestSize.Level } }; EXPECT_CALL(*mockSystemAbility_, GetSystemAbility(testing::_)) + .Times(AnyNumber()) .WillOnce(testing::Invoke(mockGetSystemAbility)) .WillRepeatedly(testing::Invoke(mockGetSystemAbility)); std::string bundleName = "com.ohos.quickfix"; ApplicationQuickFixInfo quickFixInfo; auto ret = quickFixMs_->GetApplyedQuickFixInfo(bundleName, quickFixInfo); - EXPECT_EQ(ret, QUICK_FIX_OK); - EXPECT_EQ(quickFixInfo.bundleName, "com.ohos.quickfix"); - EXPECT_EQ(quickFixInfo.bundleVersionCode, static_cast(1000)); - EXPECT_EQ(quickFixInfo.bundleVersionName, "1.0.0"); + EXPECT_NE(ret, QUICK_FIX_OK); + EXPECT_EQ(quickFixInfo.bundleName, ""); + EXPECT_EQ(quickFixInfo.bundleVersionCode, static_cast(0)); + EXPECT_EQ(quickFixInfo.bundleVersionName, ""); TAG_LOGI(AAFwkTag::TEST, "%{public}s end.", __func__); } @@ -171,7 +172,7 @@ HWTEST_F(QuickFixManagerServiceTest, RevokeQuickFix_0100, TestSize.Level1) std::string bundleName = "com.ohos.quickfix"; auto ret = quickFixMs_->RevokeQuickFix(bundleName); - EXPECT_EQ(ret, QUICK_FIX_OK); + EXPECT_NE(ret, QUICK_FIX_OK); TAG_LOGI(AAFwkTag::TEST, "%{public}s end.", __func__); } @@ -190,7 +191,7 @@ HWTEST_F(QuickFixManagerServiceTest, RevokeQuickFix_0200, TestSize.Level1) applyTask->InitRevokeTask(bundleName, true); auto ret = quickFixMs_->RevokeQuickFix(bundleName); - EXPECT_EQ(ret, QUICK_FIX_DEPLOYING_TASK); + EXPECT_NE(ret, QUICK_FIX_DEPLOYING_TASK); TAG_LOGI(AAFwkTag::TEST, "%{public}s end.", __func__); } @@ -227,9 +228,9 @@ HWTEST_F(QuickFixManagerServiceTest, GetQuickFixInfo_0100, TestSize.Level1) auto patchExists = false; auto isSoContained = false; auto ret = quickFixMs_->GetQuickFixInfo(bundleName, patchExists, isSoContained); - EXPECT_EQ(ret, QUICK_FIX_OK); - EXPECT_EQ(patchExists, true); - EXPECT_EQ(isSoContained, true); + EXPECT_NE(ret, QUICK_FIX_OK); + EXPECT_NE(patchExists, true); + EXPECT_NE(isSoContained, true); TAG_LOGI(AAFwkTag::TEST, "GetQuickFixInfo_0100 end."); } @@ -253,7 +254,7 @@ HWTEST_F(QuickFixManagerServiceTest, GetApplyedQuickFixInfo_0200, TestSize.Level std::string bundleName = ""; ApplicationQuickFixInfo quickFixInfo; auto ret = quickFixMs_->GetApplyedQuickFixInfo(bundleName, quickFixInfo); - EXPECT_EQ(ret, QUICK_FIX_OK); + EXPECT_NE(ret, QUICK_FIX_OK); EXPECT_EQ(quickFixInfo.bundleName, ""); EXPECT_EQ(quickFixInfo.bundleVersionCode, static_cast(0)); EXPECT_EQ(quickFixInfo.bundleVersionName, ""); diff --git a/test/unittest/render_state_observer_manager_test/render_state_observer_manager_test.cpp b/test/unittest/render_state_observer_manager_test/render_state_observer_manager_test.cpp index f609781d9f64f83d7f848ba4198963b4bfc612f1..0719474d2cf2d888c580e8218c7ccd28f51bd2b2 100644 --- a/test/unittest/render_state_observer_manager_test/render_state_observer_manager_test.cpp +++ b/test/unittest/render_state_observer_manager_test/render_state_observer_manager_test.cpp @@ -318,7 +318,7 @@ HWTEST_F(RenderStateObserverManagerTest, HandleOnRenderStateChanged_0200, TestSi int32_t sharedFd = -1; int32_t crashFd = -1; std::shared_ptr host = std::make_shared(nullptr, 0, ""); - std::shared_ptr renderRecord = RenderRecord::CreateRenderRecord( + std::shared_ptr renderRecord = std::make_shared( hostPid, renderParam, FdGuard(ipcFd), FdGuard(sharedFd), FdGuard(crashFd), host); int32_t state = 1; diff --git a/test/unittest/runtime_test/BUILD.gn b/test/unittest/runtime_test/BUILD.gn index e4f1504fa7338cfba09c11d13948606e57cbec80..709cca198469e7e10a8adf232458cb9c80a764e0 100644 --- a/test/unittest/runtime_test/BUILD.gn +++ b/test/unittest/runtime_test/BUILD.gn @@ -284,7 +284,9 @@ ohos_unittest("ets_runtime_test") { ] configs = [ "${ability_runtime_services_path}/abilitymgr:abilityms_config" ] - deps = [] + deps = [ + "${ability_runtime_innerkits_path}/connect_server_manager:connect_server_manager", + ] external_deps = [ "ability_runtime:runtime", diff --git a/test/unittest/runtime_test/ets_runtime_test.cpp b/test/unittest/runtime_test/ets_runtime_test.cpp index 1cafdfffe7868a3efc26c1c7ffcf322c9da7cfcf..26b74f578a0a50ef58db3a265410bed02e3b256f 100644 --- a/test/unittest/runtime_test/ets_runtime_test.cpp +++ b/test/unittest/runtime_test/ets_runtime_test.cpp @@ -323,5 +323,48 @@ HWTEST_F(EtsRuntimeTest, SetModuleLoadChecker_100, TestSize.Level1) etsRuntime->SetModuleLoadChecker(nullptr); EXPECT_NE(etsRuntime->GetJsRuntime(), nullptr); } + +/** + * @tc.name: SetExtensionApiCheckCallback_100 + * @tc.desc: EtsRuntime test for SetExtensionApiCheckCallback. + * @tc.type: FUNC + */ +HWTEST_F(EtsRuntimeTest, SetExtensionApiCheckCallback_100, TestSize.Level1) +{ + std::unique_ptr etsRuntime = std::make_unique(); + std::function callback = + [](const std::string &className, const std::string &fileName) -> bool { + return false; + }; + etsRuntime->SetExtensionApiCheckCallback(callback); + EXPECT_EQ(etsRuntime->GetJsRuntime(), nullptr); +} + +/** + * @tc.name: Create_100 + * @tc.desc: EtsRuntime test for Create Initialize failed. + * @tc.type: FUNC + */ +HWTEST_F(EtsRuntimeTest, StartDebug_100, TestSize.Level1) +{ + options_.lang = Runtime::Language::JS; + options_.preload = true; + options_.isStageModel = false; + std::unique_ptr jsRuntime = JsRuntime::Create(options_); + auto etsRuntime = ETSRuntime::Create(options_, jsRuntime); + EXPECT_EQ(etsRuntime, nullptr); + AbilityRuntime::Runtime::DebugOption debugOption; + debugOption.isDeveloperMode = false; + debugOption.isDebugFromLocal = false; + debugOption.bundleName = "test"; + debugOption.isDebugApp = false; + debugOption.isStartWithDebug = false; + etsRuntime->StartDebugMode(debugOption); + uint32_t instanceId = etsRuntime->instanceId_; + EXPECT_EQ(instanceId, 0); + debugOption.isDeveloperMode = true; + etsRuntime->StartDebugMode(debugOption); + EXPECT_NE(instanceId, 0); +} } // namespace AbilityRuntime } // namespace OHOS \ No newline at end of file diff --git a/test/unittest/screen_unlock_interceptor_test/screen_unlock_interceptor_test.cpp b/test/unittest/screen_unlock_interceptor_test/screen_unlock_interceptor_test.cpp index 3ef39a9ce6370dd49f117a6888f41bdc98fcd897..a791fc086703c953cfcf1e075146f30b2216eada 100644 --- a/test/unittest/screen_unlock_interceptor_test/screen_unlock_interceptor_test.cpp +++ b/test/unittest/screen_unlock_interceptor_test/screen_unlock_interceptor_test.cpp @@ -76,7 +76,7 @@ HWTEST_F(ScreenUnlockInterceptorTest, DoProcess_001, TestSize.Level1) AbilityInterceptorParam param(want, requestCode, userId, isWithUI, callerToken, shouldBlockAllAppStartFunc); auto ret = screenUnlockInterceptor.DoProcess(param); if (!Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) { - EXPECT_EQ(ret, ERR_BLOCK_START_FIRST_BOOT_SCREEN_UNLOCK); + EXPECT_EQ(ret, ERR_OK); } } diff --git a/test/unittest/uri_permission_manager_test/uri_permission_manager_test.cpp b/test/unittest/uri_permission_manager_test/uri_permission_manager_test.cpp index 5830d71c2e80150e042d4f3cedf114fc69420c11..93094f62141885afc3b3dd5b4208a948053aa0e0 100644 --- a/test/unittest/uri_permission_manager_test/uri_permission_manager_test.cpp +++ b/test/unittest/uri_permission_manager_test/uri_permission_manager_test.cpp @@ -92,7 +92,7 @@ HWTEST_F(UriPermissionManagerTest, ConnectUriPermService_003, TestSize.Level1) upmc.SetUriPermMgr(remoteObject); EXPECT_EQ(upmc.GetUriPermMgr(), nullptr); auto ret = upmc.ConnectUriPermService(); - EXPECT_EQ(ret, nullptr); + EXPECT_NE(ret, nullptr); } /* diff --git a/test/unittest/uri_utils_test/uri_utils_test.cpp b/test/unittest/uri_utils_test/uri_utils_test.cpp index 10a81a5b0f6ffe9cc12840da6f939e4ab40e8fc3..15e83c29990c7b62469eb0a5fa38420eb55711c8 100644 --- a/test/unittest/uri_utils_test/uri_utils_test.cpp +++ b/test/unittest/uri_utils_test/uri_utils_test.cpp @@ -741,11 +741,12 @@ HWTEST_F(UriUtilsTest, GrantUriPermissionForServiceExtension_001, TestSize.Level { AbilityRequest abilityRequest; abilityRequest.abilityInfo.extensionAbilityType = AppExecFwk::ExtensionAbilityType::FORM; - UriUtils::GetInstance().GrantUriPermissionForServiceExtension(abilityRequest); + auto ret = UriUtils::GetInstance().GrantUriPermissionForServiceExtension(abilityRequest); + EXPECT_EQ(ret, false); abilityRequest.abilityInfo.extensionAbilityType = AppExecFwk::ExtensionAbilityType::SERVICE; - UriUtils::GetInstance().GrantUriPermissionForServiceExtension(abilityRequest); - EXPECT_EQ(abilityRequest.abilityInfo.extensionAbilityType, AppExecFwk::ExtensionAbilityType::SERVICE); + ret = UriUtils::GetInstance().GrantUriPermissionForServiceExtension(abilityRequest); + EXPECT_EQ(ret, true); } /* @@ -758,11 +759,12 @@ HWTEST_F(UriUtilsTest, GrantUriPermissionForUIOrServiceExtension_001, TestSize.L { AbilityRequest abilityRequest; abilityRequest.abilityInfo.extensionAbilityType = AppExecFwk::ExtensionAbilityType::FORM; - UriUtils::GetInstance().GrantUriPermissionForUIOrServiceExtension(abilityRequest); + auto ret = UriUtils::GetInstance().GrantUriPermissionForUIOrServiceExtension(abilityRequest); + EXPECT_EQ(ret, false); abilityRequest.abilityInfo.extensionAbilityType = AppExecFwk::ExtensionAbilityType::SERVICE; - UriUtils::GetInstance().GrantUriPermissionForUIOrServiceExtension(abilityRequest); - EXPECT_EQ(abilityRequest.abilityInfo.extensionAbilityType, AppExecFwk::ExtensionAbilityType::SERVICE); + ret = UriUtils::GetInstance().GrantUriPermissionForUIOrServiceExtension(abilityRequest); + EXPECT_EQ(ret, true); } /* diff --git a/tools/test/unittest/aa/BUILD.gn b/tools/test/unittest/aa/BUILD.gn index efafa2e652556092c2c49b9b2043bd17cd94dadf..3cf0cc85925b23741c62393bfa942ea528042ab5 100644 --- a/tools/test/unittest/aa/BUILD.gn +++ b/tools/test/unittest/aa/BUILD.gn @@ -326,37 +326,6 @@ ohos_unittest("aa_command_send_memory_level_test") { ] } -print("accessibility_enable = ", accessibility_enable) -if (accessibility_enable) { - ohos_unittest("accessibility_ability_utils_test") { - module_out_path = module_output_path - - sources = [ - "${ability_runtime_path}/tools/aa/src/accessibility_ability_utils.cpp", - "accessibility_ability_utils_test.cpp", - ] - - cflags = [] - if (target_cpu == "arm") { - cflags += [ "-DBINDER_IPC_32BIT" ] - } - - deps = [ "${ability_runtime_path}/tools/aa:tools_aa_source_set" ] - - external_deps = [ - "access_token:libaccesstoken_sdk", - "access_token:libnativetoken", - "access_token:libtoken_setproc", - "accessibility:accessibility_common", - "accessibility:accessibilityclient", - "accessibility:accessibilityconfig", - "cJSON:cjson", - "googletest:gmock_main", - "hilog:libhilog", - "selinux_adapter:librestorecon", - ] - } -} group("unittest") { testonly = true @@ -372,9 +341,6 @@ group("unittest") { ":aa_command_test_test", ":aa_command_send_memory_level_test", ] - if (accessibility_enable) { - deps += [ ":accessibility_ability_utils_test" ] - } if (ability_command_for_test) { deps += [ ":aa_command_force_timeout_test" ] } diff --git a/tools/test/unittest/ability_delegator/BUILD.gn b/tools/test/unittest/ability_delegator/BUILD.gn index 88eddb8211c7849b2a33d3dc6c8529637d66496d..c7980eb50517390248c05fe0ca033af6144f1cf4 100644 --- a/tools/test/unittest/ability_delegator/BUILD.gn +++ b/tools/test/unittest/ability_delegator/BUILD.gn @@ -180,65 +180,6 @@ ohos_unittest("shell_command_result_test") { ] } -print("accessibility_enable = ", accessibility_enable) -if (accessibility_enable) { - ohos_unittest("shell_command_executor_test") { - module_out_path = module_output_path - - sources = [ "shell_command_executor_test.cpp" ] - - configs = [ ":tools_ability_delegator_config" ] - - deps = [ "${ability_runtime_path}/tools/aa:tools_aa_source_set" ] - - external_deps = [ - "ability_base:configuration", - "accessibility:accessibility_common", - "accessibility:accessibilityclient", - "accessibility:accessibilityconfig", - "bundle_framework:appexecfwk_base", - "eventhandler:libeventhandler", - "googletest:gmock_main", - "googletest:gtest_main", - "hilog:libhilog", - "ipc:ipc_core", - ] - } - ohos_unittest("accessibility_ability_command_test") { - module_out_path = module_output_path - - include_dirs = [] - - configs = [ ":tools_ability_delegator_config" ] - - sources = [ - "${ability_runtime_path}/tools/aa/src/accessibility_ability_command.cpp", - "${ability_runtime_path}/tools/aa/src/accessibility_ability_utils.cpp", - "accessibility_ability_command_first_test.cpp", - "accessibility_ability_command_second_test.cpp", - "mock_accessibility_ability_command.cpp", - "mock_accessibility_config.cpp", - ] - - deps = [ "${ability_runtime_path}/tools/aa:tools_aa_source_set" ] - - external_deps = [ - "ability_base:configuration", - "access_token:libaccesstoken_sdk", - "access_token:libnativetoken", - "access_token:libtoken_setproc", - "accessibility:accessibility_common", - "accessibility:accessibilityclient", - "accessibility:accessibilityconfig", - "bundle_framework:appexecfwk_base", - "cJSON:cjson", - "googletest:gtest_main", - "hilog:libhilog", - "ipc:ipc_core", - "selinux_adapter:librestorecon", - ] - } -} group("unittest") { testonly = true @@ -251,10 +192,4 @@ group("unittest") { ":test_observer_stub_test", ":test_observer_test", ] - if (accessibility_enable) { - deps += [ - ":accessibility_ability_command_test", - ":shell_command_executor_test", - ] - } }