mirror of
https://gitee.com/openharmony/account_os_account
synced 2024-11-27 04:00:43 +00:00
!2237 celan garbage when default account unlock
Merge pull request !2237 from yeyuning/clean
This commit is contained in:
commit
b1a2517d48
@ -81,6 +81,7 @@ private:
|
||||
bool CreateAppAccountService();
|
||||
bool CreateIAMService();
|
||||
bool CreateDomainService();
|
||||
bool IsDefaultOsAccountVerified();
|
||||
#ifdef HAS_APP_ACCOUNT_PART
|
||||
void MoveAppAccountData();
|
||||
#endif
|
||||
|
@ -107,6 +107,7 @@ public:
|
||||
virtual ErrCode ActivateDefaultOsAccount() = 0;
|
||||
virtual int32_t CleanGarbageOsAccounts(int32_t excludeId = -1) = 0;
|
||||
virtual void ResetAccountStatus() = 0;
|
||||
virtual void CleanGarbageOsAccountsAsync() = 0;
|
||||
};
|
||||
} // namespace AccountSA
|
||||
} // namespace OHOS
|
||||
|
@ -29,7 +29,7 @@
|
||||
|
||||
namespace OHOS {
|
||||
namespace AccountSA {
|
||||
class IInnerOsAccountManager : public IInnerOsAccount {
|
||||
class IInnerOsAccountManager : public IInnerOsAccount, public std::enable_shared_from_this<IInnerOsAccountManager> {
|
||||
public:
|
||||
static IInnerOsAccountManager &GetInstance();
|
||||
void Init() override;
|
||||
@ -121,6 +121,7 @@ public:
|
||||
int32_t CleanGarbageOsAccounts(int32_t excludeId = -1) override;
|
||||
void ResetAccountStatus() override;
|
||||
bool CheckAndCleanOsAccounts();
|
||||
void CleanGarbageOsAccountsAsync() override;
|
||||
|
||||
private:
|
||||
IInnerOsAccountManager();
|
||||
|
@ -259,6 +259,24 @@ void AccountMgrService::MoveAppAccountData()
|
||||
}
|
||||
#endif
|
||||
|
||||
bool AccountMgrService::IsDefaultOsAccountVerified()
|
||||
{
|
||||
int32_t defaultAccountId = -1;
|
||||
ErrCode errCode = IInnerOsAccountManager::GetInstance().GetDefaultActivatedOsAccount(defaultAccountId);
|
||||
if (errCode != ERR_OK) {
|
||||
ACCOUNT_LOGE("Failed to get default activated OS account, errCode: %{public}d", errCode);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool isVerified = false;
|
||||
errCode = IInnerOsAccountManager::GetInstance().IsOsAccountVerified(defaultAccountId, isVerified);
|
||||
if (errCode != ERR_OK) {
|
||||
ACCOUNT_LOGE("Failed get default activated OS account verified info, errCode: %{public}d", errCode);
|
||||
return false;
|
||||
}
|
||||
return isVerified;
|
||||
}
|
||||
|
||||
void AccountMgrService::OnAddSystemAbility(int32_t systemAbilityId, const std::string &deviceId)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(statusMutex_);
|
||||
@ -304,6 +322,9 @@ void AccountMgrService::OnAddSystemAbility(int32_t systemAbilityId, const std::s
|
||||
isDefaultOsAccountActivated_ = true;
|
||||
}
|
||||
}
|
||||
if (isBmsReady_ && IsDefaultOsAccountVerified()) {
|
||||
IInnerOsAccountManager::GetInstance().CleanGarbageOsAccountsAsync();
|
||||
}
|
||||
}
|
||||
|
||||
bool AccountMgrService::Init()
|
||||
|
@ -1935,11 +1935,6 @@ ErrCode IInnerOsAccountManager::SendToStorageAccountStart(OsAccountInfo &osAcco
|
||||
OsAccountInterface::PublishCommonEvent(osAccountInfo,
|
||||
OHOS::EventFwk::CommonEventSupport::COMMON_EVENT_USER_UNLOCKED, Constants::OPERATION_UNLOCK);
|
||||
subscribeManager_.Publish(localId, OS_ACCOUNT_SUBSCRIBE_TYPE::UNLOCKED);
|
||||
|
||||
auto task = [] { IInnerOsAccountManager::GetInstance().CleanGarbageOsAccounts(); };
|
||||
std::thread cleanThread(task);
|
||||
pthread_setname_np(cleanThread.native_handle(), "CleanGarbageOsAccounts");
|
||||
cleanThread.detach();
|
||||
}
|
||||
return ERR_OK;
|
||||
}
|
||||
@ -2051,6 +2046,19 @@ ErrCode IInnerOsAccountManager::IsOsAccountCompleted(const int id, bool &isOsAcc
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
void IInnerOsAccountManager::CleanGarbageOsAccountsAsync()
|
||||
{
|
||||
std::weak_ptr<IInnerOsAccountManager> weakThis = weak_from_this();
|
||||
auto task = [weakThis] {
|
||||
if (auto sharedThis = weakThis.lock()) {
|
||||
sharedThis->CleanGarbageOsAccounts();
|
||||
}
|
||||
};
|
||||
std::thread cleanThread(task);
|
||||
pthread_setname_np(cleanThread.native_handle(), "CleanGarbageOsAccounts");
|
||||
cleanThread.detach();
|
||||
}
|
||||
|
||||
ErrCode IInnerOsAccountManager::SetOsAccountIsVerified(const int id, const bool isVerified)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(*GetOrInsertUpdateLock(id));
|
||||
@ -2085,10 +2093,7 @@ ErrCode IInnerOsAccountManager::SetOsAccountIsVerified(const int id, const bool
|
||||
OHOS::EventFwk::CommonEventSupport::COMMON_EVENT_USER_UNLOCKED, Constants::OPERATION_UNLOCK);
|
||||
subscribeManager_.Publish(id, OS_ACCOUNT_SUBSCRIBE_TYPE::UNLOCKED);
|
||||
|
||||
auto task = [] { IInnerOsAccountManager::GetInstance().CleanGarbageOsAccounts(); };
|
||||
std::thread cleanThread(task);
|
||||
pthread_setname_np(cleanThread.native_handle(), "CleanGarbageOsAccounts");
|
||||
cleanThread.detach();
|
||||
CleanGarbageOsAccountsAsync();
|
||||
}
|
||||
|
||||
return ERR_OK;
|
||||
|
Loading…
Reference in New Issue
Block a user