mirror of
https://github.com/openharmony/resourceschedule_memmgr.git
synced 2026-07-01 03:23:18 -04:00
@@ -41,7 +41,7 @@ typedef struct ProcessWindowVisibilityInfo ProcessWindowVisibilityInfo;
|
||||
class WindowVisibilityObserver {
|
||||
DECLARE_SINGLE_INSTANCE_BASE(WindowVisibilityObserver);
|
||||
public:
|
||||
void UpdateWindowVisibilityPriority(const std::vector<sptr<MemMgrWindowInfo>> &MemMgrWindowInfo);
|
||||
void UpdateWindowVisibilityPriority(const std::vector<sptr<MemMgrWindowInfo>> &memMgrWindowInfo);
|
||||
void OnProcessDied(int pid);
|
||||
|
||||
private:
|
||||
|
||||
@@ -52,9 +52,7 @@ private:
|
||||
int32_t HandleNotifyProcessStatus(MessageParcel &data, MessageParcel &reply);
|
||||
int32_t HandleSetCritical(MessageParcel &data, MessageParcel &reply);
|
||||
bool CheckCallingToken();
|
||||
|
||||
using MemMgrFunc = int32_t (MemMgrStub::*)(MessageParcel &data, MessageParcel &reply);
|
||||
std::map<uint32_t, MemMgrFunc> memberFuncMap_;
|
||||
int32_t OnRemoteRequestInner(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option);
|
||||
|
||||
DISALLOW_COPY_AND_MOVE(MemMgrStub);
|
||||
};
|
||||
|
||||
@@ -30,7 +30,6 @@ public:
|
||||
private:
|
||||
std::shared_ptr<AppExecFwk::EventHandler> handler_;
|
||||
NandLifeConfig config_;
|
||||
std::function<void()> timerFunc_;
|
||||
|
||||
unsigned long long DAILY_SWAP_OUT_QUOTA_KB;
|
||||
unsigned long long TOTAL_SWAP_OUT_QUOTA_KB;
|
||||
|
||||
@@ -56,8 +56,7 @@ void KswapdObserver::Init()
|
||||
}
|
||||
// call MainLoop at handler thread
|
||||
if (handler_ != nullptr) {
|
||||
std::function<void()> mainLoopFun = std::bind(&KswapdObserver::MainLoop, this);
|
||||
handler_->PostImmediateTask(mainLoopFun);
|
||||
handler_->PostImmediateTask([this] { this->MainLoop(); });
|
||||
HILOGD("call MainLoop at handler thread");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -121,35 +121,21 @@ bool MemMgrEventCenter::RegisterEventObserver()
|
||||
void MemMgrEventCenter::HandlerRegisterEvent(int64_t registerEventId)
|
||||
{
|
||||
if (registerEventId == RegisterEvent::REG_ALLOBS_EVENT) {
|
||||
std::function<void()> RegisterEventObserverFunc =
|
||||
std::bind(&MemMgrEventCenter::RegisterEventObserver, this);
|
||||
regObsHandler_->PostImmediateTask(RegisterEventObserverFunc);
|
||||
regObsHandler_->PostImmediateTask([this] { this->RegisterEventObserver(); });
|
||||
} else if (registerEventId == RegisterEvent::REG_MEMPRESSOBS_EVENT) {
|
||||
std::function<void()> RegisterMemoryPressureObserverFunc =
|
||||
std::bind(&MemMgrEventCenter::RegisterMemoryPressureObserver, this);
|
||||
regObsHandler_->PostImmediateTask(RegisterMemoryPressureObserverFunc);
|
||||
regObsHandler_->PostImmediateTask([this] { this->RegisterMemoryPressureObserver(); });
|
||||
} else if (registerEventId == RegisterEvent::REG_APPOBS_EVENT) {
|
||||
std::function<void()> RegisterAppStateObserverFunc =
|
||||
std::bind(&MemMgrEventCenter::RegisterAppStateObserver, this);
|
||||
regObsHandler_->PostImmediateTask(RegisterAppStateObserverFunc);
|
||||
regObsHandler_->PostImmediateTask([this] { this->RegisterAppStateObserver(); });
|
||||
} else if (registerEventId == RegisterEvent::REG_EXTOBS_EVENT) {
|
||||
std::function<void()> RegisterExtConnObserverFunc =
|
||||
std::bind(&MemMgrEventCenter::RegisterExtConnObserver, this);
|
||||
regObsHandler_->PostImmediateTask(RegisterExtConnObserverFunc);
|
||||
regObsHandler_->PostImmediateTask([this] { this->RegisterExtConnObserver(); });
|
||||
} else if (registerEventId == RegisterEvent::REG_ACCOUNTOBS_EVENT) {
|
||||
std::function<void()> RegisterAccountObserverFunc =
|
||||
std::bind(&MemMgrEventCenter::RegisterAccountObserver, this);
|
||||
regObsHandler_->PostImmediateTask(RegisterAccountObserverFunc);
|
||||
regObsHandler_->PostImmediateTask([this] { this->RegisterAccountObserver(); });
|
||||
} else if (registerEventId == RegisterEvent::REG_COMMONOBS_EVENT) {
|
||||
std::function<void()> RegisterCommonEventObserverFunc =
|
||||
std::bind(&MemMgrEventCenter::RegisterCommonEventObserver, this);
|
||||
regObsHandler_->PostImmediateTask(RegisterCommonEventObserverFunc);
|
||||
regObsHandler_->PostImmediateTask([this] { this->RegisterCommonEventObserver(); });
|
||||
} else if (registerEventId == RegisterEvent::REG_BGTASKOBS_EVENT) {
|
||||
#ifdef CONFIG_BGTASK_MGR
|
||||
{
|
||||
std::function<void()> RegisterBgTaskObserverFunc =
|
||||
std::bind(&MemMgrEventCenter::RegisterBgTaskObserver, this);
|
||||
regObsHandler_->PostImmediateTask(RegisterBgTaskObserverFunc);
|
||||
regObsHandler_->PostImmediateTask([this] { this->RegisterBgTaskObserver(); });
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -193,8 +179,8 @@ void MemMgrEventCenter::RegisterExtConnObserver()
|
||||
}
|
||||
HILOGE("register fail, ret = %{public}d", ret);
|
||||
}
|
||||
std::function<void()> RegisterExtConnObserverFunc = std::bind(&MemMgrEventCenter::RegisterExtConnObserver, this);
|
||||
regObsHandler_->PostTask(RegisterExtConnObserverFunc, EXTCONN_RETRY_TIME, AppExecFwk::EventQueue::Priority::LOW);
|
||||
regObsHandler_->PostTask([this] { this->RegisterExtConnObserver(); },
|
||||
EXTCONN_RETRY_TIME, AppExecFwk::EventQueue::Priority::LOW);
|
||||
}
|
||||
|
||||
void MemMgrEventCenter::RegisterBgTaskObserver()
|
||||
@@ -250,11 +236,9 @@ void MemMgrEventCenter::RegisterAccountObserver()
|
||||
}
|
||||
|
||||
if (regAccountObsRetry_ < ACCOUNT_MAX_RETRY_TIMES) {
|
||||
std::function<void()> RegisterAccountObserverFunc =
|
||||
std::bind(&MemMgrEventCenter::RegisterAccountObserver, this);
|
||||
HILOGE("register fail, retCode = %{public}d, try again after 3s!, retryTimes=%{public}d/10",
|
||||
errCode, regAccountObsRetry_);
|
||||
regObsHandler_->PostTask(RegisterAccountObserverFunc, ACCOUNT_RETRY_DELAY,
|
||||
regObsHandler_->PostTask([this] { this->RegisterAccountObserver(); }, ACCOUNT_RETRY_DELAY,
|
||||
AppExecFwk::EventQueue::Priority::LOW); // 3000 means 3s
|
||||
}
|
||||
}
|
||||
@@ -264,16 +248,16 @@ void MemMgrEventCenter::RegisterMemoryPressureObserver()
|
||||
HILOGI("called");
|
||||
MAKE_POINTER(memoryPressureObserver_, shared, MemoryPressureObserver, "make MemoryPressureObserver failed", return,
|
||||
/* no param */);
|
||||
std::function<void()> initFunc = std::bind(&MemoryPressureObserver::Init, memoryPressureObserver_);
|
||||
regObsHandler_->PostTask(initFunc, 10000, AppExecFwk::EventQueue::Priority::HIGH); // 10000 means 10s
|
||||
regObsHandler_->PostTask([this] { this->memoryPressureObserver_->Init(); },
|
||||
10000, AppExecFwk::EventQueue::Priority::HIGH); // 10000 means 10s
|
||||
}
|
||||
|
||||
void MemMgrEventCenter::RegisterKswapdObserver()
|
||||
{
|
||||
HILOGI("called");
|
||||
MAKE_POINTER(kswapdObserver_, shared, KswapdObserver, "make KswapdObserver failed", return, /* no param */);
|
||||
std::function<void()> initFunc = std::bind(&KswapdObserver::Init, kswapdObserver_);
|
||||
regObsHandler_->PostTask(initFunc, 10000, AppExecFwk::EventQueue::Priority::HIGH); // 10000 means 10s
|
||||
regObsHandler_->PostTask([this] { this->kswapdObserver_->Init(); },
|
||||
10000, AppExecFwk::EventQueue::Priority::HIGH); // 10000 means 10s
|
||||
}
|
||||
|
||||
MemMgrEventCenter::~MemMgrEventCenter()
|
||||
|
||||
@@ -55,8 +55,7 @@ void MemoryPressureObserver::Init()
|
||||
return;
|
||||
}
|
||||
// call MainLoop at handler thread
|
||||
std::function<void()> mainLoopFun = std::bind(&MemoryPressureObserver::MainLoop, this);
|
||||
handler_->PostImmediateTask(mainLoopFun);
|
||||
handler_->PostImmediateTask([this] { this->MainLoop(); });
|
||||
HILOGI("call MainLoop at handler thread");
|
||||
}
|
||||
|
||||
|
||||
@@ -51,12 +51,12 @@ void WindowVisibilityObserver::OnProcessDied(int pid)
|
||||
}
|
||||
|
||||
void WindowVisibilityObserver::UpdateWindowVisibilityPriority(
|
||||
const std::vector<sptr<MemMgrWindowInfo>> &MemMgrWindowInfo)
|
||||
const std::vector<sptr<MemMgrWindowInfo>> &memMgrWindowInfo)
|
||||
{
|
||||
HILOGD("called");
|
||||
std::function<void()> UpdateWindowVisibilityPriorityInnerFunc =
|
||||
std::bind(&WindowVisibilityObserver::UpdateWindowVisibilityPriorityInner, this, MemMgrWindowInfo);
|
||||
handler_->PostImmediateTask(UpdateWindowVisibilityPriorityInnerFunc);
|
||||
handler_->PostImmediateTask([this, memMgrWindowInfo] {
|
||||
this->UpdateWindowVisibilityPriorityInner(memMgrWindowInfo);
|
||||
});
|
||||
}
|
||||
|
||||
void WindowVisibilityObserver::UpdateWindowVisibilityPriorityInner(
|
||||
@@ -96,7 +96,7 @@ void WindowVisibilityObserver::UpdateWindowVisibilityPriorityInner(
|
||||
UpdatePriorityForVisible(windowVisibleMap_);
|
||||
if (windowVisibleMap_.size() >= 2048) { //2048: max process num
|
||||
if (handler_) {
|
||||
handler_->PostImmediateTask(std::bind(&WindowVisibilityObserver::CheckMapSize, this, TRIGGER_BY_SIZE));
|
||||
handler_->PostImmediateTask([this] { this->CheckMapSize(TRIGGER_BY_SIZE); });
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -130,9 +130,9 @@ void WindowVisibilityObserver::UpdatePriorityForVisible(
|
||||
|
||||
void WindowVisibilityObserver::SetTimer()
|
||||
{
|
||||
std::function<void()> timerFunc_ = std::bind(&WindowVisibilityObserver::CheckMapSize, this, TRIGGER_BY_TIME);
|
||||
//set timer and call CheckMapSize each TIMER_PEROID_MIN min.
|
||||
handler_->PostTask(timerFunc_, TIMER_PEROID_MS, AppExecFwk::EventQueue::Priority::HIGH);
|
||||
handler_->PostTask([this] { this->CheckMapSize(TRIGGER_BY_TIME); },
|
||||
TIMER_PEROID_MS, AppExecFwk::EventQueue::Priority::HIGH);
|
||||
HILOGD("set timer after %{public}d mins", TIMER_PEROID_MIN);
|
||||
}
|
||||
|
||||
|
||||
@@ -235,8 +235,7 @@ void LowMemoryKiller::PsiHandler()
|
||||
HILOGE("is not initialized, return!");
|
||||
return;
|
||||
}
|
||||
std::function<void()> func = std::bind(&LowMemoryKiller::PsiHandlerInner, this);
|
||||
handler_->PostImmediateTask(func);
|
||||
handler_->PostImmediateTask([this] { this->PsiHandlerInner(); });
|
||||
}
|
||||
} // namespace Memory
|
||||
} // namespace OHOS
|
||||
@@ -34,43 +34,10 @@ namespace {
|
||||
|
||||
MemMgrStub::MemMgrStub()
|
||||
{
|
||||
memberFuncMap_[static_cast<uint32_t>(MemMgrInterfaceCode::MEM_MGR_GET_BUNDLE_PRIORITY_LIST)] =
|
||||
&MemMgrStub::HandleGetBunldePriorityList;
|
||||
memberFuncMap_[static_cast<uint32_t>(MemMgrInterfaceCode::MEM_MGR_NOTIFY_DIST_DEV_STATUS)] =
|
||||
&MemMgrStub::HandleNotifyDistDevStatus;
|
||||
memberFuncMap_[static_cast<uint32_t>(MemMgrInterfaceCode::MEM_MGR_GET_KILL_LEVEL_OF_LMKD)] =
|
||||
&MemMgrStub::HandleGetKillLevelOfLmkd;
|
||||
#ifdef USE_PURGEABLE_MEMORY
|
||||
memberFuncMap_[static_cast<uint32_t>(MemMgrInterfaceCode::MEM_MGR_REGISTER_ACTIVE_APPS)] =
|
||||
&MemMgrStub::HandleRegisterActiveApps;
|
||||
memberFuncMap_[static_cast<uint32_t>(MemMgrInterfaceCode::MEM_MGR_DEREGISTER_ACTIVE_APPS)] =
|
||||
&MemMgrStub::HandleDeregisterActiveApps;
|
||||
memberFuncMap_[static_cast<uint32_t>(MemMgrInterfaceCode::MEM_MGR_SUBSCRIBE_APP_STATE)] =
|
||||
&MemMgrStub::HandleSubscribeAppState;
|
||||
memberFuncMap_[static_cast<uint32_t>(MemMgrInterfaceCode::MEM_MGR_UNSUBSCRIBE_APP_STATE)] =
|
||||
&MemMgrStub::HandleUnsubscribeAppState;
|
||||
memberFuncMap_[static_cast<uint32_t>(MemMgrInterfaceCode::MEM_MGR_GET_AVAILABLE_MEMORY)] =
|
||||
&MemMgrStub::HandleGetAvailableMemory;
|
||||
memberFuncMap_[static_cast<uint32_t>(MemMgrInterfaceCode::MEM_MGR_GET_TOTAL_MEMORY)] =
|
||||
&MemMgrStub::HandleGetTotalMemory;
|
||||
#endif
|
||||
memberFuncMap_[static_cast<uint32_t>(MemMgrInterfaceCode::MEM_MGR_ON_WINDOW_VISIBILITY_CHANGED)] =
|
||||
&MemMgrStub::HandleOnWindowVisibilityChanged;
|
||||
memberFuncMap_[static_cast<uint32_t>(MemMgrInterfaceCode::MEM_MGR_GET_PRIORITY_BY_PID)] =
|
||||
&MemMgrStub::HandleGetReclaimPriorityByPid;
|
||||
memberFuncMap_[static_cast<uint32_t>(MemMgrInterfaceCode::MEM_MGR_NOTIFY_PROCESS_STATE_CHANGED_SYNC)] =
|
||||
&MemMgrStub::HandleNotifyProcessStateChangedSync;
|
||||
memberFuncMap_[static_cast<uint32_t>(MemMgrInterfaceCode::MEM_MGR_NOTIFY_PROCESS_STATE_CHANGED_ASYNC)] =
|
||||
&MemMgrStub::HandleNotifyProcessStateChangedAsync;
|
||||
memberFuncMap_[static_cast<uint32_t>(MemMgrInterfaceCode::MEM_MGR_NOTIFY_PROCESS_STATUS)] =
|
||||
&MemMgrStub::HandleNotifyProcessStatus;
|
||||
memberFuncMap_[static_cast<uint32_t>(MemMgrInterfaceCode::MEM_MGR_SET_CRITICAL)] =
|
||||
&MemMgrStub::HandleSetCritical;
|
||||
}
|
||||
|
||||
MemMgrStub::~MemMgrStub()
|
||||
{
|
||||
memberFuncMap_.clear();
|
||||
}
|
||||
|
||||
int MemMgrStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
|
||||
@@ -83,14 +50,48 @@ int MemMgrStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParce
|
||||
return ERR_INVALID_STATE;
|
||||
}
|
||||
|
||||
auto itFunc = memberFuncMap_.find(code);
|
||||
if (itFunc != memberFuncMap_.end()) {
|
||||
auto memberFunc = itFunc->second;
|
||||
if (memberFunc != nullptr) {
|
||||
return (this->*memberFunc)(data, reply);
|
||||
}
|
||||
return OnRemoteRequestInner(code, data, reply, option);
|
||||
}
|
||||
|
||||
int32_t MemMgrStub::OnRemoteRequestInner(uint32_t code,
|
||||
MessageParcel &data, MessageParcel &reply, MessageOption &option)
|
||||
{
|
||||
switch (code) {
|
||||
case static_cast<uint32_t>(MemMgrInterfaceCode::MEM_MGR_GET_BUNDLE_PRIORITY_LIST):
|
||||
return HandleGetBunldePriorityList(data, reply);
|
||||
case static_cast<uint32_t>(MemMgrInterfaceCode::MEM_MGR_NOTIFY_DIST_DEV_STATUS):
|
||||
return HandleNotifyDistDevStatus(data, reply);
|
||||
case static_cast<uint32_t>(MemMgrInterfaceCode::MEM_MGR_GET_KILL_LEVEL_OF_LMKD):
|
||||
return HandleGetKillLevelOfLmkd(data, reply);
|
||||
#ifdef USE_PURGEABLE_MEMORY
|
||||
case static_cast<uint32_t>(MemMgrInterfaceCode::MEM_MGR_REGISTER_ACTIVE_APPS):
|
||||
return HandleRegisterActiveApps(data, reply);
|
||||
case static_cast<uint32_t>(MemMgrInterfaceCode::MEM_MGR_DEREGISTER_ACTIVE_APPS):
|
||||
return HandleDeregisterActiveApps(data, reply);
|
||||
case static_cast<uint32_t>(MemMgrInterfaceCode::MEM_MGR_SUBSCRIBE_APP_STATE):
|
||||
return HandleSubscribeAppState(data, reply);
|
||||
case static_cast<uint32_t>(MemMgrInterfaceCode::MEM_MGR_UNSUBSCRIBE_APP_STATE):
|
||||
return HandleUnsubscribeAppState(data, reply);
|
||||
case static_cast<uint32_t>(MemMgrInterfaceCode::MEM_MGR_GET_AVAILABLE_MEMORY):
|
||||
return HandleGetAvailableMemory(data, reply);
|
||||
case static_cast<uint32_t>(MemMgrInterfaceCode::MEM_MGR_GET_TOTAL_MEMORY):
|
||||
return HandleGetTotalMemory(data, reply);
|
||||
#endif
|
||||
case static_cast<uint32_t>(MemMgrInterfaceCode::MEM_MGR_ON_WINDOW_VISIBILITY_CHANGED):
|
||||
return HandleOnWindowVisibilityChanged(data, reply);
|
||||
case static_cast<uint32_t>(MemMgrInterfaceCode::MEM_MGR_GET_PRIORITY_BY_PID):
|
||||
return HandleGetReclaimPriorityByPid(data, reply);
|
||||
case static_cast<uint32_t>(MemMgrInterfaceCode::MEM_MGR_NOTIFY_PROCESS_STATE_CHANGED_SYNC):
|
||||
return HandleNotifyProcessStateChangedSync(data, reply);
|
||||
case static_cast<uint32_t>(MemMgrInterfaceCode::MEM_MGR_NOTIFY_PROCESS_STATE_CHANGED_ASYNC):
|
||||
return HandleNotifyProcessStateChangedAsync(data, reply);
|
||||
case static_cast<uint32_t>(MemMgrInterfaceCode::MEM_MGR_NOTIFY_PROCESS_STATUS):
|
||||
return HandleNotifyProcessStatus(data, reply);
|
||||
case static_cast<uint32_t>(MemMgrInterfaceCode::MEM_MGR_SET_CRITICAL):
|
||||
return HandleSetCritical(data, reply);
|
||||
default:
|
||||
return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
|
||||
}
|
||||
return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
|
||||
}
|
||||
|
||||
int32_t MemMgrStub::HandleGetBunldePriorityList(MessageParcel &data, MessageParcel &reply)
|
||||
|
||||
@@ -179,8 +179,7 @@ void MemoryLevelManager::PsiHandler()
|
||||
HILOGE("is not initialized, return!");
|
||||
return;
|
||||
}
|
||||
std::function<void()> func = std::bind(&MemoryLevelManager::PsiHandlerInner, this);
|
||||
handler_->PostImmediateTask(func);
|
||||
handler_->PostImmediateTask([this] { this->PsiHandlerInner(); });
|
||||
}
|
||||
} // namespace Memory
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -65,7 +65,6 @@ IMPLEMENT_SINGLE_INSTANCE(NandLifeController);
|
||||
|
||||
NandLifeController::NandLifeController()
|
||||
{
|
||||
timerFunc_ = std::bind(&NandLifeController::CheckSwapOut, this);
|
||||
}
|
||||
|
||||
bool NandLifeController::Init()
|
||||
@@ -219,7 +218,7 @@ bool NandLifeController::GetSwapOutKBSinceKernelBoot(unsigned long long &ret)
|
||||
void NandLifeController::SetTimer()
|
||||
{
|
||||
// set timer and call CheckSwapOut each TIMER_PEROID_MIN min.
|
||||
handler_->PostTask(timerFunc_, TIMER_PEROID_MS, AppExecFwk::EventQueue::Priority::HIGH);
|
||||
handler_->PostTask([this] { this->CheckSwapOut(); }, TIMER_PEROID_MS, AppExecFwk::EventQueue::Priority::HIGH);
|
||||
HILOGI("[%{public}llu] set timer after %{public}d mins", iter_, TIMER_PEROID_MIN);
|
||||
}
|
||||
|
||||
|
||||
@@ -115,8 +115,7 @@ void PurgeableMemManager::AddSubscriber(const sptr<IAppStateSubscriber> &subscri
|
||||
HILOGE("subscriber is null");
|
||||
return;
|
||||
}
|
||||
std::function<void()> func = std::bind(&PurgeableMemManager::AddSubscriberInner, this, subscriber);
|
||||
handler_->PostImmediateTask(func);
|
||||
handler_->PostImmediateTask([this, subscriber] { this->AddSubscriberInner(subscriber); });
|
||||
}
|
||||
|
||||
void PurgeableMemManager::RemoveSubscriberInner(const sptr<IAppStateSubscriber> &subscriber)
|
||||
@@ -223,8 +222,7 @@ void PurgeableMemManager::RegisterActiveApps(int32_t pid, int32_t uid)
|
||||
HILOGE("is not initialized");
|
||||
return;
|
||||
}
|
||||
std::function<void()> func = std::bind(&PurgeableMemManager::RegisterActiveAppsInner, this, pid, uid);
|
||||
handler_->PostImmediateTask(func);
|
||||
handler_->PostImmediateTask([this, pid, uid] { this->RegisterActiveAppsInner(pid, uid); });
|
||||
}
|
||||
|
||||
void PurgeableMemManager::DeregisterActiveAppsInner(int32_t pid, int32_t uid)
|
||||
@@ -253,8 +251,7 @@ void PurgeableMemManager::DeregisterActiveApps(int32_t pid, int32_t uid)
|
||||
HILOGE("is not initialized");
|
||||
return;
|
||||
}
|
||||
std::function<void()> func = std::bind(&PurgeableMemManager::DeregisterActiveAppsInner, this, pid, uid);
|
||||
handler_->PostImmediateTask(func);
|
||||
handler_->PostImmediateTask([this, pid, uid] { this->DeregisterActiveAppsInner(pid, uid); });
|
||||
}
|
||||
|
||||
void PurgeableMemManager::ChangeAppStateInner(int32_t pid, int32_t uid, int32_t state)
|
||||
@@ -291,8 +288,7 @@ void PurgeableMemManager::ChangeAppState(int32_t pid, int32_t uid, int32_t state
|
||||
HILOGE("is not initialized");
|
||||
return;
|
||||
}
|
||||
std::function<void()> func = std::bind(&PurgeableMemManager::ChangeAppStateInner, this, pid, uid, state);
|
||||
handler_->PostImmediateTask(func);
|
||||
handler_->PostImmediateTask([this, pid, uid, state] { this->ChangeAppStateInner(pid, uid, state); });
|
||||
}
|
||||
|
||||
void PurgeableMemManager::TrimAllSubscribers(const SystemMemoryLevel &level)
|
||||
@@ -657,8 +653,7 @@ void PurgeableMemManager::NotifyMemoryLevel(const SystemMemoryInfo &info)
|
||||
HILOGE("is not initialized");
|
||||
return;
|
||||
}
|
||||
std::function<void()> func = std::bind(&PurgeableMemManager::NotifyMemoryLevelInner, this, info);
|
||||
handler_->PostImmediateTask(func);
|
||||
handler_->PostImmediateTask([this, info] { this->NotifyMemoryLevelInner(info); });
|
||||
}
|
||||
|
||||
bool PurgeableMemManager::ForceReclaimByDump(const DumpReclaimInfo &dumpInfo)
|
||||
|
||||
@@ -77,8 +77,7 @@ void MultiAccountManager::Init()
|
||||
return;
|
||||
}
|
||||
|
||||
std::function<void()> initMultiAccountManagerFunc = std::bind(&MultiAccountManager::Init, this);
|
||||
handler_->PostTask(initMultiAccountManagerFunc, SLEEP_TIME, AppExecFwk::EventQueue::Priority::LOW);
|
||||
handler_->PostTask([this] { this->Init(); }, SLEEP_TIME, AppExecFwk::EventQueue::Priority::LOW);
|
||||
HILOGE("Manager initial failed, try again after 3s!, retryTimes = %{public}d/10", retryTimes_);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -389,8 +389,8 @@ bool ReclaimPriorityManager::UpdateReclaimPriority(UpdateRequest request)
|
||||
return false;
|
||||
}
|
||||
int64_t eventTime = KernelInterface::GetInstance().GetSystemTimeMs();
|
||||
std::function<bool()> updateReclaimPriorityInnerFunc =
|
||||
std::bind(&ReclaimPriorityManager::UpdateReclaimPriorityInner, this, request, eventTime);
|
||||
std::function<void()> updateReclaimPriorityInnerFunc =
|
||||
[this, request, eventTime] { this->UpdateReclaimPriorityInner(request, eventTime); };
|
||||
if (request.reason == AppStateUpdateReason::ABILITY_START) {
|
||||
return handler_->PostTask(updateReclaimPriorityInnerFunc, 0, AppExecFwk::EventQueue::Priority::IMMEDIATE);
|
||||
} else {
|
||||
@@ -457,10 +457,10 @@ bool ReclaimPriorityManager::HandleAbilityStart(const UpdateRequest &request, in
|
||||
|
||||
void ReclaimPriorityManager::SetTimerForAbilityStartCompletedCheck(pid_t pid, int32_t bundleUid, int32_t accountId)
|
||||
{
|
||||
std::function<void()> timerFunc =
|
||||
std::bind(&ReclaimPriorityManager::CheckAbilityStartCompleted, this, pid, bundleUid, accountId);
|
||||
std::string taskName = std::to_string(pid) + AppStateUpdateResonToString(AppStateUpdateReason::ABILITY_START);
|
||||
handler_->PostTask(timerFunc, taskName, TIMER_ABILITY_START_CHECK_MS, AppExecFwk::EventQueue::Priority::LOW);
|
||||
std::string taskName = std::to_string(pid) + AppStateUpdateResonToString(AppStateUpdateReason::ABILITY_START);
|
||||
handler_->PostTask(
|
||||
[this, pid, bundleUid, accountId] { this->CheckAbilityStartCompleted(pid, bundleUid, accountId); },
|
||||
taskName, TIMER_ABILITY_START_CHECK_MS, AppExecFwk::EventQueue::Priority::LOW);
|
||||
HILOGI("set process<pid=%{public}d,uid=%{public}d> ability start check timer after %{public}d ms",
|
||||
pid, bundleUid, TIMER_ABILITY_START_CHECK_MS);
|
||||
}
|
||||
@@ -614,8 +614,7 @@ bool ReclaimPriorityManager::HandleTerminateProcess(ProcessPriorityInfo proc,
|
||||
|
||||
void ReclaimPriorityManager::SetTimerForDiedProcessCheck(int64_t delayTime)
|
||||
{
|
||||
std::function<void()> timerFunc = std::bind(&ReclaimPriorityManager::HandleDiedProcessCheck, this);
|
||||
handler_->PostTask(timerFunc, delayTime, AppExecFwk::EventQueue::Priority::LOW);
|
||||
handler_->PostTask([this] { this->HandleDiedProcessCheck(); }, delayTime, AppExecFwk::EventQueue::Priority::LOW);
|
||||
}
|
||||
|
||||
void ReclaimPriorityManager::FilterDiedProcess()
|
||||
@@ -1166,9 +1165,9 @@ bool ReclaimPriorityManager::OsAccountChanged(int accountId, AccountSA::OS_ACCOU
|
||||
HILOGE("invalid account id!");
|
||||
return false;
|
||||
}
|
||||
std::function<bool()> osAccountChangedInnerFunc =
|
||||
std::bind(&ReclaimPriorityManager::OsAccountChangedInner, this, accountId, switchMod);
|
||||
return handler_->PostImmediateTask(osAccountChangedInnerFunc);
|
||||
return handler_->PostImmediateTask([this, accountId, switchMod] {
|
||||
this->OsAccountChangedInner(accountId, switchMod);
|
||||
});
|
||||
}
|
||||
|
||||
bool ReclaimPriorityManager::OsAccountChangedInner(int accountId, AccountSA::OS_ACCOUNT_SWITCH_MOD switchMod)
|
||||
|
||||
@@ -100,9 +100,7 @@ void ReclaimStrategyManager::NotifyAppStateChanged(std::shared_ptr<ReclaimParam>
|
||||
HILOGE("has not been initialized_, skiped!");
|
||||
return;
|
||||
}
|
||||
std::function<bool()> func = std::bind(
|
||||
&ReclaimStrategyManager::HandleAppStateChanged_, this, reclaimPara);
|
||||
handler_->PostImmediateTask(func);
|
||||
handler_->PostImmediateTask([this, reclaimPara] { this->HandleAppStateChanged_(reclaimPara); });
|
||||
}
|
||||
|
||||
bool ReclaimStrategyManager::HandleAppStateChanged_(std::shared_ptr<ReclaimParam> reclaimPara)
|
||||
@@ -118,11 +116,10 @@ bool ReclaimStrategyManager::HandleAppStateChanged_(std::shared_ptr<ReclaimParam
|
||||
}
|
||||
HILOGI("%{public}s", reclaimPara->ToString().c_str());
|
||||
bool ret = false;
|
||||
bool (ReclaimStrategyManager::*funcPtr)(std::shared_ptr<ReclaimParam>) = nullptr;
|
||||
switch (reclaimPara->action_) {
|
||||
case AppAction::CREATE_PROCESS_AND_APP:
|
||||
case AppAction::CREATE_PROCESS_ONLY: {
|
||||
funcPtr = &ReclaimStrategyManager::HandleProcessCreate_;
|
||||
HandleProcessCreate_(reclaimPara);
|
||||
break;
|
||||
}
|
||||
case AppAction::APP_DIED:
|
||||
@@ -135,9 +132,6 @@ bool ReclaimStrategyManager::HandleAppStateChanged_(std::shared_ptr<ReclaimParam
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (funcPtr != nullptr) {
|
||||
ret = (this->*funcPtr)(reclaimPara);
|
||||
}
|
||||
reclaimPara.reset();
|
||||
return ret;
|
||||
}
|
||||
@@ -160,9 +154,7 @@ void ReclaimStrategyManager::NotifyAccountDied(int accountId)
|
||||
accountId, VALID_USER_ID_MIN);
|
||||
return;
|
||||
}
|
||||
std::function<bool()> func = std::bind(
|
||||
&ReclaimStrategyManager::HandleAccountDied_, this, accountId);
|
||||
handler_->PostImmediateTask(func);
|
||||
handler_->PostImmediateTask([this, accountId] { this->HandleAccountDied_(accountId); });
|
||||
}
|
||||
|
||||
void ReclaimStrategyManager::NotifyAccountPriorityChanged(int accountId, int priority)
|
||||
@@ -176,9 +168,9 @@ void ReclaimStrategyManager::NotifyAccountPriorityChanged(int accountId, int pri
|
||||
accountId, VALID_USER_ID_MIN);
|
||||
return;
|
||||
}
|
||||
std::function<bool()> func = std::bind(
|
||||
&ReclaimStrategyManager::HandleAccountPriorityChanged_, this, accountId, priority);
|
||||
handler_->PostImmediateTask(func);
|
||||
handler_->PostImmediateTask([this, accountId, priority] {
|
||||
this->HandleAccountPriorityChanged_(accountId, priority);
|
||||
});
|
||||
}
|
||||
|
||||
bool ReclaimStrategyManager::HandleAccountDied_(int accountId)
|
||||
|
||||
Reference in New Issue
Block a user