diff --git a/frameworks/ets/ets/@ohos.app.ability.AbilityConstant.ets b/frameworks/ets/ets/@ohos.app.ability.AbilityConstant.ets index 70516aa5b2..7e26194f88 100644 --- a/frameworks/ets/ets/@ohos.app.ability.AbilityConstant.ets +++ b/frameworks/ets/ets/@ohos.app.ability.AbilityConstant.ets @@ -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 { diff --git a/frameworks/js/napi/ability_constant/ability_constant_module.cpp b/frameworks/js/napi/ability_constant/ability_constant_module.cpp index 6fdba663ea..3a6b1fb2b4 100644 --- a/frameworks/js/napi/ability_constant/ability_constant_module.cpp +++ b/frameworks/js/napi/ability_constant/ability_constant_module.cpp @@ -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(MemoryLevel::MEMORY_LEVEL_LOW))); NAPI_CALL(env, SetEnumItem(env, object, "MEMORY_LEVEL_CRITICAL", static_cast(MemoryLevel::MEMORY_LEVEL_CRITICAL))); + NAPI_CALL(env, SetEnumItem(env, object, "MEMORY_LEVEL_UI_HIDDEN", + static_cast(MemoryLevel::MEMORY_LEVEL_UI_HIDDEN))); + NAPI_CALL(env, SetEnumItem(env, object, "MEMORY_LEVEL_BACKGROUND_MODERATE", + static_cast(MemoryLevel::MEMORY_LEVEL_BACKGROUND_MODERATE))); + NAPI_CALL(env, SetEnumItem(env, object, "MEMORY_LEVEL_BACKGROUND_LOW", + static_cast(MemoryLevel::MEMORY_LEVEL_BACKGROUND_LOW))); + NAPI_CALL(env, SetEnumItem(env, object, "MEMORY_LEVEL_BACKGROUND_CRITICAL", + static_cast(MemoryLevel::MEMORY_LEVEL_BACKGROUND_CRITICAL))); return handleEscape.Escape(object); } diff --git a/frameworks/native/appkit/app/main_thread.cpp b/frameworks/native/appkit/app/main_thread.cpp index 4c90acc9ec..ce5f745fb7 100644 --- a/frameworks/native/appkit/app/main_thread.cpp +++ b/frameworks/native/appkit/app/main_thread.cpp @@ -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 weak = this; diff --git a/frameworks/simulator/napi_module/ability_constant/ability_constant_module.cpp b/frameworks/simulator/napi_module/ability_constant/ability_constant_module.cpp index ac00cec4eb..9ff08b787b 100644 --- a/frameworks/simulator/napi_module/ability_constant/ability_constant_module.cpp +++ b/frameworks/simulator/napi_module/ability_constant/ability_constant_module.cpp @@ -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(MemoryLevel::MEMORY_LEVEL_LOW))); NAPI_CALL(env, SetEnumItem(env, object, "MEMORY_LEVEL_CRITICAL", static_cast(MemoryLevel::MEMORY_LEVEL_CRITICAL))); + NAPI_CALL(env, SetEnumItem(env, object, "MEMORY_LEVEL_UI_HIDDEN", + static_cast(MemoryLevel::MEMORY_LEVEL_UI_HIDDEN))); + NAPI_CALL(env, SetEnumItem(env, object, "MEMORY_LEVEL_BACKGROUND_MODERATE", + static_cast(MemoryLevel::MEMORY_LEVEL_BACKGROUND_MODERATE))); + NAPI_CALL(env, SetEnumItem(env, object, "MEMORY_LEVEL_BACKGROUND_LOW", + static_cast(MemoryLevel::MEMORY_LEVEL_BACKGROUND_LOW))); + NAPI_CALL(env, SetEnumItem(env, object, "MEMORY_LEVEL_BACKGROUND_CRITICAL", + static_cast(MemoryLevel::MEMORY_LEVEL_BACKGROUND_CRITICAL))); return object; } diff --git a/interfaces/inner_api/app_manager/include/appmgr/app_mem_info.h b/interfaces/inner_api/app_manager/include/appmgr/app_mem_info.h index e25577aee4..12c455bef7 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/app_mem_info.h +++ b/interfaces/inner_api/app_manager/include/appmgr/app_mem_info.h @@ -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 { diff --git a/interfaces/inner_api/app_manager/include/appmgr/app_scheduler_interface.h b/interfaces/inner_api/app_manager/include/appmgr/app_scheduler_interface.h index 8fedbcf706..49f6f1e5b2 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/app_scheduler_interface.h +++ b/interfaces/inner_api/app_manager/include/appmgr/app_scheduler_interface.h @@ -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, diff --git a/interfaces/inner_api/app_manager/include/appmgr/app_scheduler_proxy.h b/interfaces/inner_api/app_manager/include/appmgr/app_scheduler_proxy.h index 8d8a28376a..fca9667f91 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/app_scheduler_proxy.h +++ b/interfaces/inner_api/app_manager/include/appmgr/app_scheduler_proxy.h @@ -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 delegator_; }; diff --git a/interfaces/inner_api/app_manager/src/appmgr/app_scheduler_proxy.cpp b/interfaces/inner_api/app_manager/src/appmgr/app_scheduler_proxy.cpp index 8c2eea5eee..f17e2013d4 100644 --- a/interfaces/inner_api/app_manager/src/appmgr/app_scheduler_proxy.cpp +++ b/interfaces/inner_api/app_manager/src/appmgr/app_scheduler_proxy.cpp @@ -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(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; } diff --git a/interfaces/inner_api/app_manager/src/appmgr/memory_level_info.cpp b/interfaces/inner_api/app_manager/src/appmgr/memory_level_info.cpp index fbb7a5511b..cd904e857d 100644 --- a/interfaces/inner_api/app_manager/src/appmgr/memory_level_info.cpp +++ b/interfaces/inner_api/app_manager/src/appmgr/memory_level_info.cpp @@ -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(tempLevel); break; default: diff --git a/interfaces/kits/native/appkit/app/main_thread.h b/interfaces/kits/native/appkit/app/main_thread.h index 9ffd7a7765..5761ce8b7c 100644 --- a/interfaces/kits/native/appkit/app/main_thread.h +++ b/interfaces/kits/native/appkit/app/main_thread.h @@ -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; /** * diff --git a/services/appmgr/include/app_lifecycle_deal.h b/services/appmgr/include/app_lifecycle_deal.h index 650eba77b5..56ce3393f3 100644 --- a/services/appmgr/include/app_lifecycle_deal.h +++ b/services/appmgr/include/app_lifecycle_deal.h @@ -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, diff --git a/services/appmgr/include/app_running_manager.h b/services/appmgr/include/app_running_manager.h index 43a70ad857..6fa3cdb7b3 100644 --- a/services/appmgr/include/app_running_manager.h +++ b/services/appmgr/include/app_running_manager.h @@ -275,7 +275,7 @@ public: * @param procLevelMap , . * @return Returns ERR_OK on success, others on failure. */ - int32_t NotifyProcMemoryLevel(const std::map &procLevelMap); + int32_t NotifyProcMemoryLevel(const std::map &procLevelMap, bool isShellCall = false); /* * Get the application's memory allocation info. diff --git a/services/appmgr/include/app_running_record.h b/services/appmgr/include/app_running_record.h index 6876e41921..9e1b4e8518 100644 --- a/services/appmgr/include/app_running_record.h +++ b/services/appmgr/include/app_running_record.h @@ -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. diff --git a/services/appmgr/src/app_lifecycle_deal.cpp b/services/appmgr/src/app_lifecycle_deal.cpp index a961bcd64d..9cdc3aa463 100644 --- a/services/appmgr/src/app_lifecycle_deal.cpp +++ b/services/appmgr/src/app_lifecycle_deal.cpp @@ -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) diff --git a/services/appmgr/src/app_mgr_service_inner.cpp b/services/appmgr/src/app_mgr_service_inner.cpp index e027ca5a67..298674e284 100644 --- a/services/appmgr/src/app_mgr_service_inner.cpp +++ b/services/appmgr/src/app_mgr_service_inner.cpp @@ -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::mapNotifyProcMemoryLevel(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) diff --git a/services/appmgr/src/app_running_manager.cpp b/services/appmgr/src/app_running_manager.cpp index 80e6a6d16f..1570d8df0e 100644 --- a/services/appmgr/src/app_running_manager.cpp +++ b/services/appmgr/src/app_running_manager.cpp @@ -1345,7 +1345,7 @@ int32_t AppRunningManager::NotifyMemoryLevel(int32_t level) return ERR_OK; } -int32_t AppRunningManager::NotifyProcMemoryLevel(const std::map &procLevelMap) +int32_t AppRunningManager::NotifyProcMemoryLevel(const std::map &procLevelMap, bool isShellCall) { auto appRunningMap = GetAppRunningRecordMap(); for (const auto &item : appRunningMap) { @@ -1365,7 +1365,7 @@ int32_t AppRunningManager::NotifyProcMemoryLevel(const std::mapsecond); - appRecord->ScheduleMemoryLevel(it->second); + appRecord->ScheduleMemoryLevel(it->second, isShellCall); } } return ERR_OK; diff --git a/services/appmgr/src/app_running_record.cpp b/services/appmgr/src/app_running_record.cpp index 1e20747fbd..490f7a75e7 100644 --- a/services/appmgr/src/app_running_record.cpp +++ b/services/appmgr/src/app_running_record.cpp @@ -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); } } diff --git a/test/mock/services_appmgr_test/include/mock_app_scheduler.h b/test/mock/services_appmgr_test/include/mock_app_scheduler.h index fcd5f56f81..b9a052876d 100644 --- a/test/mock/services_appmgr_test/include/mock_app_scheduler.h +++ b/test/mock/services_appmgr_test/include/mock_app_scheduler.h @@ -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)); diff --git a/test/mock/services_appmgr_test/include/mock_app_scheduler_client.h b/test/mock/services_appmgr_test/include/mock_app_scheduler_client.h index 6193379078..9e9f20d975 100644 --- a/test/mock/services_appmgr_test/include/mock_app_scheduler_client.h +++ b/test/mock/services_appmgr_test/include/mock_app_scheduler_client.h @@ -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)); diff --git a/test/mock/services_appmgr_test/include/mock_application.h b/test/mock/services_appmgr_test/include/mock_application.h index fdb9ec56cb..98da28dd8d 100644 --- a/test/mock/services_appmgr_test/include/mock_application.h +++ b/test/mock/services_appmgr_test/include/mock_application.h @@ -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&, diff --git a/test/mock/services_appmgr_test/include/mock_application_proxy.h b/test/mock/services_appmgr_test/include/mock_application_proxy.h index 4a9e261dc0..5213841f5d 100644 --- a/test/mock/services_appmgr_test/include/mock_application_proxy.h +++ b/test/mock/services_appmgr_test/include/mock_application_proxy.h @@ -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&, diff --git a/test/moduletest/common/ams/ability_running_record_test/ams_ability_running_record_module_test.cpp b/test/moduletest/common/ams/ability_running_record_test/ams_ability_running_record_module_test.cpp index af4ff62960..9198f6029a 100644 --- a/test/moduletest/common/ams/ability_running_record_test/ams_ability_running_record_module_test.cpp +++ b/test/moduletest/common/ams/ability_running_record_test/ams_ability_running_record_module_test.cpp @@ -92,7 +92,7 @@ public: { scheduled_ |= LOW_MEMORY_SCHEDULED; } - void ScheduleMemoryLevel(const int) override + void ScheduleMemoryLevel(const int, bool) override { scheduled_ |= MEMORY_LEVEL_SCHEDULED; } diff --git a/test/moduletest/common/ams/app_mgr_service_test/ams_app_mgr_service_module_test.cpp b/test/moduletest/common/ams/app_mgr_service_test/ams_app_mgr_service_module_test.cpp index c8f1a188bb..cc9005d5b0 100644 --- a/test/moduletest/common/ams/app_mgr_service_test/ams_app_mgr_service_module_test.cpp +++ b/test/moduletest/common/ams/app_mgr_service_test/ams_app_mgr_service_module_test.cpp @@ -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 {} diff --git a/test/moduletest/mock/include/mock_app_scheduler.h b/test/moduletest/mock/include/mock_app_scheduler.h index 5d78540f5a..65c90ca316 100644 --- a/test/moduletest/mock/include/mock_app_scheduler.h +++ b/test/moduletest/mock/include/mock_app_scheduler.h @@ -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 &)); diff --git a/test/unittest/ams_app_running_record_test/ams_app_running_record_test.cpp b/test/unittest/ams_app_running_record_test/ams_app_running_record_test.cpp index 631aa215b4..32bc976cd3 100644 --- a/test/unittest/ams_app_running_record_test/ams_app_running_record_test.cpp +++ b/test/unittest/ams_app_running_record_test/ams_app_running_record_test.cpp @@ -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; diff --git a/test/unittest/app_mgr_service_fourth_test/mock/src/mock_app_running_record.cpp b/test/unittest/app_mgr_service_fourth_test/mock/src/mock_app_running_record.cpp index 09e4afe769..e01516eb4c 100644 --- a/test/unittest/app_mgr_service_fourth_test/mock/src/mock_app_running_record.cpp +++ b/test/unittest/app_mgr_service_fourth_test/mock/src/mock_app_running_record.cpp @@ -254,7 +254,7 @@ void AppRunningRecord::ScheduleTrimMemory() { } -void AppRunningRecord::ScheduleMemoryLevel(int32_t level) +void AppRunningRecord::ScheduleMemoryLevel(int32_t level, bool isShellCall) { } diff --git a/test/unittest/app_mgr_service_inner_eighth_test/mock/src/mock_app_running_manager.cpp b/test/unittest/app_mgr_service_inner_eighth_test/mock/src/mock_app_running_manager.cpp index b321d1e599..8cd8ae2350 100644 --- a/test/unittest/app_mgr_service_inner_eighth_test/mock/src/mock_app_running_manager.cpp +++ b/test/unittest/app_mgr_service_inner_eighth_test/mock/src/mock_app_running_manager.cpp @@ -271,7 +271,7 @@ int32_t AppRunningManager::NotifyMemoryLevel(int32_t level) return ERR_OK; } -int32_t AppRunningManager::NotifyProcMemoryLevel(const std::map &procLevelMap) +int32_t AppRunningManager::NotifyProcMemoryLevel(const std::map &procLevelMap, bool isShellCall) { AAFwk::MyStatus::GetInstance().notifyProcMemoryCall_++; return AAFwk::MyStatus::GetInstance().notifyProcMemory_; diff --git a/test/unittest/app_mgr_service_inner_eighth_test/mock/src/mock_app_running_record.cpp b/test/unittest/app_mgr_service_inner_eighth_test/mock/src/mock_app_running_record.cpp index 0607a80a64..9ed20abec0 100644 --- a/test/unittest/app_mgr_service_inner_eighth_test/mock/src/mock_app_running_record.cpp +++ b/test/unittest/app_mgr_service_inner_eighth_test/mock/src/mock_app_running_record.cpp @@ -263,7 +263,7 @@ void AppRunningRecord::ScheduleTrimMemory() { } -void AppRunningRecord::ScheduleMemoryLevel(int32_t level) +void AppRunningRecord::ScheduleMemoryLevel(int32_t level, bool isShellCall) { } diff --git a/test/unittest/app_mgr_service_inner_ninth_test/mock/include/mock_app_scheduler.h b/test/unittest/app_mgr_service_inner_ninth_test/mock/include/mock_app_scheduler.h index 4b3e38caca..e56efe6e9e 100644 --- a/test/unittest/app_mgr_service_inner_ninth_test/mock/include/mock_app_scheduler.h +++ b/test/unittest/app_mgr_service_inner_ninth_test/mock/include/mock_app_scheduler.h @@ -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)); diff --git a/test/unittest/app_mgr_service_inner_ninth_test/mock/src/mock_app_running_manager.cpp b/test/unittest/app_mgr_service_inner_ninth_test/mock/src/mock_app_running_manager.cpp index 63e04e65b8..25653c06ec 100644 --- a/test/unittest/app_mgr_service_inner_ninth_test/mock/src/mock_app_running_manager.cpp +++ b/test/unittest/app_mgr_service_inner_ninth_test/mock/src/mock_app_running_manager.cpp @@ -280,7 +280,7 @@ int32_t AppRunningManager::NotifyMemoryLevel(int32_t level) return ERR_OK; } -int32_t AppRunningManager::NotifyProcMemoryLevel(const std::map &procLevelMap) +int32_t AppRunningManager::NotifyProcMemoryLevel(const std::map &procLevelMap, bool isShellCall) { AAFwk::MyStatus::GetInstance().notifyProcMemoryCall_++; return AAFwk::MyStatus::GetInstance().notifyProcMemory_; diff --git a/test/unittest/app_mgr_service_inner_ninth_test/mock/src/mock_app_running_record.cpp b/test/unittest/app_mgr_service_inner_ninth_test/mock/src/mock_app_running_record.cpp index b90b6240e2..f2e5ff87b7 100644 --- a/test/unittest/app_mgr_service_inner_ninth_test/mock/src/mock_app_running_record.cpp +++ b/test/unittest/app_mgr_service_inner_ninth_test/mock/src/mock_app_running_record.cpp @@ -281,7 +281,7 @@ void AppRunningRecord::ScheduleTrimMemory() { } -void AppRunningRecord::ScheduleMemoryLevel(int32_t level) +void AppRunningRecord::ScheduleMemoryLevel(int32_t level, bool isShellCall) { } diff --git a/test/unittest/app_mgr_service_inner_second_test/app_mgr_service_inner_second_test.cpp b/test/unittest/app_mgr_service_inner_second_test/app_mgr_service_inner_second_test.cpp index b5e91d18f0..d5d6ea601f 100644 --- a/test/unittest/app_mgr_service_inner_second_test/app_mgr_service_inner_second_test.cpp +++ b/test/unittest/app_mgr_service_inner_second_test/app_mgr_service_inner_second_test.cpp @@ -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(); - 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(); + 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(); + 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 diff --git a/test/unittest/app_mgr_service_inner_seventh_test/mock/src/mock_app_running_manager.cpp b/test/unittest/app_mgr_service_inner_seventh_test/mock/src/mock_app_running_manager.cpp index 1f8e0cfcf5..a206a9fec9 100644 --- a/test/unittest/app_mgr_service_inner_seventh_test/mock/src/mock_app_running_manager.cpp +++ b/test/unittest/app_mgr_service_inner_seventh_test/mock/src/mock_app_running_manager.cpp @@ -271,7 +271,7 @@ int32_t AppRunningManager::NotifyMemoryLevel(int32_t level) return ERR_OK; } -int32_t AppRunningManager::NotifyProcMemoryLevel(const std::map &procLevelMap) +int32_t AppRunningManager::NotifyProcMemoryLevel(const std::map &procLevelMap, bool isShellCall) { AAFwk::MyStatus::GetInstance().notifyProcMemoryCall_++; return AAFwk::MyStatus::GetInstance().notifyProcMemory_; diff --git a/test/unittest/app_mgr_service_inner_seventh_test/mock/src/mock_app_running_record.cpp b/test/unittest/app_mgr_service_inner_seventh_test/mock/src/mock_app_running_record.cpp index d91f3c97f3..106d59c580 100644 --- a/test/unittest/app_mgr_service_inner_seventh_test/mock/src/mock_app_running_record.cpp +++ b/test/unittest/app_mgr_service_inner_seventh_test/mock/src/mock_app_running_record.cpp @@ -264,7 +264,7 @@ void AppRunningRecord::ScheduleTrimMemory() { } -void AppRunningRecord::ScheduleMemoryLevel(int32_t level) +void AppRunningRecord::ScheduleMemoryLevel(int32_t level, bool isShellCall) { } diff --git a/test/unittest/cache_process_manager_second_test/mock/src/mock_app_running_record.cpp b/test/unittest/cache_process_manager_second_test/mock/src/mock_app_running_record.cpp index 9e974012dc..af8a7f5b0e 100644 --- a/test/unittest/cache_process_manager_second_test/mock/src/mock_app_running_record.cpp +++ b/test/unittest/cache_process_manager_second_test/mock/src/mock_app_running_record.cpp @@ -279,7 +279,7 @@ void AppRunningRecord::ScheduleTrimMemory() { } -void AppRunningRecord::ScheduleMemoryLevel(int32_t level) +void AppRunningRecord::ScheduleMemoryLevel(int32_t level, bool isShellCall) { } diff --git a/test/unittest/multi_instance_utils_second_test/mock_iapp_mgr.h b/test/unittest/multi_instance_utils_second_test/mock_iapp_mgr.h index 500bfb736a..5785ad703f 100644 --- a/test/unittest/multi_instance_utils_second_test/mock_iapp_mgr.h +++ b/test/unittest/multi_instance_utils_second_test/mock_iapp_mgr.h @@ -141,7 +141,8 @@ public: return 0; } - virtual int32_t NotifyProcMemoryLevel(const std::map& procLevelMap) + virtual int32_t NotifyProcMemoryLevel(const std::map& procLevelMap, + bool isShellCall = false) { return 0; } diff --git a/tools/aa/src/ability_command.cpp b/tools/aa/src/ability_command.cpp index 26875a357d..b2c60df30d 100644 --- a/tools/aa/src/ability_command.cpp +++ b/tools/aa/src/ability_command.cpp @@ -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; diff --git a/tools/test/mock/mock_app_running_manager.cpp b/tools/test/mock/mock_app_running_manager.cpp index db28ff484b..ad4a7c4610 100644 --- a/tools/test/mock/mock_app_running_manager.cpp +++ b/tools/test/mock/mock_app_running_manager.cpp @@ -262,7 +262,7 @@ int32_t AppRunningManager::NotifyMemoryLevel(int32_t level) return ERR_OK; } -int32_t AppRunningManager::NotifyProcMemoryLevel(const std::map &procLevelMap) +int32_t AppRunningManager::NotifyProcMemoryLevel(const std::map &procLevelMap, bool isShellCall) { return ERR_OK; } diff --git a/tools/test/unittest/aa/aa_command_send_memory_level_test.cpp b/tools/test/unittest/aa/aa_command_send_memory_level_test.cpp index 386609dbcd..7e99c7b22d 100644 --- a/tools/test/unittest/aa/aa_command_send_memory_level_test.cpp +++ b/tools/test/unittest/aa/aa_command_send_memory_level_test.cpp @@ -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;