diff --git a/bundle.json b/bundle.json index bd5e1268d1..1d891d66b1 100644 --- a/bundle.json +++ b/bundle.json @@ -102,6 +102,7 @@ "//foundation/ability/ability_runtime/interfaces/inner_api:innerkits_target", "//foundation/ability/ability_runtime/frameworks/native/ability/native:ability_thread", "//foundation/ability/ability_runtime/frameworks/native/ability/native:extension_module", + "//foundation/ability/ability_runtime/frameworks/native/insight_intent:insight_intent_innerkits", "//foundation/ability/ability_runtime/frameworks/js/napi:napi_packages", "//foundation/ability/ability_runtime/js_environment/frameworks/js_environment:js_environment", "//foundation/ability/ability_runtime/services/abilitymgr/etc:appfwk_etc", diff --git a/frameworks/js/napi/BUILD.gn b/frameworks/js/napi/BUILD.gn index 1a4456cb2b..1e76eaa2de 100644 --- a/frameworks/js/napi/BUILD.gn +++ b/frameworks/js/napi/BUILD.gn @@ -52,6 +52,7 @@ group("napi_packages") { "${ability_runtime_napi_path}/feature_ability:featureability_napi", "${ability_runtime_napi_path}/inner/napi_ability_common:napi_ability_common", "${ability_runtime_napi_path}/inner/napi_common:napi_common", + "${ability_runtime_napi_path}/insight_intent_context:insightintentcontext_napi", "${ability_runtime_napi_path}/js_child_process:childprocess_napi", "${ability_runtime_napi_path}/js_child_process_manager:childprocessmanager_napi", "${ability_runtime_napi_path}/js_dialog_request:dialogrequest_napi", diff --git a/frameworks/js/napi/insight_intent_context/BUILD.gn b/frameworks/js/napi/insight_intent_context/BUILD.gn new file mode 100644 index 0000000000..0387dfc327 --- /dev/null +++ b/frameworks/js/napi/insight_intent_context/BUILD.gn @@ -0,0 +1,50 @@ +# Copyright (c) 2023 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("insightintentcontext_napi") { + include_dirs = [ + "./", + "${ability_runtime_innerkits_path}/insight_intent/insight_intent_context", + "${ability_runtime_path}/interfaces/kits/native/ability/native/ability_business_error", + ] + + sources = [ + "insight_intent_context_module.cpp", + "js_insight_intent_context.cpp", + ] + + defines = [ "AMS_LOG_TAG = \"InsigtIntent\"" ] + defines += [ "AMS_LOG_DOMAIN = 0xD001308" ] + + deps = [ + "${ability_runtime_napi_path}/inner/napi_common:napi_common", + "${ability_runtime_native_path}/ability/native:ability_business_error", + "${ability_runtime_native_path}/insight_intent/insight_intent_context:insightintentcontext", + ] + + external_deps = [ + "ability_base:want", + "c_utils:utils", + "hilog:libhilog", + "hitrace:hitrace_meter", + "ipc:ipc_single", + "napi:ace_napi", + ] + + relative_install_dir = "module/app/ability" + subsystem_name = "ability" + part_name = "ability_runtime" +} diff --git a/frameworks/js/napi/insight_intent_context/insight_intent_context_module.cpp b/frameworks/js/napi/insight_intent_context/insight_intent_context_module.cpp new file mode 100644 index 0000000000..aa64e92b54 --- /dev/null +++ b/frameworks/js/napi/insight_intent_context/insight_intent_context_module.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2023 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 "napi/native_api.h" + +/* + * The insight intent context module definition. + */ +static napi_module _module = { + .nm_version = 0, + .nm_modname = "app.ability.InsightIntentContext", + .nm_filename = "app/ability/insightintentcontext_napi.so", +}; + +/* + * The insight intent context module registration. + */ +extern "C" __attribute__((constructor)) void NAPI_Insight_Intent_Context_AutoRegister(void) +{ + napi_module_register(&_module); +} diff --git a/frameworks/js/napi/insight_intent_context/js_insight_intent_context.cpp b/frameworks/js/napi/insight_intent_context/js_insight_intent_context.cpp new file mode 100644 index 0000000000..7a4261858f --- /dev/null +++ b/frameworks/js/napi/insight_intent_context/js_insight_intent_context.cpp @@ -0,0 +1,119 @@ +/* + * Copyright (c) 2023 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_insight_intent_context.h" + +#include "ability_window_configuration.h" +#include "hilog_wrapper.h" +#include "hitrace_meter.h" +#include "js_error_utils.h" +#include "napi_common_want.h" + +namespace OHOS { +namespace AbilityRuntime { +namespace { +constexpr static char CONTEXT_MODULE_NAME[] = "InsightIntentContext"; +} + +void JsInsightIntentContext::Finalizer(napi_env env, void* data, void* hint) +{ + HILOG_INFO("enter"); + std::unique_ptr(static_cast(data)); +} + +napi_value JsInsightIntentContext::StartAbiity(napi_env env, napi_callback_info info) +{ + HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); + GET_NAPI_INFO_AND_CALL(env, info, JsInsightIntentContext, OnStartAbility); +} + +napi_value JsInsightIntentContext::OnStartAbility(napi_env env, NapiCallbackInfo& info) +{ + HILOG_DEBUG("enter"); + HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); + if (info.argc == 0) { + HILOG_ERROR("not enough args"); + ThrowTooFewParametersError(env); + return CreateJsUndefined(env); + } + // unwrap want + AAFwk::Want want; + OHOS::AppExecFwk::UnwrapWant(env, info.argv[0], want); + + auto context = context_.lock(); + if (context == nullptr) { + HILOG_ERROR("invalid context"); + ThrowError(env, AbilityErrorCode::ERROR_CODE_INNER); + return CreateJsUndefined(env); + } + + // verify if bundleName is empty or invalid + auto bundleNameFromWant = want.GetElement().GetBundleName(); + if (bundleNameFromWant.empty() || bundleNameFromWant != context->GetBundleName()) { + HILOG_ERROR("bundleName is empty or invalid"); + ThrowError(env, AbilityErrorCode::ERROR_CODE_OPERATION_NOT_SUPPORTED); + return CreateJsUndefined(env); + } + // modify windowmode setting + auto windowMode = context->GetCurrentWindowMode(); + if (windowMode == AAFwk::AbilityWindowConfiguration::MULTI_WINDOW_DISPLAY_PRIMARY || + windowMode == AAFwk::AbilityWindowConfiguration::MULTI_WINDOW_DISPLAY_SECONDARY) { + want.SetParam(AAFwk::Want::PARAM_RESV_WINDOW_MODE, windowMode); + } + + auto innerErrCode = std::make_shared(ERR_OK); + // create execute task + NapiAsyncTask::ExecuteCallback execute = [weak = context_, want, innerErrCode]() { + auto context = weak.lock(); + if (!context) { + HILOG_ERROR("context is released"); + *innerErrCode = static_cast(AbilityErrorCode::ERROR_CODE_INVALID_CONTEXT); + return; + } + *innerErrCode = context->StartAbilityByInsightIntent(want); + }; + // create complete task + NapiAsyncTask::CompleteCallback complete = [innerErrCode](napi_env env, NapiAsyncTask& task, int32_t status) { + if (*innerErrCode == ERR_OK) { + HILOG_DEBUG("StartAbility success."); + task.Resolve(env, CreateJsUndefined(env)); + } else { + task.Reject(env, CreateJsErrorByNativeErr(env, *innerErrCode)); + } + }; + + napi_value lastParam = (info.argc > 1) ? info.argv[1] : nullptr; + napi_value result = nullptr; + NapiAsyncTask::ScheduleHighQos("JsInsightIntentContext::OnStartAbility", env, + CreateAsyncTaskWithLastParam(env, lastParam, std::move(execute), std::move(complete), &result)); + HILOG_DEBUG("end"); + return result; +} + +napi_value CreateJsInsightIntentContext(napi_env env, const std::shared_ptr& context) +{ + HILOG_DEBUG("enter"); + napi_value contextObj; + napi_create_object(env, &contextObj); + + std::unique_ptr jsInsightIntentContext = std::make_unique(context); + napi_wrap(env, contextObj, jsInsightIntentContext.release(), JsInsightIntentContext::Finalizer, nullptr, nullptr); + + BindNativeFunction(env, contextObj, "startAbility", CONTEXT_MODULE_NAME, JsInsightIntentContext::StartAbiity); + HILOG_DEBUG("end"); + return contextObj; +} +} // namespace AbilityRuntime +} // namespace OHOS diff --git a/frameworks/js/napi/insight_intent_context/js_insight_intent_context.h b/frameworks/js/napi/insight_intent_context/js_insight_intent_context.h new file mode 100644 index 0000000000..f3ee43064c --- /dev/null +++ b/frameworks/js/napi/insight_intent_context/js_insight_intent_context.h @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2023 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_INSIGHT_INTENT_CONTEXT_H +#define OHOS_ABILITY_RUNTIME_JS_INSIGHT_INTENT_CONTEXT_H + +#include "native_engine/native_engine.h" +#include "insight_intent_context.h" +#include "js_runtime_utils.h" + +namespace OHOS { +namespace AbilityRuntime { +/** + * @class JsInsightIntentContext + * JsInsightIntentContext provides a context for insightintent to execute certain tasks. + */ +class JsInsightIntentContext final { +public: + explicit JsInsightIntentContext(const std::shared_ptr& context) : context_(context) {} + ~JsInsightIntentContext() = default; + + static void Finalizer(napi_env env, void* data, void* hint); + + /** + * Starts a new ability. Only such ability in the same application with the caller + * can be started. + * + * @param env, the napi environment. + * @param info, the params passed from js caller. + * + * @return result of StartAbility. + */ + static napi_value StartAbiity(napi_env env, napi_callback_info info); + +private: + napi_value OnStartAbility(napi_env env, NapiCallbackInfo& info); + + std::weak_ptr context_; +}; + +/** + * Creates an js object for specific insight intent context. + * + * @param env, the napi environment. + * @param context, the specific insight intent context object. + * + * @return result of StartAbility. + */ +napi_value CreateJsInsightIntentContext(napi_env env, const std::shared_ptr& context); + +} // namespace AbilityRuntime +} // namespace OHOS +#endif // OHOS_ABILITY_RUNTIME_JS_INSIGHT_INTENT_CONTEXT_H diff --git a/frameworks/js/napi/js_child_process_manager/js_child_process_manager.cpp b/frameworks/js/napi/js_child_process_manager/js_child_process_manager.cpp index 04229953e9..31aa48f06a 100644 --- a/frameworks/js/napi/js_child_process_manager/js_child_process_manager.cpp +++ b/frameworks/js/napi/js_child_process_manager/js_child_process_manager.cpp @@ -18,6 +18,7 @@ #include #include "child_process_manager.h" +#include "child_process_manager_error_utils.h" #include "hilog_wrapper.h" #include "js_error_utils.h" #include "js_runtime_utils.h" @@ -55,9 +56,9 @@ private: napi_value OnStartChildProcess(napi_env env, size_t argc, napi_value* argv) { HILOG_INFO("%{public}s is called", __FUNCTION__); - AbilityErrorCode errCode = preCheck(); - if (errCode != AbilityErrorCode::ERROR_OK) { - ThrowError(env, errCode); + if (ChildProcessManager::GetInstance().IsChildProcess()) { + HILOG_ERROR("Already in child process"); + ThrowError(env, AbilityErrorCode::ERROR_CODE_OPERATION_NOT_SUPPORTED); return CreateJsUndefined(env); } if (argc < ARGC_TWO) { @@ -78,7 +79,11 @@ private: return CreateJsUndefined(env); } HILOG_DEBUG("StartMode: %{public}d", startMode); - + if (startMode != MODE_SELF_FORK) { + HILOG_ERROR("Not supported StartMode"); + ThrowError(env, AbilityErrorCode::ERROR_CODE_INVALID_PARAM); + return CreateJsUndefined(env); + } NapiAsyncTask::CompleteCallback complete = [srcEntry, startMode](napi_env env, NapiAsyncTask &task, int32_t status) { switch (startMode) { @@ -93,7 +98,6 @@ private: } } }; - napi_value lastParam = (argc <= ARGC_TWO) ? nullptr : argv[ARGC_TWO]; napi_value result = nullptr; NapiAsyncTask::Schedule("JsChildProcessManager::OnStartChildProcess", @@ -101,27 +105,15 @@ private: return result; } - AbilityErrorCode preCheck() - { - auto &mgr = ChildProcessManager::GetInstance(); - if (!mgr.MultiProcessModelEnabled()) { - HILOG_ERROR("Starting child process is not supported"); - return AbilityErrorCode::ERROR_CODE_OPERATION_NOT_SUPPORTED; - } - if (mgr.IsChildProcess()) { - HILOG_ERROR("Starting child process in child process is not supported"); - return AbilityErrorCode::ERROR_CODE_OPERATION_NOT_SUPPORTED; - } - return AbilityErrorCode::ERROR_OK; - } - static void SelfForkProcess(napi_env env, NapiAsyncTask &task, const std::string &srcEntry) { - pid_t pid = ChildProcessManager::GetInstance().StartChildProcessBySelfFork(srcEntry); - if (pid >= 0) { + pid_t pid; + ChildProcessManagerErrorCode errorCode = + ChildProcessManager::GetInstance().StartChildProcessBySelfFork(srcEntry, pid); + if (errorCode == ChildProcessManagerErrorCode::ERR_OK) { task.ResolveWithNoError(env, CreateJsValue(env, pid)); } else { - task.Reject(env, CreateJsError(env, AbilityErrorCode::ERROR_CODE_INNER)); + task.Reject(env, CreateJsError(env, ChildProcessManagerErrorUtil::GetAbilityErrorCode(errorCode))); } } }; 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 old mode 100755 new mode 100644 index 987807aa8b..3b9ca20c22 --- a/frameworks/native/ability/native/ability_business_error/ability_business_error.cpp +++ b/frameworks/native/ability/native/ability_business_error/ability_business_error.cpp @@ -140,7 +140,8 @@ static std::unordered_map INNER_TO_JS_ERROR_CODE_MAP {DMS_ACCOUNT_ACCESS_PERMISSION_DENIED, AbilityErrorCode::ERROR_CODE_PERMISSION_DENIED}, {START_ABILITY_WAITING, AbilityErrorCode::ERROR_START_ABILITY_WAITTING}, {ERR_APP_CONTROLLED, AbilityErrorCode::ERROR_CODE_CONTROLLED}, - {ERR_EDM_APP_CONTROLLED, AbilityErrorCode::ERROR_CODE_EDM_CONTROLLED} + {ERR_EDM_APP_CONTROLLED, AbilityErrorCode::ERROR_CODE_EDM_CONTROLLED}, + {ERR_INSIGHT_INTENT_START_INVALID_COMPONENT, AbilityErrorCode::ERROR_CODE_OPERATION_NOT_SUPPORTED}, }; } diff --git a/frameworks/native/ability/native/child_process_manager/child_process_manager.cpp b/frameworks/native/ability/native/child_process_manager/child_process_manager.cpp index 00179d1c8e..79711cf7c5 100644 --- a/frameworks/native/ability/native/child_process_manager/child_process_manager.cpp +++ b/frameworks/native/ability/native/child_process_manager/child_process_manager.cpp @@ -28,6 +28,7 @@ #include "bundle_info.h" #include "bundle_mgr_interface.h" #include "child_process.h" +#include "child_process_manager_error_utils.h" #include "child_process_start_info.h" #include "constants.h" #include "event_runner.h" @@ -42,7 +43,6 @@ namespace OHOS { namespace AbilityRuntime { namespace { -constexpr pid_t INVALID_PID = -1; const std::string SYS_PARAM_MULTI_PROCESS_MODEL = "persist.sys.multi_process_model"; } @@ -71,23 +71,26 @@ void ChildProcessManager::HandleSigChild(int32_t signo) } } -pid_t ChildProcessManager::StartChildProcessBySelfFork(const std::string &srcEntry) +ChildProcessManagerErrorCode ChildProcessManager::StartChildProcessBySelfFork(const std::string &srcEntry, pid_t &pid) { HILOG_DEBUG("StartChildProcessBySelfFork called"); + ChildProcessManagerErrorCode errorCode = PreCheck(); + if (errorCode != ChildProcessManagerErrorCode::ERR_OK) { + return errorCode; + } std::shared_ptr applicationContext = AbilityRuntime::ApplicationContext::GetInstance(); std::string bundleName = applicationContext->GetBundleName(); - std::string moduleName = GetModuleNameFromSrcEntry(srcEntry); AppExecFwk::HapModuleInfo hapModuleInfo; - if (!GetHapModuleInfo(bundleName, moduleName, hapModuleInfo)) { + if (!GetHapModuleInfo(bundleName, hapModuleInfo)) { HILOG_ERROR("GetHapModuleInfo failed"); - return INVALID_PID; + return ChildProcessManagerErrorCode::ERR_GET_HAP_INFO_FAILED; } - pid_t pid = fork(); + pid = fork(); if (pid < 0) { HILOG_ERROR("Fork process failed"); - return pid; + return ChildProcessManagerErrorCode::ERR_FORK_FAILED; } if (pid == 0) { HILOG_DEBUG("Child process start"); @@ -96,7 +99,20 @@ pid_t ChildProcessManager::StartChildProcessBySelfFork(const std::string &srcEnt HILOG_DEBUG("Child process end"); exit(0); } - return pid; + return ChildProcessManagerErrorCode::ERR_OK; +} + +ChildProcessManagerErrorCode ChildProcessManager::PreCheck() +{ + if (!MultiProcessModelEnabled()) { + HILOG_ERROR("Multi process model is not enabled"); + return ChildProcessManagerErrorCode::ERR_MULTI_PROCESS_MODEL_DISABLED; + } + if (IsChildProcess()) { + HILOG_ERROR("Already in child process"); + return ChildProcessManagerErrorCode::ERR_ALREADY_IN_CHILD_PROCESS; + } + return ChildProcessManagerErrorCode::ERR_OK; } bool ChildProcessManager::MultiProcessModelEnabled() @@ -133,21 +149,7 @@ void ChildProcessManager::HandleChildProcess(const std::string &srcEntry, AppExe process->OnStart(); } -std::string ChildProcessManager::GetModuleNameFromSrcEntry(const std::string &srcEntry) -{ - std::string::size_type iPos = srcEntry.find_first_of('/'); - if (iPos == std::string::npos) { - return ""; - } - std::string moduleName = srcEntry.substr(0, iPos); - if (moduleName == ".") { - return ""; - } - return moduleName; -} - -bool ChildProcessManager::GetHapModuleInfo(const std::string &bundleName, - const std::string &moduleName, AppExecFwk::HapModuleInfo &hapModuleInfo) +bool ChildProcessManager::GetHapModuleInfo(const std::string &bundleName, AppExecFwk::HapModuleInfo &hapModuleInfo) { auto bundleObj = DelayedSingleton::GetInstance()->GetSystemAbility(BUNDLE_MGR_SERVICE_SYS_ABILITY_ID); @@ -176,19 +178,13 @@ bool ChildProcessManager::GetHapModuleInfo(const std::string &bundleName, return false; } if (bundleInfo.hapModuleInfos.empty()) { + HILOG_ERROR("hapModuleInfos empty!"); return false; } HILOG_DEBUG("hapModueInfos size: %{public}zu", bundleInfo.hapModuleInfos.size()); bool result = false; - const bool moduleNameExist = moduleName.length() > 0; for (auto info : bundleInfo.hapModuleInfos) { - if (moduleNameExist) { - if (info.moduleName == moduleName) { - result = true; - hapModuleInfo = info; - break; - } - } else if (info.moduleType == AppExecFwk::ModuleType::ENTRY) { + if (info.moduleType == AppExecFwk::ModuleType::ENTRY) { result = true; hapModuleInfo = info; break; diff --git a/frameworks/native/ability/native/child_process_manager/child_process_manager_error_utils.cpp b/frameworks/native/ability/native/child_process_manager/child_process_manager_error_utils.cpp new file mode 100644 index 0000000000..2c6594274e --- /dev/null +++ b/frameworks/native/ability/native/child_process_manager/child_process_manager_error_utils.cpp @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2023 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 "child_process_manager_error_utils.h" + +#include + +namespace OHOS { +namespace AbilityRuntime { +AbilityErrorCode ChildProcessManagerErrorUtil::GetAbilityErrorCode(const ChildProcessManagerErrorCode &internalErrCode) +{ + auto it = INTERNAL_ERR_CODE_MAP.find(internalErrCode); + if (it != INTERNAL_ERR_CODE_MAP.end()) { + return it->second; + } + + return AbilityErrorCode::ERROR_CODE_INNER; +} +} // namespace AbilityRuntime +} // namespace OHOS \ No newline at end of file diff --git a/frameworks/native/ability/native/child_process_manager/js_child_process.cpp b/frameworks/native/ability/native/child_process_manager/js_child_process.cpp index 97366f7756..0e196b455d 100644 --- a/frameworks/native/ability/native/child_process_manager/js_child_process.cpp +++ b/frameworks/native/ability/native/child_process_manager/js_child_process.cpp @@ -42,11 +42,11 @@ void JsChildProcess::Init(const std::shared_ptr &info) return; } std::string srcPath; - if (info->srcEntry.rfind("./", 0) == 0) { - srcPath.append(info->moduleName).append("/"); - } + srcPath.append(info->moduleName).append("/"); srcPath.append(info->srcEntry); - srcPath.erase(srcPath.rfind(".")); + if (srcPath.rfind(".") != std::string::npos) { + srcPath.erase(srcPath.rfind(".")); + } srcPath.append(".abc"); std::string moduleName(info->moduleName); moduleName.append("::").append(info->name); diff --git a/frameworks/native/ability/native/continuation/distributed/continuation_handler_stage.cpp b/frameworks/native/ability/native/continuation/distributed/continuation_handler_stage.cpp new file mode 100644 index 0000000000..cf8c1262b6 --- /dev/null +++ b/frameworks/native/ability/native/continuation/distributed/continuation_handler_stage.cpp @@ -0,0 +1,388 @@ +/* + * Copyright (c) 2023 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 "continuation_handler_stage.h" + +#include "ability_manager_client.h" +#include "context/application_context.h" +#include "distributed_errors.h" +#include "element_name.h" +#include "hilog_wrapper.h" + +using OHOS::AAFwk::WantParams; +namespace OHOS { +namespace AppExecFwk { +namespace +{ +const std::string ORIGINAL_DEVICE_ID("deviceId"); +const std::string VERSION_CODE_KEY = "version"; +} + +ContinuationHandlerStage::ContinuationHandlerStage( + std::weak_ptr &continuationManager, + std::weak_ptr &uiAbility) + : ability_(uiAbility), continuationManager_(continuationManager) {} + +bool ContinuationHandlerStage::HandleStartContinuationWithStack( + const sptr &token, const std::string &deviceId, uint32_t versionCode) +{ + HILOG_DEBUG("Begin."); + if (token == nullptr) { + HILOG_ERROR("Token is null."); + return false; + } + if (abilityInfo_ == nullptr) { + HILOG_ERROR("AbilityInfo is null."); + return false; + } + + abilityInfo_->deviceId = deviceId; + + std::shared_ptr continuationManagerTmp = nullptr; + continuationManagerTmp = continuationManager_.lock(); + if (continuationManagerTmp == nullptr) { + HILOG_ERROR("ContinuationManagerTmp is nullptr."); + return false; + } + + // decided to start continuation. Callback to ability. + Want want; + want.SetParam(VERSION_CODE_KEY, static_cast(versionCode)); + want.SetParam("targetDevice", deviceId); + WantParams wantParams = want.GetParams(); + int32_t status = continuationManagerTmp->OnContinue(wantParams); + if (status != ERR_OK) { + HILOG_ERROR("OnContinue failed, BundleName = %{public}s, ClassName= %{public}s, status: %{public}d", + abilityInfo_->bundleName.c_str(), abilityInfo_->name.c_str(), status); + } + + want.SetParams(wantParams); + want.AddFlags(want.FLAG_ABILITY_CONTINUATION); + want.SetElementName(deviceId, abilityInfo_->bundleName, abilityInfo_->name, abilityInfo_->moduleName); + + int result = AAFwk::AbilityManagerClient::GetInstance()->StartContinuation(want, token, status); + if (result != ERR_OK) { + HILOG_ERROR("StartContinuation failed."); + return false; + } + HILOG_DEBUG("End."); + return true; +} + +bool ContinuationHandlerStage::HandleStartContinuation(const sptr &token, const std::string &deviceId) +{ + HILOG_DEBUG("Begin."); + if (token == nullptr) { + HILOG_ERROR("Token is null."); + return false; + } + if (abilityInfo_ == nullptr) { + HILOG_ERROR("AbilityInfo is null."); + return false; + } + + abilityInfo_->deviceId = deviceId; + + std::shared_ptr continuationManagerTmp = nullptr; + continuationManagerTmp = continuationManager_.lock(); + if (continuationManagerTmp == nullptr) { + HILOG_ERROR("continuationManagerTmp is nullptr"); + return false; + } + + // DMS decided to start continuation. Callback to ability. + if (!continuationManagerTmp->StartContinuation()) { + HILOG_ERROR("Ability rejected, BundleName = %{public}s, ClassName= %{public}s", + abilityInfo_->bundleName.c_str(), abilityInfo_->name.c_str()); + return false; + } + + WantParams wantParams; + if (!continuationManagerTmp->SaveData(wantParams)) { + HILOG_ERROR("ScheduleSaveData failed, BundleName = %{public}s, ClassName= %{public}s", + abilityInfo_->bundleName.c_str(), abilityInfo_->name.c_str()); + return false; + } + + Want want = SetWantParams(wantParams); + want.SetElementName(deviceId, abilityInfo_->bundleName, abilityInfo_->name, abilityInfo_->moduleName); + + int result = AAFwk::AbilityManagerClient::GetInstance()->StartContinuation(want, token, 0); + if (result != 0) { + HILOG_ERROR("distClient_.startContinuation failed"); + return false; + } + HILOG_DEBUG("End."); + return true; +} + +void ContinuationHandlerStage::HandleReceiveRemoteScheduler(const sptr &remoteReplica) +{ + HILOG_DEBUG("Begin."); + if (remoteReplica == nullptr) { + HILOG_ERROR("scheduler is nullptr"); + return; + } + + if (remoteReplicaProxy_ != nullptr && schedulerDeathRecipient_ != nullptr) { + auto schedulerObjectTmp = remoteReplicaProxy_->AsObject(); + if (schedulerObjectTmp != nullptr) { + schedulerObjectTmp->RemoveDeathRecipient(schedulerDeathRecipient_); + } + } + + if (schedulerDeathRecipient_ == nullptr) { + schedulerDeathRecipient_ = new (std::nothrow) ReverseContinuationSchedulerRecipient( + std::bind(&ContinuationHandlerStage::OnReplicaDied, this, std::placeholders::_1)); + } + + remoteReplicaProxy_ = iface_cast(remoteReplica); + auto schedulerObject = remoteReplicaProxy_->AsObject(); + if (schedulerObject == nullptr || !schedulerObject->AddDeathRecipient(schedulerDeathRecipient_)) { + HILOG_ERROR("AddDeathRcipient failed."); + } + + remoteReplicaProxy_->PassPrimary(remotePrimaryStub_); + HILOG_DEBUG("End."); +} + +void ContinuationHandlerStage::HandleCompleteContinuation(int result) +{ + HILOG_DEBUG("begin"); + std::shared_ptr continuationManagerTmp = nullptr; + continuationManagerTmp = continuationManager_.lock(); + if (continuationManagerTmp == nullptr) { + HILOG_ERROR("ContinuationManagerTmp is nullptr."); + return; + } + + continuationManagerTmp->CompleteContinuation(result); + HILOG_DEBUG("End."); +} + +void ContinuationHandlerStage::SetReversible(bool reversible) +{ + HILOG_DEBUG("Called."); + reversible_ = reversible; +} + +void ContinuationHandlerStage::SetAbilityInfo(std::shared_ptr &abilityInfo) +{ + HILOG_DEBUG("Begin."); + abilityInfo_ = std::make_shared(*(abilityInfo.get())); + ClearDeviceInfo(abilityInfo_); + HILOG_DEBUG("End."); +} + +void ContinuationHandlerStage::SetPrimaryStub(const sptr &Primary) +{ + HILOG_DEBUG("Called."); + remotePrimaryStub_ = Primary; +} + +void ContinuationHandlerStage::ClearDeviceInfo(std::shared_ptr &abilityInfo) +{ + HILOG_DEBUG("Called."); + abilityInfo->deviceId = ""; + abilityInfo->deviceTypes.clear(); +} + +void ContinuationHandlerStage::OnReplicaDied(const wptr &remote) +{ + HILOG_DEBUG("begin"); + if (remoteReplicaProxy_ == nullptr) { + HILOG_ERROR("RemoteReplicaProxy_ is nullptr."); + return; + } + + auto object = remote.promote(); + if (!object) { + HILOG_ERROR("Object is null."); + return; + } + + if (object != remoteReplicaProxy_->AsObject()) { + HILOG_ERROR("RemoteReplica is not matches with remote."); + return; + } + + if (remoteReplicaProxy_ != nullptr && schedulerDeathRecipient_ != nullptr) { + auto schedulerObject = remoteReplicaProxy_->AsObject(); + if (schedulerObject != nullptr) { + schedulerObject->RemoveDeathRecipient(schedulerDeathRecipient_); + } + } + remoteReplicaProxy_.clear(); + + NotifyReplicaTerminated(); + HILOG_DEBUG("End."); +} + +void ContinuationHandlerStage::NotifyReplicaTerminated() +{ + HILOG_DEBUG("Begin."); + + CleanUpAfterReverse(); + + std::shared_ptr continuationManagerTmp = nullptr; + continuationManagerTmp = continuationManager_.lock(); + if (continuationManagerTmp == nullptr) { + HILOG_ERROR("continuationManagerTmp is nullptr"); + return; + } + HILOG_DEBUG("End."); + continuationManagerTmp->NotifyRemoteTerminated(); +} + +Want ContinuationHandlerStage::SetWantParams(const WantParams &wantParams) +{ + HILOG_DEBUG("Begin."); + Want want; + want.SetParams(wantParams); + want.AddFlags(want.FLAG_ABILITY_CONTINUATION); + if (abilityInfo_->launchMode != LaunchMode::STANDARD) { + HILOG_DEBUG("Clear task."); + } + if (reversible_) { + HILOG_DEBUG("Reversible"); + want.AddFlags(Want::FLAG_ABILITY_CONTINUATION_REVERSIBLE); + } + ElementName element("", abilityInfo_->bundleName, abilityInfo_->name, abilityInfo_->moduleName); + want.SetElement(element); + HILOG_DEBUG("End."); + return want; +} + +void ContinuationHandlerStage::CleanUpAfterReverse() +{ + HILOG_DEBUG("Called."); + remoteReplicaProxy_ = nullptr; +} + +void ContinuationHandlerStage::PassPrimary(const sptr &Primary) +{ + HILOG_DEBUG("Called."); + remotePrimaryProxy_ = iface_cast(Primary); +} + +bool ContinuationHandlerStage::ReverseContinuation() +{ + HILOG_DEBUG("Begin."); + + if (remotePrimaryProxy_ == nullptr) { + HILOG_ERROR("RemotePrimaryProxy_ not nullptr."); + return false; + } + + if (abilityInfo_ == nullptr) { + HILOG_ERROR("AbilityInfo is null."); + return false; + } + + std::shared_ptr continuationManagerTmp = nullptr; + continuationManagerTmp = continuationManager_.lock(); + if (continuationManagerTmp == nullptr) { + HILOG_ERROR("ContinuationManagerTmp is nullptr."); + return false; + } + + if (!continuationManagerTmp->StartContinuation()) { + HILOG_ERROR("Ability rejected, BundleName = %{public}s, ClassName= %{public}s", + abilityInfo_->bundleName.c_str(), abilityInfo_->name.c_str()); + return false; + } + + WantParams wantParams; + if (!continuationManagerTmp->SaveData(wantParams)) { + HILOG_ERROR("SaveData failed, BundleName = %{public}s, ClassName= %{public}s", abilityInfo_->bundleName.c_str(), + abilityInfo_->name.c_str()); + return false; + } + + Want want; + want.SetParams(wantParams); + if (remotePrimaryProxy_->ContinuationBack(want)) { + HILOG_ERROR("ContinuationBack send failed."); + return false; + } + HILOG_DEBUG("End."); + return true; +} + +void ContinuationHandlerStage::NotifyReverseResult(int reverseResult) +{ + HILOG_DEBUG("Start. result = %{public}d", reverseResult); + if (reverseResult == 0) { + std::shared_ptr ability = nullptr; + ability = ability_.lock(); + if (ability == nullptr) { + HILOG_ERROR("Ability is nullptr."); + return; + } + ability->TerminateAbility(); + } + HILOG_DEBUG("End."); +} + +bool ContinuationHandlerStage::ContinuationBack(const Want &want) +{ + HILOG_DEBUG("Begin."); + std::shared_ptr continuationManagerTmp = nullptr; + continuationManagerTmp = continuationManager_.lock(); + if (continuationManagerTmp == nullptr) { + HILOG_ERROR("ContinuationManagerTmp is nullptr."); + return false; + } + + int result = 0; + if (!continuationManagerTmp->RestoreFromRemote(want.GetParams())) { + HILOG_ERROR("RestoreFromRemote failed."); + result = ABILITY_FAILED_RESTORE_DATA; + } + + remoteReplicaProxy_->NotifyReverseResult(result); + if (result == 0) { + CleanUpAfterReverse(); + } + HILOG_DEBUG("End."); + return true; +} + +void ContinuationHandlerStage::NotifyTerminationToPrimary() +{ + HILOG_DEBUG("begin"); + if (remotePrimaryProxy_ == nullptr) { + HILOG_ERROR("RemotePrimaryProxy is nullptr."); + return; + } + + remotePrimaryProxy_->NotifyReplicaTerminated(); + HILOG_DEBUG("End."); +} + +bool ContinuationHandlerStage::ReverseContinueAbility() +{ + HILOG_DEBUG("Begin"); + if (remoteReplicaProxy_ == nullptr) { + HILOG_ERROR("RemoteReplicaProxy is nullptr."); + return false; + } + + bool requestSendSuccess = remoteReplicaProxy_->ReverseContinuation(); + HILOG_DEBUG("End."); + return requestSendSuccess; +} +} // namespace AppExecFwk +} // namespace OHOS diff --git a/frameworks/native/ability/native/continuation/distributed/continuation_manager_stage.cpp b/frameworks/native/ability/native/continuation/distributed/continuation_manager_stage.cpp new file mode 100644 index 0000000000..e498306c6e --- /dev/null +++ b/frameworks/native/ability/native/continuation/distributed/continuation_manager_stage.cpp @@ -0,0 +1,620 @@ +/* + * Copyright (c) 2023 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 "continuation_manager_stage.h" + +#include "ability_continuation_interface.h" +#include "ability_manager_client.h" +#include "bool_wrapper.h" +#include "continuation_handler.h" +#include "distributed_client.h" +#include "hilog_wrapper.h" +#include "operation_builder.h" +#include "string_ex.h" +#include "string_wrapper.h" +#include "ui_ability.h" +#include "want.h" + +namespace OHOS { +namespace AppExecFwk { +namespace { +constexpr int TIMEOUT_MS_WAIT_DMS_NOTIFY_CONTINUATION_COMPLETE = 25000; +constexpr int TIMEOUT_MS_WAIT_REMOTE_NOTIFY_BACK = 6000; +const std::string PAGE_STACK_PROPERTY_NAME = "pageStack"; +const std::string SUPPORT_CONTINUE_PAGE_STACK_PROPERTY_NAME = "ohos.extra.param.key.supportContinuePageStack"; +const int32_t CONTINUE_ABILITY_REJECTED = 29360197; +const int32_t CONTINUE_SAVE_DATA_FAILED = 29360198; +const int32_t CONTINUE_ON_CONTINUE_FAILED = 29360199; +const int32_t CONTINUE_ON_CONTINUE_MISMATCH = 29360204; +#ifdef SUPPORT_GRAPHICS +const int32_t CONTINUE_GET_CONTENT_FAILED = 29360200; +#endif +} + +ContinuationManagerStage::ContinuationManagerStage() : progressState_(ProgressState::INITIAL) {} + +bool ContinuationManagerStage::Init(const std::shared_ptr &ability, + const sptr &continueToken, const std::shared_ptr &abilityInfo, + const std::shared_ptr &continuationHandler) +{ + HILOG_DEBUG("Begin."); + if (ability == nullptr) { + HILOG_ERROR("Ability is nullptr."); + return false; + } + ability_ = ability; + + std::shared_ptr abilityTmp = nullptr; + abilityTmp = ability_.lock(); + if (abilityTmp == nullptr) { + HILOG_ERROR("Ability is nullptr."); + return false; + } + + if (abilityTmp->GetAbilityInfo() == nullptr) { + HILOG_ERROR("AbilityInfo is nullptr."); + return false; + } + abilityInfo_ = abilityTmp->GetAbilityInfo(); + + if (continueToken == nullptr) { + HILOG_ERROR("ContinueToken is nullptr."); + return false; + } + continueToken_ = continueToken; + + continuationHandler_ = continuationHandler; + HILOG_DEBUG("End."); + return true; +} + +ContinuationState ContinuationManagerStage::GetContinuationState() +{ + return continuationState_; +} + +std::string ContinuationManagerStage::GetOriginalDeviceId() +{ + return originalDeviceId_; +} + +void ContinuationManagerStage::ContinueAbilityWithStack(const std::string &deviceId, uint32_t versionCode) +{ + HILOG_DEBUG("Begin."); + HandleContinueAbilityWithStack(deviceId, versionCode); + HILOG_DEBUG("End."); +} + +bool ContinuationManagerStage::HandleContinueAbilityWithStack(const std::string &deviceId, uint32_t versionCode) +{ + HILOG_DEBUG("Begin."); + if (!CheckAbilityToken()) { + HILOG_ERROR("CheckAbilityToken failed."); + return false; + } + + InitMainHandlerIfNeed(); + wptr continueTokenWeak(continueToken_); + auto task = [continuationHandlerWeak = continuationHandler_, continueTokenWeak, deviceId, versionCode]() { + auto continuationHandler = continuationHandlerWeak.lock(); + if (continuationHandler == nullptr) { + HILOG_ERROR("ContinuationHandler is nullptr."); + return; + } + + auto continueToken = continueTokenWeak.promote(); + if (continueToken == nullptr) { + HILOG_ERROR("continueToken is nullptr."); + return; + } + continuationHandler->HandleStartContinuationWithStack(continueToken, deviceId, versionCode); + }; + if (!mainHandler_->PostTask(task)) { + HILOG_ERROR("PostTask failed."); + return false; + } + HILOG_DEBUG("End."); + return true; +} + +int32_t ContinuationManagerStage::OnStartAndSaveData(WantParams &wantParams) +{ + HILOG_DEBUG("Begin."); + std::shared_ptr ability = ability_.lock(); + if (ability == nullptr) { + HILOG_ERROR("Ability is nullptr."); + return ERR_INVALID_VALUE; + } + + if (!ability->OnStartContinuation()) { + HILOG_ERROR("Ability rejected."); + return CONTINUE_ABILITY_REJECTED; + } + if (!ability->OnSaveData(wantParams)) { + HILOG_ERROR("SaveData failed."); + return CONTINUE_SAVE_DATA_FAILED; + } + HILOG_DEBUG("End."); + return ERR_OK; +} + +bool ContinuationManagerStage::IsContinuePageStack(const WantParams &wantParams) +{ + auto value = wantParams.GetParam(SUPPORT_CONTINUE_PAGE_STACK_PROPERTY_NAME); + IBoolean *ao = IBoolean::Query(value); + if (ao != nullptr) { + return AAFwk::Boolean::Unbox(ao); + } + return true; +} + +int32_t ContinuationManagerStage::OnContinueAndGetContent(WantParams &wantParams) +{ + HILOG_DEBUG("Begin."); + std::shared_ptr ability = ability_.lock(); + if (ability == nullptr) { + HILOG_ERROR("Ability is nullptr."); + return ERR_INVALID_VALUE; + } + + HILOG_DEBUG("OnContinue begin."); + int32_t status = ability->OnContinue(wantParams); + HILOG_DEBUG("OnContinue end, status: %{public}d.", status); + if (status != OnContinueResult::AGREE) { + if (status == OnContinueResult::MISMATCH) { + HILOG_ERROR("OnContinue version mismatch."); + return CONTINUE_ON_CONTINUE_MISMATCH; + } + HILOG_ERROR("OnContinue failed."); + return CONTINUE_ON_CONTINUE_FAILED; + } + +#ifdef SUPPORT_GRAPHICS + if (IsContinuePageStack(wantParams)) { + bool ret = GetContentInfo(wantParams); + if (!ret) { + HILOG_ERROR("GetContentInfo failed"); + return CONTINUE_GET_CONTENT_FAILED; + } + } +#endif + HILOG_DEBUG("End."); + return ERR_OK; +} + +int32_t ContinuationManagerStage::OnContinue(WantParams &wantParams) +{ + HILOG_DEBUG("Begin."); + auto ability = ability_.lock(); + auto abilityInfo = abilityInfo_.lock(); + if (ability == nullptr || abilityInfo == nullptr) { + HILOG_ERROR("Ability or abilityInfo is nullptr."); + return ERR_INVALID_VALUE; + } + + bool stageBased = abilityInfo->isStageBasedModel; + HILOG_DEBUG("Ability isStageBasedModel %{public}d.", stageBased); + if (!stageBased) { + return OnStartAndSaveData(wantParams); + } + return OnContinueAndGetContent(wantParams); +} + +#ifdef SUPPORT_GRAPHICS +bool ContinuationManagerStage::GetContentInfo(WantParams &wantParams) +{ + HILOG_DEBUG("Begin."); + std::shared_ptr ability = ability_.lock(); + if (ability == nullptr) { + HILOG_ERROR("Ability is nullptr."); + return false; + } + + std::string pageStack = ability->GetContentInfo(); + if (pageStack.empty()) { + HILOG_ERROR("GetContentInfo failed."); + return false; + } + HILOG_DEBUG("Ability pageStack: %{public}s.", pageStack.c_str()); + wantParams.SetParam(PAGE_STACK_PROPERTY_NAME, String::Box(pageStack)); + + HILOG_DEBUG("End."); + return true; +} +#endif + +void ContinuationManagerStage::ContinueAbility(bool reversible, const std::string &deviceId) +{ + HILOG_DEBUG("Begin."); + if (CheckContinuationIllegal()) { + HILOG_ERROR("Ability not available to continueAbility."); + return; + } + + if (progressState_ != ProgressState::INITIAL) { + HILOG_ERROR("Another request in progressState_: %{public}d.", progressState_); + return; + } + + if (continuationState_ != ContinuationState::LOCAL_RUNNING) { + HILOG_ERROR("Illegal continuation state %{public}d.", continuationState_); + return; + } + + if (HandleContinueAbility(reversible, deviceId)) { + reversible_ = reversible; + ChangeProcessState(ProgressState::WAITING_SCHEDULE); + } + HILOG_DEBUG("end"); +} + +bool ContinuationManagerStage::ReverseContinueAbility() +{ + HILOG_DEBUG("begin"); + if (progressState_ != ProgressState::INITIAL) { + HILOG_ERROR("Failed progressState_ is %{public}d", progressState_); + return false; + } + + if (continuationState_ != ContinuationState::REMOTE_RUNNING) { + HILOG_ERROR("Failed continuationState_ is %{public}d", continuationState_); + return false; + } + + std::shared_ptr continuationHandler = continuationHandler_.lock(); + if (continuationHandler == nullptr) { + HILOG_ERROR("continuationHandler_ is nullptr"); + return false; + } + + bool requestSuccess = continuationHandler->ReverseContinueAbility(); + if (requestSuccess) { + ChangeProcessState(ProgressState::WAITING_SCHEDULE); + RestoreStateWhenTimeout(TIMEOUT_MS_WAIT_REMOTE_NOTIFY_BACK, ProgressState::WAITING_SCHEDULE); + } + HILOG_DEBUG("end"); + return requestSuccess; +} + +bool ContinuationManagerStage::StartContinuation() +{ + HILOG_DEBUG("begin"); + ChangeProcessState(ProgressState::IN_PROGRESS); + bool result = DoScheduleStartContinuation(); + if (!result) { + ChangeProcessState(ProgressState::INITIAL); + } + HILOG_DEBUG("end"); + return result; +} + +bool ContinuationManagerStage::SaveData(WantParams &saveData) +{ + HILOG_DEBUG("begin"); + bool result = DoScheduleSaveData(saveData); + if (!result) { + ChangeProcessState(ProgressState::INITIAL); + } else { + RestoreStateWhenTimeout(TIMEOUT_MS_WAIT_DMS_NOTIFY_CONTINUATION_COMPLETE, ProgressState::IN_PROGRESS); + } + HILOG_DEBUG("end"); + return result; +} + +bool ContinuationManagerStage::RestoreData( + const WantParams &restoreData, bool reversible, const std::string &originalDeviceId) +{ + HILOG_DEBUG("Begin."); + ChangeProcessState(ProgressState::IN_PROGRESS); + bool result = DoScheduleRestoreData(restoreData); + if (reversible) { + continuationState_ = ContinuationState::REPLICA_RUNNING; + } + originalDeviceId_ = originalDeviceId; + ChangeProcessState(ProgressState::INITIAL); + HILOG_DEBUG("End."); + return result; +} + +void ContinuationManagerStage::NotifyCompleteContinuation( + const std::string &originDeviceId, int sessionId, bool success, const sptr &reverseScheduler) +{ + HILOG_DEBUG("Begin."); + AAFwk::AbilityManagerClient::GetInstance()->NotifyCompleteContinuation(originDeviceId, sessionId, success); + HILOG_DEBUG("End."); +} + +void ContinuationManagerStage::CompleteContinuation(int result) +{ + HILOG_DEBUG("Begin."); + if (CheckContinuationIllegal()) { + HILOG_ERROR("Ability not available to complete continuation."); + return; + } + + std::shared_ptr ability = ability_.lock(); + if (ability == nullptr) { + HILOG_ERROR("Ability is nullptr."); + return; + } + + if (result == 0 && reversible_) { + continuationState_ = ContinuationState::REMOTE_RUNNING; + } + ChangeProcessState(ProgressState::INITIAL); + + ability->OnCompleteContinuation(result); + + if (!reversible_) { + ability->TerminateAbility(); + } + HILOG_DEBUG("End."); +} + +bool ContinuationManagerStage::RestoreFromRemote(const WantParams &restoreData) +{ + HILOG_DEBUG("Begin."); + ChangeProcessState(ProgressState::IN_PROGRESS); + bool result = DoRestoreFromRemote(restoreData); + /* + * No matter what the result is, we should reset the status. Because even it fail, we can do + * nothing but let the user send another reverse continuation request again. + */ + ChangeProcessState(ProgressState::INITIAL); + if (result) { + continuationState_ = ContinuationState::LOCAL_RUNNING; + } + HILOG_DEBUG("End."); + return result; +} + +bool ContinuationManagerStage::NotifyRemoteTerminated() +{ + HILOG_DEBUG("Begin."); + continuationState_ = ContinuationState::LOCAL_RUNNING; + ChangeProcessState(ProgressState::INITIAL); + + std::shared_ptr ability = ability_.lock(); + if (ability == nullptr) { + HILOG_ERROR("Ability is nullptr."); + return false; + } + + ability->OnRemoteTerminated(); + HILOG_DEBUG("End."); + return true; +} + +bool ContinuationManagerStage::CheckContinuationIllegal() +{ + HILOG_DEBUG("Begin."); + std::shared_ptr ability = ability_.lock(); + if (ability == nullptr) { + HILOG_ERROR("Ability is nullptr."); + return false; + } + + if (ability->GetState() >= AbilityLifecycleExecutor::LifecycleState::UNINITIALIZED) { + HILOG_ERROR("Ability state is wrong: %{public}d.", ability->GetState()); + return true; + } + HILOG_DEBUG("End."); + return false; +} + +bool ContinuationManagerStage::HandleContinueAbility(bool reversible, const std::string &deviceId) +{ + HILOG_DEBUG("Begin."); + + if (!CheckAbilityToken()) { + HILOG_ERROR("CheckAbilityToken failed."); + return false; + } + + std::shared_ptr continuationHandler = continuationHandler_.lock(); + if (continuationHandler == nullptr) { + HILOG_ERROR("ContinuationHandler is nullptr."); + return false; + } + continuationHandler->SetReversible(reversible); + + InitMainHandlerIfNeed(); + wptr continueTokeWeak(continueToken_); + auto task = [continuationHandlerWeak = continuationHandler_, continueTokeWeak, deviceId]() { + auto continuationHandler = continuationHandlerWeak.lock(); + if (continuationHandler == nullptr) { + HILOG_ERROR("ContinuationHandler is nullptr."); + return; + } + + auto continueToken = continueTokeWeak.promote(); + if (continueToken == nullptr) { + HILOG_ERROR("continueToken is nullptr."); + return; + } + continuationHandler->HandleStartContinuation(continueToken, deviceId); + }; + if (!mainHandler_->PostTask(task)) { + HILOG_ERROR("PostTask failed."); + return false; + } + + HILOG_DEBUG("End."); + return true; +} + +ContinuationManagerStage::ProgressState ContinuationManagerStage::GetProcessState() +{ + return progressState_; +} + +void ContinuationManagerStage::ChangeProcessState(const ProgressState &newState) +{ + HILOG_DEBUG("Begin progressState_: %{public}d, newState: %{public}d.", progressState_, newState); + progressState_ = newState; +} + +void ContinuationManagerStage::ChangeProcessStateToInit() +{ + if (mainHandler_ != nullptr) { + mainHandler_->RemoveTask("Restore_State_When_Timeout"); + HILOG_DEBUG("Restore_State_When_Timeout task removed."); + } + ChangeProcessState(ProgressState::INITIAL); +} + +void ContinuationManagerStage::RestoreStateWhenTimeout(long timeoutInMs, const ProgressState &preState) +{ + HILOG_DEBUG("Begin."); + InitMainHandlerIfNeed(); + + auto timeoutTask = [continuationManager = shared_from_this(), preState]() { + HILOG_DEBUG( + "preState = %{public}d, currentState = %{public}d", preState, continuationManager->GetProcessState()); + if (preState == continuationManager->GetProcessState()) { + continuationManager->ChangeProcessState(ProgressState::INITIAL); + } + }; + mainHandler_->PostTask(timeoutTask, "Restore_State_When_Timeout", timeoutInMs); + HILOG_DEBUG("End."); +} + +void ContinuationManagerStage::InitMainHandlerIfNeed() +{ + HILOG_DEBUG("Begin."); + if (mainHandler_ == nullptr) { + HILOG_DEBUG("Try to init main handler."); + std::lock_guard lock_l(lock_); + if ((mainHandler_ == nullptr) && (EventRunner::GetMainEventRunner() != nullptr)) { + mainHandler_ = std::make_shared(EventRunner::GetMainEventRunner()); + } + } + HILOG_DEBUG("End."); +} + +bool ContinuationManagerStage::CheckAbilityToken() +{ + HILOG_DEBUG("Begin."); + if (continueToken_ == nullptr) { + HILOG_ERROR("ContinueToken is nullptr."); + return false; + } + HILOG_DEBUG("End."); + return true; +} + +void ContinuationManagerStage::CheckDmsInterfaceResult(int result, const std::string &interfaceName) +{ + HILOG_DEBUG("interfaceName: %{public}s, result: %{public}d", interfaceName.c_str(), result); +} + +bool ContinuationManagerStage::DoScheduleStartContinuation() +{ + HILOG_DEBUG("Begin."); + if (CheckContinuationIllegal()) { + HILOG_ERROR("Ability not available to startContinuation."); + return false; + } + + std::shared_ptr ability = ability_.lock(); + if (ability == nullptr) { + HILOG_ERROR("Ability is nullptr."); + return false; + } + if (!ability->OnStartContinuation()) { + HILOG_ERROR("Failed to StartContinuation."); + return false; + } + HILOG_DEBUG("End."); + return true; +} + +bool ContinuationManagerStage::DoScheduleSaveData(WantParams &saveData) +{ + HILOG_DEBUG("Begin."); + if (CheckContinuationIllegal()) { + HILOG_ERROR("Ability not available to save data."); + return false; + } + + std::shared_ptr ability = ability_.lock(); + if (ability == nullptr) { + HILOG_ERROR("Ability is nullptr."); + return false; + } + + WantParams abilitySaveData; + bool ret = ability->OnSaveData(abilitySaveData); + for (std::string key : abilitySaveData.KeySet()) { + saveData.SetParam(key, abilitySaveData.GetParam(key).GetRefPtr()); + } + + if (!ret) { + HILOG_ERROR("Ability save data failed."); + } + HILOG_DEBUG("End."); + return ret; +} + +bool ContinuationManagerStage::DoScheduleRestoreData(const WantParams &restoreData) +{ + HILOG_DEBUG("Begin."); + if (CheckContinuationIllegal()) { + HILOG_ERROR("Ability not available to restore data."); + return false; + } + + std::shared_ptr ability = ability_.lock(); + if (ability == nullptr) { + HILOG_ERROR("Ability is nullptr."); + return false; + } + + WantParams abilityRestoreData; + for (std::string key : restoreData.KeySet()) { + abilityRestoreData.SetParam(key, restoreData.GetParam(key).GetRefPtr()); + } + + bool ret = ability->OnRestoreData(abilityRestoreData); + if (!ret) { + HILOG_ERROR("Ability restore data failed."); + } + HILOG_DEBUG("End."); + return ret; +} + +bool ContinuationManagerStage::DoRestoreFromRemote(const WantParams &restoreData) +{ + HILOG_DEBUG("Begin."); + std::shared_ptr ability = ability_.lock(); + if (ability == nullptr) { + HILOG_ERROR("Ability is nullptr."); + return false; + } + + WantParams abilityRestoreData; + for (std::string key : restoreData.KeySet()) { + abilityRestoreData.SetParam(key, restoreData.GetParam(key).GetRefPtr()); + } + + bool ret = ability->OnRestoreData(abilityRestoreData); + if (!ret) { + HILOG_ERROR("Ability restore data failed."); + } + HILOG_DEBUG("End."); + return ret; +} +} // namespace AppExecFwk +} // namespace OHOS diff --git a/frameworks/native/ability/native/continuation/distributed/reverse_continuation_scheduler_primary_stage.cpp b/frameworks/native/ability/native/continuation/distributed/reverse_continuation_scheduler_primary_stage.cpp new file mode 100644 index 0000000000..1d5c8add82 --- /dev/null +++ b/frameworks/native/ability/native/continuation/distributed/reverse_continuation_scheduler_primary_stage.cpp @@ -0,0 +1,106 @@ +/* + * Copyright (c) 2023 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 "reverse_continuation_scheduler_primary_stage.h" + +#include "continuation_handler_stage.h" +#include "hilog_wrapper.h" + +namespace OHOS { +namespace AppExecFwk { +ReverseContinuationSchedulerPrimaryStage::ReverseContinuationSchedulerPrimaryStage( + const std::weak_ptr &continuationHandler, + const std::shared_ptr &mainHandler) + : continuationHandler_(continuationHandler), mainHandler_(mainHandler) +{} + +void ReverseContinuationSchedulerPrimaryStage::NotifyReplicaTerminated() +{ + HILOG_DEBUG("Begin."); + wptr weak = this; + auto task = [weak]() { + auto reverseContinuationSchedulerPrimary = weak.promote(); + if (reverseContinuationSchedulerPrimary == nullptr) { + HILOG_ERROR("reverseContinuationSchedulerPrimary is nullptr."); + return; + } + reverseContinuationSchedulerPrimary->HandlerNotifyReplicaTerminated(); + }; + + if (mainHandler_ == nullptr) { + HILOG_ERROR("mainHandler_ is nullptr."); + return; + } + + bool ret = mainHandler_->PostTask(task); + if (!ret) { + HILOG_ERROR("PostTask error."); + return; + } + HILOG_DEBUG("End."); +} + +bool ReverseContinuationSchedulerPrimaryStage::ContinuationBack(const AAFwk::Want &want) +{ + HILOG_DEBUG("Begin."); + wptr weak = this; + auto task = [weak, want]() { + auto reverseContinuationSchedulerPrimary = weak.promote(); + if (reverseContinuationSchedulerPrimary == nullptr) { + HILOG_ERROR("reverseContinuationSchedulerPrimary is nullptr."); + return; + } + reverseContinuationSchedulerPrimary->HandlerContinuationBack(want); + }; + + if (mainHandler_ == nullptr) { + HILOG_ERROR("mainHandler_ is nullptr."); + return false; + } + + bool ret = mainHandler_->PostTask(task); + if (!ret) { + HILOG_ERROR("PostTask error."); + return false; + } + HILOG_DEBUG("End."); + return true; +} + +void ReverseContinuationSchedulerPrimaryStage::HandlerNotifyReplicaTerminated() +{ + HILOG_DEBUG("Begin."); + std::shared_ptr continuationHandler = continuationHandler_.lock(); + if (continuationHandler == nullptr) { + HILOG_ERROR("ContinuationHandler is nullptr."); + return; + } + continuationHandler->NotifyReplicaTerminated(); + HILOG_DEBUG("End."); +} + +void ReverseContinuationSchedulerPrimaryStage::HandlerContinuationBack(const AAFwk::Want &want) +{ + HILOG_DEBUG("Begin."); + std::shared_ptr continuationHandler = continuationHandler_.lock(); + if (continuationHandler == nullptr) { + HILOG_ERROR("ContinuationHandler is nullptr."); + return; + } + continuationHandler->ContinuationBack(want); + HILOG_DEBUG("End."); +} +} // namespace AppExecFwk +} // namespace OHOS diff --git a/frameworks/native/insight_intent/BUILD.gn b/frameworks/native/insight_intent/BUILD.gn new file mode 100644 index 0000000000..3e54d801ae --- /dev/null +++ b/frameworks/native/insight_intent/BUILD.gn @@ -0,0 +1,17 @@ +# Copyright (c) 2023 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("//foundation/ability/ability_runtime/ability_runtime.gni") + +group("insight_intent_innerkits") { + deps = [ "insight_intent_context:insightintentcontext" ] +} diff --git a/frameworks/native/insight_intent/insight_intent_context/BUILD.gn b/frameworks/native/insight_intent/insight_intent_context/BUILD.gn new file mode 100644 index 0000000000..914cde4cf3 --- /dev/null +++ b/frameworks/native/insight_intent/insight_intent_context/BUILD.gn @@ -0,0 +1,39 @@ +# Copyright (c) 2023 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("insightintentcontext") { + include_dirs = [ + "${ability_runtime_innerkits_path}/insight_intent/insight_intent_context", + ] + + sources = [ "insight_intent_context.cpp" ] + + defines = [ "AMS_LOG_TAG = \"InsigtIntent\"" ] + defines += [ "AMS_LOG_DOMAIN = 0xD001308" ] + + deps = [ "${ability_runtime_innerkits_path}/ability_manager:ability_manager" ] + + external_deps = [ + "ability_base:want", + "c_utils:utils", + "hilog:libhilog", + "hitrace:hitrace_meter", + ] + + relative_install_dir = "insight_intent" + subsystem_name = "ability" + part_name = "ability_runtime" +} diff --git a/frameworks/native/insight_intent/insight_intent_context/insight_intent_context.cpp b/frameworks/native/insight_intent/insight_intent_context/insight_intent_context.cpp new file mode 100644 index 0000000000..b00f441c1a --- /dev/null +++ b/frameworks/native/insight_intent/insight_intent_context/insight_intent_context.cpp @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2023 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 "insight_intent_context.h" + +#include "ability_manager_client.h" +#include "hilog_wrapper.h" +#include "hitrace_meter.h" + +namespace OHOS { +namespace AbilityRuntime { +ErrCode InsightIntentContext::StartAbilityByInsightIntent(const AAFwk::Want &want) +{ + HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); + HILOG_DEBUG("enter"); + ErrCode err = AAFwk::AbilityManagerClient::GetInstance()->StartAbilityByInsightIntent(want, token_, intentId_); + if (err != ERR_OK) { + HILOG_ERROR("failed to startAbility. ret=%{public}d", err); + } + HILOG_DEBUG("end"); + return err; +} +} // namespace AbilityRuntime +} // namespace OHOS diff --git a/interfaces/inner_api/ability_manager/include/ability_manager_client.h b/interfaces/inner_api/ability_manager/include/ability_manager_client.h index 4da9ef0511..7a6400198f 100644 --- a/interfaces/inner_api/ability_manager/include/ability_manager_client.h +++ b/interfaces/inner_api/ability_manager/include/ability_manager_client.h @@ -134,6 +134,21 @@ public: int requestCode = DEFAULT_INVAL_VALUE, int32_t userId = DEFAULT_INVAL_VALUE); + /** + * StartAbility by insight intent, send want to ability manager service. + * + * @param want Ability want. + * @param callerToken caller ability token. + * @param intentId insight intent id. + * @param userId userId of target ability. + * @return Returns ERR_OK on success, others on failure. + */ + ErrCode StartAbilityByInsightIntent( + const Want &want, + const sptr &callerToken, + uint64_t intentId, + int32_t userId = DEFAULT_INVAL_VALUE); + /** * Starts a new ability with specific start settings. * 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 c661f36e7f..2b6f078e42 100644 --- a/interfaces/inner_api/ability_manager/include/ability_manager_errors.h +++ b/interfaces/inner_api/ability_manager/include/ability_manager_errors.h @@ -358,6 +358,10 @@ enum { * Result(2097219) for prouct application boot setting. */ ERR_NOT_SUPPORTED_PRODUCT_TYPE, + /** + * Result(2097220) for starting invalid component. + */ + ERR_INSIGHT_INTENT_START_INVALID_COMPONENT, }; enum { diff --git a/interfaces/inner_api/ability_manager/include/ability_manager_interface.h b/interfaces/inner_api/ability_manager/include/ability_manager_interface.h index 037361334e..f5e040cfe1 100644 --- a/interfaces/inner_api/ability_manager/include/ability_manager_interface.h +++ b/interfaces/inner_api/ability_manager/include/ability_manager_interface.h @@ -100,6 +100,21 @@ public: int32_t userId = DEFAULT_INVAL_VALUE, int requestCode = DEFAULT_INVAL_VALUE) = 0; + /** + * StartAbility by insight intent, send want to ability manager service. + * + * @param want Ability want. + * @param callerToken caller ability token. + * @param intentId insight intent id. + * @param userId userId of target ability. + * @return Returns ERR_OK on success, others on failure. + */ + virtual int32_t StartAbilityByInsightIntent( + const Want &want, + const sptr &callerToken, + uint64_t intentId, + int32_t userId = DEFAULT_INVAL_VALUE) = 0; + /** * Starts a new ability with specific start settings. * diff --git a/interfaces/inner_api/ability_manager/include/ability_manager_ipc_interface_code.h b/interfaces/inner_api/ability_manager/include/ability_manager_ipc_interface_code.h index 4c6605943c..5c5819812c 100644 --- a/interfaces/inner_api/ability_manager/include/ability_manager_ipc_interface_code.h +++ b/interfaces/inner_api/ability_manager/include/ability_manager_ipc_interface_code.h @@ -347,6 +347,9 @@ enum class AbilityManagerInterfaceCode { START_UI_SESSION_ABILITY_FOR_OPTIONS = 1052, + // start ability by insigt intent + START_ABILITY_BY_INSIGHT_INTENT = 1053, + // ipc id for continue ability(1101) START_CONTINUATION = 1101, diff --git a/interfaces/inner_api/child_process_manager/BUILD.gn b/interfaces/inner_api/child_process_manager/BUILD.gn index bd3c2ae949..7227126451 100644 --- a/interfaces/inner_api/child_process_manager/BUILD.gn +++ b/interfaces/inner_api/child_process_manager/BUILD.gn @@ -30,6 +30,7 @@ ohos_shared_library("child_process_manager") { sources = [ "${ability_runtime_native_path}/ability/native/child_process_manager/child_process.cpp", "${ability_runtime_native_path}/ability/native/child_process_manager/child_process_manager.cpp", + "${ability_runtime_native_path}/ability/native/child_process_manager/child_process_manager_error_utils.cpp", "${ability_runtime_native_path}/ability/native/child_process_manager/js_child_process.cpp", ] diff --git a/interfaces/inner_api/child_process_manager/include/child_process_manager.h b/interfaces/inner_api/child_process_manager/include/child_process_manager.h index 0b12139f52..3efc677589 100644 --- a/interfaces/inner_api/child_process_manager/include/child_process_manager.h +++ b/interfaces/inner_api/child_process_manager/include/child_process_manager.h @@ -19,6 +19,7 @@ #include #include +#include "child_process_manager_error_utils.h" #include "hap_module_info.h" #include "runtime.h" @@ -34,17 +35,16 @@ public: ~ChildProcessManager(); static void HandleSigChild(int32_t signo); - pid_t StartChildProcessBySelfFork(const std::string &srcEntry); - bool MultiProcessModelEnabled(); bool IsChildProcess(); + ChildProcessManagerErrorCode StartChildProcessBySelfFork(const std::string &srcEntry, pid_t &pid); private: ChildProcessManager(); + ChildProcessManagerErrorCode PreCheck(); + bool MultiProcessModelEnabled(); void HandleChildProcess(const std::string &srcEntry, AppExecFwk::HapModuleInfo &hapModuleInfo); - std::string GetModuleNameFromSrcEntry(const std::string &srcEntry); - bool GetHapModuleInfo(const std::string &bundleName, - const std::string &moduleName, AppExecFwk::HapModuleInfo &hapModuleInfo); + bool GetHapModuleInfo(const std::string &bundleName, AppExecFwk::HapModuleInfo &hapModuleInfo); std::unique_ptr CreateRuntime(AppExecFwk::HapModuleInfo &hapModuleInfo); static bool signalRegistered_; diff --git a/interfaces/inner_api/child_process_manager/include/child_process_manager_error_utils.h b/interfaces/inner_api/child_process_manager/include/child_process_manager_error_utils.h new file mode 100644 index 0000000000..83eb764eaa --- /dev/null +++ b/interfaces/inner_api/child_process_manager/include/child_process_manager_error_utils.h @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2023 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_CHILD_PROCESS_MANAGER_ERROR_UTILS_H +#define OHOS_ABILITY_RUNTIME_CHILD_PROCESS_MANAGER_ERROR_UTILS_H + +#include + +#include "ability_business_error.h" + +namespace OHOS { +namespace AbilityRuntime { +enum class ChildProcessManagerErrorCode { + ERR_OK = 0, + ERR_MULTI_PROCESS_MODEL_DISABLED = 1, + ERR_ALREADY_IN_CHILD_PROCESS = 2, + ERR_GET_HAP_INFO_FAILED = 3, + ERR_FORK_FAILED = 4, +}; + +const std::map INTERNAL_ERR_CODE_MAP = { + { ChildProcessManagerErrorCode::ERR_OK, AbilityErrorCode::ERROR_OK }, + { ChildProcessManagerErrorCode::ERR_MULTI_PROCESS_MODEL_DISABLED, + AbilityErrorCode::ERROR_CODE_OPERATION_NOT_SUPPORTED }, + { ChildProcessManagerErrorCode::ERR_ALREADY_IN_CHILD_PROCESS, + AbilityErrorCode::ERROR_CODE_OPERATION_NOT_SUPPORTED }, + { ChildProcessManagerErrorCode::ERR_GET_HAP_INFO_FAILED, AbilityErrorCode::ERROR_CODE_INNER }, + { ChildProcessManagerErrorCode::ERR_FORK_FAILED, AbilityErrorCode::ERROR_CODE_INNER }, +}; + +class ChildProcessManagerErrorUtil { +public: + static AbilityErrorCode GetAbilityErrorCode(const ChildProcessManagerErrorCode &internalErrCode); +}; +} // namespace AbilityRuntime +} // namespace OHOS +#endif // OHOS_ABILITY_RUNTIME_CHILD_PROCESS_MANAGER_ERROR_UTILS_H \ No newline at end of file diff --git a/interfaces/inner_api/insight_intent/insight_intent_context/insight_intent_context.h b/interfaces/inner_api/insight_intent/insight_intent_context/insight_intent_context.h new file mode 100644 index 0000000000..f5c0c00538 --- /dev/null +++ b/interfaces/inner_api/insight_intent/insight_intent_context/insight_intent_context.h @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2023 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_INSIGHT_INTENT_CONTEXT_H +#define OHOS_ABILITY_RUNTIME_INSIGHT_INTENT_CONTEXT_H + +#include "iremote_object.h" +#include "want.h" + +namespace OHOS { +namespace AbilityRuntime { +/** + * @class InsightIntentContext + * InsightIntentContext provides a context for insightintent to execute certain tasks. + */ +class InsightIntentContext final { +public: + InsightIntentContext(const sptr& token, const std::string& bundleName, int32_t winMode, + uint64_t intentId) : token_(token), bundleName_(bundleName), winMode_(winMode), intentId_(intentId) {} + ~InsightIntentContext() = default; + + /** + * Starts a new ability. Only such ability in the same application with the caller + * can be started. + * + * @param want Indicates the Want containing information about the target ability to start. + * @return result of StartAbility. + */ + ErrCode StartAbilityByInsightIntent(const AAFwk::Want &want); + + std::string GetBundleName() const + { + return bundleName_; + } + + int32_t GetCurrentWindowMode() const + { + return winMode_; + } + +private: + sptr token_ = nullptr; + std::string bundleName_ = ""; + int32_t winMode_ = 0; + uint64_t intentId_ = 0; +}; +} // namespace AbilityRuntime +} // namespace OHOS +#endif // OHOS_ABILITY_RUNTIME_JS_INSIGHT_INTENT_CONTEXT_H 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 old mode 100755 new mode 100644 diff --git a/interfaces/kits/native/ability/native/continuation/distributed/continuation_handler_stage.h b/interfaces/kits/native/ability/native/continuation/distributed/continuation_handler_stage.h new file mode 100644 index 0000000000..82ae74ceaa --- /dev/null +++ b/interfaces/kits/native/ability/native/continuation/distributed/continuation_handler_stage.h @@ -0,0 +1,160 @@ +/* + * Copyright (c) 2023 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_CONTINUATION_HANDLER_STAGE_H +#define OHOS_ABILITY_RUNTIME_CONTINUATION_HANDLER_STAGE_H + +#include + +#include "continuation_manager_stage.h" +#include "distribute_schedule_handler_interface.h" +#include "iremote_broker.h" +#include "reverse_continuation_scheduler_primary_handler_interface.h" +#include "reverse_continuation_scheduler_primary_interface.h" +#include "reverse_continuation_scheduler_primary_proxy.h" +#include "reverse_continuation_scheduler_primary_stub.h" +#include "reverse_continuation_scheduler_recipient.h" +#include "reverse_continuation_scheduler_replica_handler_interface.h" +#include "reverse_continuation_scheduler_replica_interface.h" +#include "reverse_continuation_scheduler_replica_proxy.h" +#include "ui_ability.h" +#include "want.h" +#include "want_params.h" + +using Want = OHOS::AAFwk::Want; +namespace OHOS { +namespace AppExecFwk { +class ContinuationHandlerStage : public IDistributeScheduleHandler, + public IReverseContinuationSchedulerPrimaryHandler, + public IReverseContinuationSchedulerReplicaHandler { +public: + /** + * @brief constructed function + */ + ContinuationHandlerStage(std::weak_ptr &continuationManager, + std::weak_ptr &uiAbility); + virtual ~ContinuationHandlerStage() = default; + + /** + * @brief Handle continuation from DMS. + * @param token The token + * @param deviceId The device identifier. This value doesn't matter. + * @return zero if success. + */ + bool HandleStartContinuation(const sptr &token, const std::string &deviceId) override; + + /** + * @brief Receive a scheduler which could handle reverse continuation. + * Remote side will pass an scheduler before continuation completed if this continuation is + * reversible. This method will not be called if this continuation is not reversible. + * @param remoteReplica A scheduler to handle reverse continuation request. + */ + void HandleReceiveRemoteScheduler(const sptr &remoteReplica) override; + + /** + * @brief Called by DMS when the migrate device finished. + * @param result Zero indicate the continuation is success, otherwise integer less than zero. + */ + void HandleCompleteContinuation(int result) override; + + /** + * @brief Pass the primary reverse continuation scheduler object + * @param Primary The remote object repersenting the reverse continuation sch + */ + void PassPrimary(const sptr &Primary) override; + + /** + * @brief Indicate a reverse continuation + * @return true if the reverse continuation was successful initiated,otherwise false + */ + bool ReverseContinuation() override; + + /** + * @brief Notify the result of a reverse continuation + * @param reverseResult The result of the reverse continuation + */ + void NotifyReverseResult(int reverseResult) override; + + /** + * @brief Handle the continuation back request from the primary + * @param want The want object representing the continuation back request + * @return true indicating successful handling of the continuation back request + */ + bool ContinuationBack(const Want &want) override; + + /** + * @brief Notify Replica Terminated + */ + void NotifyReplicaTerminated() override; + + /** + * @brief Notify the primary that the replica has terminated + */ + void NotifyTerminationToPrimary(); + + /** + * @brief Set Reversible + * @param reversible Indicates the boolen + */ + void SetReversible(bool reversible); + + /** + * @brief Set Ability Inforamtion + * @param abilityInfo Indicates the ability Inforamtion + */ + void SetAbilityInfo(std::shared_ptr &abilityInfo); + + /** + * @brief Set the Primary Stub + * @param Primary Indicates the Primary to be set up + */ + void SetPrimaryStub(const sptr &Primary); + + /** + * @brief Reverse Continue Ability + * @return If the success returns true, the failure returns false. + */ + bool ReverseContinueAbility(); + + /** + * @brief Migrates this ability to the given device on the same distributed network. The ability to migrate and its + * ability slices must implement the IAbilityContinuation interface. + * @param token Indicates the token + * @param deviceId Indicates the ID of the target device where this ability will be migrated to. + * @param versionCode Target bundle version. + */ + bool HandleStartContinuationWithStack( + const sptr &token, const std::string &deviceId, uint32_t versionCode); + + static const std::string ORIGINAL_DEVICE_ID; + +private: + void OnReplicaDied(const wptr &remote); + void ClearDeviceInfo(std::shared_ptr &abilityInfo); + void CleanUpAfterReverse(); + Want SetWantParams(const WantParams &wantParams); + + std::shared_ptr abilityInfo_ = nullptr; + std::weak_ptr ability_; + std::weak_ptr continuationManager_; + bool reversible_ = false; + sptr remoteReplicaProxy_ = nullptr; + sptr remotePrimaryProxy_ = nullptr; + sptr remotePrimaryStub_ = nullptr; + sptr schedulerDeathRecipient_ = nullptr; +}; +} // namespace AppExecFwk +} // namespace OHOS +#endif // OHOS_ABILITY_RUNTIME_CONTINUATION_HANDLER_STAGE_H diff --git a/interfaces/kits/native/ability/native/continuation/distributed/continuation_manager_stage.h b/interfaces/kits/native/ability/native/continuation/distributed/continuation_manager_stage.h new file mode 100644 index 0000000000..e370844a5e --- /dev/null +++ b/interfaces/kits/native/ability/native/continuation/distributed/continuation_manager_stage.h @@ -0,0 +1,213 @@ +/* + * Copyright (c) 2023 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_CONTINUATION_MANAGER_STAGE_H +#define OHOS_ABILITY_RUNTIME_CONTINUATION_MANAGER_STAGE_H + +#include +#include + +#include "ability_info.h" +#include "continuation_state.h" +#include "event_handler.h" +#include "iremote_object.h" +#include "want.h" + +using OHOS::AAFwk::WantParams; +namespace OHOS { +namespace AbilityRuntime { +class UIAbility; +} +namespace AppExecFwk { +class ContinuationHandlerStage; +class IAbilityContinuation; +class ContinuationManagerStage : public std::enable_shared_from_this { +public: + /** + * @brief constructed function + */ + ContinuationManagerStage(); + virtual ~ContinuationManagerStage() = default; + + /** + * @brief Init the ContinuationManagerStage + * @param ability Indicates the ability to Init + * @param continueToken Indicates the continueToken to Init + * @param abilityInfo Indicate the Ability information + * @param continuationHandler Indicate the continuation Handler instance + */ + bool Init(const std::shared_ptr &ability, const sptr &continueToken, + const std::shared_ptr &abilityInfo, + const std::shared_ptr &continuationHandler); + + /** + * @brief Obtains the migration state of this ability. + * @return Returns the migration state. + */ + ContinuationState GetContinuationState(); + + /** + * @brief Obtains the ID of the source device from which this ability is migrated. + * @return Returns the source device ID. + */ + std::string GetOriginalDeviceId(); + + /** + * @brief Migrates this ability to the given device on the same distributed network. The ability to migrate and its + * ability slices must implement the IAbilityContinuation interface. + * @param deviceId Indicates the ID of the target device where this ability will be migrated to. + * @param versionCode Target bundle version. + */ + void ContinueAbilityWithStack(const std::string &deviceId, uint32_t versionCode); + + /** + * @brief Migrates this ability to the given device on the same distributed network. The ability to migrate and its + * ability slices must implement the IAbilityContinuation interface. + * @param reversible Parameter of Boolean type, passed in true or false + * @param deviceId Indicates the ID of the target device where this ability will be migrated to. If this parameter + * is null, this method has the same effect as continueAbility(). + */ + void ContinueAbility(bool reversible, const std::string &deviceId); + + /** + * @brief Reverse Continue Ability + * @return If the success returns true, the failure returns false. + */ + bool ReverseContinueAbility(); + + /** + * @brief Start Continuation Ability + * @return If the success returns true, the failure returns false. + */ + bool StartContinuation(); + + /** + * @brief Prepare user data of local Ability. + * @param wantParams Indicates the user data to be saved. + * @return If the ability is willing to continue and data saved successfully, it returns 0; + * otherwise, it returns errcode. + */ + int32_t OnContinue(WantParams &wantParams); + + /** + * @brief OnStart And Save Data + * @param wantParams Indicates the user data. + * @return If the success code is returned successfully, otherwise the failure code is returned. + */ + int32_t OnStartAndSaveData(WantParams &wantParams); + + /** + * @brief Determine whether to continue the continuous management phase of the page stack + * @param wantParams Indicates the user data. + * @return If you want to continue the continuous management phase of the + * page stack, return true, otherwise return false + */ + bool IsContinuePageStack(const WantParams &wantParams); + + /** + * @brief Handle the continuation request and retrieve content information if needed + * @param wantParams Indicates the user data. + * @return An error code indicating the success or failure of the operation + */ + int32_t OnContinueAndGetContent(WantParams &wantParams); + + /** + * @brief Save Data for continuation + * @param saveData Indicates WantParams data to be saved + * @return If the success returns true, the failure returns false. + */ + bool SaveData(WantParams &saveData); + + /** + * @brief Restore data for continuation + * @param restoreData The WantParams containing the data + * @param reversible reversible A flag indicating whether the continuation is reversible + * @param originalDeviceId the original device ID + * @return If the success returns true, othrewise returns false. + */ + bool RestoreData(const WantParams &restoreData, bool reversible, const std::string &originalDeviceId); + + /** + * @brief Notifies the completion of continuation + * @param originDeviceId The ID of the originating device + * @param sessionId The session ID associated with the continuation + * @param success A flag indicating the success of the continuation + * @param reverseScheduler A remote object for reverse scheduling + */ + void NotifyCompleteContinuation( + const std::string &originDeviceId, int sessionId, bool success, + [[maybe_unused]] const sptr &reverseScheduler); + + /** + * @brief complete the continuation process + * @param result The result of the continuation process + */ + void CompleteContinuation(int result); + + /** + * @brief Restore from a remote continuation + * @param The WantParams containing the data for restoration + * @return true if restoration from was successful,otherwise false + */ + bool RestoreFromRemote(const WantParams &restoreData); + + /** + * @brief Notify that remote continuation has terminated + * @return true indicating successful notification of remote termination,otherwise false + */ + bool NotifyRemoteTerminated(); + + /** + * @brief Change the process state to Initial state and remove timeout task + */ + void ChangeProcessStateToInit(); + + enum OnContinueResult { + AGREE = 0, + REJECT = 1, + MISMATCH = 2 + }; +private: + enum ProgressState { INITIAL, WAITING_SCHEDULE, IN_PROGRESS }; + bool CheckContinuationIllegal(); + bool HandleContinueAbilityWithStack(const std::string &deviceId, uint32_t versionCode); + bool HandleContinueAbility(bool reversible, const std::string &deviceId); + ProgressState GetProcessState(); + void ChangeProcessState(const ProgressState &newState); + void RestoreStateWhenTimeout(long timeoutInMs, const ProgressState &preState); + void InitMainHandlerIfNeed(); + bool CheckAbilityToken(); + void CheckDmsInterfaceResult(int result, const std::string &interfaceName); + bool DoScheduleStartContinuation(); + bool DoScheduleSaveData(WantParams &saveData); + bool DoScheduleRestoreData(const WantParams &restoreData); + bool DoRestoreFromRemote(const WantParams &restoreData); +#ifdef SUPPORT_GRAPHICS + bool GetContentInfo(WantParams &wantParams); +#endif + sptr continueToken_ = nullptr; + std::weak_ptr ability_; + std::weak_ptr abilityInfo_; + ProgressState progressState_ = ProgressState::INITIAL; + bool reversible_ = false; + ContinuationState continuationState_ = ContinuationState::LOCAL_RUNNING; + std::string originalDeviceId_; + std::weak_ptr continuationHandler_; + std::shared_ptr mainHandler_ = nullptr; + std::mutex lock_; +}; +} // namespace AppExecFwk +} // namespace OHOS +#endif // OHOS_ABILITY_RUNTIME_CONTINUATION_MANAGER_STAGE_H diff --git a/interfaces/kits/native/ability/native/continuation/distributed/reverse_continuation_scheduler_primary_stage.h b/interfaces/kits/native/ability/native/continuation/distributed/reverse_continuation_scheduler_primary_stage.h new file mode 100644 index 0000000000..2354e60271 --- /dev/null +++ b/interfaces/kits/native/ability/native/continuation/distributed/reverse_continuation_scheduler_primary_stage.h @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2023 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_REVERSE_CONTINUATION_SCHEDULER_PRIMARY_STAGE_H +#define OHOS_ABILITY_RUNTIME_REVERSE_CONTINUATION_SCHEDULER_PRIMARY_STAGE_H + +#include + +#include "ability_handler.h" +#include "reverse_continuation_scheduler_primary_handler_interface.h" +#include "reverse_continuation_scheduler_primary_stub.h" + +namespace OHOS { +namespace AppExecFwk { +class ReverseContinuationSchedulerPrimaryStage : public ReverseContinuationSchedulerPrimaryStub { +public: + ReverseContinuationSchedulerPrimaryStage( + const std::weak_ptr &continuationHandler, + const std::shared_ptr &mainHandler); + virtual ~ReverseContinuationSchedulerPrimaryStage() = default; + + /** + * @brief Replica call this method when it terminated. + */ + void NotifyReplicaTerminated() override; + + /** + * @brief Replica call this method to notify primary go on. + * @param want Contains data to be restore. + * @return True if success, otherwise false. + */ + bool ContinuationBack(const AAFwk::Want &want) override; + +private: + void HandlerNotifyReplicaTerminated(); + void HandlerContinuationBack(const AAFwk::Want &want); + + std::weak_ptr continuationHandler_; + const std::shared_ptr mainHandler_; +}; +} // namespace AppExecFwk +} // namespace OHOS +#endif // OHOS_ABILITY_RUNTIME_REVERSE_CONTINUATION_SCHEDULER_PRIMARY_STAGE_H diff --git a/services/abilitymgr/include/ability_manager_proxy.h b/services/abilitymgr/include/ability_manager_proxy.h index 5277a2bff1..5ffea34d7f 100644 --- a/services/abilitymgr/include/ability_manager_proxy.h +++ b/services/abilitymgr/include/ability_manager_proxy.h @@ -65,6 +65,21 @@ public: int32_t userId = DEFAULT_INVAL_VALUE, int requestCode = DEFAULT_INVAL_VALUE) override; + /** + * StartAbility by insight intent, send want to ability manager service. + * + * @param want Ability want. + * @param callerToken caller ability token. + * @param intentId insight intent id. + * @param userId userId of target ability. + * @return Returns ERR_OK on success, others on failure. + */ + int32_t StartAbilityByInsightIntent( + const Want &want, + const sptr &callerToken, + uint64_t intentId, + int32_t userId = DEFAULT_INVAL_VALUE) override; + /** * Starts a new ability with specific start settings. * diff --git a/services/abilitymgr/include/ability_manager_service.h b/services/abilitymgr/include/ability_manager_service.h index a4f05442f3..b242e60d65 100644 --- a/services/abilitymgr/include/ability_manager_service.h +++ b/services/abilitymgr/include/ability_manager_service.h @@ -120,6 +120,21 @@ public: int32_t userId = DEFAULT_INVAL_VALUE, int requestCode = DEFAULT_INVAL_VALUE) override; + /** + * StartAbility by insight intent, send want to ability manager service. + * + * @param want Ability want. + * @param callerToken caller ability token. + * @param intentId insight intent id. + * @param userId userId of target ability. + * @return Returns ERR_OK on success, others on failure. + */ + int32_t StartAbilityByInsightIntent( + const Want &want, + const sptr &callerToken, + uint64_t intentId, + int32_t userId = DEFAULT_INVAL_VALUE) override; + /** * Starts a new ability with specific start settings. * diff --git a/services/abilitymgr/include/ability_manager_stub.h b/services/abilitymgr/include/ability_manager_stub.h index 30605dd571..1795e86c4a 100644 --- a/services/abilitymgr/include/ability_manager_stub.h +++ b/services/abilitymgr/include/ability_manager_stub.h @@ -266,6 +266,9 @@ private: int32_t DetachAppDebugInner(MessageParcel &data, MessageParcel &reply); int32_t IsAbilityControllerStartInner(MessageParcel &data, MessageParcel &reply); + + //insight intent related + int32_t StartAbilityByInsightIntentInner(MessageParcel &data, MessageParcel &reply); }; } // namespace AAFwk } // namespace OHOS diff --git a/services/abilitymgr/src/ability_connect_manager.cpp b/services/abilitymgr/src/ability_connect_manager.cpp index 5e22f1be08..7f6526e61f 100644 --- a/services/abilitymgr/src/ability_connect_manager.cpp +++ b/services/abilitymgr/src/ability_connect_manager.cpp @@ -221,6 +221,9 @@ void AbilityConnectManager::GetOrCreateServiceRecord(const AbilityRequest &abili AppExecFwk::ElementName element(abilityRequest.abilityInfo.deviceId, abilityRequest.abilityInfo.bundleName, abilityRequest.abilityInfo.name, abilityRequest.abilityInfo.moduleName); auto serviceMapIter = serviceMap_.find(element.GetURI()); + if (noReuse && serviceMapIter != serviceMap_.end()) { + serviceMap_.erase(element.GetURI()); + } if (noReuse || serviceMapIter == serviceMap_.end()) { targetService = AbilityRecord::CreateAbilityRecord(abilityRequest); if (targetService) { diff --git a/services/abilitymgr/src/ability_manager_client.cpp b/services/abilitymgr/src/ability_manager_client.cpp index 7d8e718313..90f2ff8c48 100644 --- a/services/abilitymgr/src/ability_manager_client.cpp +++ b/services/abilitymgr/src/ability_manager_client.cpp @@ -153,6 +153,18 @@ ErrCode AbilityManagerClient::StartAbility( return abms->StartAbility(want, callerToken, userId, requestCode); } +ErrCode AbilityManagerClient::StartAbilityByInsightIntent( + const Want &want, const sptr &callerToken, uint64_t intentId, int32_t userId) +{ + HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); + auto abms = GetAbilityManager(); + CHECK_POINTER_RETURN_NOT_CONNECTED(abms); + HILOG_DEBUG("ability:%{public}s, bundle:%{public}s, intentId:%{public}llu", + want.GetElement().GetAbilityName().c_str(), want.GetElement().GetBundleName().c_str(), intentId); + HandleDlpApp(const_cast(want)); + return abms->StartAbilityByInsightIntent(want, callerToken, intentId, userId); +} + ErrCode AbilityManagerClient::StartAbility(const Want &want, const AbilityStartSetting &abilityStartSetting, const sptr &callerToken, int requestCode, int32_t userId) { diff --git a/services/abilitymgr/src/ability_manager_proxy.cpp b/services/abilitymgr/src/ability_manager_proxy.cpp index 71efd5eaf8..7704ea25ee 100644 --- a/services/abilitymgr/src/ability_manager_proxy.cpp +++ b/services/abilitymgr/src/ability_manager_proxy.cpp @@ -216,6 +216,50 @@ int AbilityManagerProxy::StartAbility( return reply.ReadInt32(); } +int32_t AbilityManagerProxy::StartAbilityByInsightIntent(const Want &want, const sptr &callerToken, + uint64_t intentId, int32_t userId) +{ + MessageParcel data; + if (callerToken == nullptr) { + HILOG_ERROR("invalid callertoken."); + return INNER_ERR; + } + + if (!WriteInterfaceToken(data)) { + HILOG_ERROR("want write failed."); + return INNER_ERR; + } + + if (!data.WriteParcelable(&want)) { + HILOG_ERROR("want write failed."); + return INNER_ERR; + } + + if (!data.WriteBool(true) || !data.WriteRemoteObject(callerToken)) { + HILOG_ERROR("callerToken and flag write failed."); + return INNER_ERR; + } + + if (!data.WriteUint64(intentId)) { + HILOG_ERROR("intentId write failed."); + return INNER_ERR; + } + + if (!data.WriteInt32(userId)) { + HILOG_ERROR("userId write failed."); + return INNER_ERR; + } + + MessageParcel reply; + MessageOption option; + int32_t error = SendRequest(AbilityManagerInterfaceCode::START_ABILITY_BY_INSIGHT_INTENT, data, reply, option); + if (error != NO_ERROR) { + HILOG_ERROR("failed to start ability err: %{public}d", error); + return error; + } + return reply.ReadInt32(); +} + int AbilityManagerProxy::StartAbility(const Want &want, const StartOptions &startOptions, const sptr &callerToken, int32_t userId, int requestCode) { diff --git a/services/abilitymgr/src/ability_manager_service.cpp b/services/abilitymgr/src/ability_manager_service.cpp index 62f72c0f49..e63787eb98 100644 --- a/services/abilitymgr/src/ability_manager_service.cpp +++ b/services/abilitymgr/src/ability_manager_service.cpp @@ -474,6 +474,34 @@ int AbilityManagerService::StartAbility(const Want &want, const sptr &callerToken, + uint64_t intentId, int32_t userId) +{ + HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); + // verify bundleName code below will be uncommentted after dependency ready + /*std::string bundleNameFromWant = want.GetElement().GetBundleName(); + std::string bundleNameFromIntentMgr = ""; + if (DelayedSingleton::GetInstance()-> + GetBundleName(intentId, bundleNameFromIntentMgr) != ERR_OK) { + HILOG_ERROR("no such bundle matched intentId"); + return ERR_INVALID_VALUE; + } + auto abilityRecord = Token::GetAbilityRecordByToken(callerToken); + if (abilityRecord == nullptr) { + HILOG_ERROR("no such bundle matched token"); + return ERR_INVALID_VALUE; + } + std::string bundleNameFromAbilityRecord = abilityRecord->GetAbilityInfo().bundleName; + + if (!bundleNameFromWant.empty() && bundleNameFromWant == bundleNameFromIntentMgr && + bundleNameFromWant == bundleNameFromAbilityRecord) { + HILOG_INFO("bundleName match"); + return StartAbility(want, callerToken, userId, -1); + }*/ + HILOG_ERROR("bundleName not match"); + return ERR_INSIGHT_INTENT_START_INVALID_COMPONENT; +} + int AbilityManagerService::StartAbilityByUIContentSession(const Want &want, const sptr &callerToken, const sptr &sessionInfo, int32_t userId, int requestCode) { @@ -8627,16 +8655,12 @@ int32_t AbilityManagerService::DetachAppDebug(const std::string &bundleName) bool AbilityManagerService::IsAbilityControllerStart(const Want &want) { - bool isSCBCall = CheckCallingTokenId(BUNDLE_NAME_SCENEBOARD, U0_USER_ID); - if (isSCBCall) { - return IsAbilityControllerStart(want, want.GetBundle()); - } auto callingUid = IPCSkeleton::GetCallingUid(); bool isBrokerCall = (callingUid == BROKER_UID || callingUid == BROKER_RESERVE_UID); if (isBrokerCall) { return IsAbilityControllerStart(want, want.GetBundle()); } - HILOG_ERROR("The interface only support for broker and WMS"); + HILOG_ERROR("The interface only support for broker"); return true; } } // namespace AAFwk diff --git a/services/abilitymgr/src/ability_manager_stub.cpp b/services/abilitymgr/src/ability_manager_stub.cpp index 3e6b0160d4..36f1709872 100644 --- a/services/abilitymgr/src/ability_manager_stub.cpp +++ b/services/abilitymgr/src/ability_manager_stub.cpp @@ -83,6 +83,8 @@ void AbilityManagerStub::FirstStepInit() &AbilityManagerStub::StartAbilityByUIContentSessionAddCallerInner; requestFuncMap_[static_cast(AbilityManagerInterfaceCode::START_UI_SESSION_ABILITY_FOR_OPTIONS)] = &AbilityManagerStub::StartAbilityByUIContentSessionForOptionsInner; + requestFuncMap_[static_cast(AbilityManagerInterfaceCode::START_ABILITY_BY_INSIGHT_INTENT)] = + &AbilityManagerStub::StartAbilityByInsightIntentInner; requestFuncMap_[static_cast(AbilityManagerInterfaceCode::CONNECT_ABILITY)] = &AbilityManagerStub::ConnectAbilityInner; requestFuncMap_[static_cast(AbilityManagerInterfaceCode::DISCONNECT_ABILITY)] = @@ -2791,5 +2793,26 @@ int32_t AbilityManagerStub::IsAbilityControllerStartInner(MessageParcel &data, M reply.WriteBool(result); return NO_ERROR; } + +int32_t AbilityManagerStub::StartAbilityByInsightIntentInner(MessageParcel &data, MessageParcel &reply) +{ + std::unique_ptr want(data.ReadParcelable()); + if (want == nullptr) { + HILOG_ERROR("want is nullptr"); + return ERR_INVALID_VALUE; + } + + sptr callerToken = nullptr; + if (!data.ReadBool()) { + HILOG_ERROR("invalid caller token"); + return ERR_INVALID_VALUE; + } + callerToken = data.ReadRemoteObject(); + uint64_t intentId = data.ReadUint64(); + int32_t userId = data.ReadInt32(); + int32_t result = StartAbilityByInsightIntent(*want, callerToken, intentId, userId); + reply.WriteInt32(result); + return NO_ERROR; +} } // namespace AAFwk } // namespace OHOS diff --git a/services/appmgr/src/app_mgr_service_inner.cpp b/services/appmgr/src/app_mgr_service_inner.cpp index 9f76288d96..8f7126c6b0 100644 --- a/services/appmgr/src/app_mgr_service_inner.cpp +++ b/services/appmgr/src/app_mgr_service_inner.cpp @@ -103,6 +103,8 @@ const std::string DLP_PARAMS_SECURITY_FLAG = "ohos.dlp.params.securityFlag"; const std::string SUPPORT_ISOLATION_MODE = "persist.bms.supportIsolationMode"; const std::string SCENE_BOARD_BUNDLE_NAME = "com.ohos.sceneboard"; const std::string DEBUG_APP = "debugApp"; +const std::string SERVICE_EXTENSION = ":ServiceExtension"; +const std::string KEEP_ALIVE = ":KeepAlive"; const int32_t SIGNAL_KILL = 9; constexpr int32_t USER_SCALE = 200000; #define ENUM_TO_STRING(s) #s @@ -313,6 +315,12 @@ void AppMgrServiceInner::MakeProcessName(const std::shared_ptr &abi return; } MakeProcessName(appInfo, hapModuleInfo, processName); + if (processName == appInfo->bundleName && abilityInfo->extensionAbilityType == ExtensionAbilityType::SERVICE) { + processName += SERVICE_EXTENSION; + if (appInfo->keepAlive) { + processName += KEEP_ALIVE; + } + } if (appIndex != 0) { processName += std::to_string(appIndex); } diff --git a/services/uripermmgr/BUILD.gn b/services/uripermmgr/BUILD.gn index cc88ce332d..7026b09b20 100644 --- a/services/uripermmgr/BUILD.gn +++ b/services/uripermmgr/BUILD.gn @@ -57,6 +57,7 @@ ohos_shared_library("libupms") { "ability_base:want", "ability_base:zuri", "access_token:libaccesstoken_sdk", + "access_token:libtokenid_sdk", "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", "c_utils:utils", diff --git a/services/uripermmgr/src/uri_permission_manager_stub_impl.cpp b/services/uripermmgr/src/uri_permission_manager_stub_impl.cpp index 468c1050f7..a6f3eeed43 100644 --- a/services/uripermmgr/src/uri_permission_manager_stub_impl.cpp +++ b/services/uripermmgr/src/uri_permission_manager_stub_impl.cpp @@ -30,6 +30,7 @@ #include "permission_constants.h" #include "permission_verification.h" #include "system_ability_definition.h" +#include "tokenid_kit.h" #include "want.h" namespace OHOS { @@ -676,9 +677,9 @@ void UriPermissionManagerStubImpl::InitPersistableUriPermissionConfig() void UriPermissionManagerStubImpl::SendEvent(const Uri &uri, const std::string &targetBundleName, uint32_t targetTokenId, const std::vector &uriVec) { - auto isSaCall = PermissionVerification::GetInstance()->IsSACall(); - auto calleeTokenType = Security::AccessToken::AccessTokenKit::GetTokenTypeFlag(targetTokenId); - if (isSaCall && calleeTokenType != Security::AccessToken::ATokenTypeEnum::TOKEN_NATIVE) { + auto isSystemAppCall = PermissionVerification::GetInstance()->IsSystemAppCall(); + auto targetIsSystemApp = Security::AccessToken::TokenIdKit::IsSystemAppByFullTokenID(targetTokenId); + if (isSystemAppCall && !targetIsSystemApp) { EventInfo eventInfo; Uri uri_inner = uri; eventInfo.bundleName = targetBundleName; diff --git a/test/mock/frameworks_kits_ability_ability_runtime_test/AMS/mock_serviceability_manager_service.h b/test/mock/frameworks_kits_ability_ability_runtime_test/AMS/mock_serviceability_manager_service.h index a6eb571c2d..2779315ca0 100644 --- a/test/mock/frameworks_kits_ability_ability_runtime_test/AMS/mock_serviceability_manager_service.h +++ b/test/mock/frameworks_kits_ability_ability_runtime_test/AMS/mock_serviceability_manager_service.h @@ -126,6 +126,8 @@ public: MOCK_METHOD2(GetPendingRequestWant, int(const sptr& target, std::shared_ptr& want)); MOCK_METHOD5(StartAbility, int(const Want& want, const AbilityStartSetting& abilityStartSetting, const sptr& callerToken, int32_t userId, int requestCode)); + MOCK_METHOD4(StartAbilityByInsightIntent, int32_t(const Want& want, const sptr& callerToken, + uint64_t intentId, int32_t userId)); MOCK_METHOD1(GetPendinTerminateAbilityTestgRequestWant, void(int id)); MOCK_METHOD3(StartContinuation, int(const Want& want, const sptr& abilityToken, int32_t status)); MOCK_METHOD2(NotifyContinuationResult, int(int32_t missionId, int32_t result)); diff --git a/test/mock/frameworks_kits_ability_native_test/include/mock_ability_manager_service.h b/test/mock/frameworks_kits_ability_native_test/include/mock_ability_manager_service.h index 83fb8bac3d..9e4b539ce1 100644 --- a/test/mock/frameworks_kits_ability_native_test/include/mock_ability_manager_service.h +++ b/test/mock/frameworks_kits_ability_native_test/include/mock_ability_manager_service.h @@ -105,6 +105,8 @@ public: MOCK_METHOD5(StartAbility, int(const Want& want, const AbilityStartSetting& abilityStartSetting, const sptr& callerToken, int32_t userId, int requestCode)); + MOCK_METHOD4(StartAbilityByInsightIntent, int32_t(const Want& want, const sptr& callerToken, + uint64_t intentId, int32_t userId)); MOCK_METHOD1(GetPendinTerminateAbilityTestgRequestWant, void(int id)); MOCK_METHOD3(StartContinuation, int(const Want& want, const sptr& abilityToken, int32_t status)); MOCK_METHOD2(NotifyContinuationResult, int(int32_t missionId, int32_t result)); diff --git a/test/mock/frameworks_kits_appkit_native_test/ability_delegator/mock_ability_delegator_stub.h b/test/mock/frameworks_kits_appkit_native_test/ability_delegator/mock_ability_delegator_stub.h index e6665eea64..a694ae215c 100644 --- a/test/mock/frameworks_kits_appkit_native_test/ability_delegator/mock_ability_delegator_stub.h +++ b/test/mock/frameworks_kits_appkit_native_test/ability_delegator/mock_ability_delegator_stub.h @@ -36,6 +36,8 @@ public: int32_t userId, int requestCode)); MOCK_METHOD5(StartAbility, int(const Want& want, const AbilityStartSetting& abilityStartSetting, const sptr& callerToken, int32_t userId, int requestCode)); + MOCK_METHOD4(StartAbilityByInsightIntent, int32_t(const Want& want, const sptr& callerToken, + uint64_t intentId, int32_t userId)); int StartAbility(const Want& want, const StartOptions& startOptions, const sptr& callerToken, int requestCode = DEFAULT_INVAL_VALUE, int32_t userId = DEFAULT_INVAL_VALUE) override; @@ -195,6 +197,8 @@ public: int32_t userId, int requestCode)); MOCK_METHOD5(StartAbility, int(const Want& want, const AbilityStartSetting& abilityStartSetting, const sptr& callerToken, int32_t userId, int requestCode)); + MOCK_METHOD4(StartAbilityByInsightIntent, int32_t(const Want& want, const sptr& callerToken, + uint64_t intentId, int32_t userId)); int StartAbility(const Want& want, const StartOptions& startOptions, const sptr& callerToken, int requestCode = DEFAULT_INVAL_VALUE, int32_t userId = DEFAULT_INVAL_VALUE) override; diff --git a/test/mock/frameworks_kits_appkit_test/include/mock_ability_mgr_service.h b/test/mock/frameworks_kits_appkit_test/include/mock_ability_mgr_service.h index 1c32ae69ba..5f00122a00 100644 --- a/test/mock/frameworks_kits_appkit_test/include/mock_ability_mgr_service.h +++ b/test/mock/frameworks_kits_appkit_test/include/mock_ability_mgr_service.h @@ -29,6 +29,8 @@ public: int requestCode)); MOCK_METHOD5(StartAbility, int(const Want& want, const AbilityStartSetting& abilityStartSetting, const sptr& callerToken, int32_t userId, int requestCode)); + MOCK_METHOD4(StartAbilityByInsightIntent, int32_t(const Want& want, const sptr& callerToken, + uint64_t intentId, int32_t userId)); MOCK_METHOD4(StartAbilityAsCaller, int(const Want& want, const sptr& callerToken, int32_t userId, int requestCode)); MOCK_METHOD5(StartAbilityAsCaller, int(const Want &want, const StartOptions &startOptions, diff --git a/test/mock/frameworks_kits_test/AMS/mock_ability_manager_service.h b/test/mock/frameworks_kits_test/AMS/mock_ability_manager_service.h index d6444c8934..b523c29e55 100644 --- a/test/mock/frameworks_kits_test/AMS/mock_ability_manager_service.h +++ b/test/mock/frameworks_kits_test/AMS/mock_ability_manager_service.h @@ -118,6 +118,8 @@ public: MOCK_METHOD2(GetPendingRequestWant, int(const sptr& target, std::shared_ptr& want)); MOCK_METHOD5(StartAbility, int(const Want& want, const AbilityStartSetting& abilityStartSetting, const sptr& callerToken, int32_t userId, int requestCode)); + MOCK_METHOD4(StartAbilityByInsightIntent, int32_t(const Want& want, const sptr& callerToken, + uint64_t intentId, int32_t userId)); MOCK_METHOD1(GetPendinTerminateAbilityTestgRequestWant, void(int id)); MOCK_METHOD3(StartContinuation, int(const Want& want, const sptr& abilityToken, int32_t status)); MOCK_METHOD2(NotifyContinuationResult, int(int32_t missionId, int32_t result)); diff --git a/test/mock/frameworks_kits_test/AMS/mock_serviceability_manager_service.h b/test/mock/frameworks_kits_test/AMS/mock_serviceability_manager_service.h index 512d639ff4..eb2759894f 100644 --- a/test/mock/frameworks_kits_test/AMS/mock_serviceability_manager_service.h +++ b/test/mock/frameworks_kits_test/AMS/mock_serviceability_manager_service.h @@ -123,6 +123,8 @@ public: MOCK_METHOD2(GetPendingRequestWant, int(const sptr& target, std::shared_ptr& want)); MOCK_METHOD5(StartAbility, int(const Want& want, const AbilityStartSetting& abilityStartSetting, const sptr& callerToken, int32_t userId, int requestCode)); + MOCK_METHOD4(StartAbilityByInsightIntent, int32_t(const Want& want, const sptr& callerToken, + uint64_t intentId, int32_t userId)); MOCK_METHOD1(GetPendinTerminateAbilityTestgRequestWant, void(int id)); MOCK_METHOD3(StartContinuation, int(const Want& want, const sptr& abilityToken, int32_t status)); MOCK_METHOD2(NotifyContinuationResult, int(int32_t missionId, int32_t result)); diff --git a/test/moduletest/mock/include/appmgr/mock_ability_mgr_host.h b/test/moduletest/mock/include/appmgr/mock_ability_mgr_host.h index 6b8ce5a01c..5671df7ffa 100644 --- a/test/moduletest/mock/include/appmgr/mock_ability_mgr_host.h +++ b/test/moduletest/mock/include/appmgr/mock_ability_mgr_host.h @@ -50,6 +50,13 @@ public: { return 0; } + + int32_t StartAbilityByInsightIntent(const Want &want, const sptr &callerToken, + uint64_t intentId, int32_t userId) override + { + return 0; + } + virtual int StartAbilityAsCaller(const Want& want, const sptr& callerToken, int32_t userId = DEFAULT_INVAL_VALUE, int requestCode = -1) override { diff --git a/test/moduletest/mock/include/mock_ability_mgr_service.h b/test/moduletest/mock/include/mock_ability_mgr_service.h index f321889896..c420df86b5 100644 --- a/test/moduletest/mock/include/mock_ability_mgr_service.h +++ b/test/moduletest/mock/include/mock_ability_mgr_service.h @@ -79,6 +79,8 @@ public: MOCK_METHOD2(GetPendingRequestWant, int(const sptr& target, std::shared_ptr& want)); MOCK_METHOD5(StartAbility, int(const Want& want, const AbilityStartSetting& abilityStartSetting, const sptr& callerToken, int32_t userId, int requestCode)); + MOCK_METHOD4(StartAbilityByInsightIntent, int32_t(const Want& want, const sptr& callerToken, + uint64_t intentId, int32_t userId)); MOCK_METHOD3(StartContinuation, int(const Want& want, const sptr& abilityToken, int32_t status)); MOCK_METHOD2(NotifyContinuationResult, int(int32_t missionId, int32_t result)); MOCK_METHOD5(ContinueMission, int(const std::string& srcDeviceId, const std::string& dstDeviceId, diff --git a/test/unittest/ability_manager_client_branch_test/ability_manager_stub_mock_test.h b/test/unittest/ability_manager_client_branch_test/ability_manager_stub_mock_test.h index 09c0d1b660..ec03acf464 100644 --- a/test/unittest/ability_manager_client_branch_test/ability_manager_stub_mock_test.h +++ b/test/unittest/ability_manager_client_branch_test/ability_manager_stub_mock_test.h @@ -297,6 +297,8 @@ public: MOCK_METHOD4(StartAbility, int(const Want& want, const sptr& callerToken, int32_t userId, int requestCode)); + MOCK_METHOD4(StartAbilityByInsightIntent, int32_t(const Want& want, const sptr& callerToken, + uint64_t intentId, int32_t userId)); MOCK_METHOD4(StartAbilityAsCaller, int(const Want& want, const sptr& callerToken, int32_t userId, int requestCode)); MOCK_METHOD2( diff --git a/test/unittest/ability_manager_proxy_test/ability_manager_stub_mock.h b/test/unittest/ability_manager_proxy_test/ability_manager_stub_mock.h index b220324807..1468164e5d 100644 --- a/test/unittest/ability_manager_proxy_test/ability_manager_stub_mock.h +++ b/test/unittest/ability_manager_proxy_test/ability_manager_stub_mock.h @@ -292,6 +292,8 @@ public: MOCK_METHOD4(StartAbility, int(const Want& want, const sptr& callerToken, int32_t userId, int requestCode)); + MOCK_METHOD4(StartAbilityByInsightIntent, int32_t(const Want& want, const sptr& callerToken, + uint64_t intentId, int32_t userId)); MOCK_METHOD4(StartAbilityAsCaller, int(const Want &want, const sptr &callerToken, int32_t userId, int requestCode)); MOCK_METHOD2( diff --git a/test/unittest/ability_manager_stub_test/ability_manager_stub_impl_mock.h b/test/unittest/ability_manager_stub_test/ability_manager_stub_impl_mock.h index 4d33df6044..0ca7150ec9 100644 --- a/test/unittest/ability_manager_stub_test/ability_manager_stub_impl_mock.h +++ b/test/unittest/ability_manager_stub_test/ability_manager_stub_impl_mock.h @@ -34,6 +34,8 @@ public: MOCK_METHOD4(StartAbility, int(const Want& want, const sptr& callerToken, int32_t userId, int requestCode)); + MOCK_METHOD4(StartAbilityByInsightIntent, int32_t(const Want& want, const sptr& callerToken, + uint64_t intentId, int32_t userId)); MOCK_METHOD4(StartAbilityAsCaller, int(const Want &want, const sptr &callerToken, int32_t userId, int requestCode)); MOCK_METHOD2( diff --git a/test/unittest/ability_manager_test/ability_manager_stub_mock.h b/test/unittest/ability_manager_test/ability_manager_stub_mock.h index 9471733505..0626703348 100644 --- a/test/unittest/ability_manager_test/ability_manager_stub_mock.h +++ b/test/unittest/ability_manager_test/ability_manager_stub_mock.h @@ -286,6 +286,8 @@ public: MOCK_METHOD4(StartAbility, int(const Want& want, const sptr& callerToken, int32_t userId, int requestCode)); + MOCK_METHOD4(StartAbilityByInsightIntent, int32_t(const Want& want, const sptr& callerToken, + uint64_t intentId, int32_t userId)); MOCK_METHOD4(StartAbilityAsCaller, int(const Want& want, const sptr& callerToken, int32_t userId, int requestCode)); MOCK_METHOD2( 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 72ac04ab4d..a5d05989a2 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 @@ -936,6 +936,33 @@ HWTEST_F(AppMgrServiceInnerTest, KillProcessByPid_001, TestSize.Level0) HILOG_INFO("KillProcessByPid_001 end"); } +/** + * @tc.name: KillProcessByPid_002 + * @tc.desc: kill process by pid. + * @tc.type: FUNC + * @tc.require: issueI5W4S7 + */ +HWTEST_F(AppMgrServiceInnerTest, KillProcessByPid_002, TestSize.Level0) +{ + HILOG_INFO("KillProcessByPid_002 start"); + auto appMgrServiceInner = std::make_shared(); + EXPECT_NE(appMgrServiceInner, nullptr); + int pid = 0; + std::string processName = "test_processName"; + std::shared_ptr appRecord = + std::make_shared(applicationInfo_, ++recordId_, processName); + auto appRunningManager = std::make_shared(); + auto priorityObject = std::make_shared(); + priorityObject->SetPid(0); + appRecord->priorityObject_ = priorityObject; + appRunningManager->appRunningRecordMap_.emplace(recordId_, appRecord); + + int result = appMgrServiceInner->KillProcessByPid(pid); + EXPECT_EQ(result, -1); + + HILOG_INFO("KillProcessByPid_002 end"); +} + /** * @tc.name: GetAllPids_001 * @tc.desc: get all pids. @@ -3399,5 +3426,154 @@ HWTEST_F(AppMgrServiceInnerTest, ChangeAppGcState_001, TestSize.Level1) EXPECT_EQ(ret, ERR_INVALID_VALUE); HILOG_INFO("ChangeAppGcState_001 end"); } + +/** + * @tc.name: SendReStartProcessEvent_001 + * @tc.desc: Change app Gc state + * @tc.type: FUNC + */ +HWTEST_F(AppMgrServiceInnerTest, SendReStartProcessEvent_001, TestSize.Level1) +{ + HILOG_INFO("SendReStartProcessEvent_001 start"); + auto appMgrServiceInner = std::make_shared(); + EXPECT_NE(appMgrServiceInner, nullptr); + AAFwk::EventInfo eventInfo; + appMgrServiceInner->SendReStartProcessEvent(eventInfo, nullptr); + HILOG_INFO("SendReStartProcessEvent_001 end"); +} + +/** + * @tc.name: SendReStartProcessEvent_002 + * @tc.desc: Change app Gc state + * @tc.type: FUNC + */ +HWTEST_F(AppMgrServiceInnerTest, SendReStartProcessEvent_002, TestSize.Level1) +{ + HILOG_INFO("SendReStartProcessEvent_002 start"); + auto appMgrServiceInner = std::make_shared(); + EXPECT_NE(appMgrServiceInner, nullptr); + AAFwk::EventInfo eventInfo; + BundleInfo info; + std::string processName = "test_processName"; + auto record = appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, info); + recordId_ += 1; + int64_t restartTime = std::chrono::duration_cast(std::chrono:: + system_clock::now().time_since_epoch()).count(); + int64_t killedTime = restartTime - 3000; + appMgrServiceInner->killedPorcessMap_.emplace(killedTime, processName); + appMgrServiceInner->SendReStartProcessEvent(eventInfo, record); + HILOG_INFO("SendReStartProcessEvent_002 end"); +} + +/** + * @tc.name: SendReStartProcessEvent_003 + * @tc.desc: Change app Gc state + * @tc.type: FUNC + */ +HWTEST_F(AppMgrServiceInnerTest, SendReStartProcessEvent_003, TestSize.Level1) +{ + HILOG_INFO("SendReStartProcessEvent_003 start"); + auto appMgrServiceInner = std::make_shared(); + EXPECT_NE(appMgrServiceInner, nullptr); + AAFwk::EventInfo eventInfo; + eventInfo.bundleName = "bundleName"; + eventInfo.callerBundleName = "callerBundleName"; + BundleInfo info; + std::string processName = "test_processName"; + auto record = appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, info); + recordId_ += 1; + int64_t restartTime = std::chrono::duration_cast(std::chrono:: + system_clock::now().time_since_epoch()).count(); + int64_t killedTime = restartTime - 1000; + appMgrServiceInner->killedPorcessMap_.emplace(killedTime, processName); + appMgrServiceInner->SendReStartProcessEvent(eventInfo, record); + HILOG_INFO("SendReStartProcessEvent_003 end"); +} + +/** + * @tc.name: SendReStartProcessEvent_004 + * @tc.desc: Change app Gc state + * @tc.type: FUNC + */ +HWTEST_F(AppMgrServiceInnerTest, SendReStartProcessEvent_004, TestSize.Level1) +{ + HILOG_INFO("SendReStartProcessEvent_004 start"); + auto appMgrServiceInner = std::make_shared(); + EXPECT_NE(appMgrServiceInner, nullptr); + AAFwk::EventInfo eventInfo; + BundleInfo info; + std::string processName = "test_processName"; + eventInfo.bundleName = "bundleName"; + eventInfo.callerBundleName = "bundleName"; + eventInfo.callerProcessName = processName; + auto record = appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, info); + recordId_ += 1; + int64_t restartTime = std::chrono::duration_cast(std::chrono:: + system_clock::now().time_since_epoch()).count(); + int64_t killedTime = restartTime - 1000; + appMgrServiceInner->killedPorcessMap_.emplace(killedTime, processName); + appMgrServiceInner->SendReStartProcessEvent(eventInfo, record); + HILOG_INFO("SendReStartProcessEvent_004 end"); +} + +/** + * @tc.name: SendReStartProcessEvent_005 + * @tc.desc: Change app Gc state + * @tc.type: FUNC + */ +HWTEST_F(AppMgrServiceInnerTest, SendReStartProcessEvent_005, TestSize.Level1) +{ + HILOG_INFO("SendReStartProcessEvent_005 start"); + auto appMgrServiceInner = std::make_shared(); + EXPECT_NE(appMgrServiceInner, nullptr); + AAFwk::EventInfo eventInfo; + BundleInfo info; + std::string processName = "test_processName"; + eventInfo.bundleName = "bundleName"; + eventInfo.callerBundleName = "bundleName"; + eventInfo.callerProcessName = "processName"; + auto record = appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, info); + recordId_ += 1; + int64_t restartTime = std::chrono::duration_cast(std::chrono:: + system_clock::now().time_since_epoch()).count(); + int64_t killedTime = restartTime - 1000; + appMgrServiceInner->killedPorcessMap_.emplace(killedTime, processName); + appMgrServiceInner->SendReStartProcessEvent(eventInfo, record); + HILOG_INFO("SendReStartProcessEvent_005 end"); +} + +/** + * @tc.name: SendAppLaunchEvent_001 + * @tc.desc: launch application. + * @tc.type: FUNC + * @tc.require: issueI5W4S7 + */ +HWTEST_F(AppMgrServiceInnerTest, SendAppLaunchEvent_001, TestSize.Level0) +{ + HILOG_INFO("SendAppLaunchEvent_001 start"); + auto appMgrServiceInner = std::make_shared(); + EXPECT_NE(appMgrServiceInner, nullptr); + + appMgrServiceInner->SendAppLaunchEvent(nullptr); + BundleInfo info; + std::string processName = "test_processName"; + std::shared_ptr appRecord = + appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, info); + recordId_ += 1; + std::shared_ptr appRecord2 = + appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, info); + recordId_ += 1; + appRecord->SetState(ApplicationState::APP_STATE_CREATE); + appRecord->SetKeepAliveAppState(false, false); + Want want; + appRecord->SetSpecifiedAbilityFlagAndWant(false, want, ""); + appMgrServiceInner->SendAppLaunchEvent(appRecord); + appRecord->SetCallerPid(appRecord2->GetPriorityObject()->GetPid()); + appMgrServiceInner->SendAppLaunchEvent(appRecord); + appRecord->appInfo_ = nullptr; + appRecord2->appInfo_ = nullptr; + appMgrServiceInner->SendAppLaunchEvent(appRecord); + HILOG_INFO("SendAppLaunchEvent_001 end"); +} } // namespace AppExecFwk } // namespace OHOS diff --git a/test/unittest/frameworks_kits_ability_native_test/ability_test.cpp b/test/unittest/frameworks_kits_ability_native_test/ability_test.cpp index c00637dce3..17d390849b 100644 --- a/test/unittest/frameworks_kits_ability_native_test/ability_test.cpp +++ b/test/unittest/frameworks_kits_ability_native_test/ability_test.cpp @@ -2280,6 +2280,31 @@ HWTEST_F(AbilityBaseTest, AbilitySetShowOnLockScreen_0100, TestSize.Level1) HILOG_INFO("%{public}s end.", __func__); } +/** + * @tc.name: AbilitySetShowOnLockScreen_0200 + * @tc.desc: Ability SetShowOnLockScreen test + * @tc.type: FUNC + * @tc.require: issueI60B7N + */ +HWTEST_F(AbilityBaseTest, AbilitySetShowOnLockScreen_0200, TestSize.Level1) +{ + HILOG_INFO("%{public}s start.", __func__); + std::shared_ptr ability = std::make_shared(); + ASSERT_NE(ability, nullptr); + std::shared_ptr pageAbilityInfo = std::make_shared(); + pageAbilityInfo->type = AppExecFwk::AbilityType::PAGE; + auto eventRunner = EventRunner::Create(pageAbilityInfo->name); + auto handler = std::make_shared(eventRunner); + ability->Init(pageAbilityInfo, nullptr, handler, nullptr); + sptr session = new (std::nothrow) AAFwk::SessionInfo(); + int32_t displayId = 0; + sptr option = new Rosen::WindowOption(); + ability->InitWindow(displayId, option); + ability->abilityInfo_ = nullptr; + ability->SetShowOnLockScreen(true); + HILOG_INFO("%{public}s end.", __func__); +} + /** * @tc.name: AbilityScene_0100 * @tc.desc: Ability Scene test diff --git a/test/unittest/mission_list_manager_test/mission_list_manager_test.cpp b/test/unittest/mission_list_manager_test/mission_list_manager_test.cpp index daae42c47c..967601f4b9 100644 --- a/test/unittest/mission_list_manager_test/mission_list_manager_test.cpp +++ b/test/unittest/mission_list_manager_test/mission_list_manager_test.cpp @@ -152,6 +152,44 @@ HWTEST_F(MissionListManagerTest, StartAbility_001, TestSize.Level1) missionListManager.reset(); } +/* + * Feature: MissionListManager + * Function: StartAbility + * SubFunction: NA + * FunctionPoints: MissionListManager StartAbility + * EnvConditions: NA + * CaseDescription: Verify StartAbility + */ +HWTEST_F(MissionListManagerTest, StartAbility_002, TestSize.Level1) +{ + int userId = 0; + auto missionListManager = std::make_shared(userId); + missionListManager->Init(); + std::shared_ptr abilityRecord = InitAbilityRecord(); + abilityRecord->abilityInfo_.launchMode = AppExecFwk::LaunchMode::SPECIFIED; + std::string missionName = "#::"; + std::string flag = "flag"; + std::shared_ptr mission = std::make_shared(1, abilityRecord, missionName); + mission->SetSpecifiedFlag(flag); + std::shared_ptr missionList = std::make_shared(); + missionList->missions_.push_front(mission); + missionListManager->launcherList_ = missionList; + AbilityRequest abilityRequest; + abilityRequest.abilityInfo.launchMode = AppExecFwk::LaunchMode::SPECIFIED; + abilityRequest.abilityInfo.applicationInfo.isLauncherApp = true; + abilityRequest.specifiedFlag = flag; + abilityRequest.abilityInfo.visible = false; + auto result = missionListManager->StartAbility(abilityRequest); + EXPECT_EQ(0, result); + abilityRequest.abilityInfo.visible = true; + auto result2 = missionListManager->StartAbility(abilityRequest); + EXPECT_EQ(0, result2); + abilityRequest.abilityInfo.launchMode = AppExecFwk::LaunchMode::SINGLETON; + auto result3 = missionListManager->StartAbility(abilityRequest); + EXPECT_NE(0, result3); + missionListManager.reset(); +} + /* * Feature: MissionListManager * Function: GetMissionBySpecifiedFlag @@ -659,6 +697,60 @@ HWTEST_F(MissionListManagerTest, StartWaitingAbility_002, TestSize.Level1) missionListManager.reset(); } +/* + * Feature: MissionListManager + * Function: StartWaitingAbility + * SubFunction: NA + * FunctionPoints: MissionListManager StartWaitingAbility + * EnvConditions: NA + * CaseDescription: Verify StartWaitingAbility + */ +HWTEST_F(MissionListManagerTest, StartWaitingAbility_003, TestSize.Level1) +{ + int userId = 0; + auto missionListManager = std::make_shared(userId); + std::shared_ptr abilityRecord = InitAbilityRecord(); + abilityRecord->currentState_ = BACKGROUND; + std::shared_ptr mission = std::make_shared(1, abilityRecord, "missionName"); + std::shared_ptr missionList = std::make_shared(); + missionList->missions_.push_front(mission); + missionListManager->currentMissionLists_.push_front(missionList); + AbilityRequest abilityRequest; + abilityRequest.abilityInfo.launchMode = AppExecFwk::LaunchMode::SPECIFIED; + abilityRequest.abilityInfo.visible = false; + missionListManager->waitingAbilityQueue_.push(abilityRequest); + EXPECT_EQ(missionListManager->waitingAbilityQueue_.size(), 1); + missionListManager->StartWaitingAbility(); + missionListManager.reset(); +} + +/* + * Feature: MissionListManager + * Function: StartWaitingAbility + * SubFunction: NA + * FunctionPoints: MissionListManager StartWaitingAbility + * EnvConditions: NA + * CaseDescription: Verify StartWaitingAbility + */ +HWTEST_F(MissionListManagerTest, StartWaitingAbility_004, TestSize.Level1) +{ + int userId = 0; + auto missionListManager = std::make_shared(userId); + std::shared_ptr abilityRecord = InitAbilityRecord(); + abilityRecord->currentState_ = BACKGROUND; + std::shared_ptr mission = std::make_shared(1, abilityRecord, "missionName"); + std::shared_ptr missionList = std::make_shared(); + missionList->missions_.push_front(mission); + missionListManager->currentMissionLists_.push_front(missionList); + AbilityRequest abilityRequest; + abilityRequest.abilityInfo.launchMode = AppExecFwk::LaunchMode::SPECIFIED; + abilityRequest.abilityInfo.visible = true; + missionListManager->waitingAbilityQueue_.push(abilityRequest); + EXPECT_EQ(missionListManager->waitingAbilityQueue_.size(), 1); + missionListManager->StartWaitingAbility(); + missionListManager.reset(); +} + /* * Feature: MissionListManager * Function: CreateOrReusedMissionInfo @@ -6207,5 +6299,113 @@ HWTEST_F(MissionListManagerTest, Unmarshalling_001, TestSize.Level1) Parcel parcel; EXPECT_EQ(missionSnapshot.Unmarshalling(parcel), nullptr); } + +/* + * Feature: MissionListManager + * Function: OnStartSpecifiedAbilityTimeoutResponse + * SubFunction: NA + * FunctionPoints: MissionListManager OnStartSpecifiedAbilityTimeoutResponse + * EnvConditions: NA + * CaseDescription: Verify OnStartSpecifiedAbilityTimeoutResponse + */ +HWTEST_F(MissionListManagerTest, OnStartSpecifiedAbilityTimeoutResponse_001, TestSize.Level1) +{ + constexpr int32_t userId = 3; + auto missionListManager = std::make_shared(userId); + EXPECT_NE(missionListManager, nullptr); + Want want; + missionListManager->OnStartSpecifiedAbilityTimeoutResponse(want); +} + +/* + * Feature: MissionListManager + * Function: OnStartSpecifiedAbilityTimeoutResponse + * SubFunction: NA + * FunctionPoints: MissionListManager OnStartSpecifiedAbilityTimeoutResponse + * EnvConditions: NA + * CaseDescription: Verify OnStartSpecifiedAbilityTimeoutResponse + */ +HWTEST_F(MissionListManagerTest, OnStartSpecifiedAbilityTimeoutResponse_002, TestSize.Level1) +{ + constexpr int32_t userId = 3; + auto missionListManager = std::make_shared(userId); + EXPECT_NE(missionListManager, nullptr); + Want want; + AbilityRequest abilityRequest; + missionListManager->waitingAbilityQueue_.push(abilityRequest); + missionListManager->OnStartSpecifiedAbilityTimeoutResponse(want); +} + +/* + * Feature: MissionListManager + * Function: OnStartSpecifiedAbilityTimeoutResponse + * SubFunction: NA + * FunctionPoints: MissionListManager OnStartSpecifiedAbilityTimeoutResponse + * EnvConditions: NA + * CaseDescription: Verify OnStartSpecifiedAbilityTimeoutResponse + */ +HWTEST_F(MissionListManagerTest, OnStartSpecifiedAbilityTimeoutResponse_003, TestSize.Level1) +{ + constexpr int32_t userId = 3; + auto missionListManager = std::make_shared(userId); + EXPECT_NE(missionListManager, nullptr); + Want want; + AbilityRequest abilityRequest1; + AbilityRequest abilityRequest2; + abilityRequest1.abilityInfo.launchMode = AppExecFwk::LaunchMode::SPECIFIED; + abilityRequest1.abilityInfo.visible = false; + missionListManager->waitingAbilityQueue_.push(abilityRequest1); + missionListManager->OnStartSpecifiedAbilityTimeoutResponse(want); + missionListManager->waitingAbilityQueue_.push(abilityRequest2); + missionListManager->OnStartSpecifiedAbilityTimeoutResponse(want); +} + +/* + * Feature: MissionListManager + * Function: OnStartSpecifiedAbilityTimeoutResponse + * SubFunction: NA + * FunctionPoints: MissionListManager OnStartSpecifiedAbilityTimeoutResponse + * EnvConditions: NA + * CaseDescription: Verify OnStartSpecifiedAbilityTimeoutResponse + */ +HWTEST_F(MissionListManagerTest, OnStartSpecifiedAbilityTimeoutResponse_004, TestSize.Level1) +{ + constexpr int32_t userId = 3; + auto missionListManager = std::make_shared(userId); + EXPECT_NE(missionListManager, nullptr); + Want want; + AbilityRequest abilityRequest1; + AbilityRequest abilityRequest2; + abilityRequest1.abilityInfo.launchMode = AppExecFwk::LaunchMode::SPECIFIED; + abilityRequest1.abilityInfo.visible = true; + missionListManager->waitingAbilityQueue_.push(abilityRequest1); + missionListManager->OnStartSpecifiedAbilityTimeoutResponse(want); + missionListManager->waitingAbilityQueue_.push(abilityRequest2); + missionListManager->OnStartSpecifiedAbilityTimeoutResponse(want); +} + +/* + * Feature: MissionListManager + * Function: OnStartSpecifiedAbilityTimeoutResponse + * SubFunction: NA + * FunctionPoints: MissionListManager OnStartSpecifiedAbilityTimeoutResponse + * EnvConditions: NA + * CaseDescription: Verify OnStartSpecifiedAbilityTimeoutResponse + */ +HWTEST_F(MissionListManagerTest, OnStartSpecifiedAbilityTimeoutResponse_005, TestSize.Level1) +{ + constexpr int32_t userId = 3; + auto missionListManager = std::make_shared(userId); + EXPECT_NE(missionListManager, nullptr); + Want want; + AbilityRequest abilityRequest1; + AbilityRequest abilityRequest2; + abilityRequest1.abilityInfo.launchMode = AppExecFwk::LaunchMode::SINGLETON; + abilityRequest1.abilityInfo.visible = true; + missionListManager->waitingAbilityQueue_.push(abilityRequest1); + missionListManager->OnStartSpecifiedAbilityTimeoutResponse(want); + missionListManager->waitingAbilityQueue_.push(abilityRequest2); + missionListManager->OnStartSpecifiedAbilityTimeoutResponse(want); +} } // namespace AAFwk } // namespace OHOS diff --git a/test/unittest/service_extension_context_test/ability_manager_stub_mock.h b/test/unittest/service_extension_context_test/ability_manager_stub_mock.h index 3f0b06f98d..b4ca5f2c0c 100644 --- a/test/unittest/service_extension_context_test/ability_manager_stub_mock.h +++ b/test/unittest/service_extension_context_test/ability_manager_stub_mock.h @@ -271,6 +271,8 @@ public: MOCK_METHOD4(StartAbility, int(const Want& want, const sptr& callerToken, int32_t userId, int requestCode)); + MOCK_METHOD4(StartAbilityByInsightIntent, int32_t(const Want& want, const sptr& callerToken, + uint64_t intentId, int32_t userId)); MOCK_METHOD4(StartAbilityAsCaller, int(const Want& want, const sptr& callerToken, int32_t userId, int requestCode)); MOCK_METHOD2( diff --git a/test/unittest/sys_mgr_client_test/mock_ability_manager_service.h b/test/unittest/sys_mgr_client_test/mock_ability_manager_service.h index d8f2004f2b..f537df56f4 100644 --- a/test/unittest/sys_mgr_client_test/mock_ability_manager_service.h +++ b/test/unittest/sys_mgr_client_test/mock_ability_manager_service.h @@ -105,6 +105,8 @@ public: MOCK_METHOD2(GetPendingRequestWant, int(const sptr& target, std::shared_ptr& want)); MOCK_METHOD5(StartAbility, int(const Want& want, const AbilityStartSetting& abilityStartSetting, const sptr& callerToken, int32_t userId, int requestCode)); + MOCK_METHOD4(StartAbilityByInsightIntent, int32_t(const Want& want, const sptr& callerToken, + uint64_t intentId, int32_t userId)); MOCK_METHOD4(StartAbilityAsCaller, int(const Want& want, const sptr& callerToken, int32_t userId, int requestCode)); MOCK_METHOD5(StartAbilityAsCaller, int(const Want &want, const StartOptions &startOptions, diff --git a/test/unittest/ui_ability_lifecycle_manager_test/ui_ability_lifecycle_manager_test.cpp b/test/unittest/ui_ability_lifecycle_manager_test/ui_ability_lifecycle_manager_test.cpp index 0d24c295a2..8d7682abdc 100644 --- a/test/unittest/ui_ability_lifecycle_manager_test/ui_ability_lifecycle_manager_test.cpp +++ b/test/unittest/ui_ability_lifecycle_manager_test/ui_ability_lifecycle_manager_test.cpp @@ -186,6 +186,23 @@ HWTEST_F(UIAbilityLifecycleManagerTest, StartUIAbility_006, TestSize.Level1) EXPECT_EQ(mgr->StartUIAbility(abilityRequest, sessionInfo), ERR_OK); } +/** + * @tc.name: UIAbilityLifecycleManager_StartUIAbility_0700 + * @tc.desc: StartUIAbility + * @tc.type: FUNC + */ +HWTEST_F(UIAbilityLifecycleManagerTest, StartUIAbility_007, TestSize.Level1) +{ + auto mgr = std::make_unique(); + AbilityRequest abilityRequest; + abilityRequest.abilityInfo.visible = true; + abilityRequest.abilityInfoCallback = new MockAbilityInfoCallbackStub(); + Rosen::SessionInfo info; + sptr sessionInfo(new SessionInfo()); + sessionInfo->sessionToken = new Rosen::Session(info); + EXPECT_EQ(mgr->StartUIAbility(abilityRequest, sessionInfo), ERR_OK); +} + /** * @tc.name: UIAbilityLifecycleManager_CreateSessionInfo_0100 * @tc.desc: CreateSessionInfo diff --git a/test/unittest/uri_permission_impl_test/BUILD.gn b/test/unittest/uri_permission_impl_test/BUILD.gn index 2d16861a26..92272f82ce 100755 --- a/test/unittest/uri_permission_impl_test/BUILD.gn +++ b/test/unittest/uri_permission_impl_test/BUILD.gn @@ -47,6 +47,7 @@ ohos_unittest("uri_permission_impl_test") { "ability_base:zuri", "access_token:libnativetoken", "access_token:libtoken_setproc", + "access_token:libtokenid_sdk", "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", "c_utils:utils", diff --git a/test/unittest/uri_permission_impl_test/uri_permission_impl_test.cpp b/test/unittest/uri_permission_impl_test/uri_permission_impl_test.cpp index d65d65474d..deae698c7c 100755 --- a/test/unittest/uri_permission_impl_test/uri_permission_impl_test.cpp +++ b/test/unittest/uri_permission_impl_test/uri_permission_impl_test.cpp @@ -19,6 +19,7 @@ #include "mock_native_token.h" #include "system_ability_definition.h" #include "system_ability_manager_client.h" +#include "tokenid_kit.h" #define private public #include "uri_permission_manager_stub_impl.h" #undef private @@ -276,5 +277,22 @@ HWTEST_F(UriPermissionImplTest, Upms_ConnectManager_002, TestSize.Level1) MockSystemAbilityManager::isNullptr = false; ASSERT_EQ(storageManager, nullptr); } + +/* + * Feature: URIPermissionManagerService + * Function: ConnectManager + * SubFunction: NA + * FunctionPoints: URIPermissionManagerService SendEvent + */ +HWTEST_F(UriPermissionImplTest, Upms_SendEvent_001, TestSize.Level1) +{ + auto upms = std::make_unique(); + ASSERT_NE(upms, nullptr); + Uri uri("test"); + std::string targetBundleName = "bundleName"; + uint32_t targetTokenId = 0; + std::vector uriVec; + upms->SendEvent(uri, targetBundleName, targetTokenId, uriVec); +} } // namespace AAFwk } // namespace OHOS diff --git a/test/unittest/uri_permission_persistable_test/BUILD.gn b/test/unittest/uri_permission_persistable_test/BUILD.gn index dbdb2fe7c7..01f685cff4 100755 --- a/test/unittest/uri_permission_persistable_test/BUILD.gn +++ b/test/unittest/uri_permission_persistable_test/BUILD.gn @@ -49,6 +49,7 @@ ohos_unittest("uri_permission_persistable_test") { "ability_base:zuri", "access_token:libnativetoken", "access_token:libtoken_setproc", + "access_token:libtokenid_sdk", "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", "c_utils:utils", diff --git a/test/unittest/uri_permission_persistable_test/uri_permission_persistable_test.cpp b/test/unittest/uri_permission_persistable_test/uri_permission_persistable_test.cpp index 371622e1c8..960a707c05 100755 --- a/test/unittest/uri_permission_persistable_test/uri_permission_persistable_test.cpp +++ b/test/unittest/uri_permission_persistable_test/uri_permission_persistable_test.cpp @@ -20,6 +20,7 @@ #include "mock_native_token.h" #include "system_ability_definition.h" #include "system_ability_manager_client.h" +#include "tokenid_kit.h" #define private public #include "uri_permission_manager_stub_impl.h" #undef private diff --git a/test/unittest/uri_permission_test/BUILD.gn b/test/unittest/uri_permission_test/BUILD.gn index 73f9dabe93..437b02238f 100755 --- a/test/unittest/uri_permission_test/BUILD.gn +++ b/test/unittest/uri_permission_test/BUILD.gn @@ -35,6 +35,7 @@ ohos_unittest("uri_permission_test") { external_deps = [ "ability_base:zuri", + "access_token:libtokenid_sdk", "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", "init:libbeget_proxy", diff --git a/test/unittest/uri_permission_test/uri_permission_test.cpp b/test/unittest/uri_permission_test/uri_permission_test.cpp index bbbbb46325..10f0441079 100755 --- a/test/unittest/uri_permission_test/uri_permission_test.cpp +++ b/test/unittest/uri_permission_test/uri_permission_test.cpp @@ -19,6 +19,7 @@ #include "istorage_manager.h" #include "storage_manager_proxy.h" #include "system_ability_definition.h" +#include "tokenid_kit.h" #define private public #include "uri_permission_manager_stub_impl.h" #undef private diff --git a/tools/test/mock/mock_ability_manager_stub.h b/tools/test/mock/mock_ability_manager_stub.h index 0e0349a6db..b89487c510 100644 --- a/tools/test/mock/mock_ability_manager_stub.h +++ b/tools/test/mock/mock_ability_manager_stub.h @@ -87,6 +87,8 @@ public: MOCK_METHOD2(GetPendingRequestWant, int(const sptr& target, std::shared_ptr& want)); MOCK_METHOD5(StartAbility, int(const Want& want, const AbilityStartSetting& abilityStartSetting, const sptr& callerToken, int32_t userId, int requestCode)); + MOCK_METHOD4(StartAbilityByInsightIntent, int32_t(const Want& want, const sptr& callerToken, + uint64_t intentId, int32_t userId)); MOCK_METHOD1(GetMissionIdByToken, int32_t(const sptr& token)); MOCK_METHOD1(GetPendinTerminateAbilityTestgRequestWant, void(int id)); MOCK_METHOD3(StartContinuation, int(const Want& want, const sptr& abilityToken, int32_t status));