diff --git a/services/session/server/avsession_service.cpp b/services/session/server/avsession_service.cpp index cf7cdd9c5a4cfeca8378380bedf321bdf7c86971..127bc94e700091e6b466bc21d06cf564242d8957 100644 --- a/services/session/server/avsession_service.cpp +++ b/services/session/server/avsession_service.cpp @@ -563,6 +563,36 @@ void AVSessionService::NotifyProcessStatus(bool isStart) #endif } +void AVSessionService::SetCritical(bool isCritical) +{ + int pid = getpid(); + void *libMemMgrClientHandle = dlopen("libmemmgrclient.z.so", RTLD_NOW); + if (!libMemMgrClientHandle) { + SLOGE("dlopen libmemmgrclient library failed"); + return; + } + void *setCriticalFunc = dlsym(libMemMgrClientHandle, "set_critical"); + if (!setCriticalFunc) { + SLOGE("dlsm set_critical failed"); +#ifndef TEST_COVERAGE + if (libMemMgrClientHandle != nullptr) { + OPENSSL_thread_stop(); + } + dlclose(libMemMgrClientHandle); +#endif + return; + } + auto setCritical = reinterpret_cast(setCriticalFunc); + SLOGI("notify to memmgr as av_session isCritical:%{public}d", isCritical); + setCritical(pid, isCritical, AVSESSION_SERVICE_ID); // 1 indicates the service is started +#ifndef TEST_COVERAGE + if (libMemMgrClientHandle != nullptr) { + OPENSSL_thread_stop(); + } + dlclose(libMemMgrClientHandle); +#endif +} + void AVSessionService::InitKeyEvent() { SLOGI("enter init keyEvent"); @@ -1614,6 +1644,9 @@ int32_t AVSessionService::CreateSessionInner(const std::string& tag, int32_t typ SLOGE("session num exceed max"); return ERR_SESSION_EXCEED_MAX; } + if (GetUsersManager().GetContainerFromAll().GetAllSessions().size() == 1) { + SetCritical(true); + } HISYSEVENT_ADD_LIFE_CYCLE_INFO(elementName.GetBundleName(), AppManagerAdapter::GetInstance().IsAppBackground(GetCallingUid(), GetCallingPid()), type, true); @@ -1634,7 +1667,6 @@ int32_t AVSessionService::CreateSessionInner(const std::string& tag, int32_t typ #ifdef ENABLE_AVSESSION_SYSEVENT_CONTROL ReportSessionState(sessionItem, SessionState::STATE_CREATE); #endif - return AVSESSION_SUCCESS; } @@ -3183,6 +3215,9 @@ void AVSessionService::HandleSessionRelease(std::string sessionId, bool continue keyEventList->erase(it); } } + if (GetUsersManager().GetContainerFromAll().GetAllSessions().size() == 0) { + SetCritical(false); + } } HandleSessionReleaseInner(); } diff --git a/services/session/server/avsession_service.h b/services/session/server/avsession_service.h index e8e41aef994d5e802f93ccf5957f117bbfbbddc2..9f1b5bd9f2592a0f92a44f938c39892e09cdf6a2 100644 --- a/services/session/server/avsession_service.h +++ b/services/session/server/avsession_service.h @@ -312,6 +312,8 @@ public: private: void NotifyProcessStatus(bool isStart); + void SetCritical(bool isCritical); + static SessionContainer& GetContainer(); static AVSessionUsersManager& GetUsersManager();