!2254 revert weak ptr

Merge pull request !2254 from yeyuning/master
This commit is contained in:
openharmony_ci 2024-11-12 02:10:17 +00:00 committed by Gitee
commit f29f02d25a
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
2 changed files with 6 additions and 15 deletions

View File

@ -29,7 +29,7 @@
namespace OHOS {
namespace AccountSA {
class IInnerOsAccountManager : public IInnerOsAccount, public std::enable_shared_from_this<IInnerOsAccountManager> {
class IInnerOsAccountManager : public IInnerOsAccount {
public:
static IInnerOsAccountManager &GetInstance();
void Init() override;

View File

@ -1742,8 +1742,8 @@ void IInnerOsAccountManager::ExecuteDeactivationAnimation(int32_t pipeFd, const
{
std::string pipeFdStr = std::to_string(pipeFd);
std::string displayIdStr = std::to_string(osAccountInfo.GetDisplayId());
char *const args[] = {const_cast<char *>(DEACTIVATION_ANIMATION_PATH),
const_cast<char *>(displayIdStr.c_str()), const_cast<char *>(pipeFdStr.c_str()), nullptr};
char *const args[] = { const_cast<char *>(DEACTIVATION_ANIMATION_PATH),
const_cast<char *>(displayIdStr.c_str()), const_cast<char *>(pipeFdStr.c_str()), nullptr };
if (execv(DEACTIVATION_ANIMATION_PATH, args) == -1) {
ACCOUNT_LOGE("Failed to execv animation: %{public}s", strerror(errno));
ReportOsAccountOperationFail(osAccountInfo.GetLocalId(), "deactivate", errno,
@ -1763,28 +1763,23 @@ ErrCode IInnerOsAccountManager::WaitForAnimationReady(int32_t pipeFd)
int ret = poll(fds, 1, MAX_WAIT_ANIMATION_READY_TIMEOUT);
if (ret < 0) {
ACCOUNT_LOGE("Error in poll: %{public}s", strerror(errno));
close(pipeFd);
return ERR_OSACCOUNT_SERVICE_INNER_ANIMATION_POLL_ERROR;
}
if (ret == 0) {
ACCOUNT_LOGE("Timeout waiting for message from child process.");
close(pipeFd);
return ERR_OSACCOUNT_SERVICE_INNER_ANIMATION_TIMEOUT;
}
if (!(fds[0].revents & POLLIN)) {
ACCOUNT_LOGE("Unexpected event in poll: %{public}d", fds[0].revents);
close(pipeFd);
return ERR_OSACCOUNT_SERVICE_INNER_ANIMATION_UNEXPECTED_EVENT;
}
ssize_t bytesRead = read(pipeFd, buf, sizeof(buf));
if (bytesRead <= 0) {
ACCOUNT_LOGE("Error reading from pipe: %{public}s", strerror(errno));
close(pipeFd);
return ERR_OSACCOUNT_SERVICE_INNER_ANIMATION_READ_ERROR;
}
buf[bytesRead] = '\0';
ACCOUNT_LOGI("Received message from child process: %{public}s", buf);
close(pipeFd);
return ERR_OK;
}
@ -1816,6 +1811,7 @@ void IInnerOsAccountManager::LaunchDeactivationAnimation(const OsAccountInfo &os
ErrCode ret = WaitForAnimationReady(pipeFd[PIPE_READ_END]);
ReportOsAccountOperationFail(localId, "deactivate", ret,
"Failed to launch deactivation animation, wait msg error");
close(pipeFd[PIPE_READ_END]);
} else {
ACCOUNT_LOGE("Failed to fork deactivation animation process: %{public}s", strerror(errno));
ReportOsAccountOperationFail(localId, "deactivate", errno,
@ -2053,14 +2049,9 @@ ErrCode IInnerOsAccountManager::IsOsAccountCompleted(const int id, bool &isOsAcc
void IInnerOsAccountManager::CleanGarbageOsAccountsAsync()
{
std::weak_ptr<IInnerOsAccountManager> weakThis = weak_from_this();
auto task = [weakThis] {
if (auto sharedThis = weakThis.lock()) {
sharedThis->CleanGarbageOsAccounts();
}
};
auto task = [] { IInnerOsAccountManager::GetInstance().CleanGarbageOsAccounts(); };
std::thread cleanThread(task);
pthread_setname_np(cleanThread.native_handle(), "CleanGarbageOsAccounts");
pthread_setname_np(cleanThread.native_handle(), "CleanGarbage");
cleanThread.detach();
}