mirror of
https://gitee.com/openharmony/bundlemanager_bundle_framework
synced 2024-11-23 07:09:53 +00:00
commit
d7757e057f
@ -558,16 +558,6 @@ private:
|
||||
*/
|
||||
bool WaitForRemoteProcessExit(std::list<pid_t> &pids, const int64_t startTime);
|
||||
|
||||
/**
|
||||
* GetPidsByBundleName, Get the corresponding pid collection through the bundle name.
|
||||
*
|
||||
* @param bundleName, bundle name in Application record.
|
||||
* @param pids, process number collection to exit.
|
||||
*
|
||||
* @return true, return back success,others fail.
|
||||
*/
|
||||
bool GetPidsByBundleName(const std::string &bundleName, std::list<pid_t> &pids);
|
||||
|
||||
/**
|
||||
* GetAllPids, Get the corresponding pid collection.
|
||||
*
|
||||
|
@ -58,7 +58,7 @@ public:
|
||||
*
|
||||
* @return process record.
|
||||
*/
|
||||
std::shared_ptr<AppRunningRecord> GetAppRunningRecordByAppName(const std::string &appName) const;
|
||||
std::shared_ptr<AppRunningRecord> GetAppRunningRecordByAppName(const std::string &appName);
|
||||
|
||||
/**
|
||||
* GetAppRunningRecordByProcessName, Get process record by application name and process Name.
|
||||
@ -69,7 +69,7 @@ public:
|
||||
* @return process record.
|
||||
*/
|
||||
std::shared_ptr<AppRunningRecord> GetAppRunningRecordByProcessName(
|
||||
const std::string &appName, const std::string &processName) const;
|
||||
const std::string &appName, const std::string &processName);
|
||||
|
||||
/**
|
||||
* GetAppRunningRecordByPid, Get process record by application pid.
|
||||
@ -78,7 +78,7 @@ public:
|
||||
*
|
||||
* @return process record.
|
||||
*/
|
||||
std::shared_ptr<AppRunningRecord> GetAppRunningRecordByPid(const pid_t pid) const;
|
||||
std::shared_ptr<AppRunningRecord> GetAppRunningRecordByPid(const pid_t pid);
|
||||
|
||||
/**
|
||||
* GetAppRunningRecordByAbilityToken, Get process record by ability token.
|
||||
@ -87,7 +87,7 @@ public:
|
||||
*
|
||||
* @return process record.
|
||||
*/
|
||||
std::shared_ptr<AppRunningRecord> GetAppRunningRecordByAbilityToken(const sptr<IRemoteObject> &abilityToken) const;
|
||||
std::shared_ptr<AppRunningRecord> GetAppRunningRecordByAbilityToken(const sptr<IRemoteObject> &abilityToken);
|
||||
|
||||
/**
|
||||
* OnRemoteDied, Equipment death notification.
|
||||
@ -102,7 +102,7 @@ public:
|
||||
*
|
||||
* @return the application record list.
|
||||
*/
|
||||
const std::map<const int32_t, const std::shared_ptr<AppRunningRecord>> &GetAppRunningRecordMap() const;
|
||||
const std::map<const int32_t, const std::shared_ptr<AppRunningRecord>> &GetAppRunningRecordMap();
|
||||
|
||||
/**
|
||||
* RemoveAppRunningRecordById, Remove application information through application id.
|
||||
@ -119,8 +119,10 @@ public:
|
||||
*/
|
||||
void ClearAppRunningRecordMap();
|
||||
|
||||
bool GetPidsByBundleName(const std::string &bundleName, std::list<pid_t> &pids);
|
||||
private:
|
||||
std::map<const int32_t, const std::shared_ptr<AppRunningRecord>> appRunningRecordMap_;
|
||||
std::recursive_mutex lock_;
|
||||
};
|
||||
|
||||
} // namespace AppExecFwk
|
||||
|
@ -207,10 +207,14 @@ void AppMgrServiceInner::ApplicationTerminated(const int32_t recordId)
|
||||
|
||||
int32_t AppMgrServiceInner::KillApplication(const std::string &bundleName)
|
||||
{
|
||||
if (!appRunningManager_) {
|
||||
APP_LOGE("appRunningManager_ is nullptr");
|
||||
return ERR_NO_INIT;
|
||||
}
|
||||
int result = ERR_OK;
|
||||
int64_t startTime = SystemTimeMillis();
|
||||
std::list<pid_t> pids;
|
||||
if (!GetPidsByBundleName(bundleName, pids)) {
|
||||
if (!appRunningManager_->GetPidsByBundleName(bundleName, pids)) {
|
||||
APP_LOGI("The process corresponding to the package name did not start");
|
||||
return result;
|
||||
}
|
||||
@ -324,22 +328,6 @@ bool AppMgrServiceInner::WaitForRemoteProcessExit(std::list<pid_t> &pids, const
|
||||
return false;
|
||||
}
|
||||
|
||||
bool AppMgrServiceInner::GetPidsByBundleName(const std::string &bundleName, std::list<pid_t> &pids)
|
||||
{
|
||||
for (const auto &item : appRunningManager_->GetAppRunningRecordMap()) {
|
||||
const auto &appRecord = item.second;
|
||||
if (appRecord->GetBundleName() == bundleName) {
|
||||
pid_t pid = appRecord->GetPriorityObject()->GetPid();
|
||||
if (pid > 0) {
|
||||
pids.push_back(pid);
|
||||
appRecord->ScheduleProcessSecurityExit();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return (pids.empty() ? false : true);
|
||||
}
|
||||
|
||||
bool AppMgrServiceInner::GetAllPids(std::list<pid_t> &pids)
|
||||
{
|
||||
for (const auto &appTaskInfo : appProcessManager_->GetRecentAppList()) {
|
||||
|
@ -44,6 +44,7 @@ std::shared_ptr<AppRunningRecord> AppRunningManager::GetOrCreateAppRunningRecord
|
||||
const std::shared_ptr<ApplicationInfo> &appInfo, const std::shared_ptr<AbilityInfo> &abilityInfo,
|
||||
const std::string &processName, const int32_t uid, RecordQueryResult &result)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> guard(lock_);
|
||||
result.Reset();
|
||||
if (!token || !appInfo || !abilityInfo) {
|
||||
APP_LOGE("param error");
|
||||
@ -81,8 +82,9 @@ std::shared_ptr<AppRunningRecord> AppRunningManager::GetOrCreateAppRunningRecord
|
||||
return record;
|
||||
}
|
||||
|
||||
std::shared_ptr<AppRunningRecord> AppRunningManager::GetAppRunningRecordByAppName(const std::string &appName) const
|
||||
std::shared_ptr<AppRunningRecord> AppRunningManager::GetAppRunningRecordByAppName(const std::string &appName)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> guard(lock_);
|
||||
auto iter = std::find_if(appRunningRecordMap_.begin(), appRunningRecordMap_.end(), [&appName](const auto &pair) {
|
||||
return pair.second->GetName() == appName;
|
||||
});
|
||||
@ -90,8 +92,9 @@ std::shared_ptr<AppRunningRecord> AppRunningManager::GetAppRunningRecordByAppNam
|
||||
}
|
||||
|
||||
std::shared_ptr<AppRunningRecord> AppRunningManager::GetAppRunningRecordByProcessName(
|
||||
const std::string &appName, const std::string &processName) const
|
||||
const std::string &appName, const std::string &processName)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> guard(lock_);
|
||||
auto iter = std::find_if(
|
||||
appRunningRecordMap_.begin(), appRunningRecordMap_.end(), [&appName, &processName](const auto &pair) {
|
||||
return ((pair.second->GetName() == appName) && (pair.second->GetProcessName() == processName));
|
||||
@ -99,8 +102,9 @@ std::shared_ptr<AppRunningRecord> AppRunningManager::GetAppRunningRecordByProces
|
||||
return ((iter == appRunningRecordMap_.end()) ? nullptr : iter->second);
|
||||
}
|
||||
|
||||
std::shared_ptr<AppRunningRecord> AppRunningManager::GetAppRunningRecordByPid(const pid_t pid) const
|
||||
std::shared_ptr<AppRunningRecord> AppRunningManager::GetAppRunningRecordByPid(const pid_t pid)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> guard(lock_);
|
||||
auto iter = std::find_if(appRunningRecordMap_.begin(), appRunningRecordMap_.end(), [&pid](const auto &pair) {
|
||||
return pair.second->GetPriorityObject()->GetPid() == pid;
|
||||
});
|
||||
@ -108,8 +112,9 @@ std::shared_ptr<AppRunningRecord> AppRunningManager::GetAppRunningRecordByPid(co
|
||||
}
|
||||
|
||||
std::shared_ptr<AppRunningRecord> AppRunningManager::GetAppRunningRecordByAbilityToken(
|
||||
const sptr<IRemoteObject> &abilityToken) const
|
||||
const sptr<IRemoteObject> &abilityToken)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> guard(lock_);
|
||||
for (const auto &item : appRunningRecordMap_) {
|
||||
const auto &appRecord = item.second;
|
||||
if (appRecord && appRecord->GetAbilityRunningRecordByToken(abilityToken)) {
|
||||
@ -119,8 +124,26 @@ std::shared_ptr<AppRunningRecord> AppRunningManager::GetAppRunningRecordByAbilit
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool AppRunningManager::GetPidsByBundleName(const std::string &bundleName, std::list<pid_t> &pids)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> guard(lock_);
|
||||
for (const auto &item : appRunningRecordMap_) {
|
||||
const auto &appRecord = item.second;
|
||||
if (appRecord && appRecord->GetBundleName() == bundleName) {
|
||||
pid_t pid = appRecord->GetPriorityObject()->GetPid();
|
||||
if (pid > 0) {
|
||||
pids.push_back(pid);
|
||||
appRecord->ScheduleProcessSecurityExit();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return (pids.empty() ? false : true);
|
||||
}
|
||||
|
||||
std::shared_ptr<AppRunningRecord> AppRunningManager::OnRemoteDied(const wptr<IRemoteObject> &remote)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> guard(lock_);
|
||||
if (remote == nullptr) {
|
||||
APP_LOGE("remote is null");
|
||||
return nullptr;
|
||||
@ -148,18 +171,20 @@ std::shared_ptr<AppRunningRecord> AppRunningManager::OnRemoteDied(const wptr<IRe
|
||||
}
|
||||
|
||||
const std::map<const int32_t, const std::shared_ptr<AppRunningRecord>> &AppRunningManager::GetAppRunningRecordMap()
|
||||
const
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> guard(lock_);
|
||||
return appRunningRecordMap_;
|
||||
}
|
||||
|
||||
void AppRunningManager::RemoveAppRunningRecordById(const int32_t recordId)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> guard(lock_);
|
||||
appRunningRecordMap_.erase(recordId);
|
||||
}
|
||||
|
||||
void AppRunningManager::ClearAppRunningRecordMap()
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> guard(lock_);
|
||||
appRunningRecordMap_.clear();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user