mirror of
https://github.com/openharmony/device_manager.git
synced 2026-07-20 02:23:30 -04:00
@@ -128,9 +128,9 @@ public:
|
||||
const std::string &extra);
|
||||
int32_t UnAuthenticateDevice(const std::string &pkgName, const std::string &deviceId);
|
||||
int32_t VerifyAuthentication(const std::string &authParam);
|
||||
void OnSessionOpened(const std::string &pkgName, int32_t sessionId, int32_t sessionSide, int32_t result);
|
||||
void OnSessionClosed(const std::string &pkgName, int32_t sessionId);
|
||||
void OnDataReceived(const std::string &pkgName, int32_t sessionId, std::string message);
|
||||
void OnSessionOpened(int32_t sessionId, int32_t sessionSide, int32_t result);
|
||||
void OnSessionClosed(int32_t sessionId);
|
||||
void OnDataReceived(int32_t sessionId, std::string message);
|
||||
void OnGroupCreated(int64_t requestId, const std::string &groupId);
|
||||
void OnMemberJoin(int64_t requestId, int32_t status);
|
||||
|
||||
@@ -146,7 +146,7 @@ public:
|
||||
std::string GetConnectAddr(std::string deviceId);
|
||||
void JoinNetwork();
|
||||
void AuthenticateFinish();
|
||||
void GetIsCryptoSupport(bool &isCryptoSupport);
|
||||
bool GetIsCryptoSupport();
|
||||
void SetAuthRequestState(std::shared_ptr<AuthRequestState> authRequestState);
|
||||
void SetAuthResponseState(std::shared_ptr<AuthResponseState> authResponseState);
|
||||
int32_t GetPinCode();
|
||||
@@ -158,7 +158,7 @@ public:
|
||||
void ShowAuthInfoDialog();
|
||||
void ShowStartAuthDialog();
|
||||
int32_t GetAuthenticationParam(DmAuthParam &authParam);
|
||||
int32_t RegisterSessionCallback();
|
||||
int32_t RegisterCallback();
|
||||
int32_t OnUserOperation(int32_t action);
|
||||
|
||||
private:
|
||||
|
||||
@@ -53,8 +53,8 @@ public:
|
||||
public:
|
||||
HiChainConnector();
|
||||
~HiChainConnector();
|
||||
int32_t RegisterHiChainCallback(const std::string &pkgName, std::shared_ptr<IHiChainConnectorCallback> callback);
|
||||
int32_t UnRegisterHiChainCallback(const std::string &pkgName);
|
||||
int32_t RegisterHiChainCallback(std::shared_ptr<IHiChainConnectorCallback> callback);
|
||||
int32_t UnRegisterHiChainCallback();
|
||||
int32_t CreateGroup(int64_t requestId, const std::string &groupName);
|
||||
int32_t AddMember(std::string deviceId, std::string &connectInfo);
|
||||
int32_t DelMemberFromGroup(std::string groupId, std::string deviceId);
|
||||
@@ -74,7 +74,7 @@ private:
|
||||
private:
|
||||
const DeviceGroupManager *deviceGroupManager_ = nullptr;
|
||||
DeviceAuthCallback deviceAuthCallback_;
|
||||
static std::map<std::string, std::shared_ptr<IHiChainConnectorCallback>> hiChainConnectorCallbackMap_;
|
||||
static std::shared_ptr<IHiChainConnectorCallback> hiChainConnectorCallback_;
|
||||
};
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -37,15 +37,15 @@ public:
|
||||
public:
|
||||
SoftbusSession();
|
||||
~SoftbusSession();
|
||||
int32_t RegisterSessionCallback(const std::string &pkgName, std::shared_ptr<ISoftbusSessionCallback> callback);
|
||||
int32_t UnRegisterSessionCallback(const std::string &pkgName);
|
||||
int32_t RegisterSessionCallback(std::shared_ptr<ISoftbusSessionCallback> callback);
|
||||
int32_t UnRegisterSessionCallback();
|
||||
int32_t OpenAuthSession(const std::string &deviceId);
|
||||
int32_t CloseAuthSession(int32_t sessionId);
|
||||
int32_t SendData(int32_t sessionId, std::string &message);
|
||||
int32_t GetPeerDeviceId(int32_t sessionId, std::string &peerDevId);
|
||||
|
||||
private:
|
||||
static std::map<std::string, std::shared_ptr<ISoftbusSessionCallback>> sessionCallbackMap_;
|
||||
static std::shared_ptr<ISoftbusSessionCallback> sessionCallback_;
|
||||
};
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -20,11 +20,10 @@ namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
class ISoftbusSessionCallback {
|
||||
public:
|
||||
virtual void OnSessionOpened(const std::string &pkgName, int32_t sessionId, int32_t sessionSide,
|
||||
int32_t result) = 0;
|
||||
virtual void OnSessionClosed(const std::string &pkgName, int32_t sessionId) = 0;
|
||||
virtual void OnDataReceived(const std::string &pkgName, int32_t sessionId, std::string message) = 0;
|
||||
virtual void GetIsCryptoSupport(bool &isCryptoSupport) = 0;
|
||||
virtual void OnSessionOpened(int32_t sessionId, int32_t sessionSide, int32_t result) = 0;
|
||||
virtual void OnSessionClosed(int32_t sessionId) = 0;
|
||||
virtual void OnDataReceived(int32_t sessionId, std::string message) = 0;
|
||||
virtual bool GetIsCryptoSupport() = 0;
|
||||
};
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -110,8 +110,9 @@ void AuthMessageProcessor::CreateNegotiateMessage(nlohmann::json &json)
|
||||
json[TAG_CRYPTO_SUPPORT] = true;
|
||||
json[TAG_CRYPTO_NAME] = cryptoAdapter_->GetName();
|
||||
json[TAG_CRYPTO_VERSION] = cryptoAdapter_->GetVersion();
|
||||
json[TAG_DEVICE_ID] = authRequestContext_->deviceId;
|
||||
json[TAG_DEVICE_ID] = authResponseContext_->deviceId;
|
||||
}
|
||||
json[TAG_AUTH_TYPE] = authResponseContext_->authType;
|
||||
json[TAG_REPLY] = authResponseContext_->reply;
|
||||
json[TAG_LOCAL_DEVICE_ID] = authResponseContext_->localDeviceId;
|
||||
}
|
||||
@@ -261,6 +262,7 @@ void AuthMessageProcessor::ParseNegotiateMessage(const nlohmann::json &json)
|
||||
if (json.contains(TAG_DEVICE_ID)) {
|
||||
authResponseContext_->deviceId = json[TAG_DEVICE_ID];
|
||||
}
|
||||
authResponseContext_->authType = json[TAG_AUTH_TYPE];
|
||||
authResponseContext_->localDeviceId = json[TAG_LOCAL_DEVICE_ID];
|
||||
authResponseContext_->reply = json[TAG_REPLY];
|
||||
}
|
||||
|
||||
@@ -71,13 +71,22 @@ DmAuthManager::DmAuthManager(std::shared_ptr<SoftbusConnector> softbusConnector,
|
||||
|
||||
DmAuthManager::~DmAuthManager()
|
||||
{
|
||||
softbusConnector_->GetSoftbusSession()->UnRegisterSessionCallback();
|
||||
hiChainConnector_->UnRegisterHiChainCallback();
|
||||
LOGI("DmAuthManager destructor");
|
||||
}
|
||||
|
||||
int32_t DmAuthManager::AuthenticateDevice(const std::string &pkgName, int32_t authType, const std::string &deviceId,
|
||||
const std::string &extra)
|
||||
{
|
||||
LOGE("DmAuthManager::AuthenticateDevice is");
|
||||
LOGE("DmAuthManager::AuthenticateDevice start");
|
||||
std::shared_ptr<IAuthentication> authentication = authenticationMap_[authType];
|
||||
if (authentication == nullptr) {
|
||||
LOGE("DmAuthManager::AuthenticateDevice authType %d not support.", authType);
|
||||
listener_->OnAuthResult(pkgName, deviceId, "", AuthState::AUTH_REQUEST_INIT,
|
||||
std::to_string(DM_AUTH_NOT_SUPPORT));
|
||||
return DM_AUTH_NOT_SUPPORT;
|
||||
}
|
||||
if (authRequestState_ != nullptr && authResponseState_ != nullptr) {
|
||||
LOGE("DmAuthManager::AuthenticateDevice %s is request authentication.",
|
||||
authRequestState_->GetAuthContext()->hostPkgName.c_str());
|
||||
@@ -98,16 +107,9 @@ int32_t DmAuthManager::AuthenticateDevice(const std::string &pkgName, int32_t au
|
||||
std::to_string(DM_AUTH_BUSINESS_BUSY));
|
||||
return DM_INPUT_PARA_EMPTY;
|
||||
}
|
||||
if (authType != AUTH_TYPE_PIN && authType != AUTH_TYPE_SCAN && authType != AUTH_TYPE_TOUCH) {
|
||||
LOGE("AuthenticateDevice failed, authType is not support");
|
||||
listener_->OnAuthResult(pkgName, deviceId, "", AuthState::AUTH_REQUEST_INIT,
|
||||
std::to_string(DM_AUTH_NOT_SUPPORT));
|
||||
return DM_AUTH_NOT_SUPPORT;
|
||||
}
|
||||
softbusConnector_->GetSoftbusSession()->UnRegisterSessionCallback(DM_PKG_NAME);
|
||||
softbusConnector_->GetSoftbusSession()->RegisterSessionCallback(pkgName, shared_from_this());
|
||||
|
||||
authMessageProcessor_ = std::make_shared<AuthMessageProcessor>(shared_from_this());
|
||||
authResponseContext_ = std::make_shared<DmAuthResponseContext>();
|
||||
authRequestContext_ = std::make_shared<DmAuthRequestContext>();
|
||||
authRequestContext_->hostPkgName = pkgName;
|
||||
authRequestContext_->authType = authType;
|
||||
@@ -131,6 +133,7 @@ int32_t DmAuthManager::AuthenticateDevice(const std::string &pkgName, int32_t au
|
||||
}
|
||||
}
|
||||
authRequestContext_->token = std::to_string(GenRandInt(MIN_PIN_TOKEN, MAX_PIN_TOKEN));
|
||||
authMessageProcessor_->SetRequestContext(authRequestContext_);
|
||||
authRequestState_ = std::make_shared<AuthRequestInitState>();
|
||||
authRequestState_->SetAuthManager(shared_from_this());
|
||||
authRequestState_->SetAuthContext(authRequestContext_);
|
||||
@@ -201,7 +204,7 @@ int32_t DmAuthManager::VerifyAuthentication(const std::string &authParam)
|
||||
return DM_OK;
|
||||
}
|
||||
|
||||
void DmAuthManager::OnSessionOpened(const std::string &pkgName, int32_t sessionId, int32_t sessionSide, int32_t result)
|
||||
void DmAuthManager::OnSessionOpened(int32_t sessionId, int32_t sessionSide, int32_t result)
|
||||
{
|
||||
LOGI("DmAuthManager::OnSessionOpened sessionId=%d result=%d", sessionId, result);
|
||||
if (sessionSide == AUTH_SESSION_SIDE_SERVER) {
|
||||
@@ -210,7 +213,6 @@ void DmAuthManager::OnSessionOpened(const std::string &pkgName, int32_t sessionI
|
||||
authResponseState_ = std::make_shared<AuthResponseInitState>();
|
||||
authResponseState_->SetAuthManager(shared_from_this());
|
||||
authResponseState_->Enter();
|
||||
hiChainConnector_->RegisterHiChainCallback(pkgName, shared_from_this());
|
||||
authResponseContext_ = std::make_shared<DmAuthResponseContext>();
|
||||
std::shared_ptr<DmTimer> waitStartTimer = std::make_shared<DmTimer>(WAIT_NEGOTIATE_TIMEOUT_TASK);
|
||||
timerMap_[WAIT_NEGOTIATE_TIMEOUT_TASK] = waitStartTimer;
|
||||
@@ -229,11 +231,9 @@ void DmAuthManager::OnSessionOpened(const std::string &pkgName, int32_t sessionI
|
||||
}
|
||||
} else {
|
||||
if (authRequestState_->GetStateType() == AuthState::AUTH_REQUEST_INIT) {
|
||||
hiChainConnector_->RegisterHiChainCallback(pkgName, shared_from_this());
|
||||
authRequestContext_->sessionId = sessionId;
|
||||
authRequestState_->SetAuthContext(authRequestContext_);
|
||||
authMessageProcessor_->SetRequestContext(authRequestContext_);
|
||||
authResponseContext_ = std::make_shared<DmAuthResponseContext>();
|
||||
authRequestState_->TransitionTo(std::make_shared<AuthRequestNegotiateState>());
|
||||
} else {
|
||||
LOGE("DmAuthManager::OnSessionOpened but request state %d is wrong", authRequestState_->GetStateType());
|
||||
@@ -241,12 +241,12 @@ void DmAuthManager::OnSessionOpened(const std::string &pkgName, int32_t sessionI
|
||||
}
|
||||
}
|
||||
|
||||
void DmAuthManager::OnSessionClosed(const std::string &pkgName, int32_t sessionId)
|
||||
void DmAuthManager::OnSessionClosed(int32_t sessionId)
|
||||
{
|
||||
LOGI("DmAuthManager::OnSessionOpened sessionId=%d", sessionId);
|
||||
}
|
||||
|
||||
void DmAuthManager::OnDataReceived(const std::string &pkgName, int32_t sessionId, std::string message)
|
||||
void DmAuthManager::OnDataReceived(int32_t sessionId, std::string message)
|
||||
{
|
||||
LOGI("DmAuthManager::OnDataReceived start");
|
||||
if (authRequestState_ == nullptr && authResponseState_ == nullptr) {
|
||||
@@ -389,6 +389,8 @@ void DmAuthManager::StartNegotiate(const int32_t &sessionId)
|
||||
GetDevUdid(localDeviceId, DEVICE_UUID_LENGTH);
|
||||
authResponseContext_->localDeviceId = localDeviceId;
|
||||
authResponseContext_->reply = DM_AUTH_NOT_AUTH;
|
||||
authResponseContext_->authType = authRequestContext_->authType;
|
||||
authResponseContext_->deviceId = authRequestContext_->deviceId;
|
||||
authMessageProcessor_->SetResponseContext(authResponseContext_);
|
||||
std::string message = authMessageProcessor_->CreateSimpleMessage(MSG_TYPE_NEGOTIATE);
|
||||
softbusConnector_->GetSoftbusSession()->SendData(sessionId, message);
|
||||
@@ -410,6 +412,12 @@ void DmAuthManager::RespNegotiate(const int32_t &sessionId)
|
||||
authResponseContext_->reply = DM_AUTH_NOT_AUTH;
|
||||
}
|
||||
|
||||
std::shared_ptr<IAuthentication> authentication = authenticationMap_[authResponseContext_->authType];
|
||||
if (authentication == nullptr) {
|
||||
LOGE("DmAuthManager::AuthenticateDevice authType %d not support.", authResponseContext_->authType);
|
||||
authResponseContext_->reply = DM_AUTH_NOT_SUPPORT;
|
||||
}
|
||||
|
||||
std::string message = authMessageProcessor_->CreateSimpleMessage(MSG_TYPE_RESP_NEGOTIATE);
|
||||
nlohmann::json jsonObject = nlohmann::json::parse(message, nullptr, false);
|
||||
if (jsonObject.is_discarded()) {
|
||||
@@ -546,11 +554,13 @@ void DmAuthManager::AuthenticateFinish()
|
||||
authResponseState_ = nullptr;
|
||||
authMessageProcessor_ = nullptr;
|
||||
} else if (authRequestState_ != nullptr) {
|
||||
std::string flag = "";
|
||||
if (authResponseContext_->reply != DM_AUTH_BUSINESS_BUSY) {
|
||||
authMessageProcessor_->SetResponseContext(authResponseContext_);
|
||||
std::string message = authMessageProcessor_->CreateSimpleMessage(MSG_TYPE_REQ_AUTH_TERMINATE);
|
||||
softbusConnector_->GetSoftbusSession()->SendData(authResponseContext_->sessionId, message);
|
||||
} else {
|
||||
authRequestContext_->reason = DM_AUTH_BUSINESS_BUSY;
|
||||
authResponseContext_->state = AuthState::AUTH_REQUEST_INIT;
|
||||
}
|
||||
|
||||
if (authResponseContext_->state == AuthState::AUTH_REQUEST_INPUT) {
|
||||
@@ -561,8 +571,8 @@ void DmAuthManager::AuthenticateFinish()
|
||||
authRequestContext_->token, authResponseContext_->state,
|
||||
std::to_string(authRequestContext_->reason));
|
||||
|
||||
softbusConnector_->GetSoftbusSession()->UnRegisterSessionCallback(authRequestContext_->hostPkgName);
|
||||
softbusConnector_->GetSoftbusSession()->CloseAuthSession(authRequestContext_->sessionId);
|
||||
|
||||
if (!timerMap_.empty()) {
|
||||
for (auto &iter : timerMap_) {
|
||||
iter.second->Stop(SESSION_CANCEL_TIMEOUT);
|
||||
@@ -602,27 +612,24 @@ std::string DmAuthManager::GenerateGroupName()
|
||||
return groupName;
|
||||
}
|
||||
|
||||
void DmAuthManager::GetIsCryptoSupport(bool &isCryptoSupport)
|
||||
bool DmAuthManager::GetIsCryptoSupport()
|
||||
{
|
||||
LOGI("DmAuthManager::GetIsCryptoSupport start");
|
||||
if (authResponseState_ == nullptr) {
|
||||
isCryptoSupport = false;
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
if (authRequestState_ == nullptr) {
|
||||
if (authResponseState_->GetStateType() == AuthState::AUTH_REQUEST_NEGOTIATE_DONE) {
|
||||
isCryptoSupport = false;
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (authRequestState_->GetStateType() == AuthState::AUTH_REQUEST_NEGOTIATE ||
|
||||
authRequestState_->GetStateType() == AuthState::AUTH_REQUEST_NEGOTIATE_DONE) {
|
||||
isCryptoSupport = false;
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
isCryptoSupport = isCryptoSupport_;
|
||||
return isCryptoSupport_;
|
||||
}
|
||||
|
||||
void DmAuthManager::SetAuthRequestState(std::shared_ptr<AuthRequestState> authRequestState)
|
||||
@@ -684,9 +691,10 @@ int32_t DmAuthManager::GetAuthenticationParam(DmAuthParam &authParam)
|
||||
return DM_OK;
|
||||
}
|
||||
|
||||
int32_t DmAuthManager::RegisterSessionCallback()
|
||||
int32_t DmAuthManager::RegisterCallback()
|
||||
{
|
||||
softbusConnector_->GetSoftbusSession()->RegisterSessionCallback(DM_PKG_NAME, shared_from_this());
|
||||
softbusConnector_->GetSoftbusSession()->RegisterSessionCallback(shared_from_this());
|
||||
hiChainConnector_->RegisterHiChainCallback(shared_from_this());
|
||||
return DM_OK;
|
||||
}
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ void from_json(const nlohmann::json &jsonObject, GroupInfo &groupInfo)
|
||||
}
|
||||
}
|
||||
|
||||
std::map<std::string, std::shared_ptr<IHiChainConnectorCallback>> HiChainConnector::hiChainConnectorCallbackMap_ = {};
|
||||
std::shared_ptr<IHiChainConnectorCallback> HiChainConnector::hiChainConnectorCallback_ = nullptr;
|
||||
|
||||
HiChainConnector::HiChainConnector()
|
||||
{
|
||||
@@ -78,16 +78,15 @@ HiChainConnector::~HiChainConnector()
|
||||
LOGI("HiChainConnector::destructor.");
|
||||
}
|
||||
|
||||
int32_t HiChainConnector::RegisterHiChainCallback(const std::string &pkgName,
|
||||
std::shared_ptr<IHiChainConnectorCallback> callback)
|
||||
int32_t HiChainConnector::RegisterHiChainCallback(std::shared_ptr<IHiChainConnectorCallback> callback)
|
||||
{
|
||||
hiChainConnectorCallbackMap_.emplace(pkgName, callback);
|
||||
hiChainConnectorCallback_ = callback;
|
||||
return DM_OK;
|
||||
}
|
||||
|
||||
int32_t HiChainConnector::UnRegisterHiChainCallback(const std::string &pkgName)
|
||||
int32_t HiChainConnector::UnRegisterHiChainCallback()
|
||||
{
|
||||
hiChainConnectorCallbackMap_.erase(pkgName);
|
||||
hiChainConnectorCallback_ = nullptr;
|
||||
return DM_OK;
|
||||
}
|
||||
|
||||
@@ -210,15 +209,11 @@ void HiChainConnector::onFinish(int64_t requestId, int32_t operationCode, const
|
||||
LOGI("HiChainConnector::onFinish reqId:%lld, operation:%d", requestId, operationCode);
|
||||
if (operationCode == GroupOperationCode::MEMBER_JOIN) {
|
||||
LOGI("Add Member To Group success");
|
||||
for (auto &iter : hiChainConnectorCallbackMap_) {
|
||||
iter.second->OnMemberJoin(requestId, DM_OK);
|
||||
}
|
||||
hiChainConnectorCallback_->OnMemberJoin(requestId, DM_OK);
|
||||
}
|
||||
if (operationCode == GroupOperationCode::GROUP_CREATE) {
|
||||
LOGI("Create group success");
|
||||
for (auto &iter : hiChainConnectorCallbackMap_) {
|
||||
iter.second->OnGroupCreated(requestId, data);
|
||||
}
|
||||
hiChainConnectorCallback_->OnGroupCreated(requestId, data);
|
||||
}
|
||||
if (operationCode == GroupOperationCode::MEMBER_DELETE) {
|
||||
LOGI("Delete Member from group success");
|
||||
@@ -234,15 +229,11 @@ void HiChainConnector::onError(int64_t requestId, int32_t operationCode, int32_t
|
||||
LOGI("HichainAuthenCallBack::onError reqId:%lld, operation:%d, errorCode:%d.", requestId, operationCode, errorCode);
|
||||
if (operationCode == GroupOperationCode::MEMBER_JOIN) {
|
||||
LOGE("Add Member To Group failed");
|
||||
for (auto &iter : hiChainConnectorCallbackMap_) {
|
||||
iter.second->OnMemberJoin(requestId, DM_FAILED);
|
||||
}
|
||||
hiChainConnectorCallback_->OnMemberJoin(requestId, DM_FAILED);
|
||||
}
|
||||
if (operationCode == GroupOperationCode::GROUP_CREATE) {
|
||||
LOGE("Create group failed");
|
||||
for (auto &iter : hiChainConnectorCallbackMap_) {
|
||||
iter.second->OnGroupCreated(requestId, "{}");
|
||||
}
|
||||
hiChainConnectorCallback_->OnGroupCreated(requestId, "{}");
|
||||
}
|
||||
if (operationCode == GroupOperationCode::MEMBER_DELETE) {
|
||||
LOGE("Delete Member from group failed");
|
||||
@@ -259,9 +250,7 @@ char *HiChainConnector::onRequest(int64_t requestId, int32_t operationCode, cons
|
||||
return nullptr;
|
||||
}
|
||||
int32_t pinCode = 0;
|
||||
for (auto &iter : hiChainConnectorCallbackMap_) {
|
||||
pinCode = iter.second->GetPinCode();
|
||||
}
|
||||
pinCode = hiChainConnectorCallback_->GetPinCode();
|
||||
nlohmann::json jsonObj;
|
||||
if (pinCode == DM_FAILED) {
|
||||
jsonObj[FIELD_CONFIRMATION] = REQUEST_REJECTED;
|
||||
@@ -286,9 +275,7 @@ int64_t HiChainConnector::GenRequestId()
|
||||
std::string HiChainConnector::GetConnectPara(std::string deviceId, std::string reqDeviceId)
|
||||
{
|
||||
std::string connectAddr = "";
|
||||
for (auto &iter : hiChainConnectorCallbackMap_) {
|
||||
connectAddr = iter.second->GetConnectAddr(deviceId);
|
||||
}
|
||||
connectAddr = hiChainConnectorCallback_->GetConnectAddr(deviceId);
|
||||
LOGE("HiChainConnector::GetConnectPara get addrInfo");
|
||||
nlohmann::json jsonObject = nlohmann::json::parse(connectAddr, nullptr, false);
|
||||
if (jsonObject.is_discarded()) {
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
std::map<std::string, std::shared_ptr<ISoftbusSessionCallback>> SoftbusSession::sessionCallbackMap_ = {};
|
||||
std::shared_ptr<ISoftbusSessionCallback> SoftbusSession::sessionCallback_ = nullptr;
|
||||
|
||||
SoftbusSession::SoftbusSession()
|
||||
{
|
||||
@@ -45,16 +45,15 @@ SoftbusSession::~SoftbusSession()
|
||||
RemoveSessionServer(DM_PKG_NAME.c_str(), DM_SESSION_NAME.c_str());
|
||||
}
|
||||
|
||||
int32_t SoftbusSession::RegisterSessionCallback(const std::string &pkgName,
|
||||
std::shared_ptr<ISoftbusSessionCallback> callback)
|
||||
int32_t SoftbusSession::RegisterSessionCallback(std::shared_ptr<ISoftbusSessionCallback> callback)
|
||||
{
|
||||
sessionCallbackMap_[pkgName] = callback;
|
||||
sessionCallback_ = callback;
|
||||
return DM_OK;
|
||||
}
|
||||
|
||||
int32_t SoftbusSession::UnRegisterSessionCallback(const std::string &pkgName)
|
||||
int32_t SoftbusSession::UnRegisterSessionCallback()
|
||||
{
|
||||
sessionCallbackMap_.erase(pkgName);
|
||||
sessionCallback_ = nullptr;
|
||||
return DM_OK;
|
||||
}
|
||||
|
||||
@@ -108,11 +107,7 @@ int32_t SoftbusSession::SendData(int32_t sessionId, std::string &message)
|
||||
}
|
||||
int32_t msgType = jsonObject[TAG_TYPE];
|
||||
LOGI("AuthMessageProcessor::ParseAuthRequestMessage msgType = %d", msgType);
|
||||
bool isCryptoSupport = false;
|
||||
for (auto &iter : sessionCallbackMap_) {
|
||||
iter.second->GetIsCryptoSupport(isCryptoSupport);
|
||||
}
|
||||
if (isCryptoSupport) {
|
||||
if (sessionCallback_->GetIsCryptoSupport()) {
|
||||
LOGI("SoftbusSession::SendData Start encryption");
|
||||
}
|
||||
int32_t ret = SendBytes(sessionId, message.c_str(), strlen(message.c_str()));
|
||||
@@ -127,9 +122,7 @@ int32_t SoftbusSession::SendData(int32_t sessionId, std::string &message)
|
||||
int32_t SoftbusSession::OnSessionOpened(int32_t sessionId, int32_t result)
|
||||
{
|
||||
int32_t sessionSide = GetSessionSide(sessionId);
|
||||
for (auto &iter : sessionCallbackMap_) {
|
||||
iter.second->OnSessionOpened(iter.first, sessionId, sessionSide, result);
|
||||
}
|
||||
sessionCallback_->OnSessionOpened(sessionId, sessionSide, result);
|
||||
LOGI("OnSessionOpened, success:");
|
||||
return DM_OK;
|
||||
}
|
||||
@@ -146,18 +139,11 @@ void SoftbusSession::OnBytesReceived(int32_t sessionId, const void *data, uint32
|
||||
LOGI("OnBytesReceived param check failed");
|
||||
return;
|
||||
}
|
||||
bool isCryptoSupport = false;
|
||||
for (auto &iter : sessionCallbackMap_) {
|
||||
iter.second->GetIsCryptoSupport(isCryptoSupport);
|
||||
}
|
||||
if (isCryptoSupport) {
|
||||
if (sessionCallback_->GetIsCryptoSupport()) {
|
||||
LOGI("SoftbusSession::OnBytesReceived Start decryption");
|
||||
}
|
||||
std::string message = std::string((const char *)data, dataLen);
|
||||
for (auto &iter : sessionCallbackMap_) {
|
||||
iter.second->OnDataReceived(iter.first, sessionId, message);
|
||||
return;
|
||||
}
|
||||
sessionCallback_->OnDataReceived(sessionId, message);
|
||||
LOGI("OnBytesReceived completed");
|
||||
}
|
||||
} // namespace DistributedHardware
|
||||
|
||||
@@ -72,7 +72,7 @@ int32_t DeviceManagerService::Init()
|
||||
LOGE("Init failed, authMgr_ apply for failure");
|
||||
return DM_MAKE_SHARED_FAIL;
|
||||
}
|
||||
authMgr_->RegisterSessionCallback();
|
||||
authMgr_->RegisterCallback();
|
||||
}
|
||||
LOGI("Init success, singleton initialized");
|
||||
intFlag_ = true;
|
||||
|
||||
@@ -256,15 +256,12 @@ HWTEST_F(HichainConnectorTest, HiChainConnector_002, testing::ext::TestSize.Leve
|
||||
*/
|
||||
HWTEST_F(HichainConnectorTest, RegisterHiChainCallback_001, testing::ext::TestSize.Level0)
|
||||
{
|
||||
std::string pkgName = "com.softbus.test";
|
||||
std::shared_ptr<DeviceManagerServiceListener> listener_ = std::make_shared<DeviceManagerServiceListener>();
|
||||
std::shared_ptr<SoftbusConnector> softbusConnector = std::make_shared<SoftbusConnector>();
|
||||
std::shared_ptr<DmAuthManager> discoveryMgr_ = std::make_shared<DmAuthManager>(softbusConnector, listener_);
|
||||
std::shared_ptr<HiChainConnector> hichainConnector = std::make_shared<HiChainConnector>();
|
||||
int ret =
|
||||
hichainConnector->RegisterHiChainCallback(pkgName, std::shared_ptr<IHiChainConnectorCallback>(discoveryMgr_));
|
||||
int ret1 = HiChainConnector::hiChainConnectorCallbackMap_.count(pkgName);
|
||||
EXPECT_EQ(ret1, 1);
|
||||
hichainConnector->RegisterHiChainCallback(std::shared_ptr<IHiChainConnectorCallback>(discoveryMgr_));
|
||||
EXPECT_EQ(ret, DM_OK);
|
||||
}
|
||||
|
||||
@@ -355,12 +352,11 @@ HWTEST_F(HichainConnectorTest, onRequest_001, testing::ext::TestSize.Level0)
|
||||
*/
|
||||
HWTEST_F(HichainConnectorTest, GetConnectPara_001, testing::ext::TestSize.Level0)
|
||||
{
|
||||
std::string pkgName = "softbus";
|
||||
std::shared_ptr<DeviceManagerServiceListener> listener_ = std::make_shared<DeviceManagerServiceListener>();
|
||||
std::shared_ptr<SoftbusConnector> softbusConnector = std::make_shared<SoftbusConnector>();
|
||||
std::shared_ptr<DmAuthManager> discoveryMgr_ = std::make_shared<DmAuthManager>(softbusConnector, listener_);
|
||||
std::shared_ptr<HiChainConnector> hichainConnector = std::make_shared<HiChainConnector>();
|
||||
hichainConnector->RegisterHiChainCallback(pkgName, std::shared_ptr<IHiChainConnectorCallback>(discoveryMgr_));
|
||||
hichainConnector->RegisterHiChainCallback(std::shared_ptr<IHiChainConnectorCallback>(discoveryMgr_));
|
||||
std::string deviceId = "23445";
|
||||
std::string reqDeviceId = "234566";
|
||||
std::string p;
|
||||
@@ -378,12 +374,11 @@ HWTEST_F(HichainConnectorTest, GetConnectPara_002, testing::ext::TestSize.Level0
|
||||
{
|
||||
std::string deviceId;
|
||||
std::string reqDeviceId = "234566";
|
||||
std::string pkgName = "softbus";
|
||||
std::shared_ptr<DeviceManagerServiceListener> listener_ = std::make_shared<DeviceManagerServiceListener>();
|
||||
std::shared_ptr<SoftbusConnector> softbusConnector = std::make_shared<SoftbusConnector>();
|
||||
std::shared_ptr<DmAuthManager> discoveryMgr_ = std::make_shared<DmAuthManager>(softbusConnector, listener_);
|
||||
std::shared_ptr<HiChainConnector> hichainConnector = std::make_shared<HiChainConnector>();
|
||||
hichainConnector->RegisterHiChainCallback(pkgName, std::shared_ptr<IHiChainConnectorCallback>(discoveryMgr_));
|
||||
hichainConnector->RegisterHiChainCallback(std::shared_ptr<IHiChainConnectorCallback>(discoveryMgr_));
|
||||
std::string ret = hichainConnector->GetConnectPara(deviceId, reqDeviceId);
|
||||
EXPECT_EQ(ret, "");
|
||||
}
|
||||
|
||||
@@ -172,7 +172,7 @@ HWTEST_F(SoftbusSessionTest, GetPeerDeviceId_001, testing::ext::TestSize.Level0)
|
||||
HWTEST_F(SoftbusSessionTest, UnRegisterSessionCallback_001, testing::ext::TestSize.Level0)
|
||||
{
|
||||
std::string pkgName = "softbus";
|
||||
int ret = softbusSession->UnRegisterSessionCallback(pkgName);
|
||||
int ret = softbusSession->UnRegisterSessionCallback();
|
||||
EXPECT_EQ(ret, DM_OK);
|
||||
}
|
||||
} // namespace
|
||||
|
||||
Reference in New Issue
Block a user