xinking129
2023-10-23 21:01:17 +08:00
65 changed files with 2770 additions and 71 deletions
+1
View File
@@ -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",
+1
View File
@@ -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",
@@ -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"
}
@@ -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);
}
@@ -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<JsInsightIntentContext>(static_cast<JsInsightIntentContext*>(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<ErrCode>(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<int>(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<InsightIntentContext>& context)
{
HILOG_DEBUG("enter");
napi_value contextObj;
napi_create_object(env, &contextObj);
std::unique_ptr<JsInsightIntentContext> jsInsightIntentContext = std::make_unique<JsInsightIntentContext>(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
@@ -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<InsightIntentContext>& 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<InsightIntentContext> 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<InsightIntentContext>& context);
} // namespace AbilityRuntime
} // namespace OHOS
#endif // OHOS_ABILITY_RUNTIME_JS_INSIGHT_INTENT_CONTEXT_H
@@ -18,6 +18,7 @@
#include <unistd.h>
#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)));
}
}
};
@@ -140,7 +140,8 @@ static std::unordered_map<int32_t, AbilityErrorCode> 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},
};
}
@@ -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<AbilityRuntime::ApplicationContext> 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<AppExecFwk::SysMrgClient>::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;
@@ -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 <map>
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
@@ -42,11 +42,11 @@ void JsChildProcess::Init(const std::shared_ptr<ChildProcessStartInfo> &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);
@@ -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<ContinuationManagerStage> &continuationManager,
std::weak_ptr<AbilityRuntime::UIAbility> &uiAbility)
: ability_(uiAbility), continuationManager_(continuationManager) {}
bool ContinuationHandlerStage::HandleStartContinuationWithStack(
const sptr<IRemoteObject> &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<ContinuationManagerStage> 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<int32_t>(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<IRemoteObject> &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<ContinuationManagerStage> 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<IRemoteObject> &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<IReverseContinuationSchedulerReplica>(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<ContinuationManagerStage> 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> &abilityInfo)
{
HILOG_DEBUG("Begin.");
abilityInfo_ = std::make_shared<AbilityInfo>(*(abilityInfo.get()));
ClearDeviceInfo(abilityInfo_);
HILOG_DEBUG("End.");
}
void ContinuationHandlerStage::SetPrimaryStub(const sptr<IRemoteObject> &Primary)
{
HILOG_DEBUG("Called.");
remotePrimaryStub_ = Primary;
}
void ContinuationHandlerStage::ClearDeviceInfo(std::shared_ptr<AbilityInfo> &abilityInfo)
{
HILOG_DEBUG("Called.");
abilityInfo->deviceId = "";
abilityInfo->deviceTypes.clear();
}
void ContinuationHandlerStage::OnReplicaDied(const wptr<IRemoteObject> &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<ContinuationManagerStage> 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<IRemoteObject> &Primary)
{
HILOG_DEBUG("Called.");
remotePrimaryProxy_ = iface_cast<IReverseContinuationSchedulerPrimary>(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<ContinuationManagerStage> 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<AbilityRuntime::UIAbility> 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<ContinuationManagerStage> 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
@@ -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<AbilityRuntime::UIAbility> &ability,
const sptr<IRemoteObject> &continueToken, const std::shared_ptr<AbilityInfo> &abilityInfo,
const std::shared_ptr<ContinuationHandlerStage> &continuationHandler)
{
HILOG_DEBUG("Begin.");
if (ability == nullptr) {
HILOG_ERROR("Ability is nullptr.");
return false;
}
ability_ = ability;
std::shared_ptr<AbilityRuntime::UIAbility> 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<IRemoteObject> 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<AbilityRuntime::UIAbility> 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<AbilityRuntime::UIAbility> 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<AbilityRuntime::UIAbility> 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<ContinuationHandlerStage> 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<IRemoteObject> &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<AbilityRuntime::UIAbility> 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<AbilityRuntime::UIAbility> 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<AbilityRuntime::UIAbility> 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<ContinuationHandlerStage> continuationHandler = continuationHandler_.lock();
if (continuationHandler == nullptr) {
HILOG_ERROR("ContinuationHandler is nullptr.");
return false;
}
continuationHandler->SetReversible(reversible);
InitMainHandlerIfNeed();
wptr<IRemoteObject> 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<std::mutex> lock_l(lock_);
if ((mainHandler_ == nullptr) && (EventRunner::GetMainEventRunner() != nullptr)) {
mainHandler_ = std::make_shared<EventHandler>(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<AbilityRuntime::UIAbility> 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<AbilityRuntime::UIAbility> 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<AbilityRuntime::UIAbility> 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<AbilityRuntime::UIAbility> 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
@@ -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<IReverseContinuationSchedulerPrimaryHandler> &continuationHandler,
const std::shared_ptr<AbilityHandler> &mainHandler)
: continuationHandler_(continuationHandler), mainHandler_(mainHandler)
{}
void ReverseContinuationSchedulerPrimaryStage::NotifyReplicaTerminated()
{
HILOG_DEBUG("Begin.");
wptr<ReverseContinuationSchedulerPrimaryStage> 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<ReverseContinuationSchedulerPrimaryStage> 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<IReverseContinuationSchedulerPrimaryHandler> 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<IReverseContinuationSchedulerPrimaryHandler> continuationHandler = continuationHandler_.lock();
if (continuationHandler == nullptr) {
HILOG_ERROR("ContinuationHandler is nullptr.");
return;
}
continuationHandler->ContinuationBack(want);
HILOG_DEBUG("End.");
}
} // namespace AppExecFwk
} // namespace OHOS
+17
View File
@@ -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" ]
}
@@ -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"
}
@@ -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
@@ -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<IRemoteObject> &callerToken,
uint64_t intentId,
int32_t userId = DEFAULT_INVAL_VALUE);
/**
* Starts a new ability with specific start settings.
*
@@ -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 {
@@ -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<IRemoteObject> &callerToken,
uint64_t intentId,
int32_t userId = DEFAULT_INVAL_VALUE) = 0;
/**
* Starts a new ability with specific start settings.
*
@@ -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,
@@ -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",
]
@@ -19,6 +19,7 @@
#include <string>
#include <sys/types.h>
#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<AbilityRuntime::Runtime> CreateRuntime(AppExecFwk::HapModuleInfo &hapModuleInfo);
static bool signalRegistered_;
@@ -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 <map>
#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<ChildProcessManagerErrorCode, AbilityErrorCode> 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
@@ -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<IRemoteObject>& 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<IRemoteObject> 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
@@ -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 <string>
#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<ContinuationManagerStage> &continuationManager,
std::weak_ptr<AbilityRuntime::UIAbility> &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<IRemoteObject> &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<IRemoteObject> &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<IRemoteObject> &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> &abilityInfo);
/**
* @brief Set the Primary Stub
* @param Primary Indicates the Primary to be set up
*/
void SetPrimaryStub(const sptr<IRemoteObject> &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<IRemoteObject> &token, const std::string &deviceId, uint32_t versionCode);
static const std::string ORIGINAL_DEVICE_ID;
private:
void OnReplicaDied(const wptr<IRemoteObject> &remote);
void ClearDeviceInfo(std::shared_ptr<AbilityInfo> &abilityInfo);
void CleanUpAfterReverse();
Want SetWantParams(const WantParams &wantParams);
std::shared_ptr<AbilityInfo> abilityInfo_ = nullptr;
std::weak_ptr<AbilityRuntime::UIAbility> ability_;
std::weak_ptr<ContinuationManagerStage> continuationManager_;
bool reversible_ = false;
sptr<IReverseContinuationSchedulerReplica> remoteReplicaProxy_ = nullptr;
sptr<IReverseContinuationSchedulerPrimary> remotePrimaryProxy_ = nullptr;
sptr<IRemoteObject> remotePrimaryStub_ = nullptr;
sptr<IRemoteObject::DeathRecipient> schedulerDeathRecipient_ = nullptr;
};
} // namespace AppExecFwk
} // namespace OHOS
#endif // OHOS_ABILITY_RUNTIME_CONTINUATION_HANDLER_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 <memory>
#include <mutex>
#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<ContinuationManagerStage> {
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<AbilityRuntime::UIAbility> &ability, const sptr<IRemoteObject> &continueToken,
const std::shared_ptr<AbilityInfo> &abilityInfo,
const std::shared_ptr<ContinuationHandlerStage> &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<IRemoteObject> &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<IRemoteObject> continueToken_ = nullptr;
std::weak_ptr<AbilityRuntime::UIAbility> ability_;
std::weak_ptr<AbilityInfo> abilityInfo_;
ProgressState progressState_ = ProgressState::INITIAL;
bool reversible_ = false;
ContinuationState continuationState_ = ContinuationState::LOCAL_RUNNING;
std::string originalDeviceId_;
std::weak_ptr<ContinuationHandlerStage> continuationHandler_;
std::shared_ptr<EventHandler> mainHandler_ = nullptr;
std::mutex lock_;
};
} // namespace AppExecFwk
} // namespace OHOS
#endif // OHOS_ABILITY_RUNTIME_CONTINUATION_MANAGER_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 <memory>
#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<IReverseContinuationSchedulerPrimaryHandler> &continuationHandler,
const std::shared_ptr<AbilityHandler> &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<IReverseContinuationSchedulerPrimaryHandler> continuationHandler_;
const std::shared_ptr<AbilityHandler> mainHandler_;
};
} // namespace AppExecFwk
} // namespace OHOS
#endif // OHOS_ABILITY_RUNTIME_REVERSE_CONTINUATION_SCHEDULER_PRIMARY_STAGE_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<IRemoteObject> &callerToken,
uint64_t intentId,
int32_t userId = DEFAULT_INVAL_VALUE) override;
/**
* Starts a new ability with specific start settings.
*
@@ -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<IRemoteObject> &callerToken,
uint64_t intentId,
int32_t userId = DEFAULT_INVAL_VALUE) override;
/**
* Starts a new ability with specific start settings.
*
@@ -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
@@ -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) {
@@ -153,6 +153,18 @@ ErrCode AbilityManagerClient::StartAbility(
return abms->StartAbility(want, callerToken, userId, requestCode);
}
ErrCode AbilityManagerClient::StartAbilityByInsightIntent(
const Want &want, const sptr<IRemoteObject> &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 &>(want));
return abms->StartAbilityByInsightIntent(want, callerToken, intentId, userId);
}
ErrCode AbilityManagerClient::StartAbility(const Want &want, const AbilityStartSetting &abilityStartSetting,
const sptr<IRemoteObject> &callerToken, int requestCode, int32_t userId)
{
@@ -216,6 +216,50 @@ int AbilityManagerProxy::StartAbility(
return reply.ReadInt32();
}
int32_t AbilityManagerProxy::StartAbilityByInsightIntent(const Want &want, const sptr<IRemoteObject> &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<IRemoteObject> &callerToken, int32_t userId, int requestCode)
{
@@ -474,6 +474,34 @@ int AbilityManagerService::StartAbility(const Want &want, const sptr<IRemoteObje
return ret;
}
int32_t AbilityManagerService::StartAbilityByInsightIntent(const Want &want, const sptr<IRemoteObject> &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<InsightIntentExecuteManager>::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<IRemoteObject> &callerToken,
const sptr<SessionInfo> &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
@@ -83,6 +83,8 @@ void AbilityManagerStub::FirstStepInit()
&AbilityManagerStub::StartAbilityByUIContentSessionAddCallerInner;
requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::START_UI_SESSION_ABILITY_FOR_OPTIONS)] =
&AbilityManagerStub::StartAbilityByUIContentSessionForOptionsInner;
requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::START_ABILITY_BY_INSIGHT_INTENT)] =
&AbilityManagerStub::StartAbilityByInsightIntentInner;
requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::CONNECT_ABILITY)] =
&AbilityManagerStub::ConnectAbilityInner;
requestFuncMap_[static_cast<uint32_t>(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> want(data.ReadParcelable<Want>());
if (want == nullptr) {
HILOG_ERROR("want is nullptr");
return ERR_INVALID_VALUE;
}
sptr<IRemoteObject> 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
@@ -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<AbilityInfo> &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);
}
+1
View File
@@ -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",
@@ -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<std::string> &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;
@@ -126,6 +126,8 @@ public:
MOCK_METHOD2(GetPendingRequestWant, int(const sptr<IWantSender>& target, std::shared_ptr<Want>& want));
MOCK_METHOD5(StartAbility, int(const Want& want, const AbilityStartSetting& abilityStartSetting,
const sptr<IRemoteObject>& callerToken, int32_t userId, int requestCode));
MOCK_METHOD4(StartAbilityByInsightIntent, int32_t(const Want& want, const sptr<IRemoteObject>& callerToken,
uint64_t intentId, int32_t userId));
MOCK_METHOD1(GetPendinTerminateAbilityTestgRequestWant, void(int id));
MOCK_METHOD3(StartContinuation, int(const Want& want, const sptr<IRemoteObject>& abilityToken, int32_t status));
MOCK_METHOD2(NotifyContinuationResult, int(int32_t missionId, int32_t result));
@@ -105,6 +105,8 @@ public:
MOCK_METHOD5(StartAbility, int(const Want& want, const AbilityStartSetting& abilityStartSetting,
const sptr<IRemoteObject>& callerToken, int32_t userId, int requestCode));
MOCK_METHOD4(StartAbilityByInsightIntent, int32_t(const Want& want, const sptr<IRemoteObject>& callerToken,
uint64_t intentId, int32_t userId));
MOCK_METHOD1(GetPendinTerminateAbilityTestgRequestWant, void(int id));
MOCK_METHOD3(StartContinuation, int(const Want& want, const sptr<IRemoteObject>& abilityToken, int32_t status));
MOCK_METHOD2(NotifyContinuationResult, int(int32_t missionId, int32_t result));
@@ -36,6 +36,8 @@ public:
int32_t userId, int requestCode));
MOCK_METHOD5(StartAbility, int(const Want& want, const AbilityStartSetting& abilityStartSetting,
const sptr<IRemoteObject>& callerToken, int32_t userId, int requestCode));
MOCK_METHOD4(StartAbilityByInsightIntent, int32_t(const Want& want, const sptr<IRemoteObject>& callerToken,
uint64_t intentId, int32_t userId));
int StartAbility(const Want& want, const StartOptions& startOptions,
const sptr<IRemoteObject>& 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<IRemoteObject>& callerToken, int32_t userId, int requestCode));
MOCK_METHOD4(StartAbilityByInsightIntent, int32_t(const Want& want, const sptr<IRemoteObject>& callerToken,
uint64_t intentId, int32_t userId));
int StartAbility(const Want& want, const StartOptions& startOptions,
const sptr<IRemoteObject>& callerToken, int requestCode = DEFAULT_INVAL_VALUE,
int32_t userId = DEFAULT_INVAL_VALUE) override;
@@ -29,6 +29,8 @@ public:
int requestCode));
MOCK_METHOD5(StartAbility, int(const Want& want, const AbilityStartSetting& abilityStartSetting,
const sptr<IRemoteObject>& callerToken, int32_t userId, int requestCode));
MOCK_METHOD4(StartAbilityByInsightIntent, int32_t(const Want& want, const sptr<IRemoteObject>& callerToken,
uint64_t intentId, int32_t userId));
MOCK_METHOD4(StartAbilityAsCaller, int(const Want& want, const sptr<IRemoteObject>& callerToken,
int32_t userId, int requestCode));
MOCK_METHOD5(StartAbilityAsCaller, int(const Want &want, const StartOptions &startOptions,
@@ -118,6 +118,8 @@ public:
MOCK_METHOD2(GetPendingRequestWant, int(const sptr<IWantSender>& target, std::shared_ptr<Want>& want));
MOCK_METHOD5(StartAbility, int(const Want& want, const AbilityStartSetting& abilityStartSetting,
const sptr<IRemoteObject>& callerToken, int32_t userId, int requestCode));
MOCK_METHOD4(StartAbilityByInsightIntent, int32_t(const Want& want, const sptr<IRemoteObject>& callerToken,
uint64_t intentId, int32_t userId));
MOCK_METHOD1(GetPendinTerminateAbilityTestgRequestWant, void(int id));
MOCK_METHOD3(StartContinuation, int(const Want& want, const sptr<IRemoteObject>& abilityToken, int32_t status));
MOCK_METHOD2(NotifyContinuationResult, int(int32_t missionId, int32_t result));
@@ -123,6 +123,8 @@ public:
MOCK_METHOD2(GetPendingRequestWant, int(const sptr<IWantSender>& target, std::shared_ptr<Want>& want));
MOCK_METHOD5(StartAbility, int(const Want& want, const AbilityStartSetting& abilityStartSetting,
const sptr<IRemoteObject>& callerToken, int32_t userId, int requestCode));
MOCK_METHOD4(StartAbilityByInsightIntent, int32_t(const Want& want, const sptr<IRemoteObject>& callerToken,
uint64_t intentId, int32_t userId));
MOCK_METHOD1(GetPendinTerminateAbilityTestgRequestWant, void(int id));
MOCK_METHOD3(StartContinuation, int(const Want& want, const sptr<IRemoteObject>& abilityToken, int32_t status));
MOCK_METHOD2(NotifyContinuationResult, int(int32_t missionId, int32_t result));
@@ -50,6 +50,13 @@ public:
{
return 0;
}
int32_t StartAbilityByInsightIntent(const Want &want, const sptr<IRemoteObject> &callerToken,
uint64_t intentId, int32_t userId) override
{
return 0;
}
virtual int StartAbilityAsCaller(const Want& want, const sptr<IRemoteObject>& callerToken,
int32_t userId = DEFAULT_INVAL_VALUE, int requestCode = -1) override
{
@@ -79,6 +79,8 @@ public:
MOCK_METHOD2(GetPendingRequestWant, int(const sptr<IWantSender>& target, std::shared_ptr<Want>& want));
MOCK_METHOD5(StartAbility, int(const Want& want, const AbilityStartSetting& abilityStartSetting,
const sptr<IRemoteObject>& callerToken, int32_t userId, int requestCode));
MOCK_METHOD4(StartAbilityByInsightIntent, int32_t(const Want& want, const sptr<IRemoteObject>& callerToken,
uint64_t intentId, int32_t userId));
MOCK_METHOD3(StartContinuation, int(const Want& want, const sptr<IRemoteObject>& 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,
@@ -297,6 +297,8 @@ public:
MOCK_METHOD4(StartAbility, int(const Want& want, const sptr<IRemoteObject>& callerToken,
int32_t userId, int requestCode));
MOCK_METHOD4(StartAbilityByInsightIntent, int32_t(const Want& want, const sptr<IRemoteObject>& callerToken,
uint64_t intentId, int32_t userId));
MOCK_METHOD4(StartAbilityAsCaller, int(const Want& want, const sptr<IRemoteObject>& callerToken,
int32_t userId, int requestCode));
MOCK_METHOD2(
@@ -292,6 +292,8 @@ public:
MOCK_METHOD4(StartAbility, int(const Want& want, const sptr<IRemoteObject>& callerToken,
int32_t userId, int requestCode));
MOCK_METHOD4(StartAbilityByInsightIntent, int32_t(const Want& want, const sptr<IRemoteObject>& callerToken,
uint64_t intentId, int32_t userId));
MOCK_METHOD4(StartAbilityAsCaller, int(const Want &want, const sptr<IRemoteObject> &callerToken,
int32_t userId, int requestCode));
MOCK_METHOD2(
@@ -34,6 +34,8 @@ public:
MOCK_METHOD4(StartAbility, int(const Want& want, const sptr<IRemoteObject>& callerToken,
int32_t userId, int requestCode));
MOCK_METHOD4(StartAbilityByInsightIntent, int32_t(const Want& want, const sptr<IRemoteObject>& callerToken,
uint64_t intentId, int32_t userId));
MOCK_METHOD4(StartAbilityAsCaller, int(const Want &want, const sptr<IRemoteObject> &callerToken,
int32_t userId, int requestCode));
MOCK_METHOD2(
@@ -286,6 +286,8 @@ public:
MOCK_METHOD4(StartAbility, int(const Want& want, const sptr<IRemoteObject>& callerToken,
int32_t userId, int requestCode));
MOCK_METHOD4(StartAbilityByInsightIntent, int32_t(const Want& want, const sptr<IRemoteObject>& callerToken,
uint64_t intentId, int32_t userId));
MOCK_METHOD4(StartAbilityAsCaller, int(const Want& want, const sptr<IRemoteObject>& callerToken,
int32_t userId, int requestCode));
MOCK_METHOD2(
@@ -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<AppMgrServiceInner>();
EXPECT_NE(appMgrServiceInner, nullptr);
int pid = 0;
std::string processName = "test_processName";
std::shared_ptr<AppRunningRecord> appRecord =
std::make_shared<AppRunningRecord>(applicationInfo_, ++recordId_, processName);
auto appRunningManager = std::make_shared<AppRunningManager>();
auto priorityObject = std::make_shared<PriorityObject>();
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<AppMgrServiceInner>();
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<AppMgrServiceInner>();
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::milliseconds>(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<AppMgrServiceInner>();
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::milliseconds>(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<AppMgrServiceInner>();
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::milliseconds>(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<AppMgrServiceInner>();
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::milliseconds>(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<AppMgrServiceInner>();
EXPECT_NE(appMgrServiceInner, nullptr);
appMgrServiceInner->SendAppLaunchEvent(nullptr);
BundleInfo info;
std::string processName = "test_processName";
std::shared_ptr<AppRunningRecord> appRecord =
appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, info);
recordId_ += 1;
std::shared_ptr<AppRunningRecord> 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
@@ -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> ability = std::make_shared<Ability>();
ASSERT_NE(ability, nullptr);
std::shared_ptr<AbilityInfo> pageAbilityInfo = std::make_shared<AbilityInfo>();
pageAbilityInfo->type = AppExecFwk::AbilityType::PAGE;
auto eventRunner = EventRunner::Create(pageAbilityInfo->name);
auto handler = std::make_shared<AbilityHandler>(eventRunner);
ability->Init(pageAbilityInfo, nullptr, handler, nullptr);
sptr<AAFwk::SessionInfo> session = new (std::nothrow) AAFwk::SessionInfo();
int32_t displayId = 0;
sptr<Rosen::WindowOption> 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
@@ -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<MissionListManager>(userId);
missionListManager->Init();
std::shared_ptr<AbilityRecord> abilityRecord = InitAbilityRecord();
abilityRecord->abilityInfo_.launchMode = AppExecFwk::LaunchMode::SPECIFIED;
std::string missionName = "#::";
std::string flag = "flag";
std::shared_ptr<Mission> mission = std::make_shared<Mission>(1, abilityRecord, missionName);
mission->SetSpecifiedFlag(flag);
std::shared_ptr<MissionList> missionList = std::make_shared<MissionList>();
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<MissionListManager>(userId);
std::shared_ptr<AbilityRecord> abilityRecord = InitAbilityRecord();
abilityRecord->currentState_ = BACKGROUND;
std::shared_ptr<Mission> mission = std::make_shared<Mission>(1, abilityRecord, "missionName");
std::shared_ptr<MissionList> missionList = std::make_shared<MissionList>();
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<MissionListManager>(userId);
std::shared_ptr<AbilityRecord> abilityRecord = InitAbilityRecord();
abilityRecord->currentState_ = BACKGROUND;
std::shared_ptr<Mission> mission = std::make_shared<Mission>(1, abilityRecord, "missionName");
std::shared_ptr<MissionList> missionList = std::make_shared<MissionList>();
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<MissionListManager>(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<MissionListManager>(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<MissionListManager>(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<MissionListManager>(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<MissionListManager>(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
@@ -271,6 +271,8 @@ public:
MOCK_METHOD4(StartAbility, int(const Want& want, const sptr<IRemoteObject>& callerToken,
int32_t userId, int requestCode));
MOCK_METHOD4(StartAbilityByInsightIntent, int32_t(const Want& want, const sptr<IRemoteObject>& callerToken,
uint64_t intentId, int32_t userId));
MOCK_METHOD4(StartAbilityAsCaller, int(const Want& want, const sptr<IRemoteObject>& callerToken,
int32_t userId, int requestCode));
MOCK_METHOD2(
@@ -105,6 +105,8 @@ public:
MOCK_METHOD2(GetPendingRequestWant, int(const sptr<IWantSender>& target, std::shared_ptr<Want>& want));
MOCK_METHOD5(StartAbility, int(const Want& want, const AbilityStartSetting& abilityStartSetting,
const sptr<IRemoteObject>& callerToken, int32_t userId, int requestCode));
MOCK_METHOD4(StartAbilityByInsightIntent, int32_t(const Want& want, const sptr<IRemoteObject>& callerToken,
uint64_t intentId, int32_t userId));
MOCK_METHOD4(StartAbilityAsCaller, int(const Want& want, const sptr<IRemoteObject>& callerToken,
int32_t userId, int requestCode));
MOCK_METHOD5(StartAbilityAsCaller, int(const Want &want, const StartOptions &startOptions,
@@ -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<UIAbilityLifecycleManager>();
AbilityRequest abilityRequest;
abilityRequest.abilityInfo.visible = true;
abilityRequest.abilityInfoCallback = new MockAbilityInfoCallbackStub();
Rosen::SessionInfo info;
sptr<SessionInfo> 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
@@ -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",
@@ -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<UriPermissionManagerStubImpl>();
ASSERT_NE(upms, nullptr);
Uri uri("test");
std::string targetBundleName = "bundleName";
uint32_t targetTokenId = 0;
std::vector<std::string> uriVec;
upms->SendEvent(uri, targetBundleName, targetTokenId, uriVec);
}
} // namespace AAFwk
} // namespace OHOS
@@ -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",
@@ -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
@@ -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",
@@ -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
@@ -87,6 +87,8 @@ public:
MOCK_METHOD2(GetPendingRequestWant, int(const sptr<IWantSender>& target, std::shared_ptr<Want>& want));
MOCK_METHOD5(StartAbility, int(const Want& want, const AbilityStartSetting& abilityStartSetting,
const sptr<IRemoteObject>& callerToken, int32_t userId, int requestCode));
MOCK_METHOD4(StartAbilityByInsightIntent, int32_t(const Want& want, const sptr<IRemoteObject>& callerToken,
uint64_t intentId, int32_t userId));
MOCK_METHOD1(GetMissionIdByToken, int32_t(const sptr<IRemoteObject>& token));
MOCK_METHOD1(GetPendinTerminateAbilityTestgRequestWant, void(int id));
MOCK_METHOD3(StartContinuation, int(const Want& want, const sptr<IRemoteObject>& abilityToken, int32_t status));