!7264 fix proxy race and sort crash

Merge pull request !7264 from SoftSquirrel/OpenHarmony-5.0.0-Release
This commit is contained in:
openharmony_ci 2024-10-30 03:40:23 +00:00 committed by Gitee
commit 1fac51bc93
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
5 changed files with 31 additions and 39 deletions

View File

@ -233,11 +233,7 @@ public:
ErrCode GetExtensionSandboxTypeList(std::vector<std::string> &typeList);
private:
/**
* @brief Get the installd proxy object.
* @return Returns true if the installd proxy object got successfully; returns false otherwise.
*/
bool GetInstalldProxy();
sptr<IInstalld> GetInstalldProxy();
bool LoadInstalldService();
template<typename F, typename... Args>
@ -246,12 +242,11 @@ private:
int32_t maxRetryTimes = 2;
ErrCode errCode = ERR_APPEXECFWK_INSTALLD_SERVICE_DIED;
for (int32_t retryTimes = 0; retryTimes < maxRetryTimes; retryTimes++) {
if (!GetInstalldProxy()) {
auto proxy = GetInstalldProxy();
if (proxy == nullptr) {
return ERR_APPEXECFWK_INSTALLD_GET_PROXY_ERROR;
}
if (installdProxy_ != nullptr) {
errCode = (installdProxy_->*func)(std::forward<Args>(args)...);
}
errCode = (proxy->*func)(std::forward<Args>(args)...);
if (errCode == ERR_APPEXECFWK_INSTALLD_SERVICE_DIED) {
APP_LOGE("CallService failed, retry times: %{public}d", retryTimes + 1);
ResetInstalldProxy();

View File

@ -50,7 +50,7 @@ bool AgingUtil::SortTwoAgingBundleInfos(AgingBundleInfo &bundle1, AgingBundleInf
return bundle1.GetStartCount() < bundle2.GetStartCount();
}
return bundle1.GetRecentlyUsedTime() <= bundle2.GetRecentlyUsedTime();
return bundle1.GetRecentlyUsedTime() < bundle2.GetRecentlyUsedTime();
}
int64_t AgingUtil::GetUnusedTimeMsBaseOnCurrentTime(int64_t currentTimeMs, int32_t days)

View File

@ -274,31 +274,31 @@ bool InstalldClient::LoadInstalldService()
return true;
}
bool InstalldClient::GetInstalldProxy()
sptr<IInstalld> InstalldClient::GetInstalldProxy()
{
std::lock_guard<std::mutex> lock(getProxyMutex_);
if (installdProxy_ != nullptr) {
APP_LOGD("installd ready");
return true;
return installdProxy_;
}
APP_LOGI("try to get installd proxy");
if (!LoadInstalldService()) {
APP_LOGE("load installd service failed");
return false;
return nullptr;
}
if ((installdProxy_ == nullptr) || (installdProxy_->AsObject() == nullptr)) {
APP_LOGE("the installd proxy or remote object is null");
return false;
return nullptr;
}
recipient_ = new (std::nothrow) InstalldDeathRecipient();
if (recipient_ == nullptr) {
APP_LOGE("the death recipient is nullptr");
return false;
return nullptr;
}
installdProxy_->AsObject()->AddDeathRecipient(recipient_);
return true;
return installdProxy_;
}
ErrCode InstalldClient::ScanDir(
@ -506,7 +506,7 @@ void InstalldClient::OnLoadSystemAbilityFail()
bool InstalldClient::StartInstalldService()
{
return GetInstalldProxy();
return GetInstalldProxy() != nullptr;
}
ErrCode InstalldClient::ExtractEncryptedSoFiles(const std::string &hapPath, const std::string &realSoFilesPath,

View File

@ -219,28 +219,25 @@ void InstalldClient::ResetInstalldProxy()
installdProxy_ = nullptr;
}
bool InstalldClient::GetInstalldProxy()
sptr<IInstalld> InstalldClient::GetInstalldProxy()
{
std::lock_guard<std::mutex> lock(mutex_);
if (installdProxy_ == nullptr) {
APP_LOGD("try to get installd proxy");
std::lock_guard<std::mutex> lock(mutex_);
if (installdProxy_ == nullptr) {
sptr<IInstalld> tempProxy =
iface_cast<IInstalld>(SystemAbilityHelper::GetSystemAbility(INSTALLD_SERVICE_ID));
if ((tempProxy == nullptr) || (tempProxy->AsObject() == nullptr)) {
APP_LOGE("the installd proxy or remote object is null");
return false;
}
recipient_ = new (std::nothrow) InstalldDeathRecipient();
if (recipient_ == nullptr) {
APP_LOGE("the death recipient is nullptr");
return false;
}
tempProxy->AsObject()->AddDeathRecipient(recipient_);
installdProxy_ = tempProxy;
sptr<IInstalld> tempProxy =
iface_cast<IInstalld>(SystemAbilityHelper::GetSystemAbility(INSTALLD_SERVICE_ID));
if ((tempProxy == nullptr) || (tempProxy->AsObject() == nullptr)) {
APP_LOGE("the installd proxy or remote object is null");
return nullptr;
}
recipient_ = new (std::nothrow) InstalldDeathRecipient();
if (recipient_ == nullptr) {
APP_LOGE("the death recipient is nullptr");
return nullptr;
}
tempProxy->AsObject()->AddDeathRecipient(recipient_);
installdProxy_ = tempProxy;
}
return true;
return installdProxy_;
}
ErrCode InstalldClient::ScanDir(
@ -468,7 +465,7 @@ ErrCode InstalldClient::DeleteEncryptionKeyId(const std::string &keyId)
bool InstalldClient::StartInstalldService()
{
return GetInstalldProxy();
return GetInstalldProxy() != nullptr;
}
ErrCode InstalldClient::GetExtensionSandboxTypeList(std::vector<std::string> &typeList)

View File

@ -146,9 +146,9 @@ void InstalldClient::ResetInstalldProxy()
return;
}
bool InstalldClient::GetInstalldProxy()
sptr<IInstalld> InstalldClient::GetInstalldProxy()
{
return true;
return nullptr;
}
ErrCode InstalldClient::ScanDir(
@ -243,7 +243,7 @@ ErrCode InstalldClient::MoveFiles(const std::string &srcDir, const std::string &
bool InstalldClient::StartInstalldService()
{
return GetInstalldProxy();
return GetInstalldProxy() != nullptr;
}
ErrCode InstalldClient::ExtractDriverSoFiles(const std::string &srcPath,