!390 Openharmony-master分支支持L0设备的devicemanager模块

Merge pull request !390 from 闻飞/master
This commit is contained in:
openharmony_ci
2022-03-19 09:41:55 +00:00
committed by Gitee
57 changed files with 4310 additions and 45 deletions
+15 -4
View File
@@ -14,10 +14,21 @@
import("//build/lite/config/component/lite_component.gni")
if (defined(ohos_lite)) {
lite_component("devicemanager_lite") {
if (ohos_kernel_type == "liteos_m") {
} else {
features = []
if (ohos_kernel_type == "liteos_m") {
lite_component("devicemanager_mini") {
features = [
"utils:devicemanagerutils_mini",
"services/devicemanagerservice:devicemanagerservice_mini",
"interfaces/inner_kits/native_cpp:devicemanagersdk_mini",
"interfaces/kits/js_mini:devicemanager_native_js",
]
}
} else {
lite_component("devicemanager_lite") {
if (ohos_kernel_type == "liteos_m") {
} else {
features = []
}
}
}
}
+41 -1
View File
@@ -19,7 +19,47 @@ if (defined(ohos_lite)) {
import("//foundation/distributedhardware/devicemanager/devicemanager.gni")
if (defined(ohos_lite)) {
shared_library("devicemanagersdk") {
if (ohos_kernel_type == "liteos_m") {
static_library("devicemanagersdk_mini") {
include_dirs = [
"${innerkits_path}/native_cpp/include",
"${innerkits_path}/native_cpp/include/notify",
"${utils_path}/include",
"${common_path}/include",
"${services_path}/include/dispatch",
]
include_dirs += [
"//utils/native/lite/include",
"//base/hiviewdfx/hilog_lite/interfaces/native/innerkits/hilog",
"//third_party/bounds_checking_function/include",
"//foundation/distributedschedule/samgr_lite/interfaces/kits/samgr",
"//third_party/json/include",
]
sources = [
"${innerkits_path}/native_cpp/src/mini/device_manager.cpp",
"${innerkits_path}/native_cpp/src/mini/device_manager_impl.cpp",
"${innerkits_path}/native_cpp/src/mini/device_manager_notify.cpp",
]
defines = [
"LITE_DEVICE",
"HI_LOG_ENABLE",
"DH_LOG_TAG=\"devicemanagerkit\"",
"LOG_DOMAIN=0xD004100",
]
deps = [
"${utils_path}:devicemanagerutils_mini",
"//base/hiviewdfx/hilog_lite/frameworks/featured:hilog_static",
"//foundation/distributedschedule/samgr_lite/samgr",
"//third_party/bounds_checking_function:libsec_static",
"//utils/native/lite:utils",
]
}
} else {
shared_library("devicemanagersdk") {
}
}
} else {
config("devicemanagersdk_config") {
@@ -17,8 +17,10 @@
#define OHOS_DEVICE_MANAGER_IMPL_H
#include "device_manager.h"
#if !defined(__LITEOS_M__)
#include "ipc_client_manager.h"
#include "ipc_client_proxy.h"
#endif
namespace OHOS {
namespace DistributedHardware {
@@ -67,8 +69,10 @@ private:
DeviceManagerImpl &operator=(DeviceManagerImpl &&) = delete;
private:
#if !defined(__LITEOS_M__)
std::shared_ptr<IpcClientProxy> ipcClientProxy_ =
std::make_shared<IpcClientProxy>(std::make_shared<IpcClientManager>());
#endif
};
} // namespace DistributedHardware
} // namespace OHOS
@@ -65,7 +65,9 @@ public:
void OnFaCall(std::string &pkgName, std::string &paramJson);
private:
#if !defined(__LITEOS_M__)
std::mutex lock_;
#endif
std::map<std::string, std::shared_ptr<DeviceStateCallback>> deviceStateCallback_;
std::map<std::string, std::map<uint16_t, std::shared_ptr<DiscoveryCallback>>> deviceDiscoveryCallbacks_;
std::map<std::string, std::map<std::string, std::shared_ptr<AuthenticateCallback>>> authenticateCallback_;
@@ -0,0 +1,27 @@
/*
* Copyright (c) 2021 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.h"
#include "device_manager_impl.h"
namespace OHOS {
namespace DistributedHardware {
DeviceManager &DeviceManager::GetInstance()
{
return DeviceManagerImpl::GetInstance();
}
} // namespace DistributedHardware
} // namespace OHOS
@@ -0,0 +1,436 @@
/*
* Copyright (c) 2021 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 "command_dispatch.h"
#include "dm_log.h"
#include "device_manager_notify.h"
#include "dm_constants.h"
#include "message_def.h"
#include "get_trustdevice_req.h"
#include "get_trustdevice_rsp.h"
#include "start_discovery_req.h"
#include "stop_discovery_req.h"
#include "get_useroperation_req.h"
#include "authenticate_device_req.h"
#include "verify_authenticate_req.h"
#include "get_local_device_info_rsp.h"
#include "get_info_by_network_rsp.h"
#include "get_info_by_network_req.h"
#include "unauthenticate_device_req.h"
#include "get_dmfaparam_rsp.h"
#include "device_manager_impl.h"
namespace OHOS {
namespace DistributedHardware {
DeviceManagerImpl &DeviceManagerImpl::GetInstance()
{
static DeviceManagerImpl instance;
return instance;
}
int32_t DeviceManagerImpl::InitDeviceManager(const std::string &pkgName, std::shared_ptr<DmInitCallback> dmInitCallback)
{
LOGI("DeviceManager::InitDeviceManager start, pkgName: %s", pkgName.c_str());
if (pkgName.empty() || dmInitCallback == nullptr) {
LOGE("InitDeviceManager error: Invalid parameter");
return DM_INVALID_VALUE;
}
CommandDispatch::GetInstance().AddPkgName(pkgName);
DeviceManagerNotify::GetInstance().RegisterDeathRecipientCallback(pkgName, dmInitCallback);
LOGI("InitDeviceManager success");
return DM_OK;
}
int32_t DeviceManagerImpl::UnInitDeviceManager(const std::string &pkgName)
{
LOGI("DeviceManager::UnInitDeviceManager start, pkgName: %s", pkgName.c_str());
if (pkgName.empty()) {
LOGE("InitDeviceManager error: Invalid parameter");
return DM_INVALID_VALUE;
}
CommandDispatch::GetInstance().DeletePkgName(pkgName);
DeviceManagerNotify::GetInstance().UnRegisterPackageCallback(pkgName);
LOGI("UnInitDeviceManager success");
return DM_OK;
}
int32_t DeviceManagerImpl::GetTrustedDeviceList(const std::string &pkgName, const std::string &extra,
std::vector<DmDeviceInfo> &deviceList)
{
LOGI("DeviceManager::GetTrustedDeviceList start, pkgName: %s", pkgName.c_str());
if (pkgName.empty()) {
LOGE("GetTrustedDeviceList error: Invalid para");
return DM_INVALID_VALUE;
}
std::shared_ptr<GetTrustDeviceReq> req = std::make_shared<GetTrustDeviceReq>();
std::shared_ptr<GetTrustDeviceRsp> rsp = std::make_shared<GetTrustDeviceRsp>();
req->SetPkgName(pkgName);
req->SetExtra(extra);
if (CommandDispatch::GetInstance().MessageSendCmd(GET_TRUST_DEVICE_LIST, req, rsp) != DM_OK) {
return DEVICEMANAGER_MESSAGE_FAILED;
}
int32_t ret = rsp->GetErrCode();
if (ret != DM_OK) {
LOGE("GetTrustedDeviceList error: failed ret: %d", ret);
return ret;
}
deviceList = rsp->GetDeviceVec();
LOGI("GetTrustedDeviceList completed, pkgName: %s", pkgName.c_str());
return DM_OK;
}
int32_t DeviceManagerImpl::GetLocalDeviceInfo(const std::string &pkgName, DmDeviceInfo &info)
{
LOGI("DeviceManager::GetLocalDeviceInfo start, pkgName: %s", pkgName.c_str());
if (pkgName.empty()) {
LOGE("GetLocalDeviceInfo error: Invalid para");
return DM_INVALID_VALUE;
}
std::shared_ptr<MessageReq> req = std::make_shared<MessageReq>();
std::shared_ptr<GetLocalDeviceInfoRsp> rsp = std::make_shared<GetLocalDeviceInfoRsp>();
req->SetPkgName(pkgName);
if (CommandDispatch::GetInstance().MessageSendCmd(GET_LOCAL_DEVICE_INFO, req, rsp) != DM_OK) {
return DEVICEMANAGER_MESSAGE_FAILED;
}
if (rsp->GetErrCode() != DM_OK) {
LOGE("GetLocalDeviceInfo error: failed ret: %d", rsp->GetErrCode());
return DM_IPC_RESPOND_ERROR;
}
info = rsp->GetLocalDeviceInfo();
LOGI("GetLocalDeviceInfo completed,pkgname%s", req->GetPkgName().c_str());
return DM_OK;
}
int32_t DeviceManagerImpl::RegisterDevStateCallback(const std::string &pkgName, const std::string &extra,
std::shared_ptr<DeviceStateCallback> callback)
{
LOGI("DeviceManager::RegisterDevStateCallback start, pkgName: %s", pkgName.c_str());
if (pkgName.empty() || callback == nullptr) {
LOGE("RegisterDevStateCallback error: Invalid para");
return DM_INVALID_VALUE;
}
DeviceManagerNotify::GetInstance().RegisterDeviceStateCallback(pkgName, callback);
LOGI("RegisterDevStateCallback completed, pkgName: %s", pkgName.c_str());
return DM_OK;
}
int32_t DeviceManagerImpl::UnRegisterDevStateCallback(const std::string &pkgName)
{
LOGI("DeviceManager::UnRegisterDevStateCallback start, pkgName: %s", pkgName.c_str());
if (pkgName.empty()) {
LOGE("UnRegisterDevStateCallback error: Invalid para");
return DM_INVALID_VALUE;
}
DeviceManagerNotify::GetInstance().UnRegisterDeviceStateCallback(pkgName);
LOGI("UnRegisterDevStateCallback completed, pkgName: %s", pkgName.c_str());
return DM_OK;
}
int32_t DeviceManagerImpl::StartDeviceDiscovery(const std::string &pkgName, const DmSubscribeInfo &subscribeInfo,
const std::string &extra, std::shared_ptr<DiscoveryCallback> callback)
{
LOGI("DeviceManager::StartDeviceDiscovery start, pkgName: %s", pkgName.c_str());
if (pkgName.empty() || callback == nullptr) {
LOGE("StartDeviceDiscovery error: Invalid para");
return DM_INVALID_VALUE;
}
LOGI("DeviceManager StartDeviceDiscovery in, pkgName %s", pkgName.c_str());
DeviceManagerNotify::GetInstance().RegisterDiscoveryCallback(pkgName, subscribeInfo.subscribeId, callback);
std::shared_ptr<StartDiscoveryReq> req = std::make_shared<StartDiscoveryReq>();
std::shared_ptr<MessageRsp> rsp = std::make_shared<MessageRsp>();
req->SetPkgName(pkgName);
req->SetExtra(extra);
req->SetSubscribeInfo(subscribeInfo);
if (CommandDispatch::GetInstance().MessageSendCmd(START_DEVICE_DISCOVER, req, rsp) != DM_OK) {
return DEVICEMANAGER_MESSAGE_FAILED;
}
int32_t ret = rsp->GetErrCode();
if (ret != DM_OK) {
LOGE("StartDeviceDiscovery error: Failed with ret %d", ret);
return ret;
}
return DM_OK;
}
int32_t DeviceManagerImpl::StopDeviceDiscovery(const std::string &pkgName, uint16_t subscribeId)
{
LOGI("DeviceManager::StopDeviceDiscovery start , pkgName: %s", pkgName.c_str());
if (pkgName.empty()) {
LOGE("StopDeviceDiscovery error: Invalid para");
return DM_INVALID_VALUE;
}
LOGI("StopDeviceDiscovery in, pkgName %s", pkgName.c_str());
std::shared_ptr<StopDiscoveryReq> req = std::make_shared<StopDiscoveryReq>();
std::shared_ptr<MessageRsp> rsp = std::make_shared<MessageRsp>();
req->SetPkgName(pkgName);
req->SetSubscribeId(subscribeId);
if (CommandDispatch::GetInstance().MessageSendCmd(STOP_DEVICE_DISCOVER, req, rsp) != DM_OK) {
return DEVICEMANAGER_MESSAGE_FAILED;
}
int32_t ret = rsp->GetErrCode();
if (ret != DM_OK) {
LOGE("StopDeviceDiscovery error: Failed with ret %d", ret);
return ret;
}
DeviceManagerNotify::GetInstance().UnRegisterDiscoveryCallback(pkgName, subscribeId);
LOGI("StopDeviceDiscovery completed, pkgName: %s", pkgName.c_str());
return DM_OK;
}
int32_t DeviceManagerImpl::AuthenticateDevice(const std::string &pkgName, int32_t authType,
const DmDeviceInfo &deviceInfo, const std::string &extra,
std::shared_ptr<AuthenticateCallback> callback)
{
LOGI("DeviceManager::AuthenticateDevice start , pkgName: %s", pkgName.c_str());
if (pkgName.empty()) {
LOGE("AuthenticateDevice error: Invalid para");
return DM_INVALID_VALUE;
}
std::string strDeviceId = deviceInfo.deviceId;
DeviceManagerNotify::GetInstance().RegisterAuthenticateCallback(pkgName, strDeviceId, callback);
std::shared_ptr<AuthenticateDeviceReq> req = std::make_shared<AuthenticateDeviceReq>();
std::shared_ptr<MessageRsp> rsp = std::make_shared<MessageRsp>();
req->SetPkgName(pkgName);
req->SetExtra(extra);
req->SetAuthType(authType);
req->SetDeviceInfo(deviceInfo);
if (CommandDispatch::GetInstance().MessageSendCmd(AUTHENTICATE_DEVICE, req, rsp) != DM_OK) {
return DEVICEMANAGER_MESSAGE_FAILED;
}
int32_t ret = rsp->GetErrCode();
if (ret != DM_OK) {
LOGE("AuthenticateDevice error: Failed with ret %d", ret);
return ret;
}
LOGI("DeviceManager::AuthenticateDevice completed, pkgName: %s", pkgName.c_str());
return DM_OK;
}
int32_t DeviceManagerImpl::UnAuthenticateDevice(const std::string &pkgName, const std::string &deviceId)
{
LOGI("DeviceManager::UnAuthenticateDevice start , pkgName: %s, deviceId: %s", pkgName.c_str(), deviceId.c_str());
if (deviceId.empty()) {
LOGE("UnAuthenticateDevice error: Invalid para");
return DM_INVALID_VALUE;
}
DmDeviceInfo deviceInfo;
strcpy_s(deviceInfo.deviceId, DM_MAX_DEVICE_ID_LEN, deviceId.c_str());
std::shared_ptr<UnAuthenticateDeviceReq> req = std::make_shared<UnAuthenticateDeviceReq>();
std::shared_ptr<MessageRsp> rsp = std::make_shared<MessageRsp>();
req->SetPkgName(pkgName);
req->SetDeviceInfo(deviceInfo);
if (CommandDispatch::GetInstance().MessageSendCmd(UNAUTHENTICATE_DEVICE, req, rsp) != DM_OK) {
return DEVICEMANAGER_MESSAGE_FAILED;
}
int32_t ret = rsp->GetErrCode();
if (ret != DM_OK) {
LOGE("UnAuthenticateDevice error: Failed with ret %d", ret);
return ret;
}
LOGI("UnAuthenticateDevice completed, pkgName: %s", pkgName.c_str());
return DM_OK;
}
int32_t DeviceManagerImpl::RegisterDeviceManagerFaCallback(const std::string &packageName,
std::shared_ptr<DeviceManagerFaCallback> callback)
{
LOGI("DeviceManager::RegisterDeviceManagerFaCallback start, pkgName: %s", packageName.c_str());
if (packageName.empty() || callback == nullptr) {
LOGE("RegisterDeviceManagerFaCallback error: Invalid para");
return DM_INVALID_VALUE;
}
DeviceManagerNotify::GetInstance().RegisterDeviceManagerFaCallback(packageName, callback);
LOGI("DeviceManager::RegisterDevStateCallback completed, pkgName: %s", packageName.c_str());
return DM_OK;
}
int32_t DeviceManagerImpl::UnRegisterDeviceManagerFaCallback(const std::string &pkgName)
{
LOGI("DeviceManager::UnRegisterDeviceManagerFaCallback start, pkgName: %s", pkgName.c_str());
if (pkgName.empty()) {
LOGE("UnRegisterDeviceManagerFaCallback error: Invalid para");
return DM_INVALID_VALUE;
}
DeviceManagerNotify::GetInstance().UnRegisterDeviceManagerFaCallback(pkgName);
LOGI("DeviceManager::UnRegisterDevStateCallback completed, pkgName: %s", pkgName.c_str());
return DM_OK;
}
int32_t DeviceManagerImpl::VerifyAuthentication(const std::string &pkgName, const std::string &authPara,
std::shared_ptr<VerifyAuthCallback> callback)
{
LOGI("DeviceManager::VerifyAuthentication start, pkgName: %s", pkgName.c_str());
if (pkgName.empty()) {
LOGE("VerifyAuthentication error: Invalid para");
return DM_INVALID_VALUE;
}
DeviceManagerNotify::GetInstance().RegisterVerifyAuthenticationCallback(pkgName, authPara, callback);
std::shared_ptr<VerifyAuthenticateReq> req = std::make_shared<VerifyAuthenticateReq>();
std::shared_ptr<MessageRsp> rsp = std::make_shared<MessageRsp>();
req->SetPkgName(pkgName);
req->SetAuthPara(authPara);
if (CommandDispatch::GetInstance().MessageSendCmd(VERIFY_AUTHENTICATION, req, rsp) != DM_OK) {
return DEVICEMANAGER_MESSAGE_FAILED;
}
int32_t ret = rsp->GetErrCode();
if (ret != DM_OK) {
LOGE("VerifyAuthentication error: Failed with ret %d", ret);
return ret;
}
LOGI("VerifyAuthentication completed, pkgName: %s", pkgName.c_str());
return DM_OK;
}
int32_t DeviceManagerImpl::GetFaParam(const std::string &pkgName, DmAuthParam &dmFaParam)
{
LOGI("DeviceManager::GetFaParam start, pkgName: %s", pkgName.c_str());
if (pkgName.empty()) {
LOGE("GetFaParam failed, pkgName is empty");
return DM_INVALID_VALUE;
}
std::shared_ptr<MessageReq> req = std::make_shared<MessageReq>();
std::shared_ptr<GetDmFaParamRsp> rsp = std::make_shared<GetDmFaParamRsp>();
req->SetPkgName(pkgName);
if (CommandDispatch::GetInstance().MessageSendCmd(SERVER_GET_DMFA_INFO, req, rsp) != DM_OK) {
return DEVICEMANAGER_MESSAGE_FAILED;
}
dmFaParam = rsp->GetDmAuthParam();
LOGI("GetFaParam completed, pkgName: %s", pkgName.c_str());
return DM_OK;
}
int32_t DeviceManagerImpl::SetUserOperation(const std::string &pkgName, int32_t action)
{
LOGI("DeviceManager::SetUserOperation start, pkgName: %s", pkgName.c_str());
if (pkgName.empty()) {
LOGE("VerifyAuthentication failed, pkgName is empty");
return DM_INVALID_VALUE;
}
std::shared_ptr<GetUserOperationReq> req = std::make_shared<GetUserOperationReq>();
std::shared_ptr<MessageRsp> rsp = std::make_shared<MessageRsp>();
req->SetPkgName(pkgName);
req->SetOperation(action);
if (CommandDispatch::GetInstance().MessageSendCmd(SERVER_USER_AUTH_OPERATION, req, rsp) != DM_OK) {
return DEVICEMANAGER_MESSAGE_FAILED;
}
int32_t ret = rsp->GetErrCode();
if (ret != DM_OK) {
LOGE("SetUserOperation Failed with ret %d", ret);
return ret;
}
LOGI("SetUserOperation completed, pkgName: %s", pkgName.c_str());
return DM_OK;
}
int32_t DeviceManagerImpl::GetUdidByNetworkId(const std::string &pkgName, const std::string &netWorkId,
std::string &udid)
{
if (pkgName.empty()) {
LOGE("GetUdidByNetworkId failed, pkgName is empty");
return DM_INVALID_VALUE;
}
std::shared_ptr<GetInfoByNetWorkReq> req = std::make_shared<GetInfoByNetWorkReq>();
std::shared_ptr<GetInfoByNetWorkRsp> rsp = std::make_shared<GetInfoByNetWorkRsp>();
req->SetPkgName(pkgName);
req->SetNetWorkId(netWorkId);
if (CommandDispatch::GetInstance().MessageSendCmd(GET_UDID_BY_NETWORK, req, rsp) != DM_OK) {
return DEVICEMANAGER_MESSAGE_FAILED;
}
int32_t ret = rsp->GetErrCode();
if (ret != DM_OK) {
LOGE("DeviceManager::GetUdidByNetworkId Failed with ret %d", ret);
return ret;
}
udid = rsp->GetUdid();
return DM_OK;
}
int32_t DeviceManagerImpl::GetUuidByNetworkId(const std::string &pkgName, const std::string &netWorkId,
std::string &uuid)
{
if (pkgName.empty()) {
LOGE("GetUuidByNetworkId failed, pkgName is empty");
return DM_INVALID_VALUE;
}
std::shared_ptr<GetInfoByNetWorkReq> req = std::make_shared<GetInfoByNetWorkReq>();
std::shared_ptr<GetInfoByNetWorkRsp> rsp = std::make_shared<GetInfoByNetWorkRsp>();
req->SetPkgName(pkgName);
req->SetNetWorkId(netWorkId);
if (CommandDispatch::GetInstance().MessageSendCmd(GET_UUID_BY_NETWORK, req, rsp) != DM_OK) {
return DEVICEMANAGER_MESSAGE_FAILED;
}
int32_t ret = rsp->GetErrCode();
if (ret != DM_OK) {
LOGE("GetUuidByNetworkId Failed with ret %d", ret);
return ret;
}
uuid = rsp->GetUuid();
return DM_OK;
}
int32_t DeviceManagerImpl::RegisterDevStateCallback(const std::string &pkgName, const std::string &extra)
{
}
int32_t DeviceManagerImpl::UnRegisterDevStateCallback(const std::string &pkgName, const std::string &extra)
{
}
} // namespace DistributedHardware
} // namespace OHOS
@@ -0,0 +1,260 @@
/*
* Copyright (c) 2021 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_notify.h"
#include "dm_log.h"
#include "nlohmann/json.hpp"
#include "dm_constants.h"
#include "device_manager.h"
namespace OHOS {
namespace DistributedHardware {
IMPLEMENT_SINGLE_INSTANCE(DeviceManagerNotify);
void DeviceManagerNotify::RegisterDeathRecipientCallback(const std::string &pkgName,
std::shared_ptr<DmInitCallback> dmInitCallback)
{
dmInitCallback_[pkgName] = dmInitCallback;
}
void DeviceManagerNotify::UnRegisterDeathRecipientCallback(const std::string &pkgName)
{
dmInitCallback_.erase(pkgName);
}
void DeviceManagerNotify::RegisterDeviceStateCallback(const std::string &pkgName,
std::shared_ptr<DeviceStateCallback> callback)
{
deviceStateCallback_[pkgName] = callback;
}
void DeviceManagerNotify::UnRegisterDeviceStateCallback(const std::string &pkgName)
{
deviceStateCallback_.erase(pkgName);
}
void DeviceManagerNotify::RegisterDiscoveryCallback(const std::string &pkgName, uint16_t subscribeId,
std::shared_ptr<DiscoveryCallback> callback)
{
if (deviceDiscoveryCallbacks_.count(pkgName) == 0) {
deviceDiscoveryCallbacks_[pkgName] = std::map<uint16_t, std::shared_ptr<DiscoveryCallback>>();
}
deviceDiscoveryCallbacks_[pkgName][subscribeId] = callback;
}
void DeviceManagerNotify::UnRegisterDiscoveryCallback(const std::string &pkgName, uint16_t subscribeId)
{
if (deviceDiscoveryCallbacks_.count(pkgName) > 0) {
deviceDiscoveryCallbacks_[pkgName].erase(subscribeId);
if (deviceDiscoveryCallbacks_[pkgName].empty()) {
deviceDiscoveryCallbacks_.erase(pkgName);
}
}
}
void DeviceManagerNotify::RegisterAuthenticateCallback(const std::string &pkgName, const std::string &deviceId,
std::shared_ptr<AuthenticateCallback> callback)
{
if (authenticateCallback_.count(pkgName) == 0) {
authenticateCallback_[pkgName] = std::map<std::string, std::shared_ptr<AuthenticateCallback>>();
}
authenticateCallback_[pkgName][deviceId] = callback;
}
void DeviceManagerNotify::UnRegisterAuthenticateCallback(const std::string &pkgName, const std::string &deviceId)
{
if (authenticateCallback_.count(pkgName) > 0) {
authenticateCallback_[pkgName].erase(deviceId);
if (authenticateCallback_[pkgName].empty()) {
authenticateCallback_.erase(pkgName);
}
}
}
void DeviceManagerNotify::UnRegisterPackageCallback(const std::string &pkgName)
{
deviceStateCallback_.erase(pkgName);
deviceDiscoveryCallbacks_.erase(pkgName);
authenticateCallback_.erase(pkgName);
dmInitCallback_.erase(pkgName);
}
void DeviceManagerNotify::RegisterVerifyAuthenticationCallback(const std::string &pkgName, const std::string &authPara,
std::shared_ptr<VerifyAuthCallback> callback)
{
verifyAuthCallback_[pkgName] = callback;
}
void DeviceManagerNotify::UnRegisterVerifyAuthenticationCallback(const std::string &pkgName)
{
verifyAuthCallback_.erase(pkgName);
}
void DeviceManagerNotify::RegisterDeviceManagerFaCallback(const std::string &pkgName,
std::shared_ptr<DeviceManagerFaCallback> callback)
{
dmFaCallback_[pkgName] = callback;
}
void DeviceManagerNotify::UnRegisterDeviceManagerFaCallback(const std::string &pkgName)
{
if (dmFaCallback_.count(pkgName) == 0) {
LOGE("DeviceManager UnRegisterDeviceManagerFaCallback not register");
return;
}
dmFaCallback_.erase(pkgName);
}
void DeviceManagerNotify::OnRemoteDied()
{
LOGW("DeviceManager : OnRemoteDied");
for (auto iter : dmInitCallback_) {
iter.second->OnRemoteDied();
}
}
void DeviceManagerNotify::OnDeviceOnline(const std::string &pkgName, const DmDeviceInfo &deviceInfo)
{
LOGI("DeviceManager OnDeviceOnline pkgName:%s", pkgName.c_str());
if (deviceStateCallback_.count(pkgName) == 0) {
LOGE("DeviceManager OnDeviceOnlinecallback not register");
return;
}
deviceStateCallback_[pkgName]->OnDeviceOnline(deviceInfo);
}
void DeviceManagerNotify::OnDeviceOffline(const std::string &pkgName, const DmDeviceInfo &deviceInfo)
{
LOGI("DeviceManager OnDeviceOffline pkgName:%s", pkgName.c_str());
if (deviceStateCallback_.count(pkgName) == 0) {
LOGE("DeviceManager OnDeviceOfflinecallback not register");
return;
}
deviceStateCallback_[pkgName]->OnDeviceOffline(deviceInfo);
}
void DeviceManagerNotify::OnDeviceChanged(const std::string &pkgName, const DmDeviceInfo &deviceInfo)
{
LOGI("DeviceManager OnDeviceChanged pkgName:%s", pkgName.c_str());
if (deviceStateCallback_.count(pkgName) == 0) {
LOGE("DeviceManager OnDeviceChangedcallback not register");
return;
}
deviceStateCallback_[pkgName]->OnDeviceChanged(deviceInfo);
}
void DeviceManagerNotify::OnDeviceFound(const std::string &pkgName, uint16_t subscribeId,
const DmDeviceInfo &deviceInfo)
{
LOGI("DeviceManager OnDeviceFound pkgName:%s, subscribeId:%d.", pkgName.c_str(), (int32_t)subscribeId);
if (deviceDiscoveryCallbacks_.count(pkgName) == 0) {
LOGE("DeviceManager OnDeviceFound: no register DiscoveryCallback for this package");
return;
}
std::map<uint16_t, std::shared_ptr<DiscoveryCallback>> &discoverCallMap = deviceDiscoveryCallbacks_[pkgName];
auto iter = discoverCallMap.find(subscribeId);
if (iter == discoverCallMap.end()) {
LOGE("DeviceManager OnDeviceFound: no register DiscoveryCallback for subscribeId %d", subscribeId);
return;
}
iter->second->OnDeviceFound(subscribeId, deviceInfo);
}
void DeviceManagerNotify::OnDiscoveryFailed(const std::string &pkgName, uint16_t subscribeId, int32_t failedReason)
{
LOGI("DeviceManager OnDiscoveryFailed pkgName:%s, subscribeId %d, reason %d", pkgName.c_str(), subscribeId,
failedReason);
if (deviceDiscoveryCallbacks_.count(pkgName) == 0) {
LOGE("DeviceManager OnDiscoveryFailed: no register DiscoveryCallback for this package");
return;
}
std::map<uint16_t, std::shared_ptr<DiscoveryCallback>> &discoverCallMap = deviceDiscoveryCallbacks_[pkgName];
auto iter = discoverCallMap.find(subscribeId);
if (iter == discoverCallMap.end()) {
LOGE("DeviceManager OnDiscoveryFailed: no register DiscoveryCallback for subscribeId %d", subscribeId);
return;
}
iter->second->OnDiscoveryFailed(subscribeId, failedReason);
}
void DeviceManagerNotify::OnDiscoverySuccess(const std::string &pkgName, uint16_t subscribeId)
{
LOGI("DeviceManager OnDiscoverySuccess pkgName:%s, subscribeId:%d.", pkgName.c_str(), subscribeId);
if (deviceDiscoveryCallbacks_.count(pkgName) == 0) {
LOGE("DeviceManager OnDiscoverySuccess: no register DiscoveryCallback for this package");
return;
}
std::map<uint16_t, std::shared_ptr<DiscoveryCallback>> &discoverCallMap = deviceDiscoveryCallbacks_[pkgName];
auto iter = discoverCallMap.find(subscribeId);
if (iter == discoverCallMap.end()) {
LOGE("DeviceManager OnDiscoverySuccess: no register DiscoveryCallback for subscribeId %d", subscribeId);
return;
}
iter->second->OnDiscoverySuccess(subscribeId);
}
void DeviceManagerNotify::OnAuthResult(const std::string &pkgName, const std::string &deviceId,
const std::string &token, uint32_t status, uint32_t reason)
{
LOGI("DeviceManagerNotify::OnAuthResult pkgName:%s, status:%d, reason:%d", pkgName.c_str(), status, reason);
if (authenticateCallback_.count(pkgName) == 0) {
LOGE("DeviceManager OnAuthResult: no register authCallback for this package");
return;
}
std::map<std::string, std::shared_ptr<AuthenticateCallback>> &authCallMap = authenticateCallback_[pkgName];
auto iter = authCallMap.find(deviceId);
if (iter == authCallMap.end()) {
LOGE("DeviceManager OnAuthResult: no register authCallback for deviceID ");
return;
}
iter->second->OnAuthResult(deviceId, token, status, reason);
authenticateCallback_[pkgName].erase(deviceId);
if (authenticateCallback_[pkgName].empty()) {
authenticateCallback_.erase(pkgName);
}
}
void DeviceManagerNotify::OnVerifyAuthResult(const std::string &pkgName, const std::string &deviceId,
int32_t resultCode, int32_t flag)
{
LOGI("DeviceManagerNotify::OnCheckAuthResult pkgName:%s, resultCode:%d, flag:%d", pkgName.c_str(), resultCode,
flag);
if (verifyAuthCallback_.count(pkgName) == 0) {
LOGE("DeviceManager OnCheckAuthResult: no register authCallback for this package");
return;
}
verifyAuthCallback_[pkgName]->OnVerifyAuthResult(deviceId, resultCode, flag);
verifyAuthCallback_.erase(pkgName);
}
void DeviceManagerNotify::OnFaCall(std::string &pkgName, std::string &paramJson)
{
LOGI("DeviceManager OnFaCallback pkgName:%s", pkgName.c_str());
if (dmFaCallback_.count(pkgName) == 0) {
LOGE("DeviceManager DmFaCallback not register");
return;
}
dmFaCallback_[pkgName]->OnCall(paramJson);
}
} // namespace DistributedHardware
} // namespace OHOS
+56
View File
@@ -0,0 +1,56 @@
# Copyright (C) 2021 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.
if (defined(ohos_lite)) {
import("//build/lite/config/component/lite_component.gni")
} else {
import("//build/ohos.gni")
}
import("//foundation/distributedhardware/devicemanager/devicemanager.gni")
innerkits_path_mini = "${devicemanager_path}/interfaces/inner_kits"
kits_path = "${devicemanager_path}/interfaces/kits"
if (ohos_kernel_type == "liteos_m") {
static_library("devicemanager_native_js") {
include_dirs = [
"//third_party/node/src",
"//third_party/json/include",
"${common_path}/include",
"//utils/native/base/include",
"${kits_path}/js_mini/include",
"${utils_path}/include",
"//foundation/ace/ace_engine_lite/interfaces/innerkits/builtin/base",
"//foundation/ace/ace_engine_lite/interfaces/innerkits/builtin/jsi",
"//foundation/ace/ace_engine_lite/interfaces/innerkits/builtin/async",
"//foundation/ace/ace_engine_lite/frameworks/include/context",
"${innerkits_path_mini}/native_cpp/include",
]
sources = [
"${kits_path}/js_mini/src/dm_native_event.cpp",
"${kits_path}/js_mini/src/native_devicemanager_js.cpp",
]
deps = [
"${innerkits_path_mini}/native_cpp:devicemanagersdk_mini",
"${utils_path}:devicemanagerutils_mini",
]
defines = [
"HI_LOG_ENABLE",
"DH_LOG_TAG=\"devicemanagerkit_js\"",
"LOG_DOMAIN=0xD004100",
]
}
}
@@ -0,0 +1,54 @@
/*
* Copyright (c) 2021 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_DEVICE_MANAGER_NATIVE_EVENT_H
#define OHOS_DEVICE_MANAGER_NATIVE_EVENT_H
#include <map>
#include <memory>
#include <string>
#include "jsi.h"
#include "dm_device_info.h"
namespace OHOS {
namespace ACELite {
struct DmEventListener {
std::string eventType;
JSIValue handlerRef = JSI::CreateUndefined();
JSIValue thisVarRef_ = JSI::CreateUndefined();
};
struct FuncParams {
JSIValue handlerRef = JSI::CreateUndefined();
JSIValue thisVarRef_ = JSI::CreateUndefined();
const JSIValue *args = nullptr;
uint8_t argsSize = 0;
};
class DmNativeEvent {
public:
DmNativeEvent();
DmNativeEvent(JSIValue thisVar);
virtual ~DmNativeEvent();
virtual void On(std::string &eventType, JSIValue handler, JSIValue thisVal);
virtual void Off(std::string &eventType);
virtual void OnEvent(const std::string &eventType, uint8_t argsSize, const JSIValue *data);
static void OnEventAsyncWorkFunc(void *data);
protected:
static std::map<std::string, std::shared_ptr<DmEventListener>> eventMap_;
};
}
}
#endif /* OHOS_DEVICE_MANAGER_NATIVE_EVENT_H */
@@ -0,0 +1,188 @@
/*
* Copyright (c) 2021 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_DEVICE_MANAGER_NATIVE_DEVICEMANAGER_JS_H
#define OHOS_DEVICE_MANAGER_NATIVE_DEVICEMANAGER_JS_H
#include <memory>
#include <string>
#include <pthread.h>
#include "device_manager_callback.h"
#include "dm_native_event.h"
#include "dm_device_info.h"
#include "dm_subscribe_info.h"
#include "nlohmann/json.hpp"
#include "dm_device_info.h"
#include "jsi.h"
#include "js_ability.h"
#include "dm_app_image_info.h"
namespace OHOS {
namespace ACELite {
#define DM_JSI_BUF_LENGTH (256)
#define DM_JSI_AUTH_REQUEST_FINISH (8)
struct AuthFuncParams {
JSIValue handlerRef = JSI::CreateUndefined();
JSIValue thisVarRef_ = JSI::CreateUndefined();
const JSIValue *args = nullptr;
uint8_t argsSize = 0;
};
struct AuthAsyncCallbackInfo {
JSIValue thisVal_ = JSI::CreateUndefined();
char bundleName[DM_JSI_BUF_LENGTH] = {0};
JSIValue callback = JSI::CreateUndefined();
int32_t authType = -1;
};
enum DmJSIDevStateChangeAction {
ONLINE = 0,
READY = 1,
OFFLINE = 2,
CHANGE = 3
};
class DmJSIInitCallback : public OHOS::DistributedHardware::DmInitCallback {
public:
explicit DmJSIInitCallback(std::string &bundleName) : bundleName_(bundleName) {}
virtual ~DmJSIInitCallback() {}
void OnRemoteDied() override;
private:
std::string bundleName_;
};
class DmJSIDeviceStateCallback : public OHOS::DistributedHardware::DeviceStateCallback {
public:
explicit DmJSIDeviceStateCallback(std::string &bundleName) : bundleName_(bundleName) {}
virtual ~DmJSIDeviceStateCallback() {};
void OnDeviceOnline(const OHOS::DistributedHardware::DmDeviceInfo &deviceInfo) override;
void OnDeviceReady(const OHOS::DistributedHardware::DmDeviceInfo &deviceInfo) override;
void OnDeviceOffline(const OHOS::DistributedHardware::DmDeviceInfo &deviceInfo) override;
void OnDeviceChanged(const OHOS::DistributedHardware::DmDeviceInfo &deviceInfo) override;
private:
std::string bundleName_;
};
class DmJSIDiscoverCallback : public OHOS::DistributedHardware::DiscoveryCallback {
public:
explicit DmJSIDiscoverCallback(std::string &bundleName) : refCount_(0), bundleName_(bundleName) {}
virtual ~DmJSIDiscoverCallback() {};
void OnDeviceFound(uint16_t subscribeId, const OHOS::DistributedHardware::DmDeviceInfo &deviceInfo) override;
void OnDiscoveryFailed(uint16_t subscribeId, int32_t failedReason) override;
void OnDiscoverySuccess(uint16_t subscribeId) override;
void IncreaseRefCount();
void DecreaseRefCount();
int32_t GetRefCount();
private:
int32_t refCount_ = 0;
pthread_mutex_t lock_;
std::string bundleName_;
};
class DmJSIAuthenticateCallback : public OHOS::DistributedHardware::AuthenticateCallback {
public:
explicit DmJSIAuthenticateCallback(std::string &bundleName) : bundleName_(bundleName) {}
virtual ~DmJSIAuthenticateCallback() {};
void OnAuthResult(const std::string &deviceId, const std::string &token, int32_t status, int32_t reason) override;
private:
std::string bundleName_;
};
class DmJSICheckAuthCallback : public OHOS::DistributedHardware::VerifyAuthCallback {
public:
explicit DmJSICheckAuthCallback(std::string &bundleName) : bundleName_(bundleName) {}
virtual ~DmJSICheckAuthCallback() {};
void OnVerifyAuthResult(const std::string &deviceId, int32_t resultCode, int32_t flag) override;
private:
std::string bundleName_;
};
class DmJSIDeviceManagerFaCallback : public OHOS::DistributedHardware::DeviceManagerFaCallback {
public:
explicit DmJSIDeviceManagerFaCallback(std::string &bundleName) : bundleName_(bundleName) {}
virtual ~DmJSIDeviceManagerFaCallback() {};
void OnCall(const std::string &paramJson) override;
private:
std::string bundleName_;
};
class DeviceManagerModule final : public MemoryHeap, DmNativeEvent {
public:
explicit DeviceManagerModule();
virtual ~DeviceManagerModule();
static JSIValue CreateDeviceManager(const JSIValue thisVal, const JSIValue *args, uint8_t argsSize);
static JSIValue ReleaseDeviceManager(const JSIValue thisVal, const JSIValue *args, uint8_t argsSize);
static JSIValue GetTrustedDeviceListSync(const JSIValue thisVal, const JSIValue *args, uint8_t argsSize);
static JSIValue StartDeviceDiscoverSync(const JSIValue thisVal, const JSIValue *args, uint8_t argsSize);
static JSIValue StopDeviceDiscoverSync(const JSIValue thisVal, const JSIValue *args, uint8_t argsSize);
static JSIValue AuthenticateDevice(const JSIValue thisVal, const JSIValue *args, uint8_t argsSize);
static JSIValue VerifyAuthInfo(const JSIValue thisVal, const JSIValue *args, uint8_t argsSize);
static JSIValue JsOn(const JSIValue thisVal, const JSIValue *args, uint8_t argsSize);
static JSIValue JsOff(const JSIValue thisVal, const JSIValue *args, uint8_t argsSize);
static JSIValue SetUserOperationSync(const JSIValue thisVal, const JSIValue *args, uint8_t argsSize);
static JSIValue GetAuthenticationParamSync(const JSIValue thisVal, const JSIValue *args, uint8_t argsSize);
static JSIValue GetLocalDeviceInfoSync(const JSIValue thisVal, const JSIValue *args, uint8_t argsSize);
static JSIValue UnAuthenticateDevice(const JSIValue thisVal, const JSIValue *args, uint8_t argsSize);
static DeviceManagerModule *GetDeviceManagerJSI(std::string &bundleName);
static void AuthRsultVerifyInfoAsyncWorkFunc(void *data);
static char *GetJSIAppBundleName();
static void DmAuthParamToJsAuthParamy(const OHOS::DistributedHardware::DmAuthParam &authParam,
JSIValue &paramResult);
void OnDmfaCall(const std::string &paramJson);
void OnVerifyResult(const std::string &deviceId, int32_t resultCode, int32_t flag);
void OnAuthResult(const std::string &deviceId, const std::string &token, int32_t status, int32_t reason);
void OnDiscoverFailed(uint16_t subscribeId, int32_t failedReason);
void OnDeviceFound(uint16_t subscribeId, const OHOS::DistributedHardware::DmDeviceInfo &deviceInfo);
void OnDeviceStateChange(DmJSIDevStateChangeAction action,
const OHOS::DistributedHardware::DmDeviceInfo &deviceInfo);
void OnRemoteDied();
static void JsToDmAuthExtra(const JSIValue &param, nlohmann::json &jsonObj);
static void JsToDmTokenInfo(const JSIValue &object, const std::string &fieldStr, nlohmann::json &jsonObj);
static void JsToJsonObject(const JSIValue &object, const std::string &fieldStr, nlohmann::json &jsonObj);
static void JsToDmBuffer(const JSIValue &object,
const std::string &fieldStr, uint8_t **bufferPtr, int32_t &bufferLen);
static void JsToDmAuthInfo(const JSIValue &object, std::string &extra);
static void JsToDmAppImageInfoAndDmExtra(const JSIValue &object,
OHOS::DistributedHardware::DmAppImageInfo& appImageInfo,
std::string &extra, int32_t &authType);
static void JsToDmDeviceInfo(const JSIValue &object, OHOS::DistributedHardware::DmDeviceInfo& info);
static int32_t JsToDmSubscribeInfo(const JSIValue &object, OHOS::DistributedHardware::DmSubscribeInfo& info);
static char *JsObjectToString(const JSIValue &object, const std::string &fieldStr);
static bool JsObjectToBool(const JSIValue &object, const std::string &fieldStr);
static int32_t JsObjectToInt(const JSIValue &object, const std::string &fieldStr);
static void DmAuthParamToJsAuthParam(const OHOS::DistributedHardware::DmAuthParam &authParam,
JSIValue &paramResult);
static void CreateDmCallback(std::string &bundleName, std::string &eventType);
static void ReleaseDmCallback(std::string &bundleName, std::string &eventType);
static void DeviceInfoToJsArray(const std::vector<OHOS::DistributedHardware::DmDeviceInfo> &vecDevInfo,
const int32_t idx, JSIValue &arrayResult);
private:
std::string bundleName_;
static AuthAsyncCallbackInfo authAsyncCallbackInfo_;
static AuthAsyncCallbackInfo verifyAsyncCallbackInfo_;
};
void InitDeviceManagerModule(JSIValue exports);
}
}
#endif // OHOS_DEVICE_MANAGER_NATIVE_DEVICEMANAGER_JS_H
@@ -0,0 +1,102 @@
/*
* Copyright (c) 2021 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 "dm_native_event.h"
#include "jsi.h"
#include "dm_log.h"
#include "js_async_work.h"
using namespace OHOS::DistributedHardware;
using namespace std;
namespace OHOS {
namespace ACELite {
std::map<std::string, std::shared_ptr<DmEventListener>> DmNativeEvent::eventMap_;
DmNativeEvent::DmNativeEvent()
{
LOGI("DmNativeEvent::DmNativeEvent() in");
}
DmNativeEvent::DmNativeEvent(JSIValue thisVar)
{
LOGI("DmNativeEvent::DmNativeEvent(JSIValue thisVar) in");
}
DmNativeEvent::~DmNativeEvent()
{
LOGI("DmNativeEvent::~DmNativeEvent() in");
}
void DmNativeEvent::On(std::string &eventType, JSIValue handle, JSIValue thisVal)
{
LOGI("DmNativeEvent On in for event: %s", eventType.c_str());
std::shared_ptr<DmEventListener> listener= std::make_shared<DmEventListener>();
listener->eventType = eventType;
listener->handlerRef = JSI::AcquireValue(handle);
listener->thisVarRef_ = JSI::AcquireValue(thisVal);
eventMap_[eventType] = listener;
}
void DmNativeEvent::Off(std::string &eventType)
{
LOGI("DmNativeEvent Off in for event: %s", eventType.c_str());
auto iter = eventMap_.find(eventType);
if (iter == eventMap_.end()) {
LOGE("eventType %s not find", eventType.c_str());
return;
}
std::shared_ptr<DmEventListener> listener = iter->second;
JSI::ReleaseValue(listener->handlerRef);
JSI::ReleaseValue(listener->thisVarRef_);
eventMap_.erase(eventType);
}
void DmNativeEvent::OnEvent(const std::string &eventType, uint8_t argsSize, const JSIValue *data)
{
LOGI("OnEvent for %s", eventType.c_str());
auto iter = eventMap_.find(eventType);
if (iter == eventMap_.end()) {
LOGE("eventType %s not find", eventType.c_str());
return;
}
auto listener = iter->second;
if (!JSI::ValueIsFunction(listener->handlerRef)) {
LOGI("OnEvent for %s handlerRef is null", eventType.c_str());
return;
}
FuncParams* params = new FuncParams();
params->handlerRef = listener->handlerRef;
params->thisVarRef_ = listener->thisVarRef_;
params->args = data;
params->argsSize = argsSize;
LOGI("OnEventAsyncWorkFunc for %s in", eventType.c_str());
JsAsyncWork::DispatchAsyncWork(OnEventAsyncWorkFunc, reinterpret_cast<void *>(params));
}
void DmNativeEvent::OnEventAsyncWorkFunc(void *data)
{
LOGI("OnEventAsyncWorkFunc in ");
FuncParams* params = reinterpret_cast<FuncParams *>(data);
JSI::CallFunction(params->handlerRef, params->thisVarRef_, params->args, params->argsSize);
}
}
}
File diff suppressed because it is too large Load Diff
+102 -2
View File
@@ -20,8 +20,108 @@ if (defined(ohos_lite)) {
import("//foundation/distributedhardware/devicemanager/devicemanager.gni")
if (defined(ohos_lite)) {
executable("devicemanagerservice") {
sources = [ "src/ipc/lite/ipc_server_main.cpp" ]
if (ohos_kernel_type == "liteos_m") {
static_library("devicemanagerservice_mini") {
include_dirs = [
"${devicemanager_path}/interfaces/inner_kits/native_cpp/include",
"${devicemanager_path}/interfaces/inner_kits/native_cpp/include/notify",
"${services_path}/include",
"${services_path}/include/config",
"${services_path}/include/adapter",
"${services_path}/include/authentication",
"${services_path}/include/ability",
"${services_path}/include/deviceinfo",
"${services_path}/include/devicestate",
"${services_path}/include/discovery",
"${services_path}/include/dependency/commonevent",
"${services_path}/include/dependency/multipleuser",
"${services_path}/include/dependency/hichain",
"${services_path}/include/dependency/softbus",
"${services_path}/include/dependency/mini",
"${services_path}/include/dependency/timer",
"${services_path}/include/eventbus",
"${common_path}/include",
"//base/security/deviceauth/interfaces/innerkits",
"//third_party/json/include",
"//base/account/os_account/interfaces/innerkits/osaccount/native/include",
"${utils_path}/include",
"${utils_path}/include/permission/lite",
"foundation/multimedia/image_standard/mock/native/include",
"${services_path}/include/dispatch",
"${ext_path}/pin_auth/include",
]
include_dirs += [
"//base/security/deviceauth/interfaces/innerkits",
"//base/startup/syspara_lite/interfaces/innerkits/native/syspara/include",
"//utils/native/lite/include",
"//utils/system/safwk/native/include",
"//third_party/json/include",
"//base/hiviewdfx/hilog_lite/interfaces/native/innerkits/hilog",
"//third_party/bounds_checking_function/include",
"//foundation/communication/ipc_lite/interfaces/kits",
"//foundation/communication/dsoftbus/interfaces/kits/bus_center",
"//foundation/communication/dsoftbus/interfaces/kits/common",
"//foundation/communication/dsoftbus/interfaces/kits/discovery",
"//foundation/communication/dsoftbus/interfaces/kits/transport",
"//foundation/communication/dsoftbus/interfaces/inner_kits/transport",
"//foundation/distributedhardware/devicemanager/services/devicemanagerservice/include/dependency/multipleuser",
"//foundation/distributedschedule/samgr_lite/interfaces/kits/samgr",
"//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy/include",
]
sources = [
"${services_path}/src/ability/lite/dm_ability_manager.cpp",
"${services_path}/src/adapter/standard/dm_adapter_manager.cpp",
"${services_path}/src/authentication/auth_message_processor.cpp",
"${services_path}/src/authentication/auth_request_state.cpp",
"${services_path}/src/authentication/auth_response_state.cpp",
"${services_path}/src/authentication/auth_ui.cpp",
"${services_path}/src/authentication/dm_auth_manager.cpp",
"${services_path}/src/config/mini/dm_config_manager.cpp",
"${services_path}/src/config/mini/pin_auth.cpp",
"${services_path}/src/dependency/hichain/hichain_connector.cpp",
"${services_path}/src/dependency/mini/dm_mutex.cpp",
"${services_path}/src/dependency/mini/dm_thread.cpp",
"${services_path}/src/dependency/multipleuser/multiple_user_connector.cpp",
"${services_path}/src/dependency/softbus/softbus_connector.cpp",
"${services_path}/src/dependency/softbus/softbus_session.cpp",
"${services_path}/src/dependency/timer/mini/dm_timer.cpp",
"${services_path}/src/device_manager_service.cpp",
"${services_path}/src/deviceinfo/dm_device_info_manager.cpp",
"${services_path}/src/devicestate/dm_device_state_manager.cpp",
"${services_path}/src/discovery/dm_discovery_manager.cpp",
"${services_path}/src/dispatch/command_dispatch.cpp",
"${services_path}/src/dispatch/device_manager_service_listener_mini.cpp",
"${services_path}/src/dispatch/server_stub.cpp",
]
defines = [
"LITE_DEVICE",
"HI_LOG_ENABLE",
"DH_LOG_TAG=\"devicemanagerservice\"",
"LOG_DOMAIN=0xD004100",
]
ldflags = dm_ldflags
deps = [
"${devicemanager_path}/interfaces/inner_kits/native_cpp:devicemanagersdk_mini",
"${utils_path}:devicemanagerutils_mini",
"//base/hiviewdfx/hilog_lite/frameworks/featured:hilog_static",
"//base/security/deviceauth/services:deviceauth",
"//base/startup/syspara_lite/frameworks/parameter/src:sysparam",
"//foundation/communication/dsoftbus/sdk:softbus_client",
"//foundation/distributedschedule/samgr_lite/samgr",
"//third_party/bounds_checking_function:libsec_static",
"//third_party/mbedtls",
"//utils/native/lite:utils",
]
}
} else {
executable("devicemanagerservice") {
sources = [ "src/ipc/lite/ipc_server_main.cpp" ]
}
}
} else if (!support_jsapi) {
group("devicemanagerservice") {
@@ -17,7 +17,7 @@
#define OHOS_DM_AUTH_UI_H
#include <cstdint>
#include <memory>
#include "dm_ability_manager.h"
namespace OHOS {
@@ -19,7 +19,9 @@
#include <cstdlib>
#include <map>
#include <memory>
#if !defined(__LITEOS_M__)
#include <mutex>
#endif
#include <set>
#include <string>
#include <vector>
@@ -66,10 +68,12 @@ private:
DmConfigManager();
private:
#if !defined(__LITEOS_M__)
std::mutex authAdapterMutex_;
std::mutex cryptoAdapterMutex_;
std::mutex decisionAdapterMutex_;
std::mutex profileAdapterMutex_;
#endif
std::map<int32_t, AuthSoLoadInfo> soAuthLoadInfo_;
std::map<std::string, AdapterSoLoadInfo> soAdapterLoadInfo_;
std::map<std::string, std::shared_ptr<IDecisionAdapter>> decisionAdapterPtr_;
@@ -46,9 +46,9 @@ void from_json(const nlohmann::json &jsonObject, GroupInfo &groupInfo);
class HiChainConnector {
public:
static bool onTransmit(int64_t requestId, const uint8_t *data, uint32_t dataLen);
static void onFinish(int64_t requestId, int32_t operationCode, const char *returnData);
static void onError(int64_t requestId, int32_t operationCode, int32_t errorCode, const char *errorReturn);
static char *onRequest(int64_t requestId, int32_t operationCode, const char *reqParams);
static void onFinish(int64_t requestId, int operationCode, const char *returnData);
static void onError(int64_t requestId, int operationCode, int errorCode, const char *errorReturn);
static char *onRequest(int64_t requestId, int operationCode, const char *reqParams);
public:
HiChainConnector();
@@ -0,0 +1,32 @@
/*
* Copyright (c) 2021 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_MUTEX_H
#define OHOS_DM_MUTEX_H
#include <pthread.h>
namespace OHOS {
namespace DistributedHardware {
class DmMutex {
public:
DmMutex();
~DmMutex();
private:
pthread_mutex_t lock_;
};
} // namespace DistributedHardware
} // namespace OHOS
#endif // OHOS_DM_MUTEX_H
@@ -0,0 +1,49 @@
/*
* Copyright (c) 2021 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_THREAD_H
#define OHOS_DM_THREAD_H
#include <pthread.h>
#include <map>
#include <string>
#include<memory>
#include "dm_device_info.h"
#include "softbus_state_callback.h"
namespace OHOS {
namespace DistributedHardware {
class DmThread {
using funcstr = void (*)(std::map<std::string, std::shared_ptr<ISoftbusStateCallback>>, DmDeviceInfo);
public:
DmThread(funcstr funcname,\
std::map<std::string, std::shared_ptr<ISoftbusStateCallback>> parameter1,\
DmDeviceInfo parameter2);
static void* PthreadDeviceStart(void* parameterInfo);
void DmCreatThread();
private:
struct PthreadCallbackParameter {
std::map<std::string, std::shared_ptr<ISoftbusStateCallback>> member1;
DmDeviceInfo member2;
};
static funcstr funcName_;
static std::map<std::string, std::shared_ptr<ISoftbusStateCallback>> parameter1_;
static DmDeviceInfo parameter2_;
PthreadCallbackParameter parameterGroup_;
};
} // namespace DistributedHardware
} // namespace OHOS
#endif // OHOS_DM_THREAD_H
@@ -34,14 +34,14 @@ namespace OHOS {
namespace DistributedHardware {
class SoftbusConnector {
public:
static void OnPublishSuccess(int32_t publishId);
static void OnPublishFail(int32_t publishId, PublishFailReason reason);
static void OnPublishSuccess(int publishId);
static void OnPublishFail(int publishId, PublishFailReason reason);
static void OnSoftBusDeviceOnline(NodeBasicInfo *info);
static void OnSoftbusDeviceOffline(NodeBasicInfo *info);
static void OnSoftbusDeviceInfoChanged(NodeBasicInfoType type, NodeBasicInfo *info);
static void OnSoftbusDeviceFound(const DeviceInfo *device);
static void OnSoftbusDiscoveryFailed(int32_t subscribeId, DiscoveryFailReason failReason);
static void OnSoftbusDiscoverySuccess(int32_t subscribeId);
static void OnSoftbusDiscoveryFailed(int subscribeId, DiscoveryFailReason failReason);
static void OnSoftbusDiscoverySuccess(int subscribeId);
static void OnParameterChgCallback(const char *key, const char *value, void *context);
static int32_t GetConnectionIpAddress(const std::string &deviceId, std::string &ipAddress);
static ConnectionAddr *GetConnectAddr(const std::string &deviceId, std::string &connectAddr);
@@ -30,9 +30,9 @@ namespace OHOS {
namespace DistributedHardware {
class SoftbusSession {
public:
static int32_t OnSessionOpened(int32_t sessionId, int32_t result);
static void OnSessionClosed(int32_t sessionId);
static void OnBytesReceived(int32_t sessionId, const void *data, uint32_t dataLen);
static int OnSessionOpened(int sessionId, int result);
static void OnSessionClosed(int sessionId);
static void OnBytesReceived(int sessionId, const void *data, unsigned int dataLen);
public:
SoftbusSession();
@@ -18,13 +18,14 @@
#include <errno.h>
#include <stdint.h>
#include <stdio.h>
#if !defined(__LITEOS_M__)
#include <sys/epoll.h>
#include <thread>
#include <unistd.h>
#endif
#include <cstdio>
#include <mutex>
#include <string>
#include <thread>
#include "dm_log.h"
@@ -62,10 +63,15 @@ private:
TimeoutHandle mHandle_;
void *mHandleData_;
int32_t mTimeFd_[2];
#if defined(__LITEOS_M__)
void *timerId = NULL;
#else
struct epoll_event mEv_;
struct epoll_event mEvents_[MAX_EVENTS];
int32_t mEpFd_;
std::thread mThread_;
#endif
std::string mTimerName_;
};
} // namespace DistributedHardware
@@ -20,8 +20,11 @@
#include <string>
#include "dm_device_info.h"
#if !defined(__LITEOS_M__)
#include "ipc_notify_dmfa_result_req.h"
#include "ipc_server_listener.h"
#endif
namespace OHOS {
namespace DistributedHardware {
@@ -38,7 +41,9 @@ public:
void OnFaCall(std::string &pkgName, std::string &paramJson);
private:
#if !defined(__LITEOS_M__)
IpcServerListener ipcServerListener_;
#endif
};
} // namespace DistributedHardware
} // namespace OHOS
@@ -18,8 +18,11 @@
#include <string>
#include <memory>
#if defined(__LITEOS_M__)
#include "dm_mutex.h"
#else
#include <mutex>
#endif
#include "device_manager_service_listener.h"
#include "dm_adapter_manager.h"
#include "softbus_connector.h"
@@ -61,8 +64,10 @@ public:
private:
std::string profileSoName_;
#if !defined(__LITEOS_M__)
std::mutex timerMapMutex_;
std::mutex remoteDeviceInfosMutex_;
#endif
std::shared_ptr<SoftbusConnector> softbusConnector_;
std::shared_ptr<DeviceManagerServiceListener> listener_;
std::map<std::string, DmDeviceInfo> remoteDeviceInfos_;
@@ -0,0 +1,65 @@
/*
* Copyright (c) 2021 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_DEVICE_MANAGER_AUTHENTICATE_DEVICE_REQ_H
#define OHOS_DEVICE_MANAGER_AUTHENTICATE_DEVICE_REQ_H
#include "message_req.h"
#include "dm_device_info.h"
#include "dm_app_image_info.h"
namespace OHOS {
namespace DistributedHardware {
class AuthenticateDeviceReq : public MessageReq {
DECLARE_MESSAGE_MODEL(AuthenticateDeviceReq);
public:
const DmDeviceInfo& GetDeviceInfo() const
{
return deviceInfo_;
}
void SetDeviceInfo(const DmDeviceInfo &deviceInfo)
{
deviceInfo_ = deviceInfo;
}
int32_t GetAuthType()
{
return authType_;
}
void SetAuthType(int32_t authType)
{
authType_ = authType;
}
const std::string& GetExtra() const
{
return extra_;
}
void SetExtra(const std::string &extra)
{
extra_ = extra;
}
private:
DmDeviceInfo deviceInfo_;
int32_t authType_;
std::string extra_;
};
} // namespace DistributedHardware
} // namespace OHOS
#endif // OHOS_DEVICE_MANAGER_AUTHENTICATE_DEVICE_REQ_H
@@ -0,0 +1,74 @@
/*
* Copyright (c) 2020 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_DEVICE_MANAGER_COMMAND_DISPATCH_H
#define OHOS_DEVICE_MANAGER_COMMAND_DISPATCH_H
#include <cstdint>
#include <string>
#include <memory>
#include <list>
#include "single_instance.h"
#include "message_req.h"
#include "message_rsp.h"
namespace OHOS {
namespace DistributedHardware {
#define DEVICEMANAGER_MESSAGE_FAILED (-1)
static int32_t GetTrustedDeviceList(const std::shared_ptr<MessageReq> &req, const std::shared_ptr<MessageRsp> &rsp);
static int32_t GetLocalDeviceInfo(const std::shared_ptr<MessageReq> &req, const std::shared_ptr<MessageRsp> &rsp);
static int32_t GetUdidByNetworkId(const std::shared_ptr<MessageReq> &req, const std::shared_ptr<MessageRsp> &rsp);
static int32_t GetUuidByNetworkId(const std::shared_ptr<MessageReq> &req, const std::shared_ptr<MessageRsp> &rsp);
static int32_t StartDeviceDiscovery(const std::shared_ptr<MessageReq> &req, const std::shared_ptr<MessageRsp> &rsp);
static int32_t StopDeviceDiscovery(const std::shared_ptr<MessageReq> &req, const std::shared_ptr<MessageRsp> &rsp);
static int32_t SetUserOperation(const std::shared_ptr<MessageReq> &req, const std::shared_ptr<MessageRsp> &rsp);
static int32_t GetFaParam(const std::shared_ptr<MessageReq> &req, const std::shared_ptr<MessageRsp> &rsp);
static int32_t AuthenticateDevice(const std::shared_ptr<MessageReq> &req, const std::shared_ptr<MessageRsp> &rsp);
static int32_t UnAuthenticateDevice(const std::shared_ptr<MessageReq> &req, const std::shared_ptr<MessageRsp> &rsp);
static int32_t VerifyAuthentication(const std::shared_ptr<MessageReq> &req, const std::shared_ptr<MessageRsp> &rsp);
typedef struct {
int32_t cmdCode;
int32_t (*MsgProcess) (const std::shared_ptr<MessageReq> &req, const std::shared_ptr<MessageRsp> &rsp);
} CmdMap;
static const CmdMap g_cmdMap[] = {
{GET_TRUST_DEVICE_LIST, GetTrustedDeviceList},
{GET_LOCAL_DEVICE_INFO, GetLocalDeviceInfo},
{GET_UDID_BY_NETWORK, GetUdidByNetworkId},
{GET_UUID_BY_NETWORK, GetUuidByNetworkId},
{START_DEVICE_DISCOVER, StartDeviceDiscovery},
{STOP_DEVICE_DISCOVER, StopDeviceDiscovery},
{SERVER_USER_AUTH_OPERATION, SetUserOperation},
{SERVER_GET_DMFA_INFO, GetFaParam},
{AUTHENTICATE_DEVICE, AuthenticateDevice},
{UNAUTHENTICATE_DEVICE, UnAuthenticateDevice},
{VERIFY_AUTHENTICATION, VerifyAuthentication},
};
class CommandDispatch {
DECLARE_SINGLE_INSTANCE(CommandDispatch);
public:
int32_t MessageSendCmd(int32_t cmdCode, const std::shared_ptr<MessageReq> &req,
const std::shared_ptr<MessageRsp> &rsp);
void AddPkgName(const std::string &pkgName);
void DeletePkgName(const std::string &pkgName);
const std::list<std::string>& GetPkgNameList() const;
private:
std::list<std::string> dmPkgName_;
};
} // namespace DistributedHardware
} // namespace OHOS
#endif // OHOS_DEVICE_MANAGER_COMMAND_DISPATCH_H
@@ -0,0 +1,43 @@
/*
* Copyright (c) 2021 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_DEVICE_MANAGER_GET_DM_FA_PARAM_RSP_H
#define OHOS_DEVICE_MANAGER_GET_DM_FA_PARAM_RSP_H
#include "dm_device_info.h"
#include "message_rsp.h"
namespace OHOS {
namespace DistributedHardware {
class GetDmFaParamRsp : public MessageRsp {
DECLARE_MESSAGE_MODEL(GetDmFaParamRsp);
public:
const DmAuthParam GetDmAuthParam() const
{
return dmFaParam_;
}
void SetDmAuthParam(const DmAuthParam &dmFaParam)
{
dmFaParam_ = dmFaParam;
}
private:
DmAuthParam dmFaParam_;
};
} // namespace DistributedHardware
} // namespace OHOS
#endif // OHOS_DEVICE_MANAGER_GET_DM_FA_PARAM_RSP_H
@@ -0,0 +1,42 @@
/*
* Copyright (c) 2021 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_DEVICE_MANAGER_GET_INFO_BY_NETWORK_REQ_H
#define OHOS_DEVICE_MANAGER_GET_INFO_BY_NETWORK_REQ_H
#include "message_req.h"
namespace OHOS {
namespace DistributedHardware {
class GetInfoByNetWorkReq : public MessageReq {
DECLARE_MESSAGE_MODEL(GetInfoByNetWorkReq);
public:
const std::string GetNetWorkId() const
{
return netWorkId_;
}
void SetNetWorkId(const std::string &netWorkId)
{
netWorkId_ = netWorkId;
}
private:
std::string netWorkId_;
};
} // namespace DistributedHardware
} // namespace OHOS
#endif // OHOS_DEVICE_MANAGER_GET_INFO_BY_NETWORK_REQ_H
@@ -0,0 +1,54 @@
/*
* Copyright (c) 2021 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_DEVICE_MANAGER_GET_INFO_BY_NETWORK_RSP_H
#define OHOS_DEVICE_MANAGER_GET_INFO_BY_NETWORK_RSP_H
#include <string>
#include "message_rsp.h"
namespace OHOS {
namespace DistributedHardware {
class GetInfoByNetWorkRsp : public MessageRsp {
DECLARE_MESSAGE_MODEL(GetInfoByNetWorkRsp);
public:
const std::string GetUdid() const
{
return udid_;
}
void SetUdid(const std::string &udid)
{
udid_ = udid;
}
const std::string GetUuid() const
{
return uuid_;
}
void SetUuid(const std::string &uuid)
{
uuid_ = uuid;
}
private:
std::string udid_;
std::string uuid_;
};
} // namespace DistributedHardware
} // namespace OHOS
#endif // OHOS_DEVICE_MANAGER_GET_INFO_BY_NETWORK_RSP_H
@@ -0,0 +1,43 @@
/*
* Copyright (c) 2021 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_DEVICE_MANAGER_GET_LOCAL_DEVICE_INFO_RSP_H
#define OHOS_DEVICE_MANAGER_GET_LOCAL_DEVICE_INFO_RSP_H
#include "dm_device_info.h"
#include "message_rsp.h"
namespace OHOS {
namespace DistributedHardware {
class GetLocalDeviceInfoRsp : public MessageRsp {
DECLARE_MESSAGE_MODEL(GetLocalDeviceInfoRsp);
public:
const DmDeviceInfo &GetLocalDeviceInfo() const
{
return localDeviceInfo_;
}
void SetLocalDeviceInfo(DmDeviceInfo &localDeviceInfo)
{
localDeviceInfo_ = localDeviceInfo;
}
private:
DmDeviceInfo localDeviceInfo_;
};
} // namespace DistributedHardware
} // namespace OHOS
#endif // OHOS_DEVICE_MANAGER_GET_LOCAL_DEVICE_INFO_RSP_H
@@ -0,0 +1,40 @@
/*
* Copyright (c) 2021 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_DEVICE_MANAGER_GET_TRUST_DEVICE_REQ_H
#define OHOS_DEVICE_MANAGER_GET_TRUST_DEVICE_REQ_H
#include "message_req.h"
namespace OHOS {
namespace DistributedHardware {
class GetTrustDeviceReq : public MessageReq {
DECLARE_MESSAGE_MODEL(GetTrustDeviceReq);
public:
const std::string& GetExtra() const
{
return extra_;
}
void SetExtra(const std::string &extra)
{
extra_ = extra;
}
private:
std::string extra_;
};
} // namespace DistributedHardware
} // namespace OHOS
#endif // OHOS_DEVICE_MANAGER_GET_TRUST_DEVICE_REQ_H
@@ -0,0 +1,44 @@
/*
* Copyright (c) 2021 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_DEVICE_MANAGER_GET_TRUSTDEVICE_RSP_H
#define OHOS_DEVICE_MANAGER_GET_TRUSTDEVICE_RSP_H
#include <vector>
#include "dm_device_info.h"
#include "message_rsp.h"
namespace OHOS {
namespace DistributedHardware {
class GetTrustDeviceRsp : public MessageRsp {
DECLARE_MESSAGE_MODEL(GetTrustDeviceRsp);
public:
std::vector<DmDeviceInfo> GetDeviceVec() const
{
return deviceVec_;
}
void SetDeviceVec(std::vector<DmDeviceInfo>& deviceVec)
{
deviceVec_ = deviceVec;
}
private:
std::vector<DmDeviceInfo> deviceVec_;
};
} // namespace DistributedHardware
} // namespace OHOS
#endif // OHOS_DEVICE_MANAGER_GET_TRUSTDEVICE_RSP_H
@@ -0,0 +1,41 @@
/*
* Copyright (c) 2021 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_DEVICE_MANAGER_GET_USER_OPERATION_REQ_H
#define OHOS_DEVICE_MANAGER_GET_USER_OPERATION_REQ_H
#include "message_req.h"
#include "dm_device_info.h"
namespace OHOS {
namespace DistributedHardware {
class GetUserOperationReq : public MessageReq {
DECLARE_MESSAGE_MODEL(GetUserOperationReq);
public:
int32_t GetOperation() const
{
return action_;
}
void SetOperation(int32_t action)
{
action_ = action;
}
private:
int32_t action_ {0};
};
} // namespace DistributedHardware
} // namespace OHOS
#endif // OHOS_DEVICE_MANAGER_GET_USER_OPERATION_REQ_H
@@ -0,0 +1,60 @@
/*
* Copyright (c) 2021 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 DEVICE_MANAGER_MESSAGE_DEF_H
#define DEVICE_MANAGER_MESSAGE_DEF_H
namespace OHOS {
namespace DistributedHardware {
#define DEVICE_MANAGER_SERVICE_NAME "dev_mgr_svc"
#define MAX_DM_IPC_LEN 2048
#define DECLARE_MESSAGE_MODEL(className) \
public: \
className() = default; \
virtual ~className() = default; \
\
public: \
className(const className &) = delete; \
className &operator=(const className &) = delete; \
className(className &&) = delete; \
className &operator=(className &&) = delete
#define DECLARE_MESSAGE_INTERFACE(className) DECLARE_MESSAGE_MODEL(className)
enum DispatchCmdID {
REGISTER_DEVICE_MANAGER_LISTENER = 0,
UNREGISTER_DEVICE_MANAGER_LISTENER,
GET_TRUST_DEVICE_LIST,
GET_LOCAL_DEVICE_INFO,
GET_UDID_BY_NETWORK,
GET_UUID_BY_NETWORK,
START_DEVICE_DISCOVER,
STOP_DEVICE_DISCOVER,
AUTHENTICATE_DEVICE,
UNAUTHENTICATE_DEVICE,
VERIFY_AUTHENTICATION,
SERVER_DEVICE_STATE_NOTIFY,
SERVER_DEVICE_FOUND,
SERVER_DISCOVER_FINISH,
SERVER_AUTH_RESULT,
SERVER_VERIFY_AUTH_RESULT,
SERVER_GET_DMFA_INFO,
SERVER_USER_AUTH_OPERATION,
SERVER_DEVICE_FA_NOTIFY,
};
} // namespace DistributedHardware
} // namespace OHOS
#endif // DEVICE_MANAGER_MESSAGE_DEF_H
@@ -0,0 +1,42 @@
/*
* Copyright (c) 2021 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_DEVICE_MANAGER_MESSAGE_REQ_H
#define OHOS_DEVICE_MANAGER_MESSAGE_REQ_H
#include <string>
#include "message_def.h"
namespace OHOS {
namespace DistributedHardware {
class MessageReq {
DECLARE_MESSAGE_MODEL(MessageReq);
public:
const std::string& GetPkgName() const
{
return pkgName_;
}
void SetPkgName(const std::string &pkgName)
{
pkgName_ = pkgName;
}
private:
std::string pkgName_;
};
} // namespace DistributedHardware
} // namespace OHOS
#endif // OHOS_DEVICE_MANAGER_MESSAGE_REQ_H
@@ -0,0 +1,40 @@
/*
* Copyright (c) 2021 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_DEVICE_MANAGER_MESSAGE_RSP_H
#define OHOS_DEVICE_MANAGER_MESSAGE_RSP_H
#include "message_def.h"
namespace OHOS {
namespace DistributedHardware {
class MessageRsp {
DECLARE_MESSAGE_MODEL(MessageRsp);
public:
int32_t GetErrCode() const
{
return errCode_;
}
void SetErrCode(int32_t errCode)
{
errCode_ = errCode;
}
private:
int32_t errCode_;
};
} // namespace DistributedHardware
} // namespace OHOS
#endif // OHOS_DEVICE_MANAGER_MESSAGE_RSP_H
@@ -0,0 +1,21 @@
/*
* Copyright (c) 2021 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_DEVICE_MANAGER_SERVER_STUB_H
#define OHOS_DEVICE_MANAGER_SERVER_STUB_H
#include <string>
#endif // OHOS_DEVICE_MANAGER_SERVER_STUB_H
@@ -0,0 +1,53 @@
/*
* Copyright (c) 2021 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_DEVICE_MANAGER_START_DISCOVERY_REQ_H
#define OHOS_DEVICE_MANAGER_START_DISCOVERY_REQ_H
#include "message_req.h"
#include "dm_subscribe_info.h"
namespace OHOS {
namespace DistributedHardware {
class StartDiscoveryReq : public MessageReq {
DECLARE_MESSAGE_MODEL(StartDiscoveryReq);
public:
const DmSubscribeInfo& GetSubscribeInfo() const
{
return subscribeInfo_;
}
void SetSubscribeInfo(const DmSubscribeInfo &subscribeInfo)
{
subscribeInfo_ = subscribeInfo;
}
const std::string &GetExtra() const
{
return extra_;
}
void SetExtra(const std::string &extra)
{
extra_ = extra;
}
private:
std::string extra_;
DmSubscribeInfo subscribeInfo_;
};
} // namespace DistributedHardware
} // namespace OHOS
#endif // OHOS_DEVICE_MANAGER_START_DISCOVERY_REQ_H
@@ -0,0 +1,40 @@
/*
* Copyright (c) 2021 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_DEVICE_MANAGER_STOP_DISCOVERY_REQ_H
#define OHOS_DEVICE_MANAGER_STOP_DISCOVERY_REQ_H
#include "message_req.h"
namespace OHOS {
namespace DistributedHardware {
class StopDiscoveryReq : public MessageReq {
DECLARE_MESSAGE_MODEL(StopDiscoveryReq);
public:
uint16_t GetSubscribeId() const
{
return subscribeId_;
}
void SetSubscribeId(uint16_t subscribeId)
{
subscribeId_ = subscribeId;
}
private:
uint16_t subscribeId_ {0};
};
} // namespace DistributedHardware
} // namespace OHOS
#endif // OHOS_DEVICE_MANAGER_STOP_DISCOVERY_REQ_H
@@ -0,0 +1,43 @@
/*
* Copyright (c) 2021 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_DEVICE_MANAGER_UNAUTHENTICATE_DEVICE_REQ_H
#define OHOS_DEVICE_MANAGER_UNAUTHENTICATE_DEVICE_REQ_H
#include "dm_device_info.h"
#include "message_req.h"
namespace OHOS {
namespace DistributedHardware {
class UnAuthenticateDeviceReq : public MessageReq {
DECLARE_MESSAGE_MODEL(UnAuthenticateDeviceReq);
public:
const DmDeviceInfo &GetDeviceInfo() const
{
return deviceInfo_;
}
void SetDeviceInfo(const DmDeviceInfo &deviceInfo)
{
deviceInfo_ = deviceInfo;
}
private:
DmDeviceInfo deviceInfo_;
};
} // namespace DistributedHardware
} // namespace OHOS
#endif // OHOS_DEVICE_MANAGER_UNAUTHENTICATE_DEVICE_REQ_H
@@ -0,0 +1,40 @@
/*
* Copyright (c) 2021 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_DEVICE_MANAGER_VERIFY_AUTHENTICATE_REQ_H
#define OHOS_DEVICE_MANAGER_VERIFY_AUTHENTICATE_REQ_H
#include "message_req.h"
namespace OHOS {
namespace DistributedHardware {
class VerifyAuthenticateReq : public MessageReq {
DECLARE_MESSAGE_MODEL(VerifyAuthenticateReq);
public:
const std::string& GetAuthPara() const
{
return authPara_;
}
void SetAuthPara(const std::string &authPara)
{
authPara_ = authPara;
}
private:
std::string authPara_;
};
} // namespace DistributedHardware
} // namespace OHOS
#endif // OHOS_DEVICE_MANAGER_VERIFY_AUTHENTICATE_REQ_H
@@ -604,11 +604,12 @@ int32_t DmAuthManager::JoinNetwork()
void DmAuthManager::AuthenticateFinish()
{
LOGI("DmAuthManager::AuthenticateFinish start");
#ifdef SUPPORT_GRAPHICS
if (authResponseState_ != nullptr) {
#ifdef SUPPORT_GRAPHICS
if (authResponseState_->GetStateType() == AuthState::AUTH_RESPONSE_FINISH) {
Ace::UIServiceMgrClient::GetInstance()->CancelDialog(authResponseContext_->pageId);
}
#endif
if (isFinishOfLocal_) {
authMessageProcessor_->SetResponseContext(authResponseContext_);
std::string message = authMessageProcessor_->CreateSimpleMessage(MSG_TYPE_REQ_AUTH_TERMINATE);
@@ -632,11 +633,11 @@ void DmAuthManager::AuthenticateFinish()
} else {
authRequestContext_->reason = authResponseContext_->reply;
}
#ifdef SUPPORT_GRAPHICS
if (authResponseContext_->state == AuthState::AUTH_REQUEST_INPUT) {
Ace::UIServiceMgrClient::GetInstance()->CancelDialog(authResponseContext_->pageId);
}
#endif
listener_->OnAuthResult(authRequestContext_->hostPkgName, authRequestContext_->deviceId,
authRequestContext_->token, authResponseContext_->state, authRequestContext_->reason);
@@ -654,7 +655,6 @@ void DmAuthManager::AuthenticateFinish()
authRequestState_ = nullptr;
authMessageProcessor_ = nullptr;
}
#endif
LOGI("DmAuthManager::AuthenticateFinish complete");
}
@@ -0,0 +1,65 @@
/*
* Copyright (c) 2021 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 "dm_config_manager.h"
#include "dm_constants.h"
#include "dm_log.h"
#include "pin_auth.h"
namespace OHOS {
namespace DistributedHardware {
DmConfigManager &DmConfigManager::GetInstance()
{
static DmConfigManager instance;
return instance;
}
DmConfigManager::DmConfigManager()
{
LOGI("DmConfigManager constructor");
}
DmConfigManager::~DmConfigManager()
{
LOGI("DmAdapterManager destructor");
}
std::shared_ptr<IDecisionAdapter> DmConfigManager::GetDecisionAdapter(const std::string &soName)
{
return nullptr;
}
std::shared_ptr<IProfileAdapter> DmConfigManager::GetProfileAdapter(const std::string &soName)
{
return nullptr;
}
std::shared_ptr<ICryptoAdapter> DmConfigManager::GetCryptoAdapter(const std::string &soName)
{
return nullptr;
}
extern "C" IAuthentication *CreatePinAuthObject(void)
{
return new PinAuth;
}
void DmConfigManager::GetAuthAdapter(std::map<int32_t, std::shared_ptr<IAuthentication>> &authAdapter)
{
authAdapter.clear();
std::shared_ptr<IAuthentication> iAuthentication(CreatePinAuthObject());
authAdapter[AUTH_TYPE_PIN] = iAuthentication;
}
} // namespace DistributedHardware
} // namespace OHOS
@@ -0,0 +1,83 @@
/*
* Copyright (c) 2021 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 "pin_auth.h"
#include <memory>
#include "dm_constants.h"
#include "dm_log.h"
#include "nlohmann/json.hpp"
namespace OHOS {
namespace DistributedHardware {
const int32_t MAX_VERIFY_TIMES = 3;
PinAuth::PinAuth()
{
LOGI("PinAuth constructor");
}
PinAuth::~PinAuth()
{
}
int32_t PinAuth::ShowAuthInfo(std::string &authToken, std::shared_ptr<DmAuthManager> authManager)
{
LOGI("ShowConfigDialog end");
return DM_OK;
}
int32_t PinAuth::StartAuth(std::string &authToken, std::shared_ptr<DmAuthManager> authManager)
{
LOGI("StartAuth end");
return DM_OK;
}
int32_t PinAuth::VerifyAuthentication(std::string &authToken, const std::string &authParam)
{
times_ += 1;
if (authParam.length() == 1) {
if (authParam == "0") {
return DM_OK;
}
LOGE("Peer rejection");
return DM_FAILED;
}
nlohmann::json authParamJson = nlohmann::json::parse(authParam, nullptr, false);
if (authParamJson.is_discarded()) {
LOGE("DecodeRequestAuth jsonStr error");
return DM_FAILED;
}
nlohmann::json authTokenJson = nlohmann::json::parse(authToken, nullptr, false);
if (authTokenJson.is_discarded()) {
LOGE("DecodeRequestAuth jsonStr error");
return DM_FAILED;
}
if (!authParamJson.contains(PIN_CODE_KEY) || !authTokenJson.contains(PIN_CODE_KEY)) {
LOGE("err json string, first time");
return DM_FAILED;
}
int32_t code = authTokenJson[PIN_CODE_KEY];
int32_t inputPinCode = authParamJson[PIN_CODE_KEY];
if (code == inputPinCode) {
return DM_OK;
} else if (code != inputPinCode && times_ < MAX_VERIFY_TIMES) {
return DM_AUTH_INPUT_FAILED;
} else {
return DM_FAILED;
}
}
} // namespace DistributedHardware
} // namespace OHOS
@@ -250,7 +250,7 @@ int32_t HiChainConnector::AddMember(std::string deviceId, std::string &connectIn
return ret;
}
void HiChainConnector::onFinish(int64_t requestId, int32_t operationCode, const char *returnData)
void HiChainConnector::onFinish(int64_t requestId, int operationCode, const char *returnData)
{
std::string data = "";
if (returnData != nullptr) {
@@ -273,7 +273,7 @@ void HiChainConnector::onFinish(int64_t requestId, int32_t operationCode, const
}
}
void HiChainConnector::onError(int64_t requestId, int32_t operationCode, int32_t errorCode, const char *errorReturn)
void HiChainConnector::onError(int64_t requestId, int operationCode, int errorCode, const char *errorReturn)
{
(void)errorReturn;
LOGI("HichainAuthenCallBack::onError reqId:%lld, operation:%d, errorCode:%d.", requestId, operationCode, errorCode);
@@ -293,7 +293,7 @@ void HiChainConnector::onError(int64_t requestId, int32_t operationCode, int32_t
}
}
char *HiChainConnector::onRequest(int64_t requestId, int32_t operationCode, const char *reqParams)
char *HiChainConnector::onRequest(int64_t requestId, int operationCode, const char *reqParams)
{
if (operationCode != GroupOperationCode::MEMBER_JOIN) {
LOGE("HiChainAuthCallBack::onRequest operationCode %d", operationCode);
@@ -0,0 +1,41 @@
/*
* Copyright (c) 2021 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 <string>
#include "dm_log.h"
#include "dm_mutex.h"
namespace OHOS {
namespace DistributedHardware {
DmMutex::DmMutex()
{
uint32_t ret = pthread_mutex_init(&lock_, NULL);
if (ret != 0) {
LOGE("init mutex lock failed: %d.", ret);
}
pthread_mutex_lock(&lock_);
}
DmMutex::~DmMutex()
{
pthread_mutex_unlock(&lock_);
uint32_t ret = pthread_mutex_destroy(&lock_);
if (ret != 0) {
LOGI("destroy mutex lock failed: %d.", ret);
}
}
} // namespace DistributedHardware
} // namespace OHOS
@@ -0,0 +1,52 @@
/*
* Copyright (c) 2021 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 "dm_thread.h"
namespace OHOS {
namespace DistributedHardware {
using funcstr = void (*)(std::map<std::string, std::shared_ptr<ISoftbusStateCallback>>, DmDeviceInfo);
funcstr DmThread::funcName_;
std::map<std::string, std::shared_ptr<ISoftbusStateCallback>> DmThread::parameter1_ = {};
DmDeviceInfo DmThread::parameter2_;
DmThread::DmThread(funcstr funcname,\
std::map<std::string, std::shared_ptr<ISoftbusStateCallback>> parameter1,\
DmDeviceInfo parameter2)
{
funcName_ = funcname;
parameter1_ = parameter1;
parameter2_ = parameter2;
parameterGroup_.member1 = parameter1;
parameterGroup_.member2 = parameter2;
}
void* DmThread::PthreadDeviceStart(void* parameterInfo)
{
PthreadCallbackParameter *parameterStruct = static_cast<PthreadCallbackParameter *>(parameterInfo);
funcName_(parameterStruct->member1, parameterStruct->member2);
return nullptr;
}
void DmThread::DmCreatThread()
{
pthread_t tid;
pthread_attr_t attr;
pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
pthread_create(&tid, &attr, PthreadDeviceStart, static_cast<void *>(&parameterGroup_));
}
} // namespace DistributedHardware
} // namespace OHOS
@@ -17,9 +17,10 @@
#include "dm_constants.h"
#include "dm_log.h"
#if !defined(__LITEOS_M__)
#include "os_account_manager.h"
using namespace OHOS::AccountSA;
#endif
namespace OHOS {
namespace DistributedHardware {
@@ -27,12 +28,16 @@ int32_t MultipleUserConnector::oldUserId_ = -1;
int32_t MultipleUserConnector::GetCurrentAccountUserID(void)
{
#if defined(__LITEOS_M__)
return 0;
#else
std::vector<int> ids;
ErrCode ret = OsAccountManager::QueryActiveOsAccountIds(ids);
if (ret != ERR_OK || ids.empty()) {
return -1;
}
return ids[0];
#endif
}
void MultipleUserConnector::SetSwitchOldUserId(int32_t userId)
@@ -17,8 +17,13 @@
#include <securec.h>
#include <unistd.h>
#if defined(__LITEOS_M__)
#include "dm_mutex.h"
#include "dm_thread.h"
#else
#include <thread>
#include <mutex>
#endif
#include "dm_anonymous.h"
#include "dm_constants.h"
@@ -49,12 +54,17 @@ INodeStateCb SoftbusConnector::softbusNodeStateCb_ = {
.onNodeOffline = SoftbusConnector::OnSoftbusDeviceOffline,
.onNodeBasicInfoChanged = SoftbusConnector::OnSoftbusDeviceInfoChanged};
void DeviceOnLine(std::map<std::string, std::shared_ptr<ISoftbusStateCallback>> stateCallbackMap,
DmDeviceInfo deviceInfo)
{
LOGI("Device on line start");
#if defined(__LITEOS_M__)
DmMutex lockDeviceOnLine;
#else
std::mutex lockDeviceOnLine;
std::lock_guard<std::mutex> lock(lockDeviceOnLine);
#endif
for (auto &iter : stateCallbackMap) {
iter.second->OnDeviceOnline(iter.first, deviceInfo);
}
@@ -65,8 +75,12 @@ void DeviceOffLine(std::map<std::string, std::shared_ptr<ISoftbusStateCallback>>
DmDeviceInfo deviceInfo)
{
LOGI("Device off line start");
#if defined(__LITEOS_M__)
DmMutex lockDeviceOffLine;
#else
std::mutex lockDeviceOffLine;
std::lock_guard<std::mutex> lock(lockDeviceOffLine);
#endif
for (auto &iter : stateCallbackMap) {
iter.second->OnDeviceOffline(iter.first, deviceInfo);
}
@@ -106,7 +120,10 @@ int32_t SoftbusConnector::Init()
dmPublishInfo.capability = DM_CAPABILITY_OSD;
dmPublishInfo.capabilityData = nullptr;
dmPublishInfo.dataLen = 0;
#if defined(__LITEOS_M__)
ret = PublishService(DM_PKG_NAME.c_str(), &dmPublishInfo, &softbusPublishCallback_);
LOGI("service publish result is : %d", ret);
#else
char discoverStatus[DISCOVER_STATUS_LEN + 1] = {0};
ret = GetParameter(DISCOVER_STATUS_KEY.c_str(), "not exist", discoverStatus, DISCOVER_STATUS_LEN);
if (strcmp(discoverStatus, "not exist") == 0) {
@@ -133,7 +150,8 @@ int32_t SoftbusConnector::Init()
}
ret = WatchParameter(DISCOVER_STATUS_KEY.c_str(), &SoftbusConnector::OnParameterChgCallback, nullptr);
LOGI("register Watch Parameter result is : %d");
LOGI("register Watch Parameter result is : %d", ret);
#endif
return ret;
}
@@ -448,12 +466,12 @@ void SoftbusConnector::CovertDeviceInfoToDmDevice(const DeviceInfo &deviceInfo,
dmDeviceInfo.deviceTypeId = deviceInfo.devType;
}
void SoftbusConnector::OnPublishSuccess(int32_t publishId)
void SoftbusConnector::OnPublishSuccess(int publishId)
{
LOGI("SoftbusConnector::OnPublishSuccess, publishId: %d", publishId);
}
void SoftbusConnector::OnPublishFail(int32_t publishId, PublishFailReason reason)
void SoftbusConnector::OnPublishFail(int publishId, PublishFailReason reason)
{
LOGI("SoftbusConnector::OnPublishFail failed, publishId: %d, reason: %d", publishId, reason);
}
@@ -468,8 +486,13 @@ void SoftbusConnector::OnSoftBusDeviceOnline(NodeBasicInfo *info)
DmDeviceInfo dmDeviceInfo;
CovertNodeBasicInfoToDmDevice(*info, dmDeviceInfo);
#if defined(__LITEOS_M__)
DmThread deviceOnLine(DeviceOnLine, stateCallbackMap_, dmDeviceInfo);
deviceOnLine.DmCreatThread();
#else
std::thread deviceOnLine(DeviceOnLine, stateCallbackMap_, dmDeviceInfo);
deviceOnLine.detach();
#endif
if (discoveryDeviceInfoMap_.empty()) {
return;
@@ -495,8 +518,13 @@ void SoftbusConnector::OnSoftbusDeviceOffline(NodeBasicInfo *info)
}
DmDeviceInfo dmDeviceInfo;
CovertNodeBasicInfoToDmDevice(*info, dmDeviceInfo);
#if defined(__LITEOS_M__)
DmThread deviceOffLine(DeviceOffLine, stateCallbackMap_, dmDeviceInfo);
deviceOffLine.DmCreatThread();
#else
std::thread deviceOffLine(DeviceOffLine, stateCallbackMap_, dmDeviceInfo);
deviceOffLine.detach();
#endif
}
void SoftbusConnector::OnSoftbusDeviceInfoChanged(NodeBasicInfoType type, NodeBasicInfo *info)
@@ -534,7 +562,7 @@ void SoftbusConnector::OnSoftbusDeviceFound(const DeviceInfo *device)
}
}
void SoftbusConnector::OnSoftbusDiscoveryFailed(int32_t subscribeId, DiscoveryFailReason failReason)
void SoftbusConnector::OnSoftbusDiscoveryFailed(int subscribeId, DiscoveryFailReason failReason)
{
LOGI("In, subscribeId %d, failReason %d", subscribeId, (int32_t)failReason);
uint16_t originId = (uint16_t)(((uint32_t)subscribeId) & SOFTBUS_SUBSCRIBE_ID_MASK);
@@ -543,7 +571,7 @@ void SoftbusConnector::OnSoftbusDiscoveryFailed(int32_t subscribeId, DiscoveryFa
}
}
void SoftbusConnector::OnSoftbusDiscoverySuccess(int32_t subscribeId)
void SoftbusConnector::OnSoftbusDiscoverySuccess(int subscribeId)
{
LOGI("In, subscribeId %d", subscribeId);
uint16_t originId = (uint16_t)(((uint32_t)subscribeId) & SOFTBUS_SUBSCRIBE_ID_MASK);
@@ -119,7 +119,7 @@ int32_t SoftbusSession::SendData(int32_t sessionId, std::string &message)
return DM_OK;
}
int32_t SoftbusSession::OnSessionOpened(int32_t sessionId, int32_t result)
int SoftbusSession::OnSessionOpened(int sessionId, int result)
{
int32_t sessionSide = GetSessionSide(sessionId);
sessionCallback_->OnSessionOpened(sessionId, sessionSide, result);
@@ -127,12 +127,12 @@ int32_t SoftbusSession::OnSessionOpened(int32_t sessionId, int32_t result)
return DM_OK;
}
void SoftbusSession::OnSessionClosed(int32_t sessionId)
void SoftbusSession::OnSessionClosed(int sessionId)
{
LOGI("OnSessionClosed, sessionId:%d", sessionId);
}
void SoftbusSession::OnBytesReceived(int32_t sessionId, const void *data, uint32_t dataLen)
void SoftbusSession::OnBytesReceived(int sessionId, const void *data, unsigned int dataLen)
{
LOGI("OnBytesReceived, sessionId:%d, dataLen:%d", sessionId, dataLen);
if (sessionId < 0 || data == nullptr || dataLen <= 0) {
@@ -0,0 +1,112 @@
/*
* Copyright (c) 2021 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 "dm_timer.h"
#include "cmsis_os2.h"
#include "securec.h"
namespace OHOS {
namespace DistributedHardware {
namespace {
const int32_t MILL_SECONDS_PER_SECOND = 1000;
}
DmTimer::DmTimer(const std::string &name)
{
if (name.empty()) {
LOGI("DmTimer name is null");
return;
}
mStatus_ = DmTimerStatus::DM_STATUS_INIT;
mTimeOutSec_ = 0;
mTimerName_ = name;
}
DmTimer::~DmTimer()
{
if (mTimerName_.empty()) {
LOGI("DmTimer is not init");
return;
}
LOGI("DmTimer %s Destroy in", mTimerName_.c_str());
}
struct DmTimst {
TimeoutHandle handle;
DmTimer *dmtimer;
void *data;
};
static void handler(void *data)
{
struct DmTimst *myTimer = (struct DmTimst *)data;
myTimer->handle(myTimer->data, *(myTimer->dmtimer));
}
DmTimerStatus DmTimer::Start(uint32_t timeOut, TimeoutHandle handle, void *data)
{
if (mTimerName_.empty() || handle == nullptr || data == nullptr) {
LOGI("DmTimer is not init or param empty");
return DmTimerStatus::DM_STATUS_FINISH;
}
LOGI("DmTimer %s start timeout(%d)", mTimerName_.c_str(), timeOut);
if (mStatus_ != DmTimerStatus::DM_STATUS_INIT) {
return DmTimerStatus::DM_STATUS_BUSY;
}
static struct DmTimst myTimer = {
.handle = handle,
.dmtimer = this,
.data = data,
};
mTimeOutSec_ = timeOut;
void *id = osTimerNew((osTimerFunc_t)handler, osTimerType_t::osTimerOnce, (void *)&myTimer, NULL);
if (id != NULL) {
LOGI("Get name of a timer success ");
} else {
LOGI("Get name of a timer failed");
return DmTimerStatus::DM_STATUS_CREATE_ERROR;
}
timerId = id;
int stOk = osTimerStart(timerId, timeOut * osKernelGetTickFreq());
if (stOk == 0) {
LOGI("DmTimer %s start timer at (%d)s", mTimerName_.c_str(), mTimeOutSec_);
mStatus_ = DmTimerStatus::DM_STATUS_RUNNING;
} else {
LOGI("Start a timer failed");
(void)osTimerDelete(timerId);
}
return mStatus_;
}
void DmTimer::Stop(int32_t code)
{
LOGI("DmTimer Stop code (%d)", code);
if (timerId != NULL) {
osTimerDelete(timerId);
timerId = NULL;
}
LOGI("DmTimer %s end timer at (%d)s", mTimerName_.c_str(), mTimeOutSec_);
return;
}
std::string DmTimer::GetTimerName()
{
return mTimerName_;
}
} // namespace DistributedHardware
} // namespace OHOS
@@ -17,16 +17,18 @@
#include <functional>
#include "common_event_support.h"
#include "device_manager_service_listener.h"
#include "dm_common_event_manager.h"
#include "dm_constants.h"
#include "dm_device_info_manager.h"
#include "dm_log.h"
#include "multiple_user_connector.h"
#include "permission_manager.h"
#if !defined(__LITEOS_M__)
#include "dm_common_event_manager.h"
#include "common_event_support.h"
using namespace OHOS::EventFwk;
#endif
namespace OHOS {
namespace DistributedHardware {
@@ -35,10 +37,12 @@ IMPLEMENT_SINGLE_INSTANCE(DeviceManagerService);
DeviceManagerService::~DeviceManagerService()
{
LOGI("DeviceManagerService destructor");
#if !defined(__LITEOS_M__)
DmCommonEventManager &dmCommonEventManager = DmCommonEventManager::GetInstance();
if (dmCommonEventManager.UnsubscribeServiceEvent(CommonEventSupport::COMMON_EVENT_USER_STOPPED)) {
LOGI("subscribe service event success");
}
#endif
softbusConnector_->GetSoftbusSession()->UnRegisterSessionCallback();
hiChainConnector_->UnRegisterHiChainCallback();
}
@@ -113,14 +117,14 @@ int32_t DeviceManagerService::Init()
LOGI("get current account user id success");
MultipleUserConnector::SetSwitchOldUserId(userId);
}
#if !defined(__LITEOS_M__)
DmCommonEventManager &dmCommonEventManager = DmCommonEventManager::GetInstance();
CommomEventCallback callback = std::bind(&DmAuthManager::UserSwitchEventCallback, *authMgr_.get(),
std::placeholders::_1);
if (dmCommonEventManager.SubscribeServiceEvent(CommonEventSupport::COMMON_EVENT_USER_SWITCHED, callback)) {
LOGI("subscribe service user switch common event success");
}
#endif
LOGI("Init success, singleton initialized");
intFlag_ = true;
return DM_OK;
@@ -70,7 +70,11 @@ int32_t DmDeviceStateManager::RegisterProfileListener(const std::string &pkgName
DmDeviceInfo saveInfo = info;
SoftbusConnector::GetUuidByNetworkId(info.deviceId, uuid);
{
#if defined(__LITEOS_M__)
DmMutex mutexLock;
#else
std::lock_guard<std::mutex> mutexLock(remoteDeviceInfosMutex_);
#endif
remoteDeviceInfos_[uuid] = saveInfo;
}
LOGI("RegisterProfileListener in, deviceId = %s, deviceUdid = %s, uuid = %s",
@@ -90,7 +94,11 @@ int32_t DmDeviceStateManager::UnRegisterProfileListener(const std::string &pkgNa
profileAdapter->UnRegisterProfileListener(pkgName);
}
{
#if defined(__LITEOS_M__)
DmMutex mutexLock;
#else
std::lock_guard<std::mutex> mutexLock(remoteDeviceInfosMutex_);
#endif
if (remoteDeviceInfos_.find(std::string(info.deviceId)) != remoteDeviceInfos_.end()) {
remoteDeviceInfos_.erase(std::string(info.deviceId));
}
@@ -199,7 +207,11 @@ void DmDeviceStateManager::OnProfileReady(const std::string &pkgName, const std:
}
DmDeviceInfo saveInfo;
{
#if defined(__LITEOS_M__)
DmMutex mutexLock;
#else
std::lock_guard<std::mutex> mutexLock(remoteDeviceInfosMutex_);
#endif
auto iter = remoteDeviceInfos_.find(deviceId);
if (iter == remoteDeviceInfos_.end()) {
LOGE("OnProfileReady complete not find deviceId: %s", GetAnonyString(deviceId).c_str());
@@ -248,8 +260,11 @@ void DmDeviceStateManager::RegisterOffLineTimer(const DmDeviceInfo &deviceInfo)
return;
}
LOGI("Register OffLine Timer with device: %s", GetAnonyString(deviceId).c_str());
#if defined(__LITEOS_M__)
DmMutex mutexLock;
#else
std::lock_guard<std::mutex> mutexLock(timerMapMutex_);
#endif
for (auto &iter : stateTimerInfoMap_) {
if (iter.second.netWorkId == deviceInfo.deviceId) {
iter.second.timer->Stop(SESSION_CANCEL_TIMEOUT);
@@ -282,7 +297,11 @@ void DmDeviceStateManager::StartOffLineTimer(const DmDeviceInfo &deviceInfo)
void DmDeviceStateManager::DeleteTimeOutGroup(std::string stateTimer)
{
#if defined(__LITEOS_M__)
DmMutex mutexLock;
#else
std::lock_guard<std::mutex> mutexLock(timerMapMutex_);
#endif
if (hiChainConnector_ != nullptr) {
auto iter = stateTimerInfoMap_.find(stateTimer);
if (iter != stateTimerInfoMap_.end()) {
@@ -0,0 +1,239 @@
/*
* Copyright (c) 2020 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 "command_dispatch.h"
#include "dm_log.h"
#include "message_def.h"
#include "dm_constants.h"
#include "server_stub.h"
#include "securec.h"
#include "dm_device_info.h"
#include "dm_subscribe_info.h"
#include "get_trustdevice_req.h"
#include "start_discovery_req.h"
#include "stop_discovery_req.h"
#include "get_useroperation_req.h"
#include "authenticate_device_req.h"
#include "verify_authenticate_req.h"
#include "get_trustdevice_rsp.h"
#include "device_manager_service.h"
#include "get_local_device_info_rsp.h"
#include "get_info_by_network_rsp.h"
#include "get_info_by_network_req.h"
#include "unauthenticate_device_req.h"
#include "get_dmfaparam_rsp.h"
namespace OHOS {
namespace DistributedHardware {
IMPLEMENT_SINGLE_INSTANCE(CommandDispatch);
int32_t CommandDispatch::MessageSendCmd(int32_t cmdCode, const std::shared_ptr<MessageReq> &req,
const std::shared_ptr<MessageRsp> &rsp)
{
if (req == nullptr || rsp == nullptr) {
LOGE("Message req or rsp is null.");
return DM_INVALID_VALUE;
}
uint32_t i = 0;
for (i = 0; i < (sizeof(g_cmdMap) / sizeof(g_cmdMap[0])); i++) {
if (g_cmdMap[i].cmdCode == cmdCode) {
break;
}
}
int32_t ret = g_cmdMap[i].MsgProcess(req, rsp);
if (ret != DM_OK) {
LOGE("MessageSendCmd Failed with ret: %d", ret);
return ret;
}
return DM_OK;
}
void CommandDispatch::AddPkgName(const std::string &pkgName)
{
dmPkgName_.push_back(pkgName);
}
void CommandDispatch::DeletePkgName(const std::string &pkgName)
{
dmPkgName_.remove(pkgName);
}
const std::list<std::string>& CommandDispatch::GetPkgNameList() const
{
return dmPkgName_;
}
static int32_t GetTrustedDeviceList(const std::shared_ptr<MessageReq> &req, const std::shared_ptr<MessageRsp> &rsp)
{
std::shared_ptr<GetTrustDeviceReq> pReq = std::static_pointer_cast<GetTrustDeviceReq>(req);
std::shared_ptr<GetTrustDeviceRsp> prsp = std::static_pointer_cast<GetTrustDeviceRsp>(rsp);
std::string pkgName = pReq->GetPkgName();
std::string extra = pReq->GetExtra();
LOGI("enter GetTrustedDeviceList");
std::vector<DmDeviceInfo> deviceList;
int32_t ret = DeviceManagerService::GetInstance().GetTrustedDeviceList(pkgName, extra, deviceList);
prsp->SetDeviceVec(deviceList);
prsp->SetErrCode(ret);
return ret;
}
static int32_t GetLocalDeviceInfo(const std::shared_ptr<MessageReq> &req, const std::shared_ptr<MessageRsp> &rsp)
{
std::shared_ptr<GetLocalDeviceInfoRsp> pRsp = std::static_pointer_cast<GetLocalDeviceInfoRsp>(rsp);
DmDeviceInfo dmDeviceInfo = {0};
int32_t ret = DeviceManagerService::GetInstance().GetLocalDeviceInfo(dmDeviceInfo);
DmDeviceInfo *Info = &dmDeviceInfo;
if (Info != nullptr) {
pRsp->SetLocalDeviceInfo(dmDeviceInfo);
}
pRsp->SetErrCode(ret);
return ret;
}
static int32_t GetUdidByNetworkId(const std::shared_ptr<MessageReq> &req, const std::shared_ptr<MessageRsp> &rsp)
{
std::shared_ptr<GetInfoByNetWorkReq> pReq = std::static_pointer_cast<GetInfoByNetWorkReq>(req);
std::shared_ptr<GetInfoByNetWorkRsp> pRsp = std::static_pointer_cast<GetInfoByNetWorkRsp>(rsp);
std::string pkgName = pReq->GetPkgName();
std::string netWorkId = pReq->GetNetWorkId();
std::string udid;
int32_t ret = DeviceManagerService::GetInstance().GetUdidByNetworkId(pkgName, netWorkId, udid);
pRsp->SetUdid(udid);
pRsp->SetErrCode(ret);
return ret;
}
static int32_t GetUuidByNetworkId(const std::shared_ptr<MessageReq> &req, const std::shared_ptr<MessageRsp> &rsp)
{
std::shared_ptr<GetInfoByNetWorkReq> pReq = std::static_pointer_cast<GetInfoByNetWorkReq>(req);
std::shared_ptr<GetInfoByNetWorkRsp> pRsp = std::static_pointer_cast<GetInfoByNetWorkRsp>(rsp);
std::string pkgName = pReq->GetPkgName();
std::string netWorkId = pReq->GetNetWorkId();
std::string uuid;
int32_t ret = DeviceManagerService::GetInstance().GetUuidByNetworkId(pkgName, netWorkId, uuid);
pRsp->SetUuid(uuid);
pRsp->SetErrCode(ret);
return ret;
}
static int32_t StartDeviceDiscovery(const std::shared_ptr<MessageReq> &req, const std::shared_ptr<MessageRsp> &rsp)
{
std::shared_ptr<StartDiscoveryReq> pReq = std::static_pointer_cast<StartDiscoveryReq>(req);
std::string pkgName = pReq->GetPkgName();
std::string extra = pReq->GetExtra();
const DmSubscribeInfo dmSubscribeInfo = pReq->GetSubscribeInfo();
LOGI("StartDeviceDiscovery service");
int32_t ret = DeviceManagerService::GetInstance().StartDeviceDiscovery(pkgName, dmSubscribeInfo, extra);
rsp->SetErrCode(ret);
return ret;
}
static int32_t StopDeviceDiscovery(const std::shared_ptr<MessageReq> &req, const std::shared_ptr<MessageRsp> &rsp)
{
LOGI("StopDeviceDiscovery service");
std::shared_ptr<StopDiscoveryReq> pReq = std::static_pointer_cast<StopDiscoveryReq>(req);
std::string pkgName = pReq->GetPkgName();
uint16_t subscribeId = pReq->GetSubscribeId();
int32_t ret = DeviceManagerService::GetInstance().StopDeviceDiscovery(pkgName, subscribeId);
rsp->SetErrCode(ret);
return ret;
}
static int32_t SetUserOperation(const std::shared_ptr<MessageReq> &req, const std::shared_ptr<MessageRsp> &rsp)
{
std::shared_ptr<GetUserOperationReq> pReq = std::static_pointer_cast<GetUserOperationReq>(req);
std::string pkgName = pReq->GetPkgName();
int32_t action = pReq->GetOperation();
LOGI("enter server user authorization operation.");
int32_t ret = DeviceManagerService::GetInstance().SetUserOperation(pkgName, action);
rsp->SetErrCode(ret);
return ret;
}
static int32_t GetFaParam(const std::shared_ptr<MessageReq> &req, const std::shared_ptr<MessageRsp> &rsp)
{
std::shared_ptr<MessageReq> pReq = std::static_pointer_cast<MessageReq>(req);
std::shared_ptr<GetDmFaParamRsp> pRsp = std::static_pointer_cast<GetDmFaParamRsp>(rsp);
std::string pkgName = pReq->GetPkgName();
DmAuthParam authParam = {
.authToken = "",
.packageName = "",
.appName = "",
.appDescription = "",
.authType = 0,
.business = 0,
.pincode = 0,
.direction = 0,
.pinToken = 0
};
LOGI("DeviceManagerStub:: GET_AUTHENTCATION_INFO:pkgName:%s", pkgName.c_str());
int32_t ret = DeviceManagerService::GetInstance().GetFaParam(pkgName, authParam);
pRsp->SetDmAuthParam(authParam);
pRsp->SetErrCode(ret);
return ret;
}
static int32_t AuthenticateDevice(const std::shared_ptr<MessageReq> &req, const std::shared_ptr<MessageRsp> &rsp)
{
std::shared_ptr<AuthenticateDeviceReq> pReq = std::static_pointer_cast<AuthenticateDeviceReq>(req);
std::string pkgName = pReq->GetPkgName();
std::string extra = pReq->GetExtra();
DmDeviceInfo deviceInfo = pReq->GetDeviceInfo();
int32_t authType = pReq->GetAuthType();
std::string deviceId = deviceInfo.deviceId;
LOGI("DeviceManagerStub:: AUTHENTCATION_DEVICE:pkgName:%s", pkgName.c_str());
int32_t ret = DeviceManagerService::GetInstance().AuthenticateDevice(pkgName, authType, deviceId, extra);
rsp->SetErrCode(ret);
return ret;
}
static int32_t UnAuthenticateDevice(const std::shared_ptr<MessageReq> &req, const std::shared_ptr<MessageRsp> &rsp)
{
std::shared_ptr<UnAuthenticateDeviceReq> pReq = std::static_pointer_cast<UnAuthenticateDeviceReq>(req);
std::string pkgName = pReq->GetPkgName();
DmDeviceInfo deviceInfo = pReq->GetDeviceInfo();
std::string deviceId = deviceInfo.deviceId;
LOGI("enter server user authorization operation.");
int32_t ret = DeviceManagerService::GetInstance().UnAuthenticateDevice(pkgName, deviceId);
rsp->SetErrCode(ret);
return ret;
}
static int32_t VerifyAuthentication(const std::shared_ptr<MessageReq> &req, const std::shared_ptr<MessageRsp> &rsp)
{
std::shared_ptr<VerifyAuthenticateReq> pReq = std::static_pointer_cast<VerifyAuthenticateReq>(req);
std::string pkgName = pReq->GetPkgName();
std::string authParam = pReq->GetAuthPara();
LOGI("DeviceManagerStub:: VERIFY_AUTHENTCATION:pkgName:%s", pkgName.c_str());
int32_t ret = DeviceManagerService::GetInstance().VerifyAuthentication(authParam);
rsp->SetErrCode(ret);
return ret;
}
} // namespace DistributedHardware
} // namespace OHOS
@@ -0,0 +1,101 @@
/*
* Copyright (c) 2021 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_listener.h"
#include "dm_anonymous.h"
#include "dm_constants.h"
#include "dm_log.h"
#include "device_manager_notify.h"
#include "command_dispatch.h"
namespace OHOS {
namespace DistributedHardware {
void DeviceManagerServiceListener::OnDeviceStateChange(const std::string &pkgName, const DmDeviceState &state,
const DmDeviceInfo &info)
{
LOGI("call OnDeviceStateChange, state=%d", state);
std::list<std::string> pkgNameList = CommandDispatch::GetInstance().GetPkgNameList();
for (auto pkgName : pkgNameList) {
DmDeviceState deviceState = static_cast<DmDeviceState>(state);
if (pkgName == "") {
LOGE("OnDeviceOnline, get para failed");
return;
}
switch (deviceState) {
case DEVICE_STATE_ONLINE:
DeviceManagerNotify::GetInstance().OnDeviceOnline(pkgName, info);
break;
case DEVICE_STATE_OFFLINE:
DeviceManagerNotify::GetInstance().OnDeviceOffline(pkgName, info);
break;
case DEVICE_INFO_CHANGED:
DeviceManagerNotify::GetInstance().OnDeviceChanged(pkgName, info);
break;
default:
LOGE("unknown device state:%d", deviceState);
break;
}
}
}
void DeviceManagerServiceListener::OnDeviceFound(const std::string &pkgName, uint16_t subscribeId,
const DmDeviceInfo &info)
{
LOGI("call OnDeviceFound for %s, originId %d, deviceId %s", pkgName.c_str(), subscribeId,
GetAnonyString(std::string(info.deviceId)).c_str());
DeviceManagerNotify::GetInstance().OnDeviceFound(pkgName, subscribeId, info);
}
void DeviceManagerServiceListener::OnDiscoveryFailed(const std::string &pkgName, uint16_t subscribeId,
int32_t failedReason)
{
LOGI("call OnDiscoveryFailed");
DeviceManagerNotify::GetInstance().OnDiscoveryFailed(pkgName, subscribeId, failedReason);
}
void DeviceManagerServiceListener::OnDiscoverySuccess(const std::string &pkgName, int32_t subscribeId)
{
LOGI("call OnDiscoverySuccess");
DeviceManagerNotify::GetInstance().OnDiscoverySuccess(pkgName, subscribeId);
}
void DeviceManagerServiceListener::OnAuthResult(const std::string &pkgName, const std::string &deviceId,
const std::string &token, int32_t status, int32_t reason)
{
LOGI("call package: %s, deviceId: %s", pkgName.c_str(), GetAnonyString(deviceId).c_str());
DeviceManagerNotify::GetInstance().OnAuthResult(pkgName, deviceId, token, status, reason);
}
void DeviceManagerServiceListener::OnVerifyAuthResult(const std::string &pkgName, const std::string &deviceId,
int32_t resultCode, const std::string &flag)
{
LOGI("call OnVerifyAuthResult");
std::list<std::string> pkgNameList = CommandDispatch::GetInstance().GetPkgNameList();
int32_t num = 0;
((resultCode == 0) && (!flag.empty())) ? (num = std::stoi(flag)) : (num = 0);
for (auto pkgName : pkgNameList) {
DeviceManagerNotify::GetInstance().OnVerifyAuthResult(pkgName, deviceId, resultCode, num);
}
}
void DeviceManagerServiceListener::OnFaCall(std::string &pkgName, std::string &paramJson)
{
LOGI("call OnFaCall in");
DeviceManagerNotify::GetInstance().OnFaCall(pkgName, paramJson);
}
} // namespace DistributedHardware
} // namespace OHOS
@@ -0,0 +1,110 @@
/*
* Copyright (c) 2021 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 "server_stub.h"
#include "securec.h"
#include "ohos_init.h"
#include "samgr_lite.h"
#include "iproxy_server.h"
#include "dm_log.h"
#include "dm_subscribe_info.h"
#include "message_def.h"
#include "device_manager_service.h"
namespace {
const int32_t WAIT_FOR_SERVER = 2;
const int32_t STACK_SIZE = 0x1000;
const int32_t QUEUE_SIZE = 32;
}
using namespace OHOS::DistributedHardware;
struct DefaultFeatureApi {
INHERIT_SERVER_IPROXY;
};
struct DeviceManagerSamgrService {
INHERIT_SERVICE;
INHERIT_IUNKNOWNENTRY(DefaultFeatureApi);
Identity identity;
};
static const char *GetName(Service *service)
{
(void)service;
return DEVICE_MANAGER_SERVICE_NAME;
}
static BOOL Initialize(Service *service, Identity identity)
{
if (service == NULL) {
LOGW("Initialize invalid param");
return FALSE;
}
const int32_t DM_SERVICE_INIT_DELAY = 2;
sleep(DM_SERVICE_INIT_DELAY);
SAMGR_Bootstrap();
DeviceManagerService::GetInstance().Init();
DeviceManagerSamgrService *mgrService = (DeviceManagerSamgrService *)service;
mgrService->identity = identity;
return TRUE;
}
static BOOL MessageHandle(Service *service, Request *request)
{
if ((service == NULL) || (request == NULL)) {
LOGW("MessageHandle invalid param");
return FALSE;
}
return TRUE;
}
static TaskConfig GetTaskConfig(Service *service)
{
(void)service;
TaskConfig config = {LEVEL_HIGH, PRI_BELOW_NORMAL, STACK_SIZE, QUEUE_SIZE, SHARED_TASK};
return config;
}
static void DevMgrSvcInit(void)
{
sleep(WAIT_FOR_SERVER);
static DeviceManagerSamgrService service = {
.GetName = GetName,
.Initialize = Initialize,
.MessageHandle = MessageHandle,
.GetTaskConfig = GetTaskConfig,
SERVER_IPROXY_IMPL_BEGIN,
.Invoke = NULL,
IPROXY_END,
};
if (!SAMGR_GetInstance()->RegisterService((Service *)&service)) {
LOGE("%s, RegisterService failed", DEVICE_MANAGER_SERVICE_NAME);
return;
}
if (!SAMGR_GetInstance()->RegisterDefaultFeatureApi(DEVICE_MANAGER_SERVICE_NAME, GET_IUNKNOWN(service))) {
LOGE("%s, RegisterDefaultFeatureApi failed", DEVICE_MANAGER_SERVICE_NAME);
return;
}
LOGI("%s, init success", DEVICE_MANAGER_SERVICE_NAME);
}
SYSEX_SERVICE_INIT(DevMgrSvcInit);
+45 -1
View File
@@ -20,7 +20,51 @@ if (defined(ohos_lite)) {
import("//foundation/distributedhardware/devicemanager/devicemanager.gni")
if (defined(ohos_lite)) {
shared_library("devicemanagerutils") {
if (ohos_kernel_type == "liteos_m") {
static_library("devicemanagerutils_mini") {
include_dirs = [
"${utils_path}/include",
"${utils_path}/include/permission/lite",
"${common_path}/include",
]
include_dirs += [
"//base/security/deviceauth/interfaces/innerkits",
"//base/startup/syspara_lite/interfaces/innerkits/native/syspara/include",
"//utils/native/lite/include",
"//utils/system/safwk/native/include",
"//third_party/json/include",
"//base/hiviewdfx/hilog_lite/interfaces/native/innerkits",
"//third_party/bounds_checking_function/include",
"//foundation/distributedschedule/samgr_lite/interfaces/kits/samgr",
]
sources = [
"${utils_path}/src/dm_anonymous.cpp",
"${utils_path}/src/dm_log.cpp",
"${utils_path}/src/dm_random.cpp",
"${utils_path}/src/permission/lite/permission_manager.cpp",
]
defines = [
"HI_LOG_ENABLE",
"DH_LOG_TAG=\"devicemanagerutils\"",
"LOG_DOMAIN=0xD004100",
]
deps = [
"//base/hiviewdfx/hilog_lite/frameworks/featured:hilog_static",
"//base/startup/syspara_lite/frameworks/parameter/src:sysparam",
"//foundation/distributedschedule/samgr_lite/samgr",
"//third_party/bounds_checking_function:libsec_static",
"//third_party/mbedtls",
"//third_party/mbedtls:mbedtls_shared",
"//utils/native/lite:utils",
]
}
} else {
shared_library("devicemanagerutils") {
}
}
} else {
config("devicemanagerutils_config") {
+5
View File
@@ -28,10 +28,15 @@ namespace OHOS {
namespace DistributedHardware {
int32_t GenRandInt(int32_t randMin, int32_t randMax)
{
#if defined(__LITEOS_M__)
srandom(time(NULL));
return (randMin + random() % (randMax - randMin));
#else
std::random_device randDevice;
std::mt19937 genRand(randDevice());
std::uniform_int_distribution<int> disRand(randMin, randMax);
return disRand(genRand);
#endif
}
int64_t GenRandLongLong(int64_t randMin, int64_t randMax)