diff --git a/interfaces_mini/inner_kits/native_cpp/include/dm_device_info.h b/interfaces_mini/inner_kits/native_cpp/include/dm_device_info.h new file mode 100644 index 0000000000000000000000000000000000000000..26088b8bbdb2771f2d1c9e1bc4cee6748b58907d --- /dev/null +++ b/interfaces_mini/inner_kits/native_cpp/include/dm_device_info.h @@ -0,0 +1,69 @@ +/* + * 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_DEVICE_INFO_H +#define OHOS_DEVICE_MANAGER_DEVICE_INFO_H + +#include + +#include "dm_app_image_info.h" + +#define DM_MAX_DEVICE_ID_LEN (96) +#define DM_MAX_DEVICE_NAME_LEN (128) + +namespace OHOS { +namespace DistributedHardware { +typedef enum DmDeviceType { + DEVICE_TYPE_UNKNOWN = 0x00, + DEVICE_TYPE_WIFI_CAMERA = 0x08, + DEVICE_TYPE_AUDIO = 0x0A, + DEVICE_TYPE_PC = 0x0C, + DEVICE_TYPE_PHONE = 0x0E, + DEVICE_TYPE_PAD = 0x11, + DEVICE_TYPE_WATCH = 0x6D, + DEVICE_TYPE_CAR = 0x83, + DEVICE_TYPE_TV = 0x9C, +} DmDeviceType; + +typedef enum DmDeviceState { + DEVICE_STATE_UNKNOWN = -1, + DEVICE_STATE_ONLINE = 0, + DEVICE_INFO_READY = 1, + DEVICE_STATE_OFFLINE = 2, + DEVICE_INFO_CHANGED = 3, +} DmDeviceState; + +typedef struct DmDeviceInfo { + char deviceId[DM_MAX_DEVICE_ID_LEN]; + char deviceName[DM_MAX_DEVICE_NAME_LEN]; + uint16_t deviceTypeId; + char networkId[DM_MAX_DEVICE_ID_LEN]; +} DmDeviceInfo; + +typedef struct DmAuthParam { + std::string authToken; + std::string packageName; + std::string appName; + std::string appDescription; + int32_t authType; + int32_t business; + int32_t pincode; + int32_t direction; + int32_t pinToken; + DmAppImageInfo imageinfo; +} DmAuthParam; +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DEVICE_MANAGER_DEVICE_INFO_H diff --git a/services/devicemanagerservice/BUILD.gn b/services/devicemanagerservice/BUILD.gn index 8ea80487db2761496c69d9de0679e847440e1049..e26b6230b0e39fde97a5b958104e8867abc30d2c 100755 --- a/services/devicemanagerservice/BUILD.gn +++ b/services/devicemanagerservice/BUILD.gn @@ -20,8 +20,105 @@ 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_mini/inner_kits/native_cpp/include", + "${devicemanager_path}/interfaces_mini/inner_kits/native_cpp/include/notify", + "${services_path}/include", + "${services_path}/include/config", + "${services_path}/include/config/mini", + "${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/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", + ] + + 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/multipleuser/mini/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/server_stub.cpp", + "${services_path}/src/dispatch/device_manager_service_listener_mini.cpp", + ] + + defines = [ + "LITE_DEVICE", + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"devicemanagerservice\"", + "LOG_DOMAIN=0xD004100", + ] + + ldflags = dm_ldflags + + deps = [ + "${devicemanager_path}/interfaces_mini/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") { diff --git a/services/devicemanagerservice/include/authentication/auth_ui.h b/services/devicemanagerservice/include/authentication/auth_ui.h index 4ba96cb50c9680afaa424212760915ad8bf64968..e7473332c92d0f644874e82d3321aa2ccebdd9ab 100644 --- a/services/devicemanagerservice/include/authentication/auth_ui.h +++ b/services/devicemanagerservice/include/authentication/auth_ui.h @@ -17,7 +17,7 @@ #define OHOS_DM_AUTH_UI_H #include - +#include #include "dm_ability_manager.h" namespace OHOS { diff --git a/services/devicemanagerservice/include/config/dm_config_manager.h b/services/devicemanagerservice/include/config/dm_config_manager.h index 4a410a1e7616838f97b01a2380f923a0e92366aa..d2082a7b79daff7539f464f9cde278c0d6bb4324 100644 --- a/services/devicemanagerservice/include/config/dm_config_manager.h +++ b/services/devicemanagerservice/include/config/dm_config_manager.h @@ -19,7 +19,9 @@ #include #include #include +#if (defined(__LINUX__) || defined(__LITEOS_A__)) #include +#endif #include #include #include @@ -66,10 +68,12 @@ private: DmConfigManager(); private: +#if (defined(__LINUX__) || defined(__LITEOS_A__)) std::mutex authAdapterMutex_; std::mutex cryptoAdapterMutex_; std::mutex decisionAdapterMutex_; std::mutex profileAdapterMutex_; +#endif std::map soAuthLoadInfo_; std::map soAdapterLoadInfo_; std::map> decisionAdapterPtr_; diff --git a/services/devicemanagerservice/include/config/mini/pin_auth.h b/services/devicemanagerservice/include/config/mini/pin_auth.h new file mode 100644 index 0000000000000000000000000000000000000000..9ea428d77684bc0371de6dc23d28beb684246dfa --- /dev/null +++ b/services/devicemanagerservice/include/config/mini/pin_auth.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_DM_PIN_AUTH_H +#define OHOS_DM_PIN_AUTH_H + +#include +#include + +#include "authentication.h" +#include "dm_auth_manager.h" +#include "dm_ability_manager.h" + +namespace OHOS { +namespace DistributedHardware { +class PinAuth : public IAuthentication { +public: + PinAuth(); + ~PinAuth(); + int32_t ShowAuthInfo(std::string &authToken, std::shared_ptr authManager) override; + int32_t StartAuth(std::string &authToken, std::shared_ptr authManager) override; + int32_t VerifyAuthentication(std::string &authToken, const std::string &authParam) override; + +private: + int32_t times_ = 0; +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DM_PIN_AUTH_H diff --git a/services/devicemanagerservice/include/dependency/hichain/hichain_connector.h b/services/devicemanagerservice/include/dependency/hichain/hichain_connector.h index 6c19fe3fd23f4a89671d3f865536ea078b3104f2..b8aa3708c7264cb36f6b264c782f20a3a9c81723 100644 --- a/services/devicemanagerservice/include/dependency/hichain/hichain_connector.h +++ b/services/devicemanagerservice/include/dependency/hichain/hichain_connector.h @@ -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(); diff --git a/services/devicemanagerservice/include/dependency/softbus/softbus_connector.h b/services/devicemanagerservice/include/dependency/softbus/softbus_connector.h index a957f42a83d211cfe2e686401bc6fa317c027f99..47193cf25a4c6b1ffede3bad5d54f8e3a9d14e81 100644 --- a/services/devicemanagerservice/include/dependency/softbus/softbus_connector.h +++ b/services/devicemanagerservice/include/dependency/softbus/softbus_connector.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); diff --git a/services/devicemanagerservice/include/dependency/softbus/softbus_session.h b/services/devicemanagerservice/include/dependency/softbus/softbus_session.h index 2eab337e692ca65a2ae63244959faa744c7c644c..a62cbc0373270c92353e7cf510230917235258d8 100644 --- a/services/devicemanagerservice/include/dependency/softbus/softbus_session.h +++ b/services/devicemanagerservice/include/dependency/softbus/softbus_session.h @@ -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(); diff --git a/services/devicemanagerservice/include/dependency/timer/dm_timer.h b/services/devicemanagerservice/include/dependency/timer/dm_timer.h index a4ffec0fdddc84600365578547bde4c5f67e169c..1c8bd16807bc6bfdf71645d67c642eb5faa8b979 100644 --- a/services/devicemanagerservice/include/dependency/timer/dm_timer.h +++ b/services/devicemanagerservice/include/dependency/timer/dm_timer.h @@ -18,12 +18,13 @@ #include #include #include +#if (defined(__LINUX__) || defined(__LITEOS_A__)) #include +#include #include - +#endif #include #include -#include #include "dm_log.h" @@ -60,10 +61,12 @@ private: TimeoutHandle mHandle_; void *mHandleData_; int32_t mTimeFd_[2]; +#if (defined(__LINUX__) || defined(__LITEOS_A__)) struct epoll_event mEv_; struct epoll_event mEvents_[MAX_EVENTS]; int32_t mEpFd_; std::thread mThread_; +#endif std::string mTimerName_; }; } // namespace DistributedHardware diff --git a/services/devicemanagerservice/include/device_manager_service_listener.h b/services/devicemanagerservice/include/device_manager_service_listener.h index e52d9ed7300ed939a0f626fbe4d316c76f908377..0c989491fc8a76812adc4f57d92c3fd05ebd5be3 100644 --- a/services/devicemanagerservice/include/device_manager_service_listener.h +++ b/services/devicemanagerservice/include/device_manager_service_listener.h @@ -20,8 +20,11 @@ #include #include "dm_device_info.h" +#if (defined(__LINUX__) || defined(__LITEOS_A__)) #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 ¶mJson); private: +#if (defined(__LINUX__) || defined(__LITEOS_A__)) IpcServerListener ipcServerListener_; +#endif }; } // namespace DistributedHardware } // namespace OHOS diff --git a/services/devicemanagerservice/include/devicestate/dm_device_state_manager.h b/services/devicemanagerservice/include/devicestate/dm_device_state_manager.h index 7817313fc7a3af962550f2886f9560afa8ee4cbc..b814324c1166f1dc91fbcddf2421d39f8fb00c8b 100755 --- a/services/devicemanagerservice/include/devicestate/dm_device_state_manager.h +++ b/services/devicemanagerservice/include/devicestate/dm_device_state_manager.h @@ -18,8 +18,11 @@ #include #include +#if (defined(__LINUX__) || defined(__LITEOS_A__)) #include - +#else +#include +#endif #include "device_manager_service_listener.h" #include "dm_adapter_manager.h" #include "softbus_connector.h" @@ -54,8 +57,12 @@ public: private: std::string profileSoName_; +#if (defined(__LINUX__) || defined(__LITEOS_A__)) std::mutex timerMapMutex_; std::mutex remoteDeviceInfosMutex_; +#else + pthread_mutex_t lock_; +#endif std::shared_ptr softbusConnector_; std::shared_ptr listener_; std::map remoteDeviceInfos_; diff --git a/services/devicemanagerservice/include/dispatch/authenticate_device_req.h b/services/devicemanagerservice/include/dispatch/authenticate_device_req.h new file mode 100644 index 0000000000000000000000000000000000000000..4bc90cfdd207d104978b5490a6e06ad1f903fe1b --- /dev/null +++ b/services/devicemanagerservice/include/dispatch/authenticate_device_req.h @@ -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 diff --git a/services/devicemanagerservice/include/dispatch/command_dispatch.h b/services/devicemanagerservice/include/dispatch/command_dispatch.h new file mode 100644 index 0000000000000000000000000000000000000000..f4683e737aaa8c03cfbde485725d17986c13c12d --- /dev/null +++ b/services/devicemanagerservice/include/dispatch/command_dispatch.h @@ -0,0 +1,39 @@ +/* + * 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 +#include +#include +#include "single_instance.h" +#include "message_req.h" +#include "message_rsp.h" + + + +namespace OHOS { +namespace DistributedHardware { + +class CommandDispatch { +DECLARE_SINGLE_INSTANCE(CommandDispatch); +public: + int32_t CmdProcessing(int32_t cmdCode, std::shared_ptr req, std::shared_ptr rsp); + int32_t MessageSendCmd(int32_t cmdCode, std::shared_ptr req, std::shared_ptr rsp); +}; +} +} +#endif \ No newline at end of file diff --git a/services/devicemanagerservice/include/dispatch/get_authenticationparam_rsp.h b/services/devicemanagerservice/include/dispatch/get_authenticationparam_rsp.h new file mode 100644 index 0000000000000000000000000000000000000000..b66e73d029c85cd7eeef2cc60274f41dbf95ad38 --- /dev/null +++ b/services/devicemanagerservice/include/dispatch/get_authenticationparam_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_AUTH_PARAM_RSP_H +#define OHOS_DEVICE_MANAGER_GET_AUTH_PARAM_RSP_H + +#include "message_rsp.h" +#include "dm_device_info.h" + +namespace OHOS { +namespace DistributedHardware { +class GetAuthParamRsp : public MessageRsp { +DECLARE_MESSAGE_MODEL(GetAuthParamRsp); +public: + const DmAuthParam& GetAuthParam() const + { + return authParam_; + } + + void SetAuthParam(DmAuthParam &authParam) + { + authParam_ = authParam; + } +private: + DmAuthParam authParam_; +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DEVICE_MANAGER_GET_AUTH_PARAM_RSP_H \ No newline at end of file diff --git a/services/devicemanagerservice/include/dispatch/get_dmfaparam_rsp.h b/services/devicemanagerservice/include/dispatch/get_dmfaparam_rsp.h new file mode 100644 index 0000000000000000000000000000000000000000..9126d2c3d4feb05a8634bce2ec9576052e893a22 --- /dev/null +++ b/services/devicemanagerservice/include/dispatch/get_dmfaparam_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_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 \ No newline at end of file diff --git a/services/devicemanagerservice/include/dispatch/get_info_by_network_req.h b/services/devicemanagerservice/include/dispatch/get_info_by_network_req.h new file mode 100644 index 0000000000000000000000000000000000000000..0b75fef007f1154f649c9784a6b5739a7978102f --- /dev/null +++ b/services/devicemanagerservice/include/dispatch/get_info_by_network_req.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 \ No newline at end of file diff --git a/services/devicemanagerservice/include/dispatch/get_info_by_network_rsp.h b/services/devicemanagerservice/include/dispatch/get_info_by_network_rsp.h new file mode 100644 index 0000000000000000000000000000000000000000..4ce591a444e9fa8abc06720dd525558a0244333b --- /dev/null +++ b/services/devicemanagerservice/include/dispatch/get_info_by_network_rsp.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 + +#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 \ No newline at end of file diff --git a/services/devicemanagerservice/include/dispatch/get_local_device_info_rsp.h b/services/devicemanagerservice/include/dispatch/get_local_device_info_rsp.h new file mode 100644 index 0000000000000000000000000000000000000000..9db77ebc45a929c8cf6ac1e05f2da27f84e518ae --- /dev/null +++ b/services/devicemanagerservice/include/dispatch/get_local_device_info_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_DM_IPC_GET_LOCAL_DEVICE_INFO_RSP_H \ No newline at end of file diff --git a/services/devicemanagerservice/include/dispatch/get_trustdevice_req.h b/services/devicemanagerservice/include/dispatch/get_trustdevice_req.h new file mode 100644 index 0000000000000000000000000000000000000000..c4f4fca14e8c373495b3bdabe181d25f8fb475c9 --- /dev/null +++ b/services/devicemanagerservice/include/dispatch/get_trustdevice_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_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 diff --git a/services/devicemanagerservice/include/dispatch/get_trustdevice_rsp.h b/services/devicemanagerservice/include/dispatch/get_trustdevice_rsp.h new file mode 100644 index 0000000000000000000000000000000000000000..7b9bef074782313e8462767e43b1d5c43af0697b --- /dev/null +++ b/services/devicemanagerservice/include/dispatch/get_trustdevice_rsp.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 + +#include "dm_device_info.h" + +#include "message_rsp.h" + +namespace OHOS { +namespace DistributedHardware { +class GetTrustDeviceRsp : public MessageRsp { +DECLARE_MESSAGE_MODEL(GetTrustDeviceRsp); +public: + std::vector GetDeviceVec() const + { + return deviceVec_; + } + + void SetDeviceVec(std::vector& deviceVec) + { + deviceVec_ = deviceVec; + } +private: + std::vector deviceVec_; +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DEVICE_MANAGER_GET_TRUSTDEVICE_RSP_H diff --git a/services/devicemanagerservice/include/dispatch/message_def.h b/services/devicemanagerservice/include/dispatch/message_def.h new file mode 100644 index 0000000000000000000000000000000000000000..06e443a7dadbd81f9b53437c664cacad1ed4fcbe --- /dev/null +++ b/services/devicemanagerservice/include/dispatch/message_def.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 diff --git a/services/devicemanagerservice/include/dispatch/message_req.h b/services/devicemanagerservice/include/dispatch/message_req.h new file mode 100644 index 0000000000000000000000000000000000000000..d8b438a112890ad4a9184424ae0f8d470d9a16fe --- /dev/null +++ b/services/devicemanagerservice/include/dispatch/message_req.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 + +#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 diff --git a/services/devicemanagerservice/include/dispatch/message_rsp.h b/services/devicemanagerservice/include/dispatch/message_rsp.h new file mode 100644 index 0000000000000000000000000000000000000000..ab2c2f0700d65a8653fc24a8de3e11352f267306 --- /dev/null +++ b/services/devicemanagerservice/include/dispatch/message_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_MESSAGE_RSP_H +#define OHOS_DEVICE_MANAGER_MESSAGE_RSP_H + +#include + +#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_RSP_H diff --git a/services/devicemanagerservice/include/dispatch/server_stub.h b/services/devicemanagerservice/include/dispatch/server_stub.h new file mode 100644 index 0000000000000000000000000000000000000000..9667dba08d0dd6f7757d5d308433430d70c57a72 --- /dev/null +++ b/services/devicemanagerservice/include/dispatch/server_stub.h @@ -0,0 +1,23 @@ +/* + * 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 +#include +#include + +#endif // OHOS_DEVICE_MANAGER_IPC_SERVER_STUB_H diff --git a/services/devicemanagerservice/include/dispatch/set_useroperation_req.h b/services/devicemanagerservice/include/dispatch/set_useroperation_req.h new file mode 100644 index 0000000000000000000000000000000000000000..c60e61d0ac0eb2c8ba7a7307a09f93a9eadcaf73 --- /dev/null +++ b/services/devicemanagerservice/include/dispatch/set_useroperation_req.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 GetOperationReq : public MessageReq { +DECLARE_MESSAGE_MODEL(GetOperationReq); +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 diff --git a/services/devicemanagerservice/include/dispatch/start_discovery_req.h b/services/devicemanagerservice/include/dispatch/start_discovery_req.h new file mode 100644 index 0000000000000000000000000000000000000000..fd88596f51b8ae98ffa28a360d40e9ac5459dac7 --- /dev/null +++ b/services/devicemanagerservice/include/dispatch/start_discovery_req.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 \ No newline at end of file diff --git a/services/devicemanagerservice/include/dispatch/stop_discovery_req.h b/services/devicemanagerservice/include/dispatch/stop_discovery_req.h new file mode 100644 index 0000000000000000000000000000000000000000..16afa9333cb50b2edab3d81f5350cbc9effb8c62 --- /dev/null +++ b/services/devicemanagerservice/include/dispatch/stop_discovery_req.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_STOP_DISCOVERY_REQ_H +#define OHOS_DEVICE_MANAGER_STOP_DISCOVERY_REQ_H + +#include + +#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 diff --git a/services/devicemanagerservice/include/dispatch/unauthenticate_device_req.h b/services/devicemanagerservice/include/dispatch/unauthenticate_device_req.h new file mode 100644 index 0000000000000000000000000000000000000000..bc00e17cf0d6c02de3ca63aebe56ff6d58fc6516 --- /dev/null +++ b/services/devicemanagerservice/include/dispatch/unauthenticate_device_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 diff --git a/services/devicemanagerservice/include/dispatch/verify_authenticate_req.h b/services/devicemanagerservice/include/dispatch/verify_authenticate_req.h new file mode 100644 index 0000000000000000000000000000000000000000..1ad6dda657966aa0b8a3e3e217da7ccf9139266f --- /dev/null +++ b/services/devicemanagerservice/include/dispatch/verify_authenticate_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_CHECK_AUTHENTICATE_REQ_H diff --git a/services/devicemanagerservice/src/config/mini/dm_config_manager.cpp b/services/devicemanagerservice/src/config/mini/dm_config_manager.cpp new file mode 100644 index 0000000000000000000000000000000000000000..63bc1df57cd5643339dad767193b65b1e8e8c236 --- /dev/null +++ b/services/devicemanagerservice/src/config/mini/dm_config_manager.cpp @@ -0,0 +1,67 @@ +/* + * 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 DmConfigManager::GetDecisionAdapter(const std::string &soName) +{ + return nullptr; +} + +std::shared_ptr DmConfigManager::GetProfileAdapter(const std::string &soName) +{ + return nullptr; +} + +std::shared_ptr DmConfigManager::GetCryptoAdapter(const std::string &soName) +{ + return nullptr; +} + +extern "C" IAuthentication *CreatePinAuthObject(void) +{ + return new PinAuth; +} + +void DmConfigManager::GetAuthAdapter(std::map> &authAdapter) +{ + authAdapter.clear(); + std::shared_ptr iAuthentication(CreatePinAuthObject()); + authAdapter[1] = iAuthentication; +} +} // namespace DistributedHardware +} // namespace OHOS \ No newline at end of file diff --git a/services/devicemanagerservice/src/config/mini/pin_auth.cpp b/services/devicemanagerservice/src/config/mini/pin_auth.cpp new file mode 100644 index 0000000000000000000000000000000000000000..37a6b8c3fa8c6d1066822240b347dde99e97fd93 --- /dev/null +++ b/services/devicemanagerservice/src/config/mini/pin_auth.cpp @@ -0,0 +1,55 @@ +/* + * 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 + +#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 authManager) +{ + LOGI("ShowConfigDialog end"); + return DM_OK; +} + +int32_t PinAuth::StartAuth(std::string &authToken, std::shared_ptr authManager) +{ + LOGI("StartAuth end"); + return DM_OK; +} + +int32_t PinAuth::VerifyAuthentication(std::string &authToken, const std::string &authParam) +{ + LOGI("VerifyAuthentication end"); + return DM_OK; +} + +} // namespace DistributedHardware +} // namespace OHOS diff --git a/services/devicemanagerservice/src/dependency/hichain/hichain_connector.cpp b/services/devicemanagerservice/src/dependency/hichain/hichain_connector.cpp index b2a5bdfc17ac556048689c8f567b186b21d451fb..974b8291390f2063c7af63fb6421ff1cabbd794e 100644 --- a/services/devicemanagerservice/src/dependency/hichain/hichain_connector.cpp +++ b/services/devicemanagerservice/src/dependency/hichain/hichain_connector.cpp @@ -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); diff --git a/services/devicemanagerservice/src/dependency/multipleuser/mini/multiple_user_connector.cpp b/services/devicemanagerservice/src/dependency/multipleuser/mini/multiple_user_connector.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ebb38c73e584a752976951c67a6766d4b9c95a5c --- /dev/null +++ b/services/devicemanagerservice/src/dependency/multipleuser/mini/multiple_user_connector.cpp @@ -0,0 +1,37 @@ +/* + * 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 "multiple_user_connector.h" + +namespace OHOS { +namespace DistributedHardware { +int32_t MultipleUserConnector::oldUserId_ = -1; + +int32_t MultipleUserConnector::GetCurrentAccountUserID(void) +{ + return 0; +} + +void MultipleUserConnector::SetSwitchOldUserId(int32_t userId) +{ + oldUserId_ = userId; +} + +int32_t MultipleUserConnector::GetSwitchOldUserId(void) +{ + return oldUserId_; +} +} // namespace DistributedHardware +} // namespace OHOS diff --git a/services/devicemanagerservice/src/dependency/softbus/softbus_connector.cpp b/services/devicemanagerservice/src/dependency/softbus/softbus_connector.cpp index 40f6707ccff6f44e2c9430af44c6c3331166db42..9449d8182923c4d42beeb01b479780234cdfc00b 100644 --- a/services/devicemanagerservice/src/dependency/softbus/softbus_connector.cpp +++ b/services/devicemanagerservice/src/dependency/softbus/softbus_connector.cpp @@ -17,8 +17,12 @@ #include #include +#if (defined(__LINUX__) || defined(__LITEOS_A__)) #include #include +#else +#include +#endif #include "dm_anonymous.h" #include "dm_constants.h" @@ -49,6 +53,7 @@ INodeStateCb SoftbusConnector::softbusNodeStateCb_ = { .onNodeOffline = SoftbusConnector::OnSoftbusDeviceOffline, .onNodeBasicInfoChanged = SoftbusConnector::OnSoftbusDeviceInfoChanged}; +#if (defined(__LINUX__) || defined(__LITEOS_A__)) void DeviceOnLine(std::map> stateCallbackMap, DmDeviceInfo deviceInfo) { @@ -72,6 +77,67 @@ void DeviceOffLine(std::map> } LOGI("Device off line end"); } +#else +void DeviceOnLine(std::map> stateCallbackMap, + DmDeviceInfo deviceInfo) +{ + LOGI("Device on line start"); + pthread_mutex_t lockDeviceOnLine; + uint32_t ret = pthread_mutex_init(&lockDeviceOnLine, NULL); + if (ret != 0) { + LOGI("init mutex lock failed: %d.",ret); + } + pthread_mutex_lock(&lockDeviceOnLine); + for (auto &iter : stateCallbackMap) { + iter.second->OnDeviceOnline(iter.first, deviceInfo); + } + pthread_mutex_unlock(&lockDeviceOnLine); + ret = pthread_mutex_destroy(&lockDeviceOnLine); + if (ret != 0) { + LOGI("destroy mutex lock failed: %d.",ret); + } + LOGI("Device on line end"); +} + +void DeviceOffLine(std::map> stateCallbackMap, + DmDeviceInfo deviceInfo) +{ + LOGI("Device off line start"); + pthread_mutex_t lockDeviceOffLine; + uint32_t ret = pthread_mutex_init(&lockDeviceOffLine, NULL); + if (ret != 0) { + LOGI("init mutex lock failed: %d.",ret); + } + pthread_mutex_lock(&lockDeviceOffLine); + for (auto &iter : stateCallbackMap) { + iter.second->OnDeviceOffline(iter.first, deviceInfo); + } + pthread_mutex_unlock(&lockDeviceOffLine); + ret = pthread_mutex_destroy(&lockDeviceOffLine); + if (ret != 0) { + LOGI("destroy mutex lock failed: %d.",ret); + } + LOGI("Device off line end"); +} +struct PthreadCallbackParameter{ + std::map> CallbackMap; + DmDeviceInfo dmDeviceInfo; +}; + +void* PthreadDeviceOnLine(void* parameterInfo) +{ + PthreadCallbackParameter *parameterStruct; + parameterStruct = static_cast(parameterInfo); + DeviceOnLine(parameterStruct->CallbackMap, parameterStruct->dmDeviceInfo); +} + +void* PthreadDeviceOffLine(void* parameterInfo) +{ + PthreadCallbackParameter *parameterStruct; + parameterStruct = static_cast(parameterInfo); + DeviceOffLine(parameterStruct->CallbackMap, parameterStruct->dmDeviceInfo); +} +#endif SoftbusConnector::SoftbusConnector() { @@ -107,6 +173,7 @@ int32_t SoftbusConnector::Init() dmPublishInfo.capabilityData = nullptr; dmPublishInfo.dataLen = 0; +#if (defined(__LINUX__) || defined(__LITEOS_A__)) 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 +200,11 @@ 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); +#else + ret = PublishService(DM_PKG_NAME.c_str(), &dmPublishInfo, &softbusPublishCallback_); + LOGI("service publish result is : %d", ret); +#endif return ret; } @@ -448,12 +519,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); } @@ -466,10 +537,21 @@ void SoftbusConnector::OnSoftBusDeviceOnline(NodeBasicInfo *info) return; } +#if (defined(__LINUX__) || defined(__LITEOS_A__)) DmDeviceInfo dmDeviceInfo; CovertNodeBasicInfoToDmDevice(*info, dmDeviceInfo); std::thread deviceOnLine(DeviceOnLine, stateCallbackMap_, dmDeviceInfo); deviceOnLine.detach(); +#else + PthreadCallbackParameter parameterStruct; + parameterStruct.CallbackMap = stateCallbackMap_; + CovertNodeBasicInfoToDmDevice(*info, parameterStruct.dmDeviceInfo); + pthread_t tid; + pthread_attr_t attr; + pthread_attr_init(&attr); + pthread_attr_setdetachstate(&attr,PTHREAD_CREATE_DETACHED); + pthread_create(&tid, &attr, PthreadDeviceOnLine, static_cast(¶meterStruct)); +#endif if (discoveryDeviceInfoMap_.empty()) { return; @@ -493,10 +575,21 @@ void SoftbusConnector::OnSoftbusDeviceOffline(NodeBasicInfo *info) LOGE("OnSoftbusDeviceOffline NodeBasicInfo is nullptr"); return; } +#if (defined(__LINUX__) || defined(__LITEOS_A__)) DmDeviceInfo dmDeviceInfo; CovertNodeBasicInfoToDmDevice(*info, dmDeviceInfo); std::thread deviceOffLine(DeviceOffLine, stateCallbackMap_, dmDeviceInfo); deviceOffLine.detach(); +#else + PthreadCallbackParameter parameterStruct; + parameterStruct.CallbackMap = stateCallbackMap_; + CovertNodeBasicInfoToDmDevice(*info, parameterStruct.dmDeviceInfo); + pthread_t tid; + pthread_attr_t attr; + pthread_attr_init(&attr); + pthread_attr_setdetachstate(&attr,PTHREAD_CREATE_DETACHED); + pthread_create(&tid, &attr, PthreadDeviceOffLine, static_cast(¶meterStruct)); +#endif } void SoftbusConnector::OnSoftbusDeviceInfoChanged(NodeBasicInfoType type, NodeBasicInfo *info) @@ -534,7 +627,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 +636,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); diff --git a/services/devicemanagerservice/src/dependency/softbus/softbus_session.cpp b/services/devicemanagerservice/src/dependency/softbus/softbus_session.cpp index 8d4b557953fa548a78dfe196ba68d5d453c8fdd7..df6fb2fb0031cf3ddefa4691f283ead32f08383d 100644 --- a/services/devicemanagerservice/src/dependency/softbus/softbus_session.cpp +++ b/services/devicemanagerservice/src/dependency/softbus/softbus_session.cpp @@ -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) { diff --git a/services/devicemanagerservice/src/dependency/timer/mini/dm_timer.cpp b/services/devicemanagerservice/src/dependency/timer/mini/dm_timer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b14a07695c27d35577d83615e355507b1a74c5c5 --- /dev/null +++ b/services/devicemanagerservice/src/dependency/timer/mini/dm_timer.cpp @@ -0,0 +1,75 @@ +/* + * 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" + +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; + } + + LOGI("DmTimer %s Construct", name.c_str()); +} + +DmTimer::~DmTimer() +{ + if (mTimerName_.empty()) { + LOGI("DmTimer is not init"); + return; + } + LOGI("DmTimer %s Destroy in", mTimerName_.c_str()); +} + +DmTimerStatus DmTimer::Start(uint32_t timeOut, TimeoutHandle handle, void *data) +{ + LOGI("DmTimer start timeout(%d)", timeOut); + mStatus_ = DmTimerStatus::DM_STATUS_RUNNING; + return mStatus_; +} + +void DmTimer::Stop(int32_t code) +{ + LOGI("DmTimer Stop code (%d)", code); + return; +} + +void DmTimer::WaitForTimeout() +{ + +} + +int32_t DmTimer::CreateTimeFd() +{ + return 0; +} + +void DmTimer::Release() +{ + +} + +std::string DmTimer::GetTimerName() +{ + return mTimerName_; +} +} // namespace DistributedHardware +} // namespace OHOS diff --git a/services/devicemanagerservice/src/device_manager_service.cpp b/services/devicemanagerservice/src/device_manager_service.cpp index cda681629c4ac9db5dee1f4785e55dff8109a551..ae5891e3877392cc209b30b9ab9607f342fe4318 100644 --- a/services/devicemanagerservice/src/device_manager_service.cpp +++ b/services/devicemanagerservice/src/device_manager_service.cpp @@ -17,16 +17,18 @@ #include -#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(__LINUX__) || defined(__LITEOS_A__)) +#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(__LINUX__) || defined(__LITEOS_A__)) 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(__LINUX__) || defined(__LITEOS_A__)) 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; diff --git a/services/devicemanagerservice/src/devicestate/dm_device_state_manager.cpp b/services/devicemanagerservice/src/devicestate/dm_device_state_manager.cpp index 1cef6db5644e8e04a502580e21820ae27e4a98a5..22f4fec9a8f7d2a9a12eee13aa457b52a1c0dadb 100755 --- a/services/devicemanagerservice/src/devicestate/dm_device_state_manager.cpp +++ b/services/devicemanagerservice/src/devicestate/dm_device_state_manager.cpp @@ -39,6 +39,12 @@ DmDeviceStateManager::DmDeviceStateManager(std::shared_ptr sof std::shared_ptr listener, std::shared_ptr hiChainConnector) : softbusConnector_(softbusConnector), listener_(listener), hiChainConnector_(hiChainConnector) { +#if defined(__LITEOS_M__) + uint32_t ret = pthread_mutex_init(&lock_, NULL); + if (ret != 0) { + LOGI("init mutex lock failed: %d.",ret); + } +#endif profileSoName_ = "libdevicemanagerext_profile.z.so"; decisionSoName_ = "libdevicemanagerext_decision.z.so"; LOGI("DmDeviceStateManager constructor"); @@ -47,6 +53,12 @@ DmDeviceStateManager::DmDeviceStateManager(std::shared_ptr sof DmDeviceStateManager::~DmDeviceStateManager() { LOGI("DmDeviceStateManager destructor"); +#if defined(__LITEOS_M__) + uint32_t ret = pthread_mutex_destroy(&lock_); + if (ret != 0) { + LOGI("destroy mutex lock failed: %d.",ret); + } +#endif if (softbusConnector_ != nullptr) { softbusConnector_->UnRegisterSoftbusStateCallback("DM_PKG_NAME"); } @@ -64,8 +76,14 @@ int32_t DmDeviceStateManager::RegisterProfileListener(const std::string &pkgName DmDeviceInfo saveInfo = info; SoftbusConnector::GetUuidByNetworkId(info.deviceId, uuid); { +#if (defined(__LINUX__) || defined(__LITEOS_A__)) std::lock_guard mutexLock(remoteDeviceInfosMutex_); remoteDeviceInfos_[uuid] = saveInfo; +#else + pthread_mutex_lock(&lock_); + remoteDeviceInfos_[uuid] = saveInfo; + pthread_mutex_unlock(&lock_); +#endif } LOGI("RegisterProfileListener in, deviceId = %s, deviceUdid = %s, uuid = %s", info.deviceId, deviceUdid.c_str(), uuid.c_str()); @@ -84,10 +102,19 @@ int32_t DmDeviceStateManager::UnRegisterProfileListener(const std::string &pkgNa profileAdapter->UnRegisterProfileListener(pkgName); } { + +#if (defined(__LINUX__) || defined(__LITEOS_A__)) std::lock_guard mutexLock(remoteDeviceInfosMutex_); if (remoteDeviceInfos_.find(std::string(info.deviceId)) != remoteDeviceInfos_.end()) { remoteDeviceInfos_.erase(std::string(info.deviceId)); } +#else + pthread_mutex_lock(&lock_); + if (remoteDeviceInfos_.find(std::string(info.deviceId)) != remoteDeviceInfos_.end()) { + remoteDeviceInfos_.erase(std::string(info.deviceId)); + } + pthread_mutex_unlock(&lock_); +#endif } return DM_OK; } @@ -193,6 +220,7 @@ void DmDeviceStateManager::OnProfileReady(const std::string &pkgName, const std: } DmDeviceInfo saveInfo; { +#if (defined(__LINUX__) || defined(__LITEOS_A__)) std::lock_guard mutexLock(remoteDeviceInfosMutex_); auto iter = remoteDeviceInfos_.find(deviceId); if (iter == remoteDeviceInfos_.end()) { @@ -200,6 +228,16 @@ void DmDeviceStateManager::OnProfileReady(const std::string &pkgName, const std: return; } saveInfo = iter->second; +#else + pthread_mutex_lock(&lock_); + auto iter = remoteDeviceInfos_.find(deviceId); + if (iter == remoteDeviceInfos_.end()) { + LOGE("OnProfileReady complete not find deviceId: %s", GetAnonyString(deviceId).c_str()); + return; + } + saveInfo = iter->second; + pthread_mutex_unlock(&lock_); +#endif } if (listener_ != nullptr) { DmDeviceState state = DEVICE_INFO_READY; @@ -242,7 +280,8 @@ void DmDeviceStateManager::RegisterOffLineTimer(const DmDeviceInfo &deviceInfo) return; } LOGI("Register OffLine Timer with device: %s", GetAnonyString(deviceId).c_str()); - + +#if (defined(__LINUX__) || defined(__LITEOS_A__)) std::lock_guard mutexLock(timerMapMutex_); deviceinfoMap_[deviceInfo.deviceId] = deviceId; auto iter = timerMap_.find(deviceId); @@ -254,6 +293,20 @@ void DmDeviceStateManager::RegisterOffLineTimer(const DmDeviceInfo &deviceInfo) if (offLineTimer != nullptr) { timerMap_[deviceId] = offLineTimer; } +#else + pthread_mutex_lock(&lock_); + deviceinfoMap_[deviceInfo.deviceId] = deviceId; + auto iter = timerMap_.find(deviceId); + if (iter != timerMap_.end()) { + iter->second->Stop(SESSION_CANCEL_TIMEOUT); + return; + } + std::shared_ptr offLineTimer = std::make_shared(deviceId); + if (offLineTimer != nullptr) { + timerMap_[deviceId] = offLineTimer; + } + pthread_mutex_unlock(&lock_); +#endif } void DmDeviceStateManager::StartOffLineTimer(const DmDeviceInfo &deviceInfo) @@ -263,13 +316,24 @@ void DmDeviceStateManager::StartOffLineTimer(const DmDeviceInfo &deviceInfo) return; } + LOGI("start offline timer with device: %s", GetAnonyString(deviceinfoMap_[deviceInfo.deviceId]).c_str()); +#if (defined(__LINUX__) || defined(__LITEOS_A__)) std::lock_guard mutexLock(timerMapMutex_); for (auto &iter : timerMap_) { if (iter.first == deviceinfoMap_[deviceInfo.deviceId]) { iter.second->Start(OFFLINE_TIMEOUT, TimeOut, this); } } +#else + pthread_mutex_lock(&lock_); + for (auto &iter : timerMap_) { + if (iter.first == deviceinfoMap_[deviceInfo.deviceId]) { + iter.second->Start(OFFLINE_TIMEOUT, TimeOut, this); + } + } + pthread_mutex_unlock(&lock_); +#endif deviceinfoMap_.erase(deviceInfo.deviceId); } diff --git a/services/devicemanagerservice/src/dispatch/command_dispatch.cpp b/services/devicemanagerservice/src/dispatch/command_dispatch.cpp new file mode 100644 index 0000000000000000000000000000000000000000..328ca5aa1c3c6be6582ecaf2fe7e1ef26bff27aa --- /dev/null +++ b/services/devicemanagerservice/src/dispatch/command_dispatch.cpp @@ -0,0 +1,209 @@ +/* + * 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 "set_useroperation_req.h" +#include "authenticate_device_req.h" +#include "verify_authenticate_req.h" +#include "get_authenticationparam_rsp.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, std::shared_ptr req, std::shared_ptr rsp) +{ + if (req == nullptr || rsp == nullptr) { + LOGE("Message req or rsp is null."); + return DM_INVALID_VALUE; + } + int32_t ret = CommandDispatch::CmdProcessing(cmdCode, req, rsp); + if (ret != DM_OK) { + LOGE("MessageSendCmd Failed with ret: %d", ret); + return ret; + } + return DM_OK; +} + +int32_t CommandDispatch::CmdProcessing(int32_t cmdCode, std::shared_ptr req, std::shared_ptr rsp) +{ + int32_t ret = 1; + LOGI("SendCmd:%d", cmdCode); + switch (cmdCode) { + case GET_TRUST_DEVICE_LIST: { + std::shared_ptr pReq = std::static_pointer_cast(req); + std::shared_ptr prsp = std::static_pointer_cast(rsp); + std::string pkgName = pReq->GetPkgName(); + std::string extra = pReq->GetExtra(); + + LOGI("enter GetTrustedDeviceList"); + std::vector deviceList; + ret = DeviceManagerService::GetInstance().GetTrustedDeviceList(pkgName, extra, deviceList); + prsp->SetDeviceVec(deviceList); + prsp->SetErrCode(ret); + break; + } + case GET_LOCAL_DEVICE_INFO: { + std::shared_ptr pRsp = std::static_pointer_cast(rsp); + DmDeviceInfo dmDeviceInfo = {0}; + ret = DeviceManagerService::GetInstance().GetLocalDeviceInfo(dmDeviceInfo); + DmDeviceInfo *Info = &dmDeviceInfo; + if (Info != nullptr) { + pRsp->SetLocalDeviceInfo(dmDeviceInfo); + } + pRsp->SetErrCode(ret); + break; + } + case GET_UDID_BY_NETWORK: { + std::shared_ptr pReq = std::static_pointer_cast(req); + std::shared_ptr pRsp = std::static_pointer_cast(rsp); + std::string pkgName = pReq->GetPkgName(); + std::string netWorkId = pReq->GetNetWorkId(); + std::string udid; + + ret = DeviceManagerService::GetInstance().GetUdidByNetworkId(pkgName, netWorkId, udid); + pRsp->SetUdid(udid); + pRsp->SetErrCode(ret); + break; + } + case GET_UUID_BY_NETWORK: { + std::shared_ptr pReq = std::static_pointer_cast(req); + std::shared_ptr pRsp = std::static_pointer_cast(rsp); + std::string pkgName = pReq->GetPkgName(); + std::string netWorkId = pReq->GetNetWorkId(); + std::string uuid; + + ret = DeviceManagerService::GetInstance().GetUuidByNetworkId(pkgName, netWorkId, uuid); + pRsp->SetUuid(uuid); + pRsp->SetErrCode(ret); + break; + } + case START_DEVICE_DISCOVER: { + std::shared_ptr pReq = std::static_pointer_cast(req); + std::string pkgName = pReq->GetPkgName(); + std::string extra = pReq->GetExtra(); + const DmSubscribeInfo dmSubscribeInfo = pReq->GetSubscribeInfo(); + LOGI("StartDeviceDiscovery service"); + + ret = DeviceManagerService::GetInstance().StartDeviceDiscovery(pkgName, dmSubscribeInfo, extra); + rsp->SetErrCode(ret); + break; + } + case STOP_DEVICE_DISCOVER: { + LOGI("StopDeviceDiscovery service"); + + std::shared_ptr pReq = std::static_pointer_cast(req); + std::string pkgName = pReq->GetPkgName(); + uint16_t subscribeId = pReq->GetSubscribeId(); + + ret = DeviceManagerService::GetInstance().StopDeviceDiscovery(pkgName, subscribeId); + rsp->SetErrCode(ret); + break; + } + case SERVER_USER_AUTH_OPERATION: { + std::shared_ptr pReq = std::static_pointer_cast(req); + std::string pkgName= pReq->GetPkgName(); + int32_t action = pReq->GetOperation(); + + LOGI("enter server user authorization operation."); + + ret = DeviceManagerService::GetInstance().SetUserOperation(pkgName, action); + rsp->SetErrCode(ret); + break; + } + case SERVER_GET_DMFA_INFO: { + std::shared_ptr pReq = std::static_pointer_cast(req); + std::shared_ptr pRsp = std::static_pointer_cast(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()); + + ret = DeviceManagerService::GetInstance().GetFaParam(pkgName, authParam); + pRsp->SetDmAuthParam(authParam); + pRsp->SetErrCode(ret); + break; + } + case AUTHENTICATE_DEVICE: { + std::shared_ptr pReq = std::static_pointer_cast(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()); + + ret = DeviceManagerService::GetInstance().AuthenticateDevice(pkgName, authType, deviceId, extra); + rsp->SetErrCode(ret); + break; + } + case UNAUTHENTICATE_DEVICE: { + std::shared_ptr pReq = std::static_pointer_cast(req); + std::string pkgName = pReq->GetPkgName(); + DmDeviceInfo deviceInfo = pReq->GetDeviceInfo(); + std::string deviceId = deviceInfo.deviceId; + + LOGI("enter server user authorization operation."); + ret = DeviceManagerService::GetInstance().UnAuthenticateDevice(pkgName, deviceId); + rsp->SetErrCode(ret); + break; + } + case VERIFY_AUTHENTICATION: { + std::shared_ptr pReq = std::static_pointer_cast(req); + std::string pkgName = pReq->GetPkgName(); + std::string authParam = pReq->GetAuthPara(); + + LOGI("DeviceManagerStub:: VERIFY_AUTHENTCATION:pkgName:%s", pkgName.c_str()); + + ret = DeviceManagerService::GetInstance().VerifyAuthentication(authParam); + rsp->SetErrCode(ret); + break; + } + + default: + break; + } + return ret; +} +} +} \ No newline at end of file diff --git a/services/devicemanagerservice/src/dispatch/device_manager_service_listener_mini.cpp b/services/devicemanagerservice/src/dispatch/device_manager_service_listener_mini.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7cee13f5e12137d3ad54a97cc7fe90f91bf52f66 --- /dev/null +++ b/services/devicemanagerservice/src/dispatch/device_manager_service_listener_mini.cpp @@ -0,0 +1,98 @@ +/* + * 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" + +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 pkgNameList = DeviceManagerNotify::GetInstance().GetPkgNameList(); + for( auto pkgName : pkgNameList) { + DmDeviceState deviceState = static_cast(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, nullptr, 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 pkgNameList = DeviceManagerNotify::GetInstance().GetPkgNameList(); + for( auto pkgName : pkgNameList) { + DeviceManagerNotify::GetInstance().OnVerifyAuthResult(pkgName, deviceId, resultCode, flag); + } +} + +void DeviceManagerServiceListener::OnFaCall(std::string &pkgName, std::string ¶mJson) +{ + LOGI("call OnFaCall in"); + DeviceManagerNotify::GetInstance().OnFaCall(pkgName, paramJson); +} +} // namespace DistributedHardware +} // namespace OHOS diff --git a/services/devicemanagerservice/src/dispatch/server_stub.cpp b/services/devicemanagerservice/src/dispatch/server_stub.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c8d3746f38941b7be25e4cde6601d4fc31e2dc6e --- /dev/null +++ b/services/devicemanagerservice/src/dispatch/server_stub.cpp @@ -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 "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);