From f88c11480996059a2207f6e30843e55f71a367a4 Mon Sep 17 00:00:00 2001 From: l60055366 Date: Wed, 8 Jan 2025 18:07:40 +0800 Subject: [PATCH 01/10] =?UTF-8?q?=E4=BF=AE=E5=A4=8Ddm=E6=A8=A1=E5=9D=975.0?= =?UTF-8?q?.2=E7=9A=84=E5=B7=AE=E5=BC=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: l60055366 --- .../include/device_manager_service_listener.h | 8 +- .../notify/device_manager_service_notify.h | 41 ++++++ .../service/src/device_manager_service.cpp | 57 +++++++-- .../src/device_manager_service_listener.cpp | 119 +++++++++++++----- .../service/src/hichain/hichain_listener.cpp | 114 +++++++++++++++++ .../service/src/ipc/lite/ipc_cmd_parser.cpp | 12 ++ .../src/ipc/standard/ipc_cmd_parser.cpp | 13 ++ .../src/ipc/standard/ipc_server_stub.cpp | 19 ++- .../notify/device_manager_service_notify.cpp | 108 ++++++++++++++++ .../dm_account_common_event.cpp | 12 +- .../service/src/softbus/softbus_listener.cpp | 1 + .../softbuscache/include/dm_softbus_cache.h | 2 +- .../softbuscache/src/dm_softbus_cache.cpp | 17 ++- test/commonunittest/UTTest_dm_timer.cpp | 2 +- .../UTTest_device_manager_notify_two.cpp | 6 +- .../UTTest_device_manager_service_two.cpp | 2 +- utils/src/kvadapter/kv_adapter.cpp | 2 +- 17 files changed, 477 insertions(+), 58 deletions(-) create mode 100644 services/service/include/notify/device_manager_service_notify.h create mode 100644 services/service/src/hichain/hichain_listener.cpp create mode 100644 services/service/src/notify/device_manager_service_notify.cpp diff --git a/services/service/include/device_manager_service_listener.h b/services/service/include/device_manager_service_listener.h index 2efafcd32..e281265e2 100644 --- a/services/service/include/device_manager_service_listener.h +++ b/services/service/include/device_manager_service_listener.h @@ -18,6 +18,7 @@ #include #include +#include #include #include @@ -87,16 +88,19 @@ private: std::string ComposeOnlineKey(const std::string &pkgName, const std::string &devId); void SetDeviceScreenInfo(std::shared_ptr pReq, const std::string &pkgName, const DmDeviceInfo &deviceInfo); + void RemoveOnlinePkgName(const DmDeviceInfo &info); #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) int32_t ConvertUdidHashToAnoyAndSave(const std::string &pkgName, DmDeviceInfo &deviceInfo); int32_t ConvertUdidHashToAnoyDeviceId(const std::string &pkgName, const std::string &udidHash, std::string &anoyDeviceId); #endif + std::unordered_set GetwhiteListSAPkgName(DmCommonNotifyEvent dmCommonNotifyEvent); + std::vector GetNotifyPkgName(DmCommonNotifyEvent dmCommonNotifyEvent); private: #if !defined(__LITEOS_M__) IpcServerListener ipcServerListener_; - static std::mutex alreadyOnlineSetLock_; - static std::unordered_set alreadyOnlineSet_; + static std::mutex alreadyOnlinePkgNameLock_; + static std::unordered_map alreadyOnlinePkgName_; #endif }; } // namespace DistributedHardware diff --git a/services/service/include/notify/device_manager_service_notify.h b/services/service/include/notify/device_manager_service_notify.h new file mode 100644 index 000000000..9dcb28ebe --- /dev/null +++ b/services/service/include/notify/device_manager_service_notify.h @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_DM_SERVICE_NOTIFY_H +#define OHOS_DM_SERVICE_NOTIFY_H + +#include +#include + +#include "dm_device_info.h" +#include "dm_single_instance.h" + +namespace OHOS { +namespace DistributedHardware { +class DeviceManagerServiceNotify { + DM_DECLARE_SINGLE_INSTANCE(DeviceManagerServiceNotify); + +public: + int32_t RegisterCallBack(int32_t dmCommonNotifyEvent, const ProcessInfo &processInfo); + void GetCallBack(int32_t dmCommonNotifyEvent, std::set &processInfos); + void ClearDiedProcessCallback(const ProcessInfo &processInfo); + +private: + std::mutex callbackLock_; + std::map> callbackMap_; +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DM_SERVICE_NOTIFY_H diff --git a/services/service/src/device_manager_service.cpp b/services/service/src/device_manager_service.cpp index b24e942a0..e1f4e9ed9 100755 --- a/services/service/src/device_manager_service.cpp +++ b/services/service/src/device_manager_service.cpp @@ -17,6 +17,7 @@ #include #include +#include #include "app_manager.h" #include "dm_anonymous.h" @@ -85,6 +86,11 @@ int32_t DeviceManagerService::InitSoftbusListener() softbusListener_ = std::make_shared(); } SoftbusCache::GetInstance().UpdateDeviceInfoCache(); + std::vector onlineDeviceList; + SoftbusCache::GetInstance().GetDeviceInfoFromCache(onlineDeviceList); + if (onlineDeviceList.size() > 0 && IsDMServiceImplReady()) { + dmServiceImpl_->SaveOnlineDeviceInfo(onlineDeviceList); + } #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) #if defined(SUPPORT_BLUETOOTH) || defined(SUPPORT_WIFI) SubscribePublishCommonEvent(); @@ -95,6 +101,14 @@ int32_t DeviceManagerService::InitSoftbusListener() return DM_OK; } +void DeviceManagerService::InitHichainListener() +{ + LOGI("DeviceManagerService::InitHichainListener Start."); + if (hichainListener_ == nullptr) { + hichainListener_ = std::make_shared(); + } + hichainListener_->RegisterDataChangeCb(); +} #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) #if defined(SUPPORT_BLUETOOTH) || defined(SUPPORT_WIFI) void DeviceManagerService::SubscribePublishCommonEvent() @@ -323,7 +337,7 @@ int32_t DeviceManagerService::GetDeviceInfo(const std::string &networkId, DmDevi int32_t DeviceManagerService::GetLocalDeviceInfo(DmDeviceInfo &info) { - LOGI("Begin."); + LOGD("Begin."); bool isOnlyShowNetworkId = false; if (!PermissionManager::GetInstance().CheckNewPermission()) { LOGE("The caller does not have permission to call GetLocalDeviceInfo."); @@ -897,6 +911,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; @@ -1598,29 +1615,36 @@ void DeviceManagerService::AccountCommonEventCallback(int32_t userId, std::strin { LOGI("CommonEventType: %{public}s", commonEventType.c_str()); if (commonEventType == CommonEventSupport::COMMON_EVENT_USER_SWITCHED) { - MultipleUserConnector::SetSwitchOldUserId(userId); - MultipleUserConnector::SetSwitchOldAccountId(MultipleUserConnector::GetOhosAccountId()); - MultipleUserConnector::SetSwitchOldAccountName(MultipleUserConnector::GetOhosAccountName()); + DMAccountInfo dmAccountInfo; + dmAccountInfo.accountId = MultipleUserConnector::GetOhosAccountId(); + dmAccountInfo.accountName = MultipleUserConnector::GetOhosAccountName(); + MultipleUserConnector::SetAccountInfo(userId, dmAccountInfo); if (IsDMServiceAdapterLoad()) { dmServiceImplExt_->AccountUserSwitched(userId, MultipleUserConnector::GetOhosAccountId()); } } else if (commonEventType == CommonEventSupport::COMMON_EVENT_HWID_LOGIN) { - MultipleUserConnector::SetSwitchOldAccountId(MultipleUserConnector::GetOhosAccountId()); - MultipleUserConnector::SetSwitchOldAccountName(MultipleUserConnector::GetOhosAccountName()); + DMAccountInfo dmAccountInfo; + dmAccountInfo.accountId = MultipleUserConnector::GetOhosAccountId(); + dmAccountInfo.accountName = MultipleUserConnector::GetOhosAccountName(); + MultipleUserConnector::SetAccountInfo(userId, dmAccountInfo); } else if (commonEventType == CommonEventSupport::COMMON_EVENT_HWID_LOGOUT) { - HandleAccountLogout(MultipleUserConnector::GetCurrentAccountUserID(), - MultipleUserConnector::GetSwitchOldAccountId()); + DMAccountInfo dmAccountInfo = MultipleUserConnector::GetAccountInfoByUserId(userId); + HandleAccountLogout(userId, dmAccountInfo.accountId, dmAccountInfo.accountName); + MultipleUserConnector::DeleteAccountInfoByUserId(userId); } else if (commonEventType == CommonEventSupport::COMMON_EVENT_USER_REMOVED) { HandleUserRemoved(userId); + MultipleUserConnector::DeleteAccountInfoByUserId(userId); } else { LOGE("Invalied account common event."); } return; } -void DeviceManagerService::HandleAccountLogout(int32_t userId, const std::string &accountId) +void DeviceManagerService::HandleAccountLogout(int32_t userId, const std::string &accountId, + const std::string &accountName) { - LOGI("UserId %{public}d, accountId %{public}s.", userId, GetAnonyString(accountId).c_str()); + LOGI("UserId %{public}d, accountId %{public}s, accountName: %{public}s", userId, GetAnonyString(accountId).c_str(), + GetAnonyString(accountName).c_str()); if (IsDMServiceAdapterLoad()) { dmServiceImplExt_->AccountIdLogout(userId, accountId); } @@ -1836,5 +1860,18 @@ void DeviceManagerService::HandleCredentialAuthStatus(const std::string &proofIn dmServiceImpl_->HandleCredentialAuthStatus(proofInfo, deviceTypeId, errcode); } } + +void DeviceManagerService::HandleDeviceUnBind(const char *peerUdid, const GroupInformation &groupInfo) +{ + LOGI("DeviceManagerService::HandleDeviceUnBind start."); + char localUdidTemp[DEVCIE_UDID_LENGTH] = {0}; + GetDevUdid(localUdidTemp, DEVCIE_UDID_LENGTH); + std::string localUdid = std::string(localUdidTemp); + if (IsDMServiceImplReady()) { + dmServiceImpl_->HandleDeviceUnBind(groupInfo.groupName, std::string(peerUdid), + localUdid, groupInfo.userId, groupInfo.osAccountId); + } + return; +} } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file diff --git a/services/service/src/device_manager_service_listener.cpp b/services/service/src/device_manager_service_listener.cpp index 3cacc7b46..f707829b0 100644 --- a/services/service/src/device_manager_service_listener.cpp +++ b/services/service/src/device_manager_service_listener.cpp @@ -17,6 +17,7 @@ #include "app_manager.h" #include "device_manager_ipc_interface_code.h" +#include "device_manager_service_notify.h" #include "dm_anonymous.h" #include "dm_constants.h" #include "dm_crypto.h" @@ -35,6 +36,9 @@ #include "ipc_notify_pin_holder_event_req.h" #include "ipc_notify_publish_result_req.h" #include "ipc_server_stub.h" +#include +#include +#include #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) #include "datetime_ex.h" #include "kv_adapter_manager.h" @@ -44,8 +48,8 @@ namespace OHOS { namespace DistributedHardware { -std::mutex DeviceManagerServiceListener::alreadyOnlineSetLock_; -std::unordered_set DeviceManagerServiceListener::alreadyOnlineSet_ = {}; +std::mutex DeviceManagerServiceListener::alreadyOnlinePkgNameLock_; +std::unordered_map DeviceManagerServiceListener::alreadyOnlinePkgName_ = {}; const int32_t LAST_APP_ONLINE_NUMS = 8; void DeviceManagerServiceListener::ConvertDeviceInfoToDeviceBasicInfo(const std::string &pkgName, const DmDeviceInfo &info, DmDeviceBasicInfo &deviceBasicInfo) @@ -108,14 +112,10 @@ void DeviceManagerServiceListener::ProcessDeviceStateChange(const DmDeviceState LOGI("In"); std::shared_ptr pReq = std::make_shared(); std::shared_ptr pRsp = std::make_shared(); - std::vector PkgNameVec = ipcServerListener_.GetAllPkgName(); + std::vector PkgNameVec = GetNotifyPkgName(DmcommonNotifyEvent::REG_DEVICE_STATE); if (state == DEVICE_STATE_OFFLINE) { + RemoveOnlinePkgName(info); for (const auto &it : PkgNameVec) { - std::string notifyKey = ComposeOnlineKey(it, std::string(info.deviceId)); - { - std::lock_guard autoLock(alreadyOnlineSetLock_); - alreadyOnlineSet_.erase(notifyKey); - } SetDeviceInfo(pReq, it, state, info, deviceBasicInfo); ipcServerListener_.SendRequest(SERVER_DEVICE_STATE_NOTIFY, pReq, pRsp); } @@ -125,11 +125,11 @@ void DeviceManagerServiceListener::ProcessDeviceStateChange(const DmDeviceState std::string notifyKey = ComposeOnlineKey(it, std::string(info.deviceId)); DmDeviceState notifyState = state; { - std::lock_guard autoLock(alreadyOnlineSetLock_); - if (alreadyOnlineSet_.find(notifyKey) != alreadyOnlineSet_.end()) { + std::lock_guard autoLock(alreadyOnlinePkgNameLock_); + if (alreadyOnlinePkgName_.find(notifyKey) != alreadyOnlinePkgName_.end()) { notifyState = DmDeviceState::DEVICE_INFO_CHANGED; } else { - alreadyOnlineSet_.insert(notifyKey); + alreadyOnlinePkgName_[notifyKey] = info; } } SetDeviceInfo(pReq, it, notifyState, info, deviceBasicInfo); @@ -150,28 +150,25 @@ void DeviceManagerServiceListener::ProcessAppStateChange(const std::string &pkgN LOGI("In"); std::shared_ptr pReq = std::make_shared(); std::shared_ptr pRsp = std::make_shared(); - std::unordered_set notifyPkgnames = PermissionManager::GetInstance().GetSystemSA(); + std::unordered_set notifyPkgnames = GetwhiteListSAPkgName(DmCommonNotifyEvent::REG_DEVICE_STATE); notifyPkgnames.insert(pkgName); if (state == DEVICE_STATE_ONLINE) { for (const auto &it : notifyPkgnames) { std::string notifyKey = it + "_" + info.deviceId; { - std::lock_guard autoLock(alreadyOnlineSetLock_); - if (alreadyOnlineSet_.find(notifyKey) != alreadyOnlineSet_.end()) { + std::lock_guard autoLock(alreadyOnlinePkgNameLock_); + if (alreadyOnlinePkgName_.find(notifyKey) != alreadyOnlinePkgName_.end()) { continue; } - alreadyOnlineSet_.insert(notifyKey); + alreadyOnlinePkgName_.[notifyKey] = info; } SetDeviceInfo(pReq, it, state, info, deviceBasicInfo); ipcServerListener_.SendRequest(SERVER_DEVICE_STATE_NOTIFY, pReq, pRsp); } } if (state == DEVICE_STATE_OFFLINE) { - if (alreadyOnlineSet_.size() == LAST_APP_ONLINE_NUMS) { - { - std::lock_guard autoLock(alreadyOnlineSetLock_); - alreadyOnlineSet_.clear(); - } + if (!SoftbusCache::GetInstance().CheckIsOnline(std::string(info.deviceId))) { + RemoveOnlinePkgName(info); for (const auto &it : notifyPkgnames) { SetDeviceInfo(pReq, it, state, info, deviceBasicInfo); ipcServerListener_.SendRequest(SERVER_DEVICE_STATE_NOTIFY, pReq, pRsp); @@ -179,9 +176,9 @@ void DeviceManagerServiceListener::ProcessAppStateChange(const std::string &pkgN } else { std::string notifyKey = pkgName + "_" + info.deviceId; { - std::lock_guard autoLock(alreadyOnlineSetLock_); - if (alreadyOnlineSet_.find(notifyKey) != alreadyOnlineSet_.end()) { - alreadyOnlineSet_.erase(notifyKey); + std::lock_guard autoLock(alreadyOnlinePkgNameLock_); + if (alreadyOnlinePkgName_.find(notifyKey) != alreadyOnlinePkgName_.end()) { + alreadyOnlinePkgName_.erase(notifyKey); } } SetDeviceInfo(pReq, pkgName, state, info, deviceBasicInfo); @@ -431,7 +428,7 @@ void DeviceManagerServiceListener::OnPinHolderEvent(const std::string &pkgName, #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) int32_t DeviceManagerServiceListener::ConvertUdidHashToAnoyAndSave(const std::string &pkgName, DmDeviceInfo &deviceInfo) { - LOGI("pkgName %{public}s.", pkgName.c_str()); + LOGD("pkgName %{public}s.", pkgName.c_str()); std::string appId = ""; if (AppManager::GetInstance().GetAppIdByPkgName(pkgName, appId) != DM_OK) { LOGD("GetAppIdByPkgName failed"); @@ -494,7 +491,7 @@ void DeviceManagerServiceListener::OnDeviceScreenStateChange(const std::string & if (pkgName == std::string(DM_PKG_NAME)) { std::shared_ptr pReq = std::make_shared(); std::shared_ptr pRsp = std::make_shared(); - std::vector PkgNameVec = ipcServerListener_.GetAllPkgName(); + std::vector PkgNameVec = GetNotifyPkgName(DmcommonNotifyEvent::REG_DEVICE_SCREEN_STATE); for (const auto &it : PkgNameVec) { SetDeviceScreenInfo(pReq, it, devInfo); ipcServerListener_.SendRequest(SERVER_DEVICE_SCREEN_STATE_NOTIFY, pReq, pRsp); @@ -502,7 +499,8 @@ void DeviceManagerServiceListener::OnDeviceScreenStateChange(const std::string & } else { std::shared_ptr pReq = std::make_shared(); std::shared_ptr pRsp = std::make_shared(); - std::unordered_set notifyPkgnames = PermissionManager::GetInstance().GetSystemSA(); + std::unordered_set notifyPkgnames = + GetwhiteListSAPkgName(DmcommonNotifyEvent::REG_DEVICE_SCREEN_STATE); notifyPkgnames.insert(pkgName); for (const auto &it : notifyPkgnames) { SetDeviceScreenInfo(pReq, it, devInfo); @@ -521,16 +519,73 @@ void DeviceManagerServiceListener::OnCredentialAuthStatus(const std::string &pkg pReq->SetProofInfo(proofInfo); pReq->SetDeviceTypeId(deviceTypeId); pReq->SetErrCode(errcode); - if (pkgName == std::string(DM_PKG_NAME)) { - std::vector PkgNameVec = ipcServerListener_.GetAllPkgName(); - for (const auto &it : PkgNameVec) { + std::vector PkgNameVec = GetNotifyPkgName(DmcommonNotifyEvent::REG_CREDENTIAL_AUTH_STATUS_NOTIFY); + for (const auto &it : PkgNameVec) { pReq->SetPkgName(it); ipcServerListener_.SendRequest(SERVICE_CREDENTIAL_AUTH_STATUS_NOTIFY, pReq, pRsp); + } +} + +void DeviceManagerServiceListener::RemoveOnlinePkgName(const DmDeviceInfo &info) +{ + LOGI("udidHash: %{public}s.", GetAnonyString(info.deviceId).c_str()); + { + std::lock_guard autoLock(alreadyNotifyPkgNameLock_); + for (auto item = alreadyOnlinePkgName_.begin(); item != alreadyOnlinePkgName_.end();) { + if (std::string(item->second.deviceId) == std::string(info.deviceId)) { + item = alreadyOnlinePkgName_.erase(item); + } else { + ++item; + } } - } else { - pReq->SetPkgName(pkgName); - ipcServerListener_.SendRequest(SERVICE_CREDENTIAL_AUTH_STATUS_NOTIFY, pReq, pRsp); } } + +std::unordered_set DeviceManagerServiceListener::GetwhiteListSAPkgName( + DmCommonNotifyEvent dmCommonNotifyEvent) +{ + if (!IsDmCommonNotifyEventValid(dmCommonNotifyEvent)) { + LOGE("Invalid dmCommonNotifyEvent: %{public}d.", dmCommonNotifyEvent); + return {}; + } + std::set notifyPkgNames; + DeviceManagerServiceNotify::GetInstance().GetCallBack(dmCommonNotifyEvent, notifyPkgNames); + if (notifyPkgNames.size() == 0) { + LOGE("callback not exist dmCommonNotifyEvent: %{public}d.", dmCommonNotifyEvent); + return {}; + } + std::unordered_set whiteListPkgNames = PermissionManager::GetInstance().GetSystemSA(); + std::unordered_set pkgNames; + for (const auto &it: whiteListPkgNames) { + if (notifyPkgNames.find(it) == notifyPkgNames.end()) { + continue; + } + pkgNames.insert(it); + } + return pkgNames; +} + +std::vector DeviceManagerServiceListener::GetNotifyPkgName(DmCommonNotifyEvent dmCommonNotifyEvent) +{ + if (!IsDmCommonNotifyEventValid(dmCommonNotifyEvent)) { + LOGE("Invalid dmCommonNotifyEvent: %{public}d.", dmCommonNotifyEvent); + return {}; + } + std::set notifyPkgNames; + DeviceManagerServiceNotify::GetInstance().GetCallBack(dmCommonNotifyEvent, notifyPkgNames); + if (notifyPkgNames.size() == 0) { + LOGE("callback not exist dmCommonNotifyEvent: %{public}d.", dmCommonNotifyEvent); + return {}; + } + std::vector pkgNames = ipcServerListener_.GetAllPkgName(); + std::vector pkgNamesTemp; + for (auto item : pkgNames) { + if (notifyPkgNames.find(item) == notifyPkgNames.end()) { + continue; + } + pkgNamesTemp.push_back(item); + } + return pkgNamesTemp; +} } // namespace DistributedHardware } // namespace OHOS diff --git a/services/service/src/hichain/hichain_listener.cpp b/services/service/src/hichain/hichain_listener.cpp new file mode 100644 index 000000000..2a6d540d9 --- /dev/null +++ b/services/service/src/hichain/hichain_listener.cpp @@ -0,0 +1,114 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "hichain_listener.h" + +#include "device_manager_service.h" +#include "dm_anonymous.h" +#include "dm_constants.h" +#include "dm_log.h" +#include "multiple_user_connector.h" + +namespace OHOS { +namespace DistributedHardware { + +namespace { + constexpr uint32_t MAX_DATA_LEN = 65536; + constexpr uint32_t DM_IDENTICAL_ACCOUNT = 1; +} + +static DataChangeListener dataChangeListener_ = { + .onDeviceUnBound = HichainListener::OnHichainDeviceUnBound, +}; + +void from_json(const nlohmann::json &jsonObject, GroupInformation &groupInfo) +{ + if (jsonObject.find(FIELD_GROUP_TYPE) != jsonObject.end() && jsonObject.at(FIELD_GROUP_TYPE).is_number_integer()) { + groupInfo.groupType = jsonObject.at(FIELD_GROUP_TYPE).get(); + } + // FIELD_USER_ID is osAccountId + if (jsonObject.find(FIELD_USER_ID) != jsonObject.end() && jsonObject.at(FIELD_USER_ID).is_string()) { + groupInfo.osAccountId = jsonObject.at(FIELD_USER_ID).get(); + } + // FIELD_OS_ACCOUNT_ID is userId + if (jsonObject.find(FIELD_OS_ACCOUNT_ID) != jsonObject.end() && + jsonObject.at(FIELD_OS_ACCOUNT_ID).is_number_integer()) { + groupInfo.userId = jsonObject.at(FIELD_OS_ACCOUNT_ID).get(); + } +} + +HichainListener::HichainListener() +{ + LOGI("HichainListener constructor start."); + InitDeviceAuthService(); + deviceGroupManager_ = GetGmInstance(); + if (deviceGroupManager_ == nullptr) { + LOGE("[HICHAIN]failed to init group manager."); + return; + } + LOGI("HichainListener::constructor success."); +} + +HichainListener::~HichainListener() +{ + LOGI("HichainListener::destructor."); +} + +void HichainListener::RegisterDataChangeCb() +{ + LOGI("HichainListener::RegisterDataChangeCb start"); + if (deviceGroupManager_ == nullptr) { + LOGE("deviceGroupManager_ is null!"); + return; + } + int32_t ret = deviceGroupManager_->regDataChangeListener(DM_PKG_NAME, &dataChangeListener_); + if (ret != DM_OK) { + LOGE("[HICHAIN]regDataChangeListener failed with ret: %{public}d.", ret); + return; + } + LOGI("RegisterDataChangeCb success!"); +} + +void HichainListener::OnHichainDeviceUnBound(const char *peerUdid, const char *groupInfo) +{ + LOGI("HichainListener::onDeviceUnBound start"); + if (peerUdid == nullptr || groupInfo == nullptr) { + LOGE("peerUdid or groupInfo is null!"); + return; + } + if (strlen(peerUdid) > MAX_DATA_LEN || strlen(groupInfo) > MAX_DATA_LEN) { + LOGE("peerUdid or groupInfo is invalid"); + return; + } + nlohmann::json groupInfoJsonObj = nlohmann::json::parse(std::string(groupInfo), nullptr, false); + if (groupInfoJsonObj.is_discarded()) { + LOGE("groupInfo parse error"); + return ; + } + GroupInformation hichainGroupInfo; + from_json(groupInfoJsonObj, hichainGroupInfo); + if (hichainGroupInfo.groupType != DM_IDENTICAL_ACCOUNT) { + LOGI("groupType is %{public}d, not idential account.", hichainGroupInfo.groupType); + return; + } + string accountId = MultipleUserConnector::GetOhosAccountId(); + if (accountId == hichainGroupInfo.osAccountId && accountId != "ohosAnonymousUid") { + LOGI("accountId = %{public}s.", GetAnonyString(accountId).c_str()); + DeviceManagerService::GetInstance().HandleDeviceUnBind(peerUdid, hichainGroupInfo); + return; + } +} +} // namespace DistributedHardware +} // namespace OHOS \ No newline at end of file diff --git a/services/service/src/ipc/lite/ipc_cmd_parser.cpp b/services/service/src/ipc/lite/ipc_cmd_parser.cpp index 9154339c2..bed113c9f 100644 --- a/services/service/src/ipc/lite/ipc_cmd_parser.cpp +++ b/services/service/src/ipc/lite/ipc_cmd_parser.cpp @@ -15,8 +15,10 @@ #include "device_manager_ipc_interface_code.h" #include "device_manager_service.h" +#include "device_manager_service_notify.h" #include "dm_anonymous.h" #include "dm_constants.h" +#include "dm_device_info.h" #include "dm_log.h" #include "ipc_cmd_register.h" #include "ipc_def.h" @@ -258,5 +260,15 @@ ON_IPC_SERVER_CMD(DELETE_CREDENTIAL, IpcIo &req, IpcIo &reply) WriteString(&reply, outParamStr.c_str()); } } + +ON_IPC_SERVER_CMD(SYNC_CALLBACK, IpcIo &req, IpcIo &reply) +{ + LOGI("start."); + std::string pkgName = (const char*)ReadString(&req, nullptr); + int32_t dmCommonNotifyEvent = 0; + ReadInt32(&req, &dmCommonNotifyEvent); + int32_t ret = DeviceManagerServiceNotify::GetInstance().RegisterCallBack(dmCommonNotifyEvent, pkgName); + WriteInt32(&reply, ret); +} } // namespace DistributedHardware } // namespace OHOS diff --git a/services/service/src/ipc/standard/ipc_cmd_parser.cpp b/services/service/src/ipc/standard/ipc_cmd_parser.cpp index 105b24526..796773020 100644 --- a/services/service/src/ipc/standard/ipc_cmd_parser.cpp +++ b/services/service/src/ipc/standard/ipc_cmd_parser.cpp @@ -19,6 +19,7 @@ #include "device_manager_ipc_interface_code.h" #include "device_manager_service.h" +#include "device_manager_service_notify.h" #include "dm_anonymous.h" #include "dm_constants.h" #include "dm_device_info.h" @@ -1573,5 +1574,17 @@ ON_IPC_READ_RESPONSE(SERVICE_CREDENTIAL_AUTH_STATUS_NOTIFY, MessageParcel &reply pBaseRsp->SetErrCode(reply.ReadInt32()); return DM_OK; } + +ON_IPC_CMD(SYNC_CALLBACK, MessageParcel &data, MessageParcel &reply) +{ + std::string pkgName = data.ReadString(); + int32_t dmCommonNotifyEvent = data.ReadInt32(); + int32_t result = DeviceManagerServiceNotify::GetInstance().RegisterCallBack(dmCommonNotifyEvent, pkgName); + if (!reply.WriteInt32(result)) { + LOGE("write result failed"); + return ERR_DM_IPC_WRITE_FAILED; + } + return DM_OK; +} } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file diff --git a/services/service/src/ipc/standard/ipc_server_stub.cpp b/services/service/src/ipc/standard/ipc_server_stub.cpp index 9a1b7bba4..de7677384 100644 --- a/services/service/src/ipc/standard/ipc_server_stub.cpp +++ b/services/service/src/ipc/standard/ipc_server_stub.cpp @@ -33,6 +33,8 @@ #endif // SUPPORT_MEMMGR #include "string_ex.h" #include "system_ability_definition.h" +#include "device_manager_service_notify.h" +#include "multiple_user_connector.h" namespace OHOS { namespace DistributedHardware { @@ -69,6 +71,8 @@ void IpcServerStub::OnStart() #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) AddSystemAbilityListener(DISTRIBUTED_KV_DATA_SERVICE_ABILITY_ID); #endif + AddSystemAbilityListener(DEVICE_AUTH_SERVICE_ID); + AddSystemAbilityListener(ACCESS_TOKEN_MANAGER_SERVICE_ID); DeviceManagerService::GetInstance().SubscribePackageCommonEvent(); } @@ -95,6 +99,10 @@ void IpcServerStub::OnAddSystemAbility(int32_t systemAbilityId, const std::strin #endif // SUPPORT_MEMMGR if (systemAbilityId == SUBSYS_ACCOUNT_SYS_ABILITY_ID_BEGIN) { + DMAccountInfo dmAccountInfo; + dmAccountInfo.accountId = MultipleUserConnector::GetOhosAccountId(); + dmAccountInfo.accountName = MultipleUserConnector::GetOhosAccountName(); + MultipleUserConnector::SetAccountInfo(MultipleUserConnector::GetCurrentAccountUserID(), dmAccountInfo); DeviceManagerService::GetInstance().InitAccountInfo(); return; } @@ -110,6 +118,14 @@ void IpcServerStub::OnAddSystemAbility(int32_t systemAbilityId, const std::strin return; } #endif + if (systemAbilityId == DEVICE_AUTH_SERVICE_ID) { + DeviceManagerService::GetInstance().InitHichainListener(); + return; + } + if (systemAbilityId == ACCESS_TOKEN_MANAGER_SERVICE_ID) { + DeviceManagerService::GetInstance().InitHichainListener(); + return; + } } void IpcServerStub::OnRemoveSystemAbility(int32_t systemAbilityId, const std::string& deviceId) @@ -224,7 +240,7 @@ int32_t IpcServerStub::RegisterDeviceManagerListener(std::string &pkgName, sptr< } dmListener_[pkgName] = listener; appRecipient_[pkgName] = appRecipient; - LOGI("Register listener complete."); + LOGD("Register listener complete."); return DM_OK; } @@ -335,6 +351,7 @@ void AppDeathRecipient::OnRemoteDied(const wptr &remote) std::string pkgName = IpcServerStub::GetInstance().GetDmListenerPkgName(remote); LOGI("AppDeathRecipient: OnRemoteDied for %{public}s", pkgName.c_str()); IpcServerStub::GetInstance().UnRegisterDeviceManagerListener(pkgName); + DeviceManagerServiceNotify::GetInstance().ClearDiedProcessCallback(pkgName); } } // namespace DistributedHardware } // namespace OHOS diff --git a/services/service/src/notify/device_manager_service_notify.cpp b/services/service/src/notify/device_manager_service_notify.cpp new file mode 100644 index 000000000..a990df9f7 --- /dev/null +++ b/services/service/src/notify/device_manager_service_notify.cpp @@ -0,0 +1,108 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "device_manager_service_notify.h" +#include "dm_anonymous.h" +#include "dm_constants.h" +#include "dm_log.h" +#include + +namespace OHOS { +namespace DistributedHardware { +DM_IMPLEMENT_SINGLE_INSTANCE(DeviceManagerServiceNotify); +namespace { +constexpr uint32_t MAX_CALLBACK_LEN = 1000; +const static std::map unRegNotifyEventMap_ = { + {DmCommonNotifyEvent::UN_REG_DEVICE_STATE, DmCommonNotifyEvent::REG_DEVICE_STATE}, + {DmCommonNotifyEvent::UN_REG_DEVICE_SCREEN_STATE, DmCommonNotifyEvent::REG_DEVICE_SCREEN_STATE}, + {DmCommonNotifyEvent::UN_REG_REMOTE_DEVICE_TRUST_CHANGE, DmCommonNotifyEvent::REG_REMOTE_DEVICE_TRUST_CHANGE}, + {DmCommonNotifyEvent::UN_REG_CREDENTIAL_AUTH_STATUS_NOTIFY, DmCommonNotifyEvent::REG_CREDENTIAL_AUTH_STATUS_NOTIFY} +}; + +const static std::set regNotifyEventSet_ = { + DmCommonNotifyEvent::REG_DEVICE_STATE, + DmCommonNotifyEvent::REG_DEVICE_SCREEN_STATE, + DmCommonNotifyEvent::REG_REMOTE_DEVICE_TRUST_CHANGE, + DmCommonNotifyEvent::REG_CREDENTIAL_AUTH_STATUS_NOTIFY +}; +} + +int32_t DeviceManagerServiceNotify::RegisterCallBack(int32_t dmCommonNotifyEvent, const std::string &pkgName) +{ + LOGI("start event %{public}d pkgName: %{public}s.", dmCommonNotifyEvent, pkgName.c_str()); + if (pkgName.empty()) { + LOGE("Invalid parameter, pkgName is empty."); + return ERR_DM_INPUT_PARA_INVALID; + } + DmCommonNotifyEvent notifyEvent = static_cast(dmCommonNotifyEvent); + std::lock_guard autoLock(callbackLock_); + if (unRegNotifyEventMap_.find(notifyEvent) != unRegNotifyEventMap_.end()) { + if (callbackMap_.find(unRegNotifyEventMap_.at(notifyEvent)) == callbackMap_.end()) { + LOGI("notifyEvent is not exist %{public}d.", unRegNotifyEventMap_.at(notifyEvent)); + return DM_OK; + } + callbackMap_.at(unRegNotifyEventMap_.at(notifyEvent)).erase(pkgName); + return DM_OK; + } + if (regNotifyEventSet_.find(notifyEvent) == regNotifyEventSet_.end()) { + LOGE("notifyEvent is not support %{public}d.", notifyEvent); + return ERR_DM_INPUT_PARA_INVALID; + } + if (callbackMap_.find(notifyEvent) == callbackMap_.end()) { + std::set pkgNameSet; + pkgNameSet.insert(pkgName); + callbackMap_[notifyEvent] = pkgNameSet; + return DM_OK; + } + if (callbackMap_[notifyEvent].size() >= MAX_CALLBACK_LEN) { + LOGE("too many callbacks dmCommonNotifyEvent: %{public}d, pkgName: %{public}s", dmCommonNotifyEvent, + pkgName.c_str()); + return ERR_DM_FAILED; + } + callbackMap_.at(notifyEvent).insert(pkgName); + return DM_OK; +} + +void DeviceManagerServiceNotify::GetCallBack(int32_t dmCommonNotifyEvent, std::set &pkgNames) +{ + LOGI("start event %{public}d.", dmCommonNotifyEvent); + DmCommonNotifyEvent notifyEvent = static_cast(dmCommonNotifyEvent); + std::lock_guard autoLock(callbackLock_); + if (regNotifyEventSet_.find(notifyEvent) == regNotifyEventSet_.end()) { + LOGE("notifyEvent is not support %{public}d.", notifyEvent); + return; + } + if (callbackMap_.find(notifyEvent) == callbackMap_.end()) { + LOGE("callback is empty %{public}d.", notifyEvent); + return; + } + pkgNames = callbackMap_.at(notifyEvent); +} + +void DeviceManagerServiceNotify::ClearDiedProcessCallback(const std::string &pkgName) +{ + LOGI("start pkgName %{public}s.", pkgName.c_str()); + std::lock_guard autoLock(callbackLock_); + for (auto iter = callbackMap_.begin(); iter != callbackMap_.end();) { + iter->second.erase(pkgName); + if (iter->second.empty()) { + iter = callbackMap_.erase(iter); + } else { + ++iter; + } + } +} +} // namespace DistributedHardware +} // namespace OHOS diff --git a/services/service/src/publishcommonevent/dm_account_common_event.cpp b/services/service/src/publishcommonevent/dm_account_common_event.cpp index 4fb3e5ef3..72f6a4f53 100644 --- a/services/service/src/publishcommonevent/dm_account_common_event.cpp +++ b/services/service/src/publishcommonevent/dm_account_common_event.cpp @@ -177,13 +177,15 @@ void DmAccountCommonEventManager::SystemAbilityStatusChangeListener::OnAddSystem if (!CommonEventManager::SubscribeCommonEvent(changeSubscriber_)) { LOGE("failed to subscribe account commom event: %{public}zu", eventNameVec.size()); } + DMAccountInfo dmAccountInfo; int32_t userId = MultipleUserConnector::GetCurrentAccountUserID(); - std::string accountId = MultipleUserConnector::GetOhosAccountId(); - LOGI("after subscribe account event accountId: %{public}s, userId: %{public}s", - GetAnonyString(accountId).c_str(), GetAnonyInt32(userId).c_str()); + dmAccountInfo.accountId = MultipleUserConnector::GetOhosAccountId(); + dmAccountInfo.accountName = MultipleUserConnector::GetOhosAccountName(); + LOGI("after subscribe account event accountId: %{public}s, userId: %{public}s, accountName: %{public}s", + GetAnonyString(dmAccountInfo.accountId).c_str(), GetAnonyInt32(userId).c_str(), + GetAnonyString(dmAccountInfo.accountName).c_str()); if (userId > 0) { - MultipleUserConnector::SetSwitchOldUserId(userId); - MultipleUserConnector::SetSwitchOldAccountId(accountId); + MultipleUserConnector::SetAccountInfo(userId, dmAccountInfo); } } diff --git a/services/service/src/softbus/softbus_listener.cpp b/services/service/src/softbus/softbus_listener.cpp index 7d560545d..7aa4d1a9c 100644 --- a/services/service/src/softbus/softbus_listener.cpp +++ b/services/service/src/softbus/softbus_listener.cpp @@ -724,6 +724,7 @@ int32_t SoftbusListener::ConvertScreenStatusToDmDevice(const NodeBasicInfo &node int32_t SoftbusListener::ConvertNodeBasicInfoToDmDevice(const NodeBasicInfo &nodeInfo, DmDeviceInfo &devInfo) { + LOGI("Begin, osType : %{public}d", nodeInfo.osType); (void)memset_s(&devInfo, sizeof(DmDeviceInfo), 0, sizeof(DmDeviceInfo)); if (memcpy_s(devInfo.networkId, sizeof(devInfo.networkId), nodeInfo.networkId, std::min(sizeof(devInfo.networkId), sizeof(nodeInfo.networkId))) != DM_OK) { diff --git a/services/softbuscache/include/dm_softbus_cache.h b/services/softbuscache/include/dm_softbus_cache.h index bf910d13b..a10fe268b 100644 --- a/services/softbuscache/include/dm_softbus_cache.h +++ b/services/softbuscache/include/dm_softbus_cache.h @@ -46,7 +46,7 @@ public: int32_t GetDevInfoByNetworkId(const std::string &networkId, DmDeviceInfo &nodeInfo); void UpDataLocalDevInfo(); int32_t GetNetworkIdFromCache(const std::string &udid, std::string &networkId); - + bool CheckIsOnline(const std::string &udidHash); private: int32_t GetUdidByNetworkId(const char *networkId, std::string &udid); int32_t GetUuidByNetworkId(const char *networkId, std::string &uuid); diff --git a/services/softbuscache/src/dm_softbus_cache.cpp b/services/softbuscache/src/dm_softbus_cache.cpp index b5a132fe7..8ee7c2606 100644 --- a/services/softbuscache/src/dm_softbus_cache.cpp +++ b/services/softbuscache/src/dm_softbus_cache.cpp @@ -62,7 +62,7 @@ int32_t SoftbusCache::GetLocalDeviceInfo(DmDeviceInfo &nodeInfo) std::lock_guard mutexLock(localDevInfoMutex_); if (g_getLocalDevInfo) { nodeInfo = localDeviceInfo_; - LOGI("SoftbusCache::GetLocalDeviceInfo from dm cache."); + LOGD("SoftbusCache::GetLocalDeviceInfo from dm cache."); return DM_OK; } NodeBasicInfo nodeBasicInfo; @@ -391,5 +391,20 @@ int32_t SoftbusCache::GetNetworkIdFromCache(const std::string &udid, std::string } return ERR_DM_FAILED; } + +bool SoftbusCache::CheckIsOnline(const std::string &deviceId) +{ + LOGI("deviceId %{public}s.", GetAnonyString(deviceId).c_str()); + { + std::lock_guard mutexLock(deviceInfosMutex_); + for (const auto &item : deviceInfo_) { + if (std::string(item.second.second.deviceId) == deviceId) { + LOGI("CheckIsOnline is true."); + return true; + } + } + } + return false; +} } // namespace DistributedHardware } // namespace OHOS diff --git a/test/commonunittest/UTTest_dm_timer.cpp b/test/commonunittest/UTTest_dm_timer.cpp index 0c136646d..f883a68af 100644 --- a/test/commonunittest/UTTest_dm_timer.cpp +++ b/test/commonunittest/UTTest_dm_timer.cpp @@ -101,7 +101,7 @@ HWTEST_F(TimeHeapTest, DeleteTimer_001, testing::ext::TestSize.Level0) EXPECT_EQ(ERR_DM_INPUT_PARA_INVALID, ret); ret = timer->DeleteTimer(name); - EXPECT_EQ(ret, ERR_DM_FAILED); + EXPECT_EQ(DM_OK, ret); } /** diff --git a/test/unittest/UTTest_device_manager_notify_two.cpp b/test/unittest/UTTest_device_manager_notify_two.cpp index 150e24432..0bfa01ca3 100644 --- a/test/unittest/UTTest_device_manager_notify_two.cpp +++ b/test/unittest/UTTest_device_manager_notify_two.cpp @@ -491,7 +491,7 @@ HWTEST_F(DeviceManagerNotifyTest, OnDeviceOnline_002, testing::ext::TestSize.Lev DmDeviceInfo deviceInfo; DeviceManagerNotify::GetInstance().OnDeviceOnline(testPkgName, deviceInfo); // 8. check if callback OnDeviceOnline called - ASSERT_NE(count, 2); + ASSERT_EQ(count, 0); } /* @@ -689,7 +689,7 @@ HWTEST_F(DeviceManagerNotifyTest, OnDeviceOffline_002, testing::ext::TestSize.Le DmDeviceInfo deviceInfo; DeviceManagerNotify::GetInstance().OnDeviceOffline(testPkgName, deviceInfo); // 8. check if callback OnDeviceOffline called - ASSERT_NE(count, 2); + ASSERT_EQ(count, 0); } /* @@ -887,7 +887,7 @@ HWTEST_F(DeviceManagerNotifyTest, OnDeviceChanged_002, testing::ext::TestSize.Le DmDeviceInfo deviceInfo; DeviceManagerNotify::GetInstance().OnDeviceChanged(testPkgName, deviceInfo); // 8. check if callback OnDeviceChanged called - ASSERT_NE(count, 2); + ASSERT_EQ(count, 0); } /* diff --git a/test/unittest/UTTest_device_manager_service_two.cpp b/test/unittest/UTTest_device_manager_service_two.cpp index e91c337a1..b86ec7c57 100644 --- a/test/unittest/UTTest_device_manager_service_two.cpp +++ b/test/unittest/UTTest_device_manager_service_two.cpp @@ -300,7 +300,7 @@ HWTEST_F(DeviceManagerServiceTest, SetDnPolicy_201, testing::ext::TestSize.Level if (ret == DM_OK || ret == ERR_DM_UNSUPPORTED_METHOD) { bRet = true; } - ASSERT_EQ(bRet, true); + ASSERT_EQ(bRet, false); } /** diff --git a/utils/src/kvadapter/kv_adapter.cpp b/utils/src/kvadapter/kv_adapter.cpp index 61ad40f14..3ecb6e2a2 100644 --- a/utils/src/kvadapter/kv_adapter.cpp +++ b/utils/src/kvadapter/kv_adapter.cpp @@ -63,7 +63,7 @@ int32_t KVAdapter::Init() LOGE("CheckKvStore, left times: %{public}d, status: %{public}d", tryTimes, status); if (status == DistributedKv::Status::STORE_META_CHANGED || status == DistributedKv::Status::SECURITY_LEVEL_ERROR || - status == DistributedKv::Status::CRYPT_ERROR) { + status == DistributedKv::Status::DATA_CORRUPTED) { LOGE("init db error, remove and rebuild it"); DeleteKvStore(); } -- Gitee From 45cf5aeb3461077e57a41596a66411fa7179fcb3 Mon Sep 17 00:00:00 2001 From: l60055366 Date: Wed, 8 Jan 2025 19:05:27 +0800 Subject: [PATCH 02/10] =?UTF-8?q?=E4=BF=AE=E5=A4=8Ddm=E6=A8=A1=E5=9D=975.0?= =?UTF-8?q?.2=E7=9A=84=E5=B7=AE=E5=BC=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: l60055366 --- .../hichain/mine_hichain_connector.cpp | 3 + .../dependency/softbus/softbus_connector.cpp | 6 ++ services/service/BUILD.gn | 8 +++ .../service/include/device_manager_service.h | 7 ++- .../include/hichain/hichain_listener.h | 55 +++++++++++++++++++ .../include/idevice_manager_service_impl.h | 3 + 6 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 services/service/include/hichain/hichain_listener.h diff --git a/services/implementation/src/dependency/hichain/mine_hichain_connector.cpp b/services/implementation/src/dependency/hichain/mine_hichain_connector.cpp index 44e54a941..c5d37fd50 100644 --- a/services/implementation/src/dependency/hichain/mine_hichain_connector.cpp +++ b/services/implementation/src/dependency/hichain/mine_hichain_connector.cpp @@ -143,6 +143,7 @@ int32_t MineHiChainConnector::DeleteCredentialAndGroup(void) LOGE("failed to delete hichain credential and group with ret:%{public}d.", retValue); return ERR_DM_FAILED; } + g_deviceGroupManager->destroyInfo(&returnInfo); #endif return DM_OK; } @@ -263,9 +264,11 @@ int MineHiChainConnector::ImportCredential(std::string reqJsonStr, std::string & } if (CreateGroup(reqJsonStr) != DM_OK) { DeleteCredentialAndGroup(); + g_deviceGroupManager->destroyInfo(&returnInfo); LOGE("fail to import hichain credential bacause create group unsuccessfully."); return ERR_DM_HICHAIN_GROUP_CREATE_FAILED; } + g_deviceGroupManager->destroyInfo(&returnInfo); #endif LOGI("import device credential info successfully."); return DM_OK; diff --git a/services/implementation/src/dependency/softbus/softbus_connector.cpp b/services/implementation/src/dependency/softbus/softbus_connector.cpp index e61a19fa6..351ac00c9 100644 --- a/services/implementation/src/dependency/softbus/softbus_connector.cpp +++ b/services/implementation/src/dependency/softbus/softbus_connector.cpp @@ -645,9 +645,11 @@ std::string SoftbusConnector::GetNetworkIdByDeviceId(const std::string &deviceId LOGE("[SOFTBUS]GetNodeKeyInfo failed."); } if (reinterpret_cast(mUdid) == deviceId) { + FreeNodeInfo(nodeInfo); return static_cast(nodeBasicInfo->networkId); } } + FreeNodeInfo(nodeInfo); return ""; } @@ -720,10 +722,12 @@ bool SoftbusConnector::CheckIsOnline(const std::string &targetDeviceId) } std::string udid = reinterpret_cast(mUdid); if (udid == targetDeviceId) { + FreeNodeInfo(nodeInfo); LOGI("The device is online."); return true; } } + FreeNodeInfo(nodeInfo); LOGI("The device is not online."); return false; } @@ -741,6 +745,7 @@ DmDeviceInfo SoftbusConnector::GetDeviceInfoByDeviceId(const std::string &device char deviceIdHash[DM_MAX_DEVICE_ID_LEN] = {0}; if (Crypto::GetUdidHash(deviceId, reinterpret_cast(deviceIdHash)) != DM_OK) { LOGE("get deviceIdHash by deviceId: %{public}s failed.", GetAnonyString(deviceId).c_str()); + FreeNodeInfo(nodeInfo); return info; } for (int32_t i = 0; i < deviceCount; ++i) { @@ -749,6 +754,7 @@ DmDeviceInfo SoftbusConnector::GetDeviceInfoByDeviceId(const std::string &device if (GetNodeKeyInfo(DM_PKG_NAME, nodeBasicInfo->networkId, NodeDeviceInfoKey::NODE_KEY_UDID, mUdid, sizeof(mUdid)) != DM_OK) { LOGE("[SOFTBUS]GetNodeKeyInfo failed."); + FreeNodeInfo(nodeInfo); return info; } std::string udid = reinterpret_cast(mUdid); diff --git a/services/service/BUILD.gn b/services/service/BUILD.gn index fa728eb3c..aa8a7494f 100644 --- a/services/service/BUILD.gn +++ b/services/service/BUILD.gn @@ -26,6 +26,8 @@ if (defined(ohos_lite)) { "include", "include/advertise", "include/discovery", + "include/hichain", + "include/notify", "include/softbus", "include/ipc/lite", "include/permission/lite", @@ -68,6 +70,7 @@ if (defined(ohos_lite)) { "src/ipc/lite/ipc_server_listenermgr.cpp", "src/ipc/lite/ipc_server_main.cpp", "src/ipc/lite/ipc_server_stub.cpp", + "src/notify/device_manager_service_notify.cpp", "src/permission/lite/permission_manager.cpp", "src/pinholder/pin_holder.cpp", "src/pinholder/pin_holder_session.cpp", @@ -118,8 +121,10 @@ if (defined(ohos_lite)) { "include", "include/advertise", "include/discovery", + "include/hichain", "include/ipc", "include/ipc/standard", + "include/notify", "include/permission/standard", "include/pinholder", "include/publishcommonevent", @@ -162,10 +167,12 @@ if (defined(ohos_lite)) { "src/device_manager_service_listener.cpp", "src/discovery/discovery_filter.cpp", "src/discovery/discovery_manager.cpp", + "src/hichain/hichain_listener.cpp", "src/ipc/standard/ipc_cmd_parser.cpp", "src/ipc/standard/ipc_server_client_proxy.cpp", "src/ipc/standard/ipc_server_listener.cpp", "src/ipc/standard/ipc_server_stub.cpp", + "src/notify/device_manager_service_notify.cpp", "src/permission/standard/permission_manager.cpp", "src/pinholder/pin_holder.cpp", "src/pinholder/pin_holder_session.cpp", @@ -198,6 +205,7 @@ if (defined(ohos_lite)) { "c_utils:utils", "common_event_service:cesfwk_core", "common_event_service:cesfwk_innerkits", + "device_auth:deviceauth_sdk", "device_info_manager:distributed_device_profile_common", "device_info_manager:distributed_device_profile_sdk", "dsoftbus:softbus_client", diff --git a/services/service/include/device_manager_service.h b/services/service/include/device_manager_service.h index 0f4bb9279..af04d215e 100644 --- a/services/service/include/device_manager_service.h +++ b/services/service/include/device_manager_service.h @@ -29,6 +29,7 @@ #include "pin_holder.h" #include "device_manager_service_listener.h" #include "idevice_manager_service_impl.h" +#include "hichain_listener.h" #include "i_dm_service_impl_ext.h" #include "dm_single_instance.h" #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) @@ -53,6 +54,8 @@ public: int32_t InitSoftbusListener(); + void InitHichainListener(); + void RegisterCallerAppId(const std::string &pkgName); void UnRegisterCallerAppId(const std::string &pkgName); @@ -205,6 +208,7 @@ public: int32_t GetDeviceScreenStatus(const std::string &pkgName, const std::string &networkId, int32_t &screenStatus); void HandleCredentialAuthStatus(const std::string &proofInfo, uint16_t deviceTypeId, int32_t errcode); + void HandleDeviceUnBind(const char *peerUdid, const GroupInformation &groupInfo); private: bool IsDMServiceImplReady(); bool IsDMServiceAdapterLoad(); @@ -219,7 +223,7 @@ private: void ConvertUdidHashToAnoyDeviceId(DmDeviceInfo &deviceInfo); int32_t ConvertUdidHashToAnoyDeviceId(const std::string &udidHash, std::string &anoyDeviceId); int32_t GetUdidHashByAnoyDeviceId(const std::string &anoyDeviceId, std::string &udidHash); - void HandleAccountLogout(int32_t userId, const std::string &accountId); + void HandleAccountLogout(int32_t userId, const std::string &accountId, const std::string &accountName); void HandleUserRemoved(int32_t preUserId); #if defined(SUPPORT_BLUETOOTH) || defined(SUPPORT_WIFI) void SubscribePublishCommonEvent(); @@ -235,6 +239,7 @@ private: std::shared_ptr advertiseMgr_; std::shared_ptr discoveryMgr_; std::shared_ptr softbusListener_; + std::shared_ptr hichainListener_; std::shared_ptr listener_; std::shared_ptr dmServiceImpl_; std::shared_ptr dmServiceImplExt_; diff --git a/services/service/include/hichain/hichain_listener.h b/services/service/include/hichain/hichain_listener.h new file mode 100644 index 000000000..0adb7b0c6 --- /dev/null +++ b/services/service/include/hichain/hichain_listener.h @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_DM_HICHAIN_LISTENER_H +#define OHOS_DM_HICHAIN_LISTENER_H + +#include + +#include "device_auth.h" +#include "nlohmann/json.hpp" + +namespace OHOS { +namespace DistributedHardware { + +struct GroupInformation { + std::string groupName; + std::string groupId; + std::string groupOwner; + int32_t groupType; + int32_t groupVisibility; + int32_t userId; + std::string osAccountId; + + GroupInformation() : groupName(""), groupId(""), groupOwner(""), groupType(0), + groupVisibility(0), userId(0), osAccountId("") { + } +}; + +void from_json(const nlohmann::json &jsonObject, GroupInformation &groupInfo); + +class HichainListener { +public: + HichainListener(); + ~HichainListener(); + void RegisterDataChangeCb(); + static void OnHichainDeviceUnBound(const char *peerUdid, const char *groupInfo); + +private: + const DeviceGroupManager *deviceGroupManager_ = nullptr; +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DM_HICHAIN_LISTENER_H \ No newline at end of file diff --git a/services/service/include/idevice_manager_service_impl.h b/services/service/include/idevice_manager_service_impl.h index 8b13fbd64..0cc0d388b 100644 --- a/services/service/include/idevice_manager_service_impl.h +++ b/services/service/include/idevice_manager_service_impl.h @@ -289,6 +289,9 @@ public: virtual void HandleDeviceScreenStatusChange(DmDeviceInfo &devInfo) = 0; virtual void HandleCredentialAuthStatus(const std::string &proofInfo, uint16_t deviceTypeId, int32_t errcode) = 0; + virtual int32_t SaveOnlineDeviceInfo(const std::vector &deviceList) = 0; + virtual void HandleDeviceUnBind(int32_t bindType, const std::string &peerUdid, + const std::string &localUdid, int32_t localUserId, const std::string &localAccountId) = 0; }; using CreateDMServiceFuncPtr = IDeviceManagerServiceImpl *(*)(void); -- Gitee From 28c966e6d7e93874b997c619c4623d4ffaadacae Mon Sep 17 00:00:00 2001 From: l60055366 Date: Thu, 9 Jan 2025 19:18:36 +0800 Subject: [PATCH 03/10] =?UTF-8?q?=E4=BF=AE=E5=A4=8Ddm=E6=A8=A1=E5=9D=975.0?= =?UTF-8?q?.2=E7=9A=84=E5=B7=AE=E5=BC=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: l60055366 --- .../include/notify/device_manager_notify.h | 2 + .../native_cpp/src/device_manager_impl.cpp | 52 +++++++++++ .../src/ipc/lite/ipc_cmd_parser.cpp | 19 ++++ .../src/ipc/standard/dm_service_load.cpp | 3 +- .../src/ipc/standard/ipc_client_manager.cpp | 11 ++- .../src/ipc/standard/ipc_cmd_parser.cpp | 22 +++++ .../src/notify/device_manager_notify.cpp | 39 ++++++++ .../kits/js/src/native_devicemanager_js.cpp | 8 +- .../js4.0/src/native_devicemanager_js.cpp | 8 +- .../authentication/auth_request_state.h | 6 ++ .../authentication/auth_response_state.h | 6 ++ .../include/authentication/dm_auth_manager.h | 6 +- .../dependency/hichain/hichain_connector.h | 5 +- .../include/device_manager_service_impl.h | 3 + .../device_manager_service_impl_lite.h | 5 +- .../src/authentication/auth_request_state.cpp | 10 ++ .../authentication/auth_response_state.cpp | 10 ++ .../src/authentication/dm_auth_manager.cpp | 49 +++++++--- .../hichain/hichain_auth_connector.cpp | 8 +- .../dependency/hichain/hichain_connector.cpp | 93 +++++++++++++++---- .../src/device_manager_service_impl.cpp | 20 +++- .../src/device_manager_service_impl_lite.cpp | 30 +++--- 22 files changed, 358 insertions(+), 57 deletions(-) diff --git a/interfaces/inner_kits/native_cpp/include/notify/device_manager_notify.h b/interfaces/inner_kits/native_cpp/include/notify/device_manager_notify.h index 4459ad971..0f183ecc3 100644 --- a/interfaces/inner_kits/native_cpp/include/notify/device_manager_notify.h +++ b/interfaces/inner_kits/native_cpp/include/notify/device_manager_notify.h @@ -21,6 +21,7 @@ #include #include #include +#include #include #include @@ -116,6 +117,7 @@ public: void OnDeviceScreenStatus(const std::string &pkgName, const DmDeviceInfo &deviceInfo); void OnCredentialAuthStatus(const std::string &pkgName, const std::string &proofInfo, uint16_t deviceTypeId, int32_t errcode); + void GetCallBack(std::map> &callbackMap); private: #if !defined(__LITEOS_M__) diff --git a/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp b/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp index b7abbb79f..0b701dbd7 100644 --- a/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp +++ b/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp @@ -56,6 +56,7 @@ #include "ipc_start_discovery_req.h" #include "ipc_start_discover_req.h" #include "ipc_stop_discovery_req.h" +#include "ipc_sync_callback_req.h" #include "ipc_unauthenticate_device_req.h" #include "ipc_unbind_device_req.h" #include "ipc_unpublish_req.h" @@ -356,6 +357,7 @@ int32_t DeviceManagerImpl::RegisterDevStateCallback(const std::string &pkgName, return ret; } #endif + SyncCallbackToService(DmCommonNotifyEvent::REG_DEVICE_STATE, pkgName); DeviceManagerNotify::GetInstance().RegisterDeviceStateCallback(pkgName, callback); LOGI("Completed"); return DM_OK; @@ -369,6 +371,7 @@ int32_t DeviceManagerImpl::RegisterDevStatusCallback(const std::string &pkgName, return ERR_DM_INPUT_PARA_INVALID; } LOGI("Start, pkgName: %{public}s", pkgName.c_str()); + SyncCallbackToService(DmCommonNotifyEvent::REG_DEVICE_STATE, pkgName); DeviceManagerNotify::GetInstance().RegisterDeviceStatusCallback(pkgName, callback); LOGI("Completed"); return DM_OK; @@ -381,6 +384,7 @@ int32_t DeviceManagerImpl::UnRegisterDevStateCallback(const std::string &pkgName return ERR_DM_INPUT_PARA_INVALID; } LOGI("Start, pkgName: %{public}s", pkgName.c_str()); + SyncCallbackToService(DmCommonNotifyEvent::UN_REG_DEVICE_STATE, pkgName); DeviceManagerNotify::GetInstance().UnRegisterDeviceStateCallback(pkgName); LOGI("Completed"); return DM_OK; @@ -393,6 +397,7 @@ int32_t DeviceManagerImpl::UnRegisterDevStatusCallback(const std::string &pkgNam return ERR_DM_INPUT_PARA_INVALID; } LOGI("Start, pkgName: %{public}s", pkgName.c_str()); + SyncCallbackToService(DmCommonNotifyEvent::UN_REG_DEVICE_STATE, pkgName); DeviceManagerNotify::GetInstance().UnRegisterDeviceStatusCallback(pkgName); LOGI("Completed"); return DM_OK; @@ -1849,6 +1854,7 @@ int32_t DeviceManagerImpl::RegisterDevStateCallback(const std::string &pkgName, LOGE("DeviceManagerImpl::RegisterDeviceStateCallback failed: input pkgName or callback is empty."); return ERR_DM_INPUT_PARA_INVALID; } + SyncCallbackToService(DmCommonNotifyEvent::REG_DEVICE_STATE, pkgName); DeviceManagerNotify::GetInstance().RegisterDeviceStateCallback(pkgName, callback); LOGI("Completed, pkgName: %{public}s", pkgName.c_str()); return DM_OK; @@ -2239,6 +2245,7 @@ int32_t DeviceManagerImpl::RegisterDeviceScreenStatusCallback(const std::string LOGE("Error: Invalid para"); return ERR_DM_INPUT_PARA_INVALID; } + SyncCallbackToService(DmCommonNotifyEvent::REG_DEVICE_SCREEN_STATE, pkgName); DeviceManagerNotify::GetInstance().RegisterDeviceScreenStatusCallback(pkgName, callback); LOGI("Completed, pkgName: %{public}s", pkgName.c_str()); return DM_OK; @@ -2250,6 +2257,7 @@ int32_t DeviceManagerImpl::UnRegisterDeviceScreenStatusCallback(const std::strin LOGE("Error: Invalid para"); return ERR_DM_INPUT_PARA_INVALID; } + SyncCallbackToService(DmCommonNotifyEvent::UN_REG_DEVICE_SCREEN_STATE, pkgName); DeviceManagerNotify::GetInstance().UnRegisterDeviceScreenStatusCallback(pkgName); LOGI("Completed, pkgName: %{public}s", pkgName.c_str()); return DM_OK; @@ -2291,6 +2299,7 @@ int32_t DeviceManagerImpl::RegisterCredentialAuthStatusCallback(const std::strin LOGE("Error: Invalid para"); return ERR_DM_INPUT_PARA_INVALID; } + SyncCallbackToService(DmCommonNotifyEvent::REG_CREDENTIAL_AUTH_STATUS_NOTIFY, pkgName); DeviceManagerNotify::GetInstance().RegisterCredentialAuthStatusCallback(pkgName, callback); LOGI("Completed, pkgName: %{public}s", pkgName.c_str()); return DM_OK; @@ -2302,9 +2311,52 @@ int32_t DeviceManagerImpl::UnRegisterCredentialAuthStatusCallback(const std::str LOGE("Error: Invalid para"); return ERR_DM_INPUT_PARA_INVALID; } + SyncCallbackToService(DmCommonNotifyEvent::UN_REG_CREDENTIAL_AUTH_STATUS_NOTIFY, pkgName); DeviceManagerNotify::GetInstance().UnRegisterCredentialAuthStatusCallback(pkgName); LOGI("Completed, pkgName: %{public}s", pkgName.c_str()); return DM_OK; } + +void DeviceManagerImpl::SyncCallbackToService(DmCommonNotifyEvent dmCommonNotifyEvent, const std::string &pkgName) +{ + if (pkgName.empty()) { + LOGE("Invalid parameter, pkgName is empty."); + return; + } + if (!IsDmCommonNotifyEventValid(dmCommonNotifyEvent)) { + LOGE("Invalid dmCommonNotifyEvent: %{public}d.", dmCommonNotifyEvent); + return; + } + std::shared_ptr req = std::make_shared(); + std::shared_ptr rsp = std::make_shared(); + req->SetPkgName(pkgName); + req->SetDmCommonNotifyEvent(static_cast(dmCommonNotifyEvent)); + int32_t ret = ipcClientProxy_->SendRequest(SYNC_CALLBACK, req, rsp); + if (ret != DM_OK) { + LOGI("Send Request failed ret: %{public}d", ret); + return; + } + ret = rsp->GetErrCode(); + if (ret != DM_OK) { + LOGE("Failed with ret %{public}d", ret); + return; + } +} + +void DeviceManagerImpl::SyncCallbacksToService(std::map> &callbackMap) +{ + if (callbackMap.size() == 0) { + LOGI("callbackMap is empty."); + return; + } + for (auto iter : callbackMap) { + if (iter.second.size() == 0) { + continue; + } + for (auto item : iter.second) { + SyncCallbackToService(iter.first, item); + } + } +} } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/src/ipc/lite/ipc_cmd_parser.cpp b/interfaces/inner_kits/native_cpp/src/ipc/lite/ipc_cmd_parser.cpp index 248628c0d..da3c00b84 100644 --- a/interfaces/inner_kits/native_cpp/src/ipc/lite/ipc_cmd_parser.cpp +++ b/interfaces/inner_kits/native_cpp/src/ipc/lite/ipc_cmd_parser.cpp @@ -32,6 +32,7 @@ #include "ipc_set_credential_rsp.h" #include "ipc_start_discover_req.h" #include "ipc_stop_discovery_req.h" +#include "ipc_sync_callback_req.h" #include "securec.h" namespace OHOS { @@ -370,5 +371,23 @@ ON_IPC_CMD(SERVER_DISCOVER_FINISH, IpcIo &reply) DeviceManagerNotify::GetInstance().OnDiscoveryFailed(pkgName, subscribeId, failedReason); } } + +ON_IPC_SET_REQUEST(SYNC_CALLBACK, std::shared_ptr pBaseReq, IpcIo &request, uint8_t *buffer, + size_t buffLen) +{ + std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); + std::string pkgName = pReq->GetPkgName(); + int32_t dmCommonNotifyEvent = pReq->GetDmCommonNotifyEvent(); + + IpcIoInit(&request, buffer, buffLen, 0); + WriteString(&request, pkgName.c_str()); + WriteInt32(&request, dmCommonNotifyEvent); + return DM_OK; +} + +ON_IPC_READ_RESPONSE(SYNC_CALLBACK, IpcIo &reply, std::shared_ptr pBaseRsp) +{ + return SetRspErrCode(reply, pBaseRsp); +} } // namespace DistributedHardware } // namespace OHOS diff --git a/interfaces/inner_kits/native_cpp/src/ipc/standard/dm_service_load.cpp b/interfaces/inner_kits/native_cpp/src/ipc/standard/dm_service_load.cpp index 73179c37a..0e447d93f 100644 --- a/interfaces/inner_kits/native_cpp/src/ipc/standard/dm_service_load.cpp +++ b/interfaces/inner_kits/native_cpp/src/ipc/standard/dm_service_load.cpp @@ -54,7 +54,8 @@ void DmServiceLoad::SetLoadFinish(void) isDMServiceLoading_ = false; } -void DMLoadCallback::OnLoadSystemAbilitySuccess(int32_t systemAbilityId, const sptr &remoteObject) +void DMLoadCallback::OnLoadSystemAbilitySuccess(int32_t systemAbilityId, + const sptr &remoteObject) { LOGI("Load DM service success remoteObject result:%{public}s", (remoteObject != nullptr) ? "true" : "false"); DmServiceLoad::GetInstance().SetLoadFinish(); diff --git a/interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_client_manager.cpp b/interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_client_manager.cpp index fac75fe60..1ed10e28c 100644 --- a/interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_client_manager.cpp +++ b/interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_client_manager.cpp @@ -12,6 +12,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include +#include #include "ipc_client_manager.h" @@ -130,7 +132,6 @@ int32_t IpcClientManager::UnInit(const std::string &pkgName) if (dmListener_.empty()) { if (dmRecipient_ != nullptr) { dmInterface_->AsObject()->RemoveDeathRecipient(dmRecipient_); - dmRecipient_ = nullptr; } dmInterface_ = nullptr; } @@ -147,6 +148,7 @@ int32_t IpcClientManager::SendRequest(int32_t cmdCode, std::shared_ptr r if (req == nullptr || rsp == nullptr) { return ERR_DM_INPUT_PARA_INVALID; } + std::lock_guard autoLock(lock_); if (dmInterface_ != nullptr) { LOGD("IpcClientManager::SendRequest cmdCode: %{public}d", cmdCode); return dmInterface_->SendCmd(cmdCode, req, rsp); @@ -224,6 +226,13 @@ void IpcClientManager::SystemAbilityListener::OnAddSystemAbility(int32_t systemA for (auto iter : dmInitCallback) { DeviceManagerImpl::GetInstance().InitDeviceManager(iter.first, iter.second); } + std::map> callbackMap; + DeviceManagerNotify::GetInstance().GetCallBack(callbackMap); + if (callbackMap.size() == 0) { + LOGE("callbackMap is empty when ReInit"); + return; + } + DeviceManagerImpl::GetInstance().SyncCallbacksToService(callbackMap); } } } // namespace DistributedHardware diff --git a/interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_cmd_parser.cpp b/interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_cmd_parser.cpp index 9db23278c..c1b939b36 100644 --- a/interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_cmd_parser.cpp +++ b/interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_cmd_parser.cpp @@ -51,6 +51,7 @@ #include "ipc_start_discovery_req.h" #include "ipc_start_discover_req.h" #include "ipc_stop_discovery_req.h" +#include "ipc_sync_callback_req.h" #include "ipc_permission_req.h" #include "ipc_publish_req.h" #include "ipc_unbind_device_req.h" @@ -1729,5 +1730,26 @@ ON_IPC_CMD(SERVICE_CREDENTIAL_AUTH_STATUS_NOTIFY, MessageParcel &data, MessagePa reply.WriteInt32(DM_OK); return DM_OK; } + +ON_IPC_SET_REQUEST(SYNC_CALLBACK, std::shared_ptr pBaseReq, MessageParcel &data) +{ + std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); + std::string pkgName = pReq->GetPkgName(); + if (!data.WriteString(pkgName)) { + LOGE("write pkgName failed"); + return ERR_DM_IPC_WRITE_FAILED; + } + if (!data.WriteInt32(pReq->GetDmCommonNotifyEvent())) { + LOGE("write notify event failed"); + return ERR_DM_IPC_WRITE_FAILED; + } + return DM_OK; +} + +ON_IPC_READ_RESPONSE(SYNC_CALLBACK, MessageParcel &reply, std::shared_ptr pBaseRsp) +{ + pBaseRsp->SetErrCode(reply.ReadInt32()); + return DM_OK; +} } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/src/notify/device_manager_notify.cpp b/interfaces/inner_kits/native_cpp/src/notify/device_manager_notify.cpp index 4f7b85b35..46a334120 100644 --- a/interfaces/inner_kits/native_cpp/src/notify/device_manager_notify.cpp +++ b/interfaces/inner_kits/native_cpp/src/notify/device_manager_notify.cpp @@ -1143,5 +1143,44 @@ void DeviceManagerNotify::OnCredentialAuthStatus(const std::string &pkgName, con } tempCbk->OnCredentialAuthStatus(proofInfo, deviceTypeId, errcode); } + +void DeviceManagerNotify::GetCallBack(std::map> &callbackMap) +{ + std::lock_guard autoLock(lock_); + std::set statePkgnameSet; + for (auto it : deviceStateCallback_) { + statePkgnameSet.insert(it.first); + } + for (auto it : deviceStatusCallback_) { + statePkgnameSet.insert(it.first); + } + if (statePkgnameSet.size() > 0) { + callbackMap[DmCommonNotifyEvent::REG_DEVICE_STATE] = statePkgnameSet; + } + + std::set trustChangePkgnameSet; + for (auto it : devTrustChangeCallback_) { + trustChangePkgnameSet.insert(it.first); + } + if (trustChangePkgnameSet.size() > 0) { + callbackMap[DmCommonNotifyEvent::REG_REMOTE_DEVICE_TRUST_CHANGE] = trustChangePkgnameSet; + } + + std::set screenStatusPkgnameSet; + for (auto it : deviceScreenStatusCallback_) { + screenStatusPkgnameSet.insert(it.first); + } + if (screenStatusPkgnameSet.size() > 0) { + callbackMap[DmCommonNotifyEvent::REG_DEVICE_SCREEN_STATE] = screenStatusPkgnameSet; + } + + std::set authStatusPkgnameSet; + for (auto it : credentialAuthStatusCallback_) { + authStatusPkgnameSet.insert(it.first); + } + if (authStatusPkgnameSet.size() > 0) { + callbackMap[DmCommonNotifyEvent::REG_CREDENTIAL_AUTH_STATUS_NOTIFY] = authStatusPkgnameSet; + } +} } // namespace DistributedHardware } // namespace OHOS diff --git a/interfaces/kits/js/src/native_devicemanager_js.cpp b/interfaces/kits/js/src/native_devicemanager_js.cpp index b6b86e47c..6bf93c8bc 100644 --- a/interfaces/kits/js/src/native_devicemanager_js.cpp +++ b/interfaces/kits/js/src/native_devicemanager_js.cpp @@ -3208,7 +3208,7 @@ napi_value DeviceManagerNapi::Constructor(napi_env env, napi_callback_info info) obj->bundleName_ = std::string(bundleName); std::lock_guard autoLock(g_deviceManagerMapMutex); g_deviceManagerMap[obj->bundleName_] = obj; - napi_wrap( + napi_status status = napi_wrap( env, thisVar, reinterpret_cast(obj), [](napi_env env, void *data, void *hint) { (void)env; @@ -3219,6 +3219,12 @@ napi_value DeviceManagerNapi::Constructor(napi_env env, napi_callback_info info) LOGI("delete deviceManager"); }, nullptr, nullptr); + if (status != napi_ok) { + delete obj; + obj = nullptr; + LOGE("failed to wrap JS object"); + return nullptr; + } return thisVar; } diff --git a/interfaces/kits/js4.0/src/native_devicemanager_js.cpp b/interfaces/kits/js4.0/src/native_devicemanager_js.cpp index cdc023721..99f10e6ad 100644 --- a/interfaces/kits/js4.0/src/native_devicemanager_js.cpp +++ b/interfaces/kits/js4.0/src/native_devicemanager_js.cpp @@ -1940,7 +1940,7 @@ napi_value DeviceManagerNapi::Constructor(napi_env env, napi_callback_info info) obj->bundleName_ = bundleName; std::lock_guard autoLock(g_deviceManagerMapMutex); g_deviceManagerMap[obj->bundleName_] = obj; - napi_wrap( + napi_status status = napi_wrap( env, thisVar, reinterpret_cast(obj), [](napi_env env, void *data, void *hint) { (void)env; @@ -1951,6 +1951,12 @@ napi_value DeviceManagerNapi::Constructor(napi_env env, napi_callback_info info) LOGI("delete deviceManager"); }, nullptr, nullptr); + if (status != napi_ok) { + delete obj; + obj = nullptr; + LOGE("failed to wrap JS object"); + return nullptr; + } return thisVar; } diff --git a/services/implementation/include/authentication/auth_request_state.h b/services/implementation/include/authentication/auth_request_state.h index 21327c4ac..f0a616e53 100644 --- a/services/implementation/include/authentication/auth_request_state.h +++ b/services/implementation/include/authentication/auth_request_state.h @@ -211,6 +211,12 @@ public: int32_t GetStateType() override; int32_t Enter() override; }; + +class AuthRequestAuthFinish : public AuthRequestState { +public: + int32_t GetStateType() override; + int32_t Enter() override; +}; } // namespace DistributedHardware } // namespace OHOS #endif // OHOS_DM_AUTH_REQUEST_STATE_H diff --git a/services/implementation/include/authentication/auth_response_state.h b/services/implementation/include/authentication/auth_response_state.h index 53c395f3f..23fbe26bd 100644 --- a/services/implementation/include/authentication/auth_response_state.h +++ b/services/implementation/include/authentication/auth_response_state.h @@ -124,6 +124,12 @@ public: int32_t GetStateType() override; int32_t Enter() override; }; + +class AuthResponseAuthFinish : public AuthResponseState { +public: + int32_t GetStateType() override; + int32_t Enter() override; +}; } // namespace DistributedHardware } // namespace OHOS #endif // OHOS_DM_AUTH_RESPONSE_STATE_H diff --git a/services/implementation/include/authentication/dm_auth_manager.h b/services/implementation/include/authentication/dm_auth_manager.h index c835eba7a..1f0c21f17 100644 --- a/services/implementation/include/authentication/dm_auth_manager.h +++ b/services/implementation/include/authentication/dm_auth_manager.h @@ -50,6 +50,7 @@ typedef enum AuthState { AUTH_REQUEST_DELETE_INIT, AUTH_REQUEST_SYNCDELETE, AUTH_REQUEST_SYNCDELETE_DONE, + AUTH_REQUEST_AUTH_FINISH, AUTH_RESPONSE_INIT = 20, AUTH_RESPONSE_NEGOTIATE, @@ -60,6 +61,7 @@ typedef enum AuthState { AUTH_RESPONSE_CREDENTIAL, AUTH_RESPONSE_SYNCDELETE, AUTH_RESPONSE_SYNCDELETE_DONE, + AUTH_RESPONSE_AUTH_FINISH, } AuthState; enum DmMsgType : int32_t { @@ -161,7 +163,7 @@ typedef struct DmAuthResponseContext { std::string authToken; int32_t pageId; int64_t requestId; - int32_t code; + int32_t code = INVALID_PINCODE; int32_t state; std::vector syncGroupList; std::string accountGroupIdHash; @@ -529,6 +531,7 @@ public: void OnScreenLocked(); void HandleDeviceNotTrust(const std::string &udid); int32_t DeleteGroup(const std::string &pkgName, const std::string &deviceId); + int32_t DeleteGroup(const std::string &pkgName, int32_t userId, std::string &deviceId); int32_t StopAuthenticateDevice(const std::string &pkgName); private: int32_t ImportCredential(std::string &deviceId, std::string &publicKey); @@ -565,6 +568,7 @@ private: std::shared_ptr adapterMgr_; std::map> authenticationMap_; std::shared_ptr authRequestState_ = nullptr; + std::shared_ptr authRequestStateTemp_ = nullptr; std::shared_ptr authResponseState_ = nullptr; std::shared_ptr authRequestContext_; std::shared_ptr authResponseContext_; diff --git a/services/implementation/include/dependency/hichain/hichain_connector.h b/services/implementation/include/dependency/hichain/hichain_connector.h index c4e0e2df6..82770256c 100644 --- a/services/implementation/include/dependency/hichain/hichain_connector.h +++ b/services/implementation/include/dependency/hichain/hichain_connector.h @@ -230,13 +230,14 @@ public: void DeleteAllGroup(int32_t userId); void DeleteP2PGroup(int32_t userId); - + int32_t GetRelatedGroups(int32_t userId, const std::string &deviceId, std::vector &groupList); int32_t GetRelatedGroupsExt(const std::string &deviceId, std::vector &groupList); int32_t DeleteGroupExt(std::string &groupId); - int32_t GetRelatedGroupsCommon(const std::string &deviceId, const char* pkgName, std::vector &groupList); + int32_t GetRelatedGroupsCommon(int32_t userId, const std::string &deviceId, const char* pkgName, + std::vector &groupList); void DeleteAllGroupByUdid(const std::string &udid); private: int64_t GenRequestId(); diff --git a/services/implementation/include/device_manager_service_impl.h b/services/implementation/include/device_manager_service_impl.h index 2c411dc23..ead505bce 100644 --- a/services/implementation/include/device_manager_service_impl.h +++ b/services/implementation/include/device_manager_service_impl.h @@ -141,6 +141,9 @@ public: int32_t StopAuthenticateDevice(const std::string &pkgName); void HandleDeviceScreenStatusChange(DmDeviceInfo &devInfo); void HandleCredentialAuthStatus(const std::string &proofInfo, uint16_t deviceTypeId, int32_t errcode); + int32_t SaveOnlineDeviceInfo(const std::vector &deviceList); + void HandleDeviceUnBind(int32_t bindType, const std::string &peerUdid, + const std::string &localUdid, int32_t localUserId, const std::string &localAccountId); 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 55dd661ba..b1a33b377 100644 --- a/services/implementation/include/device_manager_service_impl_lite.h +++ b/services/implementation/include/device_manager_service_impl_lite.h @@ -135,13 +135,14 @@ public: int32_t CheckAccessControl(const DmAccessCaller &caller, const std::string &srcUdid, const DmAccessCallee &callee, const std::string &sinkUdid); void HandleDeviceNotTrust(const std::string &udid); - void HandleIdentAccountLogout(const std::string &udid, int32_t userId, const std::string &accountId); - void HandleUserRemoved(int32_t preUserId); std::map GetDeviceIdAndBindType(int32_t userId, const std::string &accountId); int32_t StopAuthenticateDevice(const std::string &pkgName); void HandleDeviceScreenStatusChange(DmDeviceInfo &devInfo); void HandleCredentialAuthStatus(const std::string &proofInfo, uint16_t deviceTypeId, int32_t errcode); + int32_t SaveOnlineDeviceInfo(const std::vector &deviceList); + void HandleDeviceUnBind(int32_t bindType, const std::string &peerUdid, const std::string &localUdid, + int32_t localUserId, const std::string &localAccountId); private: std::string GetUdidHashByNetworkId(const std::string &networkId); diff --git a/services/implementation/src/authentication/auth_request_state.cpp b/services/implementation/src/authentication/auth_request_state.cpp index 1d479538a..bc2f79eb3 100644 --- a/services/implementation/src/authentication/auth_request_state.cpp +++ b/services/implementation/src/authentication/auth_request_state.cpp @@ -252,5 +252,15 @@ int32_t AuthRequestSyncDeleteAclNone::Enter() stateAuthManager->SyncDeleteAclDone(); return DM_OK; } + +int32_t AuthRequestAuthFinish::GetStateType() +{ + return AuthState::AUTH_REQUEST_AUTH_FINISH; +} + +int32_t AuthRequestAuthFinish::Enter() +{ + return DM_OK; +} } // namespace DistributedHardware } // namespace OHOS diff --git a/services/implementation/src/authentication/auth_response_state.cpp b/services/implementation/src/authentication/auth_response_state.cpp index e86ef6fa2..3b4842e7d 100644 --- a/services/implementation/src/authentication/auth_response_state.cpp +++ b/services/implementation/src/authentication/auth_response_state.cpp @@ -200,5 +200,15 @@ int32_t AuthResponseSyncDeleteAclNone::Enter() stateAuthManager->SyncDeleteAclDone(); return DM_OK; } + +int32_t AuthResponseAuthFinish::GetStateType() +{ + return AuthState::AUTH_RESPONSE_AUTH_FINISH; +} + +int32_t AuthResponseAuthFinish::Enter() +{ + return DM_OK; +} } // namespace DistributedHardware } // namespace OHOS diff --git a/services/implementation/src/authentication/dm_auth_manager.cpp b/services/implementation/src/authentication/dm_auth_manager.cpp index 116d75f2a..6634e2f6a 100644 --- a/services/implementation/src/authentication/dm_auth_manager.cpp +++ b/services/implementation/src/authentication/dm_auth_manager.cpp @@ -178,10 +178,9 @@ void DmAuthManager::GetAuthParam(const std::string &pkgName, int32_t authType, authRequestContext_->deviceId = deviceId; authRequestContext_->ip = deviceId; authRequestContext_->dmVersion = DM_VERSION_5_0_2; - authRequestContext_->localAccountId = MultipleUserConnector::GetOhosAccountId(); - MultipleUserConnector::SetSwitchOldAccountId(authRequestContext_->localAccountId); authRequestContext_->localUserId = MultipleUserConnector::GetCurrentAccountUserID(); - MultipleUserConnector::SetSwitchOldUserId(authRequestContext_->localUserId); + authRequestContext_->localAccountId = MultipleUserConnector::GetAccountInfoByUserId( + authRequestContext_->localUserId).accountId; authRequestContext_->isOnline = false; authRequestContext_->authed = !authRequestContext_->bindType.empty(); authRequestContext_->bindLevel = INVALIED_TYPE; @@ -504,7 +503,7 @@ void DmAuthManager::ProcessSinkMsg() } break; case MSG_TYPE_REQ_PUBLICKEY: - if (authResponseState_->GetStateType() == AuthState::AUTH_RESPONSE_SHOW) { + if (authResponseState_->GetStateType() == AuthState::AUTH_RESPONSE_AUTH_FINISH) { authResponseState_->TransitionTo(std::make_shared()); } break; @@ -966,7 +965,6 @@ bool DmAuthManager::IsAuthFinish() if (authResponseContext_->isOnline && authResponseContext_->authed) { authRequestContext_->reason = DM_OK; - authResponseContext_->reply = DM_OK; authResponseContext_->state = AuthState::AUTH_REQUEST_FINISH; authRequestState_->TransitionTo(std::make_shared()); return true; @@ -977,7 +975,6 @@ bool DmAuthManager::IsAuthFinish() softbusConnector_->JoinLnn(authRequestContext_->deviceId); authRequestContext_->reason = DM_OK; authResponseContext_->state = AuthState::AUTH_REQUEST_FINISH; - authResponseContext_->reply = DM_OK; authRequestState_->TransitionTo(std::make_shared()); return true; } @@ -1274,6 +1271,7 @@ void DmAuthManager::AuthenticateFinish() authResponseContext_ = nullptr; authMessageProcessor_ = nullptr; authPtr_ = nullptr; + authRequestStateTemp_ = nullptr; LOGI("DmAuthManager::AuthenticateFinish complete"); } @@ -1360,6 +1358,8 @@ int32_t DmAuthManager::SetAuthRequestState(std::shared_ptr aut LOGE("authRequestState is nullptr."); return ERR_DM_INPUT_PARA_INVALID; } + // Keep current state, avoid deconstructed during state transitions + authRequestStateTemp_ = authRequestState_; authRequestState_ = authRequestState; return DM_OK; } @@ -2059,6 +2059,8 @@ bool DmAuthManager::AuthDeviceTransmit(int64_t requestId, const uint8_t *data, u void DmAuthManager::SrcAuthDeviceFinish() { + CHECK_NULL_VOID(authRequestState_); + authRequestState_->TransitionTo(std::make_shared()); if (authResponseContext_->isOnline) { if (authResponseContext_->confirmOperation == USER_OPERATION_TYPE_ALLOW_AUTH || (authResponseContext_->confirmOperation == USER_OPERATION_TYPE_ALLOW_AUTH_ALWAYS && @@ -2105,6 +2107,8 @@ void DmAuthManager::SrcAuthDeviceFinish() void DmAuthManager::SinkAuthDeviceFinish() { + CHECK_NULL_VOID(authResponseState_); + authResponseState_->TransitionTo(std::make_shared()); if (!authResponseContext_->haveCredential) { authUiStateMgr_->UpdateUiState(DmUiStateMsg::MSG_CANCEL_PIN_CODE_SHOW); } @@ -2216,7 +2220,7 @@ void DmAuthManager::CompatiblePutAcl() accesser.requestBundleName = authResponseContext_->hostPkgName; if (authRequestState_ != nullptr && authResponseState_ == nullptr) { accesser.requestUserId = MultipleUserConnector::GetCurrentAccountUserID(); - accesser.requestAccountId = MultipleUserConnector::GetOhosAccountId(); + accesser.requestAccountId = MultipleUserConnector::GetAccountInfoByUserId(accesser.requestUserId).accountId; accesser.requestDeviceId = localUdid; } else if (authRequestState_ == nullptr && authResponseState_ != nullptr) { accesser.requestDeviceId = authResponseContext_->localDeviceId; @@ -2229,7 +2233,7 @@ void DmAuthManager::CompatiblePutAcl() accessee.trustDeviceId = remoteDeviceId_; } else if (authRequestState_ == nullptr && authResponseState_ != nullptr) { accessee.trustUserId = MultipleUserConnector::GetCurrentAccountUserID(); - accessee.trustAccountId = MultipleUserConnector::GetOhosAccountId(); + accessee.trustAccountId = MultipleUserConnector::GetAccountInfoByUserId(accessee.trustUserId).accountId; accessee.trustDeviceId = localUdid; } DeviceProfileConnector::GetInstance().PutAccessControlList(aclInfo, accesser, accessee); @@ -2341,10 +2345,8 @@ void DmAuthManager::ProcRespNegotiateExt(const int32_t &sessionId) { LOGI("DmAuthManager::ProcRespNegotiateExt start."); remoteDeviceId_ = authResponseContext_->localDeviceId; - std::string accountId = MultipleUserConnector::GetOhosAccountId(); - int32_t userId = MultipleUserConnector::GetCurrentAccountUserID(); - MultipleUserConnector::SetSwitchOldAccountId(accountId); - MultipleUserConnector::SetSwitchOldUserId(userId); + int32_t userId = MultipleUserConnector::GetAccountUserID(userId).accountId; + std::string accountId = MultipleUserConnector::GetAccountInfoByUserId(); authResponseContext_->isIdenticalAccount = false; if (authResponseContext_->localAccountId == accountId && accountId != "ohosAnonymousUid") { authResponseContext_->isIdenticalAccount = true; @@ -2529,6 +2531,29 @@ int32_t DmAuthManager::DeleteGroup(const std::string &pkgName, const std::string return DM_OK; } +int32_t DmAuthManager::DeleteGroup(const std::string &pkgName, int32_t userId, const std::string &deviceId) +{ + LOGI("DmAuthManager::DeleteGroup"); + if (pkgName.empty()) { + LOGE("Invalid parameter, pkgName is empty."); + return ERR_DM_FAILED; + } + std::vector groupList; + hiChainConnector_->GetRelatedGroups(userId, deviceId, groupList); + if (groupList.size() > 0) { + std::string groupId = ""; + groupId = groupList.front().groupId; + hiChainConnector_->DeleteGroup(userId, groupId); + } else { + LOGE("DmAuthManager::UnAuthenticateDevice groupList.size = 0"); + return ERR_DM_FAILED; + } + if (softbusConnector_ != nullptr) { + softbusConnector_->EraseUdidFromMap(deviceId); + } + return DM_OK; +} + void DmAuthManager::PutAccessControlList() { char localDeviceId[DEVICE_UUID_LENGTH] = {0}; diff --git a/services/implementation/src/dependency/hichain/hichain_auth_connector.cpp b/services/implementation/src/dependency/hichain/hichain_auth_connector.cpp index c7887c985..88ae36656 100644 --- a/services/implementation/src/dependency/hichain/hichain_auth_connector.cpp +++ b/services/implementation/src/dependency/hichain/hichain_auth_connector.cpp @@ -80,7 +80,7 @@ int32_t HiChainAuthConnector::ProcessAuthData(int64_t requestId, std::string aut } return DM_OK; } - + bool HiChainAuthConnector::onTransmit(int64_t requestId, const uint8_t *data, uint32_t dataLen) { LOGI("AuthDevice onTransmit, requestId %{public}" PRId64, requestId); @@ -101,15 +101,15 @@ char *HiChainAuthConnector::onRequest(int64_t requestId, int operationCode, cons return nullptr; } nlohmann::json jsonObj; - int32_t pinCode = 0; - if (dmDeviceAuthCallback_->GetPinCode(pinCode) == ERR_DM_FAILED) { + int32_t pinCode = INVALID_PINCODE; + if (dmDeviceAuthCallback_->GetPinCode(pinCode) == ERR_DM_FAILED || pinCode == INVALID_PINCODE) { jsonObj[FIELD_CONFIRMATION] = RequestResponse::REQUEST_REJECTED; } else { jsonObj[FIELD_CONFIRMATION] = RequestResponse::REQUEST_ACCEPTED; + jsonObj[FIELD_PIN_CODE] = std::to_string(pinCode); } std::string deviceId = ""; dmDeviceAuthCallback_->GetRemoteDeviceId(deviceId); - jsonObj[FIELD_PIN_CODE] = std::to_string(pinCode); jsonObj[FIELD_PEER_CONN_DEVICE_ID] = deviceId; std::string jsonStr = jsonObj.dump(); char *buffer = strdup(jsonStr.c_str()); diff --git a/services/implementation/src/dependency/hichain/hichain_connector.cpp b/services/implementation/src/dependency/hichain/hichain_connector.cpp index 721a7f224..2e9e569c4 100644 --- a/services/implementation/src/dependency/hichain/hichain_connector.cpp +++ b/services/implementation/src/dependency/hichain/hichain_connector.cpp @@ -492,13 +492,13 @@ char *HiChainConnector::onRequest(int64_t requestId, int operationCode, const ch return nullptr; } nlohmann::json jsonObj; - int32_t pinCode = 0; - if (hiChainConnectorCallback_->GetPinCode(pinCode) == ERR_DM_FAILED) { + int32_t pinCode = INVALID_PINCODE; + if (hiChainConnectorCallback_->GetPinCode(pinCode) == ERR_DM_FAILED || pinCode == INVALID_PINCODE) { jsonObj[FIELD_CONFIRMATION] = REQUEST_REJECTED; } else { jsonObj[FIELD_CONFIRMATION] = REQUEST_ACCEPTED; + jsonObj[FIELD_PIN_CODE] = std::to_string(pinCode); } - jsonObj[FIELD_PIN_CODE] = std::to_string(pinCode).c_str(); char localDeviceId[DEVICE_UUID_LENGTH] = {0}; GetDevUdid(localDeviceId, DEVICE_UUID_LENGTH); jsonObj[FIELD_DEVICE_ID] = localDeviceId; @@ -536,6 +536,12 @@ int32_t HiChainConnector::GetRelatedGroups(const std::string &deviceId, std::vec return GetRelatedGroupsCommon(deviceId, DM_PKG_NAME, groupList); } +int32_t HiChainConnector::GetRelatedGroups(int32_t userId, const std::string &deviceId, + std::vector &groupList) +{ + return GetRelatedGroupsCommon(userId, deviceId, DM_PKG_NAME, groupList); +} + int32_t HiChainConnector::GetRelatedGroupsExt(const std::string &deviceId, std::vector &groupList) { return GetRelatedGroupsCommon(deviceId, DM_PKG_NAME_EXT, groupList); @@ -667,20 +673,6 @@ int32_t HiChainConnector::DeleteGroupExt(std::string &groupId) return DM_OK; } -int32_t HiChainConnector::DeleteGroup(const int32_t userId, std::string &groupId) -{ - int64_t requestId = GenRequestId(); - nlohmann::json jsonObj; - jsonObj[FIELD_GROUP_ID] = groupId; - std::string disbandParams = jsonObj.dump(); - int32_t ret = deviceGroupManager_->deleteGroup(userId, requestId, DM_PKG_NAME, disbandParams.c_str()); - if (ret != 0) { - LOGE("[HICHAIN]fail to delete group failed, ret: %{public}d.", ret); - return ERR_DM_FAILED; - } - return DM_OK; -} - int32_t HiChainConnector::DeleteGroup(int64_t requestId_, const std::string &userId, const int32_t authType) { networkStyle_ = CREDENTIAL_NETWORK; @@ -1207,6 +1199,73 @@ int32_t HiChainConnector::GetRelatedGroupsCommon(const std::string &deviceId, co return DM_OK; } +int32_t HiChainConnector::DeleteGroup(const int32_t userId, std::string &groupId) +{ + if (userId < 0) { + LOGE("user id failed"); + return ERR_DM_FAILED; + } + int64_t requestId = GenRequestId(); + nlohmann::json jsonObj; + jsonObj[FIELD_GROUP_ID] = groupId; + std::string disbandParams = SafetyDump(jsonObj); + int32_t ret = deviceGroupManager_->deleteGroup(userId, requestId, DM_PKG_NAME, disbandParams.c_str()); + if (ret != 0) { + LOGE("[HICHAIN]fail to delete group with ret:%{public}d.", ret); + return ERR_DM_FAILED; + } + return DM_OK; +} + +int32_t HiChainConnector::GetRelatedGroupsCommon(int32_t userId, const std::string &deviceId, const char* pkgName, + std::vector &groupList) +{ + LOGI("Start to get related groups."); + if (userId < 0) { + LOGE("user id failed"); + return ERR_DM_FAILED; + } + uint32_t groupNum = 0; + char *returnGroups = nullptr; + int32_t ret = + deviceGroupManager_->getRelatedGroups(userId, pkgName, deviceId.c_str(), &returnGroups, &groupNum); + if (ret != 0) { + LOGE("[HICHAIN] fail to get related groups with ret:%{public}d.", ret); + delete[] returnGroups; + returnGroups = nullptr; + return ERR_DM_FAILED; + } + if (returnGroups == nullptr) { + LOGE("[HICHAIN] return related goups point is nullptr"); + return ERR_DM_FAILED; + } + if (groupNum == 0) { + LOGE("[HICHAIN]return related goups number is zero."); + delete[] returnGroups; + returnGroups = nullptr; + return ERR_DM_FAILED; + } + std::string relatedGroups = std::string(returnGroups); + delete[] returnGroups; + returnGroups = nullptr; + nlohmann::json jsonObject = nlohmann::json::parse(relatedGroups, nullptr, false); + if (jsonObject.is_discarded()) { + LOGE("returnGroups parse error"); + return ERR_DM_FAILED; + } + if (!jsonObject.is_array()) { + LOGE("jsonObject is not an array."); + return ERR_DM_FAILED; + } + std::vector groupInfos = jsonObject.get>(); + if (groupInfos.empty()) { + LOGE("HiChainConnector::GetRelatedGroups group failed, groupInfos is empty."); + return ERR_DM_FAILED; + } + groupList = groupInfos; + return DM_OK; +} + void HiChainConnector::DeleteAllGroupByUdid(const std::string &udid) { LOGI("HiChainConnector::DeleteAllGroupByUdid %{public}s.", GetAnonyString(udid).c_str()); diff --git a/services/implementation/src/device_manager_service_impl.cpp b/services/implementation/src/device_manager_service_impl.cpp index 97e1d5ce2..bf487b8d0 100644 --- a/services/implementation/src/device_manager_service_impl.cpp +++ b/services/implementation/src/device_manager_service_impl.cpp @@ -764,8 +764,8 @@ void DeviceManagerServiceImpl::HandleIdentAccountLogout(const std::string &udid, GetDevUdid(localUdidTemp, DEVICE_UUID_LENGTH); std::string localUdid = std::string(localUdidTemp); DeviceProfileConnector::GetInstance().DeleteAclForAccountLogOut(localUdid, userId, udid); - CHECK_NULL_VOID(hiChainConnector_); - authMgr_->DeleteGroup(DM_PKG_NAME, udid); + CHECK_NULL_VOID(authMgr_); + authMgr_->DeleteGroup(DM_PKG_NAME, userId, udid); } void DeviceManagerServiceImpl::HandleUserRemoved(int32_t preUserId) @@ -830,6 +830,22 @@ void DeviceManagerServiceImpl::HandleCredentialAuthStatus(const std::string &pro deviceStateMgr_->HandleCredentialAuthStatus(proofInfo, deviceTypeId, errcode); } +int32_t DeviceManagerServiceImpl::SaveOnlineDeviceInfo(const std::vector &deviceList) +{ + CHECK_NULL_RETURN(deviceStateMgr_, ERR_DM_POINT_NULL); + for (auto item : deviceList) { + deviceStateMgr_->SaveOnlineDeviceInfo(item); + } + return DM_OK; +} + +void DeviceManagerServiceImpl::HandleDeviceUnBind(int32_t bindType, const std::string &peerUdid, + const std::string &localUdid, int32_t localUserId, const std::string &localAccountId) +{ + return DeviceProfileConnector::GetInstance().HandleDeviceUnBind(bindType, peerUdid, + localUdid, localUserId, localAccountId); +} + 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 4e47203ba..1e08028b1 100644 --- a/services/implementation/src/device_manager_service_impl_lite.cpp +++ b/services/implementation/src/device_manager_service_impl_lite.cpp @@ -487,19 +487,6 @@ void DeviceManagerServiceImpl::HandleDeviceNotTrust(const std::string &udid) return; } -void DeviceManagerServiceImpl::HandleIdentAccountLogout(const std::string &udid, int32_t userId, - const std::string &accountId) -{ - (void)udid; - (void)userId; - (void)accountId; -} - -void DeviceManagerServiceImpl::HandleUserRemoved(int32_t preUserId) -{ - (void)preUserId; -} - std::map DeviceManagerServiceImpl::GetDeviceIdAndBindType(int32_t userId, const std::string &accountId) { @@ -529,6 +516,23 @@ void DeviceManagerServiceImpl::HandleCredentialAuthStatus(const std::string &pro return; } +int32_t DeviceManagerServiceImpl::SaveOnlineDeviceInfo(const std::vector &deviceList) +{ + (void)deviceList; + return DM_OK; +} + +void DeviceManagerServiceImpl::HandleDeviceUnBind(int32_t bindType, const std::string &peerUdid, + const std::string &localUdid, int32_t localUserId, const std::string &localAccountId) +{ + (void)bindType; + (void)peerUdid; + (void)localUdid; + (void)localUserId; + (void)localAccountId; + return; +} + extern "C" IDeviceManagerServiceImpl *CreateDMServiceObject(void) { return new DeviceManagerServiceImpl; -- Gitee From 2f6e7bae5161ed79a307814153328fefbf35d1b7 Mon Sep 17 00:00:00 2001 From: l60055366 Date: Thu, 9 Jan 2025 20:10:08 +0800 Subject: [PATCH 04/10] =?UTF-8?q?=E4=BF=AE=E5=A4=8Ddm=E6=A8=A1=E5=9D=975.0?= =?UTF-8?q?.2=E7=9A=84=E5=B7=AE=E5=BC=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: l60055366 --- .../device_manager_ipc_interface_code.h | 2 + common/include/dm_anonymous.h | 1 + common/include/dm_constants.h | 2 +- .../include/ipc/model/ipc_sync_callback_req.h | 51 +++++++++++++++ .../include/ipc/standard/ipc_cmd_register.h | 7 +++ common/src/dm_anonymous.cpp | 8 +++ common/src/ipc/standard/ipc_cmd_register.cpp | 63 +++++++++++-------- .../include/deviceprofile_connector.h | 4 ++ .../include/multiple_user_connector.h | 11 ++++ .../src/deviceprofile_connector.cpp | 36 ++++++++++- .../src/multiple_user_connector.cpp | 31 +++++++++ .../native_cpp/include/device_manager_impl.h | 3 + .../native_cpp/include/dm_device_info.h | 13 ++++ 13 files changed, 205 insertions(+), 27 deletions(-) create mode 100644 common/include/ipc/model/ipc_sync_callback_req.h diff --git a/common/include/device_manager_ipc_interface_code.h b/common/include/device_manager_ipc_interface_code.h index ab8d3b2a8..1241a75a9 100644 --- a/common/include/device_manager_ipc_interface_code.h +++ b/common/include/device_manager_ipc_interface_code.h @@ -96,6 +96,8 @@ enum DMIpcCmdInterfaceCode { SERVER_DEVICE_SCREEN_STATE_NOTIFY, GET_DEVICE_SCREEN_STATUS, SERVICE_CREDENTIAL_AUTH_STATUS_NOTIFY, + SYNC_CALLBACK, + // Add ipc msg here IPC_MSG_BUTT }; } // namespace DistributedHardware diff --git a/common/include/dm_anonymous.h b/common/include/dm_anonymous.h index 159575be3..47c57e3bf 100644 --- a/common/include/dm_anonymous.h +++ b/common/include/dm_anonymous.h @@ -41,6 +41,7 @@ std::string ConvertCharArray2String(const char *srcData, uint32_t srcLen); void VersionSplitToInt(const std::string &str, const char split, std::vector &numVec); bool CompareVecNum(const std::vector &srcVecNum, const std::vector &sinkVecNum); int32_t StringToInt(const std::string &str, int32_t base); +bool IsDmCommonNotifyEventValid(DmCommonNotifyEvent dmCommonNotifyEvent); } // namespace DistributedHardware } // namespace OHOS #endif // OHOS_DM_ANONYMOUS_H diff --git a/common/include/dm_constants.h b/common/include/dm_constants.h index 211d2b55c..683ad50cc 100755 --- a/common/include/dm_constants.h +++ b/common/include/dm_constants.h @@ -165,7 +165,7 @@ constexpr int32_t CHECK_AUTH_ALWAYS_POS = 0; constexpr const char AUTH_ALWAYS = '1'; constexpr const char AUTH_ONCE = '0'; constexpr const char* TAG_TARGET_DEVICE_NAME = "targetDeviceName"; - +constexpr int32_t INVALID_PINCODE = -1; // HiChain constexpr int32_t SERVICE_INIT_TRY_MAX_NUM = 200; constexpr int32_t DEVICE_UUID_LENGTH = 65; diff --git a/common/include/ipc/model/ipc_sync_callback_req.h b/common/include/ipc/model/ipc_sync_callback_req.h new file mode 100644 index 000000000..cf9c3e0a8 --- /dev/null +++ b/common/include/ipc/model/ipc_sync_callback_req.h @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_DM_IPC_SYNC_CALLBACK_REQ_H +#define OHOS_DM_IPC_SYNC_CALLBACK_REQ_H + +#include "ipc_req.h" + +namespace OHOS { +namespace DistributedHardware { +class IpcSyncCallbackReq : public IpcReq { + DECLARE_IPC_MODEL(IpcSyncCallbackReq); + +public: + /** + * @tc.name: IpcSyncCallbackReq::GetDmCommonNotifyEvent + * @tc.desc: Get notifyEvent of the Ipc Request + * @tc.type: FUNC + */ + int32_t GetDmCommonNotifyEvent() const + { + return dmCommonNotifyEvent_; + } + + /** + * @tc.name: IpcSyncCallbackReq::SetDmCommonNotifyEvent + * @tc.desc: Set notifyEvent of the Ipc Request + * @tc.type: FUNC + */ + void SetDmCommonNotifyEvent(int32_t dmCommonNotifyEvent) + { + dmCommonNotifyEvent_ = dmCommonNotifyEvent; + } +private: + int32_t dmCommonNotifyEvent_ = 0; +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DM_IPC_SYNC_CALLBACK_REQ_H diff --git a/common/include/ipc/standard/ipc_cmd_register.h b/common/include/ipc/standard/ipc_cmd_register.h index 650a69950..885abc550 100644 --- a/common/include/ipc/standard/ipc_cmd_register.h +++ b/common/include/ipc/standard/ipc_cmd_register.h @@ -18,6 +18,7 @@ #include #include +#include #include #include "device_manager_ipc_interface_code.h" @@ -76,6 +77,7 @@ public: */ void RegisterSetRequestFunc(int32_t cmdCode, SetIpcRequestFunc setIpcRequestFunc) { + std::lock_guard autoLock(setIpcRequestFuncMapLock_); setIpcRequestFuncMap_.emplace(cmdCode, setIpcRequestFunc); }; @@ -86,6 +88,7 @@ public: */ void RegisterReadResponseFunc(int32_t cmdCode, ReadResponseFunc readResponseFunc) { + std::lock_guard autoLock(readResponseFuncMapLock_); readResponseFuncMap_.emplace(cmdCode, readResponseFunc); }; @@ -96,6 +99,7 @@ public: */ void RegisterCmdProcessFunc(int32_t cmdCode, OnIpcCmdFunc onIpcCmdFunc) { + std::lock_guard autoLock(onIpcCmdFuncMapLock_); onIpcCmdFuncMap_.emplace(cmdCode, onIpcCmdFunc); }; @@ -121,8 +125,11 @@ public: int32_t OnIpcCmd(int32_t cmdCode, MessageParcel &data, MessageParcel &reply); private: + std::mutex setIpcRequestFuncMapLock_; std::unordered_map setIpcRequestFuncMap_; + std::mutex readResponseFuncMapLock_; std::unordered_map readResponseFuncMap_; + std::mutex onIpcCmdFuncMapLock_; std::unordered_map onIpcCmdFuncMap_; }; } // namespace DistributedHardware diff --git a/common/src/dm_anonymous.cpp b/common/src/dm_anonymous.cpp index 783289fb5..d1ef84e90 100644 --- a/common/src/dm_anonymous.cpp +++ b/common/src/dm_anonymous.cpp @@ -229,5 +229,13 @@ int32_t StringToInt(const std::string &str, int32_t base) } return static_cast(result); } + +bool IsDmCommonNotifyEventValid(DmCommonNotifyEvent dmCommonNotifyEvent) +{ + if (dmCommonNotifyEvent > DmCommonNotifyEvent::MIN && dmCommonNotifyEvent < DmCommonNotifyEvent::MAX) { + return true; + } + return false; +} } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file diff --git a/common/src/ipc/standard/ipc_cmd_register.cpp b/common/src/ipc/standard/ipc_cmd_register.cpp index 4f18a43bb..0b8f50923 100644 --- a/common/src/ipc/standard/ipc_cmd_register.cpp +++ b/common/src/ipc/standard/ipc_cmd_register.cpp @@ -42,20 +42,21 @@ int32_t IpcCmdRegister::SetRequest(int32_t cmdCode, std::shared_ptr pBas return ERR_DM_UNSUPPORTED_IPC_COMMAND; } - if (setIpcRequestFuncMap_.count(cmdCode) == 0) { - LOGE("cmdCode:%{public}d not register SetRequestFunc", cmdCode); - return ERR_DM_UNSUPPORTED_IPC_COMMAND; - } - - auto setRequestMapIter = setIpcRequestFuncMap_.find(cmdCode); - if (setRequestMapIter != setIpcRequestFuncMap_.end()) { - SetIpcRequestFunc ptr = setRequestMapIter->second; + SetIpcRequestFunc ptr = nullptr; + { + std::lock_guard autoLock(setIpcRequestFuncMapLock_); + auto setRequestMapIter = setIpcRequestFuncMap_.find(cmdCode); + if (setRequestMapIter == setIpcRequestFuncMap_.end()) { + LOGE("cmdCode:%{public}d not register SetRequestFunc", cmdCode); + return ERR_DM_UNSUPPORTED_IPC_COMMAND; + } + ptr = setRequestMapIter->second; if (ptr == nullptr) { LOGE("IpcCmdRegister::SetRequest setRequestMapIter->second is null"); return ERR_DM_POINT_NULL; } - ret = (setRequestMapIter->second)(pBaseReq, data); } + ret = (ptr)(pBaseReq, data); return ret; } @@ -65,15 +66,21 @@ int32_t IpcCmdRegister::ReadResponse(int32_t cmdCode, MessageParcel &reply, std: LOGE("IpcCmdRegister::ReadResponse cmdCode param invalid!"); return ERR_DM_UNSUPPORTED_IPC_COMMAND; } - auto readResponseMapIter = readResponseFuncMap_.find(cmdCode); - if (readResponseMapIter == readResponseFuncMap_.end()) { - LOGE("cmdCode:%{public}d not register ReadResponseFunc", cmdCode); - return ERR_DM_UNSUPPORTED_IPC_COMMAND; - } - if (readResponseMapIter->second == nullptr) { - return ERR_DM_POINT_NULL; + ReadResponseFunc ptr = nullptr; + { + std::lock_guard autoLock(readResponseFuncMapLock_); + auto readResponseMapIter = readResponseFuncMap_.find(cmdCode); + if (readResponseMapIter == readResponseFuncMap_.end()) { + LOGE("cmdCode:%{public}d not register ReadResponseFunc", cmdCode); + return ERR_DM_UNSUPPORTED_IPC_COMMAND; + } + ptr = readResponseMapIter->second; + if (ptr == nullptr) { + LOGE("IpcCmdRegister::ReadResponse readResponseMapIter->second is null"); + return ERR_DM_POINT_NULL; + } } - return (readResponseMapIter->second)(reply, pBaseRsp); + return (ptr)(reply, pBaseRsp); } int32_t IpcCmdRegister::OnIpcCmd(int32_t cmdCode, MessageParcel &data, MessageParcel &reply) @@ -82,15 +89,21 @@ int32_t IpcCmdRegister::OnIpcCmd(int32_t cmdCode, MessageParcel &data, MessagePa LOGE("IpcCmdRegister::OnIpcCmd cmdCode param invalid!"); return ERR_DM_UNSUPPORTED_IPC_COMMAND; } - auto onIpcCmdMapIter = onIpcCmdFuncMap_.find(cmdCode); - if (onIpcCmdMapIter == onIpcCmdFuncMap_.end()) { - LOGE("cmdCode:%{public}d not register OnIpcCmdFunc", cmdCode); - return ERR_DM_UNSUPPORTED_IPC_COMMAND; - } - if (onIpcCmdMapIter->second == nullptr) { - return ERR_DM_POINT_NULL; + OnIpcCmdFunc ptr = nullptr; + { + std::lock_guard autoLock(onIpcCmdFuncMapLock_); + auto onIpcCmdMapIter = onIpcCmdFuncMap_.find(cmdCode); + if (onIpcCmdMapIter == onIpcCmdFuncMap_.end()) { + LOGE("cmdCode:%{public}d not register OnIpcCmdFunc", cmdCode); + return ERR_DM_UNSUPPORTED_IPC_COMMAND; + } + ptr = onIpcCmdMapIter->second; + if (ptr == nullptr) { + LOGE("IpcCmdRegister::OnIpcCmd onIpcCmdMapIter->second is null"); + return ERR_DM_POINT_NULL; + } } - return (onIpcCmdMapIter->second)(data, reply); + return (ptr)(data, reply); } } // namespace DistributedHardware } // namespace OHOS diff --git a/commondependency/include/deviceprofile_connector.h b/commondependency/include/deviceprofile_connector.h index c573d6822..d98dbdfe3 100644 --- a/commondependency/include/deviceprofile_connector.h +++ b/commondependency/include/deviceprofile_connector.h @@ -155,6 +155,10 @@ public: void DeleteAclForAccountLogOut(const std::string &localUdid, int32_t userId, const std::string &remoteUdid); std::map GetDeviceIdAndBindType(int32_t userId, const std::string &accountId, const std::string &localUdid); + void HandleDeviceUnBind(int32_t bindType, const std::string &peerUdid, + const std::string &localUdid, int32_t localUserId, const std::string &localAccountId); + std::vector GetAllAccessControlProfile(); + void DeleteAccessControlById(int64_t accessControlId); private: int32_t HandleDmAuthForm(DistributedDeviceProfile::AccessControlProfile profiles, DmDiscoveryInfo discoveryInfo); void GetParamBindTypeVec(DistributedDeviceProfile::AccessControlProfile profiles, std::string pkgName, diff --git a/commondependency/include/multiple_user_connector.h b/commondependency/include/multiple_user_connector.h index 9dd87d383..8abfc3ce5 100644 --- a/commondependency/include/multiple_user_connector.h +++ b/commondependency/include/multiple_user_connector.h @@ -17,10 +17,15 @@ #define OHOS_DM_MULTIPLE_USER_CONNECTOR_H #include +#include #include #include namespace OHOS { namespace DistributedHardware { +typedef struct DMAccountInfo { + std::string accountId; + std::string accountName; +} DMAccountInfo; class MultipleUserConnector { public: /** @@ -82,11 +87,17 @@ public: * @tc.type: FUNC */ static std::string GetSwitchOldAccountName(void); + + static void SetAccountInfo(int32_t userId, DMAccountInfo dmAccountInfo); + static DMAccountInfo GetAccountInfoByUserId(int32_t userId); + static void DeleteAccountInfoByUserId(int32_t userId); private: static int32_t oldUserId_; static std::string accountId_; static std::string accountName_; static std::mutex lock_; + static std::map dmAccountInfoMap_; + static std::mutex dmAccountInfoMaplock_; }; } // namespace DistributedHardware } // namespace OHOS diff --git a/commondependency/src/deviceprofile_connector.cpp b/commondependency/src/deviceprofile_connector.cpp index e50a64d1d..39a991388 100644 --- a/commondependency/src/deviceprofile_connector.cpp +++ b/commondependency/src/deviceprofile_connector.cpp @@ -830,7 +830,7 @@ bool DeviceProfileConnector::SingleUserProcess(const DistributedDeviceProfile::A int32_t DeviceProfileConnector::CheckIsSameAccount(const DmAccessCaller &caller, const std::string &srcUdid, const DmAccessCallee &callee, const std::string &sinkUdid) { - LOGI(" DeviceProfileConnector::CheckIsSameAccount pkgName %{public}s, srcUdid %{public}s, sinkUdid %{public}s", + LOGI("DeviceProfileConnector::CheckIsSameAccount pkgName %{public}s, srcUdid %{public}s, sinkUdid %{public}s", caller.pkgName.c_str(), GetAnonyString(srcUdid).c_str(), GetAnonyString(sinkUdid).c_str()); std::vector profiles = GetAccessControlProfile(); for (auto &item : profiles) { @@ -846,6 +846,40 @@ int32_t DeviceProfileConnector::CheckIsSameAccount(const DmAccessCaller &caller, return ERR_DM_FAILED; } +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); +} + +void DeviceProfileConnector::HandleDeviceUnBind(int32_t bindType, const std::string &peerUdid, + const std::string &localUdid, int32_t localUserId, const std::string &localAccountId) +{ + std::vector profiles = + DeviceProfileConnector::GetInstance().GetAllAccessControlProfile(); + if (profiles.empty()) { + LOGI("profiles is empty"); + return; + } + for (auto &item : profiles) { + if ((item.GetBindType() == static_cast(bindType)) && + item.GetTrustDeviceId() == peerUdid && + item.GetAccesser().GetAccesserDeviceId() == localUdid && + item.GetAccesser().GetAccesserUserId() == localUserId && + item.GetAccesser().GetAccesserAccountId() == localAccountId) { + DeviceProfileConnector::GetInstance().DeleteAccessControlById(item.GetAccessControlId()); + } + } +} + IDeviceProfileConnector *CreateDpConnectorInstance() { return &DeviceProfileConnector::GetInstance(); diff --git a/commondependency/src/multiple_user_connector.cpp b/commondependency/src/multiple_user_connector.cpp index 133975286..ad431c87a 100644 --- a/commondependency/src/multiple_user_connector.cpp +++ b/commondependency/src/multiple_user_connector.cpp @@ -32,6 +32,8 @@ int32_t MultipleUserConnector::oldUserId_ = -1; std::string MultipleUserConnector::accountId_ = ""; std::string MultipleUserConnector::accountName_ = ""; std::mutex MultipleUserConnector::lock_; +std::map MultipleUserConnector::dmAccountInfoMap_ = {}; +std::mutex MultipleUserConnector::dmAccountInfoMaplock_; #ifndef OS_ACCOUNT_PART_EXISTS const int32_t DEFAULT_OS_ACCOUNT_ID = 0; // 0 is the default id when there is no os_account part #endif // OS_ACCOUNT_PART_EXISTS @@ -125,5 +127,34 @@ std::string MultipleUserConnector::GetSwitchOldAccountName(void) std::lock_guard lock(lock_); return accountName_; } + +void MultipleUserConnector::SetAccountInfo(int32_t userId, DMAccountInfo dmAccountInfo) +{ + std::lock_guard lock(dmAccountInfoMaplock_); + dmAccountInfoMap_[userId] = dmAccountInfo; +} + +DMAccountInfo MultipleUserConnector::GetAccountInfoByUserId(int32_t userId) +{ + DMAccountInfo dmAccountInfo; + { + std::lock_guard lock(dmAccountInfoMaplock_); + if (dmAccountInfoMap_.find(userId) != dmAccountInfoMap_.end()) { + dmAccountInfo = dmAccountInfoMap_[userId]; + return dmAccountInfo; + } + } + LOGE("userId is not exist."); + return dmAccountInfo; +} + +void MultipleUserConnector::DeleteAccountInfoByUserId(int32_t userId) +{ + std::lock_guard lock(dmAccountInfoMaplock_); + LOGI("userId: %{public}d", userId); + if (dmAccountInfoMap_.find(userId) != dmAccountInfoMap_.end()) { + dmAccountInfoMap_.erase(userId); + } +} } // namespace DistributedHardware } // namespace OHOS diff --git a/interfaces/inner_kits/native_cpp/include/device_manager_impl.h b/interfaces/inner_kits/native_cpp/include/device_manager_impl.h index e9650ba09..d7d373df1 100644 --- a/interfaces/inner_kits/native_cpp/include/device_manager_impl.h +++ b/interfaces/inner_kits/native_cpp/include/device_manager_impl.h @@ -23,6 +23,7 @@ #endif #include #include +#include namespace OHOS { namespace DistributedHardware { @@ -398,6 +399,7 @@ public: virtual int32_t RegisterCredentialAuthStatusCallback(const std::string &pkgName, std::shared_ptr callback) override; virtual int32_t UnRegisterCredentialAuthStatusCallback(const std::string &pkgName) override; + void SyncCallbacksToService(std::map> &callbackMap); private: DeviceManagerImpl() = default; @@ -413,6 +415,7 @@ private: int32_t RemovePublishCallback(const std::string &pkgName); int32_t CheckApiPermission(int32_t permissionLevel); void ConvertDeviceInfoToDeviceBasicInfo(const DmDeviceInfo &info, DmDeviceBasicInfo &deviceBasicInfo); + void SyncCallbackToService(DmCommonNotifyEvent dmCommonNotifyEvent, const std::string &pkgName); private: #if !defined(__LITEOS_M__) diff --git a/interfaces/inner_kits/native_cpp/include/dm_device_info.h b/interfaces/inner_kits/native_cpp/include/dm_device_info.h index 4354ee3ea..2eb65d951 100644 --- a/interfaces/inner_kits/native_cpp/include/dm_device_info.h +++ b/interfaces/inner_kits/native_cpp/include/dm_device_info.h @@ -334,6 +334,19 @@ typedef enum { STATUS_DM_CLOSE_PIN_INPUT_UI = 13, } DmAuthStatus; +typedef enum { + MIN = 0, + REG_DEVICE_STATE = 1, + UN_REG_DEVICE_STATE = 2, + REG_DEVICE_SCREEN_STATE = 3, + UN_REG_DEVICE_SCREEN_STATE = 4, + REG_REMOTE_DEVICE_TRUST_CHANGE = 5, + UN_REG_REMOTE_DEVICE_TRUST_CHANGE = 6, + REG_CREDENTIAL_AUTH_STATUS_NOTIFY = 7, + UN_REG_CREDENTIAL_AUTH_STATUS_NOTIFY = 8, + MAX = 9, +} DmCommonNotifyEvent; + const std::string DEVICE_TYPE_UNKNOWN_STRING = "UNKNOWN"; const std::string DEVICE_TYPE_PHONE_STRING = "PHONE"; const std::string DEVICE_TYPE_PAD_STRING = "PAD"; -- Gitee From 55144f56732b0af435bf22479ace21c60204b2cc Mon Sep 17 00:00:00 2001 From: l60055366 Date: Fri, 10 Jan 2025 09:26:06 +0800 Subject: [PATCH 05/10] =?UTF-8?q?=E4=BF=AE=E5=A4=8Ddm=E6=A8=A1=E5=9D=975.0?= =?UTF-8?q?.2=E7=9A=84=E5=B7=AE=E5=BC=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: l60055366 --- .../native_cpp/src/notify/device_manager_notify.cpp | 9 +-------- .../include/dependency/hichain/hichain_connector.h | 2 +- services/service/src/device_manager_service.cpp | 2 +- services/service/src/device_manager_service_listener.cpp | 2 +- 4 files changed, 4 insertions(+), 11 deletions(-) diff --git a/interfaces/inner_kits/native_cpp/src/notify/device_manager_notify.cpp b/interfaces/inner_kits/native_cpp/src/notify/device_manager_notify.cpp index 46a334120..00ab9b31d 100644 --- a/interfaces/inner_kits/native_cpp/src/notify/device_manager_notify.cpp +++ b/interfaces/inner_kits/native_cpp/src/notify/device_manager_notify.cpp @@ -19,6 +19,7 @@ #include "device_manager.h" #include "dm_anonymous.h" #include "dm_constants.h" +#include "dm_device_info.h" #include "dm_log.h" namespace OHOS { @@ -1158,14 +1159,6 @@ void DeviceManagerNotify::GetCallBack(std::map trustChangePkgnameSet; - for (auto it : devTrustChangeCallback_) { - trustChangePkgnameSet.insert(it.first); - } - if (trustChangePkgnameSet.size() > 0) { - callbackMap[DmCommonNotifyEvent::REG_REMOTE_DEVICE_TRUST_CHANGE] = trustChangePkgnameSet; - } - std::set screenStatusPkgnameSet; for (auto it : deviceScreenStatusCallback_) { screenStatusPkgnameSet.insert(it.first); diff --git a/services/implementation/include/dependency/hichain/hichain_connector.h b/services/implementation/include/dependency/hichain/hichain_connector.h index 82770256c..6e862e35b 100644 --- a/services/implementation/include/dependency/hichain/hichain_connector.h +++ b/services/implementation/include/dependency/hichain/hichain_connector.h @@ -230,7 +230,7 @@ public: void DeleteAllGroup(int32_t userId); void DeleteP2PGroup(int32_t userId); - int32_t GetRelatedGroups(int32_t userId, const std::string &deviceId, std::vector &groupList); + int32_t GetRelatedGroups(int32_t userId, const std::string &deviceId, std::vector &groupList); int32_t GetRelatedGroupsExt(const std::string &deviceId, std::vector &groupList); int32_t DeleteGroupExt(std::string &groupId); diff --git a/services/service/src/device_manager_service.cpp b/services/service/src/device_manager_service.cpp index e1f4e9ed9..679966892 100755 --- a/services/service/src/device_manager_service.cpp +++ b/services/service/src/device_manager_service.cpp @@ -1869,7 +1869,7 @@ void DeviceManagerService::HandleDeviceUnBind(const char *peerUdid, const GroupI std::string localUdid = std::string(localUdidTemp); if (IsDMServiceImplReady()) { dmServiceImpl_->HandleDeviceUnBind(groupInfo.groupName, std::string(peerUdid), - localUdid, groupInfo.userId, groupInfo.osAccountId); + localUdid, groupInfo.userId, groupInfo.osAccountId); } return; } diff --git a/services/service/src/device_manager_service_listener.cpp b/services/service/src/device_manager_service_listener.cpp index f707829b0..706d6c213 100644 --- a/services/service/src/device_manager_service_listener.cpp +++ b/services/service/src/device_manager_service_listener.cpp @@ -542,7 +542,7 @@ void DeviceManagerServiceListener::RemoveOnlinePkgName(const DmDeviceInfo &info) } std::unordered_set DeviceManagerServiceListener::GetwhiteListSAPkgName( - DmCommonNotifyEvent dmCommonNotifyEvent) + DmCommonNotifyEvent dmCommonNotifyEvent) { if (!IsDmCommonNotifyEventValid(dmCommonNotifyEvent)) { LOGE("Invalid dmCommonNotifyEvent: %{public}d.", dmCommonNotifyEvent); -- Gitee From 41ca963aa9ada4bf5fddbbef58b5090a9f6556a4 Mon Sep 17 00:00:00 2001 From: l60055366 Date: Fri, 10 Jan 2025 14:43:22 +0800 Subject: [PATCH 06/10] =?UTF-8?q?=E4=BF=AE=E5=A4=8Ddm=E6=A8=A1=E5=9D=975.0?= =?UTF-8?q?.2=E7=9A=84=E5=B7=AE=E5=BC=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: l60055366 --- .../include/notify/device_manager_service_notify.h | 8 ++++---- services/service/src/device_manager_service.cpp | 6 +++--- .../service/src/device_manager_service_listener.cpp | 10 +++++----- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/services/service/include/notify/device_manager_service_notify.h b/services/service/include/notify/device_manager_service_notify.h index 9dcb28ebe..c8b7a7ce6 100644 --- a/services/service/include/notify/device_manager_service_notify.h +++ b/services/service/include/notify/device_manager_service_notify.h @@ -28,13 +28,13 @@ class DeviceManagerServiceNotify { DM_DECLARE_SINGLE_INSTANCE(DeviceManagerServiceNotify); public: - int32_t RegisterCallBack(int32_t dmCommonNotifyEvent, const ProcessInfo &processInfo); - void GetCallBack(int32_t dmCommonNotifyEvent, std::set &processInfos); - void ClearDiedProcessCallback(const ProcessInfo &processInfo); + int32_t RegisterCallBack(int32_t dmCommonNotifyEvent, const std::string &pkgName); + void GetCallBack(int32_t dmCommonNotifyEvent, std::set &pkgNames); + void ClearDiedProcessCallback(const std::string &pkgName); private: std::mutex callbackLock_; - std::map> callbackMap_; + std::map> callbackMap_; }; } // namespace DistributedHardware } // namespace OHOS diff --git a/services/service/src/device_manager_service.cpp b/services/service/src/device_manager_service.cpp index 679966892..351f6c4fa 100755 --- a/services/service/src/device_manager_service.cpp +++ b/services/service/src/device_manager_service.cpp @@ -1864,11 +1864,11 @@ void DeviceManagerService::HandleCredentialAuthStatus(const std::string &proofIn void DeviceManagerService::HandleDeviceUnBind(const char *peerUdid, const GroupInformation &groupInfo) { LOGI("DeviceManagerService::HandleDeviceUnBind start."); - char localUdidTemp[DEVCIE_UDID_LENGTH] = {0}; - GetDevUdid(localUdidTemp, DEVCIE_UDID_LENGTH); + char localUdidTemp[DEVICE_UUID_LENGTH] = {0}; + GetDevUdid(localUdidTemp, DEVICE_UUID_LENGTH); std::string localUdid = std::string(localUdidTemp); if (IsDMServiceImplReady()) { - dmServiceImpl_->HandleDeviceUnBind(groupInfo.groupName, std::string(peerUdid), + dmServiceImpl_->HandleDeviceUnBind(groupInfo.groupType, std::string(peerUdid), localUdid, groupInfo.userId, groupInfo.osAccountId); } return; diff --git a/services/service/src/device_manager_service_listener.cpp b/services/service/src/device_manager_service_listener.cpp index 706d6c213..3ab8c6da9 100644 --- a/services/service/src/device_manager_service_listener.cpp +++ b/services/service/src/device_manager_service_listener.cpp @@ -112,7 +112,7 @@ void DeviceManagerServiceListener::ProcessDeviceStateChange(const DmDeviceState LOGI("In"); std::shared_ptr pReq = std::make_shared(); std::shared_ptr pRsp = std::make_shared(); - std::vector PkgNameVec = GetNotifyPkgName(DmcommonNotifyEvent::REG_DEVICE_STATE); + std::vector PkgNameVec = GetNotifyPkgName(DmCommonNotifyEvent::REG_DEVICE_STATE); if (state == DEVICE_STATE_OFFLINE) { RemoveOnlinePkgName(info); for (const auto &it : PkgNameVec) { @@ -491,7 +491,7 @@ void DeviceManagerServiceListener::OnDeviceScreenStateChange(const std::string & if (pkgName == std::string(DM_PKG_NAME)) { std::shared_ptr pReq = std::make_shared(); std::shared_ptr pRsp = std::make_shared(); - std::vector PkgNameVec = GetNotifyPkgName(DmcommonNotifyEvent::REG_DEVICE_SCREEN_STATE); + std::vector PkgNameVec = GetNotifyPkgName(DmCommonNotifyEvent::REG_DEVICE_SCREEN_STATE); for (const auto &it : PkgNameVec) { SetDeviceScreenInfo(pReq, it, devInfo); ipcServerListener_.SendRequest(SERVER_DEVICE_SCREEN_STATE_NOTIFY, pReq, pRsp); @@ -500,7 +500,7 @@ void DeviceManagerServiceListener::OnDeviceScreenStateChange(const std::string & std::shared_ptr pReq = std::make_shared(); std::shared_ptr pRsp = std::make_shared(); std::unordered_set notifyPkgnames = - GetwhiteListSAPkgName(DmcommonNotifyEvent::REG_DEVICE_SCREEN_STATE); + GetwhiteListSAPkgName(DmCommonNotifyEvent::REG_DEVICE_SCREEN_STATE); notifyPkgnames.insert(pkgName); for (const auto &it : notifyPkgnames) { SetDeviceScreenInfo(pReq, it, devInfo); @@ -519,7 +519,7 @@ void DeviceManagerServiceListener::OnCredentialAuthStatus(const std::string &pkg pReq->SetProofInfo(proofInfo); pReq->SetDeviceTypeId(deviceTypeId); pReq->SetErrCode(errcode); - std::vector PkgNameVec = GetNotifyPkgName(DmcommonNotifyEvent::REG_CREDENTIAL_AUTH_STATUS_NOTIFY); + std::vector PkgNameVec = GetNotifyPkgName(DmCommonNotifyEvent::REG_CREDENTIAL_AUTH_STATUS_NOTIFY); for (const auto &it : PkgNameVec) { pReq->SetPkgName(it); ipcServerListener_.SendRequest(SERVICE_CREDENTIAL_AUTH_STATUS_NOTIFY, pReq, pRsp); @@ -530,7 +530,7 @@ void DeviceManagerServiceListener::RemoveOnlinePkgName(const DmDeviceInfo &info) { LOGI("udidHash: %{public}s.", GetAnonyString(info.deviceId).c_str()); { - std::lock_guard autoLock(alreadyNotifyPkgNameLock_); + std::lock_guard autoLock(alreadyOnlinePkgNameLock_); for (auto item = alreadyOnlinePkgName_.begin(); item != alreadyOnlinePkgName_.end();) { if (std::string(item->second.deviceId) == std::string(info.deviceId)) { item = alreadyOnlinePkgName_.erase(item); -- Gitee From 38fe66ae2385752431a2de1ceef2d5113ea9881a Mon Sep 17 00:00:00 2001 From: l60055366 Date: Fri, 10 Jan 2025 15:36:22 +0800 Subject: [PATCH 07/10] =?UTF-8?q?=E4=BF=AE=E5=A4=8Ddm=E6=A8=A1=E5=9D=975.0?= =?UTF-8?q?.2=E7=9A=84=E5=B7=AE=E5=BC=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: l60055366 --- services/service/src/device_manager_service_listener.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/service/src/device_manager_service_listener.cpp b/services/service/src/device_manager_service_listener.cpp index 3ab8c6da9..c9b4972df 100644 --- a/services/service/src/device_manager_service_listener.cpp +++ b/services/service/src/device_manager_service_listener.cpp @@ -160,7 +160,7 @@ void DeviceManagerServiceListener::ProcessAppStateChange(const std::string &pkgN if (alreadyOnlinePkgName_.find(notifyKey) != alreadyOnlinePkgName_.end()) { continue; } - alreadyOnlinePkgName_.[notifyKey] = info; + alreadyOnlinePkgName_[notifyKey] = info; } SetDeviceInfo(pReq, it, state, info, deviceBasicInfo); ipcServerListener_.SendRequest(SERVER_DEVICE_STATE_NOTIFY, pReq, pRsp); -- Gitee From 0aed19a00f64a35ae49b607d31dbc69cc74129a4 Mon Sep 17 00:00:00 2001 From: l60055366 Date: Fri, 10 Jan 2025 16:39:59 +0800 Subject: [PATCH 08/10] =?UTF-8?q?=E4=BF=AE=E5=A4=8Ddm=E6=A8=A1=E5=9D=975.0?= =?UTF-8?q?.2=E7=9A=84=E5=B7=AE=E5=BC=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: l60055366 --- .../implementation/include/authentication/dm_auth_manager.h | 2 +- .../implementation/src/authentication/dm_auth_manager.cpp | 4 ++-- .../src/dependency/hichain/hichain_connector.cpp | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/services/implementation/include/authentication/dm_auth_manager.h b/services/implementation/include/authentication/dm_auth_manager.h index 1f0c21f17..7ebfc61e8 100644 --- a/services/implementation/include/authentication/dm_auth_manager.h +++ b/services/implementation/include/authentication/dm_auth_manager.h @@ -531,7 +531,7 @@ public: void OnScreenLocked(); void HandleDeviceNotTrust(const std::string &udid); int32_t DeleteGroup(const std::string &pkgName, const std::string &deviceId); - int32_t DeleteGroup(const std::string &pkgName, int32_t userId, std::string &deviceId); + int32_t DeleteGroup(const std::string &pkgName, int32_t userId, const std::string &deviceId); int32_t StopAuthenticateDevice(const std::string &pkgName); private: int32_t ImportCredential(std::string &deviceId, std::string &publicKey); diff --git a/services/implementation/src/authentication/dm_auth_manager.cpp b/services/implementation/src/authentication/dm_auth_manager.cpp index 6634e2f6a..802f00207 100644 --- a/services/implementation/src/authentication/dm_auth_manager.cpp +++ b/services/implementation/src/authentication/dm_auth_manager.cpp @@ -2345,8 +2345,8 @@ void DmAuthManager::ProcRespNegotiateExt(const int32_t &sessionId) { LOGI("DmAuthManager::ProcRespNegotiateExt start."); remoteDeviceId_ = authResponseContext_->localDeviceId; - int32_t userId = MultipleUserConnector::GetAccountUserID(userId).accountId; - std::string accountId = MultipleUserConnector::GetAccountInfoByUserId(); + int32_t userId = MultipleUserConnector::GetCurrentAccountUserID(); + std::string accountId = MultipleUserConnector::GetAccountInfoByUserId(userId).accountId; authResponseContext_->isIdenticalAccount = false; if (authResponseContext_->localAccountId == accountId && accountId != "ohosAnonymousUid") { authResponseContext_->isIdenticalAccount = true; diff --git a/services/implementation/src/dependency/hichain/hichain_connector.cpp b/services/implementation/src/dependency/hichain/hichain_connector.cpp index 2e9e569c4..bd6f8f5e5 100644 --- a/services/implementation/src/dependency/hichain/hichain_connector.cpp +++ b/services/implementation/src/dependency/hichain/hichain_connector.cpp @@ -1208,7 +1208,7 @@ int32_t HiChainConnector::DeleteGroup(const int32_t userId, std::string &groupId int64_t requestId = GenRequestId(); nlohmann::json jsonObj; jsonObj[FIELD_GROUP_ID] = groupId; - std::string disbandParams = SafetyDump(jsonObj); + std::string disbandParams = jsonObj.dump(); int32_t ret = deviceGroupManager_->deleteGroup(userId, requestId, DM_PKG_NAME, disbandParams.c_str()); if (ret != 0) { LOGE("[HICHAIN]fail to delete group with ret:%{public}d.", ret); -- Gitee From d80d46581c800e1ad4a6a1a4bc723eba5177fd2a Mon Sep 17 00:00:00 2001 From: l60055366 Date: Sat, 11 Jan 2025 09:54:40 +0800 Subject: [PATCH 09/10] =?UTF-8?q?=E4=BF=AE=E5=A4=8Ddm=E6=A8=A1=E5=9D=975.0?= =?UTF-8?q?.2=E7=9A=84=E5=B7=AE=E5=BC=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: l60055366 --- ...UTTest_device_manager_service_listener.cpp | 44 +++++++++---------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/test/unittest/UTTest_device_manager_service_listener.cpp b/test/unittest/UTTest_device_manager_service_listener.cpp index f082355c3..77a8944df 100644 --- a/test/unittest/UTTest_device_manager_service_listener.cpp +++ b/test/unittest/UTTest_device_manager_service_listener.cpp @@ -63,7 +63,7 @@ HWTEST_F(DeviceManagerServiceListenerTest, OnDeviceStateChange_001, testing::ext .deviceTypeId = 1, }; listener_->OnDeviceStateChange(pkgName, state, info); - EXPECT_EQ(listener_->alreadyOnlineSet_.empty(), false); + EXPECT_EQ(listener_->alreadyOnlinePkgName_.empty(), false); } /** @@ -84,7 +84,7 @@ HWTEST_F(DeviceManagerServiceListenerTest, OnDeviceStateChange_002, testing::ext .deviceTypeId = 1, }; listener_->OnDeviceStateChange(pkgName, state, info); - EXPECT_EQ(listener_->alreadyOnlineSet_.empty(), false); + EXPECT_EQ(listener_->alreadyOnlinePkgName_.empty(), true); } /** @@ -102,7 +102,7 @@ HWTEST_F(DeviceManagerServiceListenerTest, OnAuthResult_001, testing::ext::TestS int32_t status = 3; int32_t reason = 2006; listener_->OnAuthResult(pkgName, deviceId, token, status, reason); - EXPECT_EQ(listener_->alreadyOnlineSet_.empty(), false); + EXPECT_EQ(listener_->alreadyOnlinePkgName_.empty(), true); } /** @@ -120,7 +120,7 @@ HWTEST_F(DeviceManagerServiceListenerTest, OnAuthResult_002, testing::ext::TestS int32_t status = 8; int32_t reason = 2006; listener_->OnAuthResult(pkgName, deviceId, token, status, reason); - EXPECT_EQ(listener_->alreadyOnlineSet_.empty(), false); + EXPECT_EQ(listener_->alreadyOnlinePkgName_.empty(), true); } /** @@ -138,7 +138,7 @@ HWTEST_F(DeviceManagerServiceListenerTest, OnAuthResult_003, testing::ext::TestS int32_t status = -1; int32_t reason = 2006; listener_->OnAuthResult(pkgName, deviceId, token, status, reason); - EXPECT_EQ(listener_->alreadyOnlineSet_.empty(), false); + EXPECT_EQ(listener_->alreadyOnlinePkgName_.empty(), true); } /** @@ -159,7 +159,7 @@ HWTEST_F(DeviceManagerServiceListenerTest, OnDeviceFound_001, testing::ext::Test }; uint16_t subscribeId = 1; listener_->OnDeviceFound(pkgName, subscribeId, info); - EXPECT_EQ(listener_->alreadyOnlineSet_.empty(), false); + EXPECT_EQ(listener_->alreadyOnlinePkgName_.empty(), true); } /** @@ -176,7 +176,7 @@ HWTEST_F(DeviceManagerServiceListenerTest, OnDiscoveryFailed_001, testing::ext:: uint16_t subscribeId = 1; int32_t failedReason = 1; listener_->OnDiscoveryFailed(pkgName, subscribeId, failedReason); - EXPECT_EQ(listener_->alreadyOnlineSet_.empty(), false); + EXPECT_EQ(listener_->alreadyOnlinePkgName_.empty(), true); } /** @@ -191,7 +191,7 @@ HWTEST_F(DeviceManagerServiceListenerTest, OnDiscoverySuccess_001, testing::ext: std::string pkgName = "com.ohos.helloworld"; uint16_t subscribeId = 1; listener_->OnDiscoverySuccess(pkgName, subscribeId); - EXPECT_EQ(listener_->alreadyOnlineSet_.empty(), false); + EXPECT_EQ(listener_->alreadyOnlinePkgName_.empty(), true); } /** @@ -208,7 +208,7 @@ HWTEST_F(DeviceManagerServiceListenerTest, OnPublishResult_001, testing::ext::Te int32_t publishId = 1; int32_t failedReason = 1; listener_->OnPublishResult(pkgName, publishId, failedReason); - EXPECT_EQ(listener_->alreadyOnlineSet_.empty(), false); + EXPECT_EQ(listener_->alreadyOnlinePkgName_.empty(), true); } /** @@ -224,7 +224,7 @@ HWTEST_F(DeviceManagerServiceListenerTest, OnPublishResult_002, testing::ext::Te int32_t publishId = 1; int32_t failedReason = 0; listener_->OnPublishResult(pkgName, publishId, failedReason); - EXPECT_EQ(listener_->alreadyOnlineSet_.empty(), false); + EXPECT_EQ(listener_->alreadyOnlinePkgName_.empty(), true); } /** @@ -239,7 +239,7 @@ HWTEST_F(DeviceManagerServiceListenerTest, OnUiCall_001, testing::ext::TestSize. std::string pkgName = "com.ohos.helloworld"; std::string paramJson = "ahaha"; listener_->OnUiCall(pkgName, paramJson); - EXPECT_EQ(listener_->alreadyOnlineSet_.empty(), false); + EXPECT_EQ(listener_->alreadyOnlinePkgName_.empty(), true); } /** @@ -254,7 +254,7 @@ HWTEST_F(DeviceManagerServiceListenerTest, OnCredentialResult_001, testing::ext: int32_t action = 1; std::string resultInfo = "resultInfo"; listener_->OnCredentialResult(pkgName, action, resultInfo); - EXPECT_EQ(listener_->alreadyOnlineSet_.empty(), false); + EXPECT_EQ(listener_->alreadyOnlinePkgName_.empty(), true); } /** @@ -271,7 +271,7 @@ HWTEST_F(DeviceManagerServiceListenerTest, OnBindResult_001, testing::ext::TestS int32_t status = 1; std::string content = "content"; listener_->OnBindResult(pkgName, targetId, result, status, content); - EXPECT_EQ(listener_->alreadyOnlineSet_.empty(), false); + EXPECT_EQ(listener_->alreadyOnlinePkgName_.empty(), true); } /** @@ -288,7 +288,7 @@ HWTEST_F(DeviceManagerServiceListenerTest, OnBindResult_002, testing::ext::TestS int32_t status = 8; std::string content = "content"; listener_->OnBindResult(pkgName, targetId, result, status, content); - EXPECT_EQ(listener_->alreadyOnlineSet_.empty(), false); + EXPECT_EQ(listener_->alreadyOnlinePkgName_.empty(), true); } /** @@ -305,7 +305,7 @@ HWTEST_F(DeviceManagerServiceListenerTest, OnBindResult_003, testing::ext::TestS int32_t status = -1; std::string content = "content"; listener_->OnBindResult(pkgName, targetId, result, status, content); - EXPECT_EQ(listener_->alreadyOnlineSet_.empty(), false); + EXPECT_EQ(listener_->alreadyOnlinePkgName_.empty(), true); } /** @@ -321,7 +321,7 @@ HWTEST_F(DeviceManagerServiceListenerTest, OnUnbindResult_001, testing::ext::Tes int32_t result = 0; std::string content = "content"; listener_->OnUnbindResult(pkgName, targetId, result, content); - EXPECT_EQ(listener_->alreadyOnlineSet_.empty(), false); + EXPECT_EQ(listener_->alreadyOnlinePkgName_.empty(), true); } /** @@ -355,7 +355,7 @@ HWTEST_F(DeviceManagerServiceListenerTest, OnDeviceFound_002, testing::ext::Test uint16_t subscribeId = 1; DmDeviceBasicInfo info; listener_->OnDeviceFound(pkgName, subscribeId, info); - EXPECT_EQ(listener_->alreadyOnlineSet_.empty(), false); + EXPECT_EQ(listener_->alreadyOnlinePkgName_.empty(), true); } /** @@ -371,7 +371,7 @@ HWTEST_F(DeviceManagerServiceListenerTest, OnPinHolderCreate_001, testing::ext:: DmPinType pinType = static_cast(1); std::string payload = "payload"; listener_->OnPinHolderCreate(pkgName, deviceId, pinType, payload); - EXPECT_EQ(listener_->alreadyOnlineSet_.empty(), false); + EXPECT_EQ(listener_->alreadyOnlinePkgName_.empty(), true); } /** @@ -386,7 +386,7 @@ HWTEST_F(DeviceManagerServiceListenerTest, OnPinHolderDestroy_001, testing::ext: DmPinType pinType = static_cast(1); std::string payload = "payload"; listener_->OnPinHolderDestroy(pkgName, pinType, payload); - EXPECT_EQ(listener_->alreadyOnlineSet_.empty(), false); + EXPECT_EQ(listener_->alreadyOnlinePkgName_.empty(), true); } /** @@ -400,7 +400,7 @@ HWTEST_F(DeviceManagerServiceListenerTest, OnCreateResult_001, testing::ext::Tes std::string pkgName = "com.ohos.helloworld"; int32_t result = 0; listener_->OnCreateResult(pkgName, result); - EXPECT_EQ(listener_->alreadyOnlineSet_.empty(), false); + EXPECT_EQ(listener_->alreadyOnlinePkgName_.empty(), true); } /** @@ -414,7 +414,7 @@ HWTEST_F(DeviceManagerServiceListenerTest, OnDestroyResult_001, testing::ext::Te std::string pkgName = "com.ohos.helloworld"; int32_t result = 0; listener_->OnDestroyResult(pkgName, result); - EXPECT_EQ(listener_->alreadyOnlineSet_.empty(), false); + EXPECT_EQ(listener_->alreadyOnlinePkgName_.empty(), true); } /** @@ -430,7 +430,7 @@ HWTEST_F(DeviceManagerServiceListenerTest, OnPinHolderEvent_001, testing::ext::T int32_t result = 0; std::string content = "content"; listener_->OnPinHolderEvent(pkgName, event, result, content); - EXPECT_EQ(listener_->alreadyOnlineSet_.empty(), false); + EXPECT_EQ(listener_->alreadyOnlinePkgName_.empty(), true); } } // namespace } // namespace DistributedHardware -- Gitee From 24e721fe3c4770fabaf62866d5b41f91ce8cbdb2 Mon Sep 17 00:00:00 2001 From: l60055366 Date: Sat, 11 Jan 2025 11:32:36 +0800 Subject: [PATCH 10/10] =?UTF-8?q?=E4=BF=AE=E5=A4=8Ddm=E6=A8=A1=E5=9D=975.0?= =?UTF-8?q?.2=E7=9A=84=E5=B7=AE=E5=BC=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: l60055366 --- .../include/device_manager_service_impl_lite.h | 2 ++ .../src/device_manager_service_impl_lite.cpp | 13 +++++++++++++ 2 files changed, 15 insertions(+) diff --git a/services/implementation/include/device_manager_service_impl_lite.h b/services/implementation/include/device_manager_service_impl_lite.h index b1a33b377..8377e3561 100644 --- a/services/implementation/include/device_manager_service_impl_lite.h +++ b/services/implementation/include/device_manager_service_impl_lite.h @@ -135,6 +135,8 @@ public: int32_t CheckAccessControl(const DmAccessCaller &caller, const std::string &srcUdid, const DmAccessCallee &callee, const std::string &sinkUdid); void HandleDeviceNotTrust(const std::string &udid); + void HandleIdentAccountLogout(const std::string &udid, int32_t userId, const std::string &accountId); + void HandleUserRemoved(int32_t preUserId); std::map GetDeviceIdAndBindType(int32_t userId, const std::string &accountId); int32_t StopAuthenticateDevice(const std::string &pkgName); void HandleDeviceScreenStatusChange(DmDeviceInfo &devInfo); diff --git a/services/implementation/src/device_manager_service_impl_lite.cpp b/services/implementation/src/device_manager_service_impl_lite.cpp index 1e08028b1..68eac8c8d 100644 --- a/services/implementation/src/device_manager_service_impl_lite.cpp +++ b/services/implementation/src/device_manager_service_impl_lite.cpp @@ -487,6 +487,19 @@ void DeviceManagerServiceImpl::HandleDeviceNotTrust(const std::string &udid) return; } +void DeviceManagerServiceImpl::HandleIdentAccountLogout(const std::string &udid, int32_t userId, + const std::string &accountId) +{ + (void)udid; + (void)userId; + (void)accountId; +} + +void DeviceManagerServiceImpl::HandleUserRemoved(int32_t preUserId) +{ + (void)preUserId; +} + std::map DeviceManagerServiceImpl::GetDeviceIdAndBindType(int32_t userId, const std::string &accountId) { -- Gitee