!17698 merge master into master

addtdd

Created-by: zyr020212
Commit-by: zyr020212
Merged-by: openharmony_ci
Description: **IssueNo**:
https://gitcode.com/openharmony/ability_ability_runtime/issues/13836?ref=&did=3580974#tid-3580974
**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**:
![image.png](https://raw.gitcode.com/user-images/assets/4421702/eced3ee5-f026-4131-8e55-d6cc78124af6/image.png 'image.png')
![image.png](https://raw.gitcode.com/user-images/assets/4421702/ba11bfcf-b74f-412a-8f80-9323372e48fb/image.png 'image.png')
**XTS Result**:

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


See merge request: openharmony/ability_ability_runtime!17698
This commit is contained in:
openharmony_ci
2025-12-12 18:41:12 +08:00
4 changed files with 130 additions and 2 deletions
@@ -91,6 +91,10 @@ public:
MOCK_METHOD3(CheckPreloadAppRecordExist, bool(const std::string&, int32_t, int32_t));
MOCK_CONST_METHOD0(IsFoundationCall, bool());
MOCK_METHOD2(QueryRunningSharedBundles, int32_t(pid_t pid, std::map<std::string, uint32_t> &sharedBundles));
MOCK_METHOD2(NotifyPageShow, int32_t(const sptr<IRemoteObject> &token, const PageStateData &pageStateData));
MOCK_METHOD1(RegisterRenderStateObserver, int32_t(const sptr<IRenderStateObserver> &observer));
MOCK_METHOD2(RegisterApplicationStateObserver, int32_t(const sptr<IApplicationStateObserver> &observer,
const std::vector<std::string> &bundleNameList));
void StartSpecifiedAbility(const AAFwk::Want&, const AppExecFwk::AbilityInfo&, int32_t, const std::string&)
{}
@@ -327,9 +327,10 @@ HWTEST_F(AmsMgrSchedulerTest, RegisterApplicationStateObserver_001, TestSize.Lev
{
TAG_LOGD(AAFwkTag::TEST, "RegisterApplicationStateObserver_001 start");
sptr<IApplicationStateObserver> observer = new ApplicationStateObserverStub();
std::vector<std::string> bundleNameList;
auto mockAppMgrServiceInner = std::make_shared<MockAppMgrServiceInner>();
mockAppMgrServiceInner->RegisterApplicationStateObserver(observer);
int32_t err = mockAppMgrServiceInner->RegisterApplicationStateObserver(observer);
mockAppMgrServiceInner->RegisterApplicationStateObserver(observer, bundleNameList);
int32_t err = mockAppMgrServiceInner->RegisterApplicationStateObserver(observer, bundleNameList);
// repeat register return ERR_INVALID_VALUE
EXPECT_EQ(1, err);
TAG_LOGD(AAFwkTag::TEST, "RegisterApplicationStateObserver_001 end");
@@ -80,6 +80,22 @@ HWTEST_F(AppMgrServiceSecondTest, NotifyPageHide_0100, TestSize.Level1)
EXPECT_NE(ret, ERR_OK);
}
/**
* @tc.name: NotifyPageShow_0100
* @tc.desc: NotifyPageShow.
* @tc.type: FUNC
*/
HWTEST_F(AppMgrServiceSecondTest, NotifyPageShow_0100, TestSize.Level1)
{
auto appMgrService = std::make_shared<AppMgrService>();
ASSERT_NE(appMgrService, nullptr);
sptr<OHOS::IRemoteObject> token = nullptr;
PageStateData pageStateData;
appMgrService->SetInnerService(nullptr);
int32_t res = appMgrService->NotifyPageShow(token, pageStateData);
EXPECT_EQ(res, ERR_INVALID_OPERATION);
}
/**
* @tc.name: RegisterAppRunningStatusListener_0100
* @tc.desc: RegisterAppRunningStatusListener.
@@ -296,6 +296,23 @@ HWTEST_F(AppMgrServiceTest, ClearUpApplicationData_001, TestSize.Level1)
EXPECT_EQ(res, ERR_INVALID_OPERATION);
}
/*
* Feature: AppMgrService
* Function: ClearUpApplicationDataBySelf
* SubFunction: NA
* FunctionPoints: AppMgrService ClearUpApplicationDataBySelf
* EnvConditions: NA
* CaseDescription: Verify ClearUpApplicationDataBySelf
*/
HWTEST_F(AppMgrServiceTest, ClearUpApplicationDataBySelf_0100, TestSize.Level1)
{
auto appMgrService = std::make_shared<AppMgrService>();
ASSERT_NE(appMgrService, nullptr);
appMgrService->SetInnerService(nullptr);
int32_t res = appMgrService->ClearUpApplicationDataBySelf(0);
EXPECT_EQ(res, ERR_INVALID_OPERATION);
}
/*
* Feature: AppMgrService
* Function: GetAllRunningProcesses
@@ -1388,6 +1405,46 @@ HWTEST_F(AppMgrServiceTest, ChangeAppGcState_002, TestSize.Level1)
appMgrService->appMgrServiceInner_ = nullptr;
}
/**
* @tc.name: NotifyPageShow_001
* @tc.desc: Test NotifyPageShow when inpit is nullptr.
* @tc.type: FUNC
*/
HWTEST_F(AppMgrServiceTest, NotifyPageShow_001, TestSize.Level1)
{
auto appMgrService = std::make_shared<AppMgrService>();
ASSERT_NE(appMgrService, nullptr);
sptr<OHOS::IRemoteObject> token = nullptr;
PageStateData pageStateData;
appMgrService->SetInnerService(nullptr);
int32_t res = appMgrService->NotifyPageShow(token, pageStateData);
EXPECT_EQ(res, ERR_INVALID_OPERATION);
}
/**
* @tc.name: NotifyPageShow_002
* @tc.desc: verify NotifyPageShow works.
* @tc.type: FUNC
*/
HWTEST_F(AppMgrServiceTest, NotifyPageShow_002, TestSize.Level1)
{
auto appMgrService = std::make_shared<AppMgrService>();
ASSERT_NE(appMgrService, nullptr);
appMgrService->SetInnerService(mockAppMgrServiceInner_);
appMgrService->taskHandler_ = taskHandler_;
appMgrService->eventHandler_ = eventHandler_;
sptr<OHOS::IRemoteObject> token = nullptr;
PageStateData pageStateData;
EXPECT_CALL(*mockAppMgrServiceInner_, NotifyPageShow(_, _))
.Times(1)
.WillOnce(Return(ERR_OK));
int32_t res = appMgrService->NotifyPageShow(token, pageStateData);
EXPECT_EQ(res, ERR_OK);
}
/**
* @tc.name: IsAppRunning_001
* @tc.desc: Determine that the application is running by returning a value.
@@ -1411,6 +1468,23 @@ HWTEST_F(AppMgrServiceTest, IsAppRunning_001, TestSize.Level1)
EXPECT_EQ(res, AAFwk::ERR_APP_CLONE_INDEX_INVALID);
}
/**
* @tc.name: IsAppRunning_002
* @tc.desc: verify IsAppRunning calls works.
* @tc.type: FUNC
*/
HWTEST_F(AppMgrServiceTest, IsAppRunning_002, TestSize.Level1)
{
auto appMgrService = std::make_shared<AppMgrService>();
ASSERT_NE(appMgrService, nullptr);
std::string bundleName = "test_bundleName";
int32_t appCloneIndex = 0;
bool isRunning = false;
appMgrService->SetInnerService(nullptr);
int32_t res = appMgrService->IsAppRunning(bundleName, appCloneIndex, isRunning);
EXPECT_EQ(res, ERR_INVALID_OPERATION);
}
#ifdef SUPPORT_CHILD_PROCESS
/**
* @tc.name: StartChildProcess_001
@@ -1581,6 +1655,20 @@ HWTEST_F(AppMgrServiceTest, UnregisterAppForegroundStateObserver_001, TestSize.L
EXPECT_EQ(ERR_INVALID_OPERATION, res);
}
/**
* @tc.name: IsFinalAppProcess_001
* @tc.desc: Test IsFinalAppProcess when inpit is nullptr.
* @tc.type: FUNC
*/
HWTEST_F(AppMgrServiceTest, IsFinalAppProcess_001, TestSize.Level1)
{
auto appMgrService = std::make_shared<AppMgrService>();
ASSERT_NE(appMgrService, nullptr);
appMgrService->SetInnerService(nullptr);
bool res = appMgrService->IsFinalAppProcess();
EXPECT_EQ(res, false);
}
/**
* @tc.name: RegisterRenderStateObserver_0100
* @tc.desc: Test registerRenderStateObserver when inpit is nullptr.
@@ -2385,6 +2473,25 @@ HWTEST_F(AppMgrServiceTest, QueryRunningSharedBundles_003, TestSize.Level1)
TAG_LOGI(AAFwkTag::TEST, "QueryRunningSharedBundles_003 end.");
}
/**
* @tc.name: RegisterApplicationStateObserverWithFilter
* @tc.desc: verify RegisterApplicationStateObserverWithFilter works.
* @tc.type: FUNC
*/
HWTEST_F(AppMgrServiceTest, RegisterApplicationStateObserverWithFilter_001, TestSize.Level1)
{
auto appMgrService = std::make_shared<AppMgrService>();
ASSERT_NE(appMgrService, nullptr);
sptr<IApplicationStateObserver> observer = nullptr;
std::vector<std::string> bundleNameList;
AppStateFilter appStateFilter;
bool isUsingFilter = false;
appMgrService->SetInnerService(nullptr);
auto res = appMgrService->RegisterApplicationStateObserverWithFilter(observer, bundleNameList,
appStateFilter, isUsingFilter);
EXPECT_EQ(ERR_INVALID_OPERATION, res);
}
/*
* Feature: AppMgrService
* Function: GetConfiguration