!19837 merge fixclaw into master

fix 拉起cli分身时弹分身选择框 和启动specified ability流程到SCB时未更新SandboxCloneParams问题

Created-by: lidongrui
Commit-by: DESKTOP-UGVMD4B\DawnComing
Merged-by: openharmony_ci
Description: **IssueNo**:

**Description**:

**稳定性自检:**
| 自检项                                                       | 自检结果  |
| ------------------------------------------------------------ | -------- |
| 涉及跨进程调用的相关操作需要抛至主线程或加锁防止并发              |     √     |
| 成员变量进行赋值或创建需要排查并发                               |    √     |
| 谨慎在lambda表达式中使用引用捕获                                |    √      |
| 谨慎在未经拷贝的情况下使用外部传入的string、C字符串               |    √      |
| map\vector\list\set等stl模板类使用时需要排查并发                |    √      |
| 谨慎考虑加锁范围                                               |    √      |
| 在IPC通信中谨慎使用同步通信方式                                 |    √      |
| 禁止传递this指针至其他模块或线程(特别是eventhandler任务)        |    √      |
| 禁止将外部传入的裸指针在内部直接构造智能指针                      |    √      |
| 禁止多个独立创建的智能指针管理同一地址                           |     √     |
| 禁止在析构函数中抛异步任务                                      |     √     |
| 禁止js对象在非js线程(例如在IPC线程)创建、使用或销毁             |     √     |
| 禁止在对外接口中未经判空直接使用外部传入的指针                    |     √     |
| 禁止接口返回局部变量引用                                        |    √      |
| 禁止在信号函数中加锁                                            |    √      |
| 禁止在关键流程(SA启动、应用启动等主流程)执行耗时的操作           |    √      |
| 禁止将同一个cpp编译在不同的so中                                 |     √     |

**安全编码自检:**
| 自检项                                                          | 自检结果 |
| -------------------------------------------------------------- | -------- |
| 裸指针避免通过隐式转换构造为sptr                                 |     √     |
| json对象在取值之前必须先判断类型,避免类型不匹配                   |    √      |
| 序列化时必须对传入的数组大小进行校验,避免出现超大数组              |     √     |
| 避免使用未明确位宽的整型,选择使用int8_t、uint8_t等类型            |     √     |
| 外部传入的路径要做规范化校验,对路径中的.、..、../等特殊字符严格校验 |     √     |
| 指针变量、表示资源描述符的变量、bool变量必须赋初值                  |    √      |
| readParcelable获取的对象使用前需要判空                            |    √      |
| 分配和释放内存的函数需要成对出现                                   |    √      |
| 申请内存后异常退出前需要及时进行内存释放                            |    √      |
| 内存申请前必须对内存大小进行合法性校验                              |    √      |
| 内存分配后必须判断是否成功                                         |    √      |
| 禁止使用realloc、alloca函数                                       |    √      |
| 禁止打印文件路径、口令等敏感信息,如有需要,使用private修饰          |     √     |
| 禁止打印内存地址                                                  |     √     |
| 整数之间运算时必须严格检查,确保不会出现溢出、反转、除0               |    √      |
| 禁止对有符号整数进行位操作符运算                                    |    √      |
| 禁止对指针进行逻辑或位运算                                         |     √     |
| 循环次数如果收外部数据控制,需要检验其合法性                         |     √     |
| 禁止使用内存操作类危险函数,需要使用安全函数                         |     √     |
| 谨慎使用不可重入函数                                               |     √     |
| 必须检查安全函数的返回值,并进行正确处理                             |     √     |
| 禁止仅通过TokenType类型判断绕过权限校验                             |     √     |

**TDD Result**:

**XTS Result**:

### 是否已执行L0用例
- [ ] 已验证
- [ ] 不涉及。如不涉及,请写明理由


