diff --git a/commondependency/include/deviceprofile_connector.h b/commondependency/include/deviceprofile_connector.h index cf3c8e51fc125facbf1b9bf7c775704c225827ed..fb95f058bf83f0e09b71596509d6651da9a42474 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 ee5930d8c4ed85bda88520a3df40b0acb0d8fafd..58803d67e841d97e2b9113aa0fa37075a27c9430 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 c9716d65a4bb94719c11bfa0ab41aca040f4fea7..bbea5de223b1ef5966bc6d113fae82dc735d6e5f 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 13ce9b5c1b2f4717d73847acf011fa7afe200579..37c1dbecdcc71cc9f35f3678d0e14b53c6838f12 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 52c3a2478d3a3022c43ed5231e289cc88f761025..c7f35e4a84a42594b08f286a1bdce0409920f448 100644 --- a/services/implementation/include/device_manager_service_impl.h +++ b/services/implementation/include/device_manager_service_impl.h @@ -132,6 +132,8 @@ public: void HandleDeviceScreenStatusChange(DmDeviceInfo &devInfo); int32_t StopAuthenticateDevice(const std::string &pkgName); void HandleCredentialAuthStatus(uint16_t deviceTypeId, int32_t errcode); + 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 accb95b689eb39322ac5b08b8ef7bc834428eeca..c561b19e65b3be7c72425fc818e7bcf44e058016 100644 --- a/services/implementation/include/device_manager_service_impl_lite.h +++ b/services/implementation/include/device_manager_service_impl_lite.h @@ -138,6 +138,7 @@ public: void HandleUserSwitched(int32_t switchUserId); int32_t StopAuthenticateDevice(const std::string &pkgName); void HandleCredentialAuthStatus(uint16_t deviceTypeId, int32_t errcode); + 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 1fabdfe0b4a1b363aaf347b5101a2ede71234215..23041ff9d61002848a4ef12966eefa3b0dbb476f 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_); } @@ -2451,5 +2476,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 035330be9f95c7d082fbe95d07278e1fa467bd28..08045a9b4fa2663a5faa51ee22a69f8689292c68 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 23127a2383e20f3b876df92da245923ae3278e12..a5efd68a5cdb81c978546e02048cd7b5e529d214 100644 --- a/services/implementation/src/device_manager_service_impl.cpp +++ b/services/implementation/src/device_manager_service_impl.cpp @@ -859,6 +859,43 @@ void DeviceManagerServiceImpl::HandleCredentialAuthStatus(uint16_t deviceTypeId, deviceStateMgr_->HandleCredentialAuthStatus(deviceTypeId, errcode); } +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 24cf8559b3c13e1e1d63eb257e12cefe2e671c3c..28b66e4e10333d4085151a8ad37f9c4a8fefb3a4 100644 --- a/services/implementation/src/device_manager_service_impl_lite.cpp +++ b/services/implementation/src/device_manager_service_impl_lite.cpp @@ -531,6 +531,13 @@ void DeviceManagerServiceImpl::HandleCredentialAuthStatus(uint16_t deviceTypeId, return; } +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 53040f5a08e792bf2e3e7218ebae16bb40198c27..e3df75866d2ad6fac9367e0f92d69ec444e9433d 100644 --- a/services/service/include/device_manager_service_listener.h +++ b/services/service/include/device_manager_service_listener.h @@ -74,6 +74,8 @@ public: void OnDeviceTrustChange(const std::string &udid, const std::string &uuid, DmAuthForm authForm) override; void OnDeviceScreenStateChange(const std::string &pkgName, DmDeviceInfo &devInfo) override; void OnCredentialAuthStatus(const std::string &pkgName, uint16_t deviceTypeId, int32_t errcode) 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 cb63dc1b278a434a54ab7da1362f3cdfbaf17f14..eb17b151101bc835a575e190394fc93df419de5e 100644 --- a/services/service/include/idevice_manager_service_impl.h +++ b/services/service/include/idevice_manager_service_impl.h @@ -274,6 +274,7 @@ public: virtual void HandleUserSwitched(int32_t switchUserId) = 0; virtual int32_t StopAuthenticateDevice(const std::string &pkgName) = 0; virtual void HandleCredentialAuthStatus(uint16_t deviceTypeId, int32_t errcode) = 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 f727c8a520c6a0d2e0b8f094d446c98c32e728e0..a1d276dca8eccb22ec07be46549543fac527929c 100644 --- a/services/service/include/idevice_manager_service_listener.h +++ b/services/service/include/idevice_manager_service_listener.h @@ -166,6 +166,7 @@ public: */ virtual void OnCredentialAuthStatus(const std::string &pkgName, uint16_t deviceTypeId, int32_t errcode) = 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 fec36d16c1c2bb606dfd3b1f1768221049694dc5..f0964d173e19744402e24b61933ebecea8c05106 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 557a0304dc8cea48c2b3434567d5b1fae740c016..fc07f1c038022231af95c7262f3c1d01e9e1ccd4 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 c50cb827758113253bfd76c7283cb19c38d1ca60..7478a10bfadafdd26b06230e340e6c2aa1d22f40 100644 --- a/services/service/src/device_manager_service_listener.cpp +++ b/services/service/src/device_manager_service_listener.cpp @@ -572,5 +572,17 @@ void DeviceManagerServiceListener::OnCredentialAuthStatus(const std::string &pkg ipcServerListener_.SendRequest(SERVICE_CREDENTIAL_AUTH_STATUS_NOTIFY, pReq, pRsp); } } + +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 f394e5f4a74ef5184c0ca37f70744ac1073514a1..d49a5d8faa97f572052e567a1b02a4045bb662a5 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 2dc430adac8c0dc86812d5ea20f995c427fcaaf1..cfe307aa1c95a3902f398a3632679f156a01661c 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 9a90655b06ae9b67494a8c9f8c748a5f9be418e4..1434de1941bf4d39493ee3f9666e7f79a9f9c2d8 100644 --- a/test/unittest/UTTest_dm_pin_holder.h +++ b/test/unittest/UTTest_dm_pin_holder.h @@ -199,6 +199,11 @@ public: (void)deviceTypeId; (void)errcode; } + + 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 a97d1a3ef2061e0d467d20a2b9375b31fffaec5a..33927be8e12c8be97d5339d12d44a2b5d7835f67 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 2ee9069b75eb11fd1927523c479312436bb9a346..6843378672392deba429720c56e0b80d5680ff46 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 72a9ac4650b316359555b295955275251b002514..ea3ab90ccebed693a414b9eb0ff0487e420558c6 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 0d6eddab467d96d3bb4abfb7b0fb93d19ad440e2..63935cd2b5126ac3fe25ce028db84d93e5015b83 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