!18440 merge onMemoryLevel-2 into master

onMemoryLevel机制优化-2-PR"

Created-by: SKY2001
Commit-by: SKY2001
Merged-by: openharmony_ci
Description: **IssueNo**:
https://gitcode.com/openharmony/ability_ability_runtime/issues/14555?ref=&did=3773484#tid-3773484
**Description**:

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

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

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


See merge request: openharmony/ability_ability_runtime!18440
This commit is contained in:
openharmony_ci
2026-02-27 20:02:28 +08:00
39 changed files with 131 additions and 51 deletions
@@ -77,7 +77,11 @@ namespace AbilityConstant {
export enum MemoryLevel {
MEMORY_LEVEL_MODERATE = 0,
MEMORY_LEVEL_LOW = 1,
MEMORY_LEVEL_CRITICAL = 2
MEMORY_LEVEL_CRITICAL = 2,
MEMORY_LEVEL_UI_HIDDEN = 3,
MEMORY_LEVEL_BACKGROUND_MODERATE = 4,
MEMORY_LEVEL_BACKGROUND_LOW = 5,
MEMORY_LEVEL_BACKGROUND_CRITICAL = 6
}
export enum WindowMode {
@@ -29,6 +29,10 @@ enum class MemoryLevel {
MEMORY_LEVEL_MODERATE = 0,
MEMORY_LEVEL_LOW = 1,
MEMORY_LEVEL_CRITICAL = 2,
MEMORY_LEVEL_UI_HIDDEN = 3,
MEMORY_LEVEL_BACKGROUND_MODERATE = 4,
MEMORY_LEVEL_BACKGROUND_LOW = 5,
MEMORY_LEVEL_BACKGROUND_CRITICAL = 6,
};
enum CollaborateResult {
@@ -194,6 +198,14 @@ static napi_value InitMemoryLevelObject(napi_env env)
static_cast<int>(MemoryLevel::MEMORY_LEVEL_LOW)));
NAPI_CALL(env, SetEnumItem(env, object, "MEMORY_LEVEL_CRITICAL",
static_cast<int>(MemoryLevel::MEMORY_LEVEL_CRITICAL)));
NAPI_CALL(env, SetEnumItem(env, object, "MEMORY_LEVEL_UI_HIDDEN",
static_cast<int>(MemoryLevel::MEMORY_LEVEL_UI_HIDDEN)));
NAPI_CALL(env, SetEnumItem(env, object, "MEMORY_LEVEL_BACKGROUND_MODERATE",
static_cast<int>(MemoryLevel::MEMORY_LEVEL_BACKGROUND_MODERATE)));
NAPI_CALL(env, SetEnumItem(env, object, "MEMORY_LEVEL_BACKGROUND_LOW",
static_cast<int>(MemoryLevel::MEMORY_LEVEL_BACKGROUND_LOW)));
NAPI_CALL(env, SetEnumItem(env, object, "MEMORY_LEVEL_BACKGROUND_CRITICAL",
static_cast<int>(MemoryLevel::MEMORY_LEVEL_BACKGROUND_CRITICAL)));
return handleEscape.Escape(object);
}
+1 -1
View File
@@ -600,7 +600,7 @@ void MainThread::ScheduleShrinkMemory(const int level)
*
* @param level Indicates the memory trim level, which shows the current memory usage status.
*/
void MainThread::ScheduleMemoryLevel(const int level)
void MainThread::ScheduleMemoryLevel(const int level, bool isShellCall)
{
TAG_LOGD(AAFwkTag::APPKIT, "level: %{public}d", level);
wptr<MainThread> weak = this;
@@ -26,6 +26,10 @@ enum class MemoryLevel {
MEMORY_LEVEL_MODERATE = 0,
MEMORY_LEVEL_LOW = 1,
MEMORY_LEVEL_CRITICAL = 2,
MEMORY_LEVEL_UI_HIDDEN = 3,
MEMORY_LEVEL_BACKGROUND_MODERATE = 4,
MEMORY_LEVEL_BACKGROUND_LOW = 5,
MEMORY_LEVEL_BACKGROUND_CRITICAL = 6,
};
static napi_status SetEnumItem(napi_env env, napi_value object, const char* name, int32_t value)
@@ -139,6 +143,14 @@ static napi_value InitMemoryLevelObject(napi_env env)
static_cast<int>(MemoryLevel::MEMORY_LEVEL_LOW)));
NAPI_CALL(env, SetEnumItem(env, object, "MEMORY_LEVEL_CRITICAL",
static_cast<int>(MemoryLevel::MEMORY_LEVEL_CRITICAL)));
NAPI_CALL(env, SetEnumItem(env, object, "MEMORY_LEVEL_UI_HIDDEN",
static_cast<int>(MemoryLevel::MEMORY_LEVEL_UI_HIDDEN)));
NAPI_CALL(env, SetEnumItem(env, object, "MEMORY_LEVEL_BACKGROUND_MODERATE",
static_cast<int>(MemoryLevel::MEMORY_LEVEL_BACKGROUND_MODERATE)));
NAPI_CALL(env, SetEnumItem(env, object, "MEMORY_LEVEL_BACKGROUND_LOW",
static_cast<int>(MemoryLevel::MEMORY_LEVEL_BACKGROUND_LOW)));
NAPI_CALL(env, SetEnumItem(env, object, "MEMORY_LEVEL_BACKGROUND_CRITICAL",
static_cast<int>(MemoryLevel::MEMORY_LEVEL_BACKGROUND_CRITICAL)));
return object;
}
@@ -22,6 +22,10 @@ enum MemoryLevel {
MEMORY_LEVEL_MODERATE = 0,
MEMORY_LEVEL_LOW = 1,
MEMORY_LEVEL_CRITICAL = 2,
MEMORY_LEVEL_UI_HIDDEN = 3,
MEMORY_LEVEL_BACKGROUND_MODERATE = 4,
MEMORY_LEVEL_BACKGROUND_LOW = 5,
MEMORY_LEVEL_BACKGROUND_CRITICAL = 6
};
enum MemoryState : int {
@@ -82,7 +82,7 @@ public:
*
* @return
*/
virtual void ScheduleMemoryLevel(int32_t level) = 0;
virtual void ScheduleMemoryLevel(int32_t level, bool isShellCall = false) = 0;
/**
* ScheduleHeapMemory, call ScheduleHeapMemory() through proxy project,
@@ -77,7 +77,7 @@ public:
*
* @return
*/
virtual void ScheduleMemoryLevel(int32_t level) override;
virtual void ScheduleMemoryLevel(int32_t level, bool isShellCall = false) override;
/**
* ScheduleHeapMemory, call ScheduleHeapMemory() through proxy project,
@@ -333,7 +333,7 @@ public:
private:
bool WriteInterfaceToken(MessageParcel &data);
void ScheduleMemoryCommon(const int32_t level, const uint32_t operation);
void ScheduleMemoryCommon(const int32_t level, const uint32_t operation, bool isShellCall = false);
int32_t SendTransactCmd(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option);
static inline BrokerDelegator<AppSchedulerProxy> delegator_;
};
@@ -117,10 +117,10 @@ void AppSchedulerProxy::ScheduleLowMemory()
}
}
void AppSchedulerProxy::ScheduleMemoryLevel(int32_t level)
void AppSchedulerProxy::ScheduleMemoryLevel(int32_t level, bool isShellCall)
{
uint32_t operation = static_cast<uint32_t>(IAppScheduler::Message::SCHEDULE_MEMORYLEVEL_APPLICATION_TRANSACTION);
ScheduleMemoryCommon(level, operation);
ScheduleMemoryCommon(level, operation, isShellCall);
}
void AppSchedulerProxy::ScheduleHeapMemory(const int32_t pid, OHOS::AppExecFwk::MallocInfo &mallocInfo)
@@ -202,11 +202,15 @@ void AppSchedulerProxy::ScheduleShrinkMemory(const int32_t level)
ScheduleMemoryCommon(level, operation);
}
void AppSchedulerProxy::ScheduleMemoryCommon(const int32_t level, const uint32_t operation)
void AppSchedulerProxy::ScheduleMemoryCommon(const int32_t level, const uint32_t operation, bool isShellCall)
{
MessageParcel data;
MessageParcel reply;
MessageOption option(MessageOption::TF_ASYNC);
if (!isShellCall) {
option.SetFlags(MessageOption::TF_ASYNC_WAKEUP_LATER);
}
TAG_LOGD(AAFwkTag::APPMGR, "option: %{public}d", option.GetFlags());
if (!WriteInterfaceToken(data)) {
return;
}
@@ -76,6 +76,10 @@ bool MemoryLevelInfo::ReadFromParcel(Parcel &parcel)
case MEMORY_LEVEL_MODERATE:
case MEMORY_LEVEL_LOW:
case MEMORY_LEVEL_CRITICAL:
case MEMORY_LEVEL_UI_HIDDEN:
case MEMORY_LEVEL_BACKGROUND_MODERATE:
case MEMORY_LEVEL_BACKGROUND_LOW:
case MEMORY_LEVEL_BACKGROUND_CRITICAL:
level = static_cast<MemoryLevel>(tempLevel);
break;
default:
@@ -203,7 +203,7 @@ public:
*
* @param level Indicates the memory trim level, which shows the current memory usage status.
*/
void ScheduleMemoryLevel(const int level) override;
void ScheduleMemoryLevel(const int level, bool isShellCall = false) override;
/**
*
+3 -2
View File
@@ -111,11 +111,12 @@ public:
* ScheduleMemoryLevel, call ScheduleMemoryLevel() through proxy project,
* Notifies the application of the current memory.
*
* @param The memory level.
* @param Level, The memory level.
* @param isShellCall, A flag indicating whether it is invoked via the aa command.
*
* @return
*/
void ScheduleMemoryLevel(int32_t Level);
void ScheduleMemoryLevel(int32_t Level, bool isShellCall = false);
/**
* ScheduleHeapMemory, call ScheduleHeapMemory() through proxy project,
@@ -275,7 +275,7 @@ public:
* @param procLevelMap , <pid_t, MemoryLevel>.
* @return Returns ERR_OK on success, others on failure.
*/
int32_t NotifyProcMemoryLevel(const std::map<pid_t, MemoryLevel> &procLevelMap);
int32_t NotifyProcMemoryLevel(const std::map<pid_t, MemoryLevel> &procLevelMap, bool isShellCall = false);
/*
* Get the application's memory allocation info.
+1 -1
View File
@@ -445,7 +445,7 @@ public:
*
* @return
*/
void ScheduleMemoryLevel(int32_t level);
void ScheduleMemoryLevel(int32_t level, bool isShellCall = false);
/**
* ScheduleHeapMemory, Get the application's memory allocation info.
+2 -2
View File
@@ -161,7 +161,7 @@ void AppLifeCycleDeal::ScheduleTrimMemory(int32_t timeLevel)
appThread->ScheduleShrinkMemory(timeLevel);
}
void AppLifeCycleDeal::ScheduleMemoryLevel(int32_t Level)
void AppLifeCycleDeal::ScheduleMemoryLevel(int32_t Level, bool isShellCall)
{
auto appThread = GetApplicationClient();
if (!appThread) {
@@ -169,7 +169,7 @@ void AppLifeCycleDeal::ScheduleMemoryLevel(int32_t Level)
return;
}
appThread->ScheduleMemoryLevel(Level);
appThread->ScheduleMemoryLevel(Level, isShellCall);
}
void AppLifeCycleDeal::ScheduleHeapMemory(const int32_t pid, OHOS::AppExecFwk::MallocInfo &mallocInfo)
@@ -3080,9 +3080,8 @@ int32_t AppMgrServiceInner::NotifyMemoryLevel(int32_t level)
TAG_LOGE(AAFwkTag::APPMGR, "callerToken not %{public}s", MEMMGR_PROC_NAME);
return ERR_INVALID_VALUE;
}
if (!(level == OHOS::AppExecFwk::MemoryLevel::MEMORY_LEVEL_MODERATE ||
level == OHOS::AppExecFwk::MemoryLevel::MEMORY_LEVEL_CRITICAL ||
level == OHOS::AppExecFwk::MemoryLevel::MEMORY_LEVEL_LOW)) {
if (!(level >= OHOS::AppExecFwk::MemoryLevel::MEMORY_LEVEL_MODERATE &&
level <= OHOS::AppExecFwk::MemoryLevel::MEMORY_LEVEL_BACKGROUND_CRITICAL)) {
TAG_LOGE(AAFwkTag::APPMGR, "level value error");
return ERR_INVALID_VALUE;
}
@@ -3111,8 +3110,8 @@ int32_t AppMgrServiceInner::NotifyProcMemoryLevel(const std::map<pid_t, MemoryLe
TAG_LOGE(AAFwkTag::APPMGR, "appRunningManager null");
return ERR_INVALID_VALUE;
}
return appRunningManager_->NotifyProcMemoryLevel(procLevelMap);
TAG_LOGD(AAFwkTag::APPMGR, "isShellCall %{public}d", isShellCall);
return appRunningManager_->NotifyProcMemoryLevel(procLevelMap, isShellCall);
}
int32_t AppMgrServiceInner::DumpHeapMemory(const int32_t pid, OHOS::AppExecFwk::MallocInfo &mallocInfo)
+2 -2
View File
@@ -1345,7 +1345,7 @@ int32_t AppRunningManager::NotifyMemoryLevel(int32_t level)
return ERR_OK;
}
int32_t AppRunningManager::NotifyProcMemoryLevel(const std::map<pid_t, MemoryLevel> &procLevelMap)
int32_t AppRunningManager::NotifyProcMemoryLevel(const std::map<pid_t, MemoryLevel> &procLevelMap, bool isShellCall)
{
auto appRunningMap = GetAppRunningRecordMap();
for (const auto &item : appRunningMap) {
@@ -1365,7 +1365,7 @@ int32_t AppRunningManager::NotifyProcMemoryLevel(const std::map<pid_t, MemoryLev
TAG_LOGW(AAFwkTag::APPMGR, "pid%{public}d not found", pid);
} else {
TAG_LOGD(AAFwkTag::APPMGR, "pid%{public}d memory level = %{public}d", pid, it->second);
appRecord->ScheduleMemoryLevel(it->second);
appRecord->ScheduleMemoryLevel(it->second, isShellCall);
}
}
return ERR_OK;
+2 -2
View File
@@ -638,10 +638,10 @@ void AppRunningRecord::ScheduleTrimMemory()
}
}
void AppRunningRecord::ScheduleMemoryLevel(int32_t level)
void AppRunningRecord::ScheduleMemoryLevel(int32_t level, bool isShellCall)
{
if (appLifeCycleDeal_) {
appLifeCycleDeal_->ScheduleMemoryLevel(level);
appLifeCycleDeal_->ScheduleMemoryLevel(level, isShellCall);
}
}
@@ -43,7 +43,7 @@ public:
MOCK_METHOD0(ScheduleProcessSecurityExit, void());
MOCK_METHOD1(ScheduleAbilityStage, void(const HapModuleInfo&));
MOCK_METHOD2(ScheduleUpdateApplicationInfoInstalled, void(const ApplicationInfo&, const std::string&));
MOCK_METHOD1(ScheduleMemoryLevel, void(int32_t level));
MOCK_METHOD2(ScheduleMemoryLevel, void(int32_t level, bool isShellCall));
MOCK_METHOD2(ScheduleHeapMemory, void(const int32_t pid, OHOS::AppExecFwk::MallocInfo &mallocInfo));
MOCK_METHOD2(ScheduleAcceptWant, void(const AAFwk::Want& want, const std::string& moduleName));
MOCK_METHOD1(SchedulePrepareTerminate, void(const std::string &moduleName));
@@ -43,7 +43,7 @@ public:
MOCK_METHOD0(ScheduleProcessSecurityExit, void());
MOCK_METHOD1(ScheduleAbilityStage, void(const HapModuleInfo&));
MOCK_METHOD2(ScheduleUpdateApplicationInfoInstalled, void(const ApplicationInfo&, const std::string&));
MOCK_METHOD1(ScheduleMemoryLevel, void(int32_t level));
MOCK_METHOD2(ScheduleMemoryLevel, void(int32_t level, bool isShellCall));
MOCK_METHOD2(ScheduleHeapMemory, void(const int32_t pid, OHOS::AppExecFwk::MallocInfo &mallocInfo));
MOCK_METHOD2(ScheduleAcceptWant, void(const AAFwk::Want& want, const std::string& moduleName));
MOCK_METHOD1(SchedulePrepareTerminate, void(const std::string &moduleName));
@@ -29,7 +29,7 @@ public:
MOCK_METHOD1(ScheduleTerminateApplication, void(bool));
MOCK_METHOD1(ScheduleShrinkMemory, void(const int));
MOCK_METHOD0(ScheduleLowMemory, void());
MOCK_METHOD1(ScheduleMemoryLevel, void(int32_t level));
MOCK_METHOD2(ScheduleMemoryLevel, void(int32_t level, bool isShellCall));
MOCK_METHOD2(ScheduleHeapMemory, void(const int32_t pid, OHOS::AppExecFwk::MallocInfo &mallocInfo));
MOCK_METHOD2(ScheduleLaunchApplication, void(const AppLaunchData&, const Configuration& config));
MOCK_METHOD4(ScheduleLaunchAbility, void(const AbilityInfo&, const sptr<IRemoteObject>&,
@@ -30,7 +30,7 @@ public:
MOCK_METHOD1(ScheduleTerminateApplication, void(bool));
MOCK_METHOD1(ScheduleShrinkMemory, void(const int));
MOCK_METHOD0(ScheduleLowMemory, void());
MOCK_METHOD1(ScheduleMemoryLevel, void(int32_t level));
MOCK_METHOD2(ScheduleMemoryLevel, void(int32_t level, bool isShellCall));
MOCK_METHOD2(ScheduleHeapMemory, void(const int32_t pid, OHOS::AppExecFwk::MallocInfo &mallocInfo));
MOCK_METHOD2(ScheduleLaunchApplication, void(const AppLaunchData&, const Configuration& config));
MOCK_METHOD4(ScheduleLaunchAbility, void(const AbilityInfo&, const sptr<IRemoteObject>&,
@@ -92,7 +92,7 @@ public:
{
scheduled_ |= LOW_MEMORY_SCHEDULED;
}
void ScheduleMemoryLevel(const int) override
void ScheduleMemoryLevel(const int, bool) override
{
scheduled_ |= MEMORY_LEVEL_SCHEDULED;
}
@@ -53,7 +53,7 @@ public:
{}
void ScheduleLowMemory() override
{}
void ScheduleMemoryLevel(const int) override
void ScheduleMemoryLevel(const int, bool) override
{}
void ScheduleHeapMemory(const int, OHOS::AppExecFwk::MallocInfo&) override
{}
@@ -41,7 +41,7 @@ public:
MOCK_METHOD1(ScheduleProfileChanged, void(const AppExecFwk::Profile&));
MOCK_METHOD1(ScheduleConfigurationUpdated, void(const AppExecFwk::Configuration& config));
MOCK_METHOD1(ScheduleShrinkMemory, void(const int));
MOCK_METHOD1(ScheduleMemoryLevel, void(int32_t level));
MOCK_METHOD2(ScheduleMemoryLevel, void(int32_t level, bool isShellCall));
MOCK_METHOD2(ScheduleHeapMemory, void(const int32_t pid, OHOS::AppExecFwk::MallocInfo &mallocInfo));
MOCK_METHOD0(ScheduleLowMemory, void());
MOCK_METHOD1(ScheduleNotifyAppFault, int32_t(const FaultData &));
@@ -657,7 +657,7 @@ HWTEST_F(AmsAppRunningRecordTest, ScheduleProcessSecurityExit_001, TestSize.Leve
HWTEST_F(AmsAppRunningRecordTest, ScheduleMemoryLevel_001, TestSize.Level1)
{
auto record = GetTestAppRunningRecord();
EXPECT_CALL(*mockAppSchedulerClient_, ScheduleMemoryLevel(_)).Times(1);
EXPECT_CALL(*mockAppSchedulerClient_, ScheduleMemoryLevel(_, _)).Times(1);
record->ScheduleMemoryLevel(1);
record->appLifeCycleDeal_ = nullptr;
@@ -254,7 +254,7 @@ void AppRunningRecord::ScheduleTrimMemory()
{
}
void AppRunningRecord::ScheduleMemoryLevel(int32_t level)
void AppRunningRecord::ScheduleMemoryLevel(int32_t level, bool isShellCall)
{
}
@@ -271,7 +271,7 @@ int32_t AppRunningManager::NotifyMemoryLevel(int32_t level)
return ERR_OK;
}
int32_t AppRunningManager::NotifyProcMemoryLevel(const std::map<pid_t, MemoryLevel> &procLevelMap)
int32_t AppRunningManager::NotifyProcMemoryLevel(const std::map<pid_t, MemoryLevel> &procLevelMap, bool isShellCall)
{
AAFwk::MyStatus::GetInstance().notifyProcMemoryCall_++;
return AAFwk::MyStatus::GetInstance().notifyProcMemory_;
@@ -263,7 +263,7 @@ void AppRunningRecord::ScheduleTrimMemory()
{
}
void AppRunningRecord::ScheduleMemoryLevel(int32_t level)
void AppRunningRecord::ScheduleMemoryLevel(int32_t level, bool isShellCall)
{
}
@@ -43,7 +43,7 @@ public:
MOCK_METHOD0(ScheduleProcessSecurityExit, void());
MOCK_METHOD1(ScheduleAbilityStage, void(const HapModuleInfo&));
MOCK_METHOD2(ScheduleUpdateApplicationInfoInstalled, void(const ApplicationInfo&, const std::string&));
MOCK_METHOD1(ScheduleMemoryLevel, void(int32_t level));
MOCK_METHOD2(ScheduleMemoryLevel, void(int32_t level, bool isShellCall));
MOCK_METHOD2(ScheduleHeapMemory, void(const int32_t pid, OHOS::AppExecFwk::MallocInfo &mallocInfo));
MOCK_METHOD2(ScheduleAcceptWant, void(const AAFwk::Want& want, const std::string& moduleName));
MOCK_METHOD1(SchedulePrepareTerminate, void(const std::string &moduleName));
@@ -280,7 +280,7 @@ int32_t AppRunningManager::NotifyMemoryLevel(int32_t level)
return ERR_OK;
}
int32_t AppRunningManager::NotifyProcMemoryLevel(const std::map<pid_t, MemoryLevel> &procLevelMap)
int32_t AppRunningManager::NotifyProcMemoryLevel(const std::map<pid_t, MemoryLevel> &procLevelMap, bool isShellCall)
{
AAFwk::MyStatus::GetInstance().notifyProcMemoryCall_++;
return AAFwk::MyStatus::GetInstance().notifyProcMemory_;
@@ -281,7 +281,7 @@ void AppRunningRecord::ScheduleTrimMemory()
{
}
void AppRunningRecord::ScheduleMemoryLevel(int32_t level)
void AppRunningRecord::ScheduleMemoryLevel(int32_t level, bool isShellCall)
{
}
@@ -599,7 +599,7 @@ HWTEST_F(AppMgrServiceInnerSecondTest, AppMgrServiceInnerSecondTest_NotifyMemory
TAG_LOGI(AAFwkTag::TEST, "AppMgrServiceInnerSecondTest_NotifyMemoryLevel_0100 start");
MyFlag::flag_ = MyFlag::IS_SA_CALL;
auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
auto ret = appMgrServiceInner->NotifyMemoryLevel(4); // 4 means invalid level
auto ret = appMgrServiceInner->NotifyMemoryLevel(-1); // -1 means invalid level
EXPECT_EQ(ret, ERR_INVALID_VALUE);
TAG_LOGI(AAFwkTag::TEST, "AppMgrServiceInnerSecondTest_NotifyMemoryLevel_0200 end");
}
@@ -623,6 +623,46 @@ HWTEST_F(AppMgrServiceInnerSecondTest, AppMgrServiceInnerSecondTest_NotifyMemory
TAG_LOGI(AAFwkTag::TEST, "AppMgrServiceInnerSecondTest_NotifyMemoryLevel_0300 end");
}
/**
* @tc.name: AppMgrServiceInnerSecondTest_NotifyMemoryLevel_0400
* @tc.desc: Test NotifyMemoryLevel
* @tc.type: FUNC
*/
HWTEST_F(AppMgrServiceInnerSecondTest, AppMgrServiceInnerSecondTest_NotifyMemoryLevel_0400, TestSize.Level1)
{
TAG_LOGI(AAFwkTag::TEST, "AppMgrServiceInnerSecondTest_NotifyMemoryLevel_0400 start");
MyFlag::flag_ = MyFlag::IS_SA_CALL;
auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
auto ret = appMgrServiceInner->NotifyMemoryLevel(3);
EXPECT_EQ(ret, ERR_OK);
ret = appMgrServiceInner->NotifyMemoryLevel(4);
EXPECT_EQ(ret, ERR_OK);
ret = appMgrServiceInner->NotifyMemoryLevel(5);
EXPECT_EQ(ret, ERR_OK);
ret = appMgrServiceInner->NotifyMemoryLevel(6);
EXPECT_EQ(ret, ERR_OK);
TAG_LOGI(AAFwkTag::TEST, "AppMgrServiceInnerSecondTest_NotifyMemoryLevel_0400 end");
}
/**
* @tc.name: AppMgrServiceInnerSecondTest_NotifyMemoryLevel_0500
* @tc.desc: Test NotifyMemoryLevel
* @tc.type: FUNC
*/
HWTEST_F(AppMgrServiceInnerSecondTest, AppMgrServiceInnerSecondTest_NotifyMemoryLevel_0500, TestSize.Level1)
{
TAG_LOGI(AAFwkTag::TEST, "AppMgrServiceInnerSecondTest_NotifyMemoryLevel_0500 start");
MyFlag::flag_ = MyFlag::IS_SA_CALL;
auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
auto ret = appMgrServiceInner->NotifyMemoryLevel(7); // 7 means invalid level
EXPECT_EQ(ret, ERR_INVALID_VALUE);
appMgrServiceInner->appRunningManager_ = nullptr;
ret = appMgrServiceInner->NotifyMemoryLevel(3);
EXPECT_EQ(ret, ERR_INVALID_VALUE);
TAG_LOGI(AAFwkTag::TEST, "AppMgrServiceInnerSecondTest_NotifyMemoryLevel_0500 end");
}
/**
* @tc.name: AppMgrServiceInnerSecondTest_NotifyAppFault_0100
* @tc.desc: Test NotifyAppFault
@@ -271,7 +271,7 @@ int32_t AppRunningManager::NotifyMemoryLevel(int32_t level)
return ERR_OK;
}
int32_t AppRunningManager::NotifyProcMemoryLevel(const std::map<pid_t, MemoryLevel> &procLevelMap)
int32_t AppRunningManager::NotifyProcMemoryLevel(const std::map<pid_t, MemoryLevel> &procLevelMap, bool isShellCall)
{
AAFwk::MyStatus::GetInstance().notifyProcMemoryCall_++;
return AAFwk::MyStatus::GetInstance().notifyProcMemory_;
@@ -264,7 +264,7 @@ void AppRunningRecord::ScheduleTrimMemory()
{
}
void AppRunningRecord::ScheduleMemoryLevel(int32_t level)
void AppRunningRecord::ScheduleMemoryLevel(int32_t level, bool isShellCall)
{
}
@@ -279,7 +279,7 @@ void AppRunningRecord::ScheduleTrimMemory()
{
}
void AppRunningRecord::ScheduleMemoryLevel(int32_t level)
void AppRunningRecord::ScheduleMemoryLevel(int32_t level, bool isShellCall)
{
}
@@ -141,7 +141,8 @@ public:
return 0;
}
virtual int32_t NotifyProcMemoryLevel(const std::map<pid_t, MemoryLevel>& procLevelMap)
virtual int32_t NotifyProcMemoryLevel(const std::map<pid_t, MemoryLevel>& procLevelMap,
bool isShellCall = false)
{
return 0;
}
+4 -5
View File
@@ -132,7 +132,7 @@ const std::string ERR_INVALID_VALUE_SOLUTION_ONE =
const std::string ERR_INVALID_PID_VALUE_SOLUTION_ONE =
"Check if the pid specified by the application exists.";
const std::string ERR_INVALID_LEVEL_VALUE_SOLUTION_ONE =
"Check if the value range of level is [0, 1, 2].";
"Check if the value range of level is [0, 1, 2, 3, 4, 5, 6].";
const std::string BLACK_ACTION_SELECT_DATA = "ohos.want.action.select";
constexpr struct option LONG_OPTIONS[] = {
@@ -1040,10 +1040,9 @@ ErrCode AbilityManagerShellCommand::RunAsSendMemoryLevelCommand()
return ERR_INVALID_VALUE;
}
if (!(inputLevel == OHOS::AppExecFwk::MemoryLevel::MEMORY_LEVEL_MODERATE ||
inputLevel == OHOS::AppExecFwk::MemoryLevel::MEMORY_LEVEL_CRITICAL ||
inputLevel == OHOS::AppExecFwk::MemoryLevel::MEMORY_LEVEL_LOW)) {
TAG_LOGE(AAFwkTag::APPMGR, "level value error. Valid values: 0-2 (0: Moderate, 1: Low, 2: Critical)");
if (!(inputLevel >= OHOS::AppExecFwk::MemoryLevel::MEMORY_LEVEL_MODERATE &&
inputLevel <= OHOS::AppExecFwk::MemoryLevel::MEMORY_LEVEL_BACKGROUND_CRITICAL)) {
TAG_LOGE(AAFwkTag::APPMGR, "level value error. Valid values: 0-6");
resultReceiver_.append(STRING_SEND_MEMORY_LEVEL_NG + "\n");
resultReceiver_.append(GetMessageFromCode(INVALID_LEVEL));
return ERR_INVALID_VALUE;
+1 -1
View File
@@ -262,7 +262,7 @@ int32_t AppRunningManager::NotifyMemoryLevel(int32_t level)
return ERR_OK;
}
int32_t AppRunningManager::NotifyProcMemoryLevel(const std::map<pid_t, MemoryLevel> &procLevelMap)
int32_t AppRunningManager::NotifyProcMemoryLevel(const std::map<pid_t, MemoryLevel> &procLevelMap, bool isShellCall)
{
return ERR_OK;
}
@@ -379,14 +379,14 @@ HWTEST_F(AaCommandSendMemoryLevelTest, RunAsSendMemoryLevelCommand_0400, TestSiz
HWTEST_F(AaCommandSendMemoryLevelTest, RunAsSendMemoryLevelCommand_0500, TestSize.Level1)
{
GTEST_LOG_(INFO) << "Aa_Command_RunAsSendMemoryLevelCommand_0500";
std::string invalidLevel = "7";
char* argv[] = {
(char*)TOOL_NAME.c_str(),
(char*)sendMemoryLevelCmd_.c_str(),
(char*)"-p",
(char*)STRING_VALID_PID.c_str(),
(char*)"-l",
(char*)STRING_INVALID_LEVEL.c_str(),
(char*)invalidLevel.c_str(),
(char*)"",
};
int32_t argc = sizeof(argv) / sizeof(argv[0]) - 1;