diff --git a/ext/mini/BUILD.gn b/ext/mini/BUILD.gn deleted file mode 100644 index 428327db065c3b21c8800e7f07468d3713321b0c..0000000000000000000000000000000000000000 --- a/ext/mini/BUILD.gn +++ /dev/null @@ -1,35 +0,0 @@ -# Copyright (c) 2022 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") - - if (ohos_kernel_type == "liteos_m") { - lite_component("devicemanager_mini") { - features = [ - "utils:devicemanagerutils_mini", - "services/devicemanagerservice:devicemanagerservice_mini", - "interfaces_small/inner_kits/native_cpp:devicemanagersdk_mini", - "interfaces_small/kits/js:devicemanager_native_js", - ] - } - } else { - lite_component("devicemanager_lite") { - features = [ - "utils:devicemanagerutils", - "services/devicemanagerservice:devicemanagerservice", - "interfaces/inner_kits/native_cpp:devicemanagersdk", - ] - } - } -} diff --git a/ext/mini/common/include/constants.h b/ext/mini/common/include/constants.h deleted file mode 100644 index c76fa643a9fb58260a5aff0d5ae8c0706d1bf408..0000000000000000000000000000000000000000 --- a/ext/mini/common/include/constants.h +++ /dev/null @@ -1,167 +0,0 @@ -/* - * Copyright (c) 2022 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_CONSTANTS_H -#define OHOS_DEVICE_MANAGER_CONSTANTS_H - -#include -#include - -namespace OHOS { -namespace DistributedHardware { - const std::string TARGET_PKG_NAME_KEY = "targetPkgName"; - const std::string HOST_PKG_NAME_KEY = "hostPackageName"; - - const int32_t LOG_MAX_LEN = 512; - const int32_t MIN_PIN_TOKEN = 10000000; - const int32_t MAX_PIN_TOKEN = 90000000; - const int32_t MIN_PIN_CODE = 100000; - const int32_t MAX_PIN_CODE = 999999; - const int32_t TOKEN_LEN = 9; - - const int32_t FAIL = -1; - const int32_t SUCCESS = 0; - const int32_t ERROR_INPUT_PARA_EMPTY = 2000; - const int32_t ERROR_INPUT_PARA_INVALID = 2001; - const int32_t ERROR_TARGET_PKG_NAME_NULL = 2002; - const int32_t ERROR_PKG_NAME_NOT_ON_DISCOVERY = 2003; - const int32_t ERROR_START_REMOTE_DM = 2006; - const int32_t ERROR_OPEN_CHANNEL_FAIL = 2008; - const int32_t ERROR_SEND_COMMAND_FAIL = 2009; - const int32_t ERROR_CHANNEL_BROKEN = 2010; - const int32_t ERROR_DUPLICATE_REQUEST = 2011; - const int32_t ERROR_TIME_OUT = 2012; - const int32_t ERROR_REQUEST_CANCEL = 2013; - const int32_t ERROR_USER_REJECT = 2015; - const int32_t ERROR_USER_BUSY = 2016; - const int32_t ERROR_API_NOT_SUPPORT = 2018; - const int32_t ERROR_SESSION_NOT_EXIT = 2019; - const int32_t ERROR_CREAT_GROUP_FAIL = 2020; - const int32_t ERROR_JOIN_GROUP_FAIL = 2021; - const int32_t ERROR_GET_LOCAL_DEVICE_INFO_FAIL = 2022; - const int32_t ERROR_CHECK_AUTH_FAIL = 2023; - const int32_t ERROR_NETWORK_UNAVAILABLE = 2028; - const int32_t ERROR_DEVICE_INFO_NULL = 2030; - const int32_t ERROR_APP_NAME_NULL = 2031; - const int32_t ERROR_APP_DESCRIPTION_INVALID = 2032; - const int32_t ERROR_APP_ICON_INVALID = 2033; - const int32_t ERROR_APP_THUMBNAIL_INVALID = 2034; - const int32_t ERROR_FA_START_FAIL = 2100; - - const int32_t ENCRYPT_TAG_LEN = 32; - - const std::string TAG_REQUESTER = "REQUESTER"; - const std::string TAG_TOKEN = "TOKEN"; - const std::string TAG_HOST = "HOST"; - const std::string TAG_TARGET = "TARGET"; - const std::string TAG_VISIBILITY = "VISIBILITY"; - const std::string TAG_GROUPIDS = "GROUPIDLIST"; - const std::string TAG_REPLY = "REPLY"; - const std::string TAG_NET_ID = "NETID"; - const std::string TAG_GROUP_ID = "GROUPID"; - const std::string TAG_GROUP_NAME = "GROUPNAME"; - const std::string TAG_REQUEST_ID = "REQUESTID"; - const std::string TAG_DEVICE_ID = "DEVICEID"; - const std::string TAG_DEVICE_TYPE = "DEVICETYPE"; - const std::string TAG_APP_NAME = "APPNAME"; - const std::string TAG_APP_DESCRIPTION = "APPDESC"; - const std::string TAG_APP_ICON = "APPICON"; - const std::string TAG_APP_THUMBNAIL = "APPTHUM"; - const std::string TAG_INDEX = "INDEX"; - const std::string TAG_SLICE_NUM = "SLICE"; - const std::string TAG_THUMBNAIL_SIZE = "THUMSIZE"; - const std::string TAG_AUTH_TYPE = "AUTHTYPE"; - - const std::string TAG_VER = "ITF_VER"; - const std::string TAG_TYPE = "MSG_TYPE"; - const std::string DM_ITF_VER = "1.0"; - const std::string TAG = "DM_MSG_CODEC"; - - // GroupConstants - const int32_t GROUP_VISIBILITY_IS_PUBLIC = -1; - const int32_t GROUP_VISIBILITY_IS_PRIVATE = 0; - const std::string REQUEST_AUTH_ADD_ID = "REQUEST_AUTH_ADD_ID"; - const std::string INVITATE_AUTH_ADD_ID = "INVITE_AUTH_ADD_ID"; - const int32_t PIN_CODE_INVALID = -1; - - // AuthConstants - const int32_t AUTH_SESSION_SIDE_SERVER = 0; - const int32_t AUTH_SESSION_SIDE_CLIENT = 1; - const int32_t SESSION_TYPE_IS_DEVICE_AUTH = 0; - const int32_t SESSION_TYPE_IS_APP_AUTH = 1; - const int32_t SESSION_REPLY_UNKNOWN = -1; - const int32_t SESSION_REPLY_ACCEPT = 0; - const int32_t SESSION_REPLY_CANCEL = 1; - const int32_t SESSION_REPLY_TIMEOUT = 2; - const int32_t SESSION_REPLY_AUTH_CONFIRM_TIMEOUT = 2; - const int32_t SESSION_REPLY_CANCEL_PINCODE_DISPLAY = 3; - const int32_t SESSION_REPLY_CANCEL_PINCODE_INPUT = 4; - const int32_t SESSION_REPLY_CREAT_GROUP_FAILED = 7; - const int32_t REQUEST_OPERATION = 0; - const int32_t QR_OPERATION = 1; - const int32_t PIN_OPERATION = 2; - const int32_t START_ACTIVITY_DIALOG = 1; - const int32_t START_ACTIVITY_QR = 2; - const int32_t START_ACTIVITY_FINISH = 3; - const int32_t START_ACTIVITY_PIN = 4; - const int32_t AUTH_STATUS_SKIP = 3; - const int32_t DEFAULT_PIN_CODE = 0; - const int32_t DEFAULT_PIN_TOKEN = 0; - const std::string DEVICE_NAME_KEY = "deviceName"; - const std::string DISPLAY_TIME_KEY = "displayTime"; - const std::string QR_BITMAP_KEY = "qrBitMap"; - const std::string PIN_CODE_KEY = "pinCode"; - const std::string START_ACTIVITY_KEY = "startActivityType"; - const std::string AUTH_TYPE = "authType"; - const std::string TOKEN = "token"; - const std::string PIN_TOKEN = "pinToken"; - const int32_t MSG_TYPE_TO_REMOTE = 0; - const int32_t MSG_TYPE_TO_CLOSED_CHANNEL = 1; - const std::string APP_NAME_KEY = "appName"; - const std::string APP_DESCRIPTION_KEY = "appDescription"; - const std::string APP_ICON_KEY = "appIcon"; - const std::string APP_THUMBNAIL_KEY = "appThumbnail"; - const std::string CANCEL_DISPLAY_KEY = "cancelPinCodeDisplay"; - const int32_t SLICE_NUM_INVALID = -1; - const int32_t AUTH_TYPE_QR = 0; - const int32_t AUTH_TYPE_PIN = 1; - const std::string DISPLAY_OWNER = "displayOwner"; - const int32_t DISPLAY_OWNER_SYSTEM = 0; - const int32_t DISPLAY_OWNER_OTHER = 1; - - // DmService constants - const int32_t MSG_MAX_SIZE = 45 * 1024; - const int32_t DES_SLICE_MAX_NUM = 5; - const int32_t ABILITY_ON = 1; - const int32_t ABILITY_INVALID = -1; - const int32_t DES_MAX_LEN = 256; - const int32_t ICON_MAX_LEN = 32 * 1024; - const int32_t THUMB_MAX_LEN = 153 * 1024; - - const int32_t DEVICE_UUID_LENGTH = 65; - const int32_t GROUP_TYPE_IDENTICAL_ACCOUNT_GROUP = 1; - const int32_t GROUP_TYPE_PEER_TO_PEER_GROUP = 256; - - const int32_t GROUP_VISIBILITY_PUBLIC = -1; - - const int32_t BUSINESS_FA_MIRGRATION = 0; - const int32_t BUSINESS_RESOURCE_ACCESS = 1; - - // Base64 Constants - const int32_t BASE64_BYTE_LEN_3 = 3; - const int32_t BASE64_BYTE_LEN_4 = 4; -} -} -#endif diff --git a/ext/mini/common/include/device_manager_errno.h b/ext/mini/common/include/device_manager_errno.h deleted file mode 100644 index 5c1dabaaffdcd16cf8bce35c5f8ee134246a112d..0000000000000000000000000000000000000000 --- a/ext/mini/common/include/device_manager_errno.h +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (c) 2022 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_ERRNO_H -#define OHOS_DEVICE_MANAGER_ERRNO_H - -namespace OHOS { -namespace DistributedHardware { -enum { - DEVICEMANAGER_FAILED = (-10000), - DEVICEMANAGER_SERVICE_NOT_READY, - DEVICEMANAGER_DEVICE_ALREADY_TRUSTED, - DEVICEMANAGER_GET_TRUSTED_DEVICE_FAILED, - DEVICEMANAGER_ALREADY_INIT, - DEVICEMANAGER_INIT_FAILED, - DEVICEMANAGER_MALLOC_ERROR, - DEVICEMANAGER_LOCK_ERROR, - DEVICEMANAGER_INVALID_PARAM, - DEVICEMANAGER_INVALID_VALUE, - DEVICEMANAGER_COPY_FAILED, - DEVICEMANAGER_NULLPTR, - DEVICEMANAGER_DISCOVERY_FAILED, - DEVICEMANAGER_FLATTEN_OBJECT, - DEVICEMANAGER_WRITE_FAILED, - DEVICEMANAGER_IPC_FAILED, - DEVICEMANAGER_IPC_TRANSACTION_FAILED, - DEVICEMANAGER_IPC_NOT_REGISTER_FUNC, - HICHAIN_GROUP_CREATE_FAILED, - HICHAIN_MEMBER_ADD_FAILED, - HICHAIN_CREATE_CHANNEL_FAILED, - MSG_DECODE_PARA_FAILED, - ENCRYPT_UTILS_INVALID_PARAM, - ENCRYPT_UTILS_GCM_SETKEY_FAILED, - ENCRYPT_UTILS_GCM_CRYPT_FAILED, - ENCRYPT_UTILS_GCM_AUTH_DECRYPT_FAILED, - ENCRYPT_UTILS_AES_GCM_ENCRYPT_FAILED, - ENCRYPT_UTILS_AES_GCM_DECRYPT_FAILED, - ERR_GEN_RANDOM_PINTOKEN_FAILED, - PIN_CODE_CHECK_FAILED, - PIN_TOKEN_CHECK_FAILED, - DEVICEMANAGER_CREATE_SESSION_SERVER_FAILED, - DEVICEMANAGER_OPEN_SESSION_FAILED, - AUTH_PARA_INVALID, - ENCODE_DATA_ERROR, - DEVICEMANAGER_OK = 0 -}; -} // namespace DistributedHardware -} // namespace OHOS -#endif // OHOS_DEVICE_MANAGER_ERRNO_H diff --git a/ext/mini/common/include/device_manager_log.h b/ext/mini/common/include/device_manager_log.h deleted file mode 100644 index ced26f8b8c8daf36e526e8c1c90af8b24f21f3e2..0000000000000000000000000000000000000000 --- a/ext/mini/common/include/device_manager_log.h +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (c) 2022 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_LOG_H -#define OHOS_DEVICE_MANAGER_LOG_H - -#include - -#include "dm_log.h" - -namespace OHOS { -namespace DistributedHardware { -#define DMLOG(level, fmt, ...) DMLog(level, \ - (std::string("[") + DH_LOG_TAG + "][" + __FUNCTION__ + "]:" + fmt).c_str(), ##__VA_ARGS__) -} // namespace DistributedHardware -} // namespace OHOS -#endif // OHOS_DEVICE_MANAGER_LOG_H diff --git a/ext/mini/common/include/ipc/ipc_def.h b/ext/mini/common/include/ipc/ipc_def.h deleted file mode 100644 index 1424cf80687161c0873fb9a4224fe4f6dab9be40..0000000000000000000000000000000000000000 --- a/ext/mini/common/include/ipc/ipc_def.h +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (c) 2022 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_IPC_DEF_H -#define DEVICE_MANAGER_IPC_DEF_H - -namespace OHOS { -namespace DistributedHardware { -#define DEVICE_MANAGER_SERVICE_NAME "dev_mgr_svc" -#define MAX_DM_IPC_LEN 2048 - -#define DECLARE_IPC_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_IPC_INTERFACE(className) \ - DECLARE_IPC_MODEL(className) - -enum IpcCmdID { - REGISTER_DEVICE_MANAGER_LISTENER = 0, - UNREGISTER_DEVICE_MANAGER_LISTENER, - GET_TRUST_DEVICE_LIST, - START_DEVICE_DISCOVER, - STOP_DEVICE_DISCOVER, - AUTHENTICATE_DEVICE, - CHECK_AUTHENTICATION, - SERVER_DEVICE_STATE_NOTIFY, - SERVER_DEVICE_FOUND, - SERVER_DISCOVER_FINISH, - SERVER_AUTH_RESULT, - SERVER_CHECK_AUTH_RESULT, - SERVER_GET_AUTHENTCATION_INFO, - SERVER_USER_AUTHORIZATION_OPERATION, - SERVER_DEVICEMANAGER_FA_NOTIFY, -}; -} // namespace DistributedHardware -} // namespace OHOS -#endif // DEVICE_MANAGER_IPC_DEF_H diff --git a/ext/mini/common/include/ipc/model/ipc_authenticate_device_req.h b/ext/mini/common/include/ipc/model/ipc_authenticate_device_req.h deleted file mode 100644 index 8223833f7087c0825fb3dbef4a506cd16fea7dcf..0000000000000000000000000000000000000000 --- a/ext/mini/common/include/ipc/model/ipc_authenticate_device_req.h +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (c) 2022 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_IPC_AUTHENTICATE_DEVICE_REQ_H -#define OHOS_DEVICE_MANAGER_IPC_AUTHENTICATE_DEVICE_REQ_H - -#include "ipc_req.h" - -#include "dm_device_info.h" -#include "dm_app_image_info.h" - -namespace OHOS { -namespace DistributedHardware { -class IpcAuthenticateDeviceReq : public IpcReq { -DECLARE_IPC_MODEL(IpcAuthenticateDeviceReq); -public: - const DmDeviceInfo& GetDeviceInfo() const - { - return deviceInfo_; - } - - void SetDeviceInfo(const DmDeviceInfo &deviceInfo) - { - deviceInfo_ = deviceInfo; - } - - const DmAppImageInfo& GetAppImageInfo() const - { - return appImageInfo_; - } - - void SetAppImageInfo(const DmAppImageInfo &appImageInfo) - { - appImageInfo_ = appImageInfo; - } - - const std::string& GetExtra() const - { - return extra_; - } - - void SetExtra(std::string &extra) - { - extra_ = extra; - } -private: - DmDeviceInfo deviceInfo_; - DmAppImageInfo appImageInfo_; - std::string extra_; -}; -} // namespace DistributedHardware -} // namespace OHOS -#endif // OHOS_DEVICE_MANAGER_IPC_AUTHENTICATE_DEVICE_REQ_H diff --git a/ext/mini/common/include/ipc/model/ipc_check_authenticate_req.h b/ext/mini/common/include/ipc/model/ipc_check_authenticate_req.h deleted file mode 100644 index 555c956d607da7a30f97d4d02a3aee7a53059039..0000000000000000000000000000000000000000 --- a/ext/mini/common/include/ipc/model/ipc_check_authenticate_req.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (c) 2022 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_IPC_CHECK_AUTHENTICATE_REQ_H -#define OHOS_DEVICE_MANAGER_IPC_CHECK_AUTHENTICATE_REQ_H - -#include "ipc_req.h" - -namespace OHOS { -namespace DistributedHardware { -class IpcCheckAuthenticateReq : public IpcReq { -DECLARE_IPC_MODEL(IpcCheckAuthenticateReq); -public: - const std::string& GetAuthPara() const - { - return authPara_; - } - - void SetAuthPara(std::string &authPara) - { - authPara_ = authPara; - } -private: - std::string authPara_; -}; -} // namespace DistributedHardware -} // namespace OHOS -#endif // OHOS_DEVICE_MANAGER_IPC_CHECK_AUTHENTICATE_REQ_H diff --git a/ext/mini/common/include/ipc/model/ipc_get_authenticationparam_rsp.h b/ext/mini/common/include/ipc/model/ipc_get_authenticationparam_rsp.h deleted file mode 100644 index cd452337a44dcdc0e9e9fa198cf32a83c2ca3a61..0000000000000000000000000000000000000000 --- a/ext/mini/common/include/ipc/model/ipc_get_authenticationparam_rsp.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) 2022 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_IPC_GET_AUTH_PARAM_RSP_H -#define OHOS_DEVICE_MANAGER_IPC_GET_AUTH_PARAM_RSP_H - -#include "ipc_rsp.h" -#include "dm_device_info.h" - -namespace OHOS { -namespace DistributedHardware { -class IpcGetAuthParamRsp : public IpcRsp { -DECLARE_IPC_MODEL(IpcGetAuthParamRsp); -public: - const DmAuthParam& GetAuthParam() const - { - return authParam_; - } - - void SetAuthParam(DmAuthParam &authParam) - { - authParam_ = authParam; - } -private: - DmAuthParam authParam_; -}; -} // namespace DistributedHardware -} // namespace OHOS -#endif // OHOS_DEVICE_MANAGER_IPC_GET_AUTH_PARAM_RSP_H \ No newline at end of file diff --git a/ext/mini/common/include/ipc/model/ipc_get_trustdevice_req.h b/ext/mini/common/include/ipc/model/ipc_get_trustdevice_req.h deleted file mode 100644 index 4b4ac632a05a91bf986f60ad6554f3570e1131f8..0000000000000000000000000000000000000000 --- a/ext/mini/common/include/ipc/model/ipc_get_trustdevice_req.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (c) 2022 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_IPC_GET_TRUST_DEVICE_REQ_H -#define OHOS_DEVICE_MANAGER_IPC_GET_TRUST_DEVICE_REQ_H - -#include "ipc_req.h" - -namespace OHOS { -namespace DistributedHardware { -class IpcGetTrustdeviceReq : public IpcReq { -DECLARE_IPC_MODEL(IpcGetTrustdeviceReq); -public: - const std::string& GetExtra() const - { - return extra_; - } - - void SetExtra(std::string &extra) - { - extra_ = extra; - } -private: - std::string extra_; -}; -} // namespace DistributedHardware -} // namespace OHOS -#endif // OHOS_DEVICE_MANAGER_IPC_GET_TRUST_DEVICE_REQ_H diff --git a/ext/mini/common/include/ipc/model/ipc_get_trustdevice_rsp.h b/ext/mini/common/include/ipc/model/ipc_get_trustdevice_rsp.h deleted file mode 100644 index 836d97d977c9ab725a0468fffc41326f0b4f14cf..0000000000000000000000000000000000000000 --- a/ext/mini/common/include/ipc/model/ipc_get_trustdevice_rsp.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2022 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_IPC_GET_TRUSTDEVICE_RSP_H -#define OHOS_DEVICE_MANAGER_IPC_GET_TRUSTDEVICE_RSP_H - -#include - -#include "dm_device_info.h" - -#include "ipc_rsp.h" - -namespace OHOS { -namespace DistributedHardware { -class IpcGetTrustdeviceRsp : public IpcRsp { -DECLARE_IPC_MODEL(IpcGetTrustdeviceRsp); -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_IPC_GET_TRUSTDEVICE_RSP_H diff --git a/ext/mini/common/include/ipc/model/ipc_notify_auth_result_req.h b/ext/mini/common/include/ipc/model/ipc_notify_auth_result_req.h deleted file mode 100644 index 27a912946920e9d3040b298ae79322605696777d..0000000000000000000000000000000000000000 --- a/ext/mini/common/include/ipc/model/ipc_notify_auth_result_req.h +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (c) 2022 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_IPC_NOTIFY_AUTH_RESULT_REQ_H -#define OHOS_DEVICE_MANAGER_IPC_NOTIFY_AUTH_RESULT_REQ_H - -#include - -#include "ipc_req.h" - -namespace OHOS { -namespace DistributedHardware { -class IpcNotifyAuthResultReq : public IpcReq { -DECLARE_IPC_MODEL(IpcNotifyAuthResultReq); -public: - std::string GetDeviceId() const - { - return deviceId_; - } - - void SetDeviceId(std::string& deviceId) - { - deviceId_ = deviceId; - } - - int32_t GetPinToken() const - { - return pinToken_; - } - - void SetPinToken(int32_t pinToken) - { - pinToken_ = pinToken; - } - - int32_t GetStatus() const - { - return status_; - } - - void SetStatus(int32_t status) - { - status_ = status; - } - - int32_t GetReason() const - { - return reason_; - } - - void SetReason(int32_t reason) - { - reason_ = reason; - } -private: - std::string deviceId_; - int32_t pinToken_ {0}; - int32_t status_ {0}; - int32_t reason_ {0}; -}; -} // namespace DistributedHardware -} // namespace OHOS -#endif // OHOS_DEVICE_MANAGER_IPC_NOTIFY_AUTH_RESULT_REQ_H diff --git a/ext/mini/common/include/ipc/model/ipc_notify_check_auth_result_req.h b/ext/mini/common/include/ipc/model/ipc_notify_check_auth_result_req.h deleted file mode 100644 index 5fe19b7fafba046e28f53d4805ffa5a307ccbef7..0000000000000000000000000000000000000000 --- a/ext/mini/common/include/ipc/model/ipc_notify_check_auth_result_req.h +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (c) 2022 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_IPC_NOTIFY_CHECK_AUTH_RESULT_REQ_H -#define OHOS_DEVICE_MANAGER_IPC_NOTIFY_CHECK_AUTH_RESULT_REQ_H - -#include - -#include "ipc_req.h" - -namespace OHOS { -namespace DistributedHardware { -class IpcNotifyCheckAuthResultReq : public IpcReq { -DECLARE_IPC_MODEL(IpcNotifyCheckAuthResultReq); -public: - std::string GetDeviceId() const - { - return deviceId_; - } - - void SetDeviceId(std::string& deviceId) - { - deviceId_ = deviceId; - } - - int32_t GetResult() const - { - return result_; - } - - void SetResult(int32_t result) - { - result_ = result; - } - - int32_t GetFlag() const - { - return flag_; - } - - void SetFlag(int32_t flag) - { - flag_ = flag; - } -private: - std::string deviceId_; - int32_t result_ {0}; - int32_t flag_ {0}; -}; -} // namespace DistributedHardware -} // namespace OHOS -#endif // OHOS_DEVICE_MANAGER_IPC_NOTIFY_CHECK_AUTH_RESULT_REQ_H diff --git a/ext/mini/common/include/ipc/model/ipc_notify_device_found_req.h b/ext/mini/common/include/ipc/model/ipc_notify_device_found_req.h deleted file mode 100644 index 063b9e66a9affc78c1767e2f193e7a2a6b074921..0000000000000000000000000000000000000000 --- a/ext/mini/common/include/ipc/model/ipc_notify_device_found_req.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (c) 2022 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_IPC_NOTIFY_DEVICE_FOUND_REQ_H -#define OHOS_DEVICE_MANAGER_IPC_NOTIFY_DEVICE_FOUND_REQ_H - -#include "dm_device_info.h" - -#include "ipc_req.h" - -namespace OHOS { -namespace DistributedHardware { -class IpcNotifyDeviceFoundReq : public IpcReq { -DECLARE_IPC_MODEL(IpcNotifyDeviceFoundReq); -public: - const DmDeviceInfo& GetDeviceInfo() const - { - return dmDeviceInfo_; - } - - void SetDeviceInfo(DmDeviceInfo& dmDeviceInfo) - { - dmDeviceInfo_ = dmDeviceInfo; - } - - uint16_t GetSubscribeId() const - { - return subscribeId_; - } - - void SetSubscribeId(uint16_t subscribeId) - { - subscribeId_ = subscribeId; - } -private: - uint16_t subscribeId_ {0}; - DmDeviceInfo dmDeviceInfo_; -}; -} // namespace DistributedHardware -} // namespace OHOS -#endif // OHOS_DEVICE_MANAGER_IPC_NOTIFY_DEVICE_FOUND_REQ_H diff --git a/ext/mini/common/include/ipc/model/ipc_notify_device_state_req.h b/ext/mini/common/include/ipc/model/ipc_notify_device_state_req.h deleted file mode 100644 index cc833b036f028217bc3aa7d2dfc033d8c0c09fc3..0000000000000000000000000000000000000000 --- a/ext/mini/common/include/ipc/model/ipc_notify_device_state_req.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (c) 2022 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_IPC_NOTIFY_DEVICE_STATE_REQ_H -#define OHOS_DEVICE_MANAGER_IPC_NOTIFY_DEVICE_STATE_REQ_H - -#include "dm_device_info.h" - -#include "ipc_req.h" - -namespace OHOS { -namespace DistributedHardware { -class IpcNotifyDeviceStateReq : public IpcReq { -DECLARE_IPC_MODEL(IpcNotifyDeviceStateReq); -public: - int32_t GetDeviceState() const - { - return deviceState_; - } - - void SetDeviceState(int32_t deviceState) - { - deviceState_ = deviceState; - } - - const DmDeviceInfo& GetDeviceInfo() const - { - return dmDeviceInfo_; - } - - void SetDeviceInfo(DmDeviceInfo& dmDeviceInfo) - { - dmDeviceInfo_ = dmDeviceInfo; - } -private: - int32_t deviceState_ {0}; - DmDeviceInfo dmDeviceInfo_; -}; -} // namespace DistributedHardware -} // namespace OHOS -#endif // OHOS_DEVICE_MANAGER_IPC_NOTIFY_DEVICE_STATE_REQ_H diff --git a/ext/mini/common/include/ipc/model/ipc_notify_discover_result_req.h b/ext/mini/common/include/ipc/model/ipc_notify_discover_result_req.h deleted file mode 100644 index 4b2f1c21fb8216fe0d4c99456a9127fd2ab2e74e..0000000000000000000000000000000000000000 --- a/ext/mini/common/include/ipc/model/ipc_notify_discover_result_req.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (c) 2022 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_IPC_NOTIFY_DISCOVER_RESULT_REQ_H -#define OHOS_DEVICE_MANAGER_IPC_NOTIFY_DISCOVER_RESULT_REQ_H - -#include - -#include "ipc_req.h" - -namespace OHOS { -namespace DistributedHardware { -class IpcNotifyDiscoverResultReq : public IpcReq { -DECLARE_IPC_MODEL(IpcNotifyDiscoverResultReq); -public: - uint16_t GetSubscribeId() const - { - return subscribeId_; - } - - void SetSubscribeId(uint16_t subscribeId) - { - subscribeId_ = subscribeId; - } - - int32_t GetResult() const - { - return result_; - } - - void SetResult(int32_t result) - { - result_ = result; - } -private: - uint16_t subscribeId_ {0}; - int32_t result_ {0}; -}; -} // namespace DistributedHardware -} // namespace OHOS -#endif // OHOS_DEVICE_MANAGER_IPC_NOTIFY_DISCOVER_RESULT_REQ_H diff --git a/ext/mini/common/include/ipc/model/ipc_notify_dmfa_result_req.h b/ext/mini/common/include/ipc/model/ipc_notify_dmfa_result_req.h deleted file mode 100644 index fd437ef369b727ed6314ee3b30e4093ce718670c..0000000000000000000000000000000000000000 --- a/ext/mini/common/include/ipc/model/ipc_notify_dmfa_result_req.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2022 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_IPC_NOTIFY_DMFA_RESULT_REQ_H -#define OHOS_DEVICE_MANAGER_IPC_NOTIFY_DMFA_RESULT_REQ_H - -#include - -#include "ipc_req.h" - -namespace OHOS { -namespace DistributedHardware { -class IpcNotifyDMFAResultReq : public IpcReq { -DECLARE_IPC_MODEL(IpcNotifyDMFAResultReq); -public: - std::string GetJsonParam() const - { - return JsonParam_; - } - - void SetJsonParam(std::string& JsonParam) - { - JsonParam_ = JsonParam; - } -private: - std::string JsonParam_; -}; -} // namespace DistributedHardware -} // namespace OHOS -#endif // OHOS_DEVICE_MANAGER_IPC_NOTIFY_AUTH_RESULT_REQ_H diff --git a/ext/mini/common/include/ipc/model/ipc_register_listener_req.h b/ext/mini/common/include/ipc/model/ipc_register_listener_req.h deleted file mode 100644 index 00c52ece3badc734c7051582c3c480a3eaa5efad..0000000000000000000000000000000000000000 --- a/ext/mini/common/include/ipc/model/ipc_register_listener_req.h +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright (c) 2022 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_IPC_REGISTER_LISTENER_REQ_H -#define OHOS_DEVICE_MANAGER_IPC_REGISTER_LISTENER_REQ_H - -#include "ipc_req.h" - -#ifdef LITE_DEVICE -#include "liteipc_adapter.h" -#else -#include "iremote_stub.h" -#endif - -namespace OHOS { -namespace DistributedHardware { -class IpcRegisterListenerReq : public IpcReq { -DECLARE_IPC_MODEL(IpcRegisterListenerReq); -public: -#ifdef LITE_DEVICE - SvcIdentity GetSvcIdentity() const - { - return svcIdentity_; - } - - void SetSvcIdentity(SvcIdentity svcIdentity) - { - svcIdentity_ = svcIdentity; - } -#else - sptr GetListener() const - { - return listener_; - } - - void SetListener(sptr listener) - { - listener_ = listener; - } -#endif -private: -#ifdef LITE_DEVICE - SvcIdentity svcIdentity_; -#else - sptr listener_; -#endif -}; -} // namespace DistributedHardware -} // namespace OHOS -#endif // OHOS_DEVICE_MANAGER_IPC_REGISTER_LISTENER_REQ_H diff --git a/ext/mini/common/include/ipc/model/ipc_req.h b/ext/mini/common/include/ipc/model/ipc_req.h deleted file mode 100644 index d0deb7929eab486631c6f02ab502b84e65d65548..0000000000000000000000000000000000000000 --- a/ext/mini/common/include/ipc/model/ipc_req.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2022 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_IPC_REQ_H -#define OHOS_DEVICE_MANAGER_IPC_REQ_H - -#include - -#include "ipc_def.h" - -namespace OHOS { -namespace DistributedHardware { -class IpcReq { -DECLARE_IPC_MODEL(IpcReq); -public: - const std::string& GetPkgName() const - { - return pkgName_; - } - - void SetPkgName(std::string &pkgName) - { - pkgName_ = pkgName; - } -private: - std::string pkgName_; -}; -} // namespace DistributedHardware -} // namespace OHOS -#endif // OHOS_DEVICE_MANAGER_IPC_REQ_H diff --git a/ext/mini/common/include/ipc/model/ipc_rsp.h b/ext/mini/common/include/ipc/model/ipc_rsp.h deleted file mode 100644 index d2c0584608b748071ba41263683191527ed5b295..0000000000000000000000000000000000000000 --- a/ext/mini/common/include/ipc/model/ipc_rsp.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2022 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_IPC_RSP_H -#define OHOS_DEVICE_MANAGER_IPC_RSP_H - -#include - -#include "ipc_def.h" - -namespace OHOS { -namespace DistributedHardware { -class IpcRsp { -DECLARE_IPC_MODEL(IpcRsp); -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_IPC_RSP_H diff --git a/ext/mini/common/include/ipc/model/ipc_set_useroperation_req.h b/ext/mini/common/include/ipc/model/ipc_set_useroperation_req.h deleted file mode 100644 index c67d81e621c8a10dacf9ec5c6c529993bbf4d6d0..0000000000000000000000000000000000000000 --- a/ext/mini/common/include/ipc/model/ipc_set_useroperation_req.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) 2022 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_IPC_GET_USER_OPERATION_REQ_H -#define OHOS_DEVICE_MANAGER_IPC_GET_USER_OPERATION_REQ_H -#include "ipc_req.h" -#include "dm_device_info.h" - -namespace OHOS { -namespace DistributedHardware { -class IpcGetOperationReq : public IpcReq { -DECLARE_IPC_MODEL(IpcGetOperationReq); -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_IPC_GET_USER_OPERATION_REQ_H diff --git a/ext/mini/common/include/ipc/model/ipc_start_discovery_req.h b/ext/mini/common/include/ipc/model/ipc_start_discovery_req.h deleted file mode 100644 index 33a4347ad2dac6972c4e1d836b4f857838bfb450..0000000000000000000000000000000000000000 --- a/ext/mini/common/include/ipc/model/ipc_start_discovery_req.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2022 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_IPC_START_DISCOVERY_REQ_H -#define OHOS_DEVICE_MANAGER_IPC_START_DISCOVERY_REQ_H - -#include "ipc_req.h" - -#include "dm_subscribe_info.h" - -namespace OHOS { -namespace DistributedHardware { -class IpcStartDiscoveryReq : public IpcReq { -DECLARE_IPC_MODEL(IpcStartDiscoveryReq); -public: - const DmSubscribeInfo& GetSubscribeInfo() const - { - return subscribeInfo_; - } - - void SetSubscribeInfo(DmSubscribeInfo &subscribeInfo) - { - subscribeInfo_ = subscribeInfo; - } -private: - DmSubscribeInfo subscribeInfo_; -}; -} // namespace DistributedHardware -} // namespace OHOS -#endif // OHOS_DEVICE_MANAGER_IPC_START_DISCOVERY_REQ_H diff --git a/ext/mini/common/include/ipc/model/ipc_stop_discovery_req.h b/ext/mini/common/include/ipc/model/ipc_stop_discovery_req.h deleted file mode 100644 index 21c4f3b62922fadb0e112c085ac8508b309e9670..0000000000000000000000000000000000000000 --- a/ext/mini/common/include/ipc/model/ipc_stop_discovery_req.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2022 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_IPC_STOP_DISCOVERY_REQ_H -#define OHOS_DEVICE_MANAGER_IPC_STOP_DISCOVERY_REQ_H - -#include - -#include "ipc_req.h" - -namespace OHOS { -namespace DistributedHardware { -class IpcStopDiscoveryReq : public IpcReq { -DECLARE_IPC_MODEL(IpcStopDiscoveryReq); -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_IPC_STOP_DISCOVERY_REQ_H diff --git a/ext/mini/common/include/single_instance.h b/ext/mini/common/include/single_instance.h deleted file mode 100644 index be902881e05ffd896d5bccbe88fb81617a730e28..0000000000000000000000000000000000000000 --- a/ext/mini/common/include/single_instance.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2022 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_SINGLE_INSTANCE_H -#define OHOS_DEVICE_MANAGER_SINGLE_INSTANCE_H - -namespace OHOS { -namespace DistributedHardware { -#define DECLARE_SINGLE_INSTANCE_BASE(className) \ -public: \ - static className & GetInstance(); \ -private: \ - className(const className&) = delete; \ - className& operator= (const className&) = delete; \ - className(className&&) = delete; \ - className& operator= (className&&) = delete; \ - - -#define DECLARE_SINGLE_INSTANCE(className) \ - DECLARE_SINGLE_INSTANCE_BASE(className) \ -private: \ - className() = default; \ - ~className() = default; \ - -#define IMPLEMENT_SINGLE_INSTANCE(className) \ -className & className::GetInstance() \ -{ \ - static auto instance = new className(); \ - return *instance; \ -} -}; // namespace DistributedHardware -}; // namespace OHOS - -#endif // OHOS_DEVICE_MANAGER_SINGLE_INSTANCE_H \ No newline at end of file diff --git a/ext/mini/devicemanager.gni b/ext/mini/devicemanager.gni deleted file mode 100644 index bc49acbf91380356d458f8c5d37bbe649291966e..0000000000000000000000000000000000000000 --- a/ext/mini/devicemanager.gni +++ /dev/null @@ -1,28 +0,0 @@ -# Copyright (c) 2022 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. - -#------------------------device manager------------------------------# -devicemanager_path = "//foundation/distributedhardware/devicemanager" - -common_path = "${devicemanager_path}/common" -utils_path = "${devicemanager_path}/utils" -services_path = "${devicemanager_path}/services/devicemanagerservice" -innerkits_path = "${devicemanager_path}/interfaces/inner_kits" -ext_path = "${devicemanager_path}/ext" - -#--------------------------softbus----------------------------------# - -#---------------------------hichan----------------------------------# - -#----------------------compilation options--------------------------# -dm_ldflags = [ "-lpthread" ] diff --git a/ext/mini/figures/devicemanager_zh.png b/ext/mini/figures/devicemanager_zh.png deleted file mode 100644 index 0891790acd1fd75f448e04c0d98ea9fd02e1639a..0000000000000000000000000000000000000000 Binary files a/ext/mini/figures/devicemanager_zh.png and /dev/null differ diff --git a/ext/mini/interfaces_mini/inner_kits/native_cpp/BUILD.gn b/ext/mini/interfaces_mini/inner_kits/native_cpp/BUILD.gn deleted file mode 100644 index 1145709f12ddc863bc6d885835428f9f843265ef..0000000000000000000000000000000000000000 --- a/ext/mini/interfaces_mini/inner_kits/native_cpp/BUILD.gn +++ /dev/null @@ -1,162 +0,0 @@ -# Copyright (c) 2022 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") - -if (defined(ohos_lite)) { - if (ohos_kernel_type == "liteos_m") { - static_library("devicemanagersdk_mini") { - include_dirs = [ - "include", - "include/notify", - "${utils_path}/include/log", - "${common_path}/include", - "//foundation/distributedhardware/devicemanager/services/devicemanagerservice/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 = [ - "src/device_manager.cpp", - "src/device_manager_impl.cpp", - "src/notify/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") { - include_dirs = [ - "include", - "include/ipc", - "include/ipc/lite", - "include/notify", - "${utils_path}/include/log", - "${utils_path}/include/ipc/lite", - "${common_path}/include/ipc", - "${common_path}/include/ipc/model", - "${common_path}/include", - ] - include_dirs += [ - "//utils/native/lite/include", - "//base/hiviewdfx/hilog_lite/interfaces/native/innerkits/hilog", - "//third_party/bounds_checking_function/include", - "//foundation/communication/ipc_lite/interfaces/kits", - "//foundation/distributedschedule/samgr_lite/interfaces/kits/samgr", - "//third_party/json/include", - ] - - sources = [ - "src/device_manager.cpp", - "src/device_manager_impl.cpp", - "src/ipc/ipc_client_proxy.cpp", - "src/ipc/lite/ipc_client_manager.cpp", - "src/ipc/lite/ipc_client_server_proxy.cpp", - "src/ipc/lite/ipc_client_stub.cpp", - "src/ipc/lite/ipc_cmd_parser.cpp", - "src/notify/device_manager_notify.cpp", - ] - - defines = [ - "LITE_DEVICE", - "HI_LOG_ENABLE", - "DH_LOG_TAG=\"devicemanagerkit\"", - "LOG_DOMAIN=0xD004100", - ] - - deps = [ - "${utils_path}:devicemanagerutils", - "//base/hiviewdfx/hilog_lite/frameworks/featured:hilog_shared", - "//foundation/communication/ipc_lite:liteipc_adapter", - "//foundation/distributedschedule/samgr_lite/samgr:samgr", - "//third_party/bounds_checking_function:libsec_shared", - "//utils/native/lite:utils", - ] - } - } -} else { - ohos_shared_library("devicemanagersdk") { - include_dirs = [ - "//utils/native/base/include", - "//utils/system/safwk/native/include", - "include", - "include/ipc/standard", - "include/ipc", - "include/notify", - "${utils_path}/include/log", - "${common_path}/include/ipc", - "${common_path}/include/ipc/model", - "${utils_path}/include/ipc/standard", - "${common_path}/include", - "//third_party/json/include", - ] - - sources = [ - "src/device_manager.cpp", - "src/device_manager_impl.cpp", - "src/ipc/ipc_client_proxy.cpp", - "src/ipc/standard/ipc_client_manager.cpp", - "src/ipc/standard/ipc_client_server_proxy.cpp", - "src/ipc/standard/ipc_client_stub.cpp", - "src/ipc/standard/ipc_cmd_parser.cpp", - "src/notify/device_manager_notify.cpp", - ] - - deps = [ - "${utils_path}:devicemanagerutils", - "//utils/native/base:utils", - ] - - defines = [ - "HI_LOG_ENABLE", - "DH_LOG_TAG=\"devicemanagerkit\"", - "LOG_DOMAIN=0xD004100", - ] - - external_deps = [ - "appexecfwk_standard:appexecfwk_base", - "appexecfwk_standard:appexecfwk_core", - "hiviewdfx_hilog_native:libhilog", - "ipc:ipc_core", - "safwk:system_ability_fwk", - "samgr_standard:samgr_proxy", - ] - - subsystem_name = "distributedhardware" - - part_name = "device_manager_base" - } -} diff --git a/ext/mini/interfaces_mini/inner_kits/native_cpp/include/device_manager.h b/ext/mini/interfaces_mini/inner_kits/native_cpp/include/device_manager.h deleted file mode 100644 index 57f6f4763d9568cd93ec478ef2b21671be046b70..0000000000000000000000000000000000000000 --- a/ext/mini/interfaces_mini/inner_kits/native_cpp/include/device_manager.h +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2022 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_H -#define DEVICE_MANAGER_H - -#include -#include -#include - -#include "device_manager_callback.h" -#include "dm_subscribe_info.h" -#include "dm_app_image_info.h" - -namespace OHOS { -namespace DistributedHardware { -class DeviceManager { -public: - static DeviceManager &GetInstance(); -public: - virtual int32_t InitDeviceManager(std::string &pkgName, std::shared_ptr dmInitCallback) = 0; - virtual int32_t UnInitDeviceManager(std::string &pkgName) = 0; - virtual int32_t GetTrustedDeviceList(std::string &pkgName, std::string &extra, - std::vector &deviceList) = 0; - virtual int32_t RegisterDevStateCallback(std::string &pkgName, std::string &extra, - std::shared_ptr callback) = 0; - virtual int32_t UnRegisterDevStateCallback(std::string &pkgName) = 0; - virtual int32_t StartDeviceDiscovery(std::string &pkgName, DmSubscribeInfo &subscribeInfo, - std::shared_ptr callback) = 0; - virtual int32_t StopDeviceDiscovery(std::string &pkgName, uint16_t subscribeId) = 0; - virtual int32_t AuthenticateDevice(std::string &pkgName, const DmDeviceInfo &deviceInfo, - const DmAppImageInfo &imageInfo, std::string &extra, std::shared_ptr callback) = 0; - virtual int32_t CheckAuthentication(std::string &pkgName, std::string &authPara, - std::shared_ptr callback) = 0; - virtual int32_t GetAuthenticationParam(std::string &pkgName, DmAuthParam &authParam) = 0; - virtual int32_t SetUserOperation(std::string &pkgName, int32_t action) = 0; - virtual int32_t RegisterDeviceManagerFaCallback(std::string &packageName, - std::shared_ptr callback) = 0; - virtual int32_t UnRegisterDeviceManagerFaCallback(std::string &pkgName) = 0; -}; -} // namespace DistributedHardware -} // namespace OHOS -#endif // OHOS_DEVICE_MANAGER_H diff --git a/ext/mini/interfaces_mini/inner_kits/native_cpp/include/device_manager_callback.h b/ext/mini/interfaces_mini/inner_kits/native_cpp/include/device_manager_callback.h deleted file mode 100644 index 4315bec2bda79e0b5a7b56e862cdc87611052f8d..0000000000000000000000000000000000000000 --- a/ext/mini/interfaces_mini/inner_kits/native_cpp/include/device_manager_callback.h +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright (c) 2022 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_CALLBACK_H -#define OHOS_DEVICE_MANAGER_CALLBACK_H - -#include -#include - -#include "dm_device_info.h" - -namespace OHOS { -namespace DistributedHardware { -class DmInitCallback { -public: - virtual ~DmInitCallback() {} - virtual void OnRemoteDied() = 0; -}; - -class DeviceStateCallback { -public: - virtual ~DeviceStateCallback() {} - virtual void OnDeviceOnline(const DmDeviceInfo &deviceInfo) = 0; - virtual void OnDeviceReady(const DmDeviceInfo &deviceInfo) = 0; - virtual void OnDeviceOffline(const DmDeviceInfo &deviceInfo) = 0; - virtual void OnDeviceChanged(const DmDeviceInfo &deviceInfo) = 0; -}; - -class DiscoverCallback { -public: - virtual ~DiscoverCallback() {} - virtual void OnDiscoverySuccess(uint16_t subscribeId) = 0; - virtual void OnDiscoverFailed(uint16_t subscribeId, int32_t failedReason) = 0; - virtual void OnDeviceFound(uint16_t subscribeId, const DmDeviceInfo &deviceInfo) = 0; -}; - -class AuthenticateCallback { -public: - virtual ~AuthenticateCallback() {} - virtual void OnAuthResult(std::string &deviceId, int32_t pinToken, int32_t status, int32_t reason) = 0; -}; - -class CheckAuthCallback { -public: - virtual ~CheckAuthCallback() {} - virtual void OnCheckAuthResult(std::string &deviceId, int32_t resultCode, int32_t flag) = 0; -}; - -class DeviceManagerFaCallback { -public: - virtual ~DeviceManagerFaCallback() {} - virtual void OnCall(std::string ¶mJson) = 0; -}; -} // namespace DistributedHardware -} // namespace OHOS -#endif // OHOS_DEVICE_MANAGER_CALLBACK_H diff --git a/ext/mini/interfaces_mini/inner_kits/native_cpp/include/device_manager_impl.h b/ext/mini/interfaces_mini/inner_kits/native_cpp/include/device_manager_impl.h deleted file mode 100644 index cf14ee62ffd00dc43351ff0d7e1f6140f7c7f04e..0000000000000000000000000000000000000000 --- a/ext/mini/interfaces_mini/inner_kits/native_cpp/include/device_manager_impl.h +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2022 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_IMPL_H -#define OHOS_DEVICE_MANAGER_IMPL_H - -#include -#include -#include "device_manager.h" -#include "single_instance.h" - - -namespace OHOS { -namespace DistributedHardware { -class DeviceManagerImpl : public DeviceManager { -#define DEVICEMANAGER_MESSAGE_FAILED -1 -DECLARE_SINGLE_INSTANCE(DeviceManagerImpl); -public: - virtual int32_t InitDeviceManager(std::string &pkgName, - std::shared_ptr dmInitCallback) override; - virtual int32_t UnInitDeviceManager(std::string &pkgName) override; - virtual int32_t GetTrustedDeviceList(std::string &pkgName, std::string &extra, - std::vector &deviceList) override; - virtual int32_t RegisterDevStateCallback(std::string &pkgName, std::string &extra, - std::shared_ptr callback) override; - virtual int32_t UnRegisterDevStateCallback(std::string &pkgName) override; - virtual int32_t StartDeviceDiscovery(std::string &pkgName, DmSubscribeInfo &subscribeInfo, - std::shared_ptr callback) override; - virtual int32_t StopDeviceDiscovery(std::string &pkgName, uint16_t subscribeId) override; - virtual int32_t AuthenticateDevice(std::string &pkgName, const DmDeviceInfo &deviceInfo, - const DmAppImageInfo &imageInfo, std::string &extra, - std::shared_ptr callback) override; - virtual int32_t CheckAuthentication(std::string &pkgName, std::string &authPara, - std::shared_ptr callback) override; - virtual int32_t GetAuthenticationParam(std::string &pkgName, DmAuthParam &authParam) override; - virtual int32_t SetUserOperation(std::string &pkgName, int32_t action) override; - virtual int32_t RegisterDeviceManagerFaCallback(std::string &packageName, - std::shared_ptr callback) override; - virtual int32_t UnRegisterDeviceManagerFaCallback(std::string &pkgName) override; -}; -} // namespace DistributedHardware -} // namespace OHOS -#endif // OHOS_DEVICE_MANAGER_IMPL_H diff --git a/ext/mini/interfaces_mini/inner_kits/native_cpp/include/dm_app_image_info.h b/ext/mini/interfaces_mini/inner_kits/native_cpp/include/dm_app_image_info.h deleted file mode 100644 index e7ed22281021d78eddb7d7d5922a365aa850b56c..0000000000000000000000000000000000000000 --- a/ext/mini/interfaces_mini/inner_kits/native_cpp/include/dm_app_image_info.h +++ /dev/null @@ -1,183 +0,0 @@ -/* - * Copyright (c) 2022 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_APP_IMAGE_INFO_H -#define OHOS_DEVICE_MANAGER_APP_IMAGE_INFO_H - -#include - -#include "securec.h" - -namespace OHOS { -namespace DistributedHardware { -class DmAppImageInfo { -public: - DmAppImageInfo() = default; - explicit DmAppImageInfo(uint8_t *appIcon_, int32_t appIconLen_, uint8_t *appThumbnail_, int32_t appThumbnailLen_) - { - SaveData(appIcon_, appIconLen_, appThumbnail_, appThumbnailLen_); - } - - void Reset(uint8_t *appIcon_, int32_t appIconLen_, uint8_t *appThumbnail_, int32_t appThumbnailLen_) - { - SaveData(appIcon_, appIconLen_, appThumbnail_, appThumbnailLen_); - } - - void ResetIcon(uint8_t *appIcon_, int32_t appIconLen_) - { - SaveIconData(appIcon_, appIconLen_); - } - - void InitThumbnail(int32_t appThumbnailLen_) - { - if (appThumbnailLen_ <= 0 || appThumbnailLen_ > THUMB_MAX_LEN) { - appThumbnailLen = 0; - appThumbnail = nullptr; - return; - } - - appThumbnail = new (std::nothrow) uint8_t[appThumbnailLen_] {0}; - if (appThumbnail != nullptr) { - appThumbnailLen = appThumbnailLen_; - } - } - - int32_t SetThumbnailData(uint8_t *srcBuffer, int32_t srcBufferLen, int32_t copyIndex, int32_t copyLen) - { - if (srcBuffer == nullptr || srcBufferLen <= 0 || copyLen > srcBufferLen || copyIndex < 0) { - return -1; - } - - if ((copyIndex + copyLen) > appThumbnailLen) { - return -1; - } - - if (appThumbnail == nullptr) { - return -1; - } - - if (memcpy_s(appThumbnail + copyIndex, appThumbnailLen - copyIndex, srcBuffer, copyLen) != 0) { - return -1; - } - - return 0; - } - - ~DmAppImageInfo() - { - if (appIcon != nullptr) { - delete[] appIcon; - appIcon = nullptr; - } - if (appThumbnail != nullptr) { - delete[] appThumbnail; - appThumbnail = nullptr; - } - } - - DmAppImageInfo(const DmAppImageInfo &other) - { - if (this != &other) { - *this = other; - } - } - - DmAppImageInfo& operator=(const DmAppImageInfo &other) - { - if (this != &other) { - SaveData(other.GetAppIcon(), other.GetAppIconLen(), other.GetAppThumbnail(), other.GetAppThumbnailLen()); - } - return *this; - } - - DmAppImageInfo(DmAppImageInfo&&) = delete; - DmAppImageInfo& operator=(DmAppImageInfo&&) = delete; - - int32_t GetAppIconLen() const - { - return appIconLen; - } - - const uint8_t *GetAppIcon() const - { - return appIcon; - } - - int32_t GetAppThumbnailLen() const - { - return appThumbnailLen; - } - - const uint8_t *GetAppThumbnail() const - { - return appThumbnail; - } -private: - void SaveData(const uint8_t *appIcon_, int32_t appIconLen_, const uint8_t *appThumbnail_, int32_t appThumbnailLen_) - { - SaveIconData(appIcon_, appIconLen_); - SaveThumbnailData(appThumbnail_, appThumbnailLen_); - } - - void SaveIconData(const uint8_t *appIcon_, int32_t appIconLen_) - { - if (appIconLen_ > 0 && appIconLen_ < ICON_MAX_LEN && appIcon_ != nullptr) { - if (appIconLen < appIconLen_) { - if (appIcon != nullptr && appIconLen > 0) { - delete[] appIcon; - appIcon = nullptr; - appIconLen = 0; - } - appIcon = new (std::nothrow) uint8_t[appIconLen_] {0}; - } - if (appIcon != nullptr) { - appIconLen = appIconLen_; - if (memcpy_s(appIcon, appIconLen, appIcon_, appIconLen_) != 0) { - return; - } - } - } - } - - void SaveThumbnailData(const uint8_t *appThumbnail_, int32_t appThumbnailLen_) - { - if (appThumbnailLen_ > 0 && appThumbnailLen_ < THUMB_MAX_LEN && appThumbnail_ != nullptr) { - if (appThumbnailLen < appThumbnailLen_) { - if (appThumbnail != nullptr && appThumbnailLen > 0) { - delete[] appThumbnail; - appThumbnail = nullptr; - appThumbnailLen = 0; - } - appThumbnail = new (std::nothrow) uint8_t[appThumbnailLen_] {0}; - } - if (appThumbnail != nullptr) { - appThumbnailLen = appThumbnailLen_; - if (memcpy_s(appThumbnail, appThumbnailLen, appThumbnail_, appThumbnailLen_) != 0) { - return; - } - } - } - } -private: - int32_t appIconLen {0}; - uint8_t *appIcon {nullptr}; - int32_t appThumbnailLen {0}; - uint8_t *appThumbnail {nullptr}; - const int32_t ICON_MAX_LEN = 32 * 1024; - const int32_t THUMB_MAX_LEN = 153 * 1024; -}; -} // namespace DistributedHardware -} // namespace OHOS -#endif // OHOS_DEVICE_MANAGER_APP_IMAGE_INFO_H diff --git a/ext/mini/interfaces_mini/inner_kits/native_cpp/include/dm_device_info.h b/ext/mini/interfaces_mini/inner_kits/native_cpp/include/dm_device_info.h deleted file mode 100644 index 1ff9563e8c9091060d580f28da8632684185ebf6..0000000000000000000000000000000000000000 --- a/ext/mini/interfaces_mini/inner_kits/native_cpp/include/dm_device_info.h +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (c) 2022 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_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 = 0, - DEVICE_STATE_ONLINE = 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]; - DMDeviceType deviceTypeId; -} DmDeviceInfo; - -typedef struct DmAuthParam { - 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/ext/mini/interfaces_mini/inner_kits/native_cpp/include/dm_subscribe_info.h b/ext/mini/interfaces_mini/inner_kits/native_cpp/include/dm_subscribe_info.h deleted file mode 100644 index 46b58d9cd5ad09e371d9eb2dce8ccd4fbfdfffd5..0000000000000000000000000000000000000000 --- a/ext/mini/interfaces_mini/inner_kits/native_cpp/include/dm_subscribe_info.h +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright (c) 2022 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_SUBSCRIBE_INFO_H -#define OHOS_DEVICE_MANAGER_SUBSCRIBE_INFO_H - -#include - -#define DM_MAX_DEVICE_CAPABILITY_LEN 65 - -namespace OHOS { -namespace DistributedHardware { -typedef enum DmDiscoverMode { - /* Passive */ - DM_DISCOVER_MODE_PASSIVE = 0x55, - /* Proactive */ - DM_DISCOVER_MODE_ACTIVE = 0xAA -} DmDiscoverMode; - -typedef enum DmExchangeMedium { - /** Automatic medium selection */ - DM_AUTO = 0, - /** Bluetooth */ - DM_BLE = 1, - /** Wi-Fi */ - DM_COAP = 2, - /** USB */ - DM_USB = 3, - DM_MEDIUM_BUTT -} DmExchangeMedium; - -/** - * @brief Enumerates frequencies for publishing services. - * - * This enumeration applies only to Bluetooth and is not supported currently. - */ -typedef enum DmExchangeFreq { - /** Low */ - DM_LOW = 0, - /** Medium */ - DM_MID = 1, - /** High */ - DM_HIGH = 2, - /** Super-high */ - DM_SUPER_HIGH = 3, - DM_FREQ_BUTT -} DmExchangeFreq; - -typedef struct DmSubscribeInfo { - /** Service ID */ - uint16_t subscribeId; - /** Discovery mode for service subscription. For details, see {@link DmDiscoverMode}. */ - DmDiscoverMode mode; - /** Service subscription medium. For details, see {@link DmExchangeMedium}. */ - DmExchangeMedium medium; - /** Service subscription frequency. For details, see {@link DmExchangeFreq}. */ - DmExchangeFreq freq; - /** only find the device with the same account */ - bool isSameAccount; - /** find the sleeping devices */ - bool isWakeRemote; - /** Service subscription capability. */ - char capability[DM_MAX_DEVICE_CAPABILITY_LEN]; -} DmSubscribeInfo; -} // namespace DistributedHardware -} // namespace OHOS -#endif // OHOS_DEVICE_MANAGER_SUBSCRIBE_INFO_H diff --git a/ext/mini/interfaces_mini/inner_kits/native_cpp/include/notify/device_manager_notify.h b/ext/mini/interfaces_mini/inner_kits/native_cpp/include/notify/device_manager_notify.h deleted file mode 100644 index 0a827574c1526a2e2cbef70d89599d8c4427516b..0000000000000000000000000000000000000000 --- a/ext/mini/interfaces_mini/inner_kits/native_cpp/include/notify/device_manager_notify.h +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright (c) 2022 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_NOTIFY_H -#define OHOS_DEVICE_MANAGER_NOTIFY_H - -#include -#include -#include -#include -#include -#include - -#include "dm_device_info.h" -#include "dm_subscribe_info.h" -#include "device_manager_callback.h" -#include "single_instance.h" - -namespace OHOS { -namespace DistributedHardware { -class DeviceManagerNotify { -DECLARE_SINGLE_INSTANCE(DeviceManagerNotify); -public: - void RegisterDeathRecipientCallback(std::string &pkgName, std::shared_ptr dmInitCallback); - void UnRegisterDeathRecipientCallback(std::string &pkgName); - void RegisterDeviceStateCallback(std::string &pkgName, std::shared_ptr callback); - void UnRegisterDeviceStateCallback(std::string &pkgName); - void RegisterDiscoverCallback(std::string &pkgName, uint16_t subscribeId, - std::shared_ptr callback); - void UnRegisterDiscoverCallback(std::string &pkgName, uint16_t subscribeId); - void RegisterAuthenticateCallback(std::string &pkgName, std::string &deviceId, - std::shared_ptr callback); - void UnRegisterAuthenticateCallback(std::string &pkgName, std::string &deviceId); - void UnRegisterPackageCallback(std::string &pkgName); - void RegisterCheckAuthenticationCallback(std::string &pkgName, std::string &authPara, - std::shared_ptr callback); - void UnRegisterCheckAuthenticationCallback(std::string &pkgName); - void RegisterDeviceManagerFaCallback(std::string &packageName, - std::shared_ptr callback); - void UnRegisterDeviceManagerFaCallback(std::string &pkgName); -public: - void OnRemoteDied(); - void OnDeviceOnline(std::string &pkgName, const DmDeviceInfo &deviceInfo); - void OnDeviceOffline(std::string &pkgName, const DmDeviceInfo &deviceInfo); - void OnDeviceChanged(std::string &pkgName, const DmDeviceInfo &deviceInfo); - void OnDeviceFound(std::string &pkgName, uint16_t subscribeId, const DmDeviceInfo &deviceInfo); - void OnDiscoverFailed(std::string &pkgName, uint16_t subscribeId, int32_t failedReason); - void OnDiscoverySuccess(std::string &pkgName, uint16_t subscribeId); - void OnAuthResult(std::string &pkgName, std::string &deviceId, int32_t pinToken, uint32_t status, - uint32_t reason); - void OnCheckAuthResult(std::string &pkgName, std::string &deviceId, int32_t resultCode, int32_t flag); - void OnFaCall(std::string &pkgName, std::string ¶mJson); - void AddPkgName(std::string &pkgName); - void DeletePkgName(std::string &pkgName); - const std::list& GetPkgNameList() const; -private: -// std::mutex lock_; - std::map> deviceStateCallback_; - std::map>> deviceDiscoverCallbacks_; - std::map>> authenticateCallback_; - std::map> checkauthcallback_; - std::map> dmInitCallback_; - std::map> dmFaCallback_; - std::list dmPkgName_; -}; -} // namespace DistributedHardware -} // namespace OHOS -#endif // OHOS_DEVICE_MANAGER_NOTIFY_H diff --git a/ext/mini/interfaces_mini/inner_kits/native_cpp/src/device_manager.cpp b/ext/mini/interfaces_mini/inner_kits/native_cpp/src/device_manager.cpp deleted file mode 100644 index 6c7faf52ea33636a241fffa1a42c958274abedad..0000000000000000000000000000000000000000 --- a/ext/mini/interfaces_mini/inner_kits/native_cpp/src/device_manager.cpp +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (c) 2022 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 diff --git a/ext/mini/interfaces_mini/inner_kits/native_cpp/src/device_manager_impl.cpp b/ext/mini/interfaces_mini/inner_kits/native_cpp/src/device_manager_impl.cpp deleted file mode 100644 index d80e5ce4d13b44ca504f327bfbfedc4cac0db205..0000000000000000000000000000000000000000 --- a/ext/mini/interfaces_mini/inner_kits/native_cpp/src/device_manager_impl.cpp +++ /dev/null @@ -1,308 +0,0 @@ -/* - * Copyright (c) 2022 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 "device_manager_impl.h" -#include "message_processing.h" -#include "device_manager_errno.h" -#include "device_manager_log.h" -#include "device_manager_notify.h" -#include "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 "set_useroperation_req.h" -#include "get_authenticationparam_rsp.h" -#include "authenticate_device_req.h" -#include "check_authenticate_req.h" - - -namespace OHOS { -namespace DistributedHardware { -IMPLEMENT_SINGLE_INSTANCE(DeviceManagerImpl); - -int32_t DeviceManagerImpl::InitDeviceManager(std::string &pkgName, std::shared_ptr dmInitCallback) -{ - DMLOG(DM_LOG_INFO, "DeviceManager::InitDeviceManager start, pkgName: %s", pkgName.c_str()); - if (pkgName.empty() || dmInitCallback == nullptr) { - DMLOG(DM_LOG_ERROR, "InitDeviceManager error: Invalid parameter"); - return DEVICEMANAGER_INVALID_VALUE; - } - - DeviceManagerNotify::GetInstance().AddPkgName(pkgName); - DeviceManagerNotify::GetInstance().RegisterDeathRecipientCallback(pkgName, dmInitCallback); - DMLOG(DM_LOG_INFO, "success"); - return DEVICEMANAGER_OK; -} - -int32_t DeviceManagerImpl::UnInitDeviceManager(std::string &pkgName) -{ - DMLOG(DM_LOG_INFO, "DeviceManager::UnInitDeviceManager start, pkgName: %s", pkgName.c_str()); - if (pkgName.empty()) { - DMLOG(DM_LOG_ERROR, "InitDeviceManager error: Invalid parameter"); - return DEVICEMANAGER_INVALID_VALUE; - } - DeviceManagerNotify::GetInstance().DeletePkgName(pkgName); - DeviceManagerNotify::GetInstance().UnRegisterPackageCallback(pkgName); - return DEVICEMANAGER_OK; -} - -int32_t DeviceManagerImpl::GetTrustedDeviceList(std::string &pkgName, std::string &extra, - std::vector &deviceList) -{ - DMLOG(DM_LOG_INFO, "DeviceManager::GetTrustedDeviceList start, pkgName: %s", pkgName.c_str()); - if (pkgName.empty()) { - DMLOG(DM_LOG_ERROR, "Invalid para"); - return DEVICEMANAGER_INVALID_VALUE; - } - - std::shared_ptr req = std::make_shared(); - std::shared_ptr rsp = std::make_shared(); - req->SetPkgName(pkgName); - req->SetExtra(extra); - - if (CommandDispatch::GetInstance().MessageSendCmd(GET_TRUST_DEVICE_LIST, req, rsp) != DEVICEMANAGER_OK) { - return DEVICEMANAGER_MESSAGE_FAILED; - } - - if (rsp->GetErrCode() == DEVICEMANAGER_OK) { - deviceList = rsp->GetDeviceVec(); - } - - DMLOG(DM_LOG_INFO, "DeviceManager::GetTrustedDeviceList completed, pkgName: %s", pkgName.c_str()); - return DEVICEMANAGER_OK; -} - -int32_t DeviceManagerImpl::StartDeviceDiscovery(std::string &pkgName, DmSubscribeInfo &subscribeInfo, - std::shared_ptr callback) -{ - DMLOG(DM_LOG_INFO, "DeviceManager::StartDeviceDiscovery start, pkgName: %s", pkgName.c_str()); - if (pkgName.empty() || callback == nullptr) { - DMLOG(DM_LOG_ERROR, "Invalid para"); - return DEVICEMANAGER_INVALID_VALUE; - } - - DMLOG(DM_LOG_INFO, "DeviceManager StartDeviceDiscovery in, pkgName %s", pkgName.c_str()); - DeviceManagerNotify::GetInstance().RegisterDiscoverCallback(pkgName, subscribeInfo.subscribeId, callback); - - std::shared_ptr req = std::make_shared(); - std::shared_ptr rsp = std::make_shared(); - req->SetPkgName(pkgName); - req->SetSubscribeInfo(subscribeInfo); - - if (CommandDispatch::GetInstance().MessageSendCmd(START_DEVICE_DISCOVER, req, rsp) != DEVICEMANAGER_OK) { - return DEVICEMANAGER_MESSAGE_FAILED; - } - int32_t ret = rsp->GetErrCode(); - if (ret != DEVICEMANAGER_OK) { - DMLOG(DM_LOG_ERROR, "DeviceManager StartDeviceDiscovery Failed with ret %d", ret); - return ret; - } - return DEVICEMANAGER_OK; -} - -int32_t DeviceManagerImpl::StopDeviceDiscovery(std::string &pkgName, uint16_t subscribeId) -{ - DMLOG(DM_LOG_INFO, "DeviceManager::StopDeviceDiscovery start , pkgName: %s", pkgName.c_str()); - if (pkgName.empty()) { - DMLOG(DM_LOG_ERROR, "Invalid para"); - return DEVICEMANAGER_INVALID_VALUE; - } - - DMLOG(DM_LOG_INFO, "StopDeviceDiscovery in, pkgName %s", pkgName.c_str()); - - std::shared_ptr req = std::make_shared(); - std::shared_ptr rsp = std::make_shared(); - req->SetPkgName(pkgName); - req->SetSubscribeId(subscribeId); - - if (CommandDispatch::GetInstance().MessageSendCmd(STOP_DEVICE_DISCOVER, req, rsp) != DEVICEMANAGER_OK) { - return DEVICEMANAGER_MESSAGE_FAILED; - } - int32_t ret = rsp->GetErrCode(); - if (ret != DEVICEMANAGER_OK) { - DMLOG(DM_LOG_ERROR, "StopDeviceDiscovery Failed with ret %d", ret); - return ret; - } - - DeviceManagerNotify::GetInstance().UnRegisterDiscoverCallback(pkgName, subscribeId); - DMLOG(DM_LOG_INFO, "DeviceManager::StopDeviceDiscovery completed, pkgName: %s", pkgName.c_str()); - - return DEVICEMANAGER_OK; -} - -int32_t DeviceManagerImpl::SetUserOperation(std::string &pkgName, int32_t action) -{ - DMLOG(DM_LOG_INFO, "DeviceManager::SetUserOperation start"); - - if (pkgName.empty()) { - DMLOG(DM_LOG_ERROR, "Invalid para"); - return DEVICEMANAGER_INVALID_VALUE; - } - - std::shared_ptr req = std::make_shared(); - std::shared_ptr rsp = std::make_shared(); - - req->SetPkgName(pkgName); - req->SetOperation(action); - - if (CommandDispatch::GetInstance().MessageSendCmd(SERVER_USER_AUTHORIZATION_OPERATION, req, rsp) != DEVICEMANAGER_OK) { - return DEVICEMANAGER_MESSAGE_FAILED; - } - int32_t ret = rsp->GetErrCode(); - if (ret != DEVICEMANAGER_OK) { - DMLOG(DM_LOG_ERROR, "CheckAuthentication Failed with ret %d", ret); - return ret; - } - - return DEVICEMANAGER_OK; -} - -int32_t DeviceManagerImpl::GetAuthenticationParam(std::string &pkgName, DmAuthParam &authParam) -{ - DMLOG(DM_LOG_INFO, "DeviceManager::GetAuthenticationParam start"); - - std::shared_ptr req = std::make_shared(); - std::shared_ptr rsp = std::make_shared(); - req->SetPkgName(pkgName); - if (CommandDispatch::GetInstance().MessageSendCmd(SERVER_GET_AUTHENTCATION_INFO, req, rsp) != DEVICEMANAGER_OK) { - return DEVICEMANAGER_MESSAGE_FAILED; - } - - if (rsp->GetErrCode() == DEVICEMANAGER_OK) { - authParam = rsp->GetAuthParam(); - } - - return DEVICEMANAGER_OK; -} - -int32_t DeviceManagerImpl::AuthenticateDevice(std::string &pkgName, const DmDeviceInfo &deviceInfo, - const DmAppImageInfo &imageInfo, std::string &extra, std::shared_ptr callback) -{ - DMLOG(DM_LOG_INFO, "DeviceManager::AuthenticateDevice start , pkgName: %s", pkgName.c_str()); - if (pkgName.empty()) { - DMLOG(DM_LOG_ERROR, "Invalid para"); - return DEVICEMANAGER_INVALID_VALUE; - } - - DMLOG(DM_LOG_INFO, "AuthenticateDevice in, pkgName %s", pkgName.c_str()); - - std::shared_ptr req = std::make_shared(); - std::shared_ptr rsp = std::make_shared(); - req->SetPkgName(pkgName); - req->SetExtra(extra); - req->SetDeviceInfo(deviceInfo); - req->SetAppImageInfo(imageInfo); - - if (CommandDispatch::GetInstance().MessageSendCmd(AUTHENTICATE_DEVICE, req, rsp) != DEVICEMANAGER_OK) { - return DEVICEMANAGER_MESSAGE_FAILED; - } - - int32_t ret = rsp->GetErrCode(); - if (ret != DEVICEMANAGER_OK) { - DMLOG(DM_LOG_ERROR, "AuthenticateDevice Failed with ret %d", ret); - return ret; - } - - std::string strDeviceId = deviceInfo.deviceId; - DeviceManagerNotify::GetInstance().RegisterAuthenticateCallback(pkgName, strDeviceId, callback); - DMLOG(DM_LOG_INFO, "DeviceManager::AuthenticateDevice completed, pkgName: %s", pkgName.c_str()); - return DEVICEMANAGER_OK; -} - -int32_t DeviceManagerImpl::CheckAuthentication(std::string &pkgName, std::string &authPara, - std::shared_ptr callback) -{ - DMLOG(DM_LOG_INFO, "DeviceManager::CheckAuthentication start , pkgName: %s", pkgName.c_str()); - if (pkgName.empty()) { - DMLOG(DM_LOG_ERROR, "Invalid para"); - return DEVICEMANAGER_INVALID_VALUE; - } - DMLOG(DM_LOG_INFO, "CheckAuthentication in, pkgName %s", pkgName.c_str()); - - std::shared_ptr req = std::make_shared(); - std::shared_ptr rsp = std::make_shared(); - req->SetPkgName(pkgName); - req->SetAuthPara(authPara); - - if (CommandDispatch::GetInstance().MessageSendCmd(CHECK_AUTHENTICATION, req, rsp) != DEVICEMANAGER_OK) { - return DEVICEMANAGER_MESSAGE_FAILED; - } - - int32_t ret = rsp->GetErrCode(); - if (ret != DEVICEMANAGER_OK) { - DMLOG(DM_LOG_ERROR, "CheckAuthentication Failed with ret %d", ret); - return ret; - } - - DeviceManagerNotify::GetInstance().RegisterCheckAuthenticationCallback(pkgName, authPara, callback); - DMLOG(DM_LOG_INFO, "DeviceManager::CheckAuthentication completed, pkgName: %s", pkgName.c_str()); - return DEVICEMANAGER_OK; -} - -int32_t DeviceManagerImpl::RegisterDevStateCallback(std::string &pkgName, std::string &extra, - std::shared_ptr callback) -{ - DMLOG(DM_LOG_INFO, "DeviceManager::RegisterDevStateCallback start, pkgName: %s", pkgName.c_str()); - if (pkgName.empty() || callback == nullptr) { - DMLOG(DM_LOG_ERROR, "Invalid para"); - return DEVICEMANAGER_INVALID_VALUE; - } - - DeviceManagerNotify::GetInstance().RegisterDeviceStateCallback(pkgName, callback); - DMLOG(DM_LOG_INFO, "DeviceManager::RegisterDevStateCallback completed, pkgName: %s", pkgName.c_str()); - return DEVICEMANAGER_OK; -} - -int32_t DeviceManagerImpl::UnRegisterDevStateCallback(std::string &pkgName) -{ - DMLOG(DM_LOG_INFO, "DeviceManager::UnRegisterDevStateCallback start, pkgName: %s", pkgName.c_str()); - if (pkgName.empty()) { - DMLOG(DM_LOG_ERROR, "Invalid para"); - return DEVICEMANAGER_INVALID_VALUE; - } - - DeviceManagerNotify::GetInstance().UnRegisterDeviceStateCallback(pkgName); - DMLOG(DM_LOG_INFO, "DeviceManager::UnRegisterDevStateCallback completed, pkgName: %s", pkgName.c_str()); - return DEVICEMANAGER_OK; -} - -int32_t DeviceManagerImpl::RegisterDeviceManagerFaCallback(std::string &packageName, - std::shared_ptr callback) -{ - DMLOG(DM_LOG_INFO, "DeviceManager::RegisterDeviceManagerFaCallback start, pkgName: %s", packageName.c_str()); - if (packageName.empty() || callback == nullptr) { - DMLOG(DM_LOG_ERROR, "Invalid para"); - return DEVICEMANAGER_INVALID_VALUE; - } - DeviceManagerNotify::GetInstance().RegisterDeviceManagerFaCallback(packageName, callback); - DMLOG(DM_LOG_INFO, "DeviceManager::RegisterDevStateCallback completed, pkgName: %s", packageName.c_str()); - return DEVICEMANAGER_OK; -} - -int32_t DeviceManagerImpl::UnRegisterDeviceManagerFaCallback(std::string &pkgName) -{ - DMLOG(DM_LOG_INFO, "DeviceManager::UnRegisterDeviceManagerFaCallback start, pkgName: %s", pkgName.c_str()); - if (pkgName.empty()) { - DMLOG(DM_LOG_ERROR, "Invalid para"); - return DEVICEMANAGER_INVALID_VALUE; - } - DeviceManagerNotify::GetInstance().UnRegisterDeviceManagerFaCallback(pkgName); - DMLOG(DM_LOG_INFO, "DeviceManager::UnRegisterDevStateCallback completed, pkgName: %s", pkgName.c_str()); - return DEVICEMANAGER_OK; -} -} // namespace DistributedHardware -} // namespace OHOS diff --git a/ext/mini/interfaces_mini/inner_kits/native_cpp/src/notify/device_manager_notify.cpp b/ext/mini/interfaces_mini/inner_kits/native_cpp/src/notify/device_manager_notify.cpp deleted file mode 100644 index ae16dc3a93ca0ec6e95efcb7e02386bf5c9bcc4f..0000000000000000000000000000000000000000 --- a/ext/mini/interfaces_mini/inner_kits/native_cpp/src/notify/device_manager_notify.cpp +++ /dev/null @@ -1,275 +0,0 @@ -/* - * Copyright (c) 2022 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 "device_manager_log.h" -#include "device_manager_errno.h" -#include "nlohmann/json.hpp" -#include "constants.h" -#include "device_manager.h" - -namespace OHOS { -namespace DistributedHardware { -IMPLEMENT_SINGLE_INSTANCE(DeviceManagerNotify); - -void DeviceManagerNotify::RegisterDeathRecipientCallback(std::string &pkgName, - std::shared_ptr dmInitCallback) -{ - dmInitCallback_[pkgName] = dmInitCallback; -} - -void DeviceManagerNotify::UnRegisterDeathRecipientCallback(std::string &pkgName) -{ - dmInitCallback_.erase(pkgName); -} - -void DeviceManagerNotify::RegisterDeviceStateCallback(std::string &pkgName, - std::shared_ptr callback) -{ - deviceStateCallback_[pkgName] = callback; -} - -void DeviceManagerNotify::UnRegisterDeviceStateCallback(std::string &pkgName) -{ - deviceStateCallback_.erase(pkgName); -} - -void DeviceManagerNotify::RegisterDiscoverCallback(std::string &pkgName, uint16_t subscribeId, - std::shared_ptr callback) -{ - if (deviceDiscoverCallbacks_.count(pkgName) == 0) { - deviceDiscoverCallbacks_[pkgName] = std::map>(); - } - deviceDiscoverCallbacks_[pkgName][subscribeId] = callback; -} - -void DeviceManagerNotify::UnRegisterDiscoverCallback(std::string &pkgName, uint16_t subscribeId) -{ - if (deviceDiscoverCallbacks_.count(pkgName) > 0) { - deviceDiscoverCallbacks_[pkgName].erase(subscribeId); - if (deviceDiscoverCallbacks_[pkgName].empty()) { - deviceDiscoverCallbacks_.erase(pkgName); - } - } -} - -void DeviceManagerNotify::RegisterAuthenticateCallback(std::string &pkgName, std::string &deviceId, - std::shared_ptr callback) -{ - if (authenticateCallback_.count(pkgName) == 0) { - authenticateCallback_[pkgName] = std::map>(); - } - authenticateCallback_[pkgName][deviceId] = callback; -} - -void DeviceManagerNotify::UnRegisterAuthenticateCallback(std::string &pkgName, std::string &deviceId) -{ - if (authenticateCallback_.count(pkgName) > 0) { - authenticateCallback_[pkgName].erase(deviceId); - if (authenticateCallback_[pkgName].empty()) { - authenticateCallback_.erase(pkgName); - } - } -} - -void DeviceManagerNotify::UnRegisterPackageCallback(std::string &pkgName) -{ - deviceStateCallback_.erase(pkgName); - deviceDiscoverCallbacks_.erase(pkgName); - authenticateCallback_.erase(pkgName); - dmInitCallback_.erase(pkgName); -} - -void DeviceManagerNotify::RegisterCheckAuthenticationCallback(std::string &pkgName, std::string &authPara, - std::shared_ptr callback) -{ - checkauthcallback_[pkgName] = callback; -} - -void DeviceManagerNotify::UnRegisterCheckAuthenticationCallback(std::string &pkgName) -{ - checkauthcallback_.erase(pkgName); -} - -void DeviceManagerNotify::RegisterDeviceManagerFaCallback(std::string &packageName, - std::shared_ptr callback) -{ - dmFaCallback_[packageName] = callback; -} - -void DeviceManagerNotify::UnRegisterDeviceManagerFaCallback(std::string &pkgName) -{ - dmFaCallback_.erase(pkgName); -} - - -void DeviceManagerNotify::OnRemoteDied() -{ - DMLOG(DM_LOG_WARN, "DeviceManager : OnRemoteDied"); - for (auto iter : dmInitCallback_) { - iter.second->OnRemoteDied(); - } -} - -void DeviceManagerNotify::OnDeviceOnline(std::string &pkgName, const DmDeviceInfo &deviceInfo) -{ - DMLOG(DM_LOG_INFO, "DeviceManager OnDeviceOnline pkgName:%s", pkgName.c_str()); - if (deviceStateCallback_.count(pkgName) == 0) { - DMLOG(DM_LOG_ERROR, "DeviceManager OnDeviceOnlinecallback not register"); - return; - } - deviceStateCallback_[pkgName]->OnDeviceOnline(deviceInfo); -} - -void DeviceManagerNotify::OnDeviceOffline(std::string &pkgName, const DmDeviceInfo &deviceInfo) -{ - DMLOG(DM_LOG_INFO, "DeviceManager OnDeviceOffline pkgName:%s", pkgName.c_str()); - if (deviceStateCallback_.count(pkgName) == 0) { - DMLOG(DM_LOG_ERROR, "DeviceManager OnDeviceOfflinecallback not register"); - return; - } - deviceStateCallback_[pkgName]->OnDeviceOffline(deviceInfo); -} - -void DeviceManagerNotify::OnDeviceChanged(std::string &pkgName, const DmDeviceInfo &deviceInfo) -{ - DMLOG(DM_LOG_INFO, "DeviceManager OnDeviceChanged pkgName:%s", pkgName.c_str()); - if (deviceStateCallback_.count(pkgName) == 0) { - DMLOG(DM_LOG_ERROR, "DeviceManager OnDeviceChangedcallback not register"); - return; - } - deviceStateCallback_[pkgName]->OnDeviceChanged(deviceInfo); -} - -void DeviceManagerNotify::OnDeviceFound(std::string &pkgName, uint16_t subscribeId, - const DmDeviceInfo &deviceInfo) -{ - DMLOG(DM_LOG_INFO, "DeviceManager OnDeviceFound pkgName:%s, subscribeId:%d.", pkgName.c_str(), - (int32_t)subscribeId); - if (deviceDiscoverCallbacks_.count(pkgName) == 0) { - DMLOG(DM_LOG_ERROR, "DeviceManager OnDeviceFound: no register discoverCallback for this package"); - return; - } - std::map> &discoverCallMap = deviceDiscoverCallbacks_[pkgName]; - auto iter = discoverCallMap.find(subscribeId); - if (iter == discoverCallMap.end()) { - DMLOG(DM_LOG_ERROR, "DeviceManager OnDeviceFound: no register discoverCallback for subscribeId %d", - subscribeId); - return; - } - iter->second->OnDeviceFound(subscribeId, deviceInfo); -} - -void DeviceManagerNotify::OnDiscoverFailed(std::string &pkgName, uint16_t subscribeId, int32_t failedReason) -{ - DMLOG(DM_LOG_INFO, "DeviceManager OnDiscoverFailed pkgName:%s, subscribeId %d, reason %d", - pkgName.c_str(), subscribeId, failedReason); - if (deviceDiscoverCallbacks_.count(pkgName) == 0) { - DMLOG(DM_LOG_ERROR, "DeviceManager OnDiscoverFailed: no register discoverCallback for this package"); - return; - } - std::map> &discoverCallMap = deviceDiscoverCallbacks_[pkgName]; - auto iter = discoverCallMap.find(subscribeId); - if (iter == discoverCallMap.end()) { - DMLOG(DM_LOG_ERROR, "DeviceManager OnDiscoverFailed: no register discoverCallback for subscribeId %d", - subscribeId); - return; - } - iter->second->OnDiscoverFailed(subscribeId, failedReason); -} - -void DeviceManagerNotify::OnDiscoverySuccess(std::string &pkgName, uint16_t subscribeId) -{ - DMLOG(DM_LOG_INFO, "DeviceManager OnDiscoverySuccess pkgName:%s, subscribeId:%d.", pkgName.c_str(), - subscribeId); - if (deviceDiscoverCallbacks_.count(pkgName) == 0) { - DMLOG(DM_LOG_ERROR, "DeviceManager OnDiscoverySuccess: no register discoverCallback for this package"); - return; - } - std::map> &discoverCallMap = deviceDiscoverCallbacks_[pkgName]; - auto iter = discoverCallMap.find(subscribeId); - if (iter == discoverCallMap.end()) { - DMLOG(DM_LOG_ERROR, "DeviceManager OnDiscoverySuccess: no register discoverCallback for subscribeId %d", - subscribeId); - return; - } - iter->second->OnDiscoverySuccess(subscribeId); -} - -void DeviceManagerNotify::OnAuthResult(std::string &pkgName, std::string &deviceId, int32_t pinToken, - uint32_t status, uint32_t reason) -{ - DMLOG(DM_LOG_INFO, "DeviceManagerNotify::OnAuthResult pkgName:%s, status:%d, reason:%d", - pkgName.c_str(), status, reason); - if (authenticateCallback_.count(pkgName) == 0) { - DMLOG(DM_LOG_ERROR, "DeviceManager OnAuthResult: no register authCallback for this package"); - return; - } - std::map> &authCallMap = authenticateCallback_[pkgName]; - auto iter = authCallMap.find(deviceId); - if (iter == authCallMap.end()) { - DMLOG(DM_LOG_ERROR, "DeviceManager OnAuthResult: no register authCallback for deviceID "); - return; - } - iter->second->OnAuthResult(deviceId, pinToken, status, reason); - authenticateCallback_[pkgName].erase(deviceId); - if (authenticateCallback_[pkgName].empty()) { - authenticateCallback_.erase(pkgName); - } -} - -void DeviceManagerNotify::OnCheckAuthResult(std::string &pkgName, std::string &deviceId, int32_t resultCode, - int32_t flag) -{ - DMLOG(DM_LOG_INFO, "DeviceManagerNotify::OnCheckAuthResult pkgName:%s, resultCode:%d, flag:%d", - pkgName.c_str(), resultCode, flag); - if (checkauthcallback_.count(pkgName) == 0) { - DMLOG(DM_LOG_ERROR, "DeviceManager OnCheckAuthResult: no register authCallback for this package"); - return; - } - - checkauthcallback_[pkgName]->OnCheckAuthResult(deviceId, resultCode, flag); - checkauthcallback_.erase(pkgName); -} - -void DeviceManagerNotify::OnFaCall(std::string &pkgName, std::string ¶mJson) -{ - DMLOG(DM_LOG_INFO, "DeviceManager OnFaCallback pkgName:%s", pkgName.c_str()); - if (dmFaCallback_.count(pkgName) == 0) { - DMLOG(DM_LOG_ERROR, "DeviceManager DmFaCallback not register"); - return; - } - dmFaCallback_[pkgName]->OnCall(paramJson); -} - -void DeviceManagerNotify::AddPkgName(std::string &pkgName) -{ - dmPkgName_.push_back(pkgName); -} - -void DeviceManagerNotify::DeletePkgName(std::string &pkgName) -{ - dmPkgName_.remove(pkgName); -} - -const std::list& DeviceManagerNotify::GetPkgNameList() const -{ - return dmPkgName_; -} - - -} // namespace DistributedHardware -} // namespace OHOS diff --git a/ext/mini/interfaces_mini/kits/js/BUILD.gn b/ext/mini/interfaces_mini/kits/js/BUILD.gn deleted file mode 100644 index f72dd087addb9c1f4f42928b075d18b4c43fcd9e..0000000000000000000000000000000000000000 --- a/ext/mini/interfaces_mini/kits/js/BUILD.gn +++ /dev/null @@ -1,104 +0,0 @@ -# Copyright (c) 2022 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") - -if (ohos_kernel_type == "liteos_m") { - static_library("devicemanager") { - include_dirs = [ - "//third_party/node/src", - "//third_party/json/include", - "${common_path}/include", - "//utils/native/base/include", - "include", - "${utils_path}/include/log", - "//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", - "${innerkits_path}/native_cpp/include", - ] - - sources = [ - "src/dm_native_event.cpp", - "src/native_devicemanager_js.cpp", - ] - - deps = [ - "${utils_path}:devicemanagerutils_mini", - "//foundation/distributedhardware/devicemanager/interfaces_small/inner_kits/native_cpp:devicemanagersdk_mini", - ] - - defines = [ - "HI_LOG_ENABLE", - "DH_LOG_TAG=\"devicemanagerkit_js\"", - "LOG_DOMAIN=0xD004100", - ] - } -} else { - ohos_shared_library("devicemanager") { - include_dirs = [ - "//third_party/node/src", - "//third_party/json/include", - "${common_path}/include", - "//foundation/ace/napi/native_engine", - "//foundation/ace/napi/interfaces/kits", - "//utils/native/base/include", - "include", - "${utils_path}/include/log", - "${common_path}/include/ipc", - "${innerkits_path}/native_cpp/include", - "${innerkits_path}/native_cpp/include/standard", - ] - - sources = [ - "src/dm_native_event.cpp", - "src/native_devicemanager_js.cpp", - ] - - deps = [ - "${utils_path}:devicemanagerutils", - "//foundation/ace/napi:ace_napi", - "//foundation/distributedhardware/devicemanager/interfaces/inner_kits/native_cpp:devicemanagersdk", - "//utils/native/base:utils", - ] - - defines = [ - "HI_LOG_ENABLE", - "DH_LOG_TAG=\"devicemanagerkit_js\"", - "LOG_DOMAIN=0xD004100", - ] - - external_deps = [ - "appexecfwk_standard:appexecfwk_base", - "appexecfwk_standard:appexecfwk_core", - "hiviewdfx_hilog_native:libhilog", - "ipc:ipc_core", - "safwk:system_ability_fwk", - "samgr_standard:samgr_proxy", - ] - - subsystem_name = "distributedhardware" - relative_install_dir = "module/distributedhardware" - part_name = "device_manager_base" - } -} - -group("devicemanager_native_js") { - deps = [ ":devicemanager" ] -} diff --git a/ext/mini/interfaces_mini/kits/js/include/dm_native_event.h b/ext/mini/interfaces_mini/kits/js/include/dm_native_event.h deleted file mode 100644 index 8628c711fbfa98ed0f9065996bbf31d294509fdf..0000000000000000000000000000000000000000 --- a/ext/mini/interfaces_mini/kits/js/include/dm_native_event.h +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (c) 2022 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 -#include -#include -#include "jsi.h" -#include "dm_device_info.h" - -using namespace std; - -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> eventMap_; -}; - -} -} - -#endif /* OHOS_DEVICE_MANAGER_NATIVE_EVENT_H */ \ No newline at end of file diff --git a/ext/mini/interfaces_mini/kits/js/include/native_devicemanager_js.h b/ext/mini/interfaces_mini/kits/js/include/native_devicemanager_js.h deleted file mode 100644 index 94dfb108e67833afb658b752de8f164d70339564..0000000000000000000000000000000000000000 --- a/ext/mini/interfaces_mini/kits/js/include/native_devicemanager_js.h +++ /dev/null @@ -1,192 +0,0 @@ -/* - * Copyright (c) 2022 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 -#include -#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 "jsi.h" - -namespace OHOS { -namespace ACELite { - -#define DM_JSI_BUF_LENGTH (256) - -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::DiscoverCallback { -public: - explicit DmJSIDiscoverCallback(std::string &bundleName) : refCount_(0), bundleName_(bundleName) {} - virtual ~DmJSIDiscoverCallback() {}; - void OnDeviceFound(uint16_t subscribeId, const OHOS::DistributedHardware::DmDeviceInfo &deviceInfo) override; - void OnDiscoverFailed(uint16_t subscribeId, int32_t failedReason) override; - void OnDiscoverySuccess(uint16_t subscribeId) override; - void IncreaseRefCount(); - void DecreaseRefCount(); - int32_t GetRefCount(); -private: - //std::atomic refCount_; - int32_t refCount_ = 0; - std::string bundleName_; -}; - -class DmJSIAuthenticateCallback : public OHOS::DistributedHardware::AuthenticateCallback { -public: - explicit DmJSIAuthenticateCallback(std::string &bundleName) : bundleName_(bundleName) {} - virtual ~DmJSIAuthenticateCallback() {}; - void OnAuthResult(std::string &deviceId, int32_t pinToken, int32_t status, int32_t reason) override; - -private: - std::string bundleName_; -}; - -class DmJSICheckAuthCallback : public OHOS::DistributedHardware::CheckAuthCallback { -public: - explicit DmJSICheckAuthCallback(std::string &bundleName) : bundleName_(bundleName) {} - virtual ~DmJSICheckAuthCallback() {}; - void OnCheckAuthResult(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(std::string ¶mJson) override; - -private: - std::string bundleName_; -}; - -class GlobalBundleName { -public: - std::string GetBundleName() - { - return bundleName_; - } - - void SetBundleName(std::string bundleName) - { - bundleName_ = bundleName; - } -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 DeviceManagerModule *GetDeviceManagerJSI(std::string &bundleName); - static void AuthRsultVerifyInfoAsyncWorkFunc(void *data); - static void DmAuthParamToJsAuthParamy(const OHOS::DistributedHardware::DmAuthParam &authParam, JSIValue ¶mResult); - void OnDmfaCall(const std::string ¶mJson); - void OnVerifyResult(const std::string &deviceId, int32_t resultCode, int32_t flag); - void OnAuthResult(const std::string &deviceId, int32_t pinToken, 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 ¶m, 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 ¶mResult); - static void CreateDmCallback(std::string &bundleName, std::string &eventType); - static void ReleaseDmCallback(std::string &bundleName, std::string &eventType); - static void DeviceInfoToJsArray(const std::vector &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 diff --git a/ext/mini/interfaces_mini/kits/js/src/dm_native_event.cpp b/ext/mini/interfaces_mini/kits/js/src/dm_native_event.cpp deleted file mode 100644 index b60955567831f7d6bd996c6d85e3f0f8288df5c6..0000000000000000000000000000000000000000 --- a/ext/mini/interfaces_mini/kits/js/src/dm_native_event.cpp +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright (c) 2022 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 "device_manager_log.h" -#include "js_async_work.h" - -using namespace OHOS::DistributedHardware; - -namespace OHOS { -namespace ACELite { - -std::map> DmNativeEvent::eventMap_; - -DmNativeEvent::DmNativeEvent() -{ - DMLOG(DM_LOG_INFO, "DmNativeEvent ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"); -} - -DmNativeEvent::DmNativeEvent(JSIValue thisVar) -{ - DMLOG(DM_LOG_INFO, "DmNativeEvent ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"); -} - -DmNativeEvent::~DmNativeEvent() -{ - DMLOG(DM_LOG_INFO, "~DmNativeEvent ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"); -} - -void DmNativeEvent::On(std::string &eventType, JSIValue handle, JSIValue thisVal) -{ - DMLOG(DM_LOG_INFO, "DmNativeEvent On in for event: %s", eventType.c_str()); - auto listener= std::make_shared(); - - listener->eventType = eventType; - listener->handlerRef = JSI::AcquireValue(handle); - - listener->thisVarRef_ = JSI::AcquireValue(thisVal); - eventMap_[eventType] = listener; -} - -void DmNativeEvent::Off(std::string &eventType) -{ - DMLOG(DM_LOG_INFO, "DmNativeEvent Off in for event: %s", eventType.c_str()); - auto iter = eventMap_.find(eventType); - if (iter == eventMap_.end()) { - DMLOG(DM_LOG_ERROR, "eventType %s not find", eventType.c_str()); - return; - } - auto 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) -{ - DMLOG(DM_LOG_INFO, "OnEvent for %s", eventType.c_str()); - - auto iter = eventMap_.find(eventType); - if (iter == eventMap_.end()) { - DMLOG(DM_LOG_ERROR, "eventType %s not find", eventType.c_str()); - return; - } - auto listener = iter->second; - if (!JSI::ValueIsFunction(listener->handlerRef)){ - DMLOG(DM_LOG_INFO, "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; - - DMLOG(DM_LOG_INFO, "OnEventAsyncWorkFunc for %s in", eventType.c_str()); - JsAsyncWork::DispatchAsyncWork(OnEventAsyncWorkFunc, reinterpret_cast(params)); - -} - -void DmNativeEvent::OnEventAsyncWorkFunc(void *data) -{ - DMLOG(DM_LOG_INFO, "OnEventAsyncWorkFunc in "); - FuncParams* params = reinterpret_cast(data); - JSI::CallFunction(params->handlerRef, params->thisVarRef_, params->args, params->argsSize); -} - -} -} \ No newline at end of file diff --git a/ext/mini/interfaces_mini/kits/js/src/native_devicemanager_js.cpp b/ext/mini/interfaces_mini/kits/js/src/native_devicemanager_js.cpp deleted file mode 100644 index 711d56fe265bb876853c7b245fd1a17693fffc01..0000000000000000000000000000000000000000 --- a/ext/mini/interfaces_mini/kits/js/src/native_devicemanager_js.cpp +++ /dev/null @@ -1,1106 +0,0 @@ -/* - * Copyright (c) 2022 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 "native_devicemanager_js.h" -#include "jsi.h" -#include -#include "nlohmann/json.hpp" -#include "device_manager.h" -#include "device_manager_log.h" -#include "constants.h" -#include "jsi_types.h" -#include "js_async_work.h" - -using namespace OHOS::DistributedHardware; -using namespace std; - -namespace OHOS { -namespace ACELite { - -const std::string DM_JSI_EVENT_DEVICE_STATE_CHANGE = "deviceStateChange"; -const std::string DM_JSI_EVENT_DEVICE_FOUND = "deviceFound"; -const std::string DM_JSI_EVENT_DEVICE_DISCOVER_FAIL = "discoverFail"; -const std::string DM_JSI_EVENT_DMFA_CALLBACK = "dmFaCallback"; -const std::string DM_JSI_EVENT_DEVICE_SERVICE_DIE = "serviceDie"; - -const std::string DEVICE_MANAGER_JSI_CLASS_NAME = "DeviceManager"; -//int32->uint8_t -const uint8_t DM_JSI_ARGS_ONE = 1; -const uint8_t DM_JSI_ARGS_TWO = 2; -const uint8_t DM_JSI_ARGS_THREE = 3; -const int32_t DM_JSI_SUB_ID_MAX = 65535; - -const int32_t DM_AUTH_TYPE_PINCODE = 1; -const int32_t DM_AUTH_DIRECTION_CLIENT = 1; - -const int32_t DM_JSI_SUBSCRIBE_CAPABILITY_DDMP = 0; -const int32_t DM_JSI_SUBSCRIBE_CAPABILITY_OSD = 1; -const char *DM_CAPABILITY_OSD = "osdCapability"; - -std::map g_deviceManagerMap; -std::map> g_initCallbackMap; -std::map> g_deviceStateCallbackMap; -std::map> g_discoverCallbackMap; -std::map> g_authCallbackMap; -std::map> g_checkAuthCallbackMap; -std::map> g_dmfaCallbackMap; - -AuthAsyncCallbackInfo DeviceManagerModule::authAsyncCallbackInfo_; -AuthAsyncCallbackInfo DeviceManagerModule::verifyAsyncCallbackInfo_; -//add new -GlobalBundleName globalBundleName_; - - -DeviceManagerModule *DeviceManagerModule::GetDeviceManagerJSI(std::string &bundleName) -{ - auto iter = g_deviceManagerMap.find(bundleName); - if (iter == g_deviceManagerMap.end()) { - return nullptr; - } - return iter->second; -} - - -DeviceManagerModule::DeviceManagerModule() : DmNativeEvent() -{ - DMLOG(DM_LOG_INFO, "new DeviceManagerModule is success"); -} - -DeviceManagerModule::~DeviceManagerModule() -{ - -} - -void DmJSIInitCallback::OnRemoteDied() -{ - DeviceManagerModule *deviceManagerJSI = DeviceManagerModule::GetDeviceManagerJSI(bundleName_); - if (deviceManagerJSI == nullptr) { - DMLOG(DM_LOG_ERROR, "OnRemoteDied, deviceManagerJSI not find for bunderName %s", bundleName_.c_str()); - return; - } - deviceManagerJSI->OnRemoteDied(); -} - -void DeviceManagerModule::OnRemoteDied() -{ - OnEvent("serviceDie", 0, nullptr); -} - - -void DmJSIDeviceStateCallback::OnDeviceOnline(const DmDeviceInfo &deviceInfo) -{ - DeviceManagerModule *deviceManagerJSI = DeviceManagerModule::GetDeviceManagerJSI(bundleName_); - if (deviceManagerJSI == nullptr) { - DMLOG(DM_LOG_ERROR, "OnDeviceOnline, deviceManagerJSI not find for bunderName %s", bundleName_.c_str()); - return; - } - deviceManagerJSI->OnDeviceStateChange(DmJSIDevStateChangeAction::ONLINE, deviceInfo); -} - -void DmJSIDeviceStateCallback::OnDeviceReady(const DmDeviceInfo &deviceInfo) -{ - DeviceManagerModule *deviceManagerJSI = DeviceManagerModule::GetDeviceManagerJSI(bundleName_); - if (deviceManagerJSI == nullptr) { - DMLOG(DM_LOG_ERROR, "OnDeviceOnline, deviceManagerJSI not find for bunderName %s", bundleName_.c_str()); - return; - } - deviceManagerJSI->OnDeviceStateChange(DmJSIDevStateChangeAction::READY, deviceInfo); -} - -void DmJSIDeviceStateCallback::OnDeviceOffline(const DmDeviceInfo &deviceInfo) -{ - DeviceManagerModule *deviceManagerJSI = DeviceManagerModule::GetDeviceManagerJSI(bundleName_); - if (deviceManagerJSI == nullptr) { - DMLOG(DM_LOG_ERROR, "OnDeviceOffline, deviceManagerJSI not find for bunderName %s", bundleName_.c_str()); - return; - } - deviceManagerJSI->OnDeviceStateChange(DmJSIDevStateChangeAction::OFFLINE, deviceInfo); -} - -void DmJSIDeviceStateCallback::OnDeviceChanged(const DmDeviceInfo &deviceInfo) -{ - DeviceManagerModule *deviceManagerJSI = DeviceManagerModule::GetDeviceManagerJSI(bundleName_); - if (deviceManagerJSI == nullptr) { - DMLOG(DM_LOG_ERROR, "OnDeviceChanged, deviceManagerJSI not find for bunderName %s", bundleName_.c_str()); - return; - } - deviceManagerJSI->OnDeviceStateChange(DmJSIDevStateChangeAction::CHANGE, deviceInfo); -} - -void DmJSIDiscoverCallback::OnDeviceFound(uint16_t subscribeId, const DmDeviceInfo &deviceInfo) -{ - DeviceManagerModule *deviceManagerJSI = DeviceManagerModule::GetDeviceManagerJSI(bundleName_); - if (deviceManagerJSI == nullptr) { - DMLOG(DM_LOG_ERROR, "OnDeviceFound, deviceManagerJSI not find for bunderName %s", bundleName_.c_str()); - return; - } - - DMLOG(DM_LOG_INFO, "OnDeviceFound for %s, subscribeId %d", bundleName_.c_str(), (int32_t)subscribeId); - deviceManagerJSI->OnDeviceFound(subscribeId, deviceInfo); -} - -void DmJSIDiscoverCallback::OnDiscoverFailed(uint16_t subscribeId, int32_t failedReason) -{ - DeviceManagerModule *deviceManagerJSI = DeviceManagerModule::GetDeviceManagerJSI(bundleName_); - if (deviceManagerJSI == nullptr) { - DMLOG(DM_LOG_ERROR, "OnDiscoverFailed, deviceManagerJSI not find for bunderName %s", bundleName_.c_str()); - return; - } - - deviceManagerJSI->OnDiscoverFailed(subscribeId, failedReason); -} - -void DmJSIDiscoverCallback::OnDiscoverySuccess(uint16_t subscribeId) -{ - DeviceManagerModule *deviceManagerJSI = DeviceManagerModule::GetDeviceManagerJSI(bundleName_); - if (deviceManagerJSI == nullptr) { - DMLOG(DM_LOG_ERROR, "OnDiscoverySuccess, deviceManagerJSI not find for bunderName %s", bundleName_.c_str()); - return; - } - DMLOG(DM_LOG_INFO, "DiscoverySuccess for %s, subscribeId %d", bundleName_.c_str(), (int32_t)subscribeId); -} - - -void DmJSIAuthenticateCallback::OnAuthResult(std::string &deviceId, int32_t pinToken, int32_t status, int32_t reason) -{ - DeviceManagerModule *deviceManagerJSI = DeviceManagerModule::GetDeviceManagerJSI(bundleName_); - if (deviceManagerJSI == nullptr) { - DMLOG(DM_LOG_ERROR, "OnAuthResult, deviceManagerJSI not find for bunderName %s", bundleName_.c_str()); - return; - } - deviceManagerJSI->OnAuthResult(deviceId, pinToken, status, reason); -} - -void DmJSICheckAuthCallback::OnCheckAuthResult(std::string &deviceId, int32_t resultCode, int32_t flag) -{ - DeviceManagerModule *deviceManagerJSI = DeviceManagerModule::GetDeviceManagerJSI(bundleName_); - if (deviceManagerJSI == nullptr) { - DMLOG(DM_LOG_ERROR, "OnCheckAuthResult, deviceManagerJSI not find for bunderName %s", bundleName_.c_str()); - return; - } - deviceManagerJSI->OnVerifyResult(deviceId, resultCode, flag); -} - -void DmJSIDeviceManagerFaCallback::OnCall(std::string ¶mJson) -{ - DeviceManagerModule *deviceManagerJSI = DeviceManagerModule::GetDeviceManagerJSI(bundleName_); - if (deviceManagerJSI == nullptr) { - DMLOG(DM_LOG_ERROR, "OnCall, deviceManagerJSI not find for bunderName %s", bundleName_.c_str()); - return; - } - deviceManagerJSI->OnDmfaCall(paramJson); -} - -void DmJSIDiscoverCallback::IncreaseRefCount() -{ - refCount_++; -} - -void DmJSIDiscoverCallback::DecreaseRefCount() -{ - refCount_--; -} - -int32_t DmJSIDiscoverCallback::GetRefCount() -{ - return refCount_; -} - -void DeviceManagerModule::OnDeviceStateChange(DmJSIDevStateChangeAction action, const DmDeviceInfo &deviceInfo) -{ - JSIValue result = JSI::CreateObject(); - JSI::SetNumberProperty(result, "action", (double)action); - - JSIValue device = JSI::CreateObject(); - JSI::SetStringProperty(device, "deviceId", deviceInfo.deviceId); - JSI::SetStringProperty(device, "deviceName", deviceInfo.deviceName); - JSI::SetNumberProperty(device, "deviceTypeId", (double)deviceInfo.deviceTypeId); - - JSIValue param[2] = {result, device}; - OnEvent("deviceStateChange", DM_JSI_ARGS_TWO, param); - JSI::ReleaseValueList(result, device, ARGS_END); -} - -void DeviceManagerModule::OnDeviceFound(uint16_t subscribeId, const DmDeviceInfo &deviceInfo) -{ - DMLOG(DM_LOG_INFO, "OnDeviceFound for subscribeId %d", (int32_t)subscribeId); - JSIValue result = JSI::CreateObject(); - JSI::SetNumberProperty(result, "subscribeId", (double)subscribeId); - - JSIValue device = JSI::CreateObject(); - JSI::SetStringProperty(device, "deviceId", deviceInfo.deviceId); - JSI::SetStringProperty(device, "deviceName", deviceInfo.deviceName); - JSI::SetNumberProperty(device, "deviceTypeId", (double)deviceInfo.deviceTypeId); - DMLOG(DM_LOG_INFO, "OnDeviceFound subscribeId %ld ", subscribeId); - DMLOG(DM_LOG_INFO, "OnDeviceFound deviceId %s ", deviceInfo.deviceId); - DMLOG(DM_LOG_INFO, "OnDeviceFound deviceName %s ", deviceInfo.deviceName); - DMLOG(DM_LOG_INFO, "OnDeviceFound deviceTypeId %x ", deviceInfo.deviceTypeId); - - JSIValue param[2] = {result, device}; - OnEvent("deviceFound", DM_JSI_ARGS_TWO, param); - JSI::ReleaseValueList(result, device, ARGS_END); -} - -void DeviceManagerModule::OnDiscoverFailed(uint16_t subscribeId, int32_t failedReason) -{ - DMLOG(DM_LOG_INFO, "OnDiscoverFailed for subscribeId %d", (int32_t)subscribeId); - JSIValue result = JSI::CreateObject(); - JSI::SetNumberProperty(result, "subscribeId", (double)subscribeId); - JSIValue reason = JSI::CreateObject(); - JSI::SetNumberProperty(reason, "reason", (double)failedReason); - - JSIValue param[2] = {result, reason}; - OnEvent("discoverFail", DM_JSI_ARGS_TWO, param); - JSI::ReleaseValueList(result, reason, ARGS_END); -} - -void DeviceManagerModule::OnDmfaCall(const std::string ¶mJson) -{ - DMLOG(DM_LOG_INFO, "OnCall for paramJson"); - JSIValue result = JSI::CreateObject(); - JSI::SetStringProperty(result, "param", paramJson.c_str()); - - JSIValue param[1] = {result}; - OnEvent("dmFaCallback", DM_JSI_ARGS_ONE, param); - JSI::ReleaseValueList(result, ARGS_END); -} - -void DeviceManagerModule::OnAuthResult(const std::string &deviceId, int32_t pinToken, int32_t status, int32_t reason) -{ - DMLOG(DM_LOG_INFO, "OnAuthResult for status: %d, reason: %d", status, reason); - JSIValue thisVar = authAsyncCallbackInfo_.thisVal_; - JSIValue success = JSI::GetNamedProperty(authAsyncCallbackInfo_.callback, CB_SUCCESS); - JSIValue fail = JSI::GetNamedProperty(authAsyncCallbackInfo_.callback, CB_FAIL); - - JSIValue errOne = JSI::CreateObject(); - JSIValue errTwo = JSI::CreateObject(); - JSIValue successOne = JSI::CreateObject(); - JSIValue successTwo = JSI::CreateObject(); - - if (status == 0) { - DMLOG(DM_LOG_INFO, "OnAuthResult success"); - JSI::SetStringProperty(successOne, "deviceId", deviceId.c_str()); - JSI::SetNumberProperty(successTwo, "pinTone", (double)pinToken); - JSIValue param[2] = {successOne, successTwo}; - AuthFuncParams* params =new AuthFuncParams(); - params->handlerRef = success; - params->thisVarRef_ = thisVar; - params->args = param; - params->argsSize = DM_JSI_ARGS_TWO; - DMLOG(DM_LOG_INFO, "OnAuthResult SuccessCallBack in."); - JsAsyncWork::DispatchAsyncWork(AuthRsultVerifyInfoAsyncWorkFunc, reinterpret_cast(params)); - } else { - DMLOG(DM_LOG_INFO, "OnAuthResult failed"); - JSI::SetNumberProperty(errOne, "code", (double)status); - JSI::SetNumberProperty(errTwo, "reason", (double)reason); - JSIValue param[2] = {errOne, errTwo}; - AuthFuncParams* params =new AuthFuncParams(); - params->handlerRef = fail; - params->thisVarRef_ = thisVar; - params->args = param; - params->argsSize = DM_JSI_ARGS_TWO; - DMLOG(DM_LOG_INFO, "OnAuthResult FailCallBack in."); - JsAsyncWork::DispatchAsyncWork(AuthRsultVerifyInfoAsyncWorkFunc, reinterpret_cast(params)); - - } - g_authCallbackMap.erase(bundleName_); - JSI::ReleaseValueList(thisVar, success, fail, errOne, errTwo, successOne, successTwo, authAsyncCallbackInfo_.thisVal_, authAsyncCallbackInfo_.callback, ARGS_END); -} - -void DeviceManagerModule::OnVerifyResult(const std::string &deviceId, int32_t resultCode, int32_t flag) -{ - DMLOG(DM_LOG_INFO, "OnVerifyResult for resultCode: %d, flag: %d", resultCode, flag); - JSIValue thisVar = verifyAsyncCallbackInfo_.thisVal_; - JSIValue success = JSI::GetNamedProperty(verifyAsyncCallbackInfo_.callback, CB_SUCCESS); - JSIValue fail = JSI::GetNamedProperty(verifyAsyncCallbackInfo_.callback, CB_FAIL); - - JSIValue successOne = JSI::CreateObject(); - JSIValue successTwo = JSI::CreateObject(); - JSIValue errOne = JSI::CreateObject(); - - if (resultCode == 0) { - DMLOG(DM_LOG_INFO, "OnVerifyResult success"); - JSI::SetStringProperty(successOne, "deviceId", deviceId.c_str()); - JSI::SetNumberProperty(successTwo, "level", (double)flag); - JSIValue param[2] = {successOne, successTwo}; - AuthFuncParams* params =new AuthFuncParams(); - params->handlerRef = success; - params->thisVarRef_ = thisVar; - params->args = param; - params->argsSize = DM_JSI_ARGS_TWO; - DMLOG(DM_LOG_INFO, "OnVerifyResult SuccessCallBack in."); - JsAsyncWork::DispatchAsyncWork(AuthRsultVerifyInfoAsyncWorkFunc, reinterpret_cast(params)); - - } else { - DMLOG(DM_LOG_INFO, "OnVerifyResult failed"); - JSI::SetNumberProperty(errOne, "code", (double)resultCode); - JSIValue param[1] = {errOne}; - AuthFuncParams* params =new AuthFuncParams(); - params->handlerRef = fail; - params->thisVarRef_ = thisVar; - params->args = param; - params->argsSize = DM_JSI_ARGS_ONE; - DMLOG(DM_LOG_INFO, "OnVerifyResult FailCallBack in."); - JsAsyncWork::DispatchAsyncWork(AuthRsultVerifyInfoAsyncWorkFunc, reinterpret_cast(params)); - } - - g_checkAuthCallbackMap.erase(bundleName_); - JSI::ReleaseValueList(thisVar, success, fail, successOne, successTwo, errOne, verifyAsyncCallbackInfo_.thisVal_, verifyAsyncCallbackInfo_.callback, ARGS_END); -} - -void DeviceManagerModule::DeviceInfoToJsArray(const std::vector &vecDevInfo, const int32_t idx, JSIValue &arrayResult) -{ - bool status = false; - JSIValue result = JSI::CreateObject(); - char *deviceId = const_cast(vecDevInfo[idx].deviceId); - char *deviceName = const_cast(vecDevInfo[idx].deviceName); - - JSI::SetStringProperty(result, "deviceId", deviceId); - JSI::SetStringProperty(result, "deviceName", deviceName); - JSI::SetNumberProperty(result, "deviceTypeId", (double)vecDevInfo[idx].deviceTypeId); - - status = JSI::SetPropertyByIndex(arrayResult,idx,result); - if (status == false) { - DMLOG(DM_LOG_ERROR, "DmDeviceInfo To JsArray set element error"); - } - JSI::ReleaseValue(result); -} - -void DeviceManagerModule::DmAuthParamToJsAuthParamy(const DmAuthParam &authParam, JSIValue ¶mResult) -{ - DMLOG(DM_LOG_INFO, "DmAuthParamToJsAuthParamy in"); - JSI::SetNumberProperty(paramResult,"authType",(double)authParam.authType); - - JSIValue extraInfo = JSI::CreateObject(); - JSI::SetNumberProperty(extraInfo,"direction",(double)authParam.direction); - JSI::SetNumberProperty(extraInfo,"pinToken",(double)authParam.pinToken); - if (authParam.direction == DM_AUTH_DIRECTION_CLIENT) { - JSI::SetNamedProperty(paramResult,"extraInfo",extraInfo); - return; - } - JSI::SetStringProperty(extraInfo, "packageName",authParam.packageName.c_str()); - JSI::SetStringProperty(extraInfo, "appName",authParam.appName.c_str()); - JSI::SetStringProperty(extraInfo, "appDescription",authParam.appDescription.c_str()); - JSI::SetNumberProperty(extraInfo,"business",(double)authParam.business); - JSI::SetNumberProperty(extraInfo,"pincode",(double)authParam.pincode); - JSI::SetNamedProperty(paramResult,"extraInfo",extraInfo); - DMLOG(DM_LOG_INFO, "DeviceManagerModule::DmAuthParamToJsAuthParamy, packageName: %s", authParam.packageName.c_str()); - DMLOG(DM_LOG_INFO, "DeviceManagerModule::DmAuthParamToJsAuthParamy, appName: %s", authParam.appName.c_str()); - DMLOG(DM_LOG_INFO, "DeviceManagerModule::DmAuthParamToJsAuthParamy, appDescription: %s", authParam.appDescription.c_str()); - DMLOG(DM_LOG_INFO, "DeviceManagerModule::DmAuthParamToJsAuthParamy, business: %d",authParam.business); - DMLOG(DM_LOG_INFO, "DeviceManagerModule::DmAuthParamToJsAuthParamy, pincode: %d", authParam.pincode); - DMLOG(DM_LOG_INFO, "DeviceManagerModule::DmAuthParamToJsAuthParamy, pinToken: %d", authParam.pinToken); - - size_t appIconLen = (size_t)authParam.imageinfo.GetAppIconLen(); - if (appIconLen > 0) { - uint8_t *appIcon = nullptr; - JSIValue appIconBuffer = JSI::CreateArrayBuffer(appIconLen, appIcon); - if (appIcon != nullptr && - memcpy_s(appIcon, appIconLen, reinterpret_cast(authParam.imageinfo.GetAppIcon()), - appIconLen) == 0) { - JSIValue appIconArray = JSI::CreateTypedArray(TypedArrayType::JSI_UINT8_ARRAY, appIconLen, appIconBuffer, 0); - JSI::SetNamedProperty(paramResult,"appIcon",appIconArray); - } - } - - size_t appThumbnailLen = (size_t)authParam.imageinfo.GetAppThumbnailLen(); - if (appThumbnailLen > 0) { - uint8_t *appThumbnail = nullptr; - JSIValue appThumbnailBuffer = JSI::CreateArrayBuffer(appThumbnailLen, appThumbnail); - if (appThumbnail != nullptr && memcpy_s(appThumbnail, appThumbnailLen, reinterpret_cast(authParam.imageinfo.GetAppThumbnail()), appThumbnailLen) == 0) { - JSIValue appThumbnailArray = JSI::CreateTypedArray(TypedArrayType::JSI_UINT8_ARRAY, appThumbnailLen, appThumbnailBuffer, 0); - JSI::SetNamedProperty(paramResult,"appThumbnail", appThumbnailArray); - } - } -} - -int32_t DeviceManagerModule::JsObjectToInt(const JSIValue &object, - const std::string &fieldStr) -{ - double result = JSI::GetNumberProperty(object,fieldStr.c_str()); - return (int32_t)result; -} - -bool DeviceManagerModule::JsObjectToBool(const JSIValue &object, - const std::string &fieldStr) -{ - bool result = JSI::GetBooleanProperty(object,fieldStr.c_str()); - return result; -} - -char *DeviceManagerModule::JsObjectToString(const JSIValue &object, - const std::string &fieldStr) -{ - char* str = JSI::GetStringProperty(object, fieldStr.c_str()); - return str; -} - -int32_t DeviceManagerModule::JsToDmSubscribeInfo(const JSIValue &object,DmSubscribeInfo &info) -{ - int32_t subscribeId = -1; - subscribeId = JsObjectToInt(object,"subscribeId"); - if (subscribeId < 0 || subscribeId > DM_JSI_SUB_ID_MAX) { - DMLOG(DM_LOG_ERROR, "DeviceManagerModule::JsToDmSubscribeInfo, subscribeId error, subscribeId: %d ", subscribeId); - return -1; - } - info.subscribeId = (uint16_t)subscribeId; - - int32_t mode = -1; - mode = JsObjectToInt(object, "mode"); - info.mode = (DmDiscoverMode)mode; - - int32_t medium = -1; - medium = JsObjectToInt(object, "medium"); - info.medium = (DmExchangeMedium)medium; - - int32_t freq = -1; - freq = JsObjectToInt(object, "freq"); - info.freq = (DmExchangeFreq)freq; - - info.isSameAccount = JsObjectToBool(object, "isSameAccount"); - info.isWakeRemote = JsObjectToBool(object, "isWakeRemote"); - - int32_t capability = -1; - capability = JsObjectToInt(object, "capability"); - if (capability == DM_JSI_SUBSCRIBE_CAPABILITY_DDMP || capability == DM_JSI_SUBSCRIBE_CAPABILITY_OSD) { - (void)strncpy_s(info.capability, sizeof(info.capability), DM_CAPABILITY_OSD, strlen(DM_CAPABILITY_OSD)); - } - return 0; -} - -void DeviceManagerModule::JsToDmDeviceInfo( const JSIValue &object, - DmDeviceInfo &info) -{ - strcpy_s(info.deviceId, DM_MAX_DEVICE_ID_LEN, JsObjectToString(object, "deviceId")); - strcpy_s(info.deviceName, DM_MAX_DEVICE_NAME_LEN, JsObjectToString(object, "deviceName")); - int32_t deviceTypeId = -1; - deviceTypeId = (int32_t)JsObjectToInt(object, "deviceTypeId"); - info.deviceTypeId = (DMDeviceType)deviceTypeId; -} - -void DeviceManagerModule::JsToDmAppImageInfoAndDmExtra(const JSIValue &object, - DmAppImageInfo& appImageInfo, std::string &extra, int32_t &authType) -{ - DMLOG(DM_LOG_INFO, "JsToDmAppImageInfoAndDmExtra in."); - int32_t authTypeTemp = -1; - authTypeTemp = (int32_t)JsObjectToInt(object, "authType"); - authType = authTypeTemp; - - uint8_t *appIconBufferPtr = nullptr; - int32_t appIconBufferLen = 0; - JsToDmBuffer(object, "appIcon", &appIconBufferPtr, appIconBufferLen); - - uint8_t *appThumbnailBufferPtr = nullptr; - int32_t appThumbnailBufferLen = 0; - JsToDmBuffer(object, "appThumbnail", &appThumbnailBufferPtr, appThumbnailBufferLen); - - appImageInfo.Reset(appIconBufferPtr, appIconBufferLen, appThumbnailBufferPtr, appThumbnailBufferLen); - if (appIconBufferPtr != nullptr) { - free(appIconBufferPtr); - appIconBufferPtr = nullptr; - } - if (appThumbnailBufferPtr != nullptr) { - free(appThumbnailBufferPtr); - appThumbnailBufferPtr = nullptr; - } - - nlohmann::json jsonObj; - jsonObj[AUTH_TYPE] = authType; - std::string extraInfo = "extraInfo"; - - JsToJsonObject(object, "extraInfo", jsonObj); - extra = jsonObj.dump(); - DMLOG(DM_LOG_INFO, "appIconLen %d, appThumbnailLen %d", appIconBufferLen, appThumbnailBufferLen); -} - -void DeviceManagerModule::JsToDmBuffer(const JSIValue &object, - const std::string &fieldStr, uint8_t **bufferPtr, int32_t &bufferLen) -{ - DMLOG(DM_LOG_INFO, "JsToDmBuffer in."); - - JSIValue field = JSI::GetNamedProperty(object, fieldStr.c_str()); - if (field == JSI::CreateUndefined() || field == JSI::CreateNull()){ - DMLOG(DM_LOG_ERROR, "devicemanager JSI js to str no property: %s", fieldStr.c_str()); - return; - } - - OHOS::ACELite::TypedArrayType type = TypedArrayType::JSI_UINT8_ARRAY; - size_t length = 0; - JSIValue buffer = nullptr; - size_t offset = 0; - uint8_t *data = nullptr; - data = JSI::GetTypedArrayInfo(field, type, length, buffer, offset); - - if (type != TypedArrayType::JSI_UINT8_ARRAY || length == 0 || data == nullptr) { - DMLOG(DM_LOG_ERROR, "Invalid AppIconInfo"); - return; - } - *bufferPtr = (uint8_t*)calloc(sizeof(uint8_t), length); - if (*bufferPtr == nullptr) { - DMLOG(DM_LOG_ERROR, "low memory, calloc return nullptr, length is %zu, filed %s", length, fieldStr.c_str()); - return; - } - if (memcpy_s(*bufferPtr, length, data, length) != 0) { - DMLOG(DM_LOG_ERROR, "memcpy_s failed, filed %s", fieldStr.c_str()); - free(*bufferPtr); - *bufferPtr = nullptr; - return; - } - bufferLen = length; -} - -void DeviceManagerModule::JsToJsonObject(const JSIValue &object, - const std::string &fieldStr, nlohmann::json &jsonObj) -{ - DMLOG(DM_LOG_INFO, "JsToJsonObject in."); - JSIValue jsonField = JSI::GetNamedProperty(object, fieldStr.c_str()); - if (jsonField == JSI::CreateUndefined() || jsonField == JSI::CreateNull()){ - DMLOG(DM_LOG_ERROR, "devicemanager JSI js to str no property: %s", fieldStr.c_str()); - return; - } - - JSIValue jsProNameList = nullptr; - uint32_t jsProCount = 0; - jsProNameList = JSI::GetObjectKeys(jsonField); - jsProCount = JSI::GetArrayLength(jsProNameList); - DMLOG(DM_LOG_INFO, "Property size=%d.", jsProCount); - - JSIValue jsProName = nullptr; - JSIValue jsProValue = nullptr; - for (uint32_t index = 0; index < jsProCount; index++) { - jsProName = JSI::GetPropertyByIndex(jsProNameList, index); - - std::string strProName = JSI::ValueToString(jsProName); - jsProValue = JSI::GetNamedProperty(jsonField, strProName.c_str()); - - if (JSI::ValueIsString(jsProValue)){ - std::string natValue = JSI::ValueToString(jsProValue); - DMLOG(DM_LOG_INFO, "Property name=%s, string, value=%s", strProName.c_str(), natValue.c_str()); - jsonObj[strProName] = natValue; - } - - if (JSI::ValueIsBoolean(jsProValue)){ - bool elementValue = JSI::ValueToBoolean(jsProValue); - DMLOG(DM_LOG_INFO, "Property name=%s, boolean, value=%d.", strProName.c_str(), elementValue); - jsonObj[strProName] = elementValue; - } - - if (JSI::ValueIsNumber(jsProValue)){ - int32_t elementValue = 0; - elementValue = (int32_t)JSI::ValueToNumber(jsProValue); - jsonObj[strProName] = elementValue; - DMLOG(DM_LOG_INFO, "Property name=%s, number, value=%d.", strProName.c_str(), elementValue); - } - } -} - -void DeviceManagerModule::JsToDmAuthInfo(const JSIValue &object, std::string &extra) -{ - DMLOG(DM_LOG_INFO, "%s called.", __func__); - int32_t authType = -1; - int32_t token = -1; - - authType = JsObjectToInt(object, "authType"); - token = JsObjectToInt(object, "token"); - - nlohmann::json jsonObj; - jsonObj[AUTH_TYPE] = authType; - if (authType == DM_AUTH_TYPE_PINCODE) { - jsonObj[PIN_TOKEN] = token; - } else { - jsonObj[TOKEN] = token; - } - JsToJsonObject(object, "extraInfo", jsonObj); - extra = jsonObj.dump(); -} - -void DeviceManagerModule::CreateDmCallback(std::string &bundleName, std::string &eventType) -{ - DMLOG(DM_LOG_ERROR, "CreateDmCallback for bunderName %s eventType %s", bundleName.c_str(), eventType.c_str()); - if (eventType == DM_JSI_EVENT_DEVICE_STATE_CHANGE) { - auto iter = g_deviceStateCallbackMap.find(bundleName); - if (iter == g_deviceStateCallbackMap.end()) { - auto callback = std::make_shared(bundleName); - std::string extra = ""; - int32_t ret = OHOS::DistributedHardware::DeviceManager::GetInstance().RegisterDevStateCallback(bundleName, extra, callback); - if (ret != 0) { - DMLOG(DM_LOG_ERROR, "RegisterDevStateCallback failed for bunderName %s", bundleName.c_str()); - return; - } - g_deviceStateCallbackMap[bundleName] = callback; - } - return; - } - - if (eventType == DM_JSI_EVENT_DEVICE_FOUND || eventType == DM_JSI_EVENT_DEVICE_DISCOVER_FAIL) { - std::shared_ptr discoverCallback = nullptr; - auto iter = g_discoverCallbackMap.find(bundleName); - if (iter == g_discoverCallbackMap.end()) { - auto callback = std::make_shared(bundleName); - g_discoverCallbackMap[bundleName] = callback; - discoverCallback = callback; - } else { - discoverCallback = iter->second; - } - - discoverCallback->IncreaseRefCount(); - return; - } - - if (eventType == DM_JSI_EVENT_DMFA_CALLBACK) { - auto iter = g_dmfaCallbackMap.find(bundleName); - if (iter == g_dmfaCallbackMap.end()) { - auto callback = std::make_shared(bundleName); - int32_t ret = OHOS::DistributedHardware::DeviceManager::GetInstance().RegisterDeviceManagerFaCallback(bundleName, callback); - if (ret != 0) { - DMLOG(DM_LOG_ERROR, "RegisterDeviceManagerFaCallback failed for bunderName %s", bundleName.c_str()); - return; - } - g_dmfaCallbackMap[bundleName] = callback; - } - return; - } -} - -void DeviceManagerModule::ReleaseDmCallback(std::string &bundleName, std::string &eventType) -{ - if (eventType == DM_JSI_EVENT_DEVICE_STATE_CHANGE) { - auto iter = g_deviceStateCallbackMap.find(bundleName); - if (iter == g_deviceStateCallbackMap.end()) { - DMLOG(DM_LOG_ERROR, "ReleaseDmCallback: cannot find stateCallback for bunderName %s", bundleName.c_str()); - return; - } - int32_t ret = OHOS::DistributedHardware::DeviceManager::GetInstance().UnRegisterDevStateCallback(bundleName); - if (ret != 0) { - DMLOG(DM_LOG_ERROR, "RegisterDevStateCallback failed for bunderName %s", bundleName.c_str()); - return; - } - g_deviceStateCallbackMap.erase(bundleName); - return; - } - - if (eventType == DM_JSI_EVENT_DEVICE_FOUND || eventType == DM_JSI_EVENT_DEVICE_DISCOVER_FAIL) { - std::shared_ptr discoverCallback = nullptr; - auto iter = g_discoverCallbackMap.find(bundleName); - if (iter == g_discoverCallbackMap.end()) { - return; - } - - discoverCallback = iter->second; - discoverCallback->DecreaseRefCount(); - if (discoverCallback->GetRefCount() == 0) { - g_discoverCallbackMap.erase(bundleName); - } - return; - } - - if (eventType == DM_JSI_EVENT_DMFA_CALLBACK) { - auto iter = g_dmfaCallbackMap.find(bundleName); - if (iter == g_dmfaCallbackMap.end()) { - DMLOG(DM_LOG_ERROR, "cannot find dmFaCallback for bunderName %s", bundleName.c_str()); - return; - } - int32_t ret = OHOS::DistributedHardware::DeviceManager::GetInstance().UnRegisterDeviceManagerFaCallback(bundleName); - if (ret != 0) { - DMLOG(DM_LOG_ERROR, "RegisterDevStateCallback failed for bunderName %s", bundleName.c_str()); - return; - } - g_dmfaCallbackMap.erase(bundleName); - return; - } -} - -void DeviceManagerModule::AuthRsultVerifyInfoAsyncWorkFunc(void *data) -{ - DMLOG(DM_LOG_INFO, "AuthRsultVerifyInfoAsyncWorkFunc in ............"); - AuthFuncParams* params = reinterpret_cast(data); - JSI::CallFunction(params->handlerRef, params->thisVarRef_, params->args, params->argsSize); -} - - -JSIValue DeviceManagerModule::SetUserOperationSync(const JSIValue thisVal, const JSIValue *args, uint8_t argsSize) -{ - DMLOG(DM_LOG_INFO, "SetUserOperationSync in"); - if (argsSize < 1) { - DMLOG(DM_LOG_ERROR, "1 argument is required."); - return JSI::CreateNull(); - } - - if (!JSI::ValueIsNumber(args[0])){ - DMLOG(DM_LOG_ERROR, "a Number is required."); - return JSI::CreateNull(); - } - - std::string bundleName = globalBundleName_.GetBundleName(); - int32_t action = 0; - action = static_cast(JSI::ValueToNumber(args[0])); - - DMLOG(DM_LOG_INFO, "SetUserOperation action %d", action); - - int32_t ret = OHOS::DistributedHardware::DeviceManager::GetInstance().SetUserOperation(bundleName, action); - if (ret != 0) { - DMLOG(DM_LOG_ERROR, "SetUserOperation for bunderName %s failed, ret %d", - bundleName.c_str(), ret); - return JSI::CreateNull(); - } - - return JSI::CreateNull(); -} - -JSIValue DeviceManagerModule::GetAuthenticationParamSync(const JSIValue thisVal, const JSIValue *args, uint8_t argsSize) -{ - DMLOG(DM_LOG_INFO, "GetAuthenticationParamSync in"); - std::string bundleName = globalBundleName_.GetBundleName(); - JSIValue resultParam = JSI::CreateObject(); - DmAuthParam authParam; - int32_t ret = OHOS::DistributedHardware::DeviceManager::GetInstance().GetAuthenticationParam(bundleName, authParam); - if (ret != 0) { - DMLOG(DM_LOG_ERROR, "GetAuthenticationParam for %s failed, ret %d", - bundleName.c_str(), ret); - return JSI::CreateNull(); - } - DmAuthParamToJsAuthParamy(authParam,resultParam); - return resultParam; -} - -JSIValue DeviceManagerModule::GetTrustedDeviceListSync(const JSIValue thisVal, const JSIValue *args, uint8_t argsSize) -{ - DMLOG(DM_LOG_INFO, "GetTrustedDeviceList in"); - JSIValue array = JSI::CreateNull(); - std::string extra = ""; - std::vector devList; - std::string bundleName = globalBundleName_.GetBundleName(); - - int32_t ret = OHOS::DistributedHardware::DeviceManager::GetInstance().GetTrustedDeviceList(bundleName, extra, devList); - if (ret != 0) { - DMLOG(DM_LOG_ERROR, "GetTrustedDeviceList for bunderName %s failed, ret %d", - bundleName.c_str(), ret); - return array; - } - if (devList.size() > 0) { - bool isArray = false; - array = JSI::CreateArray(devList.size()); - isArray = JSI::ValueIsArray(array); - if (isArray == false) { - DMLOG(DM_LOG_ERROR, "JSI_create_array fail"); - } - - for (size_t i = 0; i != devList.size(); ++i) { - DeviceInfoToJsArray(devList, i, array); - } - } else { - DMLOG(DM_LOG_ERROR, "devList is null"); - } - - return array; -} - -JSIValue DeviceManagerModule::StartDeviceDiscoverSync(const JSIValue thisVal, const JSIValue *args, uint8_t argsSize) -{ - DMLOG(DM_LOG_INFO, "StartDeviceDiscoverSync in"); - std::string bundleName = globalBundleName_.GetBundleName(); - - if (argsSize < 1){ - DMLOG(DM_LOG_ERROR, "1 argument is required."); - return JSI::CreateNull(); - } - - if (!JSI::ValueIsObject(args[0])){ - DMLOG(DM_LOG_ERROR, "an object is required."); - return JSI::CreateNull(); - } - - std::shared_ptr discoverCallback = nullptr; - auto iter = g_discoverCallbackMap.find(bundleName); - if (iter == g_discoverCallbackMap.end()) { - discoverCallback = std::make_shared(bundleName); - g_discoverCallbackMap[bundleName] = discoverCallback; - } else { - discoverCallback = iter->second; - } - DmSubscribeInfo subInfo; - int32_t res = JsToDmSubscribeInfo(args[0], subInfo); - if (res != 0){ - DMLOG(DM_LOG_ERROR, "Wrong subscribeId."); - return JSI::CreateNull(); - } - - DMLOG(DM_LOG_INFO, "subInfo %d , %d, %d, %d, %d , %d, %s", - subInfo.subscribeId, - subInfo.mode, - subInfo.medium, - subInfo.freq, - subInfo.isSameAccount, - subInfo.isWakeRemote, - subInfo.capability); - - int32_t ret = OHOS::DistributedHardware::DeviceManager::GetInstance().StartDeviceDiscovery(bundleName, - subInfo, discoverCallback); - if (ret != 0) { - DMLOG(DM_LOG_ERROR, "StartDeviceDiscovery for bunderName %s failed, ret %d", - bundleName.c_str(), ret); - return JSI::CreateNull(); - } - return JSI::CreateNull(); -} - -JSIValue DeviceManagerModule::StopDeviceDiscoverSync(const JSIValue thisVal, const JSIValue *args, uint8_t argsSize) -{ - DMLOG(DM_LOG_INFO, "StopDeviceDiscoverSync in"); - std::string bundleName = globalBundleName_.GetBundleName(); - - if (argsSize < 1){ - DMLOG(DM_LOG_ERROR, "1 argument is required."); - return JSI::CreateNull(); - } - - if (!JSI::ValueIsNumber(args[0])){ - DMLOG(DM_LOG_ERROR, "a Number is required."); - return JSI::CreateNull(); - } - - uint16_t subscribeId = 0; - subscribeId = static_cast(JSI::ValueToNumber(args[0])); - DMLOG(DM_LOG_INFO, "subscribeId %d ", subscribeId); - - int32_t ret = OHOS::DistributedHardware::DeviceManager::GetInstance().StopDeviceDiscovery(bundleName, subscribeId); - if (ret != 0) { - DMLOG(DM_LOG_ERROR, "StopDeviceDiscovery for bunderName %s failed, ret %d", - bundleName.c_str(), ret); - return JSI::CreateNull(); - } - - return JSI::CreateNull(); -} - -JSIValue DeviceManagerModule::AuthenticateDevice(const JSIValue thisVal, const JSIValue *args, uint8_t argsSize) -{ - DMLOG(DM_LOG_INFO, "AuthenticateDevice in"); - std::string bundleName = globalBundleName_.GetBundleName(); - if (argsSize < 3){ - DMLOG(DM_LOG_ERROR, "3 argument is required."); - return JSI::CreateNull(); - } - - if (!JSI::ValueIsObject(args[0])){ - DMLOG(DM_LOG_ERROR, "an object is required."); - return JSI::CreateNull(); - } - - if (!JSI::ValueIsObject(args[1])){ - DMLOG(DM_LOG_ERROR, "an object is required."); - return JSI::CreateNull(); - } - - - authAsyncCallbackInfo_.thisVal_ = JSI::AcquireValue(thisVal); - authAsyncCallbackInfo_.callback = JSI::AcquireValue(args[2]); - - std::shared_ptr authCallback = nullptr; - auto iter = g_authCallbackMap.find(bundleName); - if (iter == g_authCallbackMap.end()) { - authCallback = std::make_shared(bundleName); - g_authCallbackMap[bundleName] = authCallback; - } else { - authCallback = iter->second; - } - DmDeviceInfo deviceInfo; - JsToDmDeviceInfo(args[0], deviceInfo); - - DMLOG(DM_LOG_INFO, "deviceInfo %s , %s, %d", - deviceInfo.deviceId, - deviceInfo.deviceName, - deviceInfo.deviceTypeId); - - DmAppImageInfo appImageInfo(nullptr, 0, nullptr, 0); - std::string extra; - JsToDmAppImageInfoAndDmExtra(args[1], appImageInfo, extra, authAsyncCallbackInfo_.authType); - - int32_t ret = OHOS::DistributedHardware::DeviceManager::GetInstance().AuthenticateDevice(bundleName, deviceInfo, - appImageInfo, extra, authCallback); - if (ret != 0) { - DMLOG(DM_LOG_ERROR, "AuthenticateDevice for bunderName %s failed, ret %d", - bundleName.c_str(), ret); - } - - return JSI::CreateUndefined(); -} - -JSIValue DeviceManagerModule::VerifyAuthInfo(const JSIValue thisVal, const JSIValue *args, uint8_t argsSize) -{ - DMLOG(DM_LOG_INFO, "VerifyAuthInfo in"); - std::string bundleName = globalBundleName_.GetBundleName(); - if (argsSize < 2){ - DMLOG(DM_LOG_ERROR, "2 argument is required."); - return JSI::CreateNull(); - } - - if (!JSI::ValueIsObject(args[0])){ - DMLOG(DM_LOG_ERROR, "an object is required."); - return JSI::CreateNull(); - } - - verifyAsyncCallbackInfo_.thisVal_ = JSI::AcquireValue(thisVal); - verifyAsyncCallbackInfo_.callback = JSI::AcquireValue(args[1]); - - std::shared_ptr verifyCallback = nullptr; - auto iter = g_checkAuthCallbackMap.find(bundleName); - if (iter == g_checkAuthCallbackMap.end()) { - verifyCallback = std::make_shared(bundleName); - g_checkAuthCallbackMap[bundleName] = verifyCallback; - } else { - verifyCallback = iter->second; - } - std::string authParam; - JsToDmAuthInfo(args[0], authParam); - int32_t ret = OHOS::DistributedHardware::DeviceManager::GetInstance().CheckAuthentication(bundleName, - authParam, verifyCallback); - if (ret != 0) { - DMLOG(DM_LOG_ERROR, "VerifyAuthInfo for bunderName %s failed, ret %d", - bundleName.c_str(), ret); - } - return JSI::CreateUndefined(); -} - -JSIValue DeviceManagerModule::JsOn(const JSIValue thisVal, const JSIValue *args, uint8_t argsSize) -{ - DMLOG(DM_LOG_INFO, "JsOn in"); - std::string bundleName = globalBundleName_.GetBundleName(); - if (argsSize < 2){ - DMLOG(DM_LOG_ERROR, "2 argument is required."); - return JSI::CreateNull(); - } - if (!JSI::ValueIsString(args[0])){ - DMLOG(DM_LOG_ERROR, "a string is required."); - return JSI::CreateNull(); - } - if (!JSI::ValueIsFunction(args[1])){ - DMLOG(DM_LOG_ERROR, "a FUNC is required."); - return JSI::CreateNull(); - } - std::string eventType = JSI::ValueToString(args[0]); - - DMLOG(DM_LOG_INFO, "JsOn for bunderName %s, eventType %s ", bundleName.c_str(), - eventType.c_str()); - std::shared_ptr DmNativeEventobj = std::make_shared(thisVal); - DmNativeEventobj->On(eventType, args[1], thisVal); - CreateDmCallback(bundleName, eventType); - - return JSI::CreateUndefined(); -} - -JSIValue DeviceManagerModule::JsOff(const JSIValue thisVal, const JSIValue *args, uint8_t argsSize) -{ - DMLOG(DM_LOG_INFO, "JsOff in"); - std::string bundleName = globalBundleName_.GetBundleName(); - if (argsSize < 2){ - DMLOG(DM_LOG_ERROR, "2 argument is required."); - return JSI::CreateNull(); - } - if (!JSI::ValueIsString(args[0])){ - DMLOG(DM_LOG_ERROR, "a string is required."); - return JSI::CreateNull(); - } - if (!JSI::ValueIsFunction(args[1])){ - DMLOG(DM_LOG_ERROR, "a FUNC is required."); - return JSI::CreateNull(); - } - - std::string eventType = JSI::ValueToString(args[0]); - - DMLOG(DM_LOG_INFO, "JsOff for bunderName %s, eventType %s ", bundleName.c_str(), - eventType.c_str()); - - std::shared_ptr DmNativeEventobj = std::make_shared(thisVal); - DmNativeEventobj->Off(eventType); - ReleaseDmCallback(bundleName, eventType); - - return JSI::CreateUndefined(); -} - -JSIValue DeviceManagerModule::ReleaseDeviceManager(const JSIValue thisVal, const JSIValue *args, uint8_t argsSize) -{ - DMLOG(DM_LOG_INFO, "ReleaseDeviceManager in"); - std::string bundleName = globalBundleName_.GetBundleName(); - DMLOG(DM_LOG_INFO, "ReleaseDeviceManager for bunderName %s", bundleName.c_str()); - - int32_t ret = OHOS::DistributedHardware::DeviceManager::GetInstance().UnInitDeviceManager(bundleName); - if (ret != 0) { - DMLOG(DM_LOG_ERROR, "ReleaseDeviceManager for bunderName %s failed, ret %d", - bundleName.c_str(), ret); - JSIValue result = JSI::CreateNumber((double)ret); - return result; - } - - g_deviceManagerMap.erase(bundleName); - g_initCallbackMap.erase(bundleName); - g_deviceStateCallbackMap.erase(bundleName); - g_discoverCallbackMap.erase(bundleName); - g_authCallbackMap.erase(bundleName); - g_checkAuthCallbackMap.erase(bundleName); - - return JSI::CreateUndefined(); -} - -JSIValue DeviceManagerModule::CreateDeviceManager(const JSIValue thisVal, const JSIValue *args, uint8_t argsSize) -{ - if (argsSize < 1) { - DMLOG(DM_LOG_ERROR,"1 argument is required."); - return JSI::CreateBoolean(false); - } - - if (!JSI::ValueIsString(args[0])) { - DMLOG(DM_LOG_ERROR,"a string is required."); - return JSI::CreateBoolean(false); - } - std::string bundleName = JSI::ValueToString(args[0]);; - globalBundleName_.SetBundleName(bundleName); - - DMLOG(DM_LOG_INFO, "CreateDeviceManager for bunderName %s", bundleName.c_str()); - - if (DeviceManagerModule::GetDeviceManagerJSI(bundleName) != nullptr) { - DMLOG(DM_LOG_INFO, "CreateDeviceManager repeat for bunderName %s", bundleName.c_str()); - return JSI::CreateBoolean(true); - } - - DeviceManagerModule *obj = new DeviceManagerModule(); - obj->bundleName_ = bundleName; - g_deviceManagerMap[bundleName] = obj; - - std::shared_ptr initCallback = std::make_shared(bundleName); - if (OHOS::DistributedHardware::DeviceManager::GetInstance().InitDeviceManager(bundleName, initCallback) != 0) { - DMLOG(DM_LOG_ERROR, "InitDeviceManager for bunderName %s failed", bundleName.c_str()); - return JSI::CreateBoolean(false); - } - - return JSI::CreateBoolean(true); -} - -void InitDeviceManagerModule(JSIValue exports) -{ - JSI::SetModuleAPI(exports, "createDeviceManager", DeviceManagerModule::CreateDeviceManager); - JSI::SetModuleAPI(exports, "getTrustedDeviceListSync", DeviceManagerModule::GetTrustedDeviceListSync); - JSI::SetModuleAPI(exports, "release", DeviceManagerModule::ReleaseDeviceManager); - JSI::SetModuleAPI(exports, "startDeviceDiscovery", DeviceManagerModule::StartDeviceDiscoverSync); - JSI::SetModuleAPI(exports, "stopDeviceDiscovery", DeviceManagerModule::StopDeviceDiscoverSync); - JSI::SetModuleAPI(exports, "authenticateDevice", DeviceManagerModule::AuthenticateDevice); - JSI::SetModuleAPI(exports, "verifyAuthInfo", DeviceManagerModule::VerifyAuthInfo); - JSI::SetModuleAPI(exports, "setUserOperation", DeviceManagerModule::SetUserOperationSync); - JSI::SetModuleAPI(exports, "getAuthenticationParam", DeviceManagerModule::GetAuthenticationParamSync); - JSI::SetModuleAPI(exports, "on", DeviceManagerModule::JsOn); - JSI::SetModuleAPI(exports, "off", DeviceManagerModule::JsOff); -} -} -} \ No newline at end of file diff --git a/ext/mini/sa_profile/4802.xml b/ext/mini/sa_profile/4802.xml deleted file mode 100644 index 3400882398acea4b5d25575d685eae5000497217..0000000000000000000000000000000000000000 --- a/ext/mini/sa_profile/4802.xml +++ /dev/null @@ -1,27 +0,0 @@ - - - - foundation - - 4802 - libdevicemanagerservice.z.so - - - true - false - 1 - - diff --git a/ext/mini/sa_profile/BUILD.gn b/ext/mini/sa_profile/BUILD.gn deleted file mode 100644 index 6edcf99eb5075577631190b30ae558b9bfcb553a..0000000000000000000000000000000000000000 --- a/ext/mini/sa_profile/BUILD.gn +++ /dev/null @@ -1,20 +0,0 @@ -# Copyright (c) 2022 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. - -import("//build/ohos/sa_profile/sa_profile.gni") - -ohos_sa_profile("dm_sa_profile") { - sources = [ "4802.xml" ] - - part_name = "device_manager_base" -} diff --git a/ext/mini/services/devicemanagerservice/BUILD.gn b/ext/mini/services/devicemanagerservice/BUILD.gn deleted file mode 100644 index b9fa421231cba147e7499e47dd80bf5af2404607..0000000000000000000000000000000000000000 --- a/ext/mini/services/devicemanagerservice/BUILD.gn +++ /dev/null @@ -1,270 +0,0 @@ -# Copyright (c) 2022 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") - -if (defined(ohos_lite)) { - if (ohos_kernel_type == "liteos_m") { - static_library("devicemanagerservice_mini") { - include_dirs = [ - "include", - "include/ability", - "include/softbus", - "include/requestauth", - "include/auth", - "include/timer", - "include/message", - "${utils_path}/include/cipher", - "${utils_path}/include/log", - "${utils_path}/include", - "${common_path}/include", - "${innerkits_path_small}/native_cpp/include", - "${innerkits_path_small}/native_cpp/include/notify", - "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/distributedschedule/samgr_lite/interfaces/kits/samgr", - ] - - sources = [ - "src/ability/lite/dm_ability_manager.cpp", - "src/auth/hichain_connector.cpp", - "src/dispatch/command_dispatch.cpp", - "src/dispatch/message_processing.cpp", - "src/dispatch/server_init.cpp", - "src/dispatch/server_stub.cpp", - "src/message/msg_codec.cpp", - "src/message/msg_head.cpp", - "src/message/msg_request_auth.cpp", - "src/message/msg_response_auth.cpp", - "src/message/msg_sync_group.cpp", - "src/requestauth/auth_manager.cpp", - "src/requestauth/request_session.cpp", - "src/requestauth/response_session.cpp", - "src/softbus/softbus_adapter.cpp", - "src/softbus/softbus_session.cpp", - "src/timer/dm_timer.cpp", - ] - - defines = [ - "LITE_DEVICE", - "HI_LOG_ENABLE", - "DH_LOG_TAG=\"devicemanagerservice\"", - "LOG_DOMAIN=0xD004100", - ] - - ldflags = dm_ldflags - - deps = [ - "${innerkits_path_small}/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") { - include_dirs = [ - "include", - "include/ability", - "include/softbus", - "include/requestauth", - "include/auth", - "include/ipc", - "include/timer", - "include/message", - "include/ipc/lite", - "${utils_path}/include/cipher", - "${utils_path}/include/log", - "${utils_path}/include/ipc/lite", - "${utils_path}/include", - "${common_path}/include/ipc", - "${common_path}/include/ipc/model", - "${common_path}/include", - "${innerkits_path}/native_cpp/include", - "${innerkits_path}/native_cpp/include/ipc/lite", - ] - - 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/distributedschedule/samgr_lite/interfaces/kits/samgr", - ] - - sources = [ - "src/ability/lite/dm_ability_manager.cpp", - "src/auth/hichain_connector.cpp", - "src/ipc/ipc_server_adapter.cpp", - "src/ipc/ipc_server_listener_adapter.cpp", - "src/ipc/lite/ipc_cmd_parser.cpp", - "src/ipc/lite/ipc_server_listener.cpp", - "src/ipc/lite/ipc_server_listenermgr.cpp", - "src/ipc/lite/ipc_server_main.cpp", - "src/ipc/lite/ipc_server_stub.cpp", - "src/message/msg_codec.cpp", - "src/message/msg_head.cpp", - "src/message/msg_request_auth.cpp", - "src/message/msg_response_auth.cpp", - "src/message/msg_sync_group.cpp", - "src/requestauth/auth_manager.cpp", - "src/requestauth/request_session.cpp", - "src/requestauth/response_session.cpp", - "src/softbus/softbus_adapter.cpp", - "src/softbus/softbus_session.cpp", - "src/timer/dm_timer.cpp", - ] - - defines = [ - "LITE_DEVICE", - "HI_LOG_ENABLE", - "DH_LOG_TAG=\"devicemanagerservice\"", - "LOG_DOMAIN=0xD004100", - ] - - ldflags = dm_ldflags - - deps = [ - "${innerkits_path}/native_cpp:devicemanagersdk", - "${utils_path}:devicemanagerutils", - "//base/hiviewdfx/hilog_lite/frameworks/featured:hilog_shared", - "//base/security/deviceauth/services:deviceauth_sdk", - "//base/startup/syspara_lite/frameworks/parameter/src:sysparam", - "//foundation/communication/dsoftbus/sdk:softbus_client", - "//foundation/communication/ipc_lite:liteipc_adapter", - "//foundation/distributedschedule/samgr_lite/samgr:samgr", - "//third_party/bounds_checking_function:libsec_shared", - "//third_party/mbedtls:mbedtls_shared", - "//utils/native/lite:utils", - ] - } - } -} else { - ohos_shared_library("devicemanagerservice") { - include_dirs = [ - "//utils/native/base/include", - "//utils/system/safwk/native/include", - "include", - "include/ability", - "include/softbus", - "include/requestauth", - "include/auth", - "include/ipc", - "include/message", - "include/timer", - "include/ipc/standard", - "${utils_path}/include/cipher", - "${utils_path}/include/log", - "${utils_path}/include", - "${utils_path}/include/ipc/standard", - "${common_path}/include", - "${common_path}/include/ipc", - "${common_path}/include/ipc/model", - "${innerkits_path}/native_cpp/include", - "${innerkits_path}/native_cpp/include/ipc/standard", - "//base/security/deviceauth/interfaces/innerkits", - "//base/startup/syspara_lite/adapter/native/syspara/include", - "//third_party/json/include", - ] - - sources = [ - "src/ability/standard/dm_ability_manager.cpp", - "src/auth/hichain_connector.cpp", - "src/ipc/ipc_server_adapter.cpp", - "src/ipc/ipc_server_listener_adapter.cpp", - "src/ipc/standard/ipc_cmd_parser.cpp", - "src/ipc/standard/ipc_server_client_proxy.cpp", - "src/ipc/standard/ipc_server_listener.cpp", - "src/ipc/standard/ipc_server_stub.cpp", - "src/message/msg_codec.cpp", - "src/message/msg_head.cpp", - "src/message/msg_request_auth.cpp", - "src/message/msg_response_auth.cpp", - "src/message/msg_sync_group.cpp", - "src/requestauth/auth_manager.cpp", - "src/requestauth/request_session.cpp", - "src/requestauth/response_session.cpp", - "src/softbus/softbus_adapter.cpp", - "src/softbus/softbus_session.cpp", - "src/timer/dm_timer.cpp", - ] - - deps = [ - "${innerkits_path}/native_cpp:devicemanagersdk", - "${utils_path}:devicemanagerutils", - "//base/security/deviceauth/services:deviceauth_sdk", - "//foundation/aafwk/standard/interfaces/innerkits/ability_manager:ability_manager", - "//foundation/aafwk/standard/interfaces/innerkits/want:want", - "//foundation/aafwk/standard/services/abilitymgr:abilityms", - "//utils/native/base:utils", - ] - - defines = [ - "HI_LOG_ENABLE", - "DH_LOG_TAG=\"devicemanagerservice\"", - "LOG_DOMAIN=0xD004100", - ] - - external_deps = [ - "appexecfwk_standard:appexecfwk_base", - "appexecfwk_standard:appexecfwk_core", - "appexecfwk_standard:libeventhandler", - "dsoftbus_standard:softbus_client", - "hiviewdfx_hilog_native:libhilog", - "ipc:ipc_core", - "safwk:system_ability_fwk", - "samgr_standard:samgr_proxy", - "startup_l2:syspara", - ] - - subsystem_name = "distributedhardware" - - part_name = "device_manager_base" - } -} diff --git a/ext/mini/services/devicemanagerservice/include/ability/dm_ability_manager.h b/ext/mini/services/devicemanagerservice/include/ability/dm_ability_manager.h deleted file mode 100644 index f29f541e6c6ce844867624f68a2e72e145f936d6..0000000000000000000000000000000000000000 --- a/ext/mini/services/devicemanagerservice/include/ability/dm_ability_manager.h +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (c) 2022 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_ABILITY_MANAGER_H -#define OHOS_DM_ABILITY_MANAGER_H - -#include -#include -#include -#include - -#include "single_instance.h" - -namespace OHOS { -namespace DistributedHardware { -enum AbilityRole : int32_t { - ABILITY_ROLE_PASSIVE = 0, - ABILITY_ROLE_INITIATIVE = 1, - ABILITY_ROLE_UNKNOWN = 2 -}; - -enum AbilityStatus : int32_t { - ABILITY_STATUS_FAILED = 0, - ABILITY_STATUS_SUCCESS = 1, - ABILITY_STATUS_START = 2 -}; - -typedef enum FaAction { - USER_OPERATION_TYPE_ALLOW_AUTH = 0, - USER_OPERATION_TYPE_CANCEL_AUTH = 1, - USER_OPERATION_TYPE_AUTH_CONFIRM_TIMEOUT = 2, - USER_OPERATION_TYPE_CANCEL_PINCODE_DISPLAY = 3, - USER_OPERATION_TYPE_CANCEL_PINCODE_INPUT = 4 -} FaAction; - -class DmAbilityManager { -DECLARE_SINGLE_INSTANCE(DmAbilityManager); -public: - AbilityRole GetAbilityRole(); - AbilityStatus StartAbility(AbilityRole role); - void StartAbilityDone(); - -private: - void WaitForTimeout(uint32_t timeout_s); - -private: - sem_t mSem_; - AbilityStatus mStatus_; - AbilityRole mAbilityStatus_; -}; -} // namespace DistributedHardware -} // namespace OHOS -#endif diff --git a/ext/mini/services/devicemanagerservice/include/auth/hichain_connector.h b/ext/mini/services/devicemanagerservice/include/auth/hichain_connector.h deleted file mode 100644 index 14032ec06a2a3b90edd7627e6cc1390e71a2ba77..0000000000000000000000000000000000000000 --- a/ext/mini/services/devicemanagerservice/include/auth/hichain_connector.h +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Copyright (c) 2022 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_HICHAIN_CONNECTOR_H -#define OHOS_HICHAIN_CONNECTOR_H - -#include -#include -#include - -#include "nlohmann/json.hpp" - -#include "device_auth.h" - -#include "single_instance.h" -#include "msg_response_auth.h" - -namespace OHOS { -namespace DistributedHardware { -enum { - HICHAIN_SUCCESS = 0, - GROUP_CREATE_FAILED = 1, - MEMBER_ADD_FAILED = 2, - CREATE_CHANNEL_FAILED = 3, -}; - -struct GroupInfo { - std::string groupName; - std::string groupId; - std::string groupOwner; - int32_t groupType; - int32_t groupVisibility; - - GroupInfo() : groupName(""), groupId(""), groupOwner(""), groupType(0), groupVisibility(0) {} -}; - -void from_json(const nlohmann::json& jsonObject, GroupInfo& groupInfo); - -class HichainConnectorCallback { -public: - virtual void OnGroupCreated(int64_t requestId, const std::string &groupId) = 0; - virtual void OnMemberJoin(int64_t requestId, int32_t status) = 0; -}; - -class HichainAuthenCallBack { -public: - static bool onTransmit(int64_t requestId, const uint8_t *data, uint32_t dataLen); - static void onSessionKeyReturned(int64_t requestId, const uint8_t *sessionKey, uint32_t sessionKeyLen); - 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); -}; - -class HichainConnector { -DECLARE_SINGLE_INSTANCE(HichainConnector); -public: - int Init(); - bool OnTransmit(int64_t requestId, const uint8_t *data, uint32_t dataLen); - int64_t GenRequestId(); - void RegisterConnectorCallback(std::shared_ptr callback); - int32_t CreateGroup(int64_t requestId, const std::string &groupName); - int32_t AddMemeber(std::string deviceId, std::shared_ptr msgResponseAuth); - void GetRelatedGroups(std::string DeviceId, std::vector &groupList); - void SyncGroups(std::string deviceId, std::vector &remoteGroupIdList); - int32_t DelMemberFromGroup(std::string groupId, std::string deviceId); - void DeleteGroup(std::string &groupId); - void OnGroupCreated(int64_t requestId, const std::string &returnData); - void GetSyncGroupList(std::vector &groupList, std::vector &syncGroupList); - void OnMemberJoin(int64_t requestId, int32_t status); - int32_t GetGroupInfo(std::string queryParams, std::vector &groupList); - int32_t IsGroupCreated(std::string groupName, GroupInfo &groupInfo); - -private: - std::string GetConnectPara(std::string deviceId, std::shared_ptr msgResponseAuth); - bool IsGroupInfoInvalid(GroupInfo &group); - -private: - std::shared_ptr hichainConnectorCallback_ = nullptr; - const DeviceGroupManager *deviceGroupManager_ = nullptr; - DeviceAuthCallback deviceAuthCallback_; -}; -} // namespace DistributedHardware -} // namespace OHOS -#endif // OHOS_HICHAIN_ADAPTER_H diff --git a/ext/mini/services/devicemanagerservice/include/dispatch/authenticate_device_req.h b/ext/mini/services/devicemanagerservice/include/dispatch/authenticate_device_req.h deleted file mode 100644 index 3e12d9a888723b165b94c4a483029f8f31de0546..0000000000000000000000000000000000000000 --- a/ext/mini/services/devicemanagerservice/include/dispatch/authenticate_device_req.h +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (c) 2022 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; - } - - const DmAppImageInfo& GetAppImageInfo() const - { - return appImageInfo_; - } - - void SetAppImageInfo(const DmAppImageInfo &appImageInfo) - { - appImageInfo_ = appImageInfo; - } - - const std::string& GetExtra() const - { - return extra_; - } - - void SetExtra(std::string &extra) - { - extra_ = extra; - } -private: - DmDeviceInfo deviceInfo_; - DmAppImageInfo appImageInfo_; - std::string extra_; -}; -} // namespace DistributedHardware -} // namespace OHOS -#endif // OHOS_DEVICE_MANAGER_AUTHENTICATE_DEVICE_REQ_H diff --git a/ext/mini/services/devicemanagerservice/include/dispatch/check_authenticate_req.h b/ext/mini/services/devicemanagerservice/include/dispatch/check_authenticate_req.h deleted file mode 100644 index 123ef182617fdbd2797d782369e000efaa11750f..0000000000000000000000000000000000000000 --- a/ext/mini/services/devicemanagerservice/include/dispatch/check_authenticate_req.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (c) 2022 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_CHECK_AUTHENTICATE_REQ_H -#define OHOS_DEVICE_MANAGER_CHECK_AUTHENTICATE_REQ_H - -#include "message_req.h" - -namespace OHOS { -namespace DistributedHardware { -class CheckAuthenticateReq : public MessageReq { -DECLARE_MESSAGE_MODEL(CheckAuthenticateReq); -public: - const std::string& GetAuthPara() const - { - return authPara_; - } - - void SetAuthPara(std::string &authPara) - { - authPara_ = authPara; - } -private: - std::string authPara_; -}; -} // namespace DistributedHardware -} // namespace OHOS -#endif // OHOS_DEVICE_MANAGER_CHECK_AUTHENTICATE_REQ_H diff --git a/ext/mini/services/devicemanagerservice/include/dispatch/command_dispatch.h b/ext/mini/services/devicemanagerservice/include/dispatch/command_dispatch.h deleted file mode 100644 index efe52f3b9351973b1a661ed9208f935180ff89f2..0000000000000000000000000000000000000000 --- a/ext/mini/services/devicemanagerservice/include/dispatch/command_dispatch.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * 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_processing.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/ext/mini/services/devicemanagerservice/include/dispatch/get_authenticationparam_rsp.h b/ext/mini/services/devicemanagerservice/include/dispatch/get_authenticationparam_rsp.h deleted file mode 100644 index 515497b229a348b1d5a5d2361f403434f8d12e85..0000000000000000000000000000000000000000 --- a/ext/mini/services/devicemanagerservice/include/dispatch/get_authenticationparam_rsp.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) 2022 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/ext/mini/services/devicemanagerservice/include/dispatch/get_trustdevice_req.h b/ext/mini/services/devicemanagerservice/include/dispatch/get_trustdevice_req.h deleted file mode 100644 index 03dacc6baceee7ca4a16905b3e793f82379a77cf..0000000000000000000000000000000000000000 --- a/ext/mini/services/devicemanagerservice/include/dispatch/get_trustdevice_req.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (c) 2022 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(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/ext/mini/services/devicemanagerservice/include/dispatch/get_trustdevice_rsp.h b/ext/mini/services/devicemanagerservice/include/dispatch/get_trustdevice_rsp.h deleted file mode 100644 index d3abf9f37d17e04b6e681e96b3f4c1e766c02f77..0000000000000000000000000000000000000000 --- a/ext/mini/services/devicemanagerservice/include/dispatch/get_trustdevice_rsp.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2022 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/ext/mini/services/devicemanagerservice/include/dispatch/message_def.h b/ext/mini/services/devicemanagerservice/include/dispatch/message_def.h deleted file mode 100644 index c735a5b7c20f34fb1b54844d82c0b4eb719443e8..0000000000000000000000000000000000000000 --- a/ext/mini/services/devicemanagerservice/include/dispatch/message_def.h +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (c) 2022 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, - START_DEVICE_DISCOVER, - STOP_DEVICE_DISCOVER, - AUTHENTICATE_DEVICE, - CHECK_AUTHENTICATION, - SERVER_DEVICE_STATE_NOTIFY, - SERVER_DEVICE_FOUND, - SERVER_DISCOVER_FINISH, - SERVER_AUTH_RESULT, - SERVER_CHECK_AUTH_RESULT, - SERVER_GET_AUTHENTCATION_INFO, - SERVER_USER_AUTHORIZATION_OPERATION, - SERVER_DEVICEMANAGER_FA_NOTIFY, -}; -} // namespace DistributedHardware -} // namespace OHOS -#endif // DEVICE_MANAGER_MESSAGE_DEF_H diff --git a/ext/mini/services/devicemanagerservice/include/dispatch/message_processing.h b/ext/mini/services/devicemanagerservice/include/dispatch/message_processing.h deleted file mode 100644 index 9b8e276dea9fe9925c6f9015c9ed92253cd0518b..0000000000000000000000000000000000000000 --- a/ext/mini/services/devicemanagerservice/include/dispatch/message_processing.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (c) 2022 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_PROCESSING_H -#define OHOS_DEVICE_MANAGER_MESSAGE_PROCESSING_H - -#include - -#include "dm_app_image_info.h" -#include "dm_device_info.h" -#include "dm_subscribe_info.h" -#include "nlohmann/json.hpp" -#include "get_authenticationparam_rsp.h" -#include "get_trustdevice_rsp.h" -#include "single_instance.h" - -namespace OHOS { -namespace DistributedHardware { -class MessageProcessing { -DECLARE_SINGLE_INSTANCE(MessageProcessing); -public: - int32_t ModuleInit(); - int32_t GetTrustedDeviceList(std::string &pkgName, std::string &extra, DmDeviceInfo **info, int32_t *infoNum, std::shared_ptr prsp); - int32_t StartDeviceDiscovery(std::string &pkgName, const DmSubscribeInfo &dmSubscribeInfo); - int32_t StopDiscovery(std::string &pkgName, uint16_t subscribeId); - int32_t AuthenticateDevice(std::string &pkgName, const DmDeviceInfo &deviceInfo, - const DmAppImageInfo &imageInfo, std::string &extra); - int32_t CheckAuthentication(std::string &authPara); - int32_t GetAuthenticationParam(std::string &pkgName, DmAuthParam &authParam, std::shared_ptr prsp); - int32_t SetUserOperation(std::string &pkgName, int32_t action); - static int32_t GenRandInt(int32_t minPinToken, int32_t maxPinToken); -private: - int32_t CheckParamValid(nlohmann::json &extraJson, const DmAppImageInfo &imageInfo); -}; -} // namespace DistributedHardware -} // namespace OHOS -#endif // OHOS_DEVICE_MANAGER_MESSAGE_PROCESSING_H diff --git a/ext/mini/services/devicemanagerservice/include/dispatch/message_req.h b/ext/mini/services/devicemanagerservice/include/dispatch/message_req.h deleted file mode 100644 index be57754bbd8e732439e8e5d0b23d15b61e157ecb..0000000000000000000000000000000000000000 --- a/ext/mini/services/devicemanagerservice/include/dispatch/message_req.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2022 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(std::string &pkgName) - { - pkgName_ = pkgName; - } -private: - std::string pkgName_; -}; -} // namespace DistributedHardware -} // namespace OHOS -#endif // OHOS_DEVICE_MANAGER_MESSAGE_REQ_H diff --git a/ext/mini/services/devicemanagerservice/include/dispatch/message_rsp.h b/ext/mini/services/devicemanagerservice/include/dispatch/message_rsp.h deleted file mode 100644 index 7132014e4efa6efee072a392a5614b8654112adb..0000000000000000000000000000000000000000 --- a/ext/mini/services/devicemanagerservice/include/dispatch/message_rsp.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2022 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/ext/mini/services/devicemanagerservice/include/dispatch/server_init.h b/ext/mini/services/devicemanagerservice/include/dispatch/server_init.h deleted file mode 100644 index 7d499e6ed488beb370704a4b3c6694366dbfdef8..0000000000000000000000000000000000000000 --- a/ext/mini/services/devicemanagerservice/include/dispatch/server_init.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright (c) 2022 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_INIT_H -#define OHOS_DEVICE_MANAGER_SERVER_INIT_H - - -void Server_Init(); - -#endif // OHOS_DEVICE_MANAGER_SERVER_INIT_H diff --git a/ext/mini/services/devicemanagerservice/include/dispatch/server_stub.h b/ext/mini/services/devicemanagerservice/include/dispatch/server_stub.h deleted file mode 100644 index 8861cc9f80e40e5873ead15ed03d898060bb7298..0000000000000000000000000000000000000000 --- a/ext/mini/services/devicemanagerservice/include/dispatch/server_stub.h +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright (c) 2022 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/ext/mini/services/devicemanagerservice/include/dispatch/set_useroperation_req.h b/ext/mini/services/devicemanagerservice/include/dispatch/set_useroperation_req.h deleted file mode 100644 index 1a975e99e0dfa3df52bc51d745a7857ca9b32533..0000000000000000000000000000000000000000 --- a/ext/mini/services/devicemanagerservice/include/dispatch/set_useroperation_req.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) 2022 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/ext/mini/services/devicemanagerservice/include/dispatch/start_discovery_req.h b/ext/mini/services/devicemanagerservice/include/dispatch/start_discovery_req.h deleted file mode 100644 index 6c5fe1897aed18d11fc8741987730c4dc0f1afb7..0000000000000000000000000000000000000000 --- a/ext/mini/services/devicemanagerservice/include/dispatch/start_discovery_req.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2022 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(DmSubscribeInfo &subscribeInfo) - { - subscribeInfo_ = subscribeInfo; - } -private: - DmSubscribeInfo subscribeInfo_; -}; -} // namespace DistributedHardware -} // namespace OHOS -#endif // OHOS_DEVICE_MANAGER_START_DISCOVERY_REQ_H diff --git a/ext/mini/services/devicemanagerservice/include/dispatch/stop_discovery_req.h b/ext/mini/services/devicemanagerservice/include/dispatch/stop_discovery_req.h deleted file mode 100644 index fd82a703c2193d1fdcbbe91c2a9cf442260d5a0c..0000000000000000000000000000000000000000 --- a/ext/mini/services/devicemanagerservice/include/dispatch/stop_discovery_req.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2022 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/ext/mini/services/devicemanagerservice/include/message/msg_codec.h b/ext/mini/services/devicemanagerservice/include/message/msg_codec.h deleted file mode 100644 index f0b6fd53bd432f5dea297e04e4d6401ee7f752ab..0000000000000000000000000000000000000000 --- a/ext/mini/services/devicemanagerservice/include/message/msg_codec.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2022 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_MSG_CODEC_H -#define OHOS_MSG_CODEC_H - -#include -#include - -#include "nlohmann/json.hpp" - -#include "msg_request_auth.h" -#include "msg_sync_group.h" -#include "msg_response_auth.h" - -namespace OHOS { -namespace DistributedHardware { -class MsgCodec { -public: - static int32_t DecodeMsgType(std::string &jsonStr); - static std::string EncodeSyncGroup(std::vector &groupIdList, std::string &deviceId); - static std::vector EncodeReqAppAuth(std::string &token, std::string hostPkg, std::string targetPkg, - const DmDeviceInfo &devReqInfo, const DmAppImageInfo &imageInfo, std::string &extras); - static std::string EncodeAcceptRespAuth(int32_t reply, int64_t requestId, std::string &groupId, - std::string &groupName, std::string &reqDeviceId); - static std::string EncodeRefuseRespAuth(int32_t reply, std::string &reqDeviceId); - static std::shared_ptr DecodeRequestAuth(std::string &jsonStr, - std::shared_ptr msgRequestAuth); - static std::shared_ptr DecodeResponseAuth(std::string &jsonStr); - static std::shared_ptr DecodeSyncGroup(std::string &jsonStr); -}; -} -} -#endif diff --git a/ext/mini/services/devicemanagerservice/include/message/msg_head.h b/ext/mini/services/devicemanagerservice/include/message/msg_head.h deleted file mode 100644 index 3a15f48cbc5870e7b5ad19926c3ce0542c1b3f9d..0000000000000000000000000000000000000000 --- a/ext/mini/services/devicemanagerservice/include/message/msg_head.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (c) 2022 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_MSG_HEAD_H -#define OHOS_MSG_HEAD_H - -#include "nlohmann/json.hpp" - -namespace OHOS { -namespace DistributedHardware { -enum DmMsgType : int32_t { - MSG_TYPE_UNKNOWN = 0, - MSG_TYPE_REQ_AUTH = 100, - MSG_TYPE_INVITE_AUTH_INFO = 102, - MSG_TYPE_RESP_AUTH = 200, - MSG_TYPE_JOIN_AUTH_INFO = 201, - MSG_TYPE_CHANNEL_CLOSED = 300, - MSG_TYPE_SYNC_GROUP = 400, - MSG_TYPE_AUTH_BY_PIN = 500, -}; - -class MsgHead { -public: - MsgHead(): mMsgType_(0), mItfVer_("") {}; - MsgHead(int32_t msg): mMsgType_(msg), mItfVer_("") {}; - ~MsgHead() = default; - void Encode(nlohmann::json &json); - static std::shared_ptr Decode(nlohmann::json &json); - int32_t GetMsgType(); -private: - int32_t mMsgType_; - std::string mItfVer_; -}; -} -} -#endif \ No newline at end of file diff --git a/ext/mini/services/devicemanagerservice/include/message/msg_request_auth.h b/ext/mini/services/devicemanagerservice/include/message/msg_request_auth.h deleted file mode 100644 index df322301312a482fc1a224d9c4ab4e59a95a9fc9..0000000000000000000000000000000000000000 --- a/ext/mini/services/devicemanagerservice/include/message/msg_request_auth.h +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright (c) 2022 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_MSG_REQUEST_AUTH_H -#define OHOS_MSG_REQUEST_AUTH_H - -#include -#include - -#include "nlohmann/json.hpp" - -#include "msg_head.h" -#include "dm_app_image_info.h" -#include "dm_device_info.h" -#include "constants.h" - -namespace OHOS { -namespace DistributedHardware { -class MsgRequestAuth { -public: - MsgRequestAuth() = default; - ~MsgRequestAuth() = default; - MsgRequestAuth(std::string &token, std::string hostPkgName, std::string targetPkgName, - const DmDeviceInfo &devReqInfo, const DmAppImageInfo &imageInfo, std::string &extras) : MsgRequestAuth( - token, hostPkgName, targetPkgName, GROUP_VISIBILITY_IS_PRIVATE, devReqInfo, imageInfo, extras) {}; - MsgRequestAuth(std::string &token, std::string hostPkgName, std::string targetPkgName, - const int32_t groupVisibility, const DmDeviceInfo &devReqInfo, const DmAppImageInfo &imageInfo, - std::string &extras); - std::vector Encode(); - static std::shared_ptr Decode(nlohmann::json &json, std::shared_ptr msgIn); - static void SetThumbnailSize(nlohmann::json &json, std::shared_ptr msg); - int32_t GetMsgSlice(); - int32_t GetMsgCnt(); - std::string GetRequestDeviceId(); -public: - std::shared_ptr mHead_ {nullptr}; - std::string mHostPkg_; - std::string mTargetPkg_; - std::string mDeviceName_; - std::string mToken_; - std::string mDeviceId_; - std::string mDeviceType_; - std::string mAppName_; - std::string mAppDescription_; - int32_t mAuthType_ {AUTH_TYPE_PIN}; - int32_t mGroupVisibility_ {GROUP_VISIBILITY_IS_PRIVATE}; - int32_t mMsgSlice_ {0}; - int32_t mMsgCnt_ {0}; - int32_t mThumbnailSize_ {0}; - int32_t mAppIconSize_ {0}; - DmAppImageInfo mImageInfo_; -private: - std::string ToHexString(int32_t value); - std::string EncodeDevInfo(); - static void DecodeDeviceInfo(nlohmann::json &json, std::shared_ptr msg); - int32_t GetEncodedAppInfo(const uint8_t *dataSrc, int32_t srcLen, std::string &outString); - void GetDecodeAppInfo(const std::string appString, uint8_t **outBuffer, int32_t &outBufferLen); - static bool IsMsgValid(std::shared_ptr msgIn, nlohmann::json &json, std::string &deviceId, - int32_t index); - static bool IsAppInfoValid(nlohmann::json &json); - static void SetAuthType(nlohmann::json &json, std::shared_ptr msg); -}; -} -} - - -#endif diff --git a/ext/mini/services/devicemanagerservice/include/message/msg_response_auth.h b/ext/mini/services/devicemanagerservice/include/message/msg_response_auth.h deleted file mode 100644 index 483b814f46887b9d83c591536c85b6a596a10d4e..0000000000000000000000000000000000000000 --- a/ext/mini/services/devicemanagerservice/include/message/msg_response_auth.h +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (c) 2022 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_MSG_RESPONSE_AUTH_H -#define OHOS_MSG_RESPONSE_AUTH_H - -#include -#include - -#include "constants.h" -#include "nlohmann/json.hpp" - -#include "msg_head.h" - -namespace OHOS { -namespace DistributedHardware { -class MsgResponseAuth { -public: - MsgResponseAuth() = default; - MsgResponseAuth(int32_t reply, std::string &reqDeviceId); - MsgResponseAuth(int32_t reply, int64_t requestId, std::string &groupId, std::string &groupName, - std::string &reqDeviceId); - ~MsgResponseAuth() = default; - void Encode(nlohmann::json &jsonObj); - int32_t Decode(nlohmann::json &jsonObj); - int32_t GetReply(); - std::string GetNetId(); - std::string GetGroupId(); - std::string GetDeviceId(); - std::string GetGroupName(); - int32_t GetPinCode(); - void SavePinCode(int32_t pinCode); - int64_t GetRequestId(); - std::vector GetSyncGroupList(); -private: - std::shared_ptr mHead_ {nullptr}; - int32_t mReply_ {SESSION_REPLY_UNKNOWN}; - std::string mNetId_; - std::string mGroupId_; - std::string mGroupName_; - std::string mDeviceId_; - int32_t mPinCode_ {-1}; - int64_t mRequestId_ {-1}; - std::vector mSyncGroupList_; -}; -} -} -#endif diff --git a/ext/mini/services/devicemanagerservice/include/message/msg_sync_group.h b/ext/mini/services/devicemanagerservice/include/message/msg_sync_group.h deleted file mode 100644 index a5467df7539514587600d258660516aea454a1d9..0000000000000000000000000000000000000000 --- a/ext/mini/services/devicemanagerservice/include/message/msg_sync_group.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (c) 2022 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_MSG_SYNC_GROUP_H -#define OHOS_MSG_SYNC_GROUP_H - -#include -#include - -#include "nlohmann/json.hpp" - -#include "msg_head.h" - -namespace OHOS { -namespace DistributedHardware { -class MsgSyncGroup { -public: - MsgSyncGroup() {}; - MsgSyncGroup(std::vector &groupList, std::string &deviceId); - ~MsgSyncGroup() = default; - void Encode(nlohmann::json &json); - int32_t Decode(nlohmann::json &json); - std::string GetDeviceId(); - std::vector GetGroupIdList(); - -private: - std::shared_ptr mHead_; - std::string mDeviceId_; - std::vector mGroupIdList_; -}; -} -} -#endif \ No newline at end of file diff --git a/ext/mini/services/devicemanagerservice/include/requestauth/auth_manager.h b/ext/mini/services/devicemanagerservice/include/requestauth/auth_manager.h deleted file mode 100644 index c942490dd4721a491c1c3dc400ce86768c1b2942..0000000000000000000000000000000000000000 --- a/ext/mini/services/devicemanagerservice/include/requestauth/auth_manager.h +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright (c) 2022 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_AUTH_MANAGER_H -#define OHOS_AUTH_MANAGER_H - -#include -#include -#include - -#include "nlohmann/json.hpp" - -#include "single_instance.h" -#include "dm_device_info.h" -#include "dm_app_image_info.h" -#include "request_session.h" -#include "response_session.h" - -namespace OHOS { -namespace DistributedHardware { -class AuthManager { - DECLARE_SINGLE_INSTANCE(AuthManager); -public: - void AuthDeviceGroup(std::string &hostPkgName, const DmDeviceInfo &devReqInfo, const DmAppImageInfo &imageInfo, - std::string &extras); - void OnReceiveMsg(long long channelId, std::string &message); - int32_t CheckAuthentication(std::string &authPara); - int32_t GetAuthenticationParam(DmAuthParam &authParam); - void OnUserOperate(int32_t action); - int32_t GetPincode(int64_t requestId); - std::string GetAuthPara(); - int32_t GetDisplayOwner(); - void NotifyHostOnCheckAuthResult(int64_t requestId, int errorCode); - -private: - void SyncDmPrivateGroup(std::string &message); - void AuthAppGroup(std::string &hostPkgName, const DmDeviceInfo &devReqInfo, const DmAppImageInfo &imageInfo, - std::string &extrasJson); - void OnReceiveMessage(long long channelId, std::string &message, int32_t msgType); - bool CanStartNewSession(); - void MoveSessionToWaitScanMap(); - int32_t CheckAuthenticationByPin(nlohmann::json &authJson); - void OnPinInputResult(int32_t pinCode, int32_t pinToken); - -private: - std::string authParam_ = ""; - int32_t displayOwner_ = 0; - std::shared_ptr mPendingReqSessionPtr_ {nullptr}; - std::shared_ptr mPendingRespSessionPtr {}; - std::map> mWaitScanReqSessionMap_ = {}; -}; -} -} -#endif diff --git a/ext/mini/services/devicemanagerservice/include/requestauth/request_session.h b/ext/mini/services/devicemanagerservice/include/requestauth/request_session.h deleted file mode 100644 index cf77af3f36dc3aa5e02f3267ceda4a15f1c69326..0000000000000000000000000000000000000000 --- a/ext/mini/services/devicemanagerservice/include/requestauth/request_session.h +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright (c) 2022 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_REQUEST_SESSION_H -#define OHOS_REQUEST_SESSION_H - -#include -#include - -#include "single_instance.h" -#include "dm_app_image_info.h" -#include "dm_device_info.h" -#include "msg_response_auth.h" - -namespace OHOS { -namespace DistributedHardware { -class RequestSession { -public: - RequestSession(std::string &hostPkgName, std::string &targetPkgName, const DmDeviceInfo &devReqInfo, - const DmAppImageInfo &imageInfo); - ~RequestSession() = default; - std::vector GetRequestCommand(std::string &extrasJson); - int32_t GetPinToken(); - void SetChannelId(long long channelId); - void Release(); - bool IsFinished(); - bool IsMyChannelId(long long channelId); - void OnReceiveMsg(std::string &msg); - bool IsWaitingForScan(); - std::string GetToken(); - bool IsMyPinToken(int32_t pinToken); - void OnReceivePinCode(int32_t pinCode); - void NotifyHostAppAuthResult(int32_t errorCode); - void OnUserOperate(int32_t action); - int64_t GetRequestId(); - std::string GetRequestDeviceId(); - -private: - int32_t StartFaService(); - std::string GetHostPkgName(); - std::string GetTargetPkgName(); - int32_t GetSessionType(); - void CloseChannel(); - int32_t ParseRespMsg(std::string &msg); - void SyncDmPrivateGroup(std::vector &remoteGroupList); - -private: - enum StatusType : int32_t { - STATUS_INIT = 0, - STATUS_WAITING_REPLY = 2, - STATUS_WATING_SCAN_OR_INPUT = 3, - STATUS_WAITING_ADD_GROUP = 4, - STATUS_FINISH = 6, - }; - int32_t mSessionType_ {SESSION_TYPE_IS_APP_AUTH}; - int32_t mStatus_ {StatusType::STATUS_INIT}; - std::string mHostPkgName_; - std::string mTargetPkgName; - std::string mToken_; - int32_t mPinToken_ {MIN_PIN_TOKEN}; - DmDeviceInfo mDevInfo_; - DmAppImageInfo mImageInfo_; - long long mChannelId_ {-1}; - bool mIsChannelOpened_ {false}; - std::string mRemoteDeviceId_; - std::string mRemoteNetId_; - std::string mRemoteGroupId_; - std::string mRemoteGroupName_; - int64_t mRequestId_ {-1}; - std::shared_ptr responseMsgPtr_; -}; -} -} -#endif diff --git a/ext/mini/services/devicemanagerservice/include/requestauth/response_session.h b/ext/mini/services/devicemanagerservice/include/requestauth/response_session.h deleted file mode 100644 index 39c3fc2acee8aab9b42efce5e02c3bb58686f83b..0000000000000000000000000000000000000000 --- a/ext/mini/services/devicemanagerservice/include/requestauth/response_session.h +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright (c) 2022 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_RESPONSE_SESSION_H -#define OHOS_RESPONSE_SESSION_H - -#include -#include -#include -#include - -#include "single_instance.h" -#include "dm_device_info.h" -#include "msg_response_auth.h" -#include "msg_request_auth.h" -#include "hichain_connector.h" -#include "dm_timer.h" - -namespace OHOS { -namespace DistributedHardware { -enum ResponseSessionStatus : int32_t { - SESSION_INIT = 0, - SESSION_WAITTING_USER_CONFIRM = 1, - SESSION_WAITTING_GROUP_CREATED = 2, - SESSION_WAITTING_PIN_CODE = 3 -}; - -class ResponseSession : public HichainConnectorCallback, public std::enable_shared_from_this { -public: - ResponseSession(); - virtual ~ResponseSession() {}; - int32_t SendResponseMessage(int32_t reply); - void OnUserOperate(int32_t action); - void OnGroupCreated(int64_t requestId, const std::string &groupId) override; - void OnMemberJoin(int64_t requestId, int32_t status) override; - void BuildAuthenticationInfo(DmAuthParam &authParam); - void OnReceiveMsg(long long channelId, std::string &message); - int64_t GetRequestId(); - int32_t GetPinCodeByReqId(int64_t requestId); - bool IsMyChannelId(long long channelId); - void Release(); - void CancelDisplay(); - int32_t GetStatus(); - -private: - int32_t DecodeReqMsg(std::string &message); - int32_t StartFaService(); - std::string GenerateGroupName(); - void OnUserConfirm(); - void OnUserReject(int32_t errorCode); - int32_t GeneratePincode(); - -private: - int64_t mRequestId_; - std::string mGroupId_; - std::string mGroupName_; - std::string mReqDeviceId_; - sem_t mSem_; - std::shared_ptr mMsgRequestAuthPtr_; - int64_t mChannelId_; - int32_t mPincode_; - int32_t mSessionStatus_; - std::shared_ptr mReceiveTimerPtr_; - std::shared_ptr mMemberJoinTimerPtr_; -}; -} // namespace DistributedHardware -} // namespace OHOS - - -#endif diff --git a/ext/mini/services/devicemanagerservice/include/softbus/softbus_adapter.h b/ext/mini/services/devicemanagerservice/include/softbus/softbus_adapter.h deleted file mode 100644 index 2bc47872ead9050a589454f4ac3ba4ead5c59506..0000000000000000000000000000000000000000 --- a/ext/mini/services/devicemanagerservice/include/softbus/softbus_adapter.h +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright (c) 2022 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_SOFTBUS_ADAPTER_H -#define OHOS_DEVICE_MANAGER_SOFTBUS_ADAPTER_H - -#include -#include -#include -#include -#include -#include -#include "softbus_bus_center.h" -#include "discovery_service.h" -#include "dm_device_info.h" -#include "dm_subscribe_info.h" - -namespace OHOS { -namespace DistributedHardware { -class PublishServiceCallBack { -public: - static void OnPublishSuccess(int publishId); - static void OnPublishFail(int publishId, PublishFailReason reason); -}; - -class SoftbusAdapter { -public: - static int32_t Init(); - static int32_t GetTrustDevices(const std::string &pkgName, NodeBasicInfo **info, int32_t *infoNum); - static int32_t StartDiscovery(std::string &pkgName, SubscribeInfo *info); - static int32_t StopDiscovery(std::string &pkgName, uint16_t subscribeId); - static bool IsDeviceOnLine(std::string &deviceId); - static int32_t GetConnectionIpAddr(std::string deviceId, std::string &ipAddr); - static ConnectionAddr *GetConnectAddr(std::string deviceId); -public: - static void OnDeviceStateChange(DmDeviceState state, DmDeviceInfo &deviceInfo); - 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 OnSoftbusDiscoverFailed(int subscribeId, DiscoveryFailReason failReason); - static void OnSoftbusDiscoverySuccess(int subscribeId); -private: - static bool GetsubscribeIdAdapter(std::string &pkgName, int16_t originId, int32_t &adapterId); - static bool GetpkgNameBySubscribeId(int32_t adapterId, std::string &pkgName); - static void SaveDiscoverDeviceInfo(const DeviceInfo *deviceInfo); - static void RemoveDiscoverDeviceInfo(const std::string deviceId); - static void NodeBasicInfoCopyToDmDevice(DmDeviceInfo &dmDeviceInfo, NodeBasicInfo &nodeBasicInfo); - static void DeviceInfoCopyToDmDevice(DmDeviceInfo &dmDeviceInfo, const DeviceInfo &deviceInfo); - static ConnectionAddr *GetConnectAddrByType(DeviceInfo *deviceInfo, ConnectionAddrType type); -private: - struct SubscribeInfoAdapter { - SubscribeInfo info; - uint16_t subscribeIdOrigin; - uint16_t subscribeIdPrefix; - }; - static std::map>> subscribeInfos_; - static std::map> discoverDeviceInfoMap_; - static std::vector> discoverDeviceInfoVector_; - static uint16_t subscribeIdPrefix; - // static std::mutex lock_; - static INodeStateCb softbusNodeStateCb_; - static IDiscoveryCallback softbusDiscoverCallback_; - static IPublishCallback servicePublishCallback_; -}; -} // namespace DistributedHardware -} // namespace OHOS -#endif // OHOS_DEVICE_MANAGER_SOFTBUS_ADAPTER_H diff --git a/ext/mini/services/devicemanagerservice/include/softbus/softbus_session.h b/ext/mini/services/devicemanagerservice/include/softbus/softbus_session.h deleted file mode 100644 index 25fecc188027eb9ff2aff146c3ad0058218c1c6f..0000000000000000000000000000000000000000 --- a/ext/mini/services/devicemanagerservice/include/softbus/softbus_session.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (c) 2022 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_SOFTBUS_SESSION_H -#define OHOS_DEVICE_MANAGER_SOFTBUS_SESSION_H - -#include -#include -#include - -#include "session.h" -#include "single_instance.h" -#include "softbus_common.h" - -namespace OHOS { -namespace DistributedHardware { -class SoftbusSession { -DECLARE_SINGLE_INSTANCE_BASE(SoftbusSession); -public: - int32_t Start(); - int OnSessionOpened(int sessionId, int result); - void OnSessionClosed(int sessionId); - void OnBytesReceived(int sessionId, const void *data, int dataLen); - void CloseSession(int32_t sessionId); - int32_t SendMessages(const char *deviceId, std::vector &messages); - int32_t SendMsg(int32_t sessionId, std::string &message); - void GetPeerDeviceId(int32_t sessionId, std::string &peerDevId); -private: - SoftbusSession() = default; - ~SoftbusSession(); -private: - int32_t SendData(int32_t sessionId, const void *data, int32_t len); -private: - const char *PKG_NAME = "ohos.distributedhardware.devicemanager"; - const char *SESSION_NAME = "ohos.distributedhardware.devicemanager.resident"; - std::set sessionIdSet_; - std::vector messages_ {}; -}; -} // namespace DistributedHardware -} // namespace OHOS -#endif // OHOS_DEVICE_MANAGER_SOFTBUS_SESSION_H diff --git a/ext/mini/services/devicemanagerservice/include/timer/dm_timer.h b/ext/mini/services/devicemanagerservice/include/timer/dm_timer.h deleted file mode 100644 index e62b03e194e15f8caed40d30b9c24d11a1bdc440..0000000000000000000000000000000000000000 --- a/ext/mini/services/devicemanagerservice/include/timer/dm_timer.h +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright (c) 2022 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 TIMER_H -#define TIMER_H -#include -#include -#include -#include -#include -#include - -#include "device_manager_log.h" - - -namespace OHOS { -namespace DistributedHardware { -typedef void (*TimeoutHandle)(void *data); - -#define MAXEVENTS 255 - -enum DmTimerStatus : int32_t { - DM_STATUS_INIT = 0, - DM_STATUS_RUNNING = 1, - DM_STATUS_BUSY = 2, - DM_STATUS_CREATE_ERROR = 3, - DM_STATUS_FINISH = 6, -}; - -class DmTimer { -public: - DmTimer(std::string &name); - ~DmTimer(); - DmTimerStatus Start(uint32_t timeOut, TimeoutHandle handle, void *data); - void Stop(int32_t code); - void WiteforTimeout(); - -private: - int32_t CreateTimeFd(); - void Release(); - -private: - DmTimerStatus mStatus_; - uint32_t mTimeOutSec_; - TimeoutHandle mHandle_; - void *mHandleData_; - int32_t mTimeFd_[2]; - int32_t mEpFd_; - std::string mTimerName_; -}; -} -} -#endif - diff --git a/ext/mini/services/devicemanagerservice/src/ability/lite/dm_ability_manager.cpp b/ext/mini/services/devicemanagerservice/src/ability/lite/dm_ability_manager.cpp deleted file mode 100644 index 5c938f4332c8bac66a05d7229237141dbd499063..0000000000000000000000000000000000000000 --- a/ext/mini/services/devicemanagerservice/src/ability/lite/dm_ability_manager.cpp +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (c) 2022 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_ability_manager.h" - -#include "semaphore.h" - -#include "constants.h" -#include "device_manager_log.h" - -namespace OHOS { -namespace DistributedHardware { -IMPLEMENT_SINGLE_INSTANCE(DmAbilityManager); - -AbilityRole DmAbilityManager::GetAbilityRole() -{ - return mAbilityStatus_; -} - -AbilityStatus DmAbilityManager::StartAbility(AbilityRole role) -{ - // not support for L1 yet, do nothing. jsut save status and role - mAbilityStatus_ = role; - mStatus_ = AbilityStatus::ABILITY_STATUS_SUCCESS; - return mStatus_; -} - -void DmAbilityManager::WaitForTimeout(uint32_t timeout_s) -{ - struct timespec ts; - clock_gettime(CLOCK_REALTIME, &ts); - ts.tv_sec += (int32_t)timeout_s; - sem_timedwait(&mSem_, &ts); -} - -void DmAbilityManager::StartAbilityDone() -{ - mStatus_ = AbilityStatus::ABILITY_STATUS_SUCCESS; - sem_post(&mSem_); -} -} -} diff --git a/ext/mini/services/devicemanagerservice/src/ability/standard/dm_ability_manager.cpp b/ext/mini/services/devicemanagerservice/src/ability/standard/dm_ability_manager.cpp deleted file mode 100644 index b7e5ebbe53ba0334334496c80a12140a07e281a7..0000000000000000000000000000000000000000 --- a/ext/mini/services/devicemanagerservice/src/ability/standard/dm_ability_manager.cpp +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright (c) 2022 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_ability_manager.h" - -#include "auth_manager.h" -#include "ability_manager_client.h" -#include "ability_record.h" -#include "ability_manager_service.h" -#include "parameter.h" -#include "semaphore.h" - -#include "constants.h" -#include "device_manager_log.h" - -namespace OHOS { -namespace DistributedHardware { -namespace { -const int32_t ABILITY_START_TIMEOUT = 3; // 3 second -} -IMPLEMENT_SINGLE_INSTANCE(DmAbilityManager); - -AbilityRole DmAbilityManager::GetAbilityRole() -{ - return mAbilityStatus_; -} - -AbilityStatus DmAbilityManager::StartAbility(AbilityRole role) -{ - std::string roleStr; - if (role == AbilityRole::ABILITY_ROLE_INITIATIVE) { - roleStr = "initiative"; - } else if (role == AbilityRole::ABILITY_ROLE_PASSIVE) { - roleStr = "passive"; - } else { - DMLOG(DM_LOG_ERROR, "StartAbility, failed, role unknown"); - return AbilityStatus::ABILITY_STATUS_FAILED; - } - - DMLOG(DM_LOG_ERROR, "StartAbility, role %s", roleStr.c_str()); - mAbilityStatus_ = role; - - char localDeviceId[DEVICE_UUID_LENGTH] = {0}; - GetDevUdid(localDeviceId, DEVICE_UUID_LENGTH); - std::string deviceId = localDeviceId; - std::string bundleName = "com.ohos.devicemanagerui"; - std::string abilityName = "com.ohos.devicemanagerui.MainAbility"; - int32_t displayOwner = (role == AbilityRole::ABILITY_ROLE_INITIATIVE) ? - AuthManager::GetInstance().GetDisplayOwner() : DISPLAY_OWNER_SYSTEM; - - mStatus_ = AbilityStatus::ABILITY_STATUS_START; - AAFwk::Want want; - AppExecFwk::ElementName element(deviceId, bundleName, abilityName); - want.SetElement(element); - if (displayOwner == DISPLAY_OWNER_OTHER) { - return AbilityStatus::ABILITY_STATUS_SUCCESS; - } - AAFwk::AbilityManagerClient::GetInstance()->Connect(); - ErrCode result = AAFwk::AbilityManagerClient::GetInstance()->StartAbility(want); - if (result == OHOS::ERR_OK) { - DMLOG(DM_LOG_INFO, "Start Ability succeed"); - } else { - DMLOG(DM_LOG_INFO, "Start Ability failed"); - mStatus_ = AbilityStatus::ABILITY_STATUS_FAILED; - return mStatus_; - } - WaitForTimeout(ABILITY_START_TIMEOUT); - return mStatus_; -} - -void DmAbilityManager::WaitForTimeout(uint32_t timeout_s) -{ - struct timespec ts; - clock_gettime(CLOCK_REALTIME, &ts); - ts.tv_sec += (int32_t)timeout_s; - sem_timedwait(&mSem_, &ts); -} - -void DmAbilityManager::StartAbilityDone() -{ - mStatus_ = AbilityStatus::ABILITY_STATUS_SUCCESS; - sem_post(&mSem_); -} -} -} diff --git a/ext/mini/services/devicemanagerservice/src/auth/hichain_connector.cpp b/ext/mini/services/devicemanagerservice/src/auth/hichain_connector.cpp deleted file mode 100644 index 2829799d7bbcb1caa06e5ca0c0007b8c45cf2103..0000000000000000000000000000000000000000 --- a/ext/mini/services/devicemanagerservice/src/auth/hichain_connector.cpp +++ /dev/null @@ -1,527 +0,0 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "hichain_connector.h" - -#include -#include -#include -#include - -#include "nlohmann/json.hpp" - -#include "parameter.h" - -#include "anonymous_string.h" -#include "device_manager_log.h" -#include "encrypt_utils.h" -#include "softbus_adapter.h" -#include "constants.h" -#if (defined(__LINUX__) || defined(__LITEOS_A__)) -#include "ipc_server_listener_adapter.h" -#include "ipc_check_authenticate_req.h" -#include "ipc_server_stub.h" -#endif -#include "softbus_session.h" -#include "auth_manager.h" -#include "dm_ability_manager.h" -#include "multiple_user_connector.h" - -namespace OHOS { -namespace DistributedHardware { -namespace { -const std::string DEVICE_ID = "DEVICE_ID"; -const std::string WIFI_IP = "WIFI_IP"; -const std::string WIFI_PORT = "WIFI_PORT"; -const std::string BR_MAC = "BR_MAC"; -const std::string BLE_MAC = "BLE_MAC"; -const std::string ETH_IP = "ETH_IP"; -const std::string ETH_PORT = "ETH_PORT"; -const std::string DEVICE_MANAGER_APP = "ohos.distributedhardware.devicemanager"; -const std::string DEVICE_MANAGER_GROUPNAME = "DMPeerToPeerGroup"; - -const int64_t MIN_REQUEST_ID = 1000000000; -const int64_t MAX_REQUEST_ID = 9999999999; -const int32_t FIELD_EXPIRE_TIME_VALUE = 7; -} - -IMPLEMENT_SINGLE_INSTANCE(HichainConnector); - -void from_json(const nlohmann::json& jsonObject, GroupInfo& groupInfo) -{ - if (jsonObject.find(FIELD_GROUP_NAME) != jsonObject.end()) { - groupInfo.groupName = jsonObject.at(FIELD_GROUP_NAME).get(); - } - - if (jsonObject.find(FIELD_GROUP_ID) != jsonObject.end()) { - groupInfo.groupId = jsonObject.at(FIELD_GROUP_ID).get(); - } - - if (jsonObject.find(FIELD_GROUP_OWNER) != jsonObject.end()) { - groupInfo.groupOwner = jsonObject.at(FIELD_GROUP_OWNER).get(); - } - - if (jsonObject.find(FIELD_GROUP_TYPE) != jsonObject.end()) { - groupInfo.groupType = jsonObject.at(FIELD_GROUP_TYPE).get(); - } - - if (jsonObject.find(FIELD_GROUP_VISIBILITY) != jsonObject.end()) { - groupInfo.groupVisibility = jsonObject.at(FIELD_GROUP_VISIBILITY).get(); - } -} - -int HichainConnector::Init() -{ - DMLOG(DM_LOG_INFO, "HichainConnector::init, init device auth service."); - InitDeviceAuthService(); - - deviceGroupManager_ = GetGmInstance(); - if (deviceGroupManager_ == nullptr) { - DMLOG(DM_LOG_INFO, "HichainConnector::init, failed to init group manager!"); - return -1; - } - - deviceAuthCallback_.onTransmit = nullptr; - deviceAuthCallback_.onFinish = HichainAuthenCallBack::onFinish; - deviceAuthCallback_.onError = HichainAuthenCallBack::onError; - deviceAuthCallback_.onRequest = HichainAuthenCallBack::onRequest; - - deviceGroupManager_->regCallback(DEVICE_MANAGER_APP.c_str(), &deviceAuthCallback_); - DMLOG(DM_LOG_INFO, "HichainConnector::init, init hichain adapter success."); - return 0; -} - -int64_t HichainConnector::GenRequestId() -{ - return EncryptUtils::GenRandLongLong(MIN_REQUEST_ID, MAX_REQUEST_ID); -} - -int32_t HichainConnector::CreateGroup(int64_t requestId, const std::string &groupName) -{ - int32_t ret; - if (deviceGroupManager_ == nullptr) { - DMLOG(DM_LOG_ERROR, "HichainConnector::CreateGroup group manager is null, requestId %lld.", requestId); - return FAIL; - } - - GroupInfo groupInfo; - if (IsGroupCreated(groupName, groupInfo)) { - DeleteGroup(groupInfo.groupId); - } - - DMLOG(DM_LOG_INFO, "HichainConnector::CreateGroup requestId %lld", requestId); - char localDeviceId[DEVICE_UUID_LENGTH] = {0}; - GetDevUdid(localDeviceId, DEVICE_UUID_LENGTH); - std::string sLocalDeviceID = localDeviceId; - - nlohmann::json jsonObj; - jsonObj[FIELD_GROUP_TYPE] = GROUP_TYPE_PEER_TO_PEER_GROUP; - jsonObj[FIELD_DEVICE_ID] = sLocalDeviceID; - jsonObj[FIELD_GROUP_NAME] = groupName; - jsonObj[FIELD_USER_TYPE] = 0; - jsonObj[FIELD_GROUP_VISIBILITY] = GROUP_VISIBILITY_PUBLIC; - jsonObj[FIELD_EXPIRE_TIME] = FIELD_EXPIRE_TIME_VALUE; - int32_t userId = MultipleUserConnector::GetCurrentAccountUserID(); - if (userId < 0) { - DMLOG(DM_LOG_ERROR, "get current process account user id failed, userId: %ld", userId); - return FAIL; - } - - ret = deviceGroupManager_->createGroup(userId, requestId, DEVICE_MANAGER_APP.c_str(), jsonObj.dump().c_str()); - if (ret != 0) { - DMLOG(DM_LOG_ERROR, "Failed to start CreateGroup task, ret: %d, requestId %lld.", ret, requestId); - return ret; - } - - return SUCCESS; -} - -int32_t HichainConnector::IsGroupCreated(std::string groupName, GroupInfo &groupInfo) -{ - nlohmann::json jsonObj; - jsonObj[FIELD_GROUP_NAME] = groupName.c_str(); - std::string queryParams = jsonObj.dump(); - - std::vector groupList; - if (GetGroupInfo(queryParams, groupList)) { - groupInfo = groupList[0]; - return true; - } - - return false; -} - -int32_t HichainConnector::GetGroupInfo(std::string queryParams, std::vector &groupList) -{ - int32_t ret; - char *groupVec = nullptr; - uint32_t num = 0; - int32_t userId = MultipleUserConnector::GetCurrentAccountUserID(); - if (userId < 0) { - DMLOG(DM_LOG_ERROR, "get current process account user id failed, userId: %ld", userId); - return false; - } - - ret = deviceGroupManager_->getGroupInfo(userId, DEVICE_MANAGER_APP.c_str(), queryParams.c_str(), &groupVec, &num); - if (ret != 0) { - DMLOG(DM_LOG_ERROR, "HichainConnector::GetGroupInfo failed , ret: %d.", ret); - return false; - } - - if (groupVec == nullptr) { - DMLOG(DM_LOG_ERROR, "HichainConnector::GetGroupInfo failed , returnGroups is nullptr"); - return false; - } - - if (num == 0) { - DMLOG(DM_LOG_ERROR, "HichainConnector::GetGroupInfo group failed, groupNum is 0."); - return false; - } - - DMLOG(DM_LOG_INFO, "HichainConnector::GetGroupInfo group(%s), groupNum(%d)", groupVec, num); - std::string relatedGroups = std::string(groupVec); - deviceGroupManager_->destroyInfo(&groupVec); - nlohmann::json jsonObject = nlohmann::json::parse(relatedGroups); - if (jsonObject.is_discarded()) { - DMLOG(DM_LOG_ERROR, "returnGroups parse error"); - return false; - } - - std::vector groupInfos = jsonObject.get>(); - if (groupInfos.size() == 0) { - DMLOG(DM_LOG_ERROR, "HichainConnector::GetGroupInfo group failed, groupInfos is empty."); - return false; - } - - groupList = groupInfos; - return true; -} - -void HichainConnector::RegisterConnectorCallback(std::shared_ptr callback) -{ - hichainConnectorCallback_ = callback; -} - -void HichainConnector::OnGroupCreated(int64_t requestId, const std::string &returnData) -{ - if (hichainConnectorCallback_ == nullptr) { - DMLOG(DM_LOG_ERROR, "HichainConnector::OnGroupCreated hichainConnectorCallback_ not register."); - return; - } - - nlohmann::json jsonObject = nlohmann::json::parse(returnData); - if (jsonObject.is_discarded()) { - DMLOG(DM_LOG_ERROR, "HichainConnector::OnGroupCreated returnData not json."); - hichainConnectorCallback_->OnGroupCreated(requestId, ""); - return; - } - - if (jsonObject.find(FIELD_GROUP_ID) == jsonObject.end()) { - DMLOG(DM_LOG_ERROR, "HichainConnector::OnGroupCreated failed to get groupId."); - hichainConnectorCallback_->OnGroupCreated(requestId, ""); - return; - } - - std::string groupId = jsonObject.at(FIELD_GROUP_ID).get(); - DMLOG(DM_LOG_INFO, "group create success, groupId:%s.", GetAnonyString(groupId).c_str()); - hichainConnectorCallback_->OnGroupCreated(requestId, groupId); -} - -void HichainConnector::OnMemberJoin(int64_t requestId, int32_t status) -{ - AbilityRole role = DmAbilityManager::GetInstance().GetAbilityRole(); - DMLOG(DM_LOG_INFO, "HichainConnector::OnMemberJoin:: role = %d", (int32_t)role); - - if (role == AbilityRole::ABILITY_ROLE_INITIATIVE) { - AuthManager::GetInstance().NotifyHostOnCheckAuthResult(requestId, status); - return; - } - - if (hichainConnectorCallback_ == nullptr) { - DMLOG(DM_LOG_ERROR, "HichainConnector::OnMemberJoin hichainConnectorCallback_ not register."); - return; - } - hichainConnectorCallback_->OnMemberJoin(requestId, status); -} - -int32_t HichainConnector::AddMemeber(std::string deviceId, std::shared_ptr msgResponseAuth) -{ - DMLOG(DM_LOG_INFO, "HichainConnector::AddMemeber"); - if (deviceGroupManager_ == nullptr) { - DMLOG(DM_LOG_INFO, "HichainConnector::AddMemeber group manager is null."); - return -1; - } - - char localDeviceId[DEVICE_UUID_LENGTH] = {0}; - GetDevUdid(localDeviceId, DEVICE_UUID_LENGTH); - std::string connectInfo = GetConnectPara(deviceId, msgResponseAuth); - - nlohmann::json jsonObj; - jsonObj[FIELD_GROUP_ID] = msgResponseAuth->GetGroupId(); - jsonObj[FIELD_GROUP_TYPE] = GROUP_TYPE_PEER_TO_PEER_GROUP; - jsonObj[FIELD_PIN_CODE] = std::to_string(msgResponseAuth->GetPinCode()).c_str(); - jsonObj[FIELD_IS_ADMIN] = false; - jsonObj[FIELD_DEVICE_ID] = localDeviceId; - jsonObj[FIELD_GROUP_NAME] = msgResponseAuth->GetGroupName(); - jsonObj[FIELD_CONNECT_PARAMS] = connectInfo.c_str(); - std::string tmpStr = jsonObj.dump(); - int32_t userId = MultipleUserConnector::GetCurrentAccountUserID(); - if (userId < 0) { - DMLOG(DM_LOG_ERROR, "get current process account user id failed, userId: %ld", userId); - return -1; - } - DMLOG(DM_LOG_INFO, "HichainConnector::AddMemeber completed"); - return deviceGroupManager_->addMemberToGroup(userId, msgResponseAuth->GetRequestId(), DEVICE_MANAGER_APP.c_str(), - tmpStr.c_str()); -} - -std::string HichainConnector::GetConnectPara(std::string deviceId, std::shared_ptr msgResponseAuth) -{ - ConnectionAddr *addrInfo = SoftbusAdapter::GetConnectAddr(deviceId); - if (addrInfo == nullptr) { - DMLOG(DM_LOG_ERROR, "HichainConnector::GetConnectPara addrInfo error"); - return ""; - } - - DMLOG(DM_LOG_ERROR, "HichainConnector::GetConnectPara get addrInfo"); - nlohmann::json jsonPara; - jsonPara[DEVICE_ID] = msgResponseAuth->GetDeviceId(); - if (addrInfo->type == ConnectionAddrType::CONNECTION_ADDR_ETH) { - DMLOG(DM_LOG_INFO, "HichainConnector::AddMemeber addr type is ETH"); - jsonPara[ETH_IP] = addrInfo->info.ip.ip; - jsonPara[ETH_PORT] = addrInfo->info.ip.port; - } else if (addrInfo->type == ConnectionAddrType::CONNECTION_ADDR_WLAN) { - DMLOG(DM_LOG_INFO, "HichainConnector::AddMemeber addr type is WIFI"); - jsonPara[WIFI_IP] = addrInfo->info.ip.ip; - jsonPara[WIFI_PORT] = addrInfo->info.ip.port; - } else if (addrInfo->type == ConnectionAddrType::CONNECTION_ADDR_BR) { - DMLOG(DM_LOG_INFO, "HichainConnector::AddMemeber addr type is br"); - jsonPara[BR_MAC] = addrInfo->info.br.brMac; - } else if (addrInfo->type == ConnectionAddrType::CONNECTION_ADDR_BLE) { - DMLOG(DM_LOG_INFO, "HichainConnector::AddMemeber addr type is ble"); - jsonPara[BLE_MAC] = addrInfo->info.ble.bleMac; - } else { - DMLOG(DM_LOG_ERROR, "HichainConnector::AddMemeber addrInfo not right"); - return ""; - } - return jsonPara.dump(); -} - -void HichainConnector::GetRelatedGroups(std::string deviceId, std::vector &groupList) -{ - DMLOG(DM_LOG_INFO, "HichainConnector::GetRelatedGroups Start to get local related groups."); - uint32_t groupNum = 0; - char *returnGroups = nullptr; - int32_t userId = MultipleUserConnector::GetCurrentAccountUserID(); - if (userId < 0) { - DMLOG(DM_LOG_ERROR, "get current process account user id failed, userId: %ld", userId); - return; - } - - int32_t ret = deviceGroupManager_->getRelatedGroups(userId, DEVICE_MANAGER_APP.c_str(), deviceId.c_str(), - &returnGroups, &groupNum); - if (ret != 0) { - DMLOG(DM_LOG_ERROR, "HichainConnector::GetRelatedGroups failed , ret: %d.", ret); - return; - } - - if (returnGroups == nullptr) { - DMLOG(DM_LOG_ERROR, "HichainConnector::GetRelatedGroups failed , returnGroups is nullptr"); - return; - } - - if (groupNum == 0) { - DMLOG(DM_LOG_ERROR, "HichainConnector::GetRelatedGroups group failed, groupNum is 0."); - return; - } - - std::string relatedGroups = std::string(returnGroups); - nlohmann::json jsonObject = nlohmann::json::parse(relatedGroups); - if (jsonObject.is_discarded()) { - DMLOG(DM_LOG_ERROR, "returnGroups parse error"); - return; - } - - std::vector groupInfos = jsonObject.get>(); - if (groupInfos.size() == 0) { - DMLOG(DM_LOG_ERROR, "HichainConnector::GetRelatedGroups group failed, groupInfos is empty."); - return; - } - - groupList = groupInfos; - return; -} - -void HichainConnector::GetSyncGroupList(std::vector &groupList, std::vector &syncGroupList) -{ - if (groupList.empty()) { - DMLOG(DM_LOG_ERROR, "groupList is empty."); - return; - } - - for (auto group : groupList) { - if (IsGroupInfoInvalid(group)) { - continue; - } - syncGroupList.push_back(group.groupId); - } -} - -bool HichainConnector::IsGroupInfoInvalid(GroupInfo &group) -{ - if (group.groupType == GROUP_TYPE_IDENTICAL_ACCOUNT_GROUP || group.groupVisibility == GROUP_VISIBILITY_PUBLIC || - group.groupOwner != DEVICE_MANAGER_APP) { - return true; - } - return false; -} - -void HichainConnector::SyncGroups(std::string deviceId, std::vector &remoteGroupIdList) -{ - std::vector groupInfoList; - GetRelatedGroups(deviceId, groupInfoList); - for (auto &groupInfo : groupInfoList) { - if (IsGroupInfoInvalid(groupInfo)) { - continue; - } - - auto iter = std::find(remoteGroupIdList.begin(), remoteGroupIdList.end(), groupInfo.groupId); - if (iter == remoteGroupIdList.end()) { - (void)DelMemberFromGroup(groupInfo.groupId, deviceId); - } - } -} - -int32_t HichainConnector::DelMemberFromGroup(std::string groupId, std::string deviceId) -{ - int64_t requestId = GenRequestId(); - DMLOG(DM_LOG_INFO, "Start to delete memeber from group, requestId %lld, deviceId %s, groupId %s", - requestId, GetAnonyString(deviceId).c_str(), GetAnonyString(groupId).c_str()); - nlohmann::json jsonObj; - jsonObj[FIELD_GROUP_ID] = groupId; - jsonObj[FIELD_DELETE_ID] = deviceId; - std::string deleteParams = jsonObj.dump(); - int32_t userId = MultipleUserConnector::GetCurrentAccountUserID(); - if (userId < 0) { - DMLOG(DM_LOG_ERROR, "get current process account user id failed, userId: %ld", userId); - return userId; - } - - int32_t ret = deviceGroupManager_->deleteMemberFromGroup(userId, requestId, DEVICE_MANAGER_APP.c_str(), - deleteParams.c_str()); - if (ret != 0) { - DMLOG(DM_LOG_ERROR, "HichainConnector::DelMemberFromGroup failed , ret: %d.", ret); - return ret; - } - return 0; -} - -void HichainConnector::DeleteGroup(std::string &groupId) -{ - int32_t ret; - int64_t requestId = GenRequestId(); - nlohmann::json jsonObj; - jsonObj[FIELD_GROUP_ID] = groupId; - std::string disbandParams = jsonObj.dump(); - int32_t userId = MultipleUserConnector::GetCurrentAccountUserID(); - if (userId < 0) { - DMLOG(DM_LOG_ERROR, "get current process account user id failed, userId: %ld", userId); - return; - } - - ret = deviceGroupManager_->deleteGroup(userId, requestId, DEVICE_MANAGER_APP.c_str(), disbandParams.c_str()); - if (ret != 0) { - DMLOG(DM_LOG_ERROR, "HichainConnector::DeleteGroup failed , ret: %d.", ret); - } -} - -void HichainAuthenCallBack::onFinish(int64_t requestId, int operationCode, const char *returnData) -{ - std::string data = ""; - if (returnData != nullptr) { - data = std::string(returnData); - } - - DMLOG(DM_LOG_INFO, "HichainAuthenCallBack::onFinish reqId:%lld, operation:%d", requestId, operationCode); - if (operationCode == GroupOperationCode::MEMBER_JOIN) { - DMLOG(DM_LOG_INFO, "Add Member To Group success"); - HichainConnector::GetInstance().OnMemberJoin(requestId, SUCCESS); - } - - if (operationCode == GroupOperationCode::GROUP_CREATE) { - DMLOG(DM_LOG_INFO, "Create group success"); - HichainConnector::GetInstance().OnGroupCreated(requestId, data); - } - - if (operationCode == GroupOperationCode::MEMBER_DELETE) { - DMLOG(DM_LOG_INFO, "Delete Member from group success"); - } - - if (operationCode == GroupOperationCode::GROUP_DISBAND) { - DMLOG(DM_LOG_INFO, "Disband group success"); - } -} - -void HichainAuthenCallBack::onError(int64_t requestId, int operationCode, int errorCode, - const char *errorReturn) -{ - (void)errorReturn; - DMLOG(DM_LOG_INFO, "HichainAuthenCallBack::onError reqId:%lld, operation:%d, errorCode:%d.", - requestId, operationCode, errorCode); - - if (operationCode == GroupOperationCode::MEMBER_JOIN) { - DMLOG(DM_LOG_ERROR, "Add Member To Group failed"); - HichainConnector::GetInstance().OnMemberJoin(requestId, FAIL); - } - - if (operationCode == GroupOperationCode::GROUP_CREATE) { - DMLOG(DM_LOG_ERROR, "Create group failed"); - HichainConnector::GetInstance().OnGroupCreated(requestId, "{}"); - } - - if (operationCode == GroupOperationCode::MEMBER_DELETE) { - DMLOG(DM_LOG_ERROR, "Delete Member from group failed"); - } - - if (operationCode == GroupOperationCode::GROUP_DISBAND) { - DMLOG(DM_LOG_ERROR, "Disband group failed"); - } -} - -char *HichainAuthenCallBack::onRequest(int64_t requestId, int operationCode, const char *reqParams) -{ - if (operationCode != GroupOperationCode::MEMBER_JOIN) { - DMLOG(DM_LOG_ERROR, "HichainAuthenCallBack::onRequest operationCode %d", operationCode); - return nullptr; - } - - int32_t pinCode = AuthManager::GetInstance().GetPincode(requestId); - nlohmann::json jsonObj; - if (pinCode == FAIL) { - jsonObj[FIELD_CONFIRMATION] = REQUEST_REJECTED; - } else { - jsonObj[FIELD_CONFIRMATION] = REQUEST_ACCEPTED; - } - jsonObj[FIELD_PIN_CODE] = std::to_string(pinCode).c_str(); - char localDeviceId[DEVICE_UUID_LENGTH] = {0}; - GetDevUdid(localDeviceId, DEVICE_UUID_LENGTH); - jsonObj[FIELD_DEVICE_ID] = localDeviceId; - - std::string jsonStr = jsonObj.dump(); - char *buffer = strdup(jsonStr.c_str()); - return buffer; -} -} -} diff --git a/ext/mini/services/devicemanagerservice/src/dispatch/command_dispatch.cpp b/ext/mini/services/devicemanagerservice/src/dispatch/command_dispatch.cpp deleted file mode 100644 index 01e8a1c51d90373f83bfff15a15428382a698491..0000000000000000000000000000000000000000 --- a/ext/mini/services/devicemanagerservice/src/dispatch/command_dispatch.cpp +++ /dev/null @@ -1,152 +0,0 @@ -/* - * 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 "message_processing.h" -#include "command_dispatch.h" -#include "device_manager_log.h" -#include "message_def.h" -#include "constants.h" -#include "device_manager_errno.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 "check_authenticate_req.h" -#include "get_authenticationparam_rsp.h" -#include "get_trustdevice_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) { - DMLOG(DM_LOG_INFO, "Message req or rsp is null"); - return DEVICEMANAGER_NULLPTR; - } - int32_t ret = CommandDispatch::CmdProcessing(cmdCode, req, rsp); - if (ret != DEVICEMANAGER_OK) { - DMLOG(DM_LOG_ERROR, "MessageSendCmd Failed with ret %d", ret); - return ret; - } - return DEVICEMANAGER_OK; -} - -int32_t CommandDispatch::CmdProcessing(int32_t cmdCode, std::shared_ptr req, std::shared_ptr rsp) -{ - int32_t ret = 1; - DMLOG(DM_LOG_INFO, "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(); - - DMLOG(DM_LOG_INFO, "enter GetTrustedDeviceList."); - DmDeviceInfo *info = nullptr; - int32_t infoNum = 0; - ret = MessageProcessing::GetInstance().GetTrustedDeviceList(pkgName, extra, &info, &infoNum, prsp); - if (prsp == nullptr) { - DMLOG(DM_LOG_INFO, "Message rsp is null."); - return DEVICEMANAGER_NULLPTR; - } - prsp->SetErrCode(ret); - break; - } - case START_DEVICE_DISCOVER: { - std::shared_ptr pReq = std::static_pointer_cast(req); - std::string pkgName = pReq->GetPkgName(); - const DmSubscribeInfo dmSubscribeInfo = pReq->GetSubscribeInfo(); - DMLOG(DM_LOG_INFO, "StartDeviceDiscovery service listener."); - - ret = MessageProcessing::GetInstance().StartDeviceDiscovery(pkgName, dmSubscribeInfo); - rsp->SetErrCode(ret); - break; - } - case STOP_DEVICE_DISCOVER: { - DMLOG(DM_LOG_INFO, "StopDeviceDiscovery service listener."); - - std::shared_ptr pReq = std::static_pointer_cast(req); - std::string pkgName = pReq->GetPkgName(); - uint16_t subscribeId = pReq->GetSubscribeId(); - ret = MessageProcessing::GetInstance().StopDiscovery(pkgName, subscribeId); - rsp->SetErrCode(ret); - break; - } - case SERVER_USER_AUTHORIZATION_OPERATION: { - std::shared_ptr pReq = std::static_pointer_cast(req); - std::string pkgName= pReq->GetPkgName(); - int32_t action = pReq->GetOperation(); - - DMLOG(DM_LOG_INFO, "enter server user authorization operation."); - ret = MessageProcessing::GetInstance().SetUserOperation(pkgName, action); - rsp->SetErrCode(ret); - break; - } - case SERVER_GET_AUTHENTCATION_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 = { - .packageName = "", - .appName = "", - .appDescription = "", - .authType = 0, - .business = 0, - .pincode = 0, - .direction = 0, - .pinToken = 0 - }; - - DMLOG(DM_LOG_INFO, "DeviceManagerStub:: GET_AUTHENTCATION_INFO:pkgName:%s", pkgName.c_str()); - ret = MessageProcessing::GetInstance().GetAuthenticationParam(pkgName, authParam, prsp); - 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(); - DmAppImageInfo imageInfo(nullptr, 0, nullptr, 0); - - DMLOG(DM_LOG_INFO, "DeviceManagerStub:: AUTHENTCATION_DEVICE:pkgName:%s", pkgName.c_str()); - ret = MessageProcessing::GetInstance().AuthenticateDevice(pkgName, deviceInfo, imageInfo, extra); - rsp->SetErrCode(ret); - break; - } - case CHECK_AUTHENTICATION: { - std::shared_ptr pReq = std::static_pointer_cast(req); - std::string pkgName = pReq->GetPkgName(); - std::string authPara = pReq->GetAuthPara(); - - DMLOG(DM_LOG_INFO, "DeviceManagerStub:: CHECK_AUTHENTCATION:pkgName:%s", pkgName.c_str()); - ret = MessageProcessing::GetInstance().CheckAuthentication(authPara); - rsp->SetErrCode(ret); - break; - } - - default: - break; - } - return ret; -} -} -} \ No newline at end of file diff --git a/ext/mini/services/devicemanagerservice/src/dispatch/message_processing.cpp b/ext/mini/services/devicemanagerservice/src/dispatch/message_processing.cpp deleted file mode 100644 index db97e06acafec91639adc6c5f1596acddbad4816..0000000000000000000000000000000000000000 --- a/ext/mini/services/devicemanagerservice/src/dispatch/message_processing.cpp +++ /dev/null @@ -1,242 +0,0 @@ -/* - * Copyright (c) 2022 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 - -#include "securec.h" -#include "softbus_bus_center.h" -#include "softbus_adapter.h" -#include "anonymous_string.h" -#include "auth_manager.h" -#include "constants.h" -#include "device_manager_errno.h" -#include "device_manager_log.h" -#include "dm_ability_manager.h" -#include "encrypt_utils.h" -#include "message_processing.h" -#include "get_trustdevice_rsp.h" -#include "get_authenticationparam_rsp.h" - - - -namespace OHOS { -namespace DistributedHardware { - -IMPLEMENT_SINGLE_INSTANCE(MessageProcessing); - -int32_t MessageProcessing::CheckParamValid(nlohmann::json &extraJson, const DmAppImageInfo &imageInfo) -{ - if (!extraJson.contains(APP_NAME_KEY) || - !extraJson.contains(APP_DESCRIPTION_KEY) || - !extraJson.contains(AUTH_TYPE)) { - DMLOG(DM_LOG_ERROR, "Invalid para"); - return DEVICEMANAGER_INVALID_VALUE; - } - - std::string appName = extraJson[APP_NAME_KEY]; - std::string appDescription = extraJson[APP_DESCRIPTION_KEY]; - - if (appName.empty() || appDescription.empty()) { - DMLOG(DM_LOG_ERROR, "Invalid app image info"); - return DEVICEMANAGER_INVALID_VALUE; - } - if (extraJson[AUTH_TYPE] != AUTH_TYPE_PIN) { - DMLOG(DM_LOG_ERROR, "invalid auth type, only support pin auth"); - return DEVICEMANAGER_INVALID_VALUE; - } - return DEVICEMANAGER_OK; -} - -int32_t MessageProcessing::GenRandInt(int32_t randMin, int32_t randMax) -{ - std::random_device randDevice; - std::mt19937 genRand(randDevice()); - std::uniform_int_distribution disRand(randMin, randMax); - return disRand(genRand); -} - -int32_t MessageProcessing::GetTrustedDeviceList(std::string &pkgName, std::string &extra, - DmDeviceInfo **info, int32_t *infoNum, std::shared_ptr prsp) -{ - if (info == nullptr || infoNum == nullptr) { - return DEVICEMANAGER_NULLPTR; - } - DMLOG(DM_LOG_INFO, "In, pkgName: %s", pkgName.c_str()); - - std::vector deviceInfoVec; - - NodeBasicInfo *nodeInfo = nullptr; - *info = nullptr; - *infoNum = 0; - - int32_t ret = SoftbusAdapter::GetTrustDevices(pkgName, &nodeInfo, infoNum); - if (ret != DEVICEMANAGER_OK || *infoNum <= 0 || nodeInfo == nullptr) { - DMLOG(DM_LOG_ERROR, "GetTrustDevices errCode:%d, num:%d", ret, *infoNum); - return ret; - } - - *info = (DmDeviceInfo *)malloc(sizeof(DmDeviceInfo) * (*infoNum)); - if (*info == nullptr) { - FreeNodeInfo(nodeInfo); - return DEVICEMANAGER_MALLOC_ERROR; - } - - for (int32_t i = 0; i < *infoNum; ++i) { - NodeBasicInfo *nodeBasicInfo = nodeInfo + i; - DmDeviceInfo *deviceInfo = *info + i; - if (memcpy_s(deviceInfo->deviceId, sizeof(deviceInfo->deviceId), nodeBasicInfo->networkId, - std::min(sizeof(deviceInfo->deviceId), sizeof(nodeBasicInfo->networkId))) != DEVICEMANAGER_OK) { - DMLOG(DM_LOG_ERROR, "memcpy failed"); - } - if (memcpy_s(deviceInfo->deviceName, sizeof(deviceInfo->deviceName), nodeBasicInfo->deviceName, - std::min(sizeof(deviceInfo->deviceName), sizeof(nodeBasicInfo->deviceName))) != DEVICEMANAGER_OK) { - DMLOG(DM_LOG_ERROR, "memcpy failed"); - } - deviceInfo->deviceTypeId = (DMDeviceType)nodeBasicInfo->deviceTypeId; - deviceInfoVec.emplace_back(*deviceInfo); - } - prsp->SetDeviceVec(deviceInfoVec); - - FreeNodeInfo(nodeInfo); - free(info); - DMLOG(DM_LOG_INFO, "success, pkgName:%s, deviceCount %d", pkgName.c_str(), *infoNum); - return DEVICEMANAGER_OK; -} - -int32_t MessageProcessing::StartDeviceDiscovery(std::string &pkgName,const DmSubscribeInfo &dmSubscribeInfo) -{ - DMLOG(DM_LOG_INFO, "In, pkgName: %s, subscribeId %d", pkgName.c_str(), - (int32_t)dmSubscribeInfo.subscribeId); - - DMLOG(DM_LOG_INFO, "capability: %s", dmSubscribeInfo.capability); - SubscribeInfo subscribeInfo; - - subscribeInfo.subscribeId = dmSubscribeInfo.subscribeId; - subscribeInfo.mode = (DiscoverMode)dmSubscribeInfo.mode; - subscribeInfo.medium = (ExchanageMedium)dmSubscribeInfo.medium; - subscribeInfo.freq = (ExchangeFreq)dmSubscribeInfo.freq; - subscribeInfo.isSameAccount = dmSubscribeInfo.isSameAccount; - subscribeInfo.isWakeRemote = dmSubscribeInfo.isWakeRemote; - subscribeInfo.capability = dmSubscribeInfo.capability; - subscribeInfo.capabilityData = nullptr; - subscribeInfo.dataLen = 0; - return SoftbusAdapter::StartDiscovery(pkgName, &subscribeInfo); -} - -int32_t MessageProcessing::StopDiscovery(std::string &pkgName, uint16_t subscribeId) -{ - DMLOG(DM_LOG_INFO, "In, pkgName: %s, subscribeId %d", pkgName.c_str(), (int32_t)subscribeId); - return SoftbusAdapter::StopDiscovery(pkgName, subscribeId); -} - -int32_t MessageProcessing::SetUserOperation(std::string &pkgName, int32_t action) -{ - if (pkgName.empty()) { - DMLOG(DM_LOG_ERROR, "invalid para"); - return DEVICEMANAGER_INVALID_VALUE; - } - - AuthManager::GetInstance().OnUserOperate(action); - return SUCCESS; -} - -int32_t MessageProcessing::GetAuthenticationParam(std::string &pkgName, DmAuthParam &authParam, std::shared_ptr prsp) -{ - DmAuthParam authParamside = { - .packageName = "", - .appName = "", - .appDescription = "", - .authType = 0, - .business = 0, - .pincode = 0, - .direction = 0, - .pinToken = 0 - }; - - if (pkgName.empty()) { - DMLOG(DM_LOG_ERROR, "invalid para"); - return DEVICEMANAGER_INVALID_VALUE; - } - - DmAbilityManager::GetInstance().StartAbilityDone(); - AuthManager::GetInstance().GetAuthenticationParam(authParam); - - authParamside.direction = authParam.direction; - authParamside.authType = authParam.authType; - if (authParamside.direction == AUTH_SESSION_SIDE_CLIENT) { - authParamside.pinToken = authParam.pinToken; - prsp->SetAuthParam(authParamside); - - DMLOG(DM_LOG_DEBUG, "DeviceManagerStub::is Client so just return direction"); - return DEVICEMANAGER_OK; - } - - authParamside.packageName = authParam.packageName; - authParamside.appName = authParam.appName; - authParamside.appDescription = authParam.appDescription; - authParamside.business = authParam.business; - authParamside.pincode = authParam.pincode; - - int32_t appIconLen = authParam.imageinfo.GetAppIconLen(); - int32_t appThumbnailLen = authParam.imageinfo.GetAppThumbnailLen(); - uint8_t *appIconBuffer = nullptr; - uint8_t *appThumbBuffer = nullptr; - if (appIconLen > 0 && authParam.imageinfo.GetAppIcon() != nullptr) { - appIconBuffer = const_cast(authParam.imageinfo.GetAppIcon()); - } - if (appThumbnailLen > 0 && authParam.imageinfo.GetAppThumbnail() != nullptr) { - appThumbBuffer = const_cast(authParam.imageinfo.GetAppThumbnail()); - } - - authParamside.imageinfo.Reset(appIconBuffer, appIconLen, appThumbBuffer, appThumbnailLen); - prsp->SetAuthParam(authParamside); - return DEVICEMANAGER_OK; -} - -int32_t MessageProcessing::AuthenticateDevice(std::string &pkgName, const DmDeviceInfo &deviceInfo, - const DmAppImageInfo &imageInfo, std::string &extra) -{ - if (pkgName.empty() || extra.empty()) { - DMLOG(DM_LOG_ERROR, "invalid para"); - return DEVICEMANAGER_INVALID_VALUE; - } - nlohmann::json jsonObject = nlohmann::json::parse(extra, nullptr, false); - if (jsonObject.is_discarded()) { - DMLOG(DM_LOG_ERROR, "AuthenticateDevice extra jsonStr error"); - return DEVICEMANAGER_INVALID_VALUE; - } - int32_t ret = CheckParamValid(jsonObject, imageInfo); - if (ret != DEVICEMANAGER_OK) { - DMLOG(DM_LOG_ERROR, "AuthenticateDevice para invalid, ret %d", ret); - return ret; - } - DMLOG(DM_LOG_INFO, "AuthenticateDevice In, pkgName: %s, deviceId %s", pkgName.c_str(), - GetAnonyString(deviceInfo.deviceId).c_str()); - - AuthManager::GetInstance().AuthDeviceGroup(pkgName, deviceInfo, imageInfo, extra); - return DEVICEMANAGER_OK; -} - -int32_t MessageProcessing::CheckAuthentication(std::string &authPara) -{ - if (authPara.empty()) { - DMLOG(DM_LOG_INFO, " DeviceManagerIpcAdapter::CheckAuthentication check authPara failed"); - return DEVICEMANAGER_INVALID_VALUE; - } - DMLOG(DM_LOG_INFO, " DeviceManagerIpcAdapter::CheckAuthentication"); - return AuthManager::GetInstance().CheckAuthentication(authPara); -} - -} // namespace DistributedHardware -} // namespace OHOS diff --git a/ext/mini/services/devicemanagerservice/src/dispatch/server_init.cpp b/ext/mini/services/devicemanagerservice/src/dispatch/server_init.cpp deleted file mode 100644 index 55b15d797d2ffd489972ee695c8fe500d5b5bd8a..0000000000000000000000000000000000000000 --- a/ext/mini/services/devicemanagerservice/src/dispatch/server_init.cpp +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2022 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 -#include - -#include "device_manager_log.h" -#include "device_manager_errno.h" -#include "hichain_connector.h" -#include "server_stub.h" -#include "server_init.h" -#include "samgr_lite.h" -#include "softbus_adapter.h" - -using namespace OHOS::DistributedHardware; - -void Server_Init() -{ - const int32_t DM_SERVICE_INIT_DELAY = 2; - - sleep(DM_SERVICE_INIT_DELAY); - SAMGR_Bootstrap(); - - if (SoftbusAdapter::Init() != DEVICEMANAGER_OK) { - DMLOG(DM_LOG_ERROR, "softbus adapter init failed"); - return; - } - if (HichainConnector::GetInstance().Init() != DEVICEMANAGER_OK) { - DMLOG(DM_LOG_ERROR, "hichain connector init failed"); - return; - } - - DMLOG(DM_LOG_INFO, "DM server Init success"); -} diff --git a/ext/mini/services/devicemanagerservice/src/dispatch/server_stub.cpp b/ext/mini/services/devicemanagerservice/src/dispatch/server_stub.cpp deleted file mode 100644 index 714116d882c94b02a151b53707a0441334eb7bcf..0000000000000000000000000000000000000000 --- a/ext/mini/services/devicemanagerservice/src/dispatch/server_stub.cpp +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Copyright (c) 2022 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 "server_init.h" - -#include "securec.h" - - -#include "ohos_init.h" -#include "samgr_lite.h" - - -#include "device_manager_log.h" -#include "device_manager_errno.h" -#include "dm_subscribe_info.h" - -#include "message_def.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 == nullptr) { - DMLOG(DM_LOG_WARN, "invalid param"); - return FALSE; - } - - Server_Init(); - - DeviceManagerSamgrService *mgrService = (DeviceManagerSamgrService *)service; - mgrService->identity = identity; - return TRUE; -} - -static BOOL MessageHandle(Service *service, Request *request) -{ - if ((service == nullptr) || (request == nullptr)) { - DMLOG(DM_LOG_WARN, "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, - }; - - if (!SAMGR_GetInstance()->RegisterService((Service *)&service)) { - DMLOG(DM_LOG_ERROR, "%s, RegisterService failed", DEVICE_MANAGER_SERVICE_NAME); - return; - } - if (!SAMGR_GetInstance()->RegisterDefaultFeatureApi(DEVICE_MANAGER_SERVICE_NAME, GET_IUNKNOWN(service))) { - DMLOG(DM_LOG_ERROR, "%s, RegisterDefaultFeatureApi failed", DEVICE_MANAGER_SERVICE_NAME); - return; - } - DMLOG(DM_LOG_INFO, "%s, init success", DEVICE_MANAGER_SERVICE_NAME); -} -SYSEX_SERVICE_INIT(DevMgrSvcInit); diff --git a/ext/mini/services/devicemanagerservice/src/message/msg_codec.cpp b/ext/mini/services/devicemanagerservice/src/message/msg_codec.cpp deleted file mode 100644 index 23b9728e4b89b4ef3f656782376df2ac756d0081..0000000000000000000000000000000000000000 --- a/ext/mini/services/devicemanagerservice/src/message/msg_codec.cpp +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Copyright (c) 2022 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 "msg_codec.h" -#include "device_manager_log.h" -#include "msg_head.h" - -#include "constants.h" -#include "device_manager_errno.h" - -namespace OHOS { -namespace DistributedHardware { -int32_t MsgCodec::DecodeMsgType(std::string &jsonStr) -{ - nlohmann::json jsonObject = nlohmann::json::parse(jsonStr, nullptr, false); - if (jsonObject.is_discarded()) { - DMLOG(DM_LOG_ERROR, "DecodeMsgType jsonStr error"); - return DmMsgType::MSG_TYPE_UNKNOWN; - } - MsgHead mMsgHead; - auto msgHeadPtr = mMsgHead.Decode(jsonObject); - if (msgHeadPtr == nullptr) { - DMLOG(DM_LOG_ERROR, "mMsgHead decode error"); - return DEVICEMANAGER_NULLPTR; - } - return msgHeadPtr->GetMsgType(); -} - -std::string MsgCodec::EncodeSyncGroup(std::vector &groupIdList, std::string &deviceId) -{ - nlohmann::json jsonObject; - MsgSyncGroup mMsgSyncGroup(groupIdList, deviceId); - mMsgSyncGroup.Encode(jsonObject); - return jsonObject.dump(); -} - -std::vector MsgCodec::EncodeReqAppAuth(std::string &token, std::string hostPkg, std::string targetPkg, - const DmDeviceInfo &devReqInfo, const DmAppImageInfo &imageInfo, std::string &extras) -{ - MsgRequestAuth mMsgRequestAuth(token, hostPkg, targetPkg, devReqInfo, imageInfo, extras); - return mMsgRequestAuth.Encode(); -} - -std::string MsgCodec::EncodeAcceptRespAuth(int32_t reply, int64_t requestId, std::string &groupId, - std::string &groupName, std::string &reqDeviceId) -{ - nlohmann::json jsonObject; - MsgResponseAuth mMsgResponseAuth(reply, requestId, groupId, groupName, reqDeviceId); - mMsgResponseAuth.Encode(jsonObject); - return jsonObject.dump(); -} - -std::string MsgCodec::EncodeRefuseRespAuth(int32_t reply, std::string &reqDeviceId) -{ - nlohmann::json jsonObject; - MsgResponseAuth mMsgResponseAuth(reply, reqDeviceId); - mMsgResponseAuth.Encode(jsonObject); - return jsonObject.dump(); -} - -std::shared_ptr MsgCodec::DecodeRequestAuth(std::string &jsonStr, - std::shared_ptr msgRequestAuth) -{ - nlohmann::json jsonObject = nlohmann::json::parse(jsonStr, nullptr, false); - if (jsonObject.is_discarded()) { - DMLOG(DM_LOG_ERROR, "DecodeRequestAuth jsonStr error"); - return nullptr; - } - return MsgRequestAuth::Decode(jsonObject, msgRequestAuth); -} - -std::shared_ptr MsgCodec::DecodeResponseAuth(std::string &jsonStr) -{ - nlohmann::json jsonObject = nlohmann::json::parse(jsonStr, nullptr, false); - if (jsonObject.is_discarded()) { - DMLOG(DM_LOG_ERROR, "DecodeResponseAuth jsonStr error"); - return nullptr; - } - std::shared_ptr msgResponseAuthPtr = std::make_shared(); - if (msgResponseAuthPtr->Decode(jsonObject) == 0) { - return msgResponseAuthPtr; - } - return nullptr; -} - -std::shared_ptr MsgCodec::DecodeSyncGroup(std::string &jsonStr) -{ - nlohmann::json jsonObject = nlohmann::json::parse(jsonStr, nullptr, false); - if (jsonObject.is_discarded()) { - DMLOG(DM_LOG_ERROR, "DecodeSyncGroup jsonStr error"); - return nullptr; - } - std::shared_ptr msgSyncGroupPtr = std::make_shared(); - if (msgSyncGroupPtr->Decode(jsonObject) == 0) { - return msgSyncGroupPtr; - } - return nullptr; -} -} -} diff --git a/ext/mini/services/devicemanagerservice/src/message/msg_head.cpp b/ext/mini/services/devicemanagerservice/src/message/msg_head.cpp deleted file mode 100644 index 30446bc361a9f0ef1e746781d7be7ac86c4ebda5..0000000000000000000000000000000000000000 --- a/ext/mini/services/devicemanagerservice/src/message/msg_head.cpp +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (c) 2022 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 "msg_head.h" -#include "device_manager_log.h" -#include "constants.h" - -namespace OHOS { -namespace DistributedHardware { -void MsgHead::Encode(nlohmann::json &json) -{ - json[TAG_VER] = DM_ITF_VER; - json[TAG_TYPE] = mMsgType_; -} - -std::shared_ptr MsgHead::Decode(nlohmann::json &json) -{ - if (json.contains(TAG_TYPE) == false || json.contains(TAG_VER) == false) { - DMLOG(DM_LOG_ERROR, "err json string"); - return nullptr; - } - - auto msgHeadPtr = std::make_shared(); - msgHeadPtr->mItfVer_ = json[TAG_VER]; - - if (DM_ITF_VER.compare(msgHeadPtr->mItfVer_) == 0) { - msgHeadPtr->mMsgType_ = json[TAG_TYPE]; - } else { - DMLOG(DM_LOG_ERROR, "msg head version mismatch"); - msgHeadPtr->mMsgType_ = DmMsgType::MSG_TYPE_UNKNOWN; - } - return msgHeadPtr; -} - -int32_t MsgHead::GetMsgType() -{ - return mMsgType_; -} -} -} \ No newline at end of file diff --git a/ext/mini/services/devicemanagerservice/src/message/msg_request_auth.cpp b/ext/mini/services/devicemanagerservice/src/message/msg_request_auth.cpp deleted file mode 100644 index 6a2aba58fa92a0e8d82342bb49f587ff6b54432a..0000000000000000000000000000000000000000 --- a/ext/mini/services/devicemanagerservice/src/message/msg_request_auth.cpp +++ /dev/null @@ -1,382 +0,0 @@ -/* - * Copyright (c) 2022 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 -#include - -#include "device_manager_log.h" -#include "constants.h" -#include "encrypt_utils.h" -#include "device_manager_errno.h" -#include "msg_request_auth.h" -#include "parameter.h" -#include "softbus_session.h" -#include "softbus_bus_center.h" - -namespace OHOS { -namespace DistributedHardware { -MsgRequestAuth::MsgRequestAuth(std::string &token, std::string hostPkgName, std::string targetPkgName, - const int32_t groupVisibility, const DmDeviceInfo& devReqInfo, const DmAppImageInfo &imageInfo, - std::string &extras) -{ - DMLOG(DM_LOG_INFO, "MsgRequestAuth construction started"); - nlohmann::json jsonObject = nlohmann::json::parse(extras, nullptr, false); - if (jsonObject.is_discarded()) { - DMLOG(DM_LOG_ERROR, "MsgRequestAuth error"); - return; - } - if (!jsonObject.contains(APP_NAME_KEY) || !jsonObject.contains(APP_DESCRIPTION_KEY)) { - DMLOG(DM_LOG_ERROR, "MsgRequestAuth, err json string"); - return; - } - - mAuthType_ = jsonObject.contains(AUTH_TYPE) ? (int32_t)jsonObject[AUTH_TYPE] : AUTH_TYPE_QR; - mHead_ = std::make_shared((mAuthType_ == AUTH_TYPE_QR) ? (DmMsgType::MSG_TYPE_REQ_AUTH) : - (DmMsgType::MSG_TYPE_AUTH_BY_PIN)); - std::string deviceManagerPkgName = "ohos.distributedhardware.devicemanager"; - NodeBasicInfo localBasicInfo; - int32_t ret = GetLocalNodeDeviceInfo(deviceManagerPkgName.c_str(), &localBasicInfo); - if (ret != 0) { - DMLOG(DM_LOG_ERROR, "GetLocalNodeDeviceInfo err: %d", ret); - return; - } - mDeviceName_ = localBasicInfo.deviceName; - char localDeviceId[DEVICE_UUID_LENGTH] = {0}; - GetDevUdid(localDeviceId, DEVICE_UUID_LENGTH); - mDeviceId_ = localDeviceId; - mToken_ = token; - mHostPkg_ = hostPkgName; - mTargetPkg_ = targetPkgName; - mGroupVisibility_ = groupVisibility; - mAppName_ = jsonObject[APP_NAME_KEY]; - mAppDescription_ = jsonObject[APP_DESCRIPTION_KEY]; - mImageInfo_ = imageInfo; - mThumbnailSize_ = mImageInfo_.GetAppThumbnailLen(); - mAppIconSize_ = mImageInfo_.GetAppIconLen(); - mDeviceType_ = ToHexString(localBasicInfo.deviceTypeId); - DMLOG(DM_LOG_INFO, "MsgRequestAuth construction completed"); -} - -int32_t MsgRequestAuth::GetEncodedAppInfo(const uint8_t *dataSrc, int32_t srcLen, std::string &outString) -{ - DMLOG(DM_LOG_INFO, "MsgRequestAuth GetEncodedAppInfo started"); - if (srcLen <= 0 || dataSrc == nullptr) { - DMLOG(DM_LOG_ERROR, "data string is empty"); - return DEVICEMANAGER_OK; - } - - int32_t tempBufLen = ((srcLen / BASE64_BYTE_LEN_3) + 1) * BASE64_BYTE_LEN_4 + 1; - char *tmpBuf = (char *)calloc(sizeof(char), tempBufLen); - if (tmpBuf == nullptr) { - DMLOG(DM_LOG_ERROR, "getEncodedAppInfoString: malloc mem error, size %d", tempBufLen); - return DEVICEMANAGER_MALLOC_ERROR; - } - - size_t outLen = 0; - int32_t ret = EncryptUtils::MbedtlsBase64Encode((uint8_t *)tmpBuf, tempBufLen, &outLen, dataSrc, (size_t)srcLen); - if (ret != 0) { - DMLOG(DM_LOG_ERROR, "MbedtlsBase64Encode error"); - free(tmpBuf); - return ENCODE_DATA_ERROR; - } - outString = tmpBuf; - free(tmpBuf); - tmpBuf = nullptr; - DMLOG(DM_LOG_INFO, "MsgRequestAuth GetEncodedAppInfo completed"); - return DEVICEMANAGER_OK; -} - -void MsgRequestAuth::GetDecodeAppInfo(const std::string appString, uint8_t **outBuffer, int32_t &outBufferLen) -{ - DMLOG(DM_LOG_INFO, "MsgRequestAuth GetDecodeAppInfo started"); - int32_t tempBufLen = appString.length() + 1; - uint8_t *buffer = (uint8_t *)calloc(sizeof(char), tempBufLen); - if (buffer == nullptr) { - DMLOG(DM_LOG_ERROR, "GetDecodeAppInfo: malloc mem error, tempBufLen %d", tempBufLen); - return; - } - - size_t outLen = 0; - int32_t ret = EncryptUtils::MbedtlsBase64Decode(buffer, tempBufLen, &outLen, - (const uint8_t*)appString.c_str(), appString.length()); - if (ret != 0 || static_cast(outLen) > tempBufLen) { - DMLOG(DM_LOG_ERROR, "MbedtlsBase64Decode failed, ret %d, outLen %zu, tempBufLen %d", - ret, outLen, tempBufLen); - outBufferLen = 0; - *outBuffer = nullptr; - free(buffer); - return; - } - - DMLOG(DM_LOG_INFO, "MsgRequestAuth GetDecodeAppInfo outBufferLen %d", outBufferLen); - outBufferLen = outLen; - *outBuffer = buffer; -} - -std::string MsgRequestAuth::EncodeDevInfo() -{ - DMLOG(DM_LOG_INFO, "MsgRequestAuth EncodeDevInfo started"); - nlohmann::json jsonObj; - mHead_->Encode(jsonObj); - jsonObj[TAG_SLICE_NUM] = mMsgSlice_; - jsonObj[TAG_INDEX] = 0; - jsonObj[TAG_REQUESTER] = mDeviceName_; - jsonObj[TAG_DEVICE_ID] = mDeviceId_; - jsonObj[TAG_DEVICE_TYPE] = mDeviceType_; - jsonObj[TAG_TOKEN] = mToken_; - jsonObj[TAG_VISIBILITY] = mGroupVisibility_; - if (mGroupVisibility_ == GROUP_VISIBILITY_IS_PRIVATE) { - jsonObj[TAG_TARGET] = mTargetPkg_; - jsonObj[TAG_HOST] = mHostPkg_; - } - jsonObj[TAG_APP_NAME] = mAppName_; - jsonObj[TAG_APP_DESCRIPTION] = mAppDescription_; - - std::string appIconStr = ""; - GetEncodedAppInfo(mImageInfo_.GetAppIcon(), mImageInfo_.GetAppIconLen(), appIconStr); - jsonObj[TAG_APP_ICON] = appIconStr; - jsonObj[TAG_THUMBNAIL_SIZE] = mThumbnailSize_; - jsonObj[TAG_AUTH_TYPE] = mAuthType_; - DMLOG(DM_LOG_INFO, "MsgRequestAuth EncodeDevInfo completed"); - return jsonObj.dump(); -} - -void MsgRequestAuth::DecodeDeviceInfo(nlohmann::json &json, std::shared_ptr msg) -{ - msg->mDeviceName_ = json[TAG_REQUESTER]; - msg->mDeviceId_ = json[TAG_DEVICE_ID]; - msg->mDeviceType_ = json[TAG_DEVICE_TYPE]; - msg->mToken_ = json[TAG_TOKEN]; - msg->mGroupVisibility_ = json[TAG_VISIBILITY]; - if (msg->mGroupVisibility_ == GROUP_VISIBILITY_IS_PRIVATE) { - msg->mTargetPkg_ = json[TAG_TARGET]; - msg->mHostPkg_ = json[TAG_HOST]; - } - msg->mAppName_ = json[TAG_APP_NAME]; - msg->mAppDescription_ = json[TAG_APP_DESCRIPTION]; - - const std::string iconStr = json[TAG_APP_ICON]; - uint8_t *appIcon = nullptr; - int32_t appIconLen = 0; - msg->GetDecodeAppInfo(iconStr, &appIcon, appIconLen); - if (appIcon != nullptr) { - msg->mImageInfo_.ResetIcon(appIcon, appIconLen); - free(appIcon); - } - - SetThumbnailSize(json, msg); - msg->mAuthType_ = json[TAG_AUTH_TYPE]; -} - -std::vector MsgRequestAuth::Encode() -{ - DMLOG(DM_LOG_INFO, "MsgRequestAuth encode started"); - std::vector jsonStrs; - int32_t thumbnailSlice = - ((mThumbnailSize_ / MSG_MAX_SIZE) + (mThumbnailSize_ % MSG_MAX_SIZE) == 0 ? 0 : 1); - mMsgSlice_ = thumbnailSlice + 1; - jsonStrs.push_back(EncodeDevInfo()); - for (int32_t idx = 0; idx < thumbnailSlice; idx++) { - nlohmann::json jsonObj; - mHead_->Encode(jsonObj); - jsonObj[TAG_SLICE_NUM] = mMsgSlice_; - jsonObj[TAG_INDEX] = idx + 1; - jsonObj[TAG_DEVICE_ID] = mDeviceId_; - jsonObj[TAG_THUMBNAIL_SIZE] = mThumbnailSize_; - - // frag thumbnail by 45KB - std::string thumbnailStr = ""; - int32_t leftLen = mImageInfo_.GetAppThumbnailLen() - idx * MSG_MAX_SIZE; - int32_t sliceLen = (leftLen > MSG_MAX_SIZE) ? MSG_MAX_SIZE : leftLen; - - DMLOG(DM_LOG_INFO, "TAG_APP_THUMBNAIL encode, idx %d, encodeLen %d, mThumbnailSize_ %d", - idx, sliceLen, mThumbnailSize_); - - const uint8_t *thumbnail = mImageInfo_.GetAppThumbnail(); - GetEncodedAppInfo(thumbnail + idx * MSG_MAX_SIZE, sliceLen, thumbnailStr); - jsonObj[TAG_APP_THUMBNAIL] = thumbnailStr; - - jsonStrs.push_back(jsonObj.dump()); - } - DMLOG(DM_LOG_INFO, "MsgRequestAuth encode completed"); - return jsonStrs; -} - -std::shared_ptr MsgRequestAuth::Decode(nlohmann::json &json, std::shared_ptr msgIn) -{ - if (!json.contains(TAG_INDEX) || !json.contains(TAG_DEVICE_ID) || !json.contains(TAG_SLICE_NUM)) { - DMLOG(DM_LOG_ERROR, "err json string, first time"); - return nullptr; - } - int32_t idx = json[TAG_INDEX]; - std::string deviceId = json[TAG_DEVICE_ID]; - if (!IsMsgValid(msgIn, json, deviceId, idx)) { - auto inValidMsg = std::make_shared(); - inValidMsg->mMsgSlice_ = FAIL; - return inValidMsg; - } - - std::shared_ptr msg = msgIn; - if (msgIn == nullptr || msgIn->mMsgCnt_ == msgIn->mMsgSlice_) { - msg = std::make_shared(); - } - msg->mHead_ = MsgHead::Decode(json); - msg->mMsgSlice_ = json[TAG_SLICE_NUM]; - if (idx == 0) { - DecodeDeviceInfo(json, msg); - } else { - SetThumbnailSize(json, msg); - msg->mDeviceId_ = deviceId; - if (!json.contains(TAG_APP_THUMBNAIL)) { - DMLOG(DM_LOG_ERROR, "err json string, TAG_APP_THUMBNAIL not exit"); - return nullptr; - } - - std::string thumbnailStr = json[TAG_APP_THUMBNAIL]; - uint8_t *thumbnail = nullptr; - int32_t thumbnailLen = 0; - msg->GetDecodeAppInfo(thumbnailStr, &thumbnail, thumbnailLen); - if (thumbnail == nullptr) { - DMLOG(DM_LOG_ERROR, "TAG_APP_THUMBNAIL Decode error"); - return nullptr; - } - - DMLOG(DM_LOG_INFO, "TAG_APP_THUMBNAIL decode, idx %d, decodeLen %d, mThumbnailSize_ %d", - idx, thumbnailLen, msg->mThumbnailSize_); - if (msg->mThumbnailSize_ < thumbnailLen + (idx - 1) * MSG_MAX_SIZE) { - auto inValidReqMsg = std::make_shared(); - inValidReqMsg->mMsgSlice_ = FAIL; - free(thumbnail); - return inValidReqMsg; - } - msg->mImageInfo_.SetThumbnailData(thumbnail, thumbnailLen, (idx - 1) * MSG_MAX_SIZE, thumbnailLen); - free(thumbnail); - } - msg->mMsgCnt_++; - return msg; -} - -int32_t MsgRequestAuth::GetMsgSlice() -{ - return mMsgSlice_; -} - -int32_t MsgRequestAuth::GetMsgCnt() -{ - return mMsgCnt_; -} - -std::string MsgRequestAuth::GetRequestDeviceId() -{ - return mDeviceId_; -} - -bool MsgRequestAuth::IsMsgValid(std::shared_ptr msgIn, nlohmann::json &json, - std::string &deviceId, int32_t index) -{ - if (msgIn != nullptr && msgIn->mMsgCnt_ != msgIn->mMsgSlice_ && deviceId.compare(msgIn->mDeviceId_)) { - DMLOG(DM_LOG_ERROR, "IsMsgValid, msgIn error"); - return false; - } - - if (!json.contains(TAG_THUMBNAIL_SIZE)) { - DMLOG(DM_LOG_ERROR, "IsMsgValid, err json string"); - return false; - } - - if (index < 0 || index >= DES_SLICE_MAX_NUM) { - DMLOG(DM_LOG_ERROR, "index err"); - return false; - } - - if (index == 0) { - return IsAppInfoValid(json); - } else { - int32_t thumbnailSlice = json[TAG_THUMBNAIL_SIZE]; - if (thumbnailSlice > THUMB_MAX_LEN || thumbnailSlice < 0) { - DMLOG(DM_LOG_ERROR, "IsMsgValid, thumbnailSlice error"); - return false; - } - } - return true; -} - -bool MsgRequestAuth::IsAppInfoValid(nlohmann::json &json) -{ - if (!json.contains(TAG_REQUESTER) || !json.contains(TAG_DEVICE_TYPE) || !json.contains(TAG_TOKEN) || - !json.contains(TAG_VISIBILITY) || !json.contains(TAG_APP_NAME) || !json.contains(TAG_APP_DESCRIPTION) || - !json.contains(TAG_APP_ICON) || !json.contains(TAG_AUTH_TYPE) || !json.contains(TAG_DEVICE_ID)) { - DMLOG(DM_LOG_ERROR, "IsAppInfoValid:: err json string"); - return false; - } - - int32_t groupVisibility = json[TAG_VISIBILITY]; - if (groupVisibility == GROUP_VISIBILITY_IS_PRIVATE) { - if (!json.contains(TAG_TARGET) || !json.contains(TAG_HOST)) { - DMLOG(DM_LOG_ERROR, "IsAppInfoValid:: err json string, TAG_TARGET or TAG_HOST not contain"); - return false; - } - } - - if (json[TAG_APP_ICON].size() > ICON_MAX_LEN) { - DMLOG(DM_LOG_ERROR, "IsAppInfoValid, appIcon size error"); - return false; - } - - int32_t thumbnailSize = json[TAG_THUMBNAIL_SIZE]; - if (thumbnailSize > THUMB_MAX_LEN || thumbnailSize < 0) { - DMLOG(DM_LOG_ERROR, "IsAppInfoValid, thumbnailSize error"); - return false; - } - return true; -} - -void MsgRequestAuth::SetAuthType(nlohmann::json &json, std::shared_ptr msg) -{ - int32_t authType = json.contains(TAG_AUTH_TYPE) ? (int32_t)json[TAG_AUTH_TYPE] : AUTH_TYPE_QR; - if (authType != AUTH_TYPE_QR && authType != AUTH_TYPE_PIN) { - authType = AUTH_TYPE_QR; - } - if (msg == nullptr) { - LOGE("msg is null"); - return; - } - msg->mAuthType_ = authType; -} - -void MsgRequestAuth::SetThumbnailSize(nlohmann::json &json, std::shared_ptr msg) -{ - if (!json.contains(TAG_THUMBNAIL_SIZE)) { - DMLOG(DM_LOG_ERROR, "SetThumbnailSize, err json string"); - return; - } - int32_t thumbnailSlice = json[TAG_THUMBNAIL_SIZE]; - if (msg->mThumbnailSize_ == 0) { - msg->mImageInfo_.InitThumbnail(thumbnailSlice); - msg->mThumbnailSize_ = msg->mImageInfo_.GetAppThumbnailLen(); - DMLOG(DM_LOG_INFO, "thumbnailSlice %d, mThumbnailSize_ is, %d", thumbnailSlice, msg->mThumbnailSize_); - } -} - -std::string MsgRequestAuth::ToHexString(int32_t value) -{ - std::stringstream ioss; - std::string tmpStr; - ioss << std::setiosflags(std::ios::uppercase) << std::hex << value; - ioss >> tmpStr; - return tmpStr; -} -} -} diff --git a/ext/mini/services/devicemanagerservice/src/message/msg_response_auth.cpp b/ext/mini/services/devicemanagerservice/src/message/msg_response_auth.cpp deleted file mode 100644 index 5f68f6fb392f2612a8a744ec9493c08f5189bc17..0000000000000000000000000000000000000000 --- a/ext/mini/services/devicemanagerservice/src/message/msg_response_auth.cpp +++ /dev/null @@ -1,160 +0,0 @@ -/* - * Copyright (c) 2022 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 "msg_response_auth.h" -#include "device_manager_log.h" -#include "device_manager_errno.h" -#include "constants.h" -#include "parameter.h" -#include "hichain_connector.h" -#include "anonymous_string.h" - -namespace OHOS { -namespace DistributedHardware { -MsgResponseAuth::MsgResponseAuth(int32_t reply, std::string &reqDeviceId) -{ - mHead_ = std::make_shared(MSG_TYPE_RESP_AUTH); - mReply_ = reply; - char localDeviceId[DEVICE_UUID_LENGTH] = {0}; - GetDevUdid(localDeviceId, DEVICE_UUID_LENGTH); - mDeviceId_ = localDeviceId; - std::vector groupList; - HichainConnector::GetInstance().GetRelatedGroups(reqDeviceId, groupList); - HichainConnector::GetInstance().GetSyncGroupList(groupList, mSyncGroupList_); -} - -MsgResponseAuth::MsgResponseAuth(int32_t reply, int64_t requestId, std::string &groupId, std::string &groupName, - std::string &reqDeviceId) -{ - mHead_ = std::make_shared(MSG_TYPE_RESP_AUTH); - mReply_ = reply; - mNetId_ = ""; - mGroupId_ = groupId; - mGroupName_ = groupName; - mRequestId_ = requestId; - char localDeviceId[DEVICE_UUID_LENGTH] = {0}; - GetDevUdid(localDeviceId, DEVICE_UUID_LENGTH); - mDeviceId_ = localDeviceId; - std::vector groupList; - HichainConnector::GetInstance().GetRelatedGroups(reqDeviceId, groupList); - HichainConnector::GetInstance().GetSyncGroupList(groupList, mSyncGroupList_); -} - -void MsgResponseAuth::Encode(nlohmann::json &jsonObj) -{ - DMLOG(DM_LOG_INFO, "MsgResponseAuth encode started"); - mHead_->Encode(jsonObj); - jsonObj[TAG_REPLY] = mReply_; - jsonObj[TAG_DEVICE_ID] = mDeviceId_; - jsonObj[TAG_GROUPIDS] = mSyncGroupList_; - if (mReply_ == SESSION_REPLY_ACCEPT) { - jsonObj[TAG_NET_ID] = mNetId_; - jsonObj[TAG_REQUEST_ID] = mRequestId_; - jsonObj[TAG_GROUP_ID] = mGroupId_; - jsonObj[TAG_GROUP_NAME] = mGroupName_; - DMLOG(DM_LOG_INFO, "MsgResponseAuth encode completed"); - } - DMLOG(DM_LOG_INFO, "encode mReply_ is : %d", mReply_); - DMLOG(DM_LOG_INFO, "encode deviceId is : %s", GetAnonyString(mDeviceId_).c_str()); - DMLOG(DM_LOG_INFO, "encode netId is : %s", GetAnonyString(mNetId_).c_str()); - DMLOG(DM_LOG_INFO, "encode mGroupId_ is %s", GetAnonyString(mGroupId_).c_str()); - DMLOG(DM_LOG_INFO, "encode mGroupName_ is %s", mGroupName_.c_str()); - DMLOG(DM_LOG_INFO, "encode mRequestId_ is %d", mRequestId_); -} - -int32_t MsgResponseAuth::Decode(nlohmann::json &jsonObj) -{ - DMLOG(DM_LOG_INFO, "MsgResponseAuth decode started"); - if (!jsonObj.contains(TAG_REPLY) || !jsonObj.contains(TAG_DEVICE_ID) || !jsonObj.contains(TAG_GROUPIDS)) { - DMLOG(DM_LOG_ERROR, "MsgResponseAuth::decode, err json string, first time"); - return MSG_DECODE_PARA_FAILED; - } - - MsgHead msgHead; - mHead_ = msgHead.Decode(jsonObj); - mReply_ = jsonObj[TAG_REPLY]; - mDeviceId_ = jsonObj[TAG_DEVICE_ID]; - std::vector groupList = jsonObj[TAG_GROUPIDS]; - for (auto str : groupList) { - mSyncGroupList_.push_back(str); - } - - if (mReply_ == SESSION_REPLY_ACCEPT) { - if (!jsonObj.contains(TAG_NET_ID) || !jsonObj.contains(TAG_GROUP_ID) || !jsonObj.contains(TAG_GROUP_NAME) || - !jsonObj.contains(TAG_REQUEST_ID)) { - DMLOG(DM_LOG_ERROR, "MsgResponseAuth::decode, err json string, second time"); - return MSG_DECODE_PARA_FAILED; - } - mNetId_ = jsonObj[TAG_NET_ID]; - mGroupId_ = jsonObj[TAG_GROUP_ID]; - mGroupName_ = jsonObj[TAG_GROUP_NAME]; - mRequestId_ = jsonObj[TAG_REQUEST_ID]; - } - DMLOG(DM_LOG_INFO, "decode mReply_ is : %d", mReply_); - DMLOG(DM_LOG_INFO, "decode mGroupId_ is %s", GetAnonyString(mGroupId_).c_str()); - DMLOG(DM_LOG_INFO, "decode mGroupName_ is %s", GetAnonyString(mGroupName_).c_str()); - DMLOG(DM_LOG_INFO, "decode deviceId is : %s", GetAnonyString(mDeviceId_).c_str()); - DMLOG(DM_LOG_INFO, "decode netId is : %s", GetAnonyString(mNetId_).c_str()); - DMLOG(DM_LOG_INFO, "decode mRequestId_ is %d", mRequestId_); - DMLOG(DM_LOG_INFO, "MsgResponseAuth decode completed"); - return DEVICEMANAGER_OK; -} - -int32_t MsgResponseAuth::GetReply() -{ - return mReply_; -} - -std::string MsgResponseAuth::GetNetId() -{ - return mNetId_; -} - -std::string MsgResponseAuth::GetGroupId() -{ - return mGroupId_; -} - -std::string MsgResponseAuth::GetDeviceId() -{ - return mDeviceId_; -} - -std::string MsgResponseAuth::GetGroupName() -{ - return mGroupName_; -} - -int64_t MsgResponseAuth::GetRequestId() -{ - return mRequestId_; -} - -std::vector MsgResponseAuth::GetSyncGroupList() -{ - return mSyncGroupList_; -} - -int32_t MsgResponseAuth::GetPinCode() -{ - return mPinCode_; -} - -void MsgResponseAuth::SavePinCode(int32_t pinCode) -{ - mPinCode_ = pinCode; -} -} -} diff --git a/ext/mini/services/devicemanagerservice/src/message/msg_sync_group.cpp b/ext/mini/services/devicemanagerservice/src/message/msg_sync_group.cpp deleted file mode 100644 index a69477892055a06a248f3935ee916b16de6382a7..0000000000000000000000000000000000000000 --- a/ext/mini/services/devicemanagerservice/src/message/msg_sync_group.cpp +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (c) 2022 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 "msg_sync_group.h" -#include "device_manager_log.h" -#include "constants.h" -#include "device_manager_errno.h" - -namespace OHOS { -namespace DistributedHardware { -MsgSyncGroup::MsgSyncGroup(std::vector &groupList, std::string &deviceId) -{ - DMLOG(DM_LOG_INFO, "MsgSyncGroup construction started"); - mHead_ = std::make_shared(DmMsgType::MSG_TYPE_SYNC_GROUP); - for (auto str: groupList) { - mGroupIdList_.push_back(str); - } - mDeviceId_ = deviceId; - DMLOG(DM_LOG_INFO, "MsgSyncGroup construction completed"); -} - -void MsgSyncGroup::Encode(nlohmann::json &json) -{ - mHead_->Encode(json); - json[TAG_DEVICE_ID] = mDeviceId_; - json[TAG_GROUPIDS] = mGroupIdList_; -} - -int32_t MsgSyncGroup::Decode(nlohmann::json &json) -{ - DMLOG(DM_LOG_INFO, "MsgSyncGroup decode started"); - if (!json.contains(TAG_DEVICE_ID) || !json.contains(TAG_GROUPIDS)) { - DMLOG(DM_LOG_ERROR, "MsgSyncGroup::decode err "); - return MSG_DECODE_PARA_FAILED; - } - - MsgHead msgHead; - mHead_ = msgHead.Decode(json); - mDeviceId_ = json[TAG_DEVICE_ID]; - mGroupIdList_ = json.at(TAG_GROUPIDS).get>(); - DMLOG(DM_LOG_INFO, "MsgSyncGroup decode completed"); - return DEVICEMANAGER_OK; -} - -std::string MsgSyncGroup::GetDeviceId() -{ - return mDeviceId_; -} - -std::vector MsgSyncGroup::GetGroupIdList() -{ - return mGroupIdList_; -} -} -} \ No newline at end of file diff --git a/ext/mini/services/devicemanagerservice/src/multipleuser/multiple_user_connector.cpp b/ext/mini/services/devicemanagerservice/src/multipleuser/multiple_user_connector.cpp deleted file mode 100644 index 3374eec1e777eb0b769ed7592726a9cd9b9f9051..0000000000000000000000000000000000000000 --- a/ext/mini/services/devicemanagerservice/src/multipleuser/multiple_user_connector.cpp +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (c) 2022 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/ext/mini/services/devicemanagerservice/src/requestauth/auth_manager.cpp b/ext/mini/services/devicemanagerservice/src/requestauth/auth_manager.cpp deleted file mode 100644 index d652d0108bba9e52b8968cdfdd83529781b99881..0000000000000000000000000000000000000000 --- a/ext/mini/services/devicemanagerservice/src/requestauth/auth_manager.cpp +++ /dev/null @@ -1,297 +0,0 @@ -/* - * Copyright (c) 2022 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 "auth_manager.h" -#include "anonymous_string.h" -#include "dm_ability_manager.h" -#include "constants.h" -#include "msg_codec.h" -#include "device_manager_log.h" -#include "device_manager_errno.h" -#include "softbus_session.h" -#include "encrypt_utils.h" -#if (defined(__LINUX__) || defined(__LITEOS_A__)) -#include "ipc_server_listener_adapter.h" -#endif -#include "msg_sync_group.h" -#include "device_manager_notify.h" - -namespace OHOS { -namespace DistributedHardware { -IMPLEMENT_SINGLE_INSTANCE(AuthManager); - -void AuthManager::AuthDeviceGroup(std::string &hostPkgName, const DmDeviceInfo &devReqInfo, - const DmAppImageInfo &imageInfo, std::string &extras) -{ - AuthAppGroup(hostPkgName, devReqInfo, imageInfo, extras); -} - -void AuthManager::OnReceiveMsg(long long channelId, std::string &message) -{ - int32_t msgType = MsgCodec::DecodeMsgType(message); - DMLOG(DM_LOG_INFO, "message type is, %d", msgType); - switch (msgType) { - case MSG_TYPE_RESP_AUTH: - case MSG_TYPE_REQ_AUTH: - case MSG_TYPE_AUTH_BY_PIN: - OnReceiveMessage(channelId, message, msgType); - break; - case MSG_TYPE_SYNC_GROUP: - SyncDmPrivateGroup(message); - break; - default: - DMLOG(DM_LOG_INFO, "msgType not support yet, msgType: %d", msgType); - break; - } -} - -void AuthManager::AuthAppGroup(std::string &hostPkgName, const DmDeviceInfo &devReqInfo, - const DmAppImageInfo &imageInfo, std::string &extrasJson) -{ - DMLOG(DM_LOG_INFO, "AuthManager::AuthAppGroup started"); - nlohmann::json jsonObject = nlohmann::json::parse(extrasJson, nullptr, false); - if (jsonObject.is_discarded()) { - DMLOG(DM_LOG_ERROR, "extrasJson error"); - return; - } - if (!jsonObject.contains(AUTH_TYPE)) { - DMLOG(DM_LOG_ERROR, "AuthAppGroup extrasJson error"); - return; - } - if (!jsonObject.contains(TARGET_PKG_NAME_KEY)) { - DMLOG(DM_LOG_ERROR, "TARGET_PKG_NAME is not in extrasJson"); - return; - } - std::string targetPkgName = jsonObject[TARGET_PKG_NAME_KEY]; - - if (!jsonObject.contains(DISPLAY_OWNER)) { - DMLOG(DM_LOG_WARN, "AuthAppGroup DISPLAY_OWNER error"); - displayOwner_ = DISPLAY_OWNER_SYSTEM; - } else { - displayOwner_ = jsonObject[DISPLAY_OWNER]; - } - - if (!CanStartNewSession()) { - DMLOG(DM_LOG_ERROR, "previous session not completed yet"); - mPendingReqSessionPtr_->NotifyHostAppAuthResult(ERROR_DUPLICATE_REQUEST); - return; - } - auto curSessionPtr = std::make_shared(hostPkgName, targetPkgName, devReqInfo, imageInfo); - mPendingReqSessionPtr_ = curSessionPtr; - std::vector msgInfo = curSessionPtr->GetRequestCommand(extrasJson); - int32_t channelId = SoftbusSession::GetInstance().SendMessages(devReqInfo.deviceId, msgInfo); - if (channelId > 0) { - DMLOG(DM_LOG_INFO, "open channel succeed, save channelId"); - mPendingReqSessionPtr_->SetChannelId(channelId); - return; - } - DMLOG(DM_LOG_ERROR, "open channel failed, close this session"); - mPendingReqSessionPtr_->Release(); - mPendingReqSessionPtr_->NotifyHostAppAuthResult(ERROR_START_REMOTE_DM); - mPendingReqSessionPtr_ = nullptr; -} - -bool AuthManager::CanStartNewSession() -{ - if (mPendingReqSessionPtr_ == nullptr || mPendingReqSessionPtr_->IsFinished()) { - return true; - } - return false; -} - -void AuthManager::OnUserOperate(int32_t action) -{ - if (action == FaAction::USER_OPERATION_TYPE_CANCEL_PINCODE_INPUT) { - if (mPendingReqSessionPtr_ == nullptr) { - DMLOG(DM_LOG_ERROR, "mPendingReqSessionPtr_ not exist"); - return; - } - mPendingReqSessionPtr_->OnUserOperate(action); - return; - } - - if (mPendingRespSessionPtr == nullptr) { - DMLOG(DM_LOG_ERROR, "mPendingRespSessionPtr not exist"); - return; - } - - mPendingRespSessionPtr->OnUserOperate(action); -} - -void AuthManager::OnReceiveMessage(long long channelId, std::string &message, int32_t msgType) -{ - DMLOG(DM_LOG_INFO, "AuthManager::OnReceiveMessage started"); - if (msgType == MSG_TYPE_RESP_AUTH) { - DMLOG(DM_LOG_ERROR, "message type is MSG_TYPE_RESP_AUTH"); - if (mPendingReqSessionPtr_ == nullptr || !mPendingReqSessionPtr_->IsMyChannelId(channelId)) { - DMLOG(DM_LOG_ERROR, "receive error message"); - return; - } - mPendingReqSessionPtr_->OnReceiveMsg(message); - if (mPendingReqSessionPtr_->IsWaitingForScan()) { - DMLOG(DM_LOG_ERROR, "move Session To Wait Scan Map "); - MoveSessionToWaitScanMap(); - } - } else if (msgType == MSG_TYPE_REQ_AUTH || msgType == MSG_TYPE_AUTH_BY_PIN) { - DMLOG(DM_LOG_INFO, "message type is MSG_TYPE_REQ_AUTH"); - if (mPendingRespSessionPtr == nullptr) { - mPendingRespSessionPtr = std::make_shared(); - } - - if (!mPendingRespSessionPtr->IsMyChannelId(channelId)) { - DMLOG(DM_LOG_ERROR, "mPendingRespSessionPtr IsMyChannelId false!"); - return; - } - mPendingRespSessionPtr->OnReceiveMsg(channelId, message); - } else { - DMLOG(DM_LOG_ERROR, "error message type"); - } -} - -void AuthManager::SyncDmPrivateGroup(std::string &message) -{ - std::shared_ptr msgSyncGroupPtr = MsgCodec::DecodeSyncGroup(message); - if (msgSyncGroupPtr == nullptr) { - DMLOG(DM_LOG_ERROR, "decode syncGroup message err"); - return; - } - std::vector groupIdList = msgSyncGroupPtr->GetGroupIdList(); - HichainConnector::GetInstance().SyncGroups(msgSyncGroupPtr->GetDeviceId(), groupIdList); -} - -void AuthManager::MoveSessionToWaitScanMap() -{ - DMLOG(DM_LOG_ERROR, "AuthManager::MoveSessionToWaitScanMap"); - mWaitScanReqSessionMap_[mPendingReqSessionPtr_->GetToken()] = mPendingReqSessionPtr_; - mPendingReqSessionPtr_ = nullptr; -} - -int32_t AuthManager::CheckAuthentication(std::string &authPara) -{ - DMLOG(DM_LOG_INFO, "AuthManager::CheckAuthentication started"); - nlohmann::json authJson = nlohmann::json::parse(authPara, nullptr, false); - if (authJson.is_discarded()) { - DMLOG(DM_LOG_ERROR, "HichainAdapter::GetGroupIdByName parse group info error, json invalid."); - return AUTH_PARA_INVALID; - } - if (!authJson.contains(AUTH_TYPE) || authJson[AUTH_TYPE] != AUTH_TYPE_PIN) { - DMLOG(DM_LOG_ERROR, "error authPara msg"); - return AUTH_PARA_INVALID; - } - DMLOG(DM_LOG_INFO, "PIN Code Auth"); - authParam_ = authPara; - return CheckAuthenticationByPin(authJson); -} - -void AuthManager::NotifyHostOnCheckAuthResult(int64_t requestId, int errorCode) -{ - DMLOG(DM_LOG_INFO, "notify host checkResult, requestId: %lld, errorcode: %d", requestId, errorCode); - for (auto iter = mWaitScanReqSessionMap_.begin(); iter != mWaitScanReqSessionMap_.end(); iter++) { - auto requestSessionPtr = iter->second; - if (requestSessionPtr != nullptr && requestSessionPtr->GetRequestId() == requestId) { - std::string deviceId = requestSessionPtr->GetRequestDeviceId(); - DMLOG(DM_LOG_INFO, "notify host checkResult, deviceId: %s, requestId: %lld", - GetAnonyString(deviceId).c_str(), requestId); -#if (defined(__LINUX__) || defined(__LITEOS_A__)) - IpcServerListenerAdapter::GetInstance().OnCheckAuthResult(deviceId, errorCode, 0); -#else - std::list pkgNameList = DeviceManagerNotify::GetInstance().GetPkgNameList(); - for( auto pkgName : pkgNameList) { - DeviceManagerNotify::GetInstance().OnCheckAuthResult(pkgName, deviceId, errorCode, 0); - } -#endif - return; - } - } - - DMLOG(DM_LOG_ERROR, "notify host checkResult error, requestId: %lld", requestId); -} - -int32_t AuthManager::CheckAuthenticationByPin(nlohmann::json &authJson) -{ - int32_t pinCode = authJson.contains(PIN_CODE_KEY) ? (int32_t)authJson[PIN_CODE_KEY] : DEFAULT_PIN_CODE; - int32_t pinToken = authJson.contains(PIN_TOKEN) ? (int32_t)authJson[PIN_TOKEN] : DEFAULT_PIN_TOKEN; - if (pinCode < MIN_PIN_CODE || pinCode >= (MIN_PIN_CODE + MAX_PIN_CODE)) { - DMLOG(DM_LOG_ERROR, "pinCode err, please check pinCode"); - return PIN_CODE_CHECK_FAILED; - } - - if (pinToken < MIN_PIN_TOKEN || pinToken >= (MIN_PIN_TOKEN + MAX_PIN_TOKEN)) { - DMLOG(DM_LOG_ERROR, "pinToken err, please check pinToken."); - return PIN_TOKEN_CHECK_FAILED; - } - OnPinInputResult(pinCode, pinToken); - DMLOG(DM_LOG_INFO, "CheckAuthenticationByPin authPara end"); - return DEVICEMANAGER_OK; -} - -void AuthManager::OnPinInputResult(int32_t pinCode, int32_t pinToken) -{ - DMLOG(DM_LOG_ERROR, "AuthManager::OnPinInputResult"); - for (auto iter = mWaitScanReqSessionMap_.begin(); iter != mWaitScanReqSessionMap_.end(); iter++) { - auto requestSessionPtr = iter->second; - if (requestSessionPtr != nullptr && requestSessionPtr->IsMyPinToken(pinToken)) { - DMLOG(DM_LOG_INFO, "AuthManager:: OnPinInputResult"); - requestSessionPtr->OnReceivePinCode(pinCode); - } - } -} - -int32_t AuthManager::GetAuthenticationParam(DmAuthParam &authParam) -{ - AbilityRole role = DmAbilityManager::GetInstance().GetAbilityRole(); - DMLOG(DM_LOG_INFO, "GetAuthenticationParam:: role = %d", (int32_t)role); - if (role == AbilityRole::ABILITY_ROLE_INITIATIVE) { - if (mPendingReqSessionPtr_ == nullptr) { - DMLOG(DM_LOG_ERROR, "AuthManager:: Get Auth params FAIL : mPendingReqSessionPtr_(nullptr)"); - return FAIL; - } - authParam.authType = AUTH_TYPE_PIN; // Currently, only Support PinCode, authType not save. - authParam.direction = (int32_t)DmAbilityManager::GetInstance().GetAbilityRole(); - authParam.pinToken = mPendingReqSessionPtr_->GetPinToken(); - DMLOG(DM_LOG_INFO, "GetAuthenticationParam, role is ABILITY_ROLE_INITIATIVE"); - return SUCCESS; - } - - if (mPendingRespSessionPtr == nullptr) { - DMLOG(DM_LOG_ERROR, "AuthManager:: Get Auth params FAIL : mPendingRespSessionPtr(nullptr)"); - return FAIL; - } - - mPendingRespSessionPtr->BuildAuthenticationInfo(authParam); - return SUCCESS; -} - -int32_t AuthManager::GetPincode(int64_t requestId) -{ - if (mPendingRespSessionPtr == nullptr) { - DMLOG(DM_LOG_ERROR, "AuthManager:: GetPincode FAIL : mPendingRespSessionPtr(nullptr)"); - return FAIL; - } - - return mPendingRespSessionPtr->GetPinCodeByReqId(requestId); -} - -std::string AuthManager::GetAuthPara() -{ - return authParam_; -} - -int32_t AuthManager::GetDisplayOwner() -{ - return displayOwner_; -} -} -} diff --git a/ext/mini/services/devicemanagerservice/src/requestauth/request_session.cpp b/ext/mini/services/devicemanagerservice/src/requestauth/request_session.cpp deleted file mode 100644 index 752cd2b1ed015f47ec0a4060fd1c9ae5d9e8162e..0000000000000000000000000000000000000000 --- a/ext/mini/services/devicemanagerservice/src/requestauth/request_session.cpp +++ /dev/null @@ -1,274 +0,0 @@ -/* - * Copyright (c) 2022 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 -#include -#include "nlohmann/json.hpp" - -#include "dm_ability_manager.h" -#include "request_session.h" -#include "constants.h" -#include "device_manager_log.h" -#include "msg_codec.h" -#include "device_manager_errno.h" -#if (defined(__LINUX__) || defined(__LITEOS_A__)) -#include "ipc_server_adapter.h" -#include "ipc_server_listener_adapter.h" -#endif -#include "encrypt_utils.h" -#include "softbus_adapter.h" -#include "hichain_connector.h" -#include "softbus_session.h" -#include "device_manager_notify.h" - -namespace OHOS { -namespace DistributedHardware { -RequestSession::RequestSession(std::string &hostPkgName, std::string &targetPkgName, const DmDeviceInfo &devReqInfo, - const DmAppImageInfo &imageInfo) -{ - DMLOG(DM_LOG_INFO, "RequestSession construction started"); - mDevInfo_ = devReqInfo; - mImageInfo_ = imageInfo; - mHostPkgName_ = hostPkgName; - mTargetPkgName = targetPkgName; -#if (defined(__LINUX__) || defined(__LITEOS_A__)) - mPinToken_ = IpcServerAdapter::GenRandInt(MIN_PIN_TOKEN, MAX_PIN_TOKEN); -#else - mPinToken_ = MIN_PIN_TOKEN + random() % (MAX_PIN_TOKEN - MIN_PIN_TOKEN); -#endif - char randStr[TOKEN_LEN] = {0}; - bool res = EncryptUtils::MbedtlsGenRandomStr(randStr, sizeof(randStr), false); - if (res == false) { - DMLOG(DM_LOG_ERROR, "get Random string failed"); - mToken_ = ""; - return; - } - mToken_ = randStr; - DMLOG(DM_LOG_INFO, "RequestSession construction completed"); -} - -std::vector RequestSession::GetRequestCommand(std::string &extrasJson) -{ - return MsgCodec::EncodeReqAppAuth(mToken_, mHostPkgName_, mTargetPkgName, mDevInfo_, mImageInfo_, extrasJson); -} - -int32_t RequestSession::GetPinToken() -{ - return mPinToken_; -} - -bool RequestSession::IsWaitingForScan() -{ - return mStatus_ == StatusType::STATUS_WATING_SCAN_OR_INPUT; -} - -std::string RequestSession::GetToken() -{ - return mToken_; -} - -bool RequestSession::IsMyPinToken(int32_t pinToken) -{ - return pinToken == mPinToken_; -} - -void RequestSession::OnReceivePinCode(int32_t pinCode) -{ - if (mStatus_ != StatusType::STATUS_WATING_SCAN_OR_INPUT) { - DMLOG(DM_LOG_ERROR, "mStatus_ is incorrect, mStatus_: %d", mStatus_); - return; - } - - DMLOG(DM_LOG_INFO, "RequestSession::OnReceivePinCode"); - responseMsgPtr_->SavePinCode(pinCode); - HichainConnector::GetInstance().AddMemeber(mDevInfo_.deviceId, responseMsgPtr_); - mStatus_ = StatusType::STATUS_WAITING_ADD_GROUP; -} - -void RequestSession::OnUserOperate(int32_t action) -{ - if (action == FaAction::USER_OPERATION_TYPE_CANCEL_PINCODE_INPUT) { - Release(); - return; - } -} - -int64_t RequestSession::GetRequestId() -{ - return mRequestId_; -} - -std::string RequestSession::GetRequestDeviceId() -{ - return mRemoteDeviceId_; -} - -int32_t RequestSession::StartFaService() -{ - DMLOG(DM_LOG_INFO, "RequestSession::StartFaService in"); - AbilityStatus status = DmAbilityManager::GetInstance().StartAbility(AbilityRole::ABILITY_ROLE_INITIATIVE); - if (status != AbilityStatus::ABILITY_STATUS_SUCCESS) { - DMLOG(DM_LOG_ERROR, "RequestSession::StartFaService timeout"); - return FAIL; - } - return SUCCESS; -} - -bool RequestSession::IsFinished() -{ - if (mStatus_ == StatusType::STATUS_INIT || mStatus_ == StatusType::STATUS_FINISH) { - return true; - } - return false; -} - -bool RequestSession::IsMyChannelId(long long channelId) -{ - return channelId == mChannelId_; -} - -void RequestSession::OnReceiveMsg(std::string &msg) -{ - if (mStatus_ != StatusType::STATUS_WAITING_REPLY) { - DMLOG(DM_LOG_ERROR, "StatusType is not waiting reply"); - return; - } - int32_t reply = ParseRespMsg(msg); - DMLOG(DM_LOG_INFO, "reply is : %d", reply); - if (reply == SESSION_REPLY_ACCEPT) { - mStatus_ = StatusType::STATUS_WATING_SCAN_OR_INPUT; - CloseChannel(); - } else { - Release(); - } - NotifyHostAppAuthResult(reply); -} - -std::string RequestSession::GetHostPkgName() -{ - return mHostPkgName_; -} - -std::string RequestSession::GetTargetPkgName() -{ - return mTargetPkgName; -} - -int32_t RequestSession::GetSessionType() -{ - return mSessionType_; -} - -void RequestSession::Release() -{ - if (mStatus_ == StatusType::STATUS_FINISH || mStatus_ == StatusType::STATUS_INIT) { - DMLOG(DM_LOG_INFO, "session is already closed"); - return; - } - DMLOG(DM_LOG_INFO, "close this session"); - mStatus_ = StatusType::STATUS_FINISH; - CloseChannel(); -} - -void RequestSession::CloseChannel() -{ - if (mIsChannelOpened_) { - SoftbusSession::GetInstance().CloseSession(mChannelId_); - DMLOG(DM_LOG_ERROR, "RequestSession:: close the channel"); - mIsChannelOpened_ = false; - } -} - -int32_t RequestSession::ParseRespMsg(std::string &msg) -{ - DMLOG(DM_LOG_INFO, "ParseRespMsg started"); - auto msgResponseAuthPtr = MsgCodec::DecodeResponseAuth(msg); - if (msgResponseAuthPtr == nullptr) { - DMLOG(DM_LOG_ERROR, "DecodeResponseAuth error"); - return SESSION_REPLY_UNKNOWN; - } - responseMsgPtr_ = msgResponseAuthPtr; - int32_t reply = msgResponseAuthPtr->GetReply(); - mRemoteDeviceId_ = msgResponseAuthPtr->GetDeviceId(); - if (reply == SESSION_REPLY_ACCEPT) { - mRemoteNetId_ = msgResponseAuthPtr->GetNetId(); - mRemoteGroupId_ = msgResponseAuthPtr->GetGroupId(); - mRemoteGroupName_ = msgResponseAuthPtr->GetGroupName(); - mRequestId_ = msgResponseAuthPtr->GetRequestId(); - - auto remoteGroupList = msgResponseAuthPtr->GetSyncGroupList(); - SyncDmPrivateGroup(remoteGroupList); - DMLOG(DM_LOG_INFO, "user accepted the auth"); - } - DMLOG(DM_LOG_INFO, "ParseRespMsg completed"); - return reply; -} - -void RequestSession::SetChannelId(long long channelId) -{ - mChannelId_ = channelId; - mIsChannelOpened_ = true; - mStatus_ = StatusType::STATUS_WAITING_REPLY; -} - -void RequestSession::SyncDmPrivateGroup(std::vector &remoteGroupList) -{ - HichainConnector::GetInstance().SyncGroups(mRemoteDeviceId_, remoteGroupList); - DMLOG(DM_LOG_INFO, "RequestSession::syncDmPrivateGroup started"); - std::vector localGroups = {}; - std::vector groupList = {}; - - HichainConnector::GetInstance().GetRelatedGroups(mRemoteDeviceId_, groupList); - HichainConnector::GetInstance().GetSyncGroupList(groupList, localGroups); - if (mRemoteGroupId_ != "") { - localGroups.push_back(mRemoteGroupId_); - } - - std::string synGroupMsg = MsgCodec::EncodeSyncGroup(localGroups, mRemoteDeviceId_); - SoftbusSession::GetInstance().SendMsg(mChannelId_, synGroupMsg); - DMLOG(DM_LOG_INFO, "RequestSession::SyncDmPrivateGroup completed"); -} - -void RequestSession::NotifyHostAppAuthResult(int32_t errorCode) -{ - if (mSessionType_ != SESSION_TYPE_IS_APP_AUTH) { - DMLOG(DM_LOG_ERROR, "wrong session type: %d", mSessionType_); - return; - } - - std::string deviceId = mDevInfo_.deviceId; - if (errorCode != SESSION_REPLY_ACCEPT) { -#if (defined(__LINUX__) || defined(__LITEOS_A__)) - IpcServerListenerAdapter::GetInstance().OnAuthResult(mHostPkgName_, deviceId, mPinToken_, FAIL, errorCode); -#else - DeviceManagerNotify::GetInstance().OnAuthResult(mHostPkgName_, deviceId, mPinToken_, FAIL, errorCode); -#endif - DMLOG(DM_LOG_INFO, "notify host result, errorcode: %d", errorCode); - return; - } - - if (StartFaService() != SUCCESS) { - DMLOG(DM_LOG_INFO, "RequestSession::StartFaService failed"); - return; - } - DMLOG(DM_LOG_INFO, "RequestSession::StartFaService success"); -#if (defined(__LINUX__) || defined(__LITEOS_A__)) - IpcServerListenerAdapter::GetInstance().OnAuthResult(mHostPkgName_, deviceId, mPinToken_, SUCCESS, errorCode); -#else - DeviceManagerNotify::GetInstance().OnAuthResult(mHostPkgName_, deviceId, mPinToken_, SUCCESS, errorCode); -#endif -} -} -} diff --git a/ext/mini/services/devicemanagerservice/src/requestauth/response_session.cpp b/ext/mini/services/devicemanagerservice/src/requestauth/response_session.cpp deleted file mode 100644 index f909026867e26dd4bf4b9a3a99c16bace5a0a4c8..0000000000000000000000000000000000000000 --- a/ext/mini/services/devicemanagerservice/src/requestauth/response_session.cpp +++ /dev/null @@ -1,349 +0,0 @@ -/* - * Copyright (c) 2022 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 -#include "nlohmann/json.hpp" - -#include "parameter.h" - -#include "dm_ability_manager.h" -#include "response_session.h" -#include "constants.h" -#include "msg_codec.h" -#include "device_manager_log.h" -#include "device_manager_errno.h" -#include "encrypt_utils.h" -#if (defined(__LINUX__) || defined(__LITEOS_A__)) -#include "ipc_server_adapter.h" -#include "ipc_server_listener_adapter.h" -#endif -#include "softbus_adapter.h" -#include "softbus_session.h" -#include "hichain_connector.h" -#include "pthread.h" -#include "dm_device_info.h" -#include "device_manager_notify.h" - -namespace OHOS { -namespace DistributedHardware { -namespace { -const int32_t SESSION_CANCEL_TIMEOUT = 0; -const int32_t SESSION_MSG_RECEIVE_TIMEOUT = 5; -const int32_t SESSION_WAIT_MEMBER_JOIN_TIMEOUT = 120; -const int32_t CANCEL_PICODE_DISPLAY = 1; -const int32_t DEVICE_ID_HALF = 2; -} - -ResponseSession::ResponseSession() -{ - mSessionStatus_ = ResponseSessionStatus::SESSION_INIT; - sem_init(&mSem_, 0, 0); - mRequestId_ = -1; - mGroupId_ = ""; - mGroupName_ = ""; - mReqDeviceId_ = ""; - mMsgRequestAuthPtr_ = nullptr; - mChannelId_ = -1; - mPincode_ = -1; -} - -int64_t ResponseSession::GetRequestId() -{ - return mRequestId_; -} - -int32_t ResponseSession::SendResponseMessage(int32_t reply) -{ - DMLOG(DM_LOG_INFO, "ResponseSession::SendResponseMessage in, reply:%d", reply); - std::string msg; - if (reply == SESSION_REPLY_ACCEPT) { - msg = MsgCodec::EncodeAcceptRespAuth(reply, mRequestId_, mGroupId_, mGroupName_, mReqDeviceId_); - } else { - msg = MsgCodec::EncodeRefuseRespAuth(reply, mReqDeviceId_); - } - - int32_t ret = SoftbusSession::GetInstance().SendMsg(mChannelId_, msg); - if (ret != SUCCESS) { - DMLOG(DM_LOG_INFO, "SendResponseMessage failed ret:%d, reply:%d", ret, reply); - return ret; - } - DMLOG(DM_LOG_INFO, "SendResponseMessage successed, reply:%d", reply); - return SUCCESS; -} - -void ResponseSession::OnUserOperate(int32_t action) -{ - switch (action) { - case FaAction::USER_OPERATION_TYPE_ALLOW_AUTH: { - OnUserConfirm(); - break; - } - case FaAction::USER_OPERATION_TYPE_CANCEL_AUTH: { - OnUserReject(ERROR_USER_REJECT); - break; - } - case FaAction::USER_OPERATION_TYPE_AUTH_CONFIRM_TIMEOUT: { - OnUserReject(SESSION_REPLY_AUTH_CONFIRM_TIMEOUT); - break; - } - case FaAction::USER_OPERATION_TYPE_CANCEL_PINCODE_DISPLAY: { - DMLOG(DM_LOG_ERROR, "cancel pincode display"); - Release(); - break; - } - default: { - DMLOG(DM_LOG_ERROR, "action %d not support", action); - break; - } - } -} - -int32_t ResponseSession::DecodeReqMsg(std::string &message) -{ - std::shared_ptr authMsg = MsgCodec::DecodeRequestAuth(message, mMsgRequestAuthPtr_); - if (authMsg == nullptr) { - DMLOG(DM_LOG_ERROR, "DecodeRequestAuth error, authMsg(nullptr)"); - return FAIL; - } - - if (authMsg->GetMsgSlice() == FAIL) { - DMLOG(DM_LOG_ERROR, "DecodeRequestAuth error, GetMsgSlice() FAIL"); - return FAIL; - } - - mMsgRequestAuthPtr_ = authMsg; - return SUCCESS; -} - -bool ResponseSession::IsMyChannelId(long long channelId) -{ - if (mSessionStatus_ == ResponseSessionStatus::SESSION_INIT) { - return true; - } - - return channelId == mChannelId_ && mChannelId_ > 0; -} - -void OnReceiveTimeOut(void *data) -{ - DMLOG(DM_LOG_ERROR, "OnReceiveTimeOut TimeOut called"); - ResponseSession *respSess = (ResponseSession*)data; - if (respSess == nullptr || respSess->GetStatus() == ResponseSessionStatus::SESSION_INIT) { - DMLOG(DM_LOG_ERROR, "respSess Status is INIT"); - return; - } - - respSess->Release(); -} - -void OnMemberJoinTimeOut(void *data) -{ - DMLOG(DM_LOG_ERROR, "OnMemberJoinTimeOut TimeOut caled"); - ResponseSession *respSess = (ResponseSession*)data; - if (respSess == nullptr || respSess->GetStatus() == ResponseSessionStatus::SESSION_INIT) { - DMLOG(DM_LOG_ERROR, "respSess Status is INIT"); - return; - } - - respSess->SendResponseMessage(SESSION_REPLY_TIMEOUT); - respSess->CancelDisplay(); - respSess->Release(); -} - -void ResponseSession::OnReceiveMsg(long long channelId, std::string &message) -{ - int32_t ret = DecodeReqMsg(message); - if (ret != SUCCESS) { - DMLOG(DM_LOG_ERROR, "DecodeReqMsg failed"); - return; - } - - if (!mReceiveTimerPtr_) { - std::string mReceiveTimerName = "mReceiveTimer"; - mReceiveTimerPtr_ = std::make_shared(mReceiveTimerName); - } - - mReceiveTimerPtr_->Start(SESSION_MSG_RECEIVE_TIMEOUT, OnReceiveTimeOut, this); - if (mMsgRequestAuthPtr_->GetMsgCnt() != mMsgRequestAuthPtr_->GetMsgSlice()) { - return; - } - - mReceiveTimerPtr_->Stop(SESSION_CANCEL_TIMEOUT); - mReqDeviceId_ = mMsgRequestAuthPtr_->GetRequestDeviceId(); - mChannelId_ = channelId; - mPincode_ = GeneratePincode(); - if (StartFaService() != SUCCESS) { - OnUserReject(ERROR_FA_START_FAIL); - return; - } - - mSessionStatus_ = ResponseSessionStatus::SESSION_WAITTING_USER_CONFIRM; - if (!mMemberJoinTimerPtr_) { - std::string mMemberJoinTimerName = "mMemberJoinTimer"; - mMemberJoinTimerPtr_ = std::make_shared(mMemberJoinTimerName); - } - - mMemberJoinTimerPtr_->Start(SESSION_WAIT_MEMBER_JOIN_TIMEOUT, OnMemberJoinTimeOut, this); -} - -int32_t ResponseSession::GetPinCodeByReqId(int64_t requestId) -{ - if (requestId != mRequestId_) { - DMLOG(DM_LOG_ERROR, "ResponseSession:: GetPinCodeByReqId FAIL : requestId(not match)"); - return FAIL; - } - return mPincode_; -} - -void ResponseSession::BuildAuthenticationInfo(DmAuthParam &authParam) -{ - DMLOG(DM_LOG_INFO, "ResponseSession::BuildAuthenticationInfo in"); - authParam.direction = (int32_t)DmAbilityManager::GetInstance().GetAbilityRole(); - if (mMsgRequestAuthPtr_ == nullptr) { - DMLOG(DM_LOG_ERROR, "ResponseSession::BuildAuthenticationInfo mMsgRequestAuthPtr_ is nullptr"); - return; - } - - authParam.packageName = mMsgRequestAuthPtr_->mTargetPkg_; - authParam.appName = mMsgRequestAuthPtr_->mAppName_; - authParam.appDescription = mMsgRequestAuthPtr_->mAppDescription_; - authParam.authType = mMsgRequestAuthPtr_->mAuthType_; - authParam.business = BUSINESS_FA_MIRGRATION; // currently, only support BUSINESS_FA_MIRGRATION - authParam.pincode = mPincode_; - - if (mMsgRequestAuthPtr_ != nullptr) { - authParam.imageinfo = mMsgRequestAuthPtr_->mImageInfo_; - } -} - -int32_t ResponseSession::StartFaService() -{ - DMLOG(DM_LOG_INFO, "ResponseSession::StartFaService in"); - AbilityStatus status = DmAbilityManager::GetInstance().StartAbility(AbilityRole::ABILITY_ROLE_PASSIVE); - if (status != AbilityStatus::ABILITY_STATUS_SUCCESS) { - DMLOG(DM_LOG_ERROR, "ResponseSession::StartFaService timeout"); - return FAIL; - } - return SUCCESS; -} - -void ResponseSession::OnGroupCreated(int64_t requestId, const std::string &groupId) -{ - DMLOG(DM_LOG_INFO, "ResponseSession OnGroupCreated in requestId= %lld groupId = %s ", requestId, groupId.c_str()); - - if (requestId != mRequestId_ || groupId.length() == 0) { - DMLOG(DM_LOG_ERROR, "ResponseSession::OnGroupCreated failed, requestId %lld, requestId %lld, groupId %s", - requestId, mRequestId_, groupId.c_str()); - SendResponseMessage(SESSION_REPLY_CREAT_GROUP_FAILED); - CancelDisplay(); - mSessionStatus_ = ResponseSessionStatus::SESSION_INIT; - return; - } - - // save requestId for peer to join, need to be checked in HiChain OnRequest and OnFinish(AddMemberToGroup) callback - mRequestId_ = HichainConnector::GetInstance().GenRequestId(); - mGroupId_ = groupId; - int32_t ret = SendResponseMessage(SESSION_REPLY_ACCEPT); - if (ret != SUCCESS) { - CancelDisplay(); - mSessionStatus_ = ResponseSessionStatus::SESSION_INIT; - return; - } - - DMLOG(DM_LOG_INFO, "Send Accept Resoponse success, wait for peer to AddMemberToGroup"); - mSessionStatus_ = ResponseSessionStatus::SESSION_WAITTING_PIN_CODE; -} - -void ResponseSession::OnMemberJoin(int64_t requestId, int32_t status) -{ - DMLOG(DM_LOG_INFO, "ResponseSession::OnMemberJoin, result: %d", status); - CancelDisplay(); - mMemberJoinTimerPtr_->Stop(SESSION_CANCEL_TIMEOUT); - Release(); -} - -std::string ResponseSession::GenerateGroupName() -{ - char localDeviceId[DEVICE_UUID_LENGTH] = {0}; - GetDevUdid(localDeviceId, DEVICE_UUID_LENGTH); - std::string sLocalDeviceID = localDeviceId; - std::string groupName = mMsgRequestAuthPtr_->mTargetPkg_ + mMsgRequestAuthPtr_->mHostPkg_ + - sLocalDeviceID.substr(0, sLocalDeviceID.size() / DEVICE_ID_HALF); - return groupName; -} - -void ResponseSession::OnUserConfirm() -{ - DMLOG(DM_LOG_INFO, "ResponseSession::OnUserConfirm in"); - mGroupName_ = GenerateGroupName(); - HichainConnector::GetInstance().RegisterConnectorCallback(shared_from_this()); - - // save requestId for CreateGroup, need to be checked in callback: OnGroupCreated - mRequestId_ = HichainConnector::GetInstance().GenRequestId(); - int32_t ret = HichainConnector::GetInstance().CreateGroup(mRequestId_, mGroupName_); - if (ret != SUCCESS) { - CancelDisplay(); - mSessionStatus_ = ResponseSessionStatus::SESSION_INIT; - return; - } - mSessionStatus_ = ResponseSessionStatus::SESSION_WAITTING_GROUP_CREATED; -} - -void ResponseSession::OnUserReject(int32_t errorCode) -{ - DMLOG(DM_LOG_INFO, "ResponseSession::OnUserReject in, errcode %d", errorCode); - SendResponseMessage(errorCode); - Release(); -} - -void ResponseSession::Release() -{ - DMLOG(DM_LOG_INFO, "ResponseSession::Release in"); - mSessionStatus_ = ResponseSessionStatus::SESSION_INIT; - mRequestId_ = -1; - mGroupId_ = ""; - mGroupName_ = ""; - mReqDeviceId_ = ""; - mMsgRequestAuthPtr_ = nullptr; - mChannelId_ = -1; - mPincode_ = -1; -} - -void ResponseSession::CancelDisplay() -{ - DMLOG(DM_LOG_INFO, "Cancel PinCode Display in"); - nlohmann::json jsonObj; - jsonObj[CANCEL_DISPLAY_KEY] = CANCEL_PICODE_DISPLAY; - std::string paramJson = jsonObj.dump(); - std::string pkgName = "com.ohos.devicemanagerui"; -#if (defined(__LINUX__) || defined(__LITEOS_A__)) - IpcServerListenerAdapter::GetInstance().OnFaCall(pkgName, paramJson); -#else - DeviceManagerNotify::GetInstance().OnFaCall(pkgName, paramJson); -#endif - DMLOG(DM_LOG_INFO, "Cancel PinCode Display success"); -} - -int32_t ResponseSession::GetStatus() -{ - return mSessionStatus_; -} - -int32_t ResponseSession::GeneratePincode() -{ - return EncryptUtils::GenRandInt(MIN_PIN_CODE, MAX_PIN_CODE); -} -} // namespace DistributedHardware -} // namespace OHOS diff --git a/ext/mini/services/devicemanagerservice/src/softbus/softbus_adapter.cpp b/ext/mini/services/devicemanagerservice/src/softbus/softbus_adapter.cpp deleted file mode 100644 index 277e5f508df8b3c72ece17d78e8ab22163854e08..0000000000000000000000000000000000000000 --- a/ext/mini/services/devicemanagerservice/src/softbus/softbus_adapter.cpp +++ /dev/null @@ -1,569 +0,0 @@ -/* - * Copyright (c) 2022 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 "softbus_adapter.h" - -#include -#include -#include -#include -#include - -#include "softbus_bus_center.h" - -#include "dm_device_info.h" -#include "dm_subscribe_info.h" - -#include "anonymous_string.h" -#include "device_manager_errno.h" -#include "device_manager_log.h" -#include "softbus_session.h" -#if (defined(__LINUX__) || defined(__LITEOS_A__)) -#include "ipc_server_listener_adapter.h" -#endif -#include "device_manager_notify.h" - -#define DISTRIBUTED_HARDWARE_DEVICEMANAGER_SA_ID 4802 -namespace OHOS { -namespace DistributedHardware { -namespace { -const std::string DEVICE_MANAGER_PACKAGE_NAME = "ohos.distributedhardware.devicemanager"; -const char *DM_CAPABILITY_OSD = "osdCapability"; -const int32_t CHECK_INTERVAL = 100000; // 100ms -const uint32_t SUBSCRIBE_ID_PREFIX_LEN = 16; -const int32_t SUBSCRIBE_ID_MASK = 0x0000FFFF; -const int32_t DISCOVER_DEVICEINFO_MAX_SIZE = 20; -} -std::map>> - SoftbusAdapter::subscribeInfos_; -std::map> SoftbusAdapter::discoverDeviceInfoMap_; -std::vector> SoftbusAdapter::discoverDeviceInfoVector_; -uint16_t SoftbusAdapter::subscribeIdPrefix = 0; -// std::mutex SoftbusAdapter::lock_; -INodeStateCb SoftbusAdapter::softbusNodeStateCb_ = { - .events = EVENT_NODE_STATE_ONLINE | EVENT_NODE_STATE_OFFLINE | EVENT_NODE_STATE_INFO_CHANGED, - .onNodeOnline = OnSoftBusDeviceOnline, - .onNodeOffline = OnSoftbusDeviceOffline, - .onNodeBasicInfoChanged = OnSoftbusDeviceInfoChanged -}; -IDiscoveryCallback SoftbusAdapter::softbusDiscoverCallback_ = { - .OnDeviceFound = OnSoftbusDeviceFound, - .OnDiscoverFailed = OnSoftbusDiscoverFailed, - .OnDiscoverySuccess = OnSoftbusDiscoverySuccess -}; -IPublishCallback SoftbusAdapter::servicePublishCallback_ = { - .OnPublishSuccess = PublishServiceCallBack::OnPublishSuccess, - .OnPublishFail = PublishServiceCallBack::OnPublishFail -}; - -void SoftbusAdapter::RemoveDiscoverDeviceInfo(const std::string deviceId) -{ - discoverDeviceInfoMap_.erase(deviceId); - auto iter = discoverDeviceInfoVector_.begin(); - while (iter != discoverDeviceInfoVector_.end()) { - if (strcmp(iter->get()->devId, deviceId.c_str()) == 0) { - iter = discoverDeviceInfoVector_.erase(iter); - } else { - ++iter; - } - } -} - -void SoftbusAdapter::OnDeviceStateChange(DmDeviceState state, DmDeviceInfo &deviceInfo) -{ - std::list pkgNameList = DeviceManagerNotify::GetInstance().GetPkgNameList(); - for( auto pkgName : pkgNameList) { - DmDeviceState deviceState = static_cast(state); - if (pkgName == "") { - DMLOG(DM_LOG_ERROR, "OnDeviceOnline, get para failed"); - return; - } - switch (deviceState) { - case DEVICE_STATE_ONLINE: - DeviceManagerNotify::GetInstance().OnDeviceOnline(pkgName, deviceInfo); - break; - case DEVICE_STATE_OFFLINE: - DeviceManagerNotify::GetInstance().OnDeviceOffline(pkgName, deviceInfo); - break; - case DEVICE_INFO_CHANGED: - DeviceManagerNotify::GetInstance().OnDeviceChanged(pkgName, deviceInfo); - break; - default: - DMLOG(DM_LOG_ERROR, "unknown device state:%d", deviceState); - break; - } - } -} - -void SoftbusAdapter::OnSoftBusDeviceOnline(NodeBasicInfo *info) -{ - if (info == nullptr) { - DMLOG(DM_LOG_ERROR, "OnSoftBusDeviceOnline NodeBasicInfo is nullptr"); - return; - } - DmDeviceInfo dmDeviceInfo; - - NodeBasicInfoCopyToDmDevice(dmDeviceInfo, *info); -#if (defined(__LINUX__) || defined(__LITEOS_A__)) - IpcServerListenerAdapter::GetInstance().OnDeviceStateChange(DmDeviceState::DEVICE_STATE_ONLINE, dmDeviceInfo); -#else - OnDeviceStateChange(DmDeviceState::DEVICE_STATE_ONLINE, dmDeviceInfo); -#endif - uint8_t udid[UDID_BUF_LEN] = {0}; - int32_t ret = GetNodeKeyInfo(DEVICE_MANAGER_PACKAGE_NAME.c_str(), info->networkId, - NodeDeviceInfoKey::NODE_KEY_UDID, udid, sizeof(udid)); - if (ret != DEVICEMANAGER_OK) { - DMLOG(DM_LOG_ERROR, "GetNodeKeyInfo failed"); - return; - } - std::string deviceId = (char *)udid; - DMLOG(DM_LOG_INFO, "device online, deviceId: %s", GetAnonyString(deviceId).c_str()); - RemoveDiscoverDeviceInfo(deviceId); -} - -void SoftbusAdapter::OnSoftbusDeviceOffline(NodeBasicInfo *info) -{ - if (info == nullptr) { - DMLOG(DM_LOG_ERROR, "OnSoftbusDeviceOffline NodeBasicInfo is nullptr"); - return; - } - DmDeviceInfo dmDeviceInfo; - - NodeBasicInfoCopyToDmDevice(dmDeviceInfo, *info); -#if (defined(__LINUX__) || defined(__LITEOS_A__)) - IpcServerListenerAdapter::GetInstance().OnDeviceStateChange(DmDeviceState::DEVICE_STATE_OFFLINE, dmDeviceInfo); -#else - OnDeviceStateChange(DmDeviceState::DEVICE_STATE_OFFLINE, dmDeviceInfo); -#endif -} - -void SoftbusAdapter::OnSoftbusDeviceInfoChanged(NodeBasicInfoType type, NodeBasicInfo *info) -{ - DMLOG(DM_LOG_INFO, "OnSoftbusDeviceInfoChanged."); - // currently do nothing - (void)type; - (void)info; -} - -void SoftbusAdapter::SaveDiscoverDeviceInfo(const DeviceInfo *deviceInfo) -{ - std::shared_ptr info = std::make_shared(); - DeviceInfo *infoPtr = info.get(); - if (memcpy_s(infoPtr, sizeof(DeviceInfo), deviceInfo, sizeof(DeviceInfo)) != 0) { - DMLOG(DM_LOG_ERROR, "SoftbusAdapter::SaveDiscoverDeviceInfo failed."); - return; - } - - std::string deviceId = deviceInfo->devId; - discoverDeviceInfoMap_[deviceId] = info; - discoverDeviceInfoVector_.push_back(info); - - // Remove the earliest element when reached the max size - if (discoverDeviceInfoVector_.size() == DISCOVER_DEVICEINFO_MAX_SIZE) { - auto iter = discoverDeviceInfoVector_.begin(); - std::string delDevId = iter->get()->devId; - discoverDeviceInfoMap_.erase(delDevId); - discoverDeviceInfoVector_.erase(iter); - } -} - -void SoftbusAdapter::OnSoftbusDeviceFound(const DeviceInfo *device) -{ - if (device == nullptr) { - DMLOG(DM_LOG_ERROR, "deviceinfo is null"); - return; - } - - std::string deviceId = device->devId; - DMLOG(DM_LOG_INFO, "SoftbusAdapter::OnSoftbusDeviceFound device %s found.", GetAnonyString(deviceId).c_str()); - if (IsDeviceOnLine(deviceId)) { - return; - } - - SaveDiscoverDeviceInfo(device); - for (auto iter = subscribeInfos_.begin(); iter != subscribeInfos_.end(); ++iter) { - auto subInfovector = iter->second; - for (auto vectorIter = subInfovector.begin(); vectorIter != subInfovector.end(); ++vectorIter) { - auto info = vectorIter->get(); - DMLOG(DM_LOG_INFO, "subscribe info capability:%s.", info->info.capability); - if (strcmp(DM_CAPABILITY_OSD, info->info.capability) != 0) { - DMLOG(DM_LOG_ERROR, "subscribe info capability invalid."); - } - uint16_t originId = (uint16_t)(((uint32_t)info->info.subscribeId) & SUBSCRIBE_ID_MASK); - std::string strPkgName = iter->first; - DmDeviceInfo dmDeviceInfo; - - DeviceInfoCopyToDmDevice(dmDeviceInfo, *device); -#if (defined(__LINUX__) || defined(__LITEOS_A__)) - IpcServerListenerAdapter::GetInstance().OnDeviceFound(strPkgName, originId, dmDeviceInfo); -#else - DeviceManagerNotify::GetInstance().OnDeviceFound(strPkgName, originId, dmDeviceInfo); -#endif - } - } -} - -bool SoftbusAdapter::GetpkgNameBySubscribeId(int32_t adapterId, std::string &pkgName) -{ - for (auto iter = subscribeInfos_.begin(); iter != subscribeInfos_.end(); ++iter) { - std::vector> &subinfoVector = iter->second; - auto vectorIter = subinfoVector.begin(); - for (; vectorIter != subinfoVector.end(); ++vectorIter) { - if (vectorIter->get()->info.subscribeId == adapterId) { - pkgName = iter->first; - return true; - } - } - } - return false; -} - -void SoftbusAdapter::OnSoftbusDiscoverFailed(int subscribeId, DiscoveryFailReason failReason) -{ - DMLOG(DM_LOG_INFO, "In, subscribeId %d, failReason %d", subscribeId, (int32_t)failReason); - std::string pkgName; - if (!GetpkgNameBySubscribeId(subscribeId, pkgName)) { - DMLOG(DM_LOG_ERROR, "OnSoftbusDiscoverFailed: pkgName not found"); - return; - } - - uint16_t originId = (uint16_t)(((uint32_t)subscribeId) & SUBSCRIBE_ID_MASK); -#if (defined(__LINUX__) || defined(__LITEOS_A__)) - IpcServerListenerAdapter::GetInstance().OnDiscoverFailed(pkgName, originId, failReason); -#else - DeviceManagerNotify::GetInstance().OnDiscoverFailed(pkgName, originId, failReason); -#endif -} - -void SoftbusAdapter::OnSoftbusDiscoverySuccess(int subscribeId) -{ - DMLOG(DM_LOG_INFO, "In, subscribeId %d", subscribeId); - std::string pkgName; - if (!GetpkgNameBySubscribeId(subscribeId, pkgName)) { - DMLOG(DM_LOG_ERROR, "OnSoftbusDiscoverySuccess: pkgName not found"); - return; - } - uint16_t originId = (uint16_t)(((uint32_t)subscribeId) & SUBSCRIBE_ID_MASK); -#if (defined(__LINUX__) || defined(__LITEOS_A__)) - IpcServerListenerAdapter::GetInstance().OnDiscoverySuccess(pkgName, originId); -#else - DeviceManagerNotify::GetInstance().OnDiscoverySuccess(pkgName, originId); -#endif -} - -bool SoftbusAdapter::GetsubscribeIdAdapter(std::string &pkgName, int16_t originId, int32_t &adapterId) -{ - DMLOG(DM_LOG_INFO, "GetsubscribeIdAdapter in, pkgName: %s, originId:%d", pkgName.c_str(), - (int32_t)originId); - auto iter = subscribeInfos_.find(pkgName); - if (iter == subscribeInfos_.end()) { - DMLOG(DM_LOG_ERROR, "subscribeInfo not find for pkgName: %s", pkgName.c_str()); - return false; - } - - std::vector> &subinfoVector = iter->second; - auto vectorIter = subinfoVector.begin(); - for (; vectorIter != subinfoVector.end(); ++vectorIter) { - if (vectorIter->get()->subscribeIdOrigin == originId) { - DMLOG(DM_LOG_ERROR, "find adapterId:%d for pkgName: %s, originId:%d", - vectorIter->get()->info.subscribeId, pkgName.c_str(), (int32_t)originId); - adapterId = vectorIter->get()->info.subscribeId; - return true; - } - } - DMLOG(DM_LOG_ERROR, "subscribe not find. pkgName: %s, originId:%d", pkgName.c_str(), (int32_t)originId); - return false; -} - -int32_t SoftbusAdapter::Init() -{ - int32_t ret; - int32_t retryTimes = 0; - do { - ret = RegNodeDeviceStateCb(DEVICE_MANAGER_PACKAGE_NAME.c_str(), &softbusNodeStateCb_); - if (ret != DEVICEMANAGER_OK) { - ++retryTimes; - DMLOG(DM_LOG_ERROR, "RegNodeDeviceStateCb failed with ret %d, retryTimes %d", ret, retryTimes); - usleep(CHECK_INTERVAL); - } - } while (ret != DEVICEMANAGER_OK); - DMLOG(DM_LOG_INFO, "RegNodeDeviceStateCb success."); - SoftbusSession::GetInstance().Start(); - - PublishInfo dmPublishInfo; - dmPublishInfo.publishId = DISTRIBUTED_HARDWARE_DEVICEMANAGER_SA_ID; - dmPublishInfo.mode = DiscoverMode::DISCOVER_MODE_ACTIVE; - dmPublishInfo.medium = ExchanageMedium::AUTO; - dmPublishInfo.freq = ExchangeFreq::HIGH; - dmPublishInfo.capability = DM_CAPABILITY_OSD; - dmPublishInfo.capabilityData = nullptr; - dmPublishInfo.dataLen = 0; - ret = PublishService(DEVICE_MANAGER_PACKAGE_NAME.c_str(), &dmPublishInfo, &servicePublishCallback_); - DMLOG(DM_LOG_INFO, "service publish result is : %d", ret); - return ret; -} - -int32_t SoftbusAdapter::GetTrustDevices(const std::string &pkgName, NodeBasicInfo **info, int32_t *infoNum) -{ - DMLOG(DM_LOG_INFO, "DM_GetSoftbusTrustDevices start, pkgName: %s", pkgName.c_str()); - int32_t ret = GetAllNodeDeviceInfo(DEVICE_MANAGER_PACKAGE_NAME.c_str(), info, infoNum); - if (ret != 0) { - DMLOG(DM_LOG_ERROR, "GetAllNodeDeviceInfo failed with ret %d", ret); - return ret; - } - DMLOG(DM_LOG_INFO, "success, pkgName: %s, deviceCount %d", pkgName.c_str(), *infoNum); - return DEVICEMANAGER_OK; -} - -int32_t SoftbusAdapter::StartDiscovery(std::string &pkgName, SubscribeInfo *info) -{ - std::shared_ptr subinfo = nullptr; - if (subscribeInfos_.find(pkgName) == subscribeInfos_.end()) { - subscribeInfos_[pkgName] = {}; - } - - auto iter = subscribeInfos_.find(pkgName); - std::vector> &subinfoVector = iter->second; - auto vectorIter = subinfoVector.begin(); - for (; vectorIter != subinfoVector.end(); ++vectorIter) { - if (vectorIter->get()->subscribeIdOrigin == info->subscribeId) { - subinfo = *vectorIter; - break; - } - } - if (subinfo == nullptr) { - // std::lock_guard autoLock(lock_); - subinfo = std::make_shared(); - subinfo->subscribeIdOrigin = info->subscribeId; - subinfo->subscribeIdPrefix = subscribeIdPrefix++; - subinfo->info = *info; - - uint32_t uSubscribeId = static_cast(info->subscribeId); - uSubscribeId = (subinfo->subscribeIdPrefix << SUBSCRIBE_ID_PREFIX_LEN) | uSubscribeId; - subinfo->info.subscribeId = static_cast(uSubscribeId); - } - if (vectorIter == subinfoVector.end()) { - subinfoVector.push_back(subinfo); - } - DMLOG(DM_LOG_INFO, "StartDiscovery, pkgName: %s, subscribeId %d, prefix %d, origin %d", - pkgName.c_str(), subinfo->info.subscribeId, subinfo->subscribeIdPrefix, subinfo->subscribeIdOrigin); - DMLOG(DM_LOG_INFO, "Capability: %s", subinfo->info.capability); - int32_t ret = ::StartDiscovery(DEVICE_MANAGER_PACKAGE_NAME.c_str(), &subinfo->info, &softbusDiscoverCallback_); - if (ret != 0) { - DMLOG(DM_LOG_ERROR, "StartDiscovery failed with ret %d.", ret); - return DEVICEMANAGER_DISCOVERY_FAILED; - } - return DEVICEMANAGER_OK; -} - -int32_t SoftbusAdapter::StopDiscovery(std::string &pkgName, uint16_t subscribeId) -{ - int32_t subscribeIdAdapter = -1; - if (!GetsubscribeIdAdapter(pkgName, subscribeId, subscribeIdAdapter)) { - DMLOG(DM_LOG_ERROR, "StopDiscovery failed, subscribeId not match"); - return DEVICEMANAGER_FAILED; - } - - DMLOG(DM_LOG_INFO, "StopDiscovery begin, pkgName: %s, subscribeId:%d, subscribeIdAdapter:%d", - pkgName.c_str(), (int32_t)subscribeId, subscribeIdAdapter); - int32_t ret = ::StopDiscovery(DEVICE_MANAGER_PACKAGE_NAME.c_str(), subscribeIdAdapter); - if (ret != 0) { - DMLOG(DM_LOG_ERROR, "StopDiscovery failed with ret %d", ret); - return ret; - } - - auto iter = subscribeInfos_.find(pkgName); - auto subinfoVector = iter->second; - auto vectorIter = subinfoVector.begin(); - while (vectorIter != subinfoVector.end()) { - if (vectorIter->get()->subscribeIdOrigin == subscribeId) { - vectorIter = subinfoVector.erase(vectorIter); - break; - } else { - ++vectorIter; - } - } - if (subinfoVector.empty()) { - subscribeInfos_.erase(pkgName); - } - DMLOG(DM_LOG_INFO, "DM_StopSoftbusDiscovery completed, pkgName: %s", pkgName.c_str()); - return DEVICEMANAGER_OK; -} - -bool SoftbusAdapter::IsDeviceOnLine(std::string &deviceId) -{ - NodeBasicInfo *info = nullptr; - int32_t infoNum = 0; - - if (GetTrustDevices(DEVICE_MANAGER_PACKAGE_NAME.c_str(), &info, &infoNum) != DEVICEMANAGER_OK) { - DMLOG(DM_LOG_ERROR, "DM_IsDeviceOnLine DM_GetSoftbusTrustDevices failed"); - return false; - } - - bool bDeviceOnline = false; - for (int32_t i = 0; i < infoNum; ++i) { - NodeBasicInfo *nodeBasicInfo = info + i; - if (nodeBasicInfo == nullptr) { - DMLOG(DM_LOG_ERROR, "nodeBasicInfo is empty for index %d, infoNum %d.", i, infoNum); - continue; - } - std::string networkId = nodeBasicInfo->networkId; - if (networkId == deviceId) { - DMLOG(DM_LOG_INFO, "DM_IsDeviceOnLine device %s online", GetAnonyString(deviceId).c_str()); - bDeviceOnline = true; - break; - } - uint8_t udid[UDID_BUF_LEN] = {0}; - int32_t ret = GetNodeKeyInfo(DEVICE_MANAGER_PACKAGE_NAME.c_str(), networkId.c_str(), - NodeDeviceInfoKey::NODE_KEY_UDID, udid, sizeof(udid)); - if (ret != DEVICEMANAGER_OK) { - DMLOG(DM_LOG_ERROR, "DM_IsDeviceOnLine GetNodeKeyInfo failed"); - break; - } - - if (strcmp((char *)udid, deviceId.c_str()) == 0) { - DMLOG(DM_LOG_INFO, "DM_IsDeviceOnLine devccie %s online", GetAnonyString(deviceId).c_str()); - bDeviceOnline = true; - break; - } - } - FreeNodeInfo(info); - return bDeviceOnline; -} - -int32_t SoftbusAdapter::GetConnectionIpAddr(std::string deviceId, std::string &ipAddr) -{ - auto iter = discoverDeviceInfoMap_.find(deviceId); - if (iter == discoverDeviceInfoMap_.end()) { - DMLOG(DM_LOG_ERROR, "deviceInfo not found by deviceId %s", GetAnonyString(deviceId).c_str()); - return DEVICEMANAGER_FAILED; - } - - DeviceInfo *deviceInfo = iter->second.get(); - if (deviceInfo->addrNum <= 0 || deviceInfo->addrNum >= CONNECTION_ADDR_MAX) { - DMLOG(DM_LOG_ERROR, "deviceInfo addrNum not valid, addrNum %d", deviceInfo->addrNum); - return DEVICEMANAGER_FAILED; - } - - for (uint32_t i = 0; i < deviceInfo->addrNum; ++i) { - // currently, only support CONNECT_ADDR_WLAN - if (deviceInfo->addr[i].type != ConnectionAddrType::CONNECTION_ADDR_WLAN && - deviceInfo->addr[i].type != ConnectionAddrType::CONNECTION_ADDR_ETH) { - continue; - } - ipAddr = deviceInfo->addr[i].info.ip.ip; - DMLOG(DM_LOG_INFO, "DM_GetConnectionIpAddr get ip ok."); - return DEVICEMANAGER_OK; - } - DMLOG(DM_LOG_ERROR, "failed to get ipAddr for deviceId %s", GetAnonyString(deviceId).c_str()); - return DEVICEMANAGER_FAILED; -} - -// eth >> wlan >> ble >> br -ConnectionAddr *SoftbusAdapter::GetConnectAddrByType(DeviceInfo *deviceInfo, ConnectionAddrType type) -{ - if (deviceInfo == nullptr) { - return nullptr; - } - for (uint32_t i = 0; i < deviceInfo->addrNum; ++i) { - if (deviceInfo->addr[i].type == type) { - return &deviceInfo->addr[i]; - } - } - return nullptr; -} - -ConnectionAddr *SoftbusAdapter::GetConnectAddr(std::string deviceId) -{ - auto iter = discoverDeviceInfoMap_.find(deviceId); - if (iter == discoverDeviceInfoMap_.end()) { - DMLOG(DM_LOG_ERROR, "deviceInfo not found by deviceId %s", GetAnonyString(deviceId).c_str()); - return nullptr; - } - - DeviceInfo *deviceInfo = iter->second.get(); - if (deviceInfo->addrNum <= 0 || deviceInfo->addrNum >= CONNECTION_ADDR_MAX) { - DMLOG(DM_LOG_ERROR, "deviceInfo addrNum not valid, addrNum %d", deviceInfo->addrNum); - return nullptr; - } - - ConnectionAddr *addr = nullptr; - addr = GetConnectAddrByType(deviceInfo, ConnectionAddrType::CONNECTION_ADDR_ETH); - if (addr != nullptr) { - DMLOG(DM_LOG_INFO, "get ETH ConnectionAddr for deviceId %s", GetAnonyString(deviceId).c_str()); - return addr; - } - - addr = GetConnectAddrByType(deviceInfo, ConnectionAddrType::CONNECTION_ADDR_WLAN); - if (addr != nullptr) { - DMLOG(DM_LOG_INFO, "get WLAN ConnectionAddr for deviceId %s", GetAnonyString(deviceId).c_str()); - return addr; - } - - addr = GetConnectAddrByType(deviceInfo, ConnectionAddrType::CONNECTION_ADDR_BLE); - if (addr != nullptr) { - DMLOG(DM_LOG_INFO, "get BLE ConnectionAddr for deviceId %s", GetAnonyString(deviceId).c_str()); - return addr; - } - - addr = GetConnectAddrByType(deviceInfo, ConnectionAddrType::CONNECTION_ADDR_BR); - if (addr != nullptr) { - DMLOG(DM_LOG_INFO, "get BR ConnectionAddr for deviceId %s", GetAnonyString(deviceId).c_str()); - return addr; - } - - DMLOG(DM_LOG_ERROR, "failed to get ConnectionAddr for deviceId %s", GetAnonyString(deviceId).c_str()); - return nullptr; -} - -void SoftbusAdapter::NodeBasicInfoCopyToDmDevice(DmDeviceInfo &dmDeviceInfo, NodeBasicInfo &nodeBasicInfo) -{ - (void)memset_s(&dmDeviceInfo, sizeof(DmDeviceInfo), 0, sizeof(DmDeviceInfo)); - if (memcpy_s(dmDeviceInfo.deviceId, sizeof(dmDeviceInfo.deviceId), nodeBasicInfo.networkId, - std::min(sizeof(dmDeviceInfo.deviceId), sizeof(nodeBasicInfo.networkId))) != DEVICEMANAGER_OK) { - DMLOG(DM_LOG_ERROR, "memcpy failed"); - } - if (memcpy_s(dmDeviceInfo.deviceName, sizeof(dmDeviceInfo.deviceName), nodeBasicInfo.deviceName, - std::min(sizeof(dmDeviceInfo.deviceName), sizeof(nodeBasicInfo.deviceName))) != DEVICEMANAGER_OK) { - DMLOG(DM_LOG_ERROR, "memcpy failed"); - } - dmDeviceInfo.deviceTypeId = (DMDeviceType)nodeBasicInfo.deviceTypeId; -} - -void SoftbusAdapter::DeviceInfoCopyToDmDevice(DmDeviceInfo &dmDeviceInfo, const DeviceInfo &deviceInfo) -{ - (void)memset_s(&dmDeviceInfo, sizeof(DmDeviceInfo), 0, sizeof(DmDeviceInfo)); - if (memcpy_s(dmDeviceInfo.deviceId, sizeof(dmDeviceInfo.deviceId), deviceInfo.devId, - std::min(sizeof(dmDeviceInfo.deviceId), sizeof(deviceInfo.devId))) != DEVICEMANAGER_OK) { - DMLOG(DM_LOG_ERROR, "memcpy failed"); - } - if (memcpy_s(dmDeviceInfo.deviceName, sizeof(dmDeviceInfo.deviceName), deviceInfo.devName, - std::min(sizeof(dmDeviceInfo.deviceName), sizeof(deviceInfo.devName))) != DEVICEMANAGER_OK) { - DMLOG(DM_LOG_ERROR, "memcpy failed"); - } - dmDeviceInfo.deviceTypeId = (DMDeviceType)deviceInfo.devType; -} - -void PublishServiceCallBack::OnPublishSuccess(int publishId) -{ - DMLOG(DM_LOG_INFO, "service publish succeed, publishId: %d", publishId); -} - -void PublishServiceCallBack::OnPublishFail(int publishId, PublishFailReason reason) -{ - DMLOG(DM_LOG_INFO, "service publish failed, publishId: %d, reason: %d", publishId, reason); -} -} // namespace DistributedHardware -} // namespace OHOS \ No newline at end of file diff --git a/ext/mini/services/devicemanagerservice/src/softbus/softbus_session.cpp b/ext/mini/services/devicemanagerservice/src/softbus/softbus_session.cpp deleted file mode 100644 index 7e2e051ac4837e8a9216fbc4926299029c81ca1e..0000000000000000000000000000000000000000 --- a/ext/mini/services/devicemanagerservice/src/softbus/softbus_session.cpp +++ /dev/null @@ -1,230 +0,0 @@ -/* - * Copyright (c) 2022 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 "softbus_session.h" -#include "softbus_adapter.h" -#include "anonymous_string.h" -#include "device_manager_log.h" -#include "device_manager_errno.h" -#include "auth_manager.h" -#include "encrypt_utils.h" -#include "constants.h" -#include "session.h" -#include "inner_session.h" - -namespace OHOS { -namespace DistributedHardware { -static int SessionOpened(int sessionId, int result) -{ - return SoftbusSession::GetInstance().OnSessionOpened(sessionId, result); -} - -static void SessionClosed(int sessionId) -{ - SoftbusSession::GetInstance().OnSessionClosed(sessionId); -} - -static void BytesReceived(int sessionId, const void *data, unsigned int dataLen) -{ - SoftbusSession::GetInstance().GetInstance().OnBytesReceived(sessionId, data, dataLen); -} - -static void MessageReceived(int sessionId, const void *data, unsigned int dataLen) -{ - (void)sessionId; - (void)data; - (void)dataLen; - DMLOG(DM_LOG_INFO, "sessionId:%d, dataLen:%d", sessionId, dataLen); -} - -static void StreamReceived(int sessionId, const StreamData *data, const StreamData *ext, const StreamFrameInfo *param) -{ - (void)sessionId; - (void)data; - (void)ext; - (void)param; - DMLOG(DM_LOG_INFO, "sessionId:%d", sessionId); -} - -IMPLEMENT_SINGLE_INSTANCE(SoftbusSession); - -SoftbusSession::~SoftbusSession() -{ - (void)RemoveSessionServer(PKG_NAME, SESSION_NAME); -} - -int32_t SoftbusSession::Start() -{ - DMLOG(DM_LOG_INFO, "SoftbusSession start"); - ISessionListener iSessionListener = { - .OnSessionOpened = SessionOpened, - .OnSessionClosed = SessionClosed, - .OnBytesReceived = BytesReceived, - .OnMessageReceived = MessageReceived, - .OnStreamReceived = StreamReceived - }; - int32_t ret = CreateSessionServer(PKG_NAME, SESSION_NAME, &iSessionListener); - if (ret != DEVICEMANAGER_OK) { - DMLOG(DM_LOG_DEBUG, "CreateSessionServer failed"); - return DEVICEMANAGER_CREATE_SESSION_SERVER_FAILED; - } - return DEVICEMANAGER_OK; -} - -int SoftbusSession::OnSessionOpened(int sessionId, int result) -{ - if (result != DEVICEMANAGER_OK) { - DMLOG(DM_LOG_INFO, "session open failed, sessionId %d", sessionId); - if (sessionIdSet_.count(sessionId) > 0) { - sessionIdSet_.erase(sessionId); - messages_.clear(); - } - return DEVICEMANAGER_OK; - } - - int32_t sessionSide = GetSessionSide(sessionId); - DMLOG(DM_LOG_INFO, "session open succeed, sessionId %d, sessionSide %d", sessionId, sessionSide); - if (sessionSide == AUTH_SESSION_SIDE_CLIENT) { - for (auto msg : messages_) { - int32_t ret = SendMsg(sessionId, msg); - if (ret != DEVICEMANAGER_OK) { - DMLOG(DM_LOG_INFO, "send message failed"); - return ret; - } - } - } else { - sessionIdSet_.insert(sessionId); - } - return DEVICEMANAGER_OK; -} - -void SoftbusSession::OnSessionClosed(int sessionId) -{ - DMLOG(DM_LOG_INFO, "OnSessionClosed, sessionId:%d", sessionId); - if (sessionIdSet_.count(sessionId) > 0) { - sessionIdSet_.erase(sessionId); - } -} - -void SoftbusSession::OnBytesReceived(int sessionId, const void *data, int dataLen) -{ - DMLOG(DM_LOG_INFO, "OnBytesReceived, sessionId:%d, dataLen:%d", sessionId, dataLen); - if (sessionId < 0 || data == nullptr || dataLen <= 0) { - DMLOG(DM_LOG_INFO, "OnBytesReceived param check failed"); - return; - } - - uint8_t *buf = (uint8_t *)calloc(sizeof(uint8_t), dataLen + 1); - if (buf == nullptr) { - DMLOG(DM_LOG_ERROR, "SendMsg: malloc memory failed"); - return; - } - - int32_t outLen = 0; - int32_t ret = EncryptUtils::MbedtlsDecrypt((const uint8_t*)data, dataLen, buf, dataLen, &outLen); - if (ret != DEVICEMANAGER_OK || outLen > (int32_t)dataLen) { - DMLOG(DM_LOG_ERROR, "MbedtlsDecrypt data failed"); - free(buf); - return; - } - - std::string message = (char *)buf; - AuthManager::GetInstance().OnReceiveMsg(sessionId, message); - free(buf); - DMLOG(DM_LOG_INFO, "OnBytesReceived completed"); - return; -} - -void SoftbusSession::CloseSession(int32_t sessionId) -{ - DMLOG(DM_LOG_INFO, "CloseSession in"); - ::CloseSession(sessionId); -} - -int32_t SoftbusSession::SendData(int32_t sessionId, const void *data, int32_t len) -{ - DMLOG(DM_LOG_INFO, "in, datalen:%d", len); - int32_t ret = DEVICEMANAGER_FAILED; - if (sessionIdSet_.count(sessionId) > 0) { - ret = SendBytes(sessionId, data, len); - if (ret != DEVICEMANAGER_OK) { - return DEVICEMANAGER_FAILED; - } - } else { - DMLOG(DM_LOG_INFO, "in, datalen:%d", len); - } - return ret; -} - -// send message by sessionId (channel opened) -int32_t SoftbusSession::SendMsg(int32_t sessionId, std::string &message) -{ - DMLOG(DM_LOG_ERROR, "start SendMsg"); - uint8_t *buf = (uint8_t *)calloc(sizeof(uint8_t), (MSG_MAX_SIZE + ENCRYPT_TAG_LEN)); - if (buf == nullptr) { - DMLOG(DM_LOG_ERROR, "SendMsg: malloc memory failed"); - return DEVICEMANAGER_MALLOC_ERROR; - } - int32_t outLen = 0; - int32_t ret = EncryptUtils::MbedtlsEncrypt((const uint8_t *)message.c_str(), message.size(), buf, MSG_MAX_SIZE, - &outLen); - if (ret != DEVICEMANAGER_OK || outLen > MSG_MAX_SIZE) { - DMLOG(DM_LOG_ERROR, "MbedtlsEncrypt data failed"); - free(buf); - return ENCRYPT_UTILS_AES_GCM_ENCRYPT_FAILED; - } - ret = SendData(sessionId, buf, outLen); - free(buf); - return ret; -} - -// send message while the channel is not opend -int32_t SoftbusSession::SendMessages(const char *deviceId, std::vector &message) -{ - DMLOG(DM_LOG_ERROR, "open channel and start SendMsg"); - int32_t sessionId = -1; - messages_ = message; - ConnectionAddr *addrInfo = SoftbusAdapter::GetConnectAddr(deviceId); - if (addrInfo == nullptr) { - DMLOG(DM_LOG_ERROR, "GetConnectAddr error"); - return sessionId; - } - - sessionId = ::OpenAuthSession(SESSION_NAME, addrInfo, 1, nullptr); - if (sessionId < 0) { - DMLOG(DM_LOG_ERROR, "open session error, ret:%d", sessionId); - return sessionId; - } - sessionIdSet_.insert(sessionId); - DMLOG(DM_LOG_INFO, "opened auth session is:%d", sessionId); - return sessionId; -} - -void SoftbusSession::GetPeerDeviceId(int32_t sessionId, std::string &peerDevId) -{ - char peerDeviceId[DEVICE_UUID_LENGTH] = {0}; - int32_t ret = ::GetPeerDeviceId(sessionId, &peerDeviceId[0], DEVICE_UUID_LENGTH); - if (ret == 0) { - peerDevId = peerDeviceId; - DMLOG(DM_LOG_INFO, "GetPeerDeviceId success for session:%d, peerDeviceId:%s", sessionId, - GetAnonyString(peerDevId).c_str()); - return; - } - - DMLOG(DM_LOG_ERROR, "GetPeerDeviceId failed for session:%d", sessionId); - peerDevId = ""; -} -} // namespace DistributedHardware -} // namespace OHOS diff --git a/ext/mini/services/devicemanagerservice/src/timer/dm_timer.cpp b/ext/mini/services/devicemanagerservice/src/timer/dm_timer.cpp deleted file mode 100644 index e899e3580798df5ed18b78546a6983f16a74ce5b..0000000000000000000000000000000000000000 --- a/ext/mini/services/devicemanagerservice/src/timer/dm_timer.cpp +++ /dev/null @@ -1,109 +0,0 @@ -/* - * Copyright (c) 2022 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 "securec.h" - -namespace OHOS { -namespace DistributedHardware { -namespace { -const int32_t MILL_SECONDS_PER_SECOND = 1000; -} -DmTimer::DmTimer(std::string &name) -{ - mStatus_ = DmTimerStatus::DM_STATUS_INIT; - mTimeOutSec_ = 0; - mHandle_ = nullptr; - mHandleData_ = nullptr; - (void)memset_s(mTimeFd_, sizeof(mTimeFd_), 0, sizeof(mTimeFd_)); - mEpFd_ = 0; - mTimerName_ = name; -} - -DmTimer::~DmTimer() -{ - DMLOG(DM_LOG_INFO, "DmTimer %s Destroy in", mTimerName_.c_str()); - Release(); -} - -DmTimerStatus DmTimer::Start(uint32_t timeOut, TimeoutHandle handle, void *data) -{ - DMLOG(DM_LOG_INFO, "DmTimer %s start timeout(%d)", mTimerName_.c_str(), timeOut); - if (mStatus_ != DmTimerStatus::DM_STATUS_INIT) { - return DmTimerStatus::DM_STATUS_BUSY; - } - - mTimeOutSec_ = timeOut; - mHandle_ = handle; - mHandleData_ = data; - - if (CreateTimeFd()) { - return DmTimerStatus::DM_STATUS_CREATE_ERROR; - } - - mStatus_ = DmTimerStatus::DM_STATUS_RUNNING; - - return mStatus_; -} - -void DmTimer::Stop(int32_t code) -{ - DMLOG(DM_LOG_INFO, "DmTimer %s Stop code (%d)", mTimerName_.c_str(), code); - if (mTimeFd_[1]) { - char event = 'S'; - if (write(mTimeFd_[1], &event, 1) < 0) { - DMLOG(DM_LOG_ERROR, "DmTimer %s Stop timer failed, errno %d", mTimerName_.c_str(), errno); - return; - } - DMLOG(DM_LOG_INFO, "DmTimer %s Stop success", mTimerName_.c_str()); - } - - return; -} - -void DmTimer::WiteforTimeout() -{ - DMLOG(DM_LOG_INFO, "DmTimer %s start timer at (%d)s", mTimerName_.c_str(), mTimeOutSec_); - mHandle_(mHandleData_); - Release(); - - DMLOG(DM_LOG_ERROR, "DmTimer %s end timer at (%d)s", mTimerName_.c_str(), mTimeOutSec_); - return; -} - -int32_t DmTimer::CreateTimeFd() -{ - DMLOG(DM_LOG_INFO, "DmTimer %s creatTimeFd", mTimerName_.c_str()); - return 0; -} - -void DmTimer::Release() -{ - if (mStatus_ == DmTimerStatus::DM_STATUS_INIT) { - DMLOG(DM_LOG_INFO, "DmTimer %s already Release", mTimerName_.c_str()); - return; - } - mStatus_ = DmTimerStatus::DM_STATUS_INIT; - close(mTimeFd_[0]); - close(mTimeFd_[1]); - if (mEpFd_ >= 0) { - close(mEpFd_); - } - mTimeFd_[0] = 0; - mTimeFd_[1] = 0; - mEpFd_ = 0; -} -} -} diff --git a/ext/mini/test/BUILD.gn b/ext/mini/test/BUILD.gn deleted file mode 100644 index cca74222a8f6b4b03d892c2c0fd78b853d976ce2..0000000000000000000000000000000000000000 --- a/ext/mini/test/BUILD.gn +++ /dev/null @@ -1,18 +0,0 @@ -# Copyright (c) 2022 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. - -group("test") { - testonly = true - - deps = [ "unittest:unittest" ] -} diff --git a/ext/mini/test/unittest/BUILD.gn b/ext/mini/test/unittest/BUILD.gn deleted file mode 100644 index cdc538f71a337de23b4b8284a45c1c2329684f57..0000000000000000000000000000000000000000 --- a/ext/mini/test/unittest/BUILD.gn +++ /dev/null @@ -1,78 +0,0 @@ -# Copyright (c) 2022 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. - -import("//build/test.gni") -import("//foundation/distributedhardware/devicemanager/devicemanager.gni") -module_out_path = "deviceManager_stander/inner_kits" - -group("unittest") { - testonly = true - - deps = [ ":device_manager_impl_test" ] -} - -## UnitTest device_manager_impl_test {{{ -ohos_unittest("device_manager_impl_test") { - module_out_path = module_out_path - - sources = [ "device_manager_impl_test.cpp" ] - - deps = [ ":device_manager_test_common" ] -} - -## UnitTest device_manager_impl_test }}} - -## Build device_manager_test_common.a {{{ -config("device_manager_test_common_public_config") { - include_dirs = [ - "//utils/native/base/include", - "//utils/system/safwk/native/include", - "//foundation/distributedhardware/devicemanager/interfaces/inner_kits/native_cpp/include", - "//foundation/distributedhardware/devicemanager/interfaces/inner_kits/native_cpp/include/ipc/standard", - "//foundation/distributedhardware/devicemanager/interfaces/inner_kits/native_cpp/include/ipc", - "//foundation/distributedhardware/devicemanager/interfaces/inner_kits/native_cpp/include/notify", - "${utils_path}/include/log", - "${common_path}/include/ipc", - "${common_path}/include/ipc/model", - "${utils_path}/include/ipc/standard", - "${common_path}/include", - "//third_party/json/include", - ] - - cflags = [ - "-Wall", - "-Werror", - "-g3", - "-Dprivate=public", - "-Dprotected=public", - ] -} - -ohos_static_library("device_manager_test_common") { - testonly = true - - visibility = [ ":*" ] - - public_configs = [ ":device_manager_test_common_public_config" ] - - public_deps = [ - "${utils_path}:devicemanagerutils", - "//foundation/communication/ipc/interfaces/innerkits/ipc_core:ipc_core", - "//foundation/distributedhardware/devicemanager/interfaces/inner_kits/native_cpp:devicemanagersdk", - "//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", - "//third_party/googletest:gmock", - "//utils/native/base:utils", - "//utils/native/base:utils", - ] -} -## Build device_manager_test_common.a }}} diff --git a/ext/mini/test/unittest/device_manager_impl_test.cpp b/ext/mini/test/unittest/device_manager_impl_test.cpp deleted file mode 100644 index 789f2b2d3593059b88db57949d4dcd1f2b7e6e38..0000000000000000000000000000000000000000 --- a/ext/mini/test/unittest/device_manager_impl_test.cpp +++ /dev/null @@ -1,186 +0,0 @@ -/* - * Copyright (c) 2022 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_impl_test.h" -#include "device_manager_errno.h" -#include "dm_device_info.h" - -#include - -namespace OHOS { -namespace DistributedHardware { -void DeviceManagerImplTest::SetUp() -{ -} - -void DeviceManagerImplTest::TearDown() -{ -} - -void DeviceManagerImplTest::SetUpTestCase() -{ -} - -void DeviceManagerImplTest::TearDownTestCase() -{ -} - -namespace { -HWTEST_F(DeviceManagerImplTest, InitDeviceManager, testing::ext::TestSize.Level0) -{ - std::string packName = ""; - int32_t ret= DeviceManager::GetInstance().InitDeviceManager(packName, nullptr); - ASSERT_EQ(ret, DEVICEMANAGER_INVALID_VALUE); -} - -HWTEST_F(DeviceManagerImplTest, AuthenticateDevice1, testing::ext::TestSize.Level0) -{ - std::string packName = ""; - DmDeviceInfo dmDeviceInfo; - DmAppImageInfo dmAppImageInfo; - std::string extra= ""; - std::shared_ptr callback = nullptr; - int32_t ret= DeviceManager::GetInstance().AuthenticateDevice(packName, dmDeviceInfo, - dmAppImageInfo, extra, callback); - ASSERT_EQ(ret, DEVICEMANAGER_INVALID_VALUE); -} - -HWTEST_F(DeviceManagerImplTest, AuthenticateDevice2, testing::ext::TestSize.Level0) -{ - std::string packName = "com.ohos.helloworld"; - DmDeviceInfo dmDeviceInfo; - DmAppImageInfo dmAppImageInfo; - std::string extra = ""; - std::shared_ptr callback = nullptr; - std::shared_ptr mockInstance = std::make_shared(); - DeviceManagerImpl::GetInstance().ipcClientProxy_ = mockInstance; - EXPECT_CALL(*mockInstance, SendRequest(testing::_, testing::_, testing::_)) - .Times(1).WillOnce(testing::Return(DEVICEMANAGER_FAILED)); - int32_t ret= DeviceManager::GetInstance().AuthenticateDevice(packName, dmDeviceInfo, - dmAppImageInfo, extra, callback); - ASSERT_EQ(ret, DEVICEMANAGER_IPC_FAILED); - DeviceManagerImpl::GetInstance().ipcClientProxy_ = nullptr; -} - -HWTEST_F(DeviceManagerImplTest, AuthenticateDevice3, testing::ext::TestSize.Level0) -{ - std::string packName = "com.ohos.helloworld"; - DmDeviceInfo dmDeviceInfo; - DmAppImageInfo dmAppImageInfo; - std::string extra = ""; - std::shared_ptr callback = nullptr; - std::shared_ptr mockInstance = std::make_shared(); - DeviceManagerImpl::GetInstance().ipcClientProxy_ = mockInstance; - EXPECT_CALL(*mockInstance, SendRequest(testing::_, testing::_, testing::_)) - .Times(1).WillOnce(testing::Return(DEVICEMANAGER_OK)); - int32_t ret= DeviceManager::GetInstance().AuthenticateDevice(packName, dmDeviceInfo, - dmAppImageInfo, extra, callback); - ASSERT_EQ(ret, DEVICEMANAGER_OK); - DeviceManagerImpl::GetInstance().ipcClientProxy_ = nullptr; -} - -HWTEST_F(DeviceManagerImplTest, CheckAuthentication1, testing::ext::TestSize.Level0) -{ - std::string packName = ""; - std::string authPara = ""; - std::shared_ptr callback = nullptr; - int32_t ret = DeviceManager::GetInstance().CheckAuthentication(packName, authPara, callback); - ASSERT_EQ(ret, DEVICEMANAGER_INVALID_VALUE); -} - -HWTEST_F(DeviceManagerImplTest, CheckAuthentication2, testing::ext::TestSize.Level0) -{ - std::string packName = "com.ohos.helloworld"; - std::string authPara = ""; - std::shared_ptr callback = nullptr; - std::shared_ptr mockInstance = std::make_shared(); - DeviceManagerImpl::GetInstance().ipcClientProxy_ = mockInstance; - EXPECT_CALL(*mockInstance, SendRequest(testing::_, testing::_, testing::_)) - .Times(1).WillOnce(testing::Return(DEVICEMANAGER_FAILED)); - int32_t ret= DeviceManager::GetInstance().CheckAuthentication(packName, authPara, callback); - ASSERT_EQ(ret, DEVICEMANAGER_IPC_FAILED); - DeviceManagerImpl::GetInstance().ipcClientProxy_ = nullptr; -} - -HWTEST_F(DeviceManagerImplTest, CheckAuthentication3, testing::ext::TestSize.Level0) -{ - std::string packName = "com.ohos.helloworld"; - std::string authPara = ""; - std::shared_ptr callback = nullptr; - std::shared_ptr mockInstance = std::make_shared(); - DeviceManagerImpl::GetInstance().ipcClientProxy_ = mockInstance; - EXPECT_CALL(*mockInstance, SendRequest(testing::_, testing::_, testing::_)) - .Times(1).WillOnce(testing::Return(DEVICEMANAGER_OK)); - int32_t ret= DeviceManager::GetInstance().CheckAuthentication(packName, authPara, callback); - ASSERT_EQ(ret, DEVICEMANAGER_OK); - DeviceManagerImpl::GetInstance().ipcClientProxy_ = nullptr; -} - -HWTEST_F(DeviceManagerImplTest, StartDeviceDiscovery1, testing::ext::TestSize.Level0) -{ - std::string packName = ""; - DmSubscribeInfo subscribeInfo; - std::shared_ptr callback = nullptr; - int32_t ret = DeviceManager::GetInstance().StartDeviceDiscovery(packName, subscribeInfo, callback); - ASSERT_EQ(ret, DEVICEMANAGER_INVALID_VALUE); -} - -HWTEST_F(DeviceManagerImplTest, StartDeviceDiscovery2, testing::ext::TestSize.Level0) -{ - std::string packName = "com.ohos.helloworld"; - DmSubscribeInfo subscribeInfo; - test_callback_ = std::make_shared(); - std::shared_ptr mockInstance = std::make_shared(); - DeviceManagerImpl::GetInstance().ipcClientProxy_ = mockInstance; - EXPECT_CALL(*mockInstance, SendRequest(testing::_, testing::_, testing::_)) - .Times(1).WillOnce(testing::Return(DEVICEMANAGER_OK)); - int32_t ret = DeviceManager::GetInstance().StartDeviceDiscovery(packName, subscribeInfo, test_callback_); - ASSERT_EQ(ret, DEVICEMANAGER_OK); - DeviceManagerImpl::GetInstance().ipcClientProxy_ = nullptr; -} - -HWTEST_F(DeviceManagerImplTest, StartDeviceDiscovery3, testing::ext::TestSize.Level0) -{ - std::string packName = "com.ohos.helloworld"; - DmSubscribeInfo subscribeInfo; - test_callback_ = std::make_shared(); - std::shared_ptr mockInstance = std::make_shared(); - DeviceManagerImpl::GetInstance().ipcClientProxy_ = mockInstance; - EXPECT_CALL(*mockInstance, SendRequest(testing::_, testing::_, testing::_)) - .Times(1).WillOnce(testing::Return(DEVICEMANAGER_FAILED)); - int32_t ret = DeviceManager::GetInstance().StartDeviceDiscovery(packName, subscribeInfo, test_callback_); - ASSERT_EQ(ret, DEVICEMANAGER_IPC_FAILED); - DeviceManagerImpl::GetInstance().ipcClientProxy_ = nullptr; -} -} // namespace - -void DeviceDiscoverCallback::OnDiscoverySuccess(uint16_t subscribeId) -{ - (void)subscribeId; -} - -void DeviceDiscoverCallback::OnDiscoverFailed(uint16_t subscribeId, int32_t failedReason) -{ - (void)subscribeId; - (void)failedReason; -} - -void DeviceDiscoverCallback::OnDeviceFound(uint16_t subscribeId, const DmDeviceInfo &deviceInfo) -{ - (void)subscribeId; - (void)deviceInfo; -} -} // namespace Vsync -} // namespace OHOS diff --git a/ext/mini/test/unittest/device_manager_impl_test.h b/ext/mini/test/unittest/device_manager_impl_test.h deleted file mode 100644 index 7a2c37e6b0c65d1bdd2892db21176e6fc604608f..0000000000000000000000000000000000000000 --- a/ext/mini/test/unittest/device_manager_impl_test.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (c) 2022 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_IMPL_TEST_H -#define OHOS_DEVICE_MANAGER_IMPL_TEST_H - -#include -#include - -#include "mock/mock_ipc_client_proxy.h" -#include "device_manager_impl.h" -#include "device_manager_callback.h" -#include "device_manager.h" - -namespace OHOS { -namespace DistributedHardware { -class DeviceManagerImplTest : public testing::Test { -public: - static void SetUpTestCase(); - static void TearDownTestCase(); - virtual void SetUp() override; - virtual void TearDown() override; -private: - std::shared_ptr test_callback_ = nullptr; -}; - -class DeviceDiscoverCallback : public DiscoverCallback { -public: - DeviceDiscoverCallback() : DiscoverCallback() {} - virtual ~DeviceDiscoverCallback() override {} - virtual void OnDiscoverySuccess(uint16_t subscribeId) override; - virtual void OnDiscoverFailed(uint16_t subscribeId, int32_t failedReason) override; - virtual void OnDeviceFound(uint16_t subscribeId, const DmDeviceInfo &deviceInfo) override; -}; -} // namespace Vsync -} // namespace OHOS - -#endif // OHOS_DEVICE_MANAGER_IMPL_TEST_H diff --git a/ext/mini/test/unittest/mock/mock_ipc_client_proxy.h b/ext/mini/test/unittest/mock/mock_ipc_client_proxy.h deleted file mode 100644 index d525f2a56a9f6d2dc8aa7dfaf4ffda1cfdae14b4..0000000000000000000000000000000000000000 --- a/ext/mini/test/unittest/mock/mock_ipc_client_proxy.h +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2022 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_MOCK_IPC_CLIENT_PROXY_H -#define OHOS_MOCK_IPC_CLIENT_PROXY_H - -#include -#include - -#include "ipc_client_proxy.h" - -namespace OHOS { -namespace DistributedHardware { -class MockIpcClientProxy : public IpcClientProxy, public RefBase { -public: - MOCK_METHOD3(SendRequest, int32_t(int32_t cmdCode, std::shared_ptr req, std::shared_ptr rsp)); -}; -} // namespace DistributedHardware -} // namespace OHOS - -#endif // OHOS_MOCK_IPC_CLIENT_PROXY_H diff --git a/ext/mini/utils/BUILD.gn b/ext/mini/utils/BUILD.gn deleted file mode 100644 index 8d9655f3e7243039ba11e0bcf3f7ed4362418dd0..0000000000000000000000000000000000000000 --- a/ext/mini/utils/BUILD.gn +++ /dev/null @@ -1,169 +0,0 @@ -# Copyright (c) 2022 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("../devicemanager.gni") - -if (defined(ohos_lite)) { - if (ohos_kernel_type == "liteos_m") { - static_library("devicemanagerutils_mini") { - include_dirs = [ - "${common_path}/include", - "include", - "include/log", - "include/cipher", - ] - - 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 = [ - "src/anonymous_string.cpp", - "src/cipher/encrypt_utils.cpp", - "src/log/dm_log.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", - "//utils/native/lite:utils", - ] - } - } else { - shared_library("devicemanagerutils") { - include_dirs = [ - "${common_path}/include", - "${common_path}/include/ipc", - "${common_path}/include/ipc/model", - "include", - "include/log", - "include/cipher", - "include/ipc/lite", - ] - - 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/distributedschedule/samgr_lite/interfaces/kits/samgr", - ] - - sources = [ - "src/anonymous_string.cpp", - "src/cipher/encrypt_utils.cpp", - "src/ipc/lite/ipc_cmd_register.cpp", - "src/log/dm_log.cpp", - ] - - defines = [ - "HI_LOG_ENABLE", - "DH_LOG_TAG=\"devicemanagerutils\"", - "LOG_DOMAIN=0xD004100", - ] - - deps = [ - "//base/hiviewdfx/hilog_lite/frameworks/featured:hilog_shared", - "//base/startup/syspara_lite/frameworks/parameter/src:sysparam", - "//foundation/communication/dsoftbus/sdk:softbus_client", - "//foundation/communication/ipc_lite:liteipc_adapter", - "//foundation/distributedschedule/samgr_lite/samgr:samgr", - "//third_party/bounds_checking_function:libsec_shared", - "//third_party/mbedtls:mbedtls_shared", - "//utils/native/lite:utils", - ] - } - } -} else { - ohos_shared_library("devicemanagerutils") { - include_dirs = [ - "//utils/native/base/include", - "//utils/system/safwk/native/include", - "${common_path}/include", - "${common_path}/include/ipc", - "${common_path}/include/ipc/model", - "include", - "include/cipher", - "include/log", - "include/ipc/standard", - "//base/security/deviceauth/interfaces/innerkits", - "//base/startup/syspara_lite/adapter/native/syspara/include", - "//third_party/json/include", - ] - - sources = [ - "src/anonymous_string.cpp", - "src/cipher/encrypt_utils.cpp", - "src/ipc/standard/ipc_cmd_register.cpp", - "src/log/dm_log.cpp", - ] - - deps = [ - "//third_party/mbedtls:mbedtls_shared", - "//utils/native/base:utils", - ] - - defines = [ - "HI_LOG_ENABLE", - "DH_LOG_TAG=\"devicemanagerutils\"", - "LOG_DOMAIN=0xD004100", - ] - - external_deps = [ - "appexecfwk_standard:appexecfwk_base", - "appexecfwk_standard:appexecfwk_core", - "appexecfwk_standard:libeventhandler", - "dsoftbus_standard:softbus_client", - "hiviewdfx_hilog_native:libhilog", - "ipc:ipc_core", - "safwk:system_ability_fwk", - "samgr_standard:samgr_proxy", - "startup_l2:syspara", - ] - - subsystem_name = "distributedhardware" - - part_name = "device_manager_base" - } -} diff --git a/ext/mini/utils/include/anonymous_string.h b/ext/mini/utils/include/anonymous_string.h deleted file mode 100644 index a587e83dfb143adcc7a9ae3846d2f51bf28f8fab..0000000000000000000000000000000000000000 --- a/ext/mini/utils/include/anonymous_string.h +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 2022 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 ANONYMOUS_STRING_H -#define ANONYMOUS_STRING_H -#include - -namespace OHOS { -namespace DistributedHardware { -std::string GetAnonyString(const std::string &value); -std::string GetAnonyInt32(const int32_t value); -} -} -#endif \ No newline at end of file diff --git a/ext/mini/utils/include/cipher/encrypt_utils.h b/ext/mini/utils/include/cipher/encrypt_utils.h deleted file mode 100644 index 56c169f757f0dd73d29b3fbcb3ff2eaeb145893b..0000000000000000000000000000000000000000 --- a/ext/mini/utils/include/cipher/encrypt_utils.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2022 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_ENCRYPT_UTILS_H -#define OHOS_DEVICE_MANAGER_ENCRYPT_UTILS_H - -#include -#include - -namespace OHOS { -namespace DistributedHardware { -class EncryptUtils { -public: - static int32_t MbedtlsBase64Encode(uint8_t *dst, size_t dlen, size_t *olen, - const uint8_t *src, size_t slen); - static int32_t MbedtlsBase64Decode(uint8_t *dst, size_t dlen, size_t *olen, - const uint8_t *src, size_t slen); - static int32_t GenRandInt(int32_t randMin, int32_t randMax); - static int64_t GenRandLongLong(int64_t randMin, int64_t randMax); - static int32_t GetRandomData(uint8_t *randStr, uint32_t len); - static int32_t MbedtlsEncrypt(const uint8_t *plainText, int32_t plainTextLen, uint8_t *cipherText, - int32_t cipherTextLen, int32_t *outLen); - static int32_t MbedtlsDecrypt(const uint8_t *cipherText, int32_t cipherTextLen, uint8_t *plainText, - int32_t plainTextLen, int32_t *outLen); - /** - * szOut最后一位为结束符,比如 szOutLen=4 可能返回 "abc" - * @param szOutLen 至少2 - * @param numberOnly 是否只生成数据 如果为true 则期望返回随机数字 如果为否,则期望返回随机字符 - */ - static bool MbedtlsGenRandomStr(char *szOut, int32_t szOutLen, bool numberOnly); -}; -} // namespace DistributedHardware -} // namespace OHOS -#endif // OHOS_DEVICE_MANAGER_ENCRYPT_UTILS_H \ No newline at end of file diff --git a/ext/mini/utils/include/ipc/lite/ipc_cmd_register.h b/ext/mini/utils/include/ipc/lite/ipc_cmd_register.h deleted file mode 100644 index 7c51223fb121e9f62279446a78225ec6780377dd..0000000000000000000000000000000000000000 --- a/ext/mini/utils/include/ipc/lite/ipc_cmd_register.h +++ /dev/null @@ -1,114 +0,0 @@ -/* - * Copyright (c) 2022 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_IPC_CMD_PARSER_H -#define OHOS_DEVICE_MANAGER_IPC_CMD_PARSER_H - -#include -#include -#include - -#include "liteipc_adapter.h" -#include "single_instance.h" - -#include "ipc_req.h" -#include "ipc_rsp.h" - -namespace OHOS { -namespace DistributedHardware { -#define ON_IPC_SET_REQUEST(cmdCode, paraA, paraB, paraC, paraD) \ - static int32_t IpcSetRequest##cmdCode(paraA, paraB, paraC, paraD); \ - struct IpcRegisterSetRequestFunc##cmdCode { \ - IpcRegisterSetRequestFunc##cmdCode() \ - { \ - IpcCmdRegister::GetInstance().RegisterSetRequestFunc(cmdCode, IpcSetRequest##cmdCode); \ - } \ - }; \ - IpcRegisterSetRequestFunc##cmdCode g_IpcRegisterSetRequestFunc##cmdCode; \ - static int32_t IpcSetRequest##cmdCode(paraA, paraB, paraC, paraD) \ - -#define ON_IPC_READ_RESPONSE(cmdCode, paraA, paraB) \ - static int32_t IpcReadResponse##cmdCode(paraA, paraB); \ - struct IpcRegisterReadResponseFunc##cmdCode { \ - IpcRegisterReadResponseFunc##cmdCode() \ - { \ - IpcCmdRegister::GetInstance().RegisterReadResponseFunc(cmdCode, IpcReadResponse##cmdCode); \ - } \ - }; \ - IpcRegisterReadResponseFunc##cmdCode g_IpcRegisterReadResponseFunc##cmdCode; \ - static int32_t IpcReadResponse##cmdCode(paraA, paraB) \ - -#define ON_IPC_CMD(cmdCode, paraA) \ - static void IpcCmdProcess##cmdCode(paraA); \ - struct IpcRegisterCmdProcessFunc##cmdCode { \ - IpcRegisterCmdProcessFunc##cmdCode() \ - { \ - IpcCmdRegister::GetInstance().RegisterCmdProcessFunc(cmdCode, IpcCmdProcess##cmdCode); \ - } \ - }; \ - IpcRegisterCmdProcessFunc##cmdCode g_IpcRegisterCmdProcessFunc##cmdCode; \ - static void IpcCmdProcess##cmdCode(paraA) \ - -#define ON_IPC_SERVER_CMD(cmdCode, paraA, paraB) \ - static void IpcServerCmdProcess##cmdCode(paraA, paraB); \ - class IpcRegisterServerCmdProcessFunc##cmdCode { \ - public: \ - IpcRegisterServerCmdProcessFunc##cmdCode() \ - { \ - IpcCmdRegister::GetInstance().RegisterServerCmdProcessFunc(cmdCode, IpcServerCmdProcess##cmdCode); \ - } \ - }; \ - IpcRegisterServerCmdProcessFunc##cmdCode g_IpcRegisterServerCmdProcessFunc##cmdCode; \ - static void IpcServerCmdProcess##cmdCode(paraA, paraB) - -using SetIpcRequestFunc = int32_t (*)(std::shared_ptr pBaseReq, IpcIo &request, - uint8_t *buffer, size_t bufferLen); -using ReadResponseFunc = int32_t (*)(IpcIo &reply, std::shared_ptr pBaseRsp); -using OnIpcCmdFunc = void (*)(IpcIo &reply); -using OnIpcServerCmdFunc = void (*)(IpcIo &req, IpcIo &reply); - -class IpcCmdRegister { -DECLARE_SINGLE_INSTANCE(IpcCmdRegister); -public: - void RegisterSetRequestFunc(int32_t cmdCode, SetIpcRequestFunc setIpcRequestFunc) - { - setIpcRequestFuncMap_.emplace(cmdCode, setIpcRequestFunc); - }; - void RegisterReadResponseFunc(int32_t cmdCode, ReadResponseFunc readResponseFunc) - { - readResponseFuncMap_.emplace(cmdCode, readResponseFunc); - }; - void RegisterCmdProcessFunc(int32_t cmdCode, OnIpcCmdFunc onIpcCmdFunc) - { - onIpcCmdFuncMap_.emplace(cmdCode, onIpcCmdFunc); - }; - void RegisterServerCmdProcessFunc(int32_t cmdCode, OnIpcServerCmdFunc onIpcServerCmdFunc) - { - onIpcServerCmdFuncMap_.emplace(cmdCode, onIpcServerCmdFunc); - }; - int32_t SetRequest(int32_t cmdCode, std::shared_ptr pBaseReq, IpcIo &request, - uint8_t *buffer, size_t buffLen); - int32_t ReadResponse(int32_t cmdCode, IpcIo &reply, std::shared_ptr pBaseRsp); - int32_t OnIpcCmd(int32_t cmdCode, IpcIo &reply); - int32_t OnIpcServerCmd(int32_t cmdCode, IpcIo &req, IpcIo &reply); -private: - std::unordered_map setIpcRequestFuncMap_; - std::unordered_map readResponseFuncMap_; - std::unordered_map onIpcCmdFuncMap_; - std::unordered_map onIpcServerCmdFuncMap_; -}; -} // namespace DistributedHardware -} // namespace OHOS -#endif // OHOS_DEVICE_MANAGER_IPC_CMD_PARSER_H \ No newline at end of file diff --git a/ext/mini/utils/include/ipc/standard/ipc_cmd_register.h b/ext/mini/utils/include/ipc/standard/ipc_cmd_register.h deleted file mode 100644 index 4e7eeb1509cc65db445f7ff43511647e7158aa68..0000000000000000000000000000000000000000 --- a/ext/mini/utils/include/ipc/standard/ipc_cmd_register.h +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright (c) 2022 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_IPC_CMD_PARSER_H -#define OHOS_DEVICE_MANAGER_IPC_CMD_PARSER_H - -#include -#include -#include - -#include "iremote_broker.h" -#include "single_instance.h" - -#include "ipc_types.h" -#include "ipc_req.h" -#include "ipc_rsp.h" - -namespace OHOS { -namespace DistributedHardware { -#define ON_IPC_SET_REQUEST(cmdCode, paraA, paraB) \ - static int32_t IpcSetRequest##cmdCode(paraA, paraB); \ - struct IpcRegisterSetRequestFunc##cmdCode { \ - IpcRegisterSetRequestFunc##cmdCode() \ - { \ - IpcCmdRegister::GetInstance().RegisterSetRequestFunc(cmdCode, IpcSetRequest##cmdCode); \ - } \ - }; \ - IpcRegisterSetRequestFunc##cmdCode g_IpcRegisterSetRequestFunc##cmdCode; \ - static int32_t IpcSetRequest##cmdCode(paraA, paraB) \ - -#define ON_IPC_READ_RESPONSE(cmdCode, paraA, paraB) \ - static int32_t IpcReadResponse##cmdCode(paraA, paraB); \ - struct IpcRegisterReadResponseFunc##cmdCode { \ - IpcRegisterReadResponseFunc##cmdCode() \ - { \ - IpcCmdRegister::GetInstance().RegisterReadResponseFunc(cmdCode, IpcReadResponse##cmdCode); \ - } \ - }; \ - IpcRegisterReadResponseFunc##cmdCode g_IpcRegisterReadResponseFunc##cmdCode; \ - static int32_t IpcReadResponse##cmdCode(paraA, paraB) \ - -#define ON_IPC_CMD(cmdCode, paraA, paraB) \ - static int32_t IpcCmdProcess##cmdCode(paraA, paraB); \ - struct IpcRegisterCmdProcessFunc##cmdCode { \ - IpcRegisterCmdProcessFunc##cmdCode() \ - { \ - IpcCmdRegister::GetInstance().RegisterCmdProcessFunc(cmdCode, IpcCmdProcess##cmdCode); \ - } \ - }; \ - IpcRegisterCmdProcessFunc##cmdCode g_IpcRegisterCmdProcessFunc##cmdCode; \ - static int32_t IpcCmdProcess##cmdCode(paraA, paraB) - -using SetIpcRequestFunc = int32_t (*)(std::shared_ptr pBaseReq, MessageParcel &data); -using ReadResponseFunc = int32_t (*)(MessageParcel &reply, std::shared_ptr pBaseRsp); -using OnIpcCmdFunc = int32_t (*)(MessageParcel &data, MessageParcel &reply); - -class IpcCmdRegister { -DECLARE_SINGLE_INSTANCE(IpcCmdRegister); -public: - void RegisterSetRequestFunc(int32_t cmdCode, SetIpcRequestFunc setIpcRequestFunc) - { - setIpcRequestFuncMap_.emplace(cmdCode, setIpcRequestFunc); - }; - void RegisterReadResponseFunc(int32_t cmdCode, ReadResponseFunc readResponseFunc) - { - readResponseFuncMap_.emplace(cmdCode, readResponseFunc); - }; - void RegisterCmdProcessFunc(int32_t cmdCode, OnIpcCmdFunc onIpcCmdFunc) - { - onIpcCmdFuncMap_.emplace(cmdCode, onIpcCmdFunc); - }; - int32_t SetRequest(int32_t cmdCode, std::shared_ptr pBaseReq, MessageParcel &data); - int32_t ReadResponse(int32_t cmdCode, MessageParcel &reply, std::shared_ptr pBaseRsp); - int32_t OnIpcCmd(int32_t cmdCode, MessageParcel &data, MessageParcel &reply); -private: - std::unordered_map setIpcRequestFuncMap_; - std::unordered_map readResponseFuncMap_; - std::unordered_map onIpcCmdFuncMap_; -}; -} // namespace DistributedHardware -} // namespace OHOS -#endif // OHOS_DEVICE_MANAGER_IPC_CMD_PARSER_H \ No newline at end of file diff --git a/ext/mini/utils/include/log/dm_log.h b/ext/mini/utils/include/log/dm_log.h deleted file mode 100644 index bf5ba0eea693a73c951a1c65a1022c26c6ddfb66..0000000000000000000000000000000000000000 --- a/ext/mini/utils/include/log/dm_log.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (c) 2022 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_LOG_H -#define OHOS_DM_LOG_H - -namespace OHOS { -namespace DistributedHardware { -typedef enum { - DM_LOG_DEBUG, - DM_LOG_INFO, - DM_LOG_WARN, - DM_LOG_ERROR, -} DMLogLevel; - -void DMLog(DMLogLevel logLevel, const char *fmt, ...); -} // namespace DistributedHardware -} // namespace OHOS -#endif // OHOS_DM_LOG_H diff --git a/ext/mini/utils/src/anonymous_string.cpp b/ext/mini/utils/src/anonymous_string.cpp deleted file mode 100644 index 3892aab08ff2e6d639a1813b9a24d5619115c799..0000000000000000000000000000000000000000 --- a/ext/mini/utils/src/anonymous_string.cpp +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright (c) 2022 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 "anonymous_string.h" - -#include "securec.h" - -namespace OHOS { -namespace DistributedHardware { -std::string GetAnonyString(const std::string &value) -{ - const int32_t INT32_SHORT_ID_LENGTH = 20; - const int32_t INT32_PLAINTEXT_LENGTH = 4; - const int32_t INT32_MIN_ID_LENGTH = 3; - std::string res; - std::string tmpStr("******"); - int32_t strLen = value.length(); - if (strLen < INT32_MIN_ID_LENGTH) { - return tmpStr; - } - - if (strLen <= INT32_SHORT_ID_LENGTH) { - res += value[0]; - res += tmpStr; - res += value[strLen - 1]; - } else { - res.append(value, 0, INT32_PLAINTEXT_LENGTH); - res += tmpStr; - res.append(value, strLen - INT32_PLAINTEXT_LENGTH, INT32_PLAINTEXT_LENGTH); - } - - return res; -} - -std::string GetAnonyInt32(const int32_t value) -{ - const int32_t INT32_STRING_LENGTH = 40; - char tempBuffer[INT32_STRING_LENGTH] = ""; - int32_t secRet = sprintf_s(tempBuffer, INT32_STRING_LENGTH, "%d", value); - if (secRet <= 0) { - std::string nullString(""); - return nullString; - } - int32_t length = strlen(tempBuffer); - for (int32_t i = 1; i < length - 1; i++) { - tempBuffer[i] = '*'; - } - if (length == 0x01) { - tempBuffer[0] = '*'; - } - - std::string tempSting(tempBuffer); - return tempSting; -} -} -} \ No newline at end of file diff --git a/ext/mini/utils/src/cipher/encrypt_utils.cpp b/ext/mini/utils/src/cipher/encrypt_utils.cpp deleted file mode 100644 index 575d3bea6e2cdea2255dfd236b90d95d2d6ffc3e..0000000000000000000000000000000000000000 --- a/ext/mini/utils/src/cipher/encrypt_utils.cpp +++ /dev/null @@ -1,156 +0,0 @@ -/* - * Copyright (c) 2022 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 "encrypt_utils.h" - -#include "mbedtls/base64.h" -#include "mbedtls/gcm.h" -#include "mbedtls/md.h" - -#include "mbedtls/ctr_drbg.h" -#include "mbedtls/entropy.h" - -#include -#include -#include -#include "device_manager_errno.h" -#include "device_manager_log.h" -#include "securec.h" - -namespace OHOS { -namespace DistributedHardware { -int32_t EncryptUtils::MbedtlsBase64Encode(uint8_t *dst, size_t dlen, size_t *olen, - const uint8_t *src, size_t slen) -{ - return mbedtls_base64_encode(dst, dlen, olen, src, slen); -} - -int32_t EncryptUtils::MbedtlsBase64Decode(uint8_t *dst, size_t dlen, size_t *olen, - const uint8_t *src, size_t slen) -{ - return mbedtls_base64_decode(dst, dlen, olen, src, slen); -} - -int32_t EncryptUtils::GenRandInt(int32_t randMin, int32_t randMax) -{ -#if (defined(__LINUX__) || defined(__LITEOS_A__)) - std::random_device randDevice; - std::mt19937 genRand(randDevice()); - std::uniform_int_distribution disRand(randMin, randMax); - return disRand(genRand); -#else - return (randMin + random() % (randMax - randMin)); -#endif -} - -int64_t EncryptUtils::GenRandLongLong(int64_t randMin, int64_t randMax) -{ - std::random_device randDevice; - std::mt19937 genRand(randDevice()); - std::uniform_int_distribution disRand(randMin, randMax); - return disRand(genRand); -} - -int32_t EncryptUtils::GetRandomData(uint8_t *randStr, uint32_t len) -{ - mbedtls_entropy_context *entropy = nullptr; - mbedtls_ctr_drbg_context *ctrDrbg = nullptr; - int32_t ret = DEVICEMANAGER_FAILED; - do { - if (randStr == nullptr || len == 0) { - break; - } - entropy = (mbedtls_entropy_context *)malloc(sizeof(mbedtls_entropy_context)); - if (entropy == nullptr) { - break; - } - ctrDrbg = (mbedtls_ctr_drbg_context *)malloc(sizeof(mbedtls_ctr_drbg_context)); - if (ctrDrbg == nullptr) { - break; - } - mbedtls_ctr_drbg_init(ctrDrbg); - mbedtls_entropy_init(entropy); - ret = mbedtls_ctr_drbg_seed(ctrDrbg, mbedtls_entropy_func, entropy, nullptr, 0); - if (ret != 0) { - break; - } - ret = mbedtls_ctr_drbg_random(ctrDrbg, randStr, len); - if (ret != 0) { - break; - } - ret = DEVICEMANAGER_OK; - } while (0); - if (entropy != nullptr) { - free(entropy); - } - if (ctrDrbg != nullptr) { - free(ctrDrbg); - } - return ret; -} - -int32_t EncryptUtils::MbedtlsEncrypt(const uint8_t *plainText, int32_t plainTextLen, uint8_t *cipherText, - int32_t cipherTextLen, int32_t *outLen) -{ - // Security algorithms do not support open source. Customize if required - if (memcpy_s(cipherText, cipherTextLen, plainText, plainTextLen) != DEVICEMANAGER_OK) { - return DEVICEMANAGER_COPY_FAILED; - } - *outLen = plainTextLen; - return DEVICEMANAGER_OK; -} - -int32_t EncryptUtils::MbedtlsDecrypt(const uint8_t *cipherText, int32_t cipherTextLen, uint8_t *plainText, - int32_t plainTextLen, int32_t *outLen) -{ - // Security algorithms do not support open source. Customize if required - (void)outLen; - if (memcpy_s(plainText, plainTextLen, cipherText, cipherTextLen) != DEVICEMANAGER_OK) { - return DEVICEMANAGER_COPY_FAILED; - } - return DEVICEMANAGER_OK; -} - -bool EncryptUtils::MbedtlsGenRandomStr(char *szOut, int32_t szOutLen, bool numberOnly) -{ - const int32_t MIN_OUT_LENGTH = 2; - if (szOut == nullptr || szOutLen <= MIN_OUT_LENGTH) { - return false; - } - szOut[--szOutLen] = 0; - GetRandomData((uint8_t*)szOut, szOutLen); - const int32_t NUMBER_COUNT = 10; - const int32_t ALPHA_COUNT = 26; - const int32_t ALPHA_BYTE_COUNT = 2; - int32_t M = numberOnly ? NUMBER_COUNT : (NUMBER_COUNT + ALPHA_BYTE_COUNT * ALPHA_COUNT); - for (int32_t i = 0; i < szOutLen; i++) { - // 0~9,A~Z,a~z - uint32_t idx = ((uint32_t)szOut[i] % M); - char base; - if (idx < NUMBER_COUNT) { - base = '0'; - } else if (idx >= NUMBER_COUNT && idx < (NUMBER_COUNT + ALPHA_COUNT)) { - base = 'A'; - idx -= NUMBER_COUNT; - } else { - base = 'a'; - idx -= (NUMBER_COUNT + ALPHA_COUNT); - } - szOut[i] = base + idx; - } - return true; -} -} // namespace DistributedHardware -} // namespace OHOS diff --git a/ext/mini/utils/src/ipc/lite/ipc_cmd_register.cpp b/ext/mini/utils/src/ipc/lite/ipc_cmd_register.cpp deleted file mode 100644 index 02cfc2f9635bf8279b91219fcd8c7e542418b500..0000000000000000000000000000000000000000 --- a/ext/mini/utils/src/ipc/lite/ipc_cmd_register.cpp +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright (c) 2022 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 "ipc_cmd_register.h" - -#include "device_manager_errno.h" -#include "device_manager_log.h" - -namespace OHOS { -namespace DistributedHardware { -IMPLEMENT_SINGLE_INSTANCE(IpcCmdRegister); - -int32_t IpcCmdRegister::SetRequest(int32_t cmdCode, std::shared_ptr pBaseReq, IpcIo &request, - uint8_t *buffer, size_t buffLen) -{ - auto setRequestMapIter = setIpcRequestFuncMap_.find(cmdCode); - if (setRequestMapIter == setIpcRequestFuncMap_.end()) { - DMLOG(DM_LOG_ERROR, "cmdCode:%d not register SetRequestFunc", cmdCode); - return DEVICEMANAGER_IPC_NOT_REGISTER_FUNC; - } - return (setRequestMapIter->second)(pBaseReq, request, buffer, buffLen); -} - -int32_t IpcCmdRegister::ReadResponse(int32_t cmdCode, IpcIo &reply, std::shared_ptr pBaseRsp) -{ - auto readResponseMapIter = readResponseFuncMap_.find(cmdCode); - if (readResponseMapIter == readResponseFuncMap_.end()) { - DMLOG(DM_LOG_ERROR, "cmdCode:%d not register ReadResponseFunc", cmdCode); - return DEVICEMANAGER_IPC_NOT_REGISTER_FUNC; - } - return (readResponseMapIter->second)(reply, pBaseRsp); -} - -int32_t IpcCmdRegister::OnIpcCmd(int32_t cmdCode, IpcIo &reply) -{ - auto onIpcCmdMapIter = onIpcCmdFuncMap_.find(cmdCode); - if (onIpcCmdMapIter == onIpcCmdFuncMap_.end()) { - DMLOG(DM_LOG_ERROR, "cmdCode:%d not register OnIpcCmdFunc", cmdCode); - return DEVICEMANAGER_IPC_NOT_REGISTER_FUNC; - } - (onIpcCmdMapIter->second)(reply); - return DEVICEMANAGER_OK; -} - -int32_t IpcCmdRegister::OnIpcServerCmd(int32_t cmdCode, IpcIo &req, IpcIo &reply) -{ - auto onIpcServerCmdMapIter = onIpcServerCmdFuncMap_.find(cmdCode); - if (onIpcServerCmdMapIter == onIpcServerCmdFuncMap_.end()) { - DMLOG(DM_LOG_ERROR, "cmdCode:%d not register OnIpcCmdFunc", cmdCode); - return DEVICEMANAGER_IPC_NOT_REGISTER_FUNC; - } - (onIpcServerCmdMapIter->second)(req, reply); - return DEVICEMANAGER_OK; -} -} // namespace DistributedHardware -} // namespace OHOS diff --git a/ext/mini/utils/src/ipc/standard/ipc_cmd_register.cpp b/ext/mini/utils/src/ipc/standard/ipc_cmd_register.cpp deleted file mode 100644 index e703a30e28ae9e7bcee6b67f6d8fd5b082ff3557..0000000000000000000000000000000000000000 --- a/ext/mini/utils/src/ipc/standard/ipc_cmd_register.cpp +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2022 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 "ipc_cmd_register.h" - -#include "device_manager_errno.h" -#include "device_manager_log.h" - -namespace OHOS { -namespace DistributedHardware { -IMPLEMENT_SINGLE_INSTANCE(IpcCmdRegister); - -int32_t IpcCmdRegister::SetRequest(int32_t cmdCode, std::shared_ptr pBaseReq, MessageParcel &data) -{ - auto setRequestMapIter = setIpcRequestFuncMap_.find(cmdCode); - if (setRequestMapIter == setIpcRequestFuncMap_.end()) { - DMLOG(DM_LOG_ERROR, "cmdCode:%d not register SetRequestFunc", cmdCode); - return DEVICEMANAGER_IPC_NOT_REGISTER_FUNC; - } - return (setRequestMapIter->second)(pBaseReq, data); -} - -int32_t IpcCmdRegister::ReadResponse(int32_t cmdCode, MessageParcel &reply, std::shared_ptr pBaseRsp) -{ - auto readResponseMapIter = readResponseFuncMap_.find(cmdCode); - if (readResponseMapIter == readResponseFuncMap_.end()) { - DMLOG(DM_LOG_ERROR, "cmdCode:%d not register ReadResponseFunc", cmdCode); - return DEVICEMANAGER_IPC_NOT_REGISTER_FUNC; - } - return (readResponseMapIter->second)(reply, pBaseRsp); -} - -int32_t IpcCmdRegister::OnIpcCmd(int32_t cmdCode, MessageParcel &data, MessageParcel &reply) -{ - auto onIpcCmdMapIter = onIpcCmdFuncMap_.find(cmdCode); - if (onIpcCmdMapIter == onIpcCmdFuncMap_.end()) { - DMLOG(DM_LOG_ERROR, "cmdCode:%d not register OnIpcCmdFunc", cmdCode); - return DEVICEMANAGER_IPC_NOT_REGISTER_FUNC; - } - return (onIpcCmdMapIter->second)(data, reply); -} -} // namespace DistributedHardware -} // namespace OHOS diff --git a/ext/mini/utils/src/log/dm_log.cpp b/ext/mini/utils/src/log/dm_log.cpp deleted file mode 100644 index 491c372444b68839627e6cca67617215d9327840..0000000000000000000000000000000000000000 --- a/ext/mini/utils/src/log/dm_log.cpp +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright (c) 2022 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_log.h" - -#include "securec.h" - -#include "constants.h" - -#ifdef HI_LOG_ENABLE -#include "hilog/log.h" -#else -#include - -#endif - -namespace OHOS { -namespace DistributedHardware { -static void DMLogOut(DMLogLevel logLevel, const char *logBuf) -{ -#ifdef HI_LOG_ENABLE - LogLevel hiLogLevel = LOG_INFO; - switch (logLevel) { - case DM_LOG_DEBUG: - hiLogLevel = LOG_DEBUG; - break; - case DM_LOG_INFO: - hiLogLevel = LOG_INFO; - break; - case DM_LOG_WARN: - hiLogLevel = LOG_WARN; - break; - case DM_LOG_ERROR: - hiLogLevel = LOG_ERROR; - break; - default: - break; - } - (void)HiLogPrint(LOG_CORE, hiLogLevel, LOG_DOMAIN, "", "%{public}s", logBuf); -#else - switch (logLevel) { - case DM_LOG_DEBUG: - printf("[D]%s\n", logBuf); - break; - case DM_LOG_INFO: - printf("[I]%s\n", logBuf); - break; - case DM_LOG_WARN: - printf("[W]%s\n", logBuf); - break; - case DM_LOG_ERROR: - printf("[E]%s\n", logBuf); - break; - default: - break; - } -#endif -} - -void DMLog(DMLogLevel logLevel, const char *fmt, ...) -{ - char logBuf[LOG_MAX_LEN] = {0}; - va_list arg; - - int32_t ret = memset_s(&arg, sizeof(va_list), 0, sizeof(va_list)); - if (ret != 0) { - DMLogOut(logLevel, "DM log memset_s error."); - return; - } - va_start(arg, fmt); - ret = vsprintf_s(logBuf, sizeof(logBuf), fmt, arg); - va_end(arg); - if (ret < 0) { - DMLogOut(logLevel, "DM log length error."); - return; - } - DMLogOut(logLevel, logBuf); -} -} // namespace DistributedHardware -} // namespace OHOS diff --git a/interfaces/inner_kits/native_cpp/BUILD.gn b/interfaces/inner_kits/native_cpp/BUILD.gn index 78710b38ee35b4ecb730cf1e1a7fcf8af6ce28b2..bcfad4c642eead57912d42c784a48e531e38a41f 100644 --- a/interfaces/inner_kits/native_cpp/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/BUILD.gn @@ -26,6 +26,8 @@ if (defined(ohos_lite)) { "${innerkits_path}/native_cpp/include/notify", "${utils_path}/include", "${common_path}/include", + "${common_path}/include/ipc", + "${common_path}/include/ipc/model", "${services_path}/include/dispatch", ] include_dirs += [ diff --git a/interfaces/inner_kits/native_cpp/src/mini/device_manager_impl.cpp b/interfaces/inner_kits/native_cpp/src/mini/device_manager_impl.cpp index 38d460f69123a32511708d6fea4a6c4659e2e3ff..35e34f372f0c114355a33c5b939282a83e6e57bb 100644 --- a/interfaces/inner_kits/native_cpp/src/mini/device_manager_impl.cpp +++ b/interfaces/inner_kits/native_cpp/src/mini/device_manager_impl.cpp @@ -16,19 +16,19 @@ #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 "ipc_def.h" +#include "ipc_get_trustdevice_req.h" +#include "ipc_get_trustdevice_rsp.h" +#include "ipc_start_discovery_req.h" +#include "ipc_stop_discovery_req.h" +#include "ipc_set_useroperation_req.h" +#include "ipc_authenticate_device_req.h" +#include "ipc_verify_authenticate_req.h" +#include "ipc_get_local_device_info_rsp.h" +#include "ipc_get_info_by_network_rsp.h" +#include "ipc_get_info_by_network_req.h" +#include "ipc_unauthenticate_device_req.h" +#include "ipc_get_dmfaparam_rsp.h" #include "device_manager_impl.h" namespace OHOS { @@ -76,8 +76,8 @@ int32_t DeviceManagerImpl::GetTrustedDeviceList(const std::string &pkgName, cons return DM_INVALID_VALUE; } - std::shared_ptr req = std::make_shared(); - std::shared_ptr rsp = std::make_shared(); + std::shared_ptr req = std::make_shared(); + std::shared_ptr rsp = std::make_shared(); req->SetPkgName(pkgName); req->SetExtra(extra); @@ -104,8 +104,8 @@ int32_t DeviceManagerImpl::GetLocalDeviceInfo(const std::string &pkgName, DmDevi return DM_INVALID_VALUE; } - std::shared_ptr req = std::make_shared(); - std::shared_ptr rsp = std::make_shared(); + std::shared_ptr req = std::make_shared(); + std::shared_ptr rsp = std::make_shared(); req->SetPkgName(pkgName); if (CommandDispatch::GetInstance().MessageSendCmd(GET_LOCAL_DEVICE_INFO, req, rsp) != DM_OK) { @@ -160,8 +160,8 @@ int32_t DeviceManagerImpl::StartDeviceDiscovery(const std::string &pkgName, cons LOGI("DeviceManager StartDeviceDiscovery in, pkgName %s", pkgName.c_str()); DeviceManagerNotify::GetInstance().RegisterDiscoveryCallback(pkgName, subscribeInfo.subscribeId, callback); - std::shared_ptr req = std::make_shared(); - std::shared_ptr rsp = std::make_shared(); + std::shared_ptr req = std::make_shared(); + std::shared_ptr rsp = std::make_shared(); req->SetPkgName(pkgName); req->SetExtra(extra); req->SetSubscribeInfo(subscribeInfo); @@ -186,8 +186,8 @@ int32_t DeviceManagerImpl::StopDeviceDiscovery(const std::string &pkgName, uint1 } LOGI("StopDeviceDiscovery in, pkgName %s", pkgName.c_str()); - std::shared_ptr req = std::make_shared(); - std::shared_ptr rsp = std::make_shared(); + std::shared_ptr req = std::make_shared(); + std::shared_ptr rsp = std::make_shared(); req->SetPkgName(pkgName); req->SetSubscribeId(subscribeId); @@ -217,8 +217,8 @@ int32_t DeviceManagerImpl::AuthenticateDevice(const std::string &pkgName, int32_ std::string strDeviceId = deviceInfo.deviceId; DeviceManagerNotify::GetInstance().RegisterAuthenticateCallback(pkgName, strDeviceId, callback); - std::shared_ptr req = std::make_shared(); - std::shared_ptr rsp = std::make_shared(); + std::shared_ptr req = std::make_shared(); + std::shared_ptr rsp = std::make_shared(); req->SetPkgName(pkgName); req->SetExtra(extra); req->SetAuthType(authType); @@ -248,8 +248,8 @@ int32_t DeviceManagerImpl::UnAuthenticateDevice(const std::string &pkgName, cons DmDeviceInfo deviceInfo; strcpy_s(deviceInfo.deviceId, DM_MAX_DEVICE_ID_LEN, deviceId.c_str()); - std::shared_ptr req = std::make_shared(); - std::shared_ptr rsp = std::make_shared(); + std::shared_ptr req = std::make_shared(); + std::shared_ptr rsp = std::make_shared(); req->SetPkgName(pkgName); req->SetDeviceInfo(deviceInfo); @@ -304,8 +304,8 @@ int32_t DeviceManagerImpl::VerifyAuthentication(const std::string &pkgName, cons DeviceManagerNotify::GetInstance().RegisterVerifyAuthenticationCallback(pkgName, authPara, callback); - std::shared_ptr req = std::make_shared(); - std::shared_ptr rsp = std::make_shared(); + std::shared_ptr req = std::make_shared(); + std::shared_ptr rsp = std::make_shared(); req->SetPkgName(pkgName); req->SetAuthPara(authPara); @@ -331,8 +331,8 @@ int32_t DeviceManagerImpl::GetFaParam(const std::string &pkgName, DmAuthParam &d return DM_INVALID_VALUE; } - std::shared_ptr req = std::make_shared(); - std::shared_ptr rsp = std::make_shared(); + std::shared_ptr req = std::make_shared(); + std::shared_ptr rsp = std::make_shared(); req->SetPkgName(pkgName); if (CommandDispatch::GetInstance().MessageSendCmd(SERVER_GET_DMFA_INFO, req, rsp) != DM_OK) { @@ -353,9 +353,8 @@ int32_t DeviceManagerImpl::SetUserOperation(const std::string &pkgName, int32_t return DM_INVALID_VALUE; } - std::shared_ptr req = std::make_shared(); - std::shared_ptr rsp = std::make_shared(); - + std::shared_ptr req = std::make_shared(); + std::shared_ptr rsp = std::make_shared(); req->SetPkgName(pkgName); req->SetOperation(action); @@ -380,8 +379,8 @@ int32_t DeviceManagerImpl::GetUdidByNetworkId(const std::string &pkgName, const return DM_INVALID_VALUE; } - std::shared_ptr req = std::make_shared(); - std::shared_ptr rsp = std::make_shared(); + std::shared_ptr req = std::make_shared(); + std::shared_ptr rsp = std::make_shared(); req->SetPkgName(pkgName); req->SetNetWorkId(netWorkId); @@ -407,8 +406,8 @@ int32_t DeviceManagerImpl::GetUuidByNetworkId(const std::string &pkgName, const return DM_INVALID_VALUE; } - std::shared_ptr req = std::make_shared(); - std::shared_ptr rsp = std::make_shared(); + std::shared_ptr req = std::make_shared(); + std::shared_ptr rsp = std::make_shared(); req->SetPkgName(pkgName); req->SetNetWorkId(netWorkId); diff --git a/services/devicemanagerservice/BUILD.gn b/services/devicemanagerservice/BUILD.gn index ee18a47596cc6b122b858eb5f0d8942ce14c746f..ccf8586ac7f5b677929e2d48bbf6463b5f53f8dc 100755 --- a/services/devicemanagerservice/BUILD.gn +++ b/services/devicemanagerservice/BUILD.gn @@ -29,6 +29,7 @@ if (defined(ohos_lite)) { "${services_path}/include/config", "${services_path}/include/adapter", "${services_path}/include/authentication", + "${services_path}/include/authentication/showconfirm/lite", "${services_path}/include/ability", "${services_path}/include/deviceinfo", "${services_path}/include/devicestate", @@ -41,6 +42,8 @@ if (defined(ohos_lite)) { "${services_path}/include/dependency/timer", "${services_path}/include/eventbus", "${common_path}/include", + "${common_path}/include/ipc", + "${common_path}/include/ipc/model", "//base/security/deviceauth/interfaces/innerkits", "//third_party/json/include", "//base/account/os_account/interfaces/innerkits/osaccount/native/include", @@ -49,6 +52,7 @@ if (defined(ohos_lite)) { "foundation/multimedia/image_standard/mock/native/include", "${services_path}/include/dispatch", "${ext_path}/pin_auth/include", + "${ext_path}/pin_auth/include/lite", ] include_dirs += [ @@ -77,6 +81,7 @@ if (defined(ohos_lite)) { "${services_path}/src/authentication/auth_request_state.cpp", "${services_path}/src/authentication/auth_response_state.cpp", "${services_path}/src/authentication/dm_auth_manager.cpp", + "${services_path}/src/authentication/showconfirm/lite/show_confirm.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", diff --git a/services/devicemanagerservice/include/dependency/timer/dm_timer.h b/services/devicemanagerservice/include/dependency/timer/dm_timer.h index 3d91af1219f1968e8f4750980b2e602e7ec30644..48da129d0a971f9311bc79f608d7adead77a0693 100644 --- a/services/devicemanagerservice/include/dependency/timer/dm_timer.h +++ b/services/devicemanagerservice/include/dependency/timer/dm_timer.h @@ -22,9 +22,9 @@ #include #include #include +#include #endif #include -#include #include #include "dm_log.h" @@ -57,7 +57,6 @@ private: void Release(); private: - std::mutex mTimerLock_; DmTimerStatus mStatus_; uint32_t mTimeOutSec_; TimeoutHandle mHandle_; @@ -70,6 +69,7 @@ private: struct epoll_event mEvents_[MAX_EVENTS]; int32_t mEpFd_; std::thread mThread_; + std::mutex mTimerLock_; #endif std::string mTimerName_; diff --git a/services/devicemanagerservice/include/dispatch/authenticate_device_req.h b/services/devicemanagerservice/include/dispatch/authenticate_device_req.h deleted file mode 100644 index 4bc90cfdd207d104978b5490a6e06ad1f903fe1b..0000000000000000000000000000000000000000 --- a/services/devicemanagerservice/include/dispatch/authenticate_device_req.h +++ /dev/null @@ -1,65 +0,0 @@ -/* - * 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 index 1ccfe254c5f44a21aeac1c9b57d8d3d3e9404a50..10dcc87fb2d2ad863304f94db0d9170cf4b9f766 100644 --- a/services/devicemanagerservice/include/dispatch/command_dispatch.h +++ b/services/devicemanagerservice/include/dispatch/command_dispatch.h @@ -21,27 +21,27 @@ #include #include #include "single_instance.h" -#include "message_req.h" -#include "message_rsp.h" +#include "ipc_req.h" +#include "ipc_rsp.h" namespace OHOS { namespace DistributedHardware { #define DEVICEMANAGER_MESSAGE_FAILED (-1) -static int32_t GetTrustedDeviceList(const std::shared_ptr &req, const std::shared_ptr &rsp); -static int32_t GetLocalDeviceInfo(const std::shared_ptr &req, const std::shared_ptr &rsp); -static int32_t GetUdidByNetworkId(const std::shared_ptr &req, const std::shared_ptr &rsp); -static int32_t GetUuidByNetworkId(const std::shared_ptr &req, const std::shared_ptr &rsp); -static int32_t StartDeviceDiscovery(const std::shared_ptr &req, const std::shared_ptr &rsp); -static int32_t StopDeviceDiscovery(const std::shared_ptr &req, const std::shared_ptr &rsp); -static int32_t SetUserOperation(const std::shared_ptr &req, const std::shared_ptr &rsp); -static int32_t GetFaParam(const std::shared_ptr &req, const std::shared_ptr &rsp); -static int32_t AuthenticateDevice(const std::shared_ptr &req, const std::shared_ptr &rsp); -static int32_t UnAuthenticateDevice(const std::shared_ptr &req, const std::shared_ptr &rsp); -static int32_t VerifyAuthentication(const std::shared_ptr &req, const std::shared_ptr &rsp); +static int32_t GetTrustedDeviceList(const std::shared_ptr &req, const std::shared_ptr &rsp); +static int32_t GetLocalDeviceInfo(const std::shared_ptr &req, const std::shared_ptr &rsp); +static int32_t GetUdidByNetworkId(const std::shared_ptr &req, const std::shared_ptr &rsp); +static int32_t GetUuidByNetworkId(const std::shared_ptr &req, const std::shared_ptr &rsp); +static int32_t StartDeviceDiscovery(const std::shared_ptr &req, const std::shared_ptr &rsp); +static int32_t StopDeviceDiscovery(const std::shared_ptr &req, const std::shared_ptr &rsp); +static int32_t SetUserOperation(const std::shared_ptr &req, const std::shared_ptr &rsp); +static int32_t GetFaParam(const std::shared_ptr &req, const std::shared_ptr &rsp); +static int32_t AuthenticateDevice(const std::shared_ptr &req, const std::shared_ptr &rsp); +static int32_t UnAuthenticateDevice(const std::shared_ptr &req, const std::shared_ptr &rsp); +static int32_t VerifyAuthentication(const std::shared_ptr &req, const std::shared_ptr &rsp); typedef struct { int32_t cmdCode; - int32_t (*MsgProcess) (const std::shared_ptr &req, const std::shared_ptr &rsp); + int32_t (*MsgProcess) (const std::shared_ptr &req, const std::shared_ptr &rsp); } CmdMap; static const CmdMap g_cmdMap[] = { @@ -61,8 +61,8 @@ static const CmdMap g_cmdMap[] = { class CommandDispatch { DECLARE_SINGLE_INSTANCE(CommandDispatch); public: - int32_t MessageSendCmd(int32_t cmdCode, const std::shared_ptr &req, - const std::shared_ptr &rsp); + int32_t MessageSendCmd(int32_t cmdCode, const std::shared_ptr &req, + const std::shared_ptr &rsp); void AddPkgName(const std::string &pkgName); void DeletePkgName(const std::string &pkgName); const std::list& GetPkgNameList() const; diff --git a/services/devicemanagerservice/include/dispatch/get_dmfaparam_rsp.h b/services/devicemanagerservice/include/dispatch/get_dmfaparam_rsp.h deleted file mode 100644 index 9126d2c3d4feb05a8634bce2ec9576052e893a22..0000000000000000000000000000000000000000 --- a/services/devicemanagerservice/include/dispatch/get_dmfaparam_rsp.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 deleted file mode 100644 index 0b75fef007f1154f649c9784a6b5739a7978102f..0000000000000000000000000000000000000000 --- a/services/devicemanagerservice/include/dispatch/get_info_by_network_req.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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 deleted file mode 100644 index 4ce591a444e9fa8abc06720dd525558a0244333b..0000000000000000000000000000000000000000 --- a/services/devicemanagerservice/include/dispatch/get_info_by_network_rsp.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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 deleted file mode 100644 index d87cc4a5a936d26505174c213414221a7b389b12..0000000000000000000000000000000000000000 --- a/services/devicemanagerservice/include/dispatch/get_local_device_info_rsp.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 diff --git a/services/devicemanagerservice/include/dispatch/get_trustdevice_req.h b/services/devicemanagerservice/include/dispatch/get_trustdevice_req.h deleted file mode 100644 index c4f4fca14e8c373495b3bdabe181d25f8fb475c9..0000000000000000000000000000000000000000 --- a/services/devicemanagerservice/include/dispatch/get_trustdevice_req.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * 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 deleted file mode 100644 index 7b9bef074782313e8462767e43b1d5c43af0697b..0000000000000000000000000000000000000000 --- a/services/devicemanagerservice/include/dispatch/get_trustdevice_rsp.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * 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/get_useroperation_req.h b/services/devicemanagerservice/include/dispatch/get_useroperation_req.h deleted file mode 100644 index 5b2f2679cbd7a3794364080a565331e4a4237a78..0000000000000000000000000000000000000000 --- a/services/devicemanagerservice/include/dispatch/get_useroperation_req.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * 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 diff --git a/services/devicemanagerservice/include/dispatch/message_def.h b/services/devicemanagerservice/include/dispatch/message_def.h deleted file mode 100644 index a5efbeb5e8b504d5916fca10f1631c8488be64f2..0000000000000000000000000000000000000000 --- a/services/devicemanagerservice/include/dispatch/message_def.h +++ /dev/null @@ -1,60 +0,0 @@ -/* - * 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 deleted file mode 100644 index d8b438a112890ad4a9184424ae0f8d470d9a16fe..0000000000000000000000000000000000000000 --- a/services/devicemanagerservice/include/dispatch/message_req.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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 deleted file mode 100644 index 811a281821b56c613942458690fa160d3b9e83de..0000000000000000000000000000000000000000 --- a/services/devicemanagerservice/include/dispatch/message_rsp.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * 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 diff --git a/services/devicemanagerservice/include/dispatch/start_discovery_req.h b/services/devicemanagerservice/include/dispatch/start_discovery_req.h deleted file mode 100644 index fd88596f51b8ae98ffa28a360d40e9ac5459dac7..0000000000000000000000000000000000000000 --- a/services/devicemanagerservice/include/dispatch/start_discovery_req.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * 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 deleted file mode 100644 index 4ce6703ac23e3f43168fd60fc418134d2b816381..0000000000000000000000000000000000000000 --- a/services/devicemanagerservice/include/dispatch/stop_discovery_req.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * 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 diff --git a/services/devicemanagerservice/include/dispatch/unauthenticate_device_req.h b/services/devicemanagerservice/include/dispatch/unauthenticate_device_req.h deleted file mode 100644 index bc00e17cf0d6c02de3ca63aebe56ff6d58fc6516..0000000000000000000000000000000000000000 --- a/services/devicemanagerservice/include/dispatch/unauthenticate_device_req.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 deleted file mode 100644 index 236e77480a1102aba7fbef0f26dcda17c269a46f..0000000000000000000000000000000000000000 --- a/services/devicemanagerservice/include/dispatch/verify_authenticate_req.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * 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 diff --git a/services/devicemanagerservice/src/authentication/dm_auth_manager.cpp b/services/devicemanagerservice/src/authentication/dm_auth_manager.cpp index 49c3591eefd1ea45ba988ac9fc38fea4aff7733f..a1626a32661ccc5fb1812ed054ed639e5ad05714 100644 --- a/services/devicemanagerservice/src/authentication/dm_auth_manager.cpp +++ b/services/devicemanagerservice/src/authentication/dm_auth_manager.cpp @@ -26,11 +26,8 @@ #include "multiple_user_connector.h" #include "nlohmann/json.hpp" #include "parameter.h" -#ifdef SUPPORT_GRAPHICS #include "show_confirm.h" -#endif - namespace OHOS { namespace DistributedHardware { const int32_t SESSION_CANCEL_TIMEOUT = 0; @@ -342,14 +339,17 @@ void DmAuthManager::OnGroupCreated(int64_t requestId, const std::string &groupId softbusConnector_->GetSoftbusSession()->SendData(authResponseContext_->sessionId, message); return; } + + int32_t pinCode = GeneratePincode(); nlohmann::json jsonObj; - jsonObj[PIN_CODE_KEY] = GeneratePincode(); + jsonObj[PIN_CODE_KEY] = pinCode; jsonObj[PIN_TOKEN] = authResponseContext_->token; jsonObj[QR_CODE_KEY] = GenerateGroupName(); jsonObj[NFC_CODE_KEY] = GenerateGroupName(); authResponseContext_->authToken = jsonObj.dump(); LOGI("DmAuthManager::AddMember start %s", authResponseContext_->authToken.c_str()); authResponseContext_->groupId = groupId; + authResponseContext_->code = pinCode; authMessageProcessor_->SetResponseContext(authResponseContext_); std::string message = authMessageProcessor_->CreateSimpleMessage(MSG_TYPE_RESP_AUTH); softbusConnector_->GetSoftbusSession()->SendData(authResponseContext_->sessionId, message); @@ -563,7 +563,6 @@ int32_t DmAuthManager::AddMember(const std::string &deviceId) return DM_FAILED; } LOGI("DmAuthManager::authRequestContext CancelDisplay start"); -#ifdef SUPPORT_GRAPHICS std::shared_ptr ptr; if (authenticationMap_.find(authResponseContext_->authType) == authenticationMap_.end()) { LOGE("DmAuthManager::authenticationMap_ is null"); @@ -571,7 +570,6 @@ int32_t DmAuthManager::AddMember(const std::string &deviceId) } ptr = authenticationMap_[authResponseContext_->authType]; ptr->CloseAuthInfo(authResponseContext_->pageId, shared_from_this()); -#endif return DM_OK; } @@ -600,7 +598,6 @@ void DmAuthManager::AuthenticateFinish() { LOGI("DmAuthManager::AuthenticateFinish start"); if (authResponseState_ != nullptr) { -#ifdef SUPPORT_GRAPHICS if (authResponseState_->GetStateType() == AuthState::AUTH_RESPONSE_FINISH) { std::shared_ptr ptr; if (authenticationMap_.find(authResponseContext_->authType) == authenticationMap_.end()) { @@ -610,7 +607,6 @@ void DmAuthManager::AuthenticateFinish() ptr = authenticationMap_[authResponseContext_->authType]; ptr->CloseAuthInfo(authResponseContext_->pageId, shared_from_this()); } -#endif if (isFinishOfLocal_) { authMessageProcessor_->SetResponseContext(authResponseContext_); std::string message = authMessageProcessor_->CreateSimpleMessage(MSG_TYPE_REQ_AUTH_TERMINATE); @@ -634,7 +630,6 @@ void DmAuthManager::AuthenticateFinish() } else { authRequestContext_->reason = authResponseContext_->reply; } -#ifdef SUPPORT_GRAPHICS if (authResponseContext_->state == AuthState::AUTH_REQUEST_INPUT) { std::shared_ptr ptr; if (authenticationMap_.find(authResponseContext_->authType) == authenticationMap_.end()) { @@ -644,7 +639,6 @@ void DmAuthManager::AuthenticateFinish() ptr = authenticationMap_[authResponseContext_->authType]; ptr->CloseAuthInfo(authResponseContext_->pageId, shared_from_this()); } -#endif listener_->OnAuthResult(authRequestContext_->hostPkgName, authRequestContext_->deviceId, authRequestContext_->token, authResponseContext_->state, authRequestContext_->reason); @@ -734,7 +728,6 @@ int32_t DmAuthManager::GetPinCode() void DmAuthManager::ShowConfigDialog() { -#ifdef SUPPORT_GRAPHICS LOGI("ShowConfigDialog start"); dmAbilityMgr_ = std::make_shared(); nlohmann::json jsonObj; @@ -746,8 +739,7 @@ void DmAuthManager::ShowConfigDialog() std::shared_ptr showConfirm_ = std::make_shared(); showConfirm_->ShowConfirmDialog(params, shared_from_this(), dmAbilityMgr_); LOGI("ShowConfigDialog end"); -#endif - } +} void DmAuthManager::ShowAuthInfoDialog() { @@ -793,7 +785,6 @@ int32_t DmAuthManager::GetAuthenticationParam(DmAuthParam &authParam) authParam.authToken = authResponseContext_->token; if (role == AbilityRole::ABILITY_ROLE_PASSIVE) { - authResponseContext_->code = GeneratePincode(); authParam.packageName = authResponseContext_->targetPkgName; authParam.appName = authResponseContext_->appName; authParam.appDescription = authResponseContext_->appDesc; diff --git a/services/devicemanagerservice/src/config/mini/pin_auth.cpp b/services/devicemanagerservice/src/config/mini/pin_auth.cpp index 5ac1ade7b9c742754332992ecb233aa57ff93ebd..0a13d233b098e4bf9861a95168179b0d8fc3e511 100644 --- a/services/devicemanagerservice/src/config/mini/pin_auth.cpp +++ b/services/devicemanagerservice/src/config/mini/pin_auth.cpp @@ -33,6 +33,18 @@ PinAuth::~PinAuth() { } +int32_t PinAuth::CloseAuthInfo(const int32_t &pageId, std::shared_ptr authManager) +{ + LOGI("ClosePage hap start"); + if (authManager == nullptr) { + LOGE("PinAuthUi::authManager is null"); + return DM_FAILED; + } + LOGI("ClosePage hap end"); + authManager->CancelDisplay(); + return DM_OK; +} + int32_t PinAuth::ShowAuthInfo(std::string &authToken, std::shared_ptr authManager) { LOGI("ShowConfigDialog end"); diff --git a/services/devicemanagerservice/src/dispatch/command_dispatch.cpp b/services/devicemanagerservice/src/dispatch/command_dispatch.cpp index 06e21ae6c69131d54b4571fd3787780ef49f6b71..a18bcab6352330fb492cf6866a555b0ea0e01e37 100644 --- a/services/devicemanagerservice/src/dispatch/command_dispatch.cpp +++ b/services/devicemanagerservice/src/dispatch/command_dispatch.cpp @@ -15,32 +15,30 @@ #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 "ipc_get_trustdevice_req.h" +#include "ipc_start_discovery_req.h" +#include "ipc_stop_discovery_req.h" +#include "ipc_set_useroperation_req.h" +#include "ipc_authenticate_device_req.h" +#include "ipc_verify_authenticate_req.h" +#include "ipc_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" +#include "ipc_get_local_device_info_rsp.h" +#include "ipc_get_info_by_network_rsp.h" +#include "ipc_get_info_by_network_req.h" +#include "ipc_unauthenticate_device_req.h" +#include "ipc_get_dmfaparam_rsp.h" namespace OHOS { namespace DistributedHardware { IMPLEMENT_SINGLE_INSTANCE(CommandDispatch); -int32_t CommandDispatch::MessageSendCmd(int32_t cmdCode, const std::shared_ptr &req, - const std::shared_ptr &rsp) +int32_t CommandDispatch::MessageSendCmd(int32_t cmdCode, const std::shared_ptr &req, + const std::shared_ptr &rsp) { if (req == nullptr || rsp == nullptr) { LOGE("Message req or rsp is null."); @@ -75,10 +73,10 @@ const std::list& CommandDispatch::GetPkgNameList() const return dmPkgName_; } -static int32_t GetTrustedDeviceList(const std::shared_ptr &req, const std::shared_ptr &rsp) +static int32_t GetTrustedDeviceList(const std::shared_ptr &req, const std::shared_ptr &rsp) { - std::shared_ptr pReq = std::static_pointer_cast(req); - std::shared_ptr prsp = std::static_pointer_cast(rsp); + 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(); @@ -90,9 +88,9 @@ static int32_t GetTrustedDeviceList(const std::shared_ptr &req, cons return ret; } -static int32_t GetLocalDeviceInfo(const std::shared_ptr &req, const std::shared_ptr &rsp) +static int32_t GetLocalDeviceInfo(const std::shared_ptr &req, const std::shared_ptr &rsp) { - std::shared_ptr pRsp = std::static_pointer_cast(rsp); + std::shared_ptr pRsp = std::static_pointer_cast(rsp); DmDeviceInfo dmDeviceInfo = {0}; int32_t ret = DeviceManagerService::GetInstance().GetLocalDeviceInfo(dmDeviceInfo); DmDeviceInfo *Info = &dmDeviceInfo; @@ -103,10 +101,10 @@ static int32_t GetLocalDeviceInfo(const std::shared_ptr &req, const return ret; } -static int32_t GetUdidByNetworkId(const std::shared_ptr &req, const std::shared_ptr &rsp) +static int32_t GetUdidByNetworkId(const std::shared_ptr &req, const std::shared_ptr &rsp) { - std::shared_ptr pReq = std::static_pointer_cast(req); - std::shared_ptr pRsp = std::static_pointer_cast(rsp); + 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; @@ -117,10 +115,10 @@ static int32_t GetUdidByNetworkId(const std::shared_ptr &req, const return ret; } -static int32_t GetUuidByNetworkId(const std::shared_ptr &req, const std::shared_ptr &rsp) +static int32_t GetUuidByNetworkId(const std::shared_ptr &req, const std::shared_ptr &rsp) { - std::shared_ptr pReq = std::static_pointer_cast(req); - std::shared_ptr pRsp = std::static_pointer_cast(rsp); + 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; @@ -131,9 +129,9 @@ static int32_t GetUuidByNetworkId(const std::shared_ptr &req, const return ret; } -static int32_t StartDeviceDiscovery(const std::shared_ptr &req, const std::shared_ptr &rsp) +static int32_t StartDeviceDiscovery(const std::shared_ptr &req, const std::shared_ptr &rsp) { - std::shared_ptr pReq = std::static_pointer_cast(req); + std::shared_ptr pReq = std::static_pointer_cast(req); std::string pkgName = pReq->GetPkgName(); std::string extra = pReq->GetExtra(); const DmSubscribeInfo dmSubscribeInfo = pReq->GetSubscribeInfo(); @@ -144,10 +142,10 @@ static int32_t StartDeviceDiscovery(const std::shared_ptr &req, cons return ret; } -static int32_t StopDeviceDiscovery(const std::shared_ptr &req, const std::shared_ptr &rsp) +static int32_t StopDeviceDiscovery(const std::shared_ptr &req, const std::shared_ptr &rsp) { LOGI("StopDeviceDiscovery service"); - std::shared_ptr pReq = std::static_pointer_cast(req); + std::shared_ptr pReq = std::static_pointer_cast(req); std::string pkgName = pReq->GetPkgName(); uint16_t subscribeId = pReq->GetSubscribeId(); @@ -156,9 +154,9 @@ static int32_t StopDeviceDiscovery(const std::shared_ptr &req, const return ret; } -static int32_t SetUserOperation(const std::shared_ptr &req, const std::shared_ptr &rsp) +static int32_t SetUserOperation(const std::shared_ptr &req, const std::shared_ptr &rsp) { - std::shared_ptr pReq = std::static_pointer_cast(req); + std::shared_ptr pReq = std::static_pointer_cast(req); std::string pkgName = pReq->GetPkgName(); int32_t action = pReq->GetOperation(); @@ -169,10 +167,10 @@ static int32_t SetUserOperation(const std::shared_ptr &req, const st return ret; } -static int32_t GetFaParam(const std::shared_ptr &req, const std::shared_ptr &rsp) +static int32_t GetFaParam(const std::shared_ptr &req, const std::shared_ptr &rsp) { - std::shared_ptr pReq = std::static_pointer_cast(req); - std::shared_ptr pRsp = std::static_pointer_cast(rsp); + 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 = "", @@ -194,9 +192,9 @@ static int32_t GetFaParam(const std::shared_ptr &req, const std::sha return ret; } -static int32_t AuthenticateDevice(const std::shared_ptr &req, const std::shared_ptr &rsp) +static int32_t AuthenticateDevice(const std::shared_ptr &req, const std::shared_ptr &rsp) { - std::shared_ptr pReq = std::static_pointer_cast(req); + std::shared_ptr pReq = std::static_pointer_cast(req); std::string pkgName = pReq->GetPkgName(); std::string extra = pReq->GetExtra(); DmDeviceInfo deviceInfo = pReq->GetDeviceInfo(); @@ -210,9 +208,9 @@ static int32_t AuthenticateDevice(const std::shared_ptr &req, const return ret; } -static int32_t UnAuthenticateDevice(const std::shared_ptr &req, const std::shared_ptr &rsp) +static int32_t UnAuthenticateDevice(const std::shared_ptr &req, const std::shared_ptr &rsp) { - std::shared_ptr pReq = std::static_pointer_cast(req); + std::shared_ptr pReq = std::static_pointer_cast(req); std::string pkgName = pReq->GetPkgName(); DmDeviceInfo deviceInfo = pReq->GetDeviceInfo(); std::string deviceId = deviceInfo.deviceId; @@ -223,9 +221,9 @@ static int32_t UnAuthenticateDevice(const std::shared_ptr &req, cons return ret; } -static int32_t VerifyAuthentication(const std::shared_ptr &req, const std::shared_ptr &rsp) +static int32_t VerifyAuthentication(const std::shared_ptr &req, const std::shared_ptr &rsp) { - std::shared_ptr pReq = std::static_pointer_cast(req); + std::shared_ptr pReq = std::static_pointer_cast(req); std::string pkgName = pReq->GetPkgName(); std::string authParam = pReq->GetAuthPara(); diff --git a/services/devicemanagerservice/src/dispatch/server_stub.cpp b/services/devicemanagerservice/src/dispatch/server_stub.cpp index 28a106516ef3a439b20968b0c5de2e6430643cb2..ca22a2b7f89be80fc07f3ab9ae66be5e03052733 100644 --- a/services/devicemanagerservice/src/dispatch/server_stub.cpp +++ b/services/devicemanagerservice/src/dispatch/server_stub.cpp @@ -20,8 +20,7 @@ #include "iproxy_server.h" #include "dm_log.h" #include "dm_subscribe_info.h" - -#include "message_def.h" +#include "ipc_def.h" #include "device_manager_service.h" namespace {