See merge request: openharmony/ability_ability_runtime!19837
This commit is contained in:
openharmony_ci
2026-07-13 21:22:03 +08:00
7 changed files with 112 additions and 21 deletions
@@ -864,6 +864,14 @@ private:
*/
int NotifySCBPendingActivation(sptr<SessionInfo> &sessionInfo,
const AbilityRequest &abilityRequest, std::string &errMsg);
/**
* @brief Store sandbox clone params (isWebSandBoxClone, sandboxCloneIndex, caller info) into
* sessionInfo->want for the SCB callback.
* @param sessionInfo The session info to be updated
* @param abilityRequest The ability request carrying the sandbox clone flag and caller info
*/
void SetSandboxCloneParamsForSession(sptr<SessionInfo> &sessionInfo, const AbilityRequest &abilityRequest);
void CreateSessionConfigurations(std::vector<sptr<SessionInfo>> &sessionInfoList, int primaryWindowId,
std::vector<Rosen::PendingSessionActivationConfig> &configList, sptr<SessionInfo> sessionInfo);
@@ -578,7 +578,7 @@ bool DialogSessionManager::IsCreateCloneSelectorDialog(const std::string &bundle
StartAbilityUtils::isWantWithAppCloneIndex = false;
return false;
#else
if (StartAbilityUtils::isWantWithAppCloneIndex) {
if (StartAbilityUtils::isWantWithAppCloneIndex || StartAbilityUtils::isSandBoxClone) {
TAG_LOGI(AAFwkTag::ABILITYMGR, "no clone index");
StartAbilityUtils::isWantWithAppCloneIndex = false;
return false;
@@ -721,6 +721,27 @@ bool UIAbilityLifecycleManager::AddStartCallerTimestamp(int32_t callerUid)
return true;
}
void UIAbilityLifecycleManager::SetSandboxCloneParamsForSession(sptr<SessionInfo> &sessionInfo,
const AbilityRequest &abilityRequest)
{
if (sessionInfo == nullptr || !abilityRequest.isWebSandBoxClone) {
return;
}
// Store isWebSandBoxClone and appIndex in want for SCB callback.
sessionInfo->want.SetParam(AbilityRuntime::GlobalConstant::IS_WEB_SANDBOX_CLONE,
abilityRequest.isWebSandBoxClone);
sessionInfo->want.SetParam(AbilityRuntime::GlobalConstant::SANDBOX_CLONE_INDEX,
abilityRequest.abilityInfo.applicationInfo.appIndex);
std::string callerBundleName = abilityRequest.want.GetStringParam(
AbilityRuntime::GlobalConstant::CLI_CALLER_BUNDLE_NAME);
std::string callerTokenId = abilityRequest.want.GetStringParam(
AbilityRuntime::GlobalConstant::CLI_CALLER_TOKEN_ID);
sessionInfo->want.SetParam(AbilityRuntime::GlobalConstant::CLI_CALLER_BUNDLE_NAME, callerBundleName);
sessionInfo->want.SetParam(AbilityRuntime::GlobalConstant::CLI_CALLER_TOKEN_ID, callerTokenId);
TAG_LOGD(AAFwkTag::ABILITYMGR, "WebSandBoxClone params: bundle = %{public}s, tokenId = %{public}s",
callerBundleName.c_str(), callerTokenId.c_str());
}
int UIAbilityLifecycleManager::NotifySCBToStartUIAbility(AbilityRequest &abilityRequest)
{
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
@@ -796,20 +817,7 @@ int UIAbilityLifecycleManager::NotifySCBToStartUIAbility(AbilityRequest &ability
sessionInfo->reuse = reuse;
}
// Store isWebSandBoxClone and appIndex in want for SCB callback.
if (abilityRequest.isWebSandBoxClone) {
sessionInfo->want.SetParam(AbilityRuntime::GlobalConstant::IS_WEB_SANDBOX_CLONE,
abilityRequest.isWebSandBoxClone);
sessionInfo->want.SetParam(AbilityRuntime::GlobalConstant::SANDBOX_CLONE_INDEX,
abilityRequest.abilityInfo.applicationInfo.appIndex);
std::string callerBundleName = abilityRequest.want.GetStringParam(
AbilityRuntime::GlobalConstant::CLI_CALLER_BUNDLE_NAME);
std::string callerTokenId = abilityRequest.want.GetStringParam(
AbilityRuntime::GlobalConstant::CLI_CALLER_TOKEN_ID);
sessionInfo->want.SetParam(AbilityRuntime::GlobalConstant::CLI_CALLER_BUNDLE_NAME, callerBundleName);
sessionInfo->want.SetParam(AbilityRuntime::GlobalConstant::CLI_CALLER_TOKEN_ID, callerTokenId);
TAG_LOGD(AAFwkTag::ABILITYMGR, "WebSandBoxClone params: bundle = %{public}s, tokenId = %{public}s",
callerBundleName.c_str(), callerTokenId.c_str());
}
SetSandboxCloneParamsForSession(sessionInfo, abilityRequest);
sessionInfo->userId = userId_;
sessionInfo->isAtomicService = (abilityInfo.applicationInfo.bundleType == AppExecFwk::BundleType::ATOMIC_SERVICE);
TAG_LOGI(AAFwkTag::ABILITYMGR,
@@ -4558,6 +4566,8 @@ void UIAbilityLifecycleManager::StartSpecifiedRequest(SpecifiedRequest &specifie
}
sessionInfo->requestCode = request.requestCode;
sessionInfo->userId = userId_;
// Store isWebSandBoxClone and appIndex in want for SCB callback.
SetSandboxCloneParamsForSession(sessionInfo, request);
TAG_LOGI(AAFwkTag::ABILITYMGR, "StartSpecifiedRequest cold");
std::string errMsg;
auto result = NotifySCBPendingActivation(sessionInfo, request, errMsg);
@@ -9735,7 +9735,7 @@ int32_t AppMgrServiceInner::IsAppRunning(const std::string &bundleName, int32_t
TAG_LOGE(AAFwkTag::APPMGR, "permission verification fail");
return ERR_PERMISSION_DENIED;
}
if (appCloneIndex < 0 || AbilityRuntime::GlobalConstant::IsDlpIndex(appCloneIndex)) {
if (appCloneIndex < 0 || appCloneIndex > AbilityRuntime::GlobalConstant::MAX_APP_CLONE_INDEX) {
TAG_LOGE(AAFwkTag::APPMGR, "appCloneIndex invalid");
return AAFwk::ERR_APP_CLONE_INDEX_INVALID;
}
@@ -9782,7 +9782,7 @@ int32_t AppMgrServiceInner::IsAppRunning(const std::string &bundleName, int32_t
TAG_LOGE(AAFwkTag::APPMGR, "permission verification fail");
return ERR_PERMISSION_DENIED;
}
if (appCloneIndex < 0 || AbilityRuntime::GlobalConstant::IsDlpIndex(appCloneIndex)) {
if (appCloneIndex < 0 || appCloneIndex > AbilityRuntime::GlobalConstant::MAX_APP_CLONE_INDEX) {
TAG_LOGI(AAFwkTag::APPMGR, "appCloneIndex invalid");
appCloneIndex = -1;
}
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2025 Huawei Device Co., Ltd.
* Copyright (c) 2025-2026 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
@@ -32,6 +32,7 @@
#include "process_options.h"
#include "session/host/include/session.h"
#include "session_info.h"
#include "global_constant.h"
#include "startup_util.h"
#define private public
#define protected public
@@ -1221,6 +1222,78 @@ HWTEST_F(UIAbilityLifecycleManagerSecondTest, BackToCallerAbilityWithResultLocke
EXPECT_EQ(ret, ERR_INVALID_VALUE);
}
/**
* @tc.name: UIAbilityLifecycleManager_SetSandboxCloneParamsForSession_0100
* @tc.desc: SetSandboxCloneParamsForSession with null sessionInfo returns early without crash.
* @tc.type: FUNC
*/
HWTEST_F(UIAbilityLifecycleManagerSecondTest, SetSandboxCloneParamsForSession_001, TestSize.Level1)
{
auto mgr = std::make_shared<UIAbilityLifecycleManager>();
sptr<SessionInfo> sessionInfo = nullptr;
AbilityRequest abilityRequest;
abilityRequest.isWebSandBoxClone = true;
mgr->SetSandboxCloneParamsForSession(sessionInfo, abilityRequest);
EXPECT_EQ(sessionInfo, nullptr);
}
/**
* @tc.name: UIAbilityLifecycleManager_SetSandboxCloneParamsForSession_0200
* @tc.desc: SetSandboxCloneParamsForSession with isWebSandBoxClone false sets no params.
* @tc.type: FUNC
*/
HWTEST_F(UIAbilityLifecycleManagerSecondTest, SetSandboxCloneParamsForSession_002, TestSize.Level1)
{
auto mgr = std::make_shared<UIAbilityLifecycleManager>();
sptr<SessionInfo> sessionInfo(new SessionInfo());
ASSERT_NE(sessionInfo, nullptr);
AbilityRequest abilityRequest;
abilityRequest.isWebSandBoxClone = false;
abilityRequest.abilityInfo.applicationInfo.appIndex = 2000;
mgr->SetSandboxCloneParamsForSession(sessionInfo, abilityRequest);
EXPECT_FALSE(sessionInfo->want.GetBoolParam(
AbilityRuntime::GlobalConstant::IS_WEB_SANDBOX_CLONE, false));
EXPECT_EQ(sessionInfo->want.GetIntParam(
AbilityRuntime::GlobalConstant::SANDBOX_CLONE_INDEX, -1), -1);
EXPECT_TRUE(sessionInfo->want.GetStringParam(
AbilityRuntime::GlobalConstant::CLI_CALLER_BUNDLE_NAME).empty());
}
/**
* @tc.name: UIAbilityLifecycleManager_SetSandboxCloneParamsForSession_0300
* @tc.desc: SetSandboxCloneParamsForSession with isWebSandBoxClone true stores all params into sessionInfo->want.
* @tc.type: FUNC
*/
HWTEST_F(UIAbilityLifecycleManagerSecondTest, SetSandboxCloneParamsForSession_003, TestSize.Level1)
{
auto mgr = std::make_shared<UIAbilityLifecycleManager>();
sptr<SessionInfo> sessionInfo(new SessionInfo());
ASSERT_NE(sessionInfo, nullptr);
AbilityRequest abilityRequest;
abilityRequest.isWebSandBoxClone = true;
abilityRequest.abilityInfo.applicationInfo.appIndex = 2000;
const std::string callerBundleName = "com.test.cli.caller";
const std::string callerTokenId = "537919265";
abilityRequest.want.SetParam(AbilityRuntime::GlobalConstant::CLI_CALLER_BUNDLE_NAME, callerBundleName);
abilityRequest.want.SetParam(AbilityRuntime::GlobalConstant::CLI_CALLER_TOKEN_ID, callerTokenId);
mgr->SetSandboxCloneParamsForSession(sessionInfo, abilityRequest);
EXPECT_TRUE(sessionInfo->want.GetBoolParam(
AbilityRuntime::GlobalConstant::IS_WEB_SANDBOX_CLONE, false));
EXPECT_EQ(sessionInfo->want.GetIntParam(
AbilityRuntime::GlobalConstant::SANDBOX_CLONE_INDEX, -1),
abilityRequest.abilityInfo.applicationInfo.appIndex);
EXPECT_EQ(sessionInfo->want.GetStringParam(
AbilityRuntime::GlobalConstant::CLI_CALLER_BUNDLE_NAME), callerBundleName);
EXPECT_EQ(sessionInfo->want.GetStringParam(
AbilityRuntime::GlobalConstant::CLI_CALLER_TOKEN_ID), callerTokenId);
}
/**
* @tc.name: QueryCallerTokenIdForAnco_001
* @tc.desc: Test QueryCallerTokenIdForAnco with empty callerInfoMap_
+1 -1
View File
@@ -184,7 +184,7 @@ private:
void FormatOutputForWithWait(const Want &want, const AbilityStartWithWaitObserverData& data);
bool startAbilityWithWaitFlag_ = false;
bool StartSandboxCloneAbilityFlag_ = false;
bool startSandboxCloneAbilityFlag_ = false;
std::map<int32_t, AaToolErrorInfo> errorInfoMap_;
};
} // namespace AAFwk
+2 -2
View File
@@ -315,7 +315,7 @@ ErrCode ClawAaShellCommand::RunAsStartAbility()
if (result == OHOS::ERR_OK) {
if (startAbilityWithWaitFlag_) {
result = StartAbilityWithWait(want);
} else if (StartSandboxCloneAbilityFlag_) {
} else if (startSandboxCloneAbilityFlag_) {
SandboxCloneParams params;
// Get caller info from environment variables (set by SA-CLI via config["env"])
if (const char* envCallerUid = std::getenv("ohos_cli_callerUid")) {
@@ -953,7 +953,7 @@ ErrCode ClawAaShellCommand::MakeWantFromCmd(Want& want, int32_t& userId)
}
sandBoxCloneIndex = std::stoi(sandBoxCloneIndexStr);
hasSandBoxCloneIndex = true;
StartSandboxCloneAbilityFlag_ = true;
startSandboxCloneAbilityFlag_ = true;
TAG_LOGI(AAFwkTag::AA_TOOL, "sandBoxCloneIndex = %{public}d, Flag_ set to true", sandBoxCloneIndex);
}
break;