From b7092a7914ffbe226042aef52f376db2b6dcb8db Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 22 Feb 2022 11:04:34 +0800 Subject: [PATCH] add multi-user Signed-off-by: unknown --- .../include/ability_manager_service.h | 1 + .../abilitymgr/include/data_ability_manager.h | 1 + .../src/ability_manager_service.cpp | 26 +++++++++++++++++-- .../abilitymgr/src/data_ability_manager.cpp | 18 +++++++++++++ 4 files changed, 44 insertions(+), 2 deletions(-) diff --git a/services/abilitymgr/include/ability_manager_service.h b/services/abilitymgr/include/ability_manager_service.h index 735a0afb16..7cc47fda65 100644 --- a/services/abilitymgr/include/ability_manager_service.h +++ b/services/abilitymgr/include/ability_manager_service.h @@ -1115,6 +1115,7 @@ private: bool IsSystemUI(const std::string &bundleName) const; bool VerificationAllToken(const sptr &token); + const std::shared_ptr &GetDataAbilityManager(const sptr &scheduler); bool CheckDataAbilityRequest(AbilityRequest &abilityRequest); std::shared_ptr GetStackManagerByUserId(int32_t userId); std::shared_ptr GetListManagerByUserId(int32_t userId); diff --git a/services/abilitymgr/include/data_ability_manager.h b/services/abilitymgr/include/data_ability_manager.h index 5d91f49a4f..a3561ea651 100644 --- a/services/abilitymgr/include/data_ability_manager.h +++ b/services/abilitymgr/include/data_ability_manager.h @@ -49,6 +49,7 @@ public: void DumpState(std::vector &info, const std::string &args = "") const; void DumpSysState(std::vector &info, bool isClient = false, const std::string &args = "") const; void GetAbilityRunningInfos(std::vector &info); + bool ContainsDataAbility(const sptr &scheduler); private: using DataAbilityRecordPtr = std::shared_ptr; diff --git a/services/abilitymgr/src/ability_manager_service.cpp b/services/abilitymgr/src/ability_manager_service.cpp index a2716af04c..60e8f3bd03 100644 --- a/services/abilitymgr/src/ability_manager_service.cpp +++ b/services/abilitymgr/src/ability_manager_service.cpp @@ -1617,12 +1617,17 @@ int AbilityManagerService::ReleaseDataAbility( if (!isSystem) { HILOG_INFO("callerToken not system %{public}s", __func__); if (!VerificationAllToken(callerToken)) { - HILOG_INFO("VerificationAllToken fail"); + HILOG_ERROR("VerificationAllToken fail"); return ERR_INVALID_STATE; } } - return dataAbilityManager_->Release(dataAbilityScheduler, callerToken, isSystem); + std::shared_ptr dataAbilityManager = GetDataAbilityManager(dataAbilityScheduler); + if (!dataAbilityManager) { + HILOG_ERROR("dataAbilityScheduler is not exists"); + } + + return dataAbilityManager->Release(dataAbilityScheduler, callerToken, isSystem); } int AbilityManagerService::AttachAbilityThread( @@ -3080,6 +3085,23 @@ bool AbilityManagerService::VerificationAllToken(const sptr &toke return false; } +const std::shared_ptr &AbilityManagerService::GetDataAbilityManager( + const sptr &scheduler) +{ + if (scheduler == nullptr) { + HILOG_ERROR("the param ability scheduler is nullptr"); + return nullptr; + } + + for (auto item: dataAbilityManagers_) { + if (item.second && item.second->ContainsDataAbility(scheduler)) { + return item.second; + } + } + + return nullptr; +} + std::shared_ptr AbilityManagerService::GetStackManagerByUserId(int32_t userId) { auto it = stackManagers_.find(userId); diff --git a/services/abilitymgr/src/data_ability_manager.cpp b/services/abilitymgr/src/data_ability_manager.cpp index 1e4128d979..898ecdb426 100644 --- a/services/abilitymgr/src/data_ability_manager.cpp +++ b/services/abilitymgr/src/data_ability_manager.cpp @@ -168,6 +168,24 @@ int DataAbilityManager::Release( return ERR_OK; } +bool DataAbilityManager::ContainsDataAbility(const sptr &scheduler) +{ + HILOG_DEBUG("%{public}s(%{public}d)", __PRETTY_FUNCTION__, __LINE__); + + CHECK_POINTER_AND_RETURN(scheduler, ERR_NULL_OBJECT); + + std::lock_guard locker(mutex_); + + DataAbilityRecordPtrMap::iterator it; + for (it = dataAbilityRecordsLoaded_.begin(); it != dataAbilityRecordsLoaded_.end(); ++it) { + if (it->second->GetScheduler() != nullptr && it->second->GetScheduler()->AsObject() == scheduler->AsObject()) { + return true; + } + } + + return false; +} + int DataAbilityManager::AttachAbilityThread(const sptr &scheduler, const sptr &token) { HILOG_DEBUG("%{public}s(%{public}d)", __PRETTY_FUNCTION__, __LINE__);