From 0462f4f869a82ea805754966a5613dde3ee7247e Mon Sep 17 00:00:00 2001 From: liuzhongming Date: Tue, 15 Oct 2024 09:23:13 +0800 Subject: [PATCH] =?UTF-8?q?=E6=97=A5=E8=90=BD=E7=BE=A4=E7=BB=84=E5=92=8C?= =?UTF-8?q?=E5=8D=B8=E8=BD=BDapp=E5=88=A0=E9=99=A4=E5=8F=AF=E4=BF=A1?= =?UTF-8?q?=E5=85=B3=E7=B3=BB=20Signed-off-by:=20liuzhongming=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../include/deviceprofile_connector.h | 2 + .../src/deviceprofile_connector.cpp | 14 +++ .../include/authentication/dm_auth_manager.h | 3 + .../dependency/hichain/hichain_connector.h | 11 +- .../include/device_manager_service_impl.h | 2 + .../device_manager_service_impl_lite.h | 1 + .../src/authentication/dm_auth_manager.cpp | 51 ++++++++- .../dependency/hichain/hichain_connector.cpp | 104 ++++++++++++------ .../src/device_manager_service_impl.cpp | 37 +++++++ .../src/device_manager_service_impl_lite.cpp | 7 ++ .../include/device_manager_service_listener.h | 1 + .../include/idevice_manager_service_impl.h | 1 + .../idevice_manager_service_listener.h | 2 + .../dm_package_common_event.h | 2 +- .../service/src/device_manager_service.cpp | 8 +- .../src/device_manager_service_listener.cpp | 12 ++ .../dm_package_common_event.cpp | 4 +- .../UTTest_device_manager_service.cpp | 2 +- test/unittest/UTTest_dm_pin_holder.h | 5 + utils/include/appInfo/lite/app_manager.h | 1 + utils/include/appInfo/standard/app_manager.h | 1 + utils/src/appInfo/lite/app_manager.cpp | 5 + utils/src/appInfo/standard/app_manager.cpp | 14 +++ 23 files changed, 247 insertions(+), 43 deletions(-) diff --git a/commondependency/include/deviceprofile_connector.h b/commondependency/include/deviceprofile_connector.h index cf3c8e51f..fb95f058b 100644 --- a/commondependency/include/deviceprofile_connector.h +++ b/commondependency/include/deviceprofile_connector.h @@ -134,6 +134,8 @@ public: int32_t HandleDevUnBindEvent(int32_t remoteUserId, const std::string &remoteUdid, const std::string &localUdid); std::string HandleAppUnBindEvent(int32_t remoteUserId, const std::string &remoteUdid, int32_t tokenId, const std::string &localUdid); + std::vector GetAllAccessControlProfile(); + void DeleteAccessControlById(int64_t accessControlId); private: int32_t HandleDmAuthForm(DistributedDeviceProfile::AccessControlProfile profiles, DmDiscoveryInfo discoveryInfo); diff --git a/commondependency/src/deviceprofile_connector.cpp b/commondependency/src/deviceprofile_connector.cpp index ee5930d8c..58803d67e 100644 --- a/commondependency/src/deviceprofile_connector.cpp +++ b/commondependency/src/deviceprofile_connector.cpp @@ -979,6 +979,20 @@ std::string DeviceProfileConnector::HandleAppUnBindEvent(int32_t remoteUserId, c return pkgName; } +std::vector DeviceProfileConnector::GetAllAccessControlProfile() +{ + std::vector profiles; + if (DistributedDeviceProfileClient::GetInstance().GetAllAccessControlProfile(profiles) != DM_OK) { + LOGE("DP failed."); + } + return profiles; +} + +void DeviceProfileConnector::DeleteAccessControlById(int64_t accessControlId) +{ + DistributedDeviceProfileClient::GetInstance().DeleteAccessControlProfile(accessControlId); +} + IDeviceProfileConnector *CreateDpConnectorInstance() { return &DeviceProfileConnector::GetInstance(); diff --git a/services/implementation/include/authentication/dm_auth_manager.h b/services/implementation/include/authentication/dm_auth_manager.h index c9716d65a..bbea5de22 100644 --- a/services/implementation/include/authentication/dm_auth_manager.h +++ b/services/implementation/include/authentication/dm_auth_manager.h @@ -464,6 +464,7 @@ public: private: int32_t CheckAuthParamVaild(const std::string &pkgName, int32_t authType, const std::string &deviceId, const std::string &extra); + int32_t CheckAuthParamVaildExtra(const std::string &extra); void ProcessSourceMsg(); void ProcessSinkMsg(); std::string GetAccountGroupIdHash(); @@ -528,6 +529,8 @@ private: int32_t GetTaskTimeout(const char* taskName, int32_t taskTimeOut); void GetPeerUdidHash(int32_t sessionId, std::string &peerUdidHash); void DeleteOffLineTimer(int32_t sessionId); + bool IsAllowDeviceBind(); + int32_t GetBindLevel(int32_t bindLevel); private: std::shared_ptr softbusConnector_; diff --git a/services/implementation/include/dependency/hichain/hichain_connector.h b/services/implementation/include/dependency/hichain/hichain_connector.h index 13ce9b5c1..37c1dbecd 100644 --- a/services/implementation/include/dependency/hichain/hichain_connector.h +++ b/services/implementation/include/dependency/hichain/hichain_connector.h @@ -166,8 +166,12 @@ public: * @tc.desc: Get GroupInfo of the HiChain Connector * @tc.type: FUNC */ - int32_t GetGroupInfo(const int32_t userId, const std::string &queryParams, std::vector &groupList); + bool GetGroupInfo(const int32_t userId, const std::string &queryParams, std::vector &groupList); + + bool GetGroupInfoExt(const int32_t userId, const std::string &queryParams, std::vector &groupList); + bool GetGroupInfoCommon(const int32_t userId, const std::string &queryParams, const char* pkgName, + std::vector &groupList); /** * @tc.name: HiChainConnector::GetGroupType * @tc.desc: Get GroupType of the HiChain Connector @@ -237,6 +241,11 @@ public: std::vector &groupList); void DeleteAllGroupByUdid(const std::string &udid); void DeleteP2PGroup(int32_t switchUserId); + int32_t DeleteGroupByACL(std::vector> &delACLInfoVec, + std::vector &userIdVec); + bool IsNeedDelete(std::string &groupName, int32_t userId, + std::vector> &delACLInfoVec); + private: int64_t GenRequestId(); int32_t SyncGroups(std::string deviceId, std::vector &remoteGroupIdList); diff --git a/services/implementation/include/device_manager_service_impl.h b/services/implementation/include/device_manager_service_impl.h index 8fcd1502f..1b5eed062 100644 --- a/services/implementation/include/device_manager_service_impl.h +++ b/services/implementation/include/device_manager_service_impl.h @@ -131,6 +131,8 @@ public: void HandleIdentAccountLogout(const std::string &udid, int32_t userId, const std::string &accountId); void HandleDeviceScreenStatusChange(DmDeviceInfo &devInfo); int32_t StopAuthenticateDevice(const std::string &pkgName); + int32_t ProcessAppUnintall(const std::string &appId, int32_t accessTokenId); + private: int32_t PraseNotifyEventJson(const std::string &event, nlohmann::json &jsonObject); std::string GetUdidHashByNetworkId(const std::string &networkId); diff --git a/services/implementation/include/device_manager_service_impl_lite.h b/services/implementation/include/device_manager_service_impl_lite.h index 788447f84..9bd447c78 100644 --- a/services/implementation/include/device_manager_service_impl_lite.h +++ b/services/implementation/include/device_manager_service_impl_lite.h @@ -137,6 +137,7 @@ public: void HandleDeviceScreenStatusChange(DmDeviceInfo &devInfo); void HandleUserSwitched(int32_t switchUserId); int32_t StopAuthenticateDevice(const std::string &pkgName); + int32_t ProcessAppUnintall(const std::string &appId, int32_t accessTokenId); private: std::string GetUdidHashByNetworkId(const std::string &networkId); diff --git a/services/implementation/src/authentication/dm_auth_manager.cpp b/services/implementation/src/authentication/dm_auth_manager.cpp index f5fb9c185..181fd9224 100644 --- a/services/implementation/src/authentication/dm_auth_manager.cpp +++ b/services/implementation/src/authentication/dm_auth_manager.cpp @@ -26,6 +26,7 @@ #endif #include "system_ability_definition.h" +#include "app_manager.h" #include "auth_message_processor.h" #include "common_event_support.h" #include "dm_ability_manager.h" @@ -164,6 +165,25 @@ int32_t DmAuthManager::CheckAuthParamVaild(const std::string &pkgName, int32_t a return DM_OK; } +int32_t DmAuthManager::CheckAuthParamVaildExtra(const std::string &extra) +{ + nlohmann::json jsonObject = nlohmann::json::parse(extra, nullptr, false); + if (!jsonObject.is_discarded()) { + if (IsInt32(jsonObject, TAG_BIND_LEVEL)) { + int32_t bindLevel = jsonObject[TAG_BIND_LEVEL].get(); + if (bindLevel > APP || bindLevel < INVALID_TYPE) { + LOGE("bindlevel error %{public}d.", bindLevel); + return ERR_DM_INPUT_PARA_INVALID; + } + if (bindLevel == DEVICE && !IsAllowDeviceBind()) { + LOGE("not allowd device level bind bindlevel: %{public}d.", bindLevel); + return ERR_DM_INPUT_PARA_INVALID; + } + } + } + return DM_OK; +} + void DmAuthManager::GetAuthParam(const std::string &pkgName, int32_t authType, const std::string &deviceId, const std::string &extra) { @@ -207,6 +227,7 @@ void DmAuthManager::GetAuthParam(const std::string &pkgName, int32_t authType, if (IsInt32(jsonObject, TAG_BIND_LEVEL)) { authRequestContext_->bindLevel = jsonObject[TAG_BIND_LEVEL].get(); } + authRequestContext_->bindLevel = GetBindLevel(authRequestContext_->bindLevel); } authRequestContext_->token = std::to_string(GenRandInt(MIN_PIN_TOKEN, MAX_PIN_TOKEN)); } @@ -247,6 +268,11 @@ int32_t DmAuthManager::AuthenticateDevice(const std::string &pkgName, int32_t au LOGE("DmAuthManager::AuthenticateDevice failed, param is invaild."); return ret; } + ret = CheckAuthParamVaildExtra(extra); + if (ret != DM_OK) { + LOGE("CheckAuthParamVaildExtra failed, param is invaild."); + return ret; + } isAuthenticateDevice_ = true; if (authType == AUTH_TYPE_CRE) { LOGI("DmAuthManager::AuthenticateDevice for credential type, joinLNN directly."); @@ -1229,8 +1255,7 @@ void DmAuthManager::AuthenticateFinish() } if (DeviceProfileConnector::GetInstance().GetTrustNumber(remoteDeviceId_) >= 1 && CompareVersion(remoteVersion_, std::string(DM_VERSION_4_1_5_1)) && - authResponseContext_->bindLevel == INVALIED_TYPE && softbusConnector_->CheckIsOnline(remoteDeviceId_) && - authResponseContext_->isFinish) { + softbusConnector_->CheckIsOnline(remoteDeviceId_) && authResponseContext_->isFinish) { softbusConnector_->HandleDeviceOnline(remoteDeviceId_, authForm_); } @@ -2450,5 +2475,27 @@ int32_t DmAuthManager::GetTaskTimeout(const char* taskName, int32_t taskTimeOut) } return taskTimeOut; } + +bool DmAuthManager::IsAllowDeviceBind() +{ + if (AppManager::GetInstance().IsSystemSA()) { + return true; + } + return false; +} + +int32_t DmAuthManager::GetBindLevel(int32_t bindLevel) +{ + if (IsAllowDeviceBind()) { + if (bindLevel == INVALIED_TYPE || bindLevel > APP || bindLevel < DEVICE) { + return DEVICE; + } + return bindLevel; + } + if (bindLevel == INVALIED_TYPE || (bindLevel != APP && bindLevel != SERVICE)) { + return APP; + } + return bindLevel; +} } // namespace DistributedHardware } // namespace OHOS diff --git a/services/implementation/src/dependency/hichain/hichain_connector.cpp b/services/implementation/src/dependency/hichain/hichain_connector.cpp index 035330be9..08045a9b4 100644 --- a/services/implementation/src/dependency/hichain/hichain_connector.cpp +++ b/services/implementation/src/dependency/hichain/hichain_connector.cpp @@ -40,6 +40,7 @@ const int32_t CREDENTIAL_NETWORK = 1; const int32_t DELAY_TIME_MS = 10000; // 10ms const int32_t FIELD_EXPIRE_TIME_VALUE = 7; const int32_t SAME_ACCOUNT = 1; +const int32_t DEVICE_ID_HALF = 2; constexpr const char* DEVICE_ID = "DEVICE_ID"; constexpr const char* FIELD_CREDENTIAL = "credential"; @@ -211,53 +212,36 @@ bool HiChainConnector::IsRedundanceGroup(const std::string &userId, int32_t auth bool HiChainConnector::GetGroupInfo(const std::string &queryParams, std::vector &groupList) { - char *groupVec = nullptr; - uint32_t num = 0; int32_t userId = MultipleUserConnector::GetCurrentAccountUserID(); if (userId < 0) { LOGE("get current process account user id failed"); return false; } - int32_t ret = deviceGroupManager_->getGroupInfo(userId, DM_PKG_NAME, queryParams.c_str(), &groupVec, &num); - if (ret != 0) { - LOGE("[HICHAIN]fail to get group info with ret:%{public}d.", ret); - return false; - } - if (groupVec == nullptr) { - LOGE("[HICHAIN]return groups info point is nullptr"); - return false; - } - if (num == 0) { - LOGE("[HICHAIN]return groups info number is zero."); - return false; - } - LOGI("HiChainConnector::GetGroupInfo groupNum(%{public}u)", num); - std::string relatedGroups = std::string(groupVec); - deviceGroupManager_->destroyInfo(&groupVec); - nlohmann::json jsonObject = nlohmann::json::parse(relatedGroups, nullptr, false); - if (jsonObject.is_discarded()) { - LOGE("returnGroups parse error"); - return false; - } - if (!jsonObject.is_array()) { - LOGE("json string is not array."); - return false; - } - std::vector groupInfos = jsonObject.get>(); - if (groupInfos.size() == 0) { - LOGE("HiChainConnector::GetGroupInfo group failed, groupInfos is empty."); - return false; - } - groupList = groupInfos; - return true; + return GetGroupInfo(userId, queryParams, groupList); +} + +bool HiChainConnector::GetGroupInfo(const int32_t userId, const std::string &queryParams, + std::vector &groupList) +{ + return GetGroupInfoCommon(userId, queryParams, DM_PKG_NAME, groupList); } -int32_t HiChainConnector::GetGroupInfo(const int32_t userId, const std::string &queryParams, +bool HiChainConnector::GetGroupInfoExt(const int32_t userId, const std::string &queryParams, + std::vector &groupList) +{ + return GetGroupInfoCommon(userId, queryParams, DM_PKG_NAME_EXT, groupList); +} + +bool HiChainConnector::GetGroupInfoCommon(const int32_t userId, const std::string &queryParams, const char* pkgName, std::vector &groupList) { char *groupVec = nullptr; uint32_t num = 0; - int32_t ret = deviceGroupManager_->getGroupInfo(userId, DM_PKG_NAME, queryParams.c_str(), &groupVec, &num); + if (deviceGroupManager_ == nullptr) { + LOGE("deviceGroupManager_ is null"); + return false; + } + int32_t ret = deviceGroupManager_->getGroupInfo(userId, pkgName, queryParams.c_str(), &groupVec, &num); if (ret != 0) { LOGE("[HICHAIN]fail to get group info with ret:%{public}d.", ret); return false; @@ -1223,5 +1207,53 @@ void HiChainConnector::DeleteP2PGroup(int32_t switchUserId) } } } + +int32_t HiChainConnector::DeleteGroupByACL(std::vector> &delACLInfoVec, + std::vector &userIdVec) +{ + if (delACLInfoVec.size() == 0) { + LOGI("delACLInfoVec is empty"); + return DM_OK; + } + if (userIdVec.size() == 0) { + LOGI("userIdVec is empty"); + return DM_OK; + } + nlohmann::json jsonObj; + jsonObj[FIELD_GROUP_TYPE] = GROUP_TYPE_PEER_TO_PEER_GROUP; + std::string queryParams = jsonObj.dump(); + for (int32_t userId : userIdVec) { + std::vector groupList; + if (!GetGroupInfo(userId, queryParams, groupList)) { + continue; + } + for (auto iter = groupList.begin(); iter != groupList.end(); iter++) { + if (!IsNeedDelete(iter->groupName, userId, delACLInfoVec)) { + continue; + } + if (DeleteGroup(userId, iter->groupId) != DM_OK) { + LOGE("failed to delete group %{public}s", GetAnonyString(iter->groupId).c_str()); + } + } + } + return DM_OK; +} + +bool HiChainConnector::IsNeedDelete(std::string &groupName, int32_t userId, + std::vector> &delACLInfoVec) +{ + if (delACLInfoVec.size() == 0 || groupName.empty()) { + LOGI("delACLInfoVec or groupName is empty"); + return false; + } + for (auto item : delACLInfoVec) { + uint32_t interceptLength = item.second.size() / DEVICE_ID_HALF; + std::string interceptUdid = item.second.substr(0, interceptLength); + if (groupName.find(interceptUdid) != std::string::npos && userId == item.first) { + return true; + } + } + return false; +} } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file diff --git a/services/implementation/src/device_manager_service_impl.cpp b/services/implementation/src/device_manager_service_impl.cpp index dc6d1df62..7935c4697 100644 --- a/services/implementation/src/device_manager_service_impl.cpp +++ b/services/implementation/src/device_manager_service_impl.cpp @@ -853,6 +853,43 @@ void DeviceManagerServiceImpl::HandleDeviceScreenStatusChange(DmDeviceInfo &devI deviceStateMgr_->HandleDeviceScreenStatusChange(devInfo); } +int32_t DeviceManagerServiceImpl::ProcessAppUnintall(const std::string &appId, int32_t accessTokenId) +{ + CHECK_NULL_RETURN(listener_, ERR_DM_POINT_NULL); + std::vector profiles = + DeviceProfileConnector::GetInstance().GetAllAccessControlProfile(); + LOGI("delete ACL size is %{public}zu, appId %{public}s", profiles.size(), GetAnonyString(appId).c_str()); + if (profiles.size() == 0) { + return DM_OK; + } + std::vector> delACLInfoVec; + std::vector userIdVec; + for (auto &item : profiles) { + int64_t tokenId = item.GetAccesser().GetAccesserTokenId(); + if (accessTokenId != static_cast(tokenId)) { + continue; + } + DeviceProfileConnector::GetInstance().DeleteAccessControlById(item.GetAccessControlId()); + listener_->OnAppUnintall(item.GetAccesser().GetAccesserBundleName()); + if (item.GetBindLevel() == DEVICE) { + userIdVec.push_back(item.GetAccesser().GetAccesserUserId()); + delACLInfoVec.push_back(std::pair(item.GetAccesser().GetAccesserUserId(), + item.GetAccessee().GetAccesseeDeviceId())); + } + } + if (delACLInfoVec.size() == 0) { + LOGI("delACLInfoVec is empty"); + return DM_OK; + } + if (userIdVec.size() == 0) { + LOGI("userIdVec is empty"); + return DM_OK; + } + CHECK_NULL_RETURN(hiChainConnector_, ERR_DM_POINT_NULL); + hiChainConnector_->DeleteGroupByACL(delACLInfoVec, userIdVec); + return DM_OK; +} + extern "C" IDeviceManagerServiceImpl *CreateDMServiceObject(void) { return new DeviceManagerServiceImpl; diff --git a/services/implementation/src/device_manager_service_impl_lite.cpp b/services/implementation/src/device_manager_service_impl_lite.cpp index de163f557..5a325a36e 100644 --- a/services/implementation/src/device_manager_service_impl_lite.cpp +++ b/services/implementation/src/device_manager_service_impl_lite.cpp @@ -524,6 +524,13 @@ int32_t DeviceManagerServiceImpl::StopAuthenticateDevice(const std::string &pkgN return 0; } +int32_t ProcessAppUnintall(const std::string &appId, int32_t accessTokenId) +{ + (void)appId; + (void)accessTokenId; + return 0; +} + extern "C" IDeviceManagerServiceImpl *CreateDMServiceObject(void) { return new DeviceManagerServiceImpl; diff --git a/services/service/include/device_manager_service_listener.h b/services/service/include/device_manager_service_listener.h index 7112ecf70..4f2e6ddb9 100644 --- a/services/service/include/device_manager_service_listener.h +++ b/services/service/include/device_manager_service_listener.h @@ -73,6 +73,7 @@ public: const std::string &content) override; void OnDeviceTrustChange(const std::string &udid, const std::string &uuid, DmAuthForm authForm) override; void OnDeviceScreenStateChange(const std::string &pkgName, DmDeviceInfo &devInfo) override; + void OnAppUnintall(const std::string &pkgName) override; private: void ConvertDeviceInfoToDeviceBasicInfo(const std::string &pkgName, const DmDeviceInfo &info, DmDeviceBasicInfo &deviceBasicInfo); diff --git a/services/service/include/idevice_manager_service_impl.h b/services/service/include/idevice_manager_service_impl.h index 90e35e986..a35ad8515 100644 --- a/services/service/include/idevice_manager_service_impl.h +++ b/services/service/include/idevice_manager_service_impl.h @@ -273,6 +273,7 @@ public: virtual void HandleDeviceScreenStatusChange(DmDeviceInfo &devInfo) = 0; virtual void HandleUserSwitched(int32_t switchUserId) = 0; virtual int32_t StopAuthenticateDevice(const std::string &pkgName) = 0; + virtual int32_t ProcessAppUnintall(const std::string &appId, int32_t accessTokenId) = 0; }; using CreateDMServiceFuncPtr = IDeviceManagerServiceImpl *(*)(void); diff --git a/services/service/include/idevice_manager_service_listener.h b/services/service/include/idevice_manager_service_listener.h index 57ab0697f..45922f040 100644 --- a/services/service/include/idevice_manager_service_listener.h +++ b/services/service/include/idevice_manager_service_listener.h @@ -158,6 +158,8 @@ public: * @tc.type: FUNC */ virtual void OnDeviceScreenStateChange(const std::string &pkgName, DmDeviceInfo &devInfo) = 0; + + virtual void OnAppUnintall(const std::string &pkgName) = 0; }; } // namespace DistributedHardware } // namespace OHOS diff --git a/services/service/include/publishcommonevent/dm_package_common_event.h b/services/service/include/publishcommonevent/dm_package_common_event.h index fec36d16c..f0964d173 100644 --- a/services/service/include/publishcommonevent/dm_package_common_event.h +++ b/services/service/include/publishcommonevent/dm_package_common_event.h @@ -33,7 +33,7 @@ namespace DistributedHardware { using OHOS::EventFwk::CommonEventData; using OHOS::EventFwk::CommonEventSubscriber; using OHOS::EventFwk::CommonEventSubscribeInfo; -using PackageEventCallback = std::function; +using PackageEventCallback = std::function; class DmPackageEventSubscriber : public CommonEventSubscriber { public: diff --git a/services/service/src/device_manager_service.cpp b/services/service/src/device_manager_service.cpp index f7b5d0ff2..b027ee120 100755 --- a/services/service/src/device_manager_service.cpp +++ b/services/service/src/device_manager_service.cpp @@ -948,6 +948,9 @@ bool DeviceManagerService::IsDMServiceImplReady() } dmServiceImpl_ = std::shared_ptr(func()); + if (listener_ == nullptr) { + listener_ = std::make_shared(); + } if (dmServiceImpl_->Initialize(listener_) != DM_OK) { dlclose(so_handle); dmServiceImpl_ = nullptr; @@ -1982,7 +1985,10 @@ void DeviceManagerService::SubscribePackageCommonEvent() if (packageCommonEventManager_ == nullptr) { packageCommonEventManager_ = std::make_shared(); } - PackageEventCallback callback = [=](const auto &arg1, const auto &arg2) { + PackageEventCallback callback = [=](const auto &arg1, const auto &arg2, const auto &arg3) { + if (IsDMServiceImplReady()) { + dmServiceImpl_->ProcessAppUnintall(arg1, arg3); + } KVAdapterManager::GetInstance().AppUnintall(arg1); }; std::vector commonEventVec; diff --git a/services/service/src/device_manager_service_listener.cpp b/services/service/src/device_manager_service_listener.cpp index 326326716..4e6dbca86 100644 --- a/services/service/src/device_manager_service_listener.cpp +++ b/services/service/src/device_manager_service_listener.cpp @@ -550,5 +550,17 @@ void DeviceManagerServiceListener::RemoveOnlinePkgName(const DmDeviceInfo &info) } } } + +void DeviceManagerServiceListener::OnAppUnintall(const std::string &pkgName) +{ + std::lock_guard autoLock(alreadyOnlinePkgNameLock_); + for (auto it = alreadyOnlinePkgName_.begin(); it != alreadyOnlinePkgName_.end();) { + if (it->first.find(pkgName) == 0) { + it = alreadyOnlinePkgName_.erase(it); + } else { + ++it; + } + } +} } // namespace DistributedHardware } // namespace OHOS diff --git a/services/service/src/publishcommonevent/dm_package_common_event.cpp b/services/service/src/publishcommonevent/dm_package_common_event.cpp index f394e5f4a..d49a5d8fa 100644 --- a/services/service/src/publishcommonevent/dm_package_common_event.cpp +++ b/services/service/src/publishcommonevent/dm_package_common_event.cpp @@ -36,6 +36,7 @@ using OHOS::EventFwk::CommonEventManager; constexpr const char* DEAL_THREAD = "package_common_event"; #endif const std::string APP_ID = "appId"; +const std::string ACCESS_TOKEN_ID = "accessTokenId"; constexpr int32_t MAX_TRY_TIMES = 3; std::vector DmPackageEventSubscriber::GetSubscriberEventNameVec() const @@ -136,6 +137,7 @@ void DmPackageEventSubscriber::OnReceiveEvent(const CommonEventData &data) { std::string receiveEvent = data.GetWant().GetAction(); std::string appId = data.GetWant().GetStringParam(APP_ID); + int32_t accessTokenId = static_cast(data.GetWant().GetIntParam(ACCESS_TOKEN_ID, 0)); LOGI("Received package event: %{public}s", receiveEvent.c_str()); if (receiveEvent != EventFwk::CommonEventSupport::COMMON_EVENT_PACKAGE_FULLY_REMOVED && @@ -144,7 +146,7 @@ void DmPackageEventSubscriber::OnReceiveEvent(const CommonEventData &data) return; } #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) - ffrt::submit([=]() { callback_(appId, receiveEvent); }); + ffrt::submit([=]() { callback_(appId, receiveEvent, accessTokenId); }); #else std::thread dealThread([=]() { callback_(appId, receiveEvent); }); int32_t ret = pthread_setname_np(dealThread.native_handle(), DEAL_THREAD); diff --git a/test/unittest/UTTest_device_manager_service.cpp b/test/unittest/UTTest_device_manager_service.cpp index e7344fe2a..ca597c5e3 100644 --- a/test/unittest/UTTest_device_manager_service.cpp +++ b/test/unittest/UTTest_device_manager_service.cpp @@ -1187,7 +1187,7 @@ HWTEST_F(DeviceManagerServiceTest, RegisterCallerAppId_001, testing::ext::TestSi { std::string pkgName; DeviceManagerService::GetInstance().RegisterCallerAppId(pkgName); - EXPECT_EQ(DeviceManagerService::GetInstance().listener_, nullptr); + EXPECT_NE(DeviceManagerService::GetInstance().listener_, nullptr); } /** diff --git a/test/unittest/UTTest_dm_pin_holder.h b/test/unittest/UTTest_dm_pin_holder.h index 3a249b3a9..ed607b33b 100644 --- a/test/unittest/UTTest_dm_pin_holder.h +++ b/test/unittest/UTTest_dm_pin_holder.h @@ -192,6 +192,11 @@ public: (void)pkgName; (void)devInfo; } + + void OnAppUnintall(const std::string &pkgName) override + { + (void)pkgName; + } }; } // namespace DistributedHardware } // namespace OHOS diff --git a/utils/include/appInfo/lite/app_manager.h b/utils/include/appInfo/lite/app_manager.h index a97d1a3ef..33927be8e 100644 --- a/utils/include/appInfo/lite/app_manager.h +++ b/utils/include/appInfo/lite/app_manager.h @@ -29,6 +29,7 @@ public: void RegisterCallerAppId(const std::string &pkgName); void UnRegisterCallerAppId(const std::string &pkgName); int32_t GetAppIdByPkgName(const std::string &pkgName, std::string &appId); + bool IsSystemSA(); }; } // namespace DistributedHardware } // namespace OHOS diff --git a/utils/include/appInfo/standard/app_manager.h b/utils/include/appInfo/standard/app_manager.h index 2ee9069b7..684337867 100644 --- a/utils/include/appInfo/standard/app_manager.h +++ b/utils/include/appInfo/standard/app_manager.h @@ -35,6 +35,7 @@ public: void RegisterCallerAppId(const std::string &pkgName); void UnRegisterCallerAppId(const std::string &pkgName); int32_t GetAppIdByPkgName(const std::string &pkgName, std::string &appId); + bool IsSystemSA(); private: bool GetBundleManagerProxy(sptr &bundleManager); std::mutex appIdMapLock_; diff --git a/utils/src/appInfo/lite/app_manager.cpp b/utils/src/appInfo/lite/app_manager.cpp index 72a9ac465..ea3ab90cc 100644 --- a/utils/src/appInfo/lite/app_manager.cpp +++ b/utils/src/appInfo/lite/app_manager.cpp @@ -41,5 +41,10 @@ int32_t AppManager::GetAppIdByPkgName(const std::string &pkgName, std::string &a (void)appId; return DM_OK; } + +bool AppManager::IsSystemSA() +{ + return true; +} } // namespace DistributedHardware } // namespace OHOS diff --git a/utils/src/appInfo/standard/app_manager.cpp b/utils/src/appInfo/standard/app_manager.cpp index 0d6eddab4..63935cd2b 100644 --- a/utils/src/appInfo/standard/app_manager.cpp +++ b/utils/src/appInfo/standard/app_manager.cpp @@ -137,5 +137,19 @@ bool AppManager::GetBundleManagerProxy(sptr &bundleManag } return true; } + +bool AppManager::IsSystemSA() +{ + AccessTokenID tokenCaller = IPCSkeleton::GetCallingTokenID(); + if (tokenCaller == 0) { + LOGE("IsSystemSA GetCallingTokenID error."); + return false; + } + ATokenTypeEnum tokenTypeFlag = AccessTokenKit::GetTokenTypeFlag(tokenCaller); + if (tokenTypeFlag == ATokenTypeEnum::TOKEN_NATIVE) { + return true; + } + return false; +} } // namespace DistributedHardware } // namespace OHOS -- Gitee