!1 新device manager工程代码上库

Merge pull request !1 from 曹刘超/master

Signed-off-by: puhui <puhui1@huawei.com>
This commit is contained in:
蒲辉
2022-01-12 13:47:58 +00:00
committed by Gitee
136 changed files with 2465 additions and 10448 deletions
+11 -7
View File
@@ -11,13 +11,17 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import("//build/lite/config/component/lite_component.gni")
if (defined(ohos_lite)) {
import("//build/lite/config/component/lite_component.gni")
lite_component("devicemanager_lite") {
features = [
"utils:devicemanagerutils",
"services/devicemanagerservice:devicemanagerservice",
"interfaces/inner_kits/native_cpp:devicemanagersdk",
]
if (ohos_kernel_type == "liteos_m") {
} else {
features = [
"utils:devicemanagerutils",
"services/devicemanagerservice:devicemanagerservice",
"interfaces/inner_kits/native_cpp:devicemanagersdk",
]
}
}
}
}
-167
View File
@@ -1,167 +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_CONSTANTS_H
#define OHOS_DEVICE_MANAGER_CONSTANTS_H
#include <cstdint>
#include <string>
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
-61
View File
@@ -1,61 +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_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
-29
View File
@@ -1,29 +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_LOG_H
#define OHOS_DEVICE_MANAGER_LOG_H
#include <string>
#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
+21 -17
View File
@@ -4,7 +4,7 @@
* 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
* 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,
@@ -21,35 +21,39 @@ 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_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)
#define DECLARE_IPC_INTERFACE(className) DECLARE_IPC_MODEL(className)
enum IpcCmdID {
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,
CHECK_AUTHENTICATION,
UNAUTHENTICATE_DEVICE,
VERIFY_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,
SERVER_VERIFY_AUTH_RESULT,
SERVER_GET_DMFA_INFO,
SERVER_USER_AUTH_OPERATION,
SERVER_DEVICE_FA_NOTIFY,
};
} // namespace DistributedHardware
} // namespace OHOS
@@ -4,7 +4,7 @@
* 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
* 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,
@@ -13,20 +13,19 @@
* 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"
#ifndef OHOS_DM_IPC_AUTHENTICATE_DEVICE_REQ_H
#define OHOS_DM_IPC_AUTHENTICATE_DEVICE_REQ_H
#include "dm_device_info.h"
#include "dm_app_image_info.h"
#include "ipc_req.h"
namespace OHOS {
namespace DistributedHardware {
class IpcAuthenticateDeviceReq : public IpcReq {
DECLARE_IPC_MODEL(IpcAuthenticateDeviceReq);
DECLARE_IPC_MODEL(IpcAuthenticateDeviceReq);
public:
const DmDeviceInfo& GetDeviceInfo() const
const DmDeviceInfo &GetDeviceInfo() const
{
return deviceInfo_;
}
@@ -36,30 +35,31 @@ public:
deviceInfo_ = deviceInfo;
}
const DmAppImageInfo& GetAppImageInfo() const
int32_t GetAuthType()
{
return appImageInfo_;
return authType_;
}
void SetAppImageInfo(const DmAppImageInfo &appImageInfo)
void SetAuthType(int32_t authType)
{
appImageInfo_ = appImageInfo;
authType_ = authType;
}
const std::string& GetExtra() const
const std::string &GetExtra() const
{
return extra_;
}
void SetExtra(std::string &extra)
void SetExtra(const std::string &extra)
{
extra_ = extra;
}
private:
DmDeviceInfo deviceInfo_;
DmAppImageInfo appImageInfo_;
int32_t authType_;
std::string extra_;
};
} // namespace DistributedHardware
} // namespace OHOS
#endif // OHOS_DEVICE_MANAGER_IPC_AUTHENTICATE_DEVICE_REQ_H
#endif // OHOS_DM_IPC_AUTHENTICATE_DEVICE_REQ_H
@@ -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_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
@@ -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_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
@@ -4,7 +4,7 @@
* 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
* 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,
@@ -13,28 +13,30 @@
* limitations under the License.
*/
#ifndef OHOS_DEVICE_MANAGER_IPC_GET_TRUST_DEVICE_REQ_H
#define OHOS_DEVICE_MANAGER_IPC_GET_TRUST_DEVICE_REQ_H
#ifndef OHOS_DM_IPC_GET_TRUST_DEVICE_REQ_H
#define OHOS_DM_IPC_GET_TRUST_DEVICE_REQ_H
#include "ipc_req.h"
namespace OHOS {
namespace DistributedHardware {
class IpcGetTrustdeviceReq : public IpcReq {
DECLARE_IPC_MODEL(IpcGetTrustdeviceReq);
class IpcGetTrustDeviceReq : public IpcReq {
DECLARE_IPC_MODEL(IpcGetTrustDeviceReq);
public:
const std::string& GetExtra() const
const std::string &GetExtra() const
{
return extra_;
}
void SetExtra(std::string &extra)
void SetExtra(const std::string &extra)
{
extra_ = extra;
}
private:
std::string extra_;
};
} // namespace DistributedHardware
} // namespace OHOS
#endif // OHOS_DEVICE_MANAGER_IPC_GET_TRUST_DEVICE_REQ_H
#endif // OHOS_DM_IPC_GET_TRUST_DEVICE_REQ_H
@@ -4,7 +4,7 @@
* 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
* 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,
@@ -13,32 +13,33 @@
* limitations under the License.
*/
#ifndef OHOS_DEVICE_MANAGER_IPC_GET_TRUSTDEVICE_RSP_H
#define OHOS_DEVICE_MANAGER_IPC_GET_TRUSTDEVICE_RSP_H
#ifndef OHOS_DM_IPC_GET_TRUST_DEVICE_RSP_H
#define OHOS_DM_IPC_GET_TRUST_DEVICE_RSP_H
#include <vector>
#include "dm_device_info.h"
#include "ipc_rsp.h"
namespace OHOS {
namespace DistributedHardware {
class IpcGetTrustdeviceRsp : public IpcRsp {
DECLARE_IPC_MODEL(IpcGetTrustdeviceRsp);
class IpcGetTrustDeviceRsp : public IpcRsp {
DECLARE_IPC_MODEL(IpcGetTrustDeviceRsp);
public:
std::vector<DmDeviceInfo> GetDeviceVec() const
{
return deviceVec_;
}
void SetDeviceVec(std::vector<DmDeviceInfo>& deviceVec)
void SetDeviceVec(std::vector<DmDeviceInfo> &deviceVec)
{
deviceVec_ = deviceVec;
}
private:
std::vector<DmDeviceInfo> deviceVec_;
};
} // namespace DistributedHardware
} // namespace OHOS
#endif // OHOS_DEVICE_MANAGER_IPC_GET_TRUSTDEVICE_RSP_H
#endif // OHOS_DM_IPC_GET_TRUST_DEVICE_RSP_H
@@ -4,7 +4,7 @@
* 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
* 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,
@@ -13,8 +13,8 @@
* limitations under the License.
*/
#ifndef OHOS_DEVICE_MANAGER_IPC_NOTIFY_AUTH_RESULT_REQ_H
#define OHOS_DEVICE_MANAGER_IPC_NOTIFY_AUTH_RESULT_REQ_H
#ifndef OHOS_DM_IPC_NOTIFY_AUTH_RESULT_REQ_H
#define OHOS_DM_IPC_NOTIFY_AUTH_RESULT_REQ_H
#include <cstdint>
@@ -23,26 +23,27 @@
namespace OHOS {
namespace DistributedHardware {
class IpcNotifyAuthResultReq : public IpcReq {
DECLARE_IPC_MODEL(IpcNotifyAuthResultReq);
DECLARE_IPC_MODEL(IpcNotifyAuthResultReq);
public:
std::string GetDeviceId() const
{
return deviceId_;
}
void SetDeviceId(std::string& deviceId)
void SetDeviceId(const std::string &deviceId)
{
deviceId_ = deviceId;
}
int32_t GetPinToken() const
std::string GetPinToken() const
{
return pinToken_;
return token_;
}
void SetPinToken(int32_t pinToken)
void SetToken(const std::string &token)
{
pinToken_ = pinToken;
token_ = token;
}
int32_t GetStatus() const
@@ -64,12 +65,13 @@ public:
{
reason_ = reason;
}
private:
std::string deviceId_;
int32_t pinToken_ {0};
int32_t status_ {0};
int32_t reason_ {0};
std::string token_;
int32_t status_{0};
int32_t reason_{0};
};
} // namespace DistributedHardware
} // namespace OHOS
#endif // OHOS_DEVICE_MANAGER_IPC_NOTIFY_AUTH_RESULT_REQ_H
#endif // OHOS_DM_IPC_NOTIFY_AUTH_RESULT_REQ_H
@@ -1,64 +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_IPC_NOTIFY_CHECK_AUTH_RESULT_REQ_H
#define OHOS_DEVICE_MANAGER_IPC_NOTIFY_CHECK_AUTH_RESULT_REQ_H
#include <cstdint>
#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
@@ -4,7 +4,7 @@
* 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
* 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,
@@ -13,24 +13,24 @@
* limitations under the License.
*/
#ifndef OHOS_DEVICE_MANAGER_IPC_NOTIFY_DEVICE_FOUND_REQ_H
#define OHOS_DEVICE_MANAGER_IPC_NOTIFY_DEVICE_FOUND_REQ_H
#ifndef OHOS_DM_IPC_NOTIFY_DEVICE_FOUND_REQ_H
#define OHOS_DM_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);
DECLARE_IPC_MODEL(IpcNotifyDeviceFoundReq);
public:
const DmDeviceInfo& GetDeviceInfo() const
const DmDeviceInfo &GetDeviceInfo() const
{
return dmDeviceInfo_;
}
void SetDeviceInfo(DmDeviceInfo& dmDeviceInfo)
void SetDeviceInfo(const DmDeviceInfo &dmDeviceInfo)
{
dmDeviceInfo_ = dmDeviceInfo;
}
@@ -44,10 +44,11 @@ public:
{
subscribeId_ = subscribeId;
}
private:
uint16_t subscribeId_ {0};
uint16_t subscribeId_{0};
DmDeviceInfo dmDeviceInfo_;
};
} // namespace DistributedHardware
} // namespace OHOS
#endif // OHOS_DEVICE_MANAGER_IPC_NOTIFY_DEVICE_FOUND_REQ_H
#endif // OHOS_DM_IPC_NOTIFY_DEVICE_FOUND_REQ_H
@@ -4,7 +4,7 @@
* 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
* 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,
@@ -13,17 +13,17 @@
* limitations under the License.
*/
#ifndef OHOS_DEVICE_MANAGER_IPC_NOTIFY_DEVICE_STATE_REQ_H
#define OHOS_DEVICE_MANAGER_IPC_NOTIFY_DEVICE_STATE_REQ_H
#ifndef OHOS_DM_IPC_NOTIFY_DEVICE_STATE_REQ_H
#define OHOS_DM_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);
DECLARE_IPC_MODEL(IpcNotifyDeviceStateReq);
public:
int32_t GetDeviceState() const
{
@@ -35,19 +35,20 @@ public:
deviceState_ = deviceState;
}
const DmDeviceInfo& GetDeviceInfo() const
const DmDeviceInfo &GetDeviceInfo() const
{
return dmDeviceInfo_;
}
void SetDeviceInfo(DmDeviceInfo& dmDeviceInfo)
void SetDeviceInfo(const DmDeviceInfo &dmDeviceInfo)
{
dmDeviceInfo_ = dmDeviceInfo;
}
private:
int32_t deviceState_ {0};
int32_t deviceState_{0};
DmDeviceInfo dmDeviceInfo_;
};
} // namespace DistributedHardware
} // namespace OHOS
#endif // OHOS_DEVICE_MANAGER_IPC_NOTIFY_DEVICE_STATE_REQ_H
#endif // OHOS_DM_IPC_NOTIFY_DEVICE_STATE_REQ_H
@@ -4,7 +4,7 @@
* 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
* 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,
@@ -13,17 +13,16 @@
* 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 <cstdint>
#ifndef OHOS_DM_IPC_NOTIFY_DISCOVER_RESULT_REQ_H
#define OHOS_DM_IPC_NOTIFY_DISCOVER_RESULT_REQ_H
#include "ipc_req.h"
namespace OHOS {
namespace DistributedHardware {
class IpcNotifyDiscoverResultReq : public IpcReq {
DECLARE_IPC_MODEL(IpcNotifyDiscoverResultReq);
DECLARE_IPC_MODEL(IpcNotifyDiscoverResultReq);
public:
uint16_t GetSubscribeId() const
{
@@ -44,10 +43,11 @@ public:
{
result_ = result;
}
private:
uint16_t subscribeId_ {0};
int32_t result_ {0};
uint16_t subscribeId_{0};
int32_t result_{0};
};
} // namespace DistributedHardware
} // namespace OHOS
#endif // OHOS_DEVICE_MANAGER_IPC_NOTIFY_DISCOVER_RESULT_REQ_H
#endif // OHOS_DM_IPC_NOTIFY_DISCOVER_RESULT_REQ_H
@@ -4,7 +4,7 @@
* 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
* 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,
@@ -16,27 +16,27 @@
#ifndef OHOS_DEVICE_MANAGER_IPC_NOTIFY_DMFA_RESULT_REQ_H
#define OHOS_DEVICE_MANAGER_IPC_NOTIFY_DMFA_RESULT_REQ_H
#include <stdint.h>
#include "ipc_req.h"
namespace OHOS {
namespace DistributedHardware {
class IpcNotifyDMFAResultReq : public IpcReq {
DECLARE_IPC_MODEL(IpcNotifyDMFAResultReq);
DECLARE_IPC_MODEL(IpcNotifyDMFAResultReq);
public:
std::string GetJsonParam() const
{
return JsonParam_;
}
void SetJsonParam(std::string& JsonParam)
void SetJsonParam(const std::string &JsonParam)
{
JsonParam_ = JsonParam;
}
private:
std::string JsonParam_;
};
} // namespace DistributedHardware
} // namespace OHOS
#endif // OHOS_DEVICE_MANAGER_IPC_NOTIFY_AUTH_RESULT_REQ_H
#endif // OHOS_DEVICE_MANAGER_IPC_NOTIFY_DMFA_RESULT_REQ_H
@@ -4,7 +4,7 @@
* 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
* 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,
@@ -13,8 +13,8 @@
* limitations under the License.
*/
#ifndef OHOS_DEVICE_MANAGER_IPC_REGISTER_LISTENER_REQ_H
#define OHOS_DEVICE_MANAGER_IPC_REGISTER_LISTENER_REQ_H
#ifndef OHOS_DM_IPC_REGISTER_LISTENER_REQ_H
#define OHOS_DM_IPC_REGISTER_LISTENER_REQ_H
#include "ipc_req.h"
@@ -27,7 +27,8 @@
namespace OHOS {
namespace DistributedHardware {
class IpcRegisterListenerReq : public IpcReq {
DECLARE_IPC_MODEL(IpcRegisterListenerReq);
DECLARE_IPC_MODEL(IpcRegisterListenerReq);
public:
#ifdef LITE_DEVICE
SvcIdentity GetSvcIdentity() const
@@ -59,4 +60,4 @@ private:
};
} // namespace DistributedHardware
} // namespace OHOS
#endif // OHOS_DEVICE_MANAGER_IPC_REGISTER_LISTENER_REQ_H
#endif // OHOS_DM_IPC_REGISTER_LISTENER_REQ_H
+9 -7
View File
@@ -4,7 +4,7 @@
* 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
* 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,
@@ -13,8 +13,8 @@
* limitations under the License.
*/
#ifndef OHOS_DEVICE_MANAGER_IPC_REQ_H
#define OHOS_DEVICE_MANAGER_IPC_REQ_H
#ifndef OHOS_DM_IPC_REQ_H
#define OHOS_DM_IPC_REQ_H
#include <string>
@@ -23,20 +23,22 @@
namespace OHOS {
namespace DistributedHardware {
class IpcReq {
DECLARE_IPC_MODEL(IpcReq);
DECLARE_IPC_MODEL(IpcReq);
public:
const std::string& GetPkgName() const
const std::string &GetPkgName() const
{
return pkgName_;
}
void SetPkgName(std::string &pkgName)
void SetPkgName(const std::string &pkgName)
{
pkgName_ = pkgName;
}
private:
std::string pkgName_;
};
} // namespace DistributedHardware
} // namespace OHOS
#endif // OHOS_DEVICE_MANAGER_IPC_REQ_H
#endif // OHOS_DM_IPC_REQ_H
+7 -5
View File
@@ -4,7 +4,7 @@
* 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
* 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,
@@ -13,8 +13,8 @@
* limitations under the License.
*/
#ifndef OHOS_DEVICE_MANAGER_IPC_RSP_H
#define OHOS_DEVICE_MANAGER_IPC_RSP_H
#ifndef OHOS_DM_IPC_RSP_H
#define OHOS_DM_IPC_RSP_H
#include <cstdint>
@@ -23,7 +23,8 @@
namespace OHOS {
namespace DistributedHardware {
class IpcRsp {
DECLARE_IPC_MODEL(IpcRsp);
DECLARE_IPC_MODEL(IpcRsp);
public:
int32_t GetErrCode() const
{
@@ -34,9 +35,10 @@ public:
{
errCode_ = errCode;
}
private:
int32_t errCode_;
};
} // namespace DistributedHardware
} // namespace OHOS
#endif // OHOS_DEVICE_MANAGER_IPC_RSP_H
#endif // OHOS_DM_IPC_RSP_H
@@ -4,7 +4,7 @@
* 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
* 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,
@@ -15,13 +15,15 @@
#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"
#include "ipc_req.h"
namespace OHOS {
namespace DistributedHardware {
class IpcGetOperationReq : public IpcReq {
DECLARE_IPC_MODEL(IpcGetOperationReq);
DECLARE_IPC_MODEL(IpcGetOperationReq);
public:
int32_t GetOperation() const
{
@@ -34,7 +36,7 @@ public:
}
private:
int32_t action_ {0};
int32_t action_{0};
};
} // namespace DistributedHardware
} // namespace OHOS
@@ -4,7 +4,7 @@
* 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
* 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,
@@ -13,30 +13,42 @@
* 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"
#ifndef OHOS_DM_IPC_START_DISCOVERY_REQ_H
#define OHOS_DM_IPC_START_DISCOVERY_REQ_H
#include "dm_subscribe_info.h"
#include "ipc_req.h"
namespace OHOS {
namespace DistributedHardware {
class IpcStartDiscoveryReq : public IpcReq {
DECLARE_IPC_MODEL(IpcStartDiscoveryReq);
DECLARE_IPC_MODEL(IpcStartDiscoveryReq);
public:
const DmSubscribeInfo& GetSubscribeInfo() const
const DmSubscribeInfo &GetSubscribeInfo() const
{
return subscribeInfo_;
}
void SetSubscribeInfo(DmSubscribeInfo &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_IPC_START_DISCOVERY_REQ_H
#endif // OHOS_DM_IPC_START_DISCOVERY_REQ_H
@@ -4,7 +4,7 @@
* 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
* 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,
@@ -13,8 +13,8 @@
* limitations under the License.
*/
#ifndef OHOS_DEVICE_MANAGER_IPC_STOP_DISCOVERY_REQ_H
#define OHOS_DEVICE_MANAGER_IPC_STOP_DISCOVERY_REQ_H
#ifndef OHOS_DM_IPC_STOP_DISCOVERY_REQ_H
#define OHOS_DM_IPC_STOP_DISCOVERY_REQ_H
#include <cstdint>
@@ -23,7 +23,8 @@
namespace OHOS {
namespace DistributedHardware {
class IpcStopDiscoveryReq : public IpcReq {
DECLARE_IPC_MODEL(IpcStopDiscoveryReq);
DECLARE_IPC_MODEL(IpcStopDiscoveryReq);
public:
uint16_t GetSubscribeId() const
{
@@ -34,9 +35,10 @@ public:
{
subscribeId_ = subscribeId;
}
private:
uint16_t subscribeId_ {0};
uint16_t subscribeId_{0};
};
} // namespace DistributedHardware
} // namespace OHOS
#endif // OHOS_DEVICE_MANAGER_IPC_STOP_DISCOVERY_REQ_H
#endif // OHOS_DM_IPC_STOP_DISCOVERY_REQ_H
+18 -18
View File
@@ -4,7 +4,7 @@
* 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
* 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,
@@ -13,34 +13,34 @@
* limitations under the License.
*/
#ifndef OHOS_DEVICE_MANAGER_SINGLE_INSTANCE_H
#define OHOS_DEVICE_MANAGER_SINGLE_INSTANCE_H
#ifndef OHOS_DM_SINGLE_INSTANCE_H
#define OHOS_DM_SINGLE_INSTANCE_H
namespace OHOS {
namespace DistributedHardware {
#define DECLARE_SINGLE_INSTANCE_BASE(className) \
public: \
static className & GetInstance(); \
public: \
static className &GetInstance(); \
\
private: \
className(const className&) = delete; \
className& operator= (const className&) = delete; \
className(className&&) = delete; \
className& operator= (className&&) = delete; \
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; \
~className() = default;
#define IMPLEMENT_SINGLE_INSTANCE(className) \
className & className::GetInstance() \
{ \
static auto instance = new className(); \
return *instance; \
}
#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
#endif // OHOS_DM_SINGLE_INSTANCE_H
+8 -4
View File
@@ -11,14 +11,18 @@
# 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"
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" ]
-476
View File
@@ -1,476 +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.
*/
import { AsyncCallback, Callback } from './basic';
declare namespace deviceManager {
/**
* DeviceInfo
*/
interface DeviceInfo {
/**
* DeviceId ID.
*/
deviceId: string;
/**
* Device name of the device.
*/
deviceName: string;
/**
* Device type of the device.
*/
deviceType: DeviceType;
}
/**
* Device Type definitions
*/
enum DeviceType {
/**
* Indicates an unknown device type.
*/
UNKNOWN_TYPE = 0,
/**
* Indicates a speaker.
*/
SPEAKER = 0x0A,
/**
* Indicates a smartphone.
*/
PHONE = 0x0E,
/**
* Indicates a tablet.
*/
TABLET = 0x11,
/**
* Indicates a smart watch.
*/
WEARABLE = 0x6D,
/**
* Indicates a car.
*/
CAR = 0x83,
/**
* Indicates a smart TV.
*/
TV = 0x9C
}
/**
* Device state change event definition
*/
enum DeviceStateChangeAction {
/**
* device online action
*/
ONLINE = 0,
/**
* device ready action, the device information synchronization was completed.
*/
READY = 1,
/**
* device offline action
*/
OFFLINE = 2,
/**
* device change action
*/
CHANGE = 3
}
/**
* Service subscribe info for device discover
*
* @systemapi this method can be used only by system applications.
*/
interface SubscribeInfo {
/**
* Service subscribe ID, the value is in scope [0, 65535], should be unique for each discover process
*/
subscribeId: number;
/**
* Discovery mode for service subscription.
*/
mode: DiscoverMode;
/**
* Service subscription medium.
*/
medium: ExchangeMedium;
/**
* Service subscription frequency.
*/
freq: ExchangeFreq;
/**
* only find the device with the same account.
*/
isSameAccount: boolean;
/**
* find the sleeping devices.
*/
isWakeRemote: boolean;
/**
* Subscribe capability.
*/
capability: SubscribeCap;
}
/**
* device discover mode
*
* @systemapi this method can be used only by system applications.
*/
enum DiscoverMode {
/**
* Passive
*/
DISCOVER_MODE_PASSIVE = 0x55,
/**
* Proactive
*/
DISCOVER_MODE_ACTIVE = 0xAA
}
/**
* device discover medium
*
* @systemapi this method can be used only by system applications.
*/
enum ExchangeMedium {
/**
* Automatic medium selection
*/
AUTO = 0,
/**
* Bluetooth
*/
BLE = 1,
/**
* Wi-Fi
*/
COAP = 2,
/**
* USB
*/
USB = 3
}
/**
* device discover freq
*
* @systemapi this method can be used only by system applications.
*/
enum ExchangeFreq {
/**
* Low
*/
LOW = 0,
/**
* Medium
*/
MID = 1,
/**
* High
*/
HIGH = 2,
/**
* Super-high
*/
SUPER_HIGH = 3
}
/**
* device discover capability
*
* @systemapi this method can be used only by system applications.
*/
enum SubscribeCap {
/**
* ddmpCapability
*/
SUBSCRIBE_CAPABILITY_DDMP = 0
}
/**
* Device Authentication param
*
* @systemapi this method can be used only by system applications
*/
interface AuthParam {
/**
* Authentication type, 1 for pin code.
*/
authType: number;
/**
* App application Icon.
*/
appIcon?: Uint8Array;
/**
* App application thumbnail.
*/
appThumbnail?: Uint8Array;
/**
* Authentication extra infos.
*/
extraInfo: {[key:string] : any};
}
/**
* Device auth info.
*
* @systemapi this method can be used only by system applications
*/
interface AuthInfo {
/**
* Authentication type, 1 for pin code.
*/
authType: number;
/**
* the token used for this authentication.
*/
token: number;
/**
* Authentication extra infos.
*/
extraInfo: {[key:string] : any};
}
/**
* User Operation Action from devicemanager Fa.
*
* @systemapi this method can be used only by system applications.
*/
enum UserOperationAction {
/**
* allow authentication
*/
ACTION_ALLOW_AUTH = 0,
/**
* cancel authentication
*/
ACTION_CANCEL_AUTH = 1,
/**
* user operation timeout for authentication confirm
*/
ACTION_AUTH_CONFIRM_TIMEOUT = 2,
/**
* cancel pincode display
*/
ACTION_CANCEL_PINCODE_DISPLAY = 3,
/**
* cancel pincode input
*/
ACTION_CANCEL_PINCODE_INPUT = 4,
}
/**
* Creates a {@code DeviceManager} instance.
*
* <p>To manage devices, you must first call this method to obtain a {@code DeviceManager} instance and then
* use this instance to call other device management methods.
*
* @param bundleName Indicates the bundle name of the application.
* @param callback Indicates the callback to be invoked upon {@code DeviceManager} instance creation.
*/
function createDeviceManager(bundleName: string, callback: AsyncCallback<DeviceManager>): void;
/**
* Provides methods for managing devices.
*/
interface DeviceManager {
/**
* Releases the {@code DeviceManager} instance after the methods for device management are no longer used.
*/
release(): void;
/**
* Obtains a list of trusted devices.
*
* @param options Indicates the extra parameters to be passed to this method for device filtering or sorting.
* This parameter can be null. For details about available values, see {@link #TARGET_PACKAGE_NAME} and
* {@link #SORT_TYPE}.
* @return Returns a list of trusted devices.
*/
getTrustedDeviceListSync(): Array<DeviceInfo>;
/**
* Start to discover device.
*
* @param bundleName Indicates the bundle name of the application.
* @param subscribeInfo subscribe info to discovery device
* @systemapi this method can be used only by system applications.
*/
startDeviceDiscovery(subscribeInfo: SubscribeInfo): void;
/**
* Stop to discover device.
*
* @param bundleName Indicates the bundle name of the application.
* @param subscribeId Service subscribe ID
* @systemapi this method can be used only by system applications.
*/
stopDeviceDiscovery(subscribeId: number): void;
/**
* Authenticate the specified device.
*
* @param deviceInfo deviceInfo of device to authenticate
* @param authparam authparam of device to authenticate
* @param callback Indicates the callback to be invoked upon authenticateDevice
* @systemapi this method can be used only by system applications.
*/
authenticateDevice(deviceInfo: DeviceInfo, authparam: AuthParam, callback: AsyncCallback<{deviceId: string, pinTone ?: number}>): void;
/**
* verify auth info, such as pin code.
*
* @param authInfo device auth info o verify
* @param callback Indicates the callback to be invoked upon verifyAuthInfo
* @systemapi this method can be used only by system applications.
*/
verifyAuthInfo(authInfo: AuthInfo, callback: AsyncCallback<{deviceId: string, level: number}>): void;
/**
* Get authenticate parameters for peer device, this interface can only used by devicemanager Fa.
*
* @param authParam authparam for peer device
* @systemapi this method can be used only by system applications.
*/
getAuthenticationParam(): AuthParam;
/**
* Set user Operation from devicemanager Fa, this interface can only used by devicemanager Fa.
*
* @param operateAction User Operation Actions.
* @systemapi this method can be used only by system applications.
*/
setUserOperation(operateAction: UserOperationAction): void;
/**
* Register a callback from deviceManager service so that the devicemanager Fa can be notified when some events happen.
* this interface can only used by devicemanager Fa.
*
* @param callback for devicemanager Fa to register.
* @systemapi this method can be used only by system applications.
*/
on(type: 'dmFaCallback', callback: Callback<{ param: string}>): void;
/**
* UnRegister dmFaCallback, this interface can only used by devicemanager Fa.
*
* @param callback for devicemanager Fa to register.
* @systemapi this method can be used only by system applications.
*/
off(type: 'dmFaCallback', callback?: Callback<{ param: string}>): void;
/**
* Register a device state callback so that the application can be notified upon device state changes based on
* the application bundle name.
*
* @param bundleName Indicates the bundle name of the application.
* @param callback Indicates the device state callback to register.
*/
on(type: 'deviceStateChange', callback: Callback<{ action: DeviceStateChangeAction, device: DeviceInfo }>): void;
/**
* UnRegister device state callback based on the application bundle name.
*
* @param bundleName Indicates the bundle name of the application.
* @param callback Indicates the device state callback to register.
*/
off(type: 'deviceStateChange', callback?: Callback<{ action: DeviceStateChangeAction, device: DeviceInfo }>): void;
/**
* Register a device found callback so that the application can be notified when the device was found
*
* @param callback Indicates the device found callback to register.
* @systemapi this method can be used only by system applications.
*/
on(type: 'deviceFound', callback: Callback<{ subscribeId: number, device: DeviceInfo }>): void;
/**
* UnRegister a device found callback so that the application can be notified when the device was found
*
* @param callback Indicates the device found callback to register.
* @systemapi this method can be used only by system applications.
*/
off(type: 'deviceFound', callback?: Callback<{ subscribeId: number, device: DeviceInfo }>): void;
/**
* Register a device found result callback so that the application can be notified when the device discover was failed
*
* @param callback Indicates the device found result callback to register.
* @systemapi this method can be used only by system applications.
*/
on(type: 'discoverFail', callback: Callback<{ subscribeId: number, reason: number }>): void;
/**
* UnRegister a device found result callback so that the application can be notified when the device discover was failed
*
* @param callback Indicates the device found result callback to register.
* @systemapi this method can be used only by system applications.
*/
off(type: 'discoverFail', callback?: Callback<{ subscribeId: number, reason: number }>): void;
/**
* Register a serviceError callback so that the application can be notified when devicemanager service died
*
* @param callback Indicates the service error callback to register.
*/
on(type: 'serviceDie', callback: () => void): void;
/**
* UnRegister a serviceError callback so that the application can be notified when devicemanager service died
*
* @param callback Indicates the service error callback to register.
*/
off(type: 'serviceDie', callback?: () => void): void;
}
}
export default deviceManager;
-57
View File
@@ -1,57 +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.
*/
// Top-level build file where you can add configuration options common to all sub-projects/modules.
apply plugin: 'com.huawei.ohos.app'
ohos {
compileSdkVersion 6
defaultConfig {
compatibleSdkVersion 6
}
}
buildscript {
repositories {
maven {
url 'http://repo.ark.tools.huawei.com/artifactory/maven-public/'
}
maven {
url 'https://mirrors.huaweicloud.com/repository/maven/'
}
maven {
url 'https://developer.huawei.com/repo/'
}
jcenter()
}
dependencies {
classpath 'com.huawei.ohos:hap:2.4.4.3-RC'
}
}
allprojects {
repositories {
maven {
url 'http://repo.ark.tools.huawei.com/artifactory/maven-public/'
}
maven {
url 'https://mirrors.huaweicloud.com/repository/maven/'
}
maven {
url 'https://developer.huawei.com/repo/'
}
jcenter()
}
}
-42
View File
@@ -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.
*/
apply plugin: 'com.huawei.ohos.hap'
apply plugin: 'com.huawei.ohos.decctest'
//For instructions on signature configuration, see https://developer.harmonyos.com/cn/docs/documentation/doc-guides/ide_debug_device-0000001053822404#section1112183053510
ohos {
compileSdkVersion 6
defaultConfig {
compatibleSdkVersion 6
}
buildTypes {
release {
proguardOpt {
proguardEnabled false
rulesFiles 'proguard-rules.pro'
}
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar', '*.har'])
testImplementation 'junit:junit:4.13'
ohosTestImplementation 'com.huawei.ohos.testkit:runner:1.0.0.200'
}
decc {
supportType = ['html', 'xml']
}
-61
View File
@@ -1,61 +0,0 @@
{
"app": {
"bundleName": "com.ohos.devicemanagerui",
"vendor": "ohos",
"version": {
"code": 1000000,
"name": "1.0.0"
}
},
"deviceConfig": {},
"module": {
"package": "com.ohos.devicemanagerui",
"name": ".MyApplication",
"mainAbility": "com.ohos.devicemanagerui.MainAbility",
"deviceType": [
"phone",
"tablet",
"tv",
"wearable"
],
"distro": {
"deliveryWithInstall": true,
"moduleName": "entry",
"moduleType": "entry",
"installationFree": false
},
"abilities": [
{
"skills": [
{
"entities": [
"entity.system.home"
],
"actions": [
"action.system.home"
]
}
],
"visible": true,
"name": "com.ohos.devicemanagerui.MainAbility",
"icon": "$media:icon",
"description": "$string:mainability_description",
"label": "$string:entry_MainAbility",
"type": "page",
"launchType": "standard"
}
],
"js": [
{
"pages": [
"pages/index/index"
],
"name": "default",
"window": {
"designWidth": 720,
"autoDesignWidth": true
}
}
]
}
}
-23
View File
@@ -1,23 +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.
*/
export default {
onCreate() {
console.info('AceApplication onCreate');
},
onDestroy() {
console.info('AceApplication onDestroy');
}
};
@@ -1,4 +0,0 @@
{
"strings": {
}
}
@@ -1,4 +0,0 @@
{
"strings": {
}
}
@@ -1,169 +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.
*/
.container {
flex-direction: column;
justify-content: center;
align-items: center;
opacity: 0.8;
background-color: azure;
}
.container > div {
flex-direction: column;
justify-content: center;
align-items: center;
}
.main-pin > .pin-numb {
flex-direction: row;
justify-content: space-around;
align-items: center;
padding: 15px 30px 10px 30px;
}
.main-pin > .pin-numb > .pin-numb-item {
font-size: 30px;
line-height: 30px;
height: 40px;
padding-bottom: 5px;
font-weight: 800;
width: 30px;
border-bottom-width: 2px;
border-bottom-color: darkgray;
text-align: center;
}
.main-pin > .input {
flex-direction: row;
justify-content: space-around;
align-items: center;
padding: 5px 30px 5px 30px;
}
.main-pin > .input > .numb {
text-color: black;
padding: 5px;
flex-shrink: 0;
flex-basis: 60px;
background-color: white;
border: 1px;
}
.join-auth {
padding-top: 30px;
}
.join-auth-image > image {
height: 170px;
}
.join-authorize {
padding-top: 10px;
}
.join-pin {
padding: 10px 0;
}
.join-pin > .pin {
font-size: 50px;
line-height: 90px;
font-weight: bolder;
color: #000000;
}
.join-auth > .title,
.join-auth-image > .title,
.join-authorize > .title {
font-size: 18px;
line-height: 80px;
font-weight: 800;
color: #000000;
}
.join-auth > .title {
line-height: 40px;
}
.join-auth-image > .title {
line-height: 26px;
}
.join-pin > .title {
font-size: 28px;
line-height: 60px;
font-weight: 800;
}
.main-pin > .title {
font-size: 30px;
line-height: 40px;
font-weight: bolder;
}
.join-auth > .title-tip,
.join-auth-image > .title-tip,
.main-pin > .title-tip,
.join-authorize > .title-tip {
font-size: 15px;
line-height: 40px;
color: #5A5A5A;
}
.join-auth > .title-tip {
line-height: 40px;
}
.join-auth-image > .title-tip {
line-height: 24px;
}
.join-pin > .title-tip {
font-size: 20px;
line-height: 50px;
font-weight: 600;
}
.main-pin > .title-tip {
font-size: 18px;
line-height: 30px;
font-weight: 800;
}
.join-auth > .dialog-foot,
.join-auth-image > .dialog-foot,
.join-authorize > .dialog-foot {
flex-direction: row;
justify-content: center;
align-items: center;
justify-content: space-around;
margin: 80px 20px 30px 20px;
}
.join-authorize > .dialog-foot {
margin: 100px 20px 30px 20px;
}
.join-auth-image > .dialog-foot {
margin: 10px 20px 10px 20px;
}
.join-pin > .dialog-foot {
margin: 10px 20px 10px 20px;
}
.join-auth .button-cancel,
.join-auth-image .button-cancel,
.join-authorize .button-cancel {
width: 160px;
height: 36px;
}
.join-pin .button-cancel {
width: 100%;
font-size: 26px;
height: 50px;
}
.join-auth .button-ok,
.join-auth-image .button-ok,
.join-authorize .button-ok {
width: 150px;
height: 36px;
}
@@ -1,98 +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.
*/
-->
<div class="container">
<div if="{{status == 'main-pin'}}" class="main-pin">
<text class="title">PIN码连接</text>
<text class="title-tip">请输入平板上显示的PIN码</text>
<div class="pin-numb" >
<text class="pin-numb-item">{{pin[0]}}</text>
<text class="pin-numb-item">{{pin[1]}}</text>
<text class="pin-numb-item">{{pin[2]}}</text>
<text class="pin-numb-item">{{pin[3]}}</text>
<text class="pin-numb-item">{{pin[4]}}</text>
<text class="pin-numb-item">{{pin[5]}}</text>
</div>
<div class="input" >
<button @click="mainInputPin(1)" type="text" class="numb">1</button>
<button @click="mainInputPin(2)" type="text" class="numb">2</button>
<button @click="mainInputPin(3)" type="text" class="numb">3</button>
<button @click="mainInputPin(4)" type="text" class="numb">4</button>
</div>
<div class="input" >
<button @click="mainInputPin(5)" type="text" class="numb">5</button>
<button @click="mainInputPin(6)" type="text" class="numb">6</button>
<button @click="mainInputPin(7)" type="text" class="numb">7</button>
<button @click="mainInputPin(8)" type="text" class="numb">8</button>
</div>
<div class="input" >
<button @click="mainInputPin(9)" type="text" class="numb">9</button>
<button @click="mainInputPin(0)" type="text" class="numb">0</button>
<button @click="mainInputPinBack" type="text" class="numb">删除</button>
<button @click="mainInputPinCancel" type="text" class="numb">取消</button>
</div>
</div>
<div if="{{status == 'join-authorize'}}" class="join-authorize">
<text class="title">是否允许{{statusInfo.deviceName}}连接本机</text>
<text class="title-tip">用于资源访问</text>
<div class="dialog-foot">
<button @click="joinAuthorizeCancel" type="text" class="button-cancel">
取消({{ timeRemaining }}
</button>
<button @click="joinAuthorizeOk" class="button-ok" type="capsule">
允许
</button>
</div>
</div>
<div if="{{status == 'join-auth'}}" class="join-auth">
<text class="title-tip">{{ statusInfo.appName }}</text>
<text class="title">是否允许打开apply auth?</text>
<text class="title-tip">来自{{statusInfo.deviceName}}</text>
<div class="dialog-foot">
<button @click="joinAuthCancel" type="text" class="button-cancel">
取消({{ timeRemaining }}
</button>
<button @click="joinAuthOk" class="button-ok" type="capsule">
允许
</button>
</div>
</div>
<div if="{{status == 'join-auth-image'}}" class="join-auth-image">
<image src="{{ statusInfo.appIcon }}"></image>
<text class="title-tip">{{ statusInfo.appName }}</text>
<text class="title">是否允许打开apply auth?</text>
<text class="title-tip">来自{{statusInfo.deviceName}}</text>
<div class="dialog-foot">
<button @click="joinAuthImageCancel" type="text" class="button-cancel">
取消({{ timeRemaining }}
</button>
<button @click="joinAuthImageOk" class="button-ok" type="capsule">
允许
</button>
</div>
</div>
<div if="{{status == 'join-pin'}}" class="join-pin">
<text class="title">PIN码连接</text>
<text class="title-tip">请在主控端输入连接码进行验证</text>
<text class="pin">{{statusInfo.pinCode.split('').join(' ')}}</text>
<div class="dialog-foot">
<button @click="joinPinCancel" type="text" class="button-cancel">
取消
</button>
</div>
</div>
</div>
@@ -1,331 +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.
*/
import router from '@system.router';
import deviceManager from '@ohos.distributedHardware.deviceManager';
function uint8ArrayToBase64(array) {
array = new Uint8Array(array);
let table = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','0','1','2','3','4','5','6','7','8','9','+','/'],
base64Str = '', length = array.byteLength, i = 0;
for(i = 0; length - i >= 3; i += 3) {
let num1 = array[i], num2 = array[i + 1], num3 = array[i + 2];
base64Str += table[num1 >>> 2] + table[((num1 & 0b11) << 4) | (num2 >>> 4)] + table[((num2 & 0b1111) << 2) | (num3 >>> 6)] + table[num3 & 0b111111];
}
const lastByte = length - i;
if (lastByte === 1) {
const lastNum1 = array[i];
base64Str += table[lastNum1 >>> 2] + table[((lastNum1 & 0b11) << 4)] + '==';
} else if (lastByte === 2) {
const lastNum1 = array[i];
const lastNum2 = array[i + 1];
base64Str += table[lastNum1 >>> 2] + table[((lastNum1 & 0b11) << 4) | (lastNum2 >>> 4)] + table[(lastNum2 & 0b1111) << 2] + '=';
}
return 'data:image/png;base64,' + base64Str;
}
const TAG = "DeviceManagerUI:";
let dmClass;
export default {
data: {
// showType: ['main-pin','join-authorize','join-auth','join-auth-image','join-pin']
status: "",
// showInfo
statusInfo: {
deviceName: "AppName",
appName: 'PackageName',
appIcon: null,
pinCode: '',
pinToken: ''
},
// join: join-authorize timing
timeRemaining: 0,
// input pinCode
pin: ['','','','','',''],
// input pinCode next number
pinNumb: 0
},
log(m) {
console.info(TAG + m);
},
onDestroy() {
if (dmClass != null) {
dmClass.off('dmFaCallback');
dmClass.off('deviceStateChange');
dmClass.off('serviceDie');
dmClass.release();
dmClass = null
}
},
onShow() {
if (dmClass) {
this.initStatue()
} else {
this.log('createDeviceManager')
deviceManager.createDeviceManager('com.ohos.devicemanagerui', (err, dm) => {
this.log("createDeviceManager err:" + JSON.stringify(err) + ' --success:' + JSON.stringify(dm))
if (err) return;
dmClass = dm;
dmClass.on('dmFaCallback', () => router.back())
this.initStatue()
});
}
},
onHide() {
this.timeRemaining = 0
},
/**
* Get authentication param
*/
initStatue() {
this.log('initStatue')
const data = dmClass.getAuthenticationParam()
this.log('getAuthenticationParam:' + JSON.stringify(data))
// Authentication type, 1 for pin code.
if (data && data.authType == 1) {
this.statusInfo = {
deviceName: data.extraInfo.PackageName,
appName: data.extraInfo.appName,
appIcon: uint8ArrayToBase64(data.appIcon),
pinCode: data.extraInfo.pinCode + '',
pinToken: data.extraInfo.pinToken
}
// direction: 1(main)/0(join)
if (data.extraInfo.direction == 1) {
this.mainPin()
} else if (data.appIcon) {
this.joinAuthImage()
} else if (data.extraInfo.business == 0) {
// business: 0(FA流转)/1(资源访问)
this.joinAuth()
} else {
this.joinAuthorize()
}
}
},
/**
* Set user Operation from devicemanager Fa, this interface can only used by devicemanager Fa.
*
* @param operateAction User Operation Actions.
* ACTION_ALLOW_AUTH = 0, allow authentication
* ACTION_CANCEL_AUTH = 1, cancel authentication
* ACTION_AUTH_CONFIRM_TIMEOUT = 2, user operation timeout for authentication confirm
* ACTION_CANCEL_PINCODE_DISPLAY = 3, cancel pinCode display
* ACTION_CANCEL_PINCODE_INPUT = 4, cancel pinCode input
*/
setUserOperation(operation) {
this.log('setUserOperation: ' + operation)
if (dmClass != null) {
var data = dmClass.setUserOperation(operation);
this.log('setUserOperation result: ' + JSON.stringify(data))
} else {
this.log('deviceManagerObject not exit')
}
},
/**
* verify auth info, such as pin code.
* @param pinCode
* @return
*/
verifyAuthInfo(pinCode) {
this.log('verifyAuthInfo: ' + pinCode)
if (dmClass != null) {
dmClass.verifyAuthInfo({
"authType": 1,
"token": this.statusInfo.pinToken,
"extraInfo": {
"pinCode": +pinCode
}
}, (err, data) => {
if (err) {
this.log("verifyAuthInfo err:" + JSON.stringify(err))
}
this.log("verifyAuthInfo result:" + JSON.stringify(data))
router.back()
});
} else {
this.log('deviceManagerObject not exit')
}
},
/**
* Input pinCode at the main control terminal
*/
mainPin() {
this.status = 'main-pin'
},
/**
* Enter a number with the keyboard
* @param s
* @return
*/
mainInputPin(s) {
this.log('mainInputPin input: ' + s + '-' + this.pin)
if (this.pinNumb == 6) return
if (this.pinNumb < 6) {
this.pin[this.pinNumb] = s
++this.pinNumb
this.pin = [...this.pin]
}
this.log('mainInputPin pin: ' + this.pin + '-' + this.pin.join(''))
if (this.pinNumb == 6) {
// input end
this.log('mainInputPin end: ' + this.pin + '-' + this.pin.join(''))
this.verifyAuthInfo(this.pin.join(''))
}
},
/**
* Keyboard delete number
*/
mainInputPinBack() {
if (this.pinNumb > 0) {
--this.pinNumb
this.pin[this.pinNumb] = ''
this.pin = [...this.pin]
}
},
/**
* Cancel pinCode input
*/
mainInputPinCancel() {
this.setUserOperation(4)
},
/**
* Join end authorization, business(FA流转)/1(资源访问): 0
*/
joinAuthorize() {
this.status = 'join-authorize'
this.timing(60, 'join-authorize', () => {
this.setUserOperation(2)
router.back()
})
},
/**
* Join end authorization, business(FA流转)/1(资源访问): 1
*/
joinAuth() {
this.status = 'join-auth'
this.timing(60, 'join-auth', () => {
this.setUserOperation(2)
router.back()
})
},
/**
* Join end authorization, business(FA流转)/1(资源访问): 1, show application icon
*/
joinAuthImage() {
this.status = 'join-auth-image'
this.timing(60, 'join-auth-image', () => {
this.setUserOperation(2)
router.back()
})
},
/**
* Display pinCode at join end
*/
joinPin() {
this.status = 'join-pin'
},
/**
* Cancel authorization
*/
joinAuthorizeCancel() {
this.setUserOperation(1)
router.back()
},
/**
* Confirm authorization
*/
joinAuthorizeOk() {
this.setUserOperation(0)
this.joinPin()
},
/**
* Cancel authorization
*/
joinAuthCancel() {
this.setUserOperation(1)
router.back()
},
/**
* Confirm authorization
*/
joinAuthOk() {
this.setUserOperation(0)
this.joinPin()
},
/**
* Cancel authorization
*/
joinAuthImageCancel() {
this.setUserOperation(1)
router.back()
},
/**
* Confirm authorization
*/
joinAuthImageOk() {
this.setUserOperation(0)
this.joinPin()
},
/**
* Cancel authorization
*/
joinPinCancel() {
this.setUserOperation(3)
router.back()
},
/**
* Pure function countdown
* @param numb second
* @param status
* @param callback
* @return
*/
timing(numb, status, callback) {
this.timeRemaining = numb
const next = () => {
if (status != this.status) return
--this.timeRemaining
if (this.timeRemaining > 0) {
setTimeout(next, 1000)
} else {
callback()
}
}
next()
}
}
@@ -1,12 +0,0 @@
{
"string": [
{
"name": "entry_MainAbility",
"value": "entry_MainAbility"
},
{
"name": "mainability_description",
"value": "JS_Empty Ability"
}
]
}
Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.6 KiB

-1
View File
@@ -1 +0,0 @@
include ':entry'
+12 -9
View File
@@ -25,11 +25,11 @@ if (defined(ohos_lite)) {
"include/ipc",
"include/ipc/lite",
"include/notify",
"${utils_path}/include/log",
"${utils_path}/include/ipc/lite",
"${common_path}/include",
"${common_path}/include/ipc",
"${common_path}/include/ipc/model",
"${common_path}/include",
"${utils_path}/include",
"${utils_path}/include/ipc/lite",
]
include_dirs += [
"//utils/native/lite/include",
@@ -70,18 +70,20 @@ if (defined(ohos_lite)) {
} else {
ohos_shared_library("devicemanagersdk") {
include_dirs = [
"//utils/native/base/include",
"//utils/system/safwk/native/include",
"include",
"include/ipc/standard",
"include/ipc",
"include/ipc/standard",
"include/notify",
"${utils_path}/include/log",
"${common_path}/include",
"${common_path}/include/ipc",
"${common_path}/include/ipc/model",
"${utils_path}/include",
"${utils_path}/include/ipc/standard",
"${common_path}/include",
"//third_party/json/include",
"//utils/native/base/include",
"//utils/system/safwk/native/include",
"//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_base/include",
"//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_core/include/bundlemgr",
]
sources = [
@@ -97,6 +99,7 @@ if (defined(ohos_lite)) {
deps = [
"${utils_path}:devicemanagerutils",
"//foundation/aafwk/standard/interfaces/innerkits/want:want",
"//utils/native/base:utils",
]
@@ -119,4 +122,4 @@ if (defined(ohos_lite)) {
part_name = "device_manager_base"
}
}
}
@@ -4,7 +4,7 @@
* 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
* 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,
@@ -13,43 +13,48 @@
* limitations under the License.
*/
#ifndef DEVICE_MANAGER_H
#define DEVICE_MANAGER_H
#ifndef OHOS_DEVICE_MANAGER_H
#define OHOS_DEVICE_MANAGER_H
#include <vector>
#include <string>
#include <memory>
#include <string>
#include <vector>
#include "device_manager_callback.h"
#include "dm_device_info.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> dmInitCallback) = 0;
virtual int32_t UnInitDeviceManager(std::string &pkgName) = 0;
virtual int32_t GetTrustedDeviceList(std::string &pkgName, std::string &extra,
std::vector<DmDeviceInfo> &deviceList) = 0;
virtual int32_t RegisterDevStateCallback(std::string &pkgName, std::string &extra,
std::shared_ptr<DeviceStateCallback> callback) = 0;
virtual int32_t UnRegisterDevStateCallback(std::string &pkgName) = 0;
virtual int32_t StartDeviceDiscovery(std::string &pkgName, DmSubscribeInfo &subscribeInfo,
std::shared_ptr<DiscoverCallback> 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<AuthenticateCallback> callback) = 0;
virtual int32_t CheckAuthentication(std::string &pkgName, std::string &authPara,
std::shared_ptr<CheckAuthCallback> 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<DeviceManagerFaCallback> callback) = 0;
virtual int32_t UnRegisterDeviceManagerFaCallback(std::string &pkgName) = 0;
virtual int32_t InitDeviceManager(const std::string &pkgName, std::shared_ptr<DmInitCallback> dmInitCallback) = 0;
virtual int32_t UnInitDeviceManager(const std::string &pkgName) = 0;
virtual int32_t GetTrustedDeviceList(const std::string &pkgName, const std::string &extra,
std::vector<DmDeviceInfo> &deviceList) = 0;
virtual int32_t GetLocalDeviceInfo(const std::string &pkgName, DmDeviceInfo &deviceInfo) = 0;
virtual int32_t RegisterDevStateCallback(const std::string &pkgName, const std::string &extra,
std::shared_ptr<DeviceStateCallback> callback) = 0;
virtual int32_t UnRegisterDevStateCallback(const std::string &pkgName) = 0;
virtual int32_t StartDeviceDiscovery(const std::string &pkgName, const DmSubscribeInfo &subscribeInfo,
const std::string &extra, std::shared_ptr<DiscoveryCallback> callback) = 0;
virtual int32_t StopDeviceDiscovery(const std::string &pkgName, uint16_t subscribeId) = 0;
virtual int32_t AuthenticateDevice(const std::string &pkgName, int32_t authType, const DmDeviceInfo &deviceInfo,
const std::string &extra, std::shared_ptr<AuthenticateCallback> callback) = 0;
virtual int32_t UnAuthenticateDevice(const std::string &pkgName, const std::string &deviceId) = 0;
virtual int32_t VerifyAuthentication(const std::string &pkgName, const std::string &authPara,
std::shared_ptr<VerifyAuthCallback> callback) = 0;
virtual int32_t RegisterDeviceManagerFaCallback(const std::string &pkgName,
std::shared_ptr<DeviceManagerFaCallback> callback) = 0;
virtual int32_t UnRegisterDeviceManagerFaCallback(const std::string &pkgName) = 0;
virtual int32_t GetFaParam(const std::string &pkgName, DmAuthParam &faParam) = 0;
virtual int32_t SetUserOperation(const std::string &pkgName, int32_t action) = 0;
virtual int32_t GetUdidByNetworkId(const std::string &pkgName, const std::string &netWorkId, std::string &udid) = 0;
virtual int32_t GetUuidByNetworkId(const std::string &pkgName, const std::string &netWorkId, std::string &uuid) = 0;
};
} // namespace DistributedHardware
} // namespace OHOS
#endif // OHOS_DEVICE_MANAGER_H
#endif // DEVICE_MANAGER_H
@@ -4,7 +4,7 @@
* 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
* 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,
@@ -13,8 +13,8 @@
* limitations under the License.
*/
#ifndef OHOS_DEVICE_MANAGER_CALLBACK_H
#define OHOS_DEVICE_MANAGER_CALLBACK_H
#ifndef OHOS_DM_CALLBACK_H
#define OHOS_DM_CALLBACK_H
#include <cstdint>
#include <string>
@@ -25,44 +25,56 @@ namespace OHOS {
namespace DistributedHardware {
class DmInitCallback {
public:
virtual ~DmInitCallback() {}
virtual ~DmInitCallback()
{
}
virtual void OnRemoteDied() = 0;
};
class DeviceStateCallback {
public:
virtual ~DeviceStateCallback() {}
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;
virtual void OnDeviceReady(const DmDeviceInfo &deviceInfo) = 0;
};
class DiscoverCallback {
class DiscoveryCallback {
public:
virtual ~DiscoverCallback() {}
virtual ~DiscoveryCallback()
{
}
virtual void OnDiscoverySuccess(uint16_t subscribeId) = 0;
virtual void OnDiscoverFailed(uint16_t subscribeId, int32_t failedReason) = 0;
virtual void OnDiscoveryFailed(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;
virtual ~AuthenticateCallback()
{
}
virtual void OnAuthResult(const std::string &deviceId, const std::string &token, int32_t status,
int32_t reason) = 0;
};
class CheckAuthCallback {
class VerifyAuthCallback {
public:
virtual ~CheckAuthCallback() {}
virtual void OnCheckAuthResult(std::string &deviceId, int32_t resultCode, int32_t flag) = 0;
virtual ~VerifyAuthCallback()
{
}
virtual void OnVerifyAuthResult(const std::string &deviceId, int32_t resultCode, int32_t flag) = 0;
};
class DeviceManagerFaCallback {
public:
virtual ~DeviceManagerFaCallback() {}
virtual void OnCall(std::string &paramJson) = 0;
virtual ~DeviceManagerFaCallback()
{
}
virtual void OnCall(const std::string &paramJson) = 0;
};
} // namespace DistributedHardware
} // namespace OHOS
#endif // OHOS_DEVICE_MANAGER_CALLBACK_H
#endif // OHOS_DM_CALLBACK_H
@@ -4,7 +4,7 @@
* 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
* 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,
@@ -16,41 +16,57 @@
#ifndef OHOS_DEVICE_MANAGER_IMPL_H
#define OHOS_DEVICE_MANAGER_IMPL_H
#include <memory>
#include "device_manager.h"
#include "ipc_client_proxy.h"
#include "ipc_client_manager.h"
#include "single_instance.h"
#include "ipc_client_proxy.h"
namespace OHOS {
namespace DistributedHardware {
class DeviceManagerImpl : public DeviceManager {
DECLARE_SINGLE_INSTANCE(DeviceManagerImpl);
public:
virtual int32_t InitDeviceManager(std::string &pkgName,
std::shared_ptr<DmInitCallback> dmInitCallback) override;
virtual int32_t UnInitDeviceManager(std::string &pkgName) override;
virtual int32_t GetTrustedDeviceList(std::string &pkgName, std::string &extra,
std::vector<DmDeviceInfo> &deviceList) override;
virtual int32_t RegisterDevStateCallback(std::string &pkgName, std::string &extra,
std::shared_ptr<DeviceStateCallback> callback) override;
virtual int32_t UnRegisterDevStateCallback(std::string &pkgName) override;
virtual int32_t StartDeviceDiscovery(std::string &pkgName, DmSubscribeInfo &subscribeInfo,
std::shared_ptr<DiscoverCallback> 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<AuthenticateCallback> callback) override;
virtual int32_t CheckAuthentication(std::string &pkgName, std::string &authPara,
std::shared_ptr<CheckAuthCallback> 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<DeviceManagerFaCallback> callback) override;
virtual int32_t UnRegisterDeviceManagerFaCallback(std::string &pkgName) override;
static DeviceManagerImpl &GetInstance();
public:
virtual int32_t InitDeviceManager(const std::string &pkgName,
std::shared_ptr<DmInitCallback> dmInitCallback) override;
virtual int32_t UnInitDeviceManager(const std::string &pkgName) override;
virtual int32_t GetTrustedDeviceList(const std::string &pkgName, const std::string &extra,
std::vector<DmDeviceInfo> &deviceList) override;
virtual int32_t GetLocalDeviceInfo(const std::string &pkgName, DmDeviceInfo &deviceInfo) override;
virtual int32_t RegisterDevStateCallback(const std::string &pkgName, const std::string &extra,
std::shared_ptr<DeviceStateCallback> callback) override;
virtual int32_t UnRegisterDevStateCallback(const std::string &pkgName) override;
virtual int32_t StartDeviceDiscovery(const std::string &pkgName, const DmSubscribeInfo &subscribeInfo,
const std::string &extra,
std::shared_ptr<DiscoveryCallback> callback) override;
virtual int32_t StopDeviceDiscovery(const std::string &pkgName, uint16_t subscribeId) override;
virtual int32_t AuthenticateDevice(const std::string &pkgName, int32_t authType, const DmDeviceInfo &deviceInfo,
const std::string &extra,
std::shared_ptr<AuthenticateCallback> callback) override;
virtual int32_t UnAuthenticateDevice(const std::string &pkgName, const std::string &deviceId) override;
virtual int32_t VerifyAuthentication(const std::string &pkgName, const std::string &authPara,
std::shared_ptr<VerifyAuthCallback> callback) override;
virtual int32_t RegisterDeviceManagerFaCallback(const std::string &packageName,
std::shared_ptr<DeviceManagerFaCallback> callback) override;
virtual int32_t UnRegisterDeviceManagerFaCallback(const std::string &pkgName) override;
virtual int32_t GetFaParam(const std::string &pkgName, DmAuthParam &faParam) override;
virtual int32_t SetUserOperation(const std::string &pkgName, int32_t action) override;
virtual int32_t GetUdidByNetworkId(const std::string &pkgName, const std::string &netWorkId,
std::string &udid) override;
virtual int32_t GetUuidByNetworkId(const std::string &pkgName, const std::string &netWorkId,
std::string &uuid) override;
private:
DeviceManagerImpl() = default;
~DeviceManagerImpl() = default;
DeviceManagerImpl(const DeviceManagerImpl &) = delete;
DeviceManagerImpl &operator=(const DeviceManagerImpl &) = delete;
DeviceManagerImpl(DeviceManagerImpl &&) = delete;
DeviceManagerImpl &operator=(DeviceManagerImpl &&) = delete;
private:
bool isSystemAppCalling(void);
private:
std::shared_ptr<IpcClientProxy> ipcClientProxy_ =
std::make_shared<IpcClientProxy>(std::make_shared<IpcClientManager>());
@@ -4,7 +4,7 @@
* 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
* 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,
@@ -13,8 +13,8 @@
* limitations under the License.
*/
#ifndef OHOS_DEVICE_MANAGER_APP_IMAGE_INFO_H
#define OHOS_DEVICE_MANAGER_APP_IMAGE_INFO_H
#ifndef OHOS_DM_APP_IMAGE_INFO_H
#define OHOS_DM_APP_IMAGE_INFO_H
#include <cstdint>
@@ -48,7 +48,7 @@ public:
return;
}
appThumbnail = new (std::nothrow) uint8_t[appThumbnailLen_] {0};
appThumbnail = new (std::nothrow) uint8_t[appThumbnailLen_]{0};
if (appThumbnail != nullptr) {
appThumbnailLen = appThumbnailLen_;
}
@@ -56,7 +56,7 @@ public:
int32_t SetThumbnailData(uint8_t *srcBuffer, int32_t srcBufferLen, int32_t copyIndex, int32_t copyLen)
{
if (srcBuffer == nullptr || srcBufferLen <= 0 || copyLen > srcBufferLen || copyIndex < 0) {
if (srcBuffer == nullptr || srcBufferLen <= 0 || copyLen > srcBufferLen || copyIndex < 0) {
return -1;
}
@@ -94,7 +94,7 @@ public:
}
}
DmAppImageInfo& operator=(const DmAppImageInfo &other)
DmAppImageInfo &operator=(const DmAppImageInfo &other)
{
if (this != &other) {
SaveData(other.GetAppIcon(), other.GetAppIconLen(), other.GetAppThumbnail(), other.GetAppThumbnailLen());
@@ -102,8 +102,8 @@ public:
return *this;
}
DmAppImageInfo(DmAppImageInfo&&) = delete;
DmAppImageInfo& operator=(DmAppImageInfo&&) = delete;
DmAppImageInfo(DmAppImageInfo &&) = delete;
DmAppImageInfo &operator=(DmAppImageInfo &&) = delete;
int32_t GetAppIconLen() const
{
@@ -124,6 +124,7 @@ public:
{
return appThumbnail;
}
private:
void SaveData(const uint8_t *appIcon_, int32_t appIconLen_, const uint8_t *appThumbnail_, int32_t appThumbnailLen_)
{
@@ -140,7 +141,7 @@ private:
appIcon = nullptr;
appIconLen = 0;
}
appIcon = new (std::nothrow) uint8_t[appIconLen_] {0};
appIcon = new (std::nothrow) uint8_t[appIconLen_]{0};
}
if (appIcon != nullptr) {
appIconLen = appIconLen_;
@@ -160,7 +161,7 @@ private:
appThumbnail = nullptr;
appThumbnailLen = 0;
}
appThumbnail = new (std::nothrow) uint8_t[appThumbnailLen_] {0};
appThumbnail = new (std::nothrow) uint8_t[appThumbnailLen_]{0};
}
if (appThumbnail != nullptr) {
appThumbnailLen = appThumbnailLen_;
@@ -170,14 +171,15 @@ private:
}
}
}
private:
int32_t appIconLen {0};
uint8_t *appIcon {nullptr};
int32_t appThumbnailLen {0};
uint8_t *appThumbnail {nullptr};
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
#endif // OHOS_DM_APP_IMAGE_INFO_H
@@ -4,7 +4,7 @@
* 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
* 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,
@@ -13,8 +13,8 @@
* limitations under the License.
*/
#ifndef OHOS_DEVICE_MANAGER_DEVICE_INFO_H
#define OHOS_DEVICE_MANAGER_DEVICE_INFO_H
#ifndef OHOS_DM_DEVICE_INFO_H
#define OHOS_DM_DEVICE_INFO_H
#include <cstdint>
@@ -25,31 +25,34 @@
namespace OHOS {
namespace DistributedHardware {
typedef enum DMDeviceType {
typedef enum DmDeviceType {
DEVICE_TYPE_UNKNOWN = 0x00,
DEVICE_TYPE_WIFI_CAMERA = 0x08,
DEVICE_TYPE_AUDIO = 0x0A,
DEVICE_TYPE_PC = 0x0C,
DEVICE_TYPE_PHONE = 0x0E,
DEVICE_TYPE_PAD = 0x11,
DEVICE_TYPE_WATCH = 0x6D,
DEVICE_TYPE_CAR = 0x83,
DEVICE_TYPE_TV = 0x9C,
} DMDeviceType;
} DmDeviceType;
typedef enum DmDeviceState {
DEVICE_STATE_UNKNOWN = 0,
DEVICE_STATE_ONLINE = 1,
DEVICE_STATE_OFFLINE = 2,
DEVICE_INFO_CHANGED = 3,
DEVICE_INFO_READY = 4,
} DmDeviceState;
typedef struct DmDeviceInfo {
char deviceId[DM_MAX_DEVICE_ID_LEN];
char deviceName[DM_MAX_DEVICE_NAME_LEN];
DMDeviceType deviceTypeId;
uint16_t deviceTypeId;
} DmDeviceInfo;
typedef struct DmAuthParam {
std::string authToken;
std::string packageName;
std::string appName;
std::string appDescription;
@@ -60,6 +63,7 @@ typedef struct DmAuthParam {
int32_t pinToken;
DmAppImageInfo imageinfo;
} DmAuthParam;
} // namespace DistributedHardware
} // namespace OHOS
#endif // OHOS_DEVICE_MANAGER_DEVICE_INFO_H
#endif // OHOS_DM_DEVICE_INFO_H
@@ -4,7 +4,7 @@
* 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
* 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,
@@ -13,8 +13,8 @@
* limitations under the License.
*/
#ifndef OHOS_DEVICE_MANAGER_SUBSCRIBE_INFO_H
#define OHOS_DEVICE_MANAGER_SUBSCRIBE_INFO_H
#ifndef OHOS_DM_SUBSCRIBE_INFO_H
#define OHOS_DM_SUBSCRIBE_INFO_H
#include <stdbool.h>
@@ -26,7 +26,7 @@ typedef enum DmDiscoverMode {
/* Passive */
DM_DISCOVER_MODE_PASSIVE = 0x55,
/* Proactive */
DM_DISCOVER_MODE_ACTIVE = 0xAA
DM_DISCOVER_MODE_ACTIVE = 0xAA
} DmDiscoverMode;
typedef enum DmExchangeMedium {
@@ -76,4 +76,4 @@ typedef struct DmSubscribeInfo {
} DmSubscribeInfo;
} // namespace DistributedHardware
} // namespace OHOS
#endif // OHOS_DEVICE_MANAGER_SUBSCRIBE_INFO_H
#endif // OHOS_DM_SUBSCRIBE_INFO_H
@@ -4,7 +4,7 @@
* 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
* 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,
@@ -13,12 +13,12 @@
* limitations under the License.
*/
#ifndef OHOS_DEVICE_MANAGER_IPC_CLIENT_H
#define OHOS_DEVICE_MANAGER_IPC_CLIENT_H
#ifndef OHOS_DM_IPC_CLIENT_H
#define OHOS_DM_IPC_CLIENT_H
#include <cstdint>
#include <string>
#include <memory>
#include <string>
#include "ipc_req.h"
#include "ipc_rsp.h"
@@ -26,12 +26,13 @@
namespace OHOS {
namespace DistributedHardware {
class IpcClient {
DECLARE_IPC_INTERFACE(IpcClient);
DECLARE_IPC_INTERFACE(IpcClient);
public:
virtual int32_t Init(std::string &pkgName) = 0;
virtual int32_t UnInit(std::string &pkgName) = 0;
virtual int32_t Init(const std::string &pkgName) = 0;
virtual int32_t UnInit(const std::string &pkgName) = 0;
virtual int32_t SendRequest(int32_t cmdCode, std::shared_ptr<IpcReq> req, std::shared_ptr<IpcRsp> rsp) = 0;
};
} // namespace DistributedHardware
} // namespace OHOS
#endif // OHOS_DEVICE_MANAGER_IPC_CLIENT_H
#endif // OHOS_DM_IPC_CLIENT_H
@@ -4,7 +4,7 @@
* 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
* 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,
@@ -13,8 +13,8 @@
* limitations under the License.
*/
#ifndef OHOS_DEVICE_MANAGER_IPC_CLIENT_PROXY_H
#define OHOS_DEVICE_MANAGER_IPC_CLIENT_PROXY_H
#ifndef OHOS_DM_IPC_CLIENT_PROXY_H
#define OHOS_DM_IPC_CLIENT_PROXY_H
#include <cstdint>
#include <memory>
@@ -26,16 +26,19 @@
namespace OHOS {
namespace DistributedHardware {
class IpcClientProxy : public IpcClient {
DECLARE_IPC_INTERFACE(IpcClientProxy);
DECLARE_IPC_INTERFACE(IpcClientProxy);
public:
IpcClientProxy(std::shared_ptr<IpcClient> ipcClientManager) : ipcClientManager_(ipcClientManager) {};
IpcClientProxy(std::shared_ptr<IpcClient> ipcClientManager) : ipcClientManager_(ipcClientManager){};
public:
virtual int32_t Init(std::string &pkgName);
virtual int32_t UnInit(std::string &pkgName);
virtual int32_t Init(const std::string &pkgName);
virtual int32_t UnInit(const std::string &pkgName);
virtual int32_t SendRequest(int32_t cmdCode, std::shared_ptr<IpcReq> req, std::shared_ptr<IpcRsp> rsp);
private:
std::shared_ptr<IpcClient> ipcClientManager_ {nullptr};
std::shared_ptr<IpcClient> ipcClientManager_{nullptr};
};
} // namespace DistributedHardware
} // namespace OHOS
#endif // OHOS_DEVICE_MANAGER_IPC_CLIENT_PROXY_H
#endif // OHOS_DM_IPC_CLIENT_PROXY_H
@@ -4,7 +4,7 @@
* 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
* 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,
@@ -13,12 +13,12 @@
* limitations under the License.
*/
#ifndef OHOS_DEVICE_MANAGER_IPC_CLIENT_MANAGER_H
#define OHOS_DEVICE_MANAGER_IPC_CLIENT_MANAGER_H
#ifndef OHOS_DM_IPC_CLIENT_MANAGER_H
#define OHOS_DM_IPC_CLIENT_MANAGER_H
#include <cstdint>
#include <string>
#include <set>
#include <string>
#include "ipc_client.h"
#include "ipc_client_server_proxy.h"
@@ -26,17 +26,20 @@
namespace OHOS {
namespace DistributedHardware {
class IpcClientManager : public IpcClient {
DECLARE_IPC_INTERFACE(IpcClientManager);
DECLARE_IPC_INTERFACE(IpcClientManager);
public:
virtual int32_t Init(std::string &pkgName) override;
virtual int32_t UnInit(std::string &pkgName) override;
virtual int32_t Init(const std::string &pkgName) override;
virtual int32_t UnInit(const std::string &pkgName) override;
virtual int32_t SendRequest(int32_t cmdCode, std::shared_ptr<IpcReq> req, std::shared_ptr<IpcRsp> rsp) override;
private:
bool IsInit(std::string &pkgName);
bool IsInit(const std::string &pkgName);
private:
IpcClientServerProxy serverProxy_;
std::set<std::string> packageInitSet_;
};
} // namespace DistributedHardware
} // namespace OHOS
#endif // OHOS_DEVICE_MANAGER_IPC_CLIENT_MANAGER_H
#endif // OHOS_DM_IPC_CLIENT_MANAGER_H
@@ -4,7 +4,7 @@
* 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
* 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,
@@ -13,33 +13,34 @@
* limitations under the License.
*/
#ifndef OHOS_DEVICE_MANAGER_IPC_CLIENT_SERVER_PROXY_H
#define OHOS_DEVICE_MANAGER_IPC_CLIENT_SERVER_PROXY_H
#ifndef OHOS_DM_IPC_CLIENT_SERVER_PROXY_H
#define OHOS_DM_IPC_CLIENT_SERVER_PROXY_H
#include <cstdint>
#include <memory>
#include <mutex>
#include "ipc_req.h"
#include "ipc_rsp.h"
#include "iproxy_client.h"
#include "liteipc_adapter.h"
#include "samgr_lite.h"
#include "ipc_req.h"
#include "ipc_rsp.h"
namespace OHOS {
namespace DistributedHardware {
class IpcClientServerProxy {
public:
int32_t Init();
int32_t SendCmd(int32_t cmdCode, std::shared_ptr<IpcReq> req, std::shared_ptr<IpcRsp> rsp);
private:
IClientProxy *GetServerProxy(void);
int32_t RegisterServerDeathCb(void);
private:
std::mutex lock_;
IClientProxy *serviceProxy_ {nullptr};
IClientProxy *serviceProxy_{nullptr};
};
} // namespace DistributedHardware
} // namespace OHOS
#endif // OHOS_DEVICE_MANAGER_IPC_CLIENT_SERVER_PROXY_H
#endif // OHOS_DM_IPC_CLIENT_SERVER_PROXY_H
@@ -4,7 +4,7 @@
* 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
* 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,
@@ -13,31 +13,32 @@
* limitations under the License.
*/
#ifndef OHOS_DEVICE_MANAGER_IPC_CLIENT_STUB_H
#define OHOS_DEVICE_MANAGER_IPC_CLIENT_STUB_H
#ifndef OHOS_DM_IPC_CLIENT_STUB_H
#define OHOS_DM_IPC_CLIENT_STUB_H
#include <mutex>
#include <cstdint>
#include <mutex>
#include "liteipc_adapter.h"
#include "single_instance.h"
namespace OHOS {
namespace DistributedHardware {
class IpcClientStub {
DECLARE_SINGLE_INSTANCE(IpcClientStub);
DECLARE_SINGLE_INSTANCE(IpcClientStub);
public:
int32_t Init();
SvcIdentity GetSvcIdentity() const
{
return clientIdentity_;
}
private:
std::mutex lock_;
bool bInit {false};
bool bInit{false};
SvcIdentity clientIdentity_;
};
} // namespace DistributedHardware
} // namespace OHOS
#endif // OHOS_DEVICE_MANAGER_IPC_CLIENT_STUB_H
#endif // OHOS_DM_IPC_CLIENT_STUB_H
@@ -4,7 +4,7 @@
* 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
* 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,
@@ -13,20 +13,19 @@
* limitations under the License.
*/
#ifndef OHOS_DEVICE_MANAGER_IPC_CLIENT_MANAGER_H
#define OHOS_DEVICE_MANAGER_IPC_CLIENT_MANAGER_H
#ifndef OHOS_DM_IPC_CLIENT_MANAGER_H
#define OHOS_DM_IPC_CLIENT_MANAGER_H
#include <cstdint>
#include <mutex>
#include <map>
#include <mutex>
#include <string>
#include "iremote_object.h"
#include "ipc_client.h"
#include "ipc_client_stub.h"
#include "ipc_def.h"
#include "ipc_remote_broker.h"
#include "iremote_object.h"
namespace OHOS {
namespace DistributedHardware {
@@ -38,21 +37,24 @@ public:
};
class IpcClientManager : public IpcClient {
friend class DmDeathRecipient;
DECLARE_IPC_INTERFACE(IpcClientManager);
friend class DmDeathRecipient;
DECLARE_IPC_INTERFACE(IpcClientManager);
public:
virtual int32_t Init(std::string &pkgName) override;
virtual int32_t UnInit(std::string &pkgName) override;
virtual int32_t Init(const std::string &pkgName) override;
virtual int32_t UnInit(const std::string &pkgName) override;
virtual int32_t SendRequest(int32_t cmdCode, std::shared_ptr<IpcReq> req, std::shared_ptr<IpcRsp> rsp) override;
private:
bool IsInit(std::string &pkgName);
bool IsInit(const std::string &pkgName);
int32_t ClientInit();
private:
std::mutex lock_;
std::map<std::string, sptr<IpcClientStub>> dmListener_;
sptr<IpcRemoteBroker> dmInterface_ {nullptr};
sptr<DmDeathRecipient> dmRecipient_ {nullptr};
sptr<IpcRemoteBroker> dmInterface_{nullptr};
sptr<DmDeathRecipient> dmRecipient_{nullptr};
};
} // namespace DistributedHardware
} // namespace OHOS
#endif // OHOS_DEVICE_MANAGER_IPC_CLIENT_MANAGER_H
#endif // OHOS_DM_IPC_CLIENT_MANAGER_H
@@ -4,7 +4,7 @@
* 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
* 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,
@@ -13,27 +13,28 @@
* limitations under the License.
*/
#ifndef OHOS_DEVICE_MANAGER_IPC_CLIENT_SERVER_PROXY_H
#define OHOS_DEVICE_MANAGER_IPC_CLIENT_SERVER_PROXY_H
#ifndef OHOS_DM_IPC_CLIENT_SERVER_PROXY_H
#define OHOS_DM_IPC_CLIENT_SERVER_PROXY_H
#include <cstdint>
#include <memory>
#include "iremote_proxy.h"
#include "ipc_remote_broker.h"
#include "ipc_req.h"
#include "ipc_rsp.h"
#include "iremote_proxy.h"
namespace OHOS {
namespace DistributedHardware {
class IpcClientServerProxy : public IRemoteProxy<IpcRemoteBroker> {
public:
explicit IpcClientServerProxy(const sptr<IRemoteObject> &impl) : IRemoteProxy<IpcRemoteBroker>(impl) {};
~IpcClientServerProxy() {};
explicit IpcClientServerProxy(const sptr<IRemoteObject> &impl) : IRemoteProxy<IpcRemoteBroker>(impl){};
~IpcClientServerProxy(){};
int32_t SendCmd(int32_t cmdCode, std::shared_ptr<IpcReq> req, std::shared_ptr<IpcRsp> rsp) override;
private:
static inline BrokerDelegator<IpcClientServerProxy> delegator_;
};
} // namespace DistributedHardware
} // namespace OHOS
#endif // OHOS_DEVICE_MANAGER_IPC_CLIENT_SERVER_PROXY_H
#endif // OHOS_DM_IPC_CLIENT_SERVER_PROXY_H
@@ -4,7 +4,7 @@
* 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
* 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,
@@ -13,28 +13,27 @@
* limitations under the License.
*/
#ifndef OHOS_DEVICE_MANAGER_IPC_CLIENT_STUB_H
#define OHOS_DEVICE_MANAGER_IPC_CLIENT_STUB_H
#ifndef OHOS_DM_IPC_CLIENT_STUB_H
#define OHOS_DM_IPC_CLIENT_STUB_H
#include <cstdint>
#include <memory>
#include "iremote_stub.h"
#include "iremote_broker.h"
#include "ipc_remote_broker.h"
#include "ipc_req.h"
#include "ipc_rsp.h"
#include "iremote_broker.h"
#include "iremote_stub.h"
namespace OHOS {
namespace DistributedHardware {
class IpcClientStub : public IRemoteStub<IpcRemoteBroker> {
public:
IpcClientStub() {};
~IpcClientStub() {};
IpcClientStub(){};
~IpcClientStub(){};
int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override;
int32_t SendCmd(int32_t cmdCode, std::shared_ptr<IpcReq> req, std::shared_ptr<IpcRsp> rsp) override;
};
} // namespace DistributedHardware
} // namespace OHOS
#endif // OHOS_DEVICE_MANAGER_IPC_CLIENT_STUB_H
#endif // OHOS_DM_IPC_CLIENT_STUB_H
@@ -4,7 +4,7 @@
* 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
* 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,
@@ -13,26 +13,28 @@
* limitations under the License.
*/
#ifndef OHOS_DEVICE_MANAGER_IPC_REMOTE_BROKER_H
#define OHOS_DEVICE_MANAGER_IPC_REMOTE_BROKER_H
#ifndef OHOS_DM_IPC_REMOTE_BROKER_H
#define OHOS_DM_IPC_REMOTE_BROKER_H
#include <cstdint>
#include <memory>
#include "iremote_broker.h"
#include "ipc_req.h"
#include "ipc_rsp.h"
#include "iremote_broker.h"
namespace OHOS {
namespace DistributedHardware {
class IpcRemoteBroker : public OHOS::IRemoteBroker {
public:
virtual ~IpcRemoteBroker() {}
virtual ~IpcRemoteBroker()
{
}
virtual int32_t SendCmd(int32_t cmdCode, std::shared_ptr<IpcReq> req, std::shared_ptr<IpcRsp> rsp) = 0;
public:
DECLARE_INTERFACE_DESCRIPTOR(u"ohos.distributedhardware.devicemanager");
};
} // namespace DistributedHardware
} // namespace OHOS
#endif // OHOS_DEVICE_MANAGER_IPC_REMOTE_BROKER_H
#endif // OHOS_DM_IPC_REMOTE_BROKER_H
@@ -4,7 +4,7 @@
* 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
* 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,
@@ -13,63 +13,66 @@
* limitations under the License.
*/
#ifndef OHOS_DEVICE_MANAGER_NOTIFY_H
#define OHOS_DEVICE_MANAGER_NOTIFY_H
#ifndef OHOS_DM_NOTIFY_H
#define OHOS_DM_NOTIFY_H
#include <mutex>
#include <map>
#include <vector>
#include <string>
#include <memory>
#include <mutex>
#include <string>
#include <vector>
#include "device_manager_callback.h"
#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);
DECLARE_SINGLE_INSTANCE(DeviceManagerNotify);
public:
void RegisterDeathRecipientCallback(std::string &pkgName, std::shared_ptr<DmInitCallback> dmInitCallback);
void UnRegisterDeathRecipientCallback(std::string &pkgName);
void RegisterDeviceStateCallback(std::string &pkgName, std::shared_ptr<DeviceStateCallback> callback);
void UnRegisterDeviceStateCallback(std::string &pkgName);
void RegisterDiscoverCallback(std::string &pkgName, uint16_t subscribeId,
std::shared_ptr<DiscoverCallback> callback);
void UnRegisterDiscoverCallback(std::string &pkgName, uint16_t subscribeId);
void RegisterAuthenticateCallback(std::string &pkgName, std::string &deviceId,
std::shared_ptr<AuthenticateCallback> 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<CheckAuthCallback> callback);
void UnRegisterCheckAuthenticationCallback(std::string &pkgName);
void RegisterDeviceManagerFaCallback(std::string &packageName,
std::shared_ptr<DeviceManagerFaCallback> callback);
void UnRegisterDeviceManagerFaCallback(std::string &pkgName);
void RegisterDeathRecipientCallback(const std::string &pkgName, std::shared_ptr<DmInitCallback> dmInitCallback);
void UnRegisterDeathRecipientCallback(const std::string &pkgName);
void RegisterDeviceStateCallback(const std::string &pkgName, std::shared_ptr<DeviceStateCallback> callback);
void UnRegisterDeviceStateCallback(const std::string &pkgName);
void RegisterDiscoveryCallback(const std::string &pkgName, uint16_t subscribeId,
std::shared_ptr<DiscoveryCallback> callback);
void UnRegisterDiscoveryCallback(const std::string &pkgName, uint16_t subscribeId);
void RegisterAuthenticateCallback(const std::string &pkgName, const std::string &deviceId,
std::shared_ptr<AuthenticateCallback> callback);
void UnRegisterAuthenticateCallback(const std::string &pkgName, const std::string &deviceId);
void UnRegisterPackageCallback(const std::string &pkgName);
void RegisterVerifyAuthenticationCallback(const std::string &pkgName, const std::string &authPara,
std::shared_ptr<VerifyAuthCallback> callback);
void UnRegisterVerifyAuthenticationCallback(const std::string &pkgName);
void RegisterDeviceManagerFaCallback(const std::string &pkgName, std::shared_ptr<DeviceManagerFaCallback> callback);
void UnRegisterDeviceManagerFaCallback(const 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 OnDeviceOnline(const std::string &pkgName, const DmDeviceInfo &deviceInfo);
void OnDeviceOffline(const std::string &pkgName, const DmDeviceInfo &deviceInfo);
void OnDeviceChanged(const std::string &pkgName, const DmDeviceInfo &deviceInfo);
void OnDeviceReady(const std::string &pkgName, const DmDeviceInfo &deviceInfo);
void OnDeviceFound(const std::string &pkgName, uint16_t subscribeId, const DmDeviceInfo &deviceInfo);
void OnDiscoveryFailed(const std::string &pkgName, uint16_t subscribeId, int32_t failedReason);
void OnDiscoverySuccess(const std::string &pkgName, uint16_t subscribeId);
void OnAuthResult(const std::string &pkgName, const std::string &deviceId, const std::string &token,
uint32_t status, uint32_t reason);
void OnVerifyAuthResult(const std::string &pkgName, const std::string &deviceId, int32_t resultCode, int32_t flag);
void OnFaCall(std::string &pkgName, std::string &paramJson);
private:
std::mutex lock_;
std::map<std::string, std::shared_ptr<DeviceStateCallback>> deviceStateCallback_;
std::map<std::string, std::map<uint16_t, std::shared_ptr<DiscoverCallback>>> deviceDiscoverCallbacks_;
std::map<std::string, std::map<uint16_t, std::shared_ptr<DiscoveryCallback>>> deviceDiscoveryCallbacks_;
std::map<std::string, std::map<std::string, std::shared_ptr<AuthenticateCallback>>> authenticateCallback_;
std::map<std::string, std::shared_ptr<CheckAuthCallback>> checkauthcallback_;
std::map<std::string, std::shared_ptr<VerifyAuthCallback>> verifyAuthCallback_;
std::map<std::string, std::shared_ptr<DmInitCallback>> dmInitCallback_;
std::map<std::string, std::shared_ptr<DeviceManagerFaCallback>> dmFaCallback_;
};
} // namespace DistributedHardware
} // namespace OHOS
#endif // OHOS_DEVICE_MANAGER_NOTIFY_H
#endif // OHOS_DM_NOTIFY_H
@@ -4,7 +4,7 @@
* 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
* 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,
@@ -4,7 +4,7 @@
* 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
* 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,
@@ -15,279 +15,521 @@
#include "device_manager_impl.h"
#include "device_manager_errno.h"
#include "device_manager_log.h"
#include "device_manager_notify.h"
#include "constants.h"
#include "bundle_constants.h"
#include "bundle_info.h"
#include "bundle_mgr_client.h"
#include "bundle_mgr_interface.h"
#include "if_system_ability_manager.h"
#include "iservice_registry.h"
#include "system_ability_definition.h"
#include "device_manager_notify.h"
#include "dm_constants.h"
#include "dm_log.h"
#include "ipc_authenticate_device_req.h"
#include "ipc_check_authenticate_req.h"
#include "ipc_get_dmfaparam_rsp.h"
#include "ipc_get_info_by_network_req.h"
#include "ipc_get_info_by_network_rsp.h"
#include "ipc_get_local_device_info_rsp.h"
#include "ipc_get_trustdevice_req.h"
#include "ipc_get_trustdevice_rsp.h"
#include "ipc_rsp.h"
#include "ipc_req.h"
#include "ipc_rsp.h"
#include "ipc_set_useroperation_req.h"
#include "ipc_skeleton.h"
#include "ipc_start_discovery_req.h"
#include "ipc_stop_discovery_req.h"
#include "ipc_get_authenticationparam_rsp.h"
#include "ipc_set_useroperation_req.h"
#include "ipc_unauthenticate_device_req.h"
#include "ipc_verify_authenticate_req.h"
using namespace OHOS::AppExecFwk;
using namespace OHOS::AppExecFwk::Constants;
namespace OHOS {
namespace DistributedHardware {
IMPLEMENT_SINGLE_INSTANCE(DeviceManagerImpl);
int32_t DeviceManagerImpl::InitDeviceManager(std::string &pkgName, std::shared_ptr<DmInitCallback> dmInitCallback)
bool DeviceManagerImpl::isSystemAppCalling(void)
{
DMLOG(DM_LOG_INFO, "DeviceManager::InitDeviceManager start, pkgName: %s", pkgName.c_str());
int32_t uid = IPCSkeleton::GetCallingUid();
if (uid < 0) {
LOGI("app caller uid is: %d,", uid);
return false;
}
sptr<ISystemAbilityManager> systemAbilityManager =
SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
if (systemAbilityManager == nullptr) {
LOGE("failed to get system ability mgr.");
return false;
}
sptr<IRemoteObject> remoteObject =
systemAbilityManager->GetSystemAbility(BUNDLE_MGR_SERVICE_SYS_ABILITY_ID);
if (remoteObject == nullptr) {
LOGE("failed to get bundle manager proxy.");
return false;
}
LOGI("get bundle manager proxy success.");
sptr<IBundleMgr> iBundleMgr = iface_cast<IBundleMgr>(remoteObject);
return iBundleMgr->CheckIsSystemAppByUid(uid);
}
DeviceManagerImpl &DeviceManagerImpl::GetInstance()
{
static DeviceManagerImpl instance;
return instance;
}
int32_t DeviceManagerImpl::InitDeviceManager(const std::string &pkgName, std::shared_ptr<DmInitCallback> dmInitCallback)
{
LOGI("DeviceManager::InitDeviceManager start, pkgName: %s", pkgName.c_str());
if (!isSystemAppCalling()) {
LOGI("the caller is not a system app");
return DM_NOT_SYSTEM_APP;
}
if (pkgName.empty() || dmInitCallback == nullptr) {
DMLOG(DM_LOG_ERROR, "InitDeviceManager error: Invalid parameter");
return DEVICEMANAGER_INVALID_VALUE;
LOGE("InitDeviceManager error: Invalid parameter");
return DM_INVALID_VALUE;
}
int32_t ret = ipcClientProxy_->Init(pkgName);
if (ret != DEVICEMANAGER_OK) {
return ret;
if (ret != DM_OK) {
LOGE("InitDeviceManager error: proxy init failed ret: %d", ret);
return DM_INIT_FAILED;
}
DeviceManagerNotify::GetInstance().RegisterDeathRecipientCallback(pkgName, dmInitCallback);
DMLOG(DM_LOG_INFO, "success");
return DEVICEMANAGER_OK;
LOGI("InitDeviceManager success");
return DM_OK;
}
int32_t DeviceManagerImpl::UnInitDeviceManager(std::string &pkgName)
int32_t DeviceManagerImpl::UnInitDeviceManager(const std::string &pkgName)
{
DMLOG(DM_LOG_INFO, "DeviceManager::UnInitDeviceManager start, pkgName: %s", pkgName.c_str());
LOGI("DeviceManager::UnInitDeviceManager start, pkgName: %s", pkgName.c_str());
if (!isSystemAppCalling()) {
LOGI("the caller is not a system app");
return DM_NOT_SYSTEM_APP;
}
if (pkgName.empty()) {
DMLOG(DM_LOG_ERROR, "InitDeviceManager error: Invalid parameter");
return DEVICEMANAGER_INVALID_VALUE;
LOGE("UnInitDeviceManager error: Invalid parameter");
return DM_INVALID_VALUE;
}
int32_t ret = ipcClientProxy_->UnInit(pkgName);
if (ret != DEVICEMANAGER_OK) {
return ret;
if (ret != DM_OK) {
LOGE("UnInitDeviceManager error: proxy unInit failed ret: %d", ret);
return DM_UNINIT_FAILED;
}
DeviceManagerNotify::GetInstance().UnRegisterPackageCallback(pkgName);
DMLOG(DM_LOG_INFO, "DeviceManager::UnInitDeviceManager completed with errcode %d", ret);
return DEVICEMANAGER_OK;
LOGI("UnInitDeviceManager success");
return DM_OK;
}
int32_t DeviceManagerImpl::GetTrustedDeviceList(std::string &pkgName, std::string &extra,
std::vector<DmDeviceInfo> &deviceList)
int32_t DeviceManagerImpl::GetTrustedDeviceList(const std::string &pkgName, const std::string &extra,
std::vector<DmDeviceInfo> &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;
LOGI("DeviceManager::GetTrustedDeviceList start, pkgName: %s", pkgName.c_str());
if (!isSystemAppCalling()) {
LOGI("the caller is not a system app");
return DM_NOT_SYSTEM_APP;
}
std::shared_ptr<IpcGetTrustdeviceReq> req = std::make_shared<IpcGetTrustdeviceReq>();
std::shared_ptr<IpcGetTrustdeviceRsp> rsp = std::make_shared<IpcGetTrustdeviceRsp>();
if (pkgName.empty()) {
LOGE("GetTrustedDeviceList error: Invalid para");
return DM_INVALID_VALUE;
}
std::shared_ptr<IpcGetTrustDeviceReq> req = std::make_shared<IpcGetTrustDeviceReq>();
std::shared_ptr<IpcGetTrustDeviceRsp> rsp = std::make_shared<IpcGetTrustDeviceRsp>();
req->SetPkgName(pkgName);
req->SetExtra(extra);
if (ipcClientProxy_->SendRequest(GET_TRUST_DEVICE_LIST, req, rsp) != DEVICEMANAGER_OK) {
return DEVICEMANAGER_IPC_FAILED;
int32_t ret = ipcClientProxy_->SendRequest(GET_TRUST_DEVICE_LIST, req, rsp);
if (ret != DM_OK) {
LOGE("GetTrustedDeviceList error: Send Request failed ret: %d", ret);
return DM_IPC_SEND_REQUEST_FAILED;
}
if (rsp->GetErrCode() == DEVICEMANAGER_OK) {
deviceList = rsp->GetDeviceVec();
ret = rsp->GetErrCode();
if (ret != DM_OK) {
LOGI("GetTrustedDeviceList error: failed ret: %d", ret);
return DM_IPC_RESPOND_ERROR;
}
DMLOG(DM_LOG_INFO, "DeviceManager::GetTrustedDeviceList completed, pkgName: %s", pkgName.c_str());
return DEVICEMANAGER_OK;
deviceList = rsp->GetDeviceVec();
LOGI("GetTrustedDeviceList completed, pkgName: %s", pkgName.c_str());
return DM_OK;
}
int32_t DeviceManagerImpl::RegisterDevStateCallback(std::string &pkgName, std::string &extra,
std::shared_ptr<DeviceStateCallback> callback)
int32_t DeviceManagerImpl::GetLocalDeviceInfo(const std::string &pkgName, DmDeviceInfo &info)
{
DMLOG(DM_LOG_INFO, "DeviceManager::RegisterDevStateCallback start, pkgName: %s", pkgName.c_str());
LOGI("DeviceManager::GetLocalDeviceInfo start, pkgName: %s", pkgName.c_str());
if (!isSystemAppCalling()) {
LOGI("the caller is not a system app");
return DM_NOT_SYSTEM_APP;
}
std::shared_ptr<IpcReq> req = std::make_shared<IpcReq>();
std::shared_ptr<IpcGetLocalDeviceInfoRsp> rsp = std::make_shared<IpcGetLocalDeviceInfoRsp>();
req->SetPkgName(pkgName);
int32_t ret = ipcClientProxy_->SendRequest(GET_LOCAL_DEVICE_INFO, req, rsp);
if (ret != DM_OK) {
LOGE("GetLocalDeviceInfo error: Send Request failed ret: %d", ret);
return DM_IPC_SEND_REQUEST_FAILED;
}
ret = rsp->GetErrCode();
if (ret != DM_OK) {
LOGI("GetLocalDeviceInfo error: failed ret: %d", ret);
return DM_IPC_RESPOND_ERROR;
}
info = rsp->GetLocalDeviceInfo();
LOGI("GetLocalDeviceInfo completed,pkgname%s", req->GetPkgName().c_str());
return DM_OK;
}
int32_t DeviceManagerImpl::RegisterDevStateCallback(const std::string &pkgName, const std::string &extra,
std::shared_ptr<DeviceStateCallback> callback)
{
LOGI("DeviceManager::RegisterDevStateCallback start, pkgName: %s", pkgName.c_str());
if (!isSystemAppCalling()) {
LOGI("the caller is not a system app");
return DM_NOT_SYSTEM_APP;
}
if (pkgName.empty() || callback == nullptr) {
DMLOG(DM_LOG_ERROR, "Invalid para");
return DEVICEMANAGER_INVALID_VALUE;
LOGE("RegisterDevStateCallback error: Invalid para");
return DM_INVALID_VALUE;
}
DeviceManagerNotify::GetInstance().RegisterDeviceStateCallback(pkgName, callback);
DMLOG(DM_LOG_INFO, "DeviceManager::RegisterDevStateCallback completed, pkgName: %s", pkgName.c_str());
return DEVICEMANAGER_OK;
LOGI("RegisterDevStateCallback completed, pkgName: %s", pkgName.c_str());
return DM_OK;
}
int32_t DeviceManagerImpl::UnRegisterDevStateCallback(std::string &pkgName)
int32_t DeviceManagerImpl::UnRegisterDevStateCallback(const std::string &pkgName)
{
DMLOG(DM_LOG_INFO, "DeviceManager::UnRegisterDevStateCallback start, pkgName: %s", pkgName.c_str());
LOGI("DeviceManager::UnRegisterDevStateCallback start, pkgName: %s", pkgName.c_str());
if (!isSystemAppCalling()) {
LOGI("the caller is not a system app");
return DM_NOT_SYSTEM_APP;
}
if (pkgName.empty()) {
DMLOG(DM_LOG_ERROR, "Invalid para");
return DEVICEMANAGER_INVALID_VALUE;
LOGE("UnRegisterDevStateCallback error: Invalid para");
return DM_INVALID_VALUE;
}
DeviceManagerNotify::GetInstance().UnRegisterDeviceStateCallback(pkgName);
DMLOG(DM_LOG_INFO, "DeviceManager::UnRegisterDevStateCallback completed, pkgName: %s", pkgName.c_str());
return DEVICEMANAGER_OK;
LOGI("UnRegisterDevStateCallback completed, pkgName: %s", pkgName.c_str());
return DM_OK;
}
int32_t DeviceManagerImpl::StartDeviceDiscovery(std::string &pkgName, DmSubscribeInfo &subscribeInfo,
std::shared_ptr<DiscoverCallback> callback)
int32_t DeviceManagerImpl::StartDeviceDiscovery(const std::string &pkgName, const DmSubscribeInfo &subscribeInfo,
const std::string &extra, std::shared_ptr<DiscoveryCallback> 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;
LOGI("DeviceManager::StartDeviceDiscovery start, pkgName: %s", pkgName.c_str());
if (!isSystemAppCalling()) {
LOGI("the caller is not a system app");
return DM_NOT_SYSTEM_APP;
}
DMLOG(DM_LOG_INFO, "DeviceManager StartDeviceDiscovery in, pkgName %s", pkgName.c_str());
DeviceManagerNotify::GetInstance().RegisterDiscoverCallback(pkgName, subscribeInfo.subscribeId, callback);
if (pkgName.empty() || callback == nullptr) {
LOGE("StartDeviceDiscovery error: Invalid para");
return DM_INVALID_VALUE;
}
LOGI("DeviceManager StartDeviceDiscovery in, pkgName %s", pkgName.c_str());
DeviceManagerNotify::GetInstance().RegisterDiscoveryCallback(pkgName, subscribeInfo.subscribeId, callback);
std::shared_ptr<IpcStartDiscoveryReq> req = std::make_shared<IpcStartDiscoveryReq>();
std::shared_ptr<IpcRsp> rsp = std::make_shared<IpcRsp>();
req->SetPkgName(pkgName);
req->SetExtra(extra);
req->SetSubscribeInfo(subscribeInfo);
if (ipcClientProxy_->SendRequest(START_DEVICE_DISCOVER, req, rsp) != DEVICEMANAGER_OK) {
return DEVICEMANAGER_IPC_FAILED;
int32_t ret = ipcClientProxy_->SendRequest(START_DEVICE_DISCOVER, req, rsp);
if (ret != DM_OK) {
LOGE("StartDeviceDiscovery error: Send Request failed ret: %d", ret);
return DM_IPC_SEND_REQUEST_FAILED;
}
int32_t ret = rsp->GetErrCode();
if (ret != DEVICEMANAGER_OK) {
DMLOG(DM_LOG_ERROR, "DeviceManager StartDeviceDiscovery Failed with ret %d", ret);
return ret;
ret = rsp->GetErrCode();
if (ret != DM_OK) {
LOGE("StartDeviceDiscovery error: Failed with ret %d", ret);
return DM_IPC_RESPOND_ERROR;
}
return DEVICEMANAGER_OK;
LOGI("StartDeviceDiscovery completed, pkgName: %s", pkgName.c_str());
return DM_OK;
}
int32_t DeviceManagerImpl::StopDeviceDiscovery(std::string &pkgName, uint16_t subscribeId)
int32_t DeviceManagerImpl::StopDeviceDiscovery(const 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;
LOGI("DeviceManager::StopDeviceDiscovery start , pkgName: %s", pkgName.c_str());
if (!isSystemAppCalling()) {
LOGI("the caller is not a system app");
return DM_NOT_SYSTEM_APP;
}
DMLOG(DM_LOG_INFO, "StopDeviceDiscovery in, pkgName %s", pkgName.c_str());
if (pkgName.empty()) {
LOGE("StopDeviceDiscovery error: Invalid para");
return DM_INVALID_VALUE;
}
LOGI("StopDeviceDiscovery in, pkgName %s", pkgName.c_str());
std::shared_ptr<IpcStopDiscoveryReq> req = std::make_shared<IpcStopDiscoveryReq>();
std::shared_ptr<IpcRsp> rsp = std::make_shared<IpcRsp>();
req->SetPkgName(pkgName);
req->SetSubscribeId(subscribeId);
if (ipcClientProxy_->SendRequest(STOP_DEVICE_DISCOVER, req, rsp) != DEVICEMANAGER_OK) {
return DEVICEMANAGER_IPC_FAILED;
int32_t ret = ipcClientProxy_->SendRequest(STOP_DEVICE_DISCOVER, req, rsp);
if (ret != DM_OK) {
LOGE("StopDeviceDiscovery error: Send Request failed ret: %d", ret);
return DM_IPC_SEND_REQUEST_FAILED;
}
int32_t ret = rsp->GetErrCode();
if (ret != DEVICEMANAGER_OK) {
DMLOG(DM_LOG_ERROR, "StopDeviceDiscovery Failed with ret %d", ret);
return ret;
ret = rsp->GetErrCode();
if (ret != DM_OK) {
LOGE("StopDeviceDiscovery error: Failed with ret %d", ret);
return DM_IPC_RESPOND_ERROR;
}
DeviceManagerNotify::GetInstance().UnRegisterDiscoverCallback(pkgName, subscribeId);
DMLOG(DM_LOG_INFO, "DeviceManager::StopDeviceDiscovery completed, pkgName: %s", pkgName.c_str());
return DEVICEMANAGER_OK;
DeviceManagerNotify::GetInstance().UnRegisterDiscoveryCallback(pkgName, subscribeId);
LOGI("StopDeviceDiscovery completed, pkgName: %s", pkgName.c_str());
return DM_OK;
}
int32_t DeviceManagerImpl::AuthenticateDevice(std::string &pkgName, const DmDeviceInfo &deviceInfo,
const DmAppImageInfo &imageInfo, std::string &extra, std::shared_ptr<AuthenticateCallback> callback)
int32_t DeviceManagerImpl::AuthenticateDevice(const std::string &pkgName, int32_t authType,
const DmDeviceInfo &deviceInfo, const std::string &extra,
std::shared_ptr<AuthenticateCallback> 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;
LOGI("DeviceManager::AuthenticateDevice start , pkgName: %s", pkgName.c_str());
if (!isSystemAppCalling()) {
LOGI("the caller is not a system app");
return DM_NOT_SYSTEM_APP;
}
if (pkgName.empty()) {
LOGE("AuthenticateDevice error: Invalid para");
return DM_INVALID_VALUE;
}
DMLOG(DM_LOG_INFO, "AuthenticateDevice in, pkgName %s", pkgName.c_str());
std::shared_ptr<IpcAuthenticateDeviceReq> req = std::make_shared<IpcAuthenticateDeviceReq>();
std::shared_ptr<IpcRsp> rsp = std::make_shared<IpcRsp>();
req->SetPkgName(pkgName);
req->SetExtra(extra);
req->SetAuthType(authType);
req->SetDeviceInfo(deviceInfo);
req->SetAppImageInfo(imageInfo);
if (ipcClientProxy_->SendRequest(AUTHENTICATE_DEVICE, req, rsp) != DEVICEMANAGER_OK) {
return DEVICEMANAGER_IPC_FAILED;
int32_t ret = ipcClientProxy_->SendRequest(AUTHENTICATE_DEVICE, req, rsp);
if (ret != DM_OK) {
LOGE("AuthenticateDevice error: Send Request failed ret: %d", ret);
return DM_IPC_SEND_REQUEST_FAILED;
}
int32_t ret = rsp->GetErrCode();
if (ret != DEVICEMANAGER_OK) {
DMLOG(DM_LOG_ERROR, "AuthenticateDevice Failed with ret %d", ret);
return ret;
ret = rsp->GetErrCode();
if (ret != DM_OK) {
LOGE("AuthenticateDevice error: Failed with ret %d", ret);
return DM_IPC_RESPOND_ERROR;
}
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;
LOGI("DeviceManager::AuthenticateDevice completed, pkgName: %s", pkgName.c_str());
return DM_OK;
}
int32_t DeviceManagerImpl::CheckAuthentication(std::string &pkgName, std::string &authPara,
std::shared_ptr<CheckAuthCallback> callback)
int32_t DeviceManagerImpl::UnAuthenticateDevice(const std::string &pkgName, const std::string &deviceId)
{
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;
LOGI("DeviceManager::UnAuthenticateDevice start , pkgName: %s, deviceId: %s", pkgName.c_str(), deviceId.c_str());
if (!isSystemAppCalling()) {
LOGI("the caller is not a system app");
return DM_NOT_SYSTEM_APP;
}
DMLOG(DM_LOG_INFO, "CheckAuthentication in, pkgName %s", pkgName.c_str());
std::shared_ptr<IpcCheckAuthenticateReq> req = std::make_shared<IpcCheckAuthenticateReq>();
if (deviceId.empty()) {
LOGE("UnAuthenticateDevice error: Invalid para");
return DM_INVALID_VALUE;
}
DmDeviceInfo deviceInfo;
strcpy(deviceInfo.deviceId, deviceId.c_str());
std::shared_ptr<IpcUnAuthenticateDeviceReq> req = std::make_shared<IpcUnAuthenticateDeviceReq>();
std::shared_ptr<IpcRsp> rsp = std::make_shared<IpcRsp>();
req->SetPkgName(pkgName);
req->SetDeviceInfo(deviceInfo);
int32_t ret = ipcClientProxy_->SendRequest(UNAUTHENTICATE_DEVICE, req, rsp);
if (ret != DM_OK) {
LOGE("UnAuthenticateDevice error: Send Request failed ret: %d", ret);
return DM_IPC_SEND_REQUEST_FAILED;
}
ret = rsp->GetErrCode();
if (ret != DM_OK) {
LOGE("UnAuthenticateDevice error: Failed with ret %d", ret);
return DM_IPC_RESPOND_ERROR;
}
DeviceManagerNotify::GetInstance().UnRegisterAuthenticateCallback(pkgName, deviceId);
LOGI("UnAuthenticateDevice completed, pkgName: %s", pkgName.c_str());
return DM_OK;
}
int32_t DeviceManagerImpl::RegisterDeviceManagerFaCallback(const std::string &pkgName,
std::shared_ptr<DeviceManagerFaCallback> callback)
{
LOGI("DeviceManager::RegisterDeviceManagerFaCallback start, pkgName: %s", pkgName.c_str());
if (pkgName.empty() || callback == nullptr) {
LOGE("RegisterDeviceManagerFaCallback error: Invalid para");
return DM_INVALID_VALUE;
}
DeviceManagerNotify::GetInstance().RegisterDeviceManagerFaCallback(pkgName, callback);
LOGI("DeviceManager::RegisterDevStateCallback completed, pkgName: %s", pkgName.c_str());
return DM_OK;
}
int32_t DeviceManagerImpl::UnRegisterDeviceManagerFaCallback(const std::string &pkgName)
{
LOGI("DeviceManager::UnRegisterDeviceManagerFaCallback start, pkgName: %s", pkgName.c_str());
if (pkgName.empty()) {
LOGE("UnRegisterDeviceManagerFaCallback error: Invalid para");
return DM_INVALID_VALUE;
}
DeviceManagerNotify::GetInstance().UnRegisterDeviceManagerFaCallback(pkgName);
LOGI("DeviceManager::UnRegisterDevStateCallback completed, pkgName: %s", pkgName.c_str());
return DM_OK;
}
int32_t DeviceManagerImpl::VerifyAuthentication(const std::string &pkgName, const std::string &authPara,
std::shared_ptr<VerifyAuthCallback> callback)
{
LOGI("DeviceManager::VerifyAuthentication start, pkgName: %s", pkgName.c_str());
if (!isSystemAppCalling()) {
LOGI("the caller is not a system app");
return DM_NOT_SYSTEM_APP;
}
if (pkgName.empty()) {
LOGE("VerifyAuthentication error: Invalid para");
return DM_INVALID_VALUE;
}
DeviceManagerNotify::GetInstance().RegisterVerifyAuthenticationCallback(pkgName, authPara, callback);
std::shared_ptr<IpcVerifyAuthenticateReq> req = std::make_shared<IpcVerifyAuthenticateReq>();
std::shared_ptr<IpcRsp> rsp = std::make_shared<IpcRsp>();
req->SetPkgName(pkgName);
req->SetAuthPara(authPara);
if (ipcClientProxy_->SendRequest(CHECK_AUTHENTICATION, req, rsp) != DEVICEMANAGER_OK) {
return DEVICEMANAGER_IPC_FAILED;
}
int32_t ret = rsp->GetErrCode();
if (ret != DEVICEMANAGER_OK) {
DMLOG(DM_LOG_ERROR, "CheckAuthentication Failed with ret %d", ret);
int32_t ret = ipcClientProxy_->SendRequest(VERIFY_AUTHENTICATION, req, rsp);
if (ret != DM_OK) {
LOGE("VerifyAuthentication error: Send Request failed ret: %d", ret);
return DM_IPC_SEND_REQUEST_FAILED;
}
ret = rsp->GetErrCode();
if (ret != DM_OK) {
LOGE("VerifyAuthentication error: 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;
LOGI("VerifyAuthentication completed, pkgName: %s", pkgName.c_str());
return DM_OK;
}
int32_t DeviceManagerImpl::GetAuthenticationParam(std::string &pkgName, DmAuthParam &authParam)
int32_t DeviceManagerImpl::GetFaParam(const std::string &pkgName, DmAuthParam &dmFaParam)
{
DMLOG(DM_LOG_INFO, "DeviceManager::GetAuthenticationParam start");
std::shared_ptr<IpcReq> req = std::make_shared<IpcReq>();
std::shared_ptr<IpcGetAuthParamRsp> rsp = std::make_shared<IpcGetAuthParamRsp>();
req->SetPkgName(pkgName);
if (ipcClientProxy_->SendRequest(SERVER_GET_AUTHENTCATION_INFO, req, rsp) != DEVICEMANAGER_OK) {
return DEVICEMANAGER_IPC_FAILED;
LOGI("DeviceManager::GetFaParam start, pkgName: %s", pkgName.c_str());
if (pkgName.empty()) {
LOGE("VerifyAuthentication failed, pkgName is empty");
return DM_INVALID_VALUE;
}
authParam = rsp->GetAuthParam();
return DEVICEMANAGER_OK;
std::shared_ptr<IpcReq> req = std::make_shared<IpcReq>();
std::shared_ptr<IpcGetDmFaParamRsp> rsp = std::make_shared<IpcGetDmFaParamRsp>();
req->SetPkgName(pkgName);
if (ipcClientProxy_->SendRequest(SERVER_GET_DMFA_INFO, req, rsp) != DM_OK) {
LOGI("DeviceManagerImpl::GetFaParam start 2");
return DM_IPC_SEND_REQUEST_FAILED;
}
dmFaParam = rsp->GetDmAuthParam();
LOGI("GetFaParam completed, pkgName: %s", pkgName.c_str());
return DM_OK;
}
int32_t DeviceManagerImpl::SetUserOperation(std::string &pkgName, int32_t action)
int32_t DeviceManagerImpl::SetUserOperation(const std::string &pkgName, int32_t action)
{
DMLOG(DM_LOG_INFO, "DeviceManager::SetUserOperation start");
LOGI("DeviceManager::SetUserOperation start, pkgName: %s", pkgName.c_str());
if (pkgName.empty()) {
LOGE("VerifyAuthentication failed, pkgName is empty");
return DM_INVALID_VALUE;
}
std::shared_ptr<IpcGetOperationReq> req = std::make_shared<IpcGetOperationReq>();
std::shared_ptr<IpcRsp> rsp = std::make_shared<IpcRsp>();
req->SetPkgName(pkgName);
req->SetOperation(action);
if (ipcClientProxy_->SendRequest(SERVER_USER_AUTHORIZATION_OPERATION, req, rsp) != DEVICEMANAGER_OK) {
return DEVICEMANAGER_IPC_FAILED;
if (ipcClientProxy_->SendRequest(SERVER_USER_AUTH_OPERATION, req, rsp) != DM_OK) {
return DM_IPC_SEND_REQUEST_FAILED;
}
int32_t ret = rsp->GetErrCode();
if (ret != DEVICEMANAGER_OK) {
DMLOG(DM_LOG_ERROR, "CheckAuthentication Failed with ret %d", ret);
if (ret != DM_OK) {
LOGE("CheckAuthentication Failed with ret %d", ret);
return ret;
}
return DEVICEMANAGER_OK;
LOGI("SetUserOperation completed, pkgName: %s", pkgName.c_str());
return DM_OK;
}
int32_t DeviceManagerImpl::RegisterDeviceManagerFaCallback(std::string &packageName,
std::shared_ptr<DeviceManagerFaCallback> callback)
int32_t DeviceManagerImpl::GetUdidByNetworkId(const std::string &pkgName, const std::string &netWorkId,
std::string &udid)
{
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;
LOGE("VerifyAuthentication failed, pkgName is empty");
return DM_INVALID_VALUE;
}
DeviceManagerNotify::GetInstance().UnRegisterDeviceManagerFaCallback(pkgName);
DMLOG(DM_LOG_INFO, "DeviceManager::UnRegisterDevStateCallback completed, pkgName: %s", pkgName.c_str());
return DEVICEMANAGER_OK;
std::shared_ptr<IpcGetInfoByNetWorkReq> req = std::make_shared<IpcGetInfoByNetWorkReq>();
std::shared_ptr<IpcGetInfoByNetWorkRsp> rsp = std::make_shared<IpcGetInfoByNetWorkRsp>();
req->SetPkgName(pkgName);
req->SetNetWorkId(netWorkId);
if (ipcClientProxy_->SendRequest(GET_UDID_BY_NETWORK, req, rsp) != DM_OK) {
return DM_IPC_SEND_REQUEST_FAILED;
}
int32_t ret = rsp->GetErrCode();
if (ret != DM_OK) {
LOGE("CheckAuthentication Failed with ret %d", ret);
return ret;
}
udid = rsp->GetUdid();
return DM_OK;
}
int32_t DeviceManagerImpl::GetUuidByNetworkId(const std::string &pkgName, const std::string &netWorkId,
std::string &uuid)
{
if (pkgName.empty()) {
LOGE("VerifyAuthentication failed, pkgName is empty");
return DM_INVALID_VALUE;
}
std::shared_ptr<IpcGetInfoByNetWorkReq> req = std::make_shared<IpcGetInfoByNetWorkReq>();
std::shared_ptr<IpcGetInfoByNetWorkRsp> rsp = std::make_shared<IpcGetInfoByNetWorkRsp>();
req->SetPkgName(pkgName);
req->SetNetWorkId(netWorkId);
if (ipcClientProxy_->SendRequest(GET_UUID_BY_NETWORK, req, rsp) != DM_OK) {
return DM_IPC_SEND_REQUEST_FAILED;
}
int32_t ret = rsp->GetErrCode();
if (ret != DM_OK) {
LOGE("CheckAuthentication Failed with ret %d", ret);
return ret;
}
uuid = rsp->GetUuid();
return DM_OK;
}
} // namespace DistributedHardware
} // namespace OHOS
@@ -4,7 +4,7 @@
* 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
* 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,
@@ -15,23 +15,23 @@
#include "ipc_client_proxy.h"
#include "device_manager_log.h"
#include "device_manager_errno.h"
#include "dm_constants.h"
#include "dm_log.h"
namespace OHOS {
namespace DistributedHardware {
int32_t IpcClientProxy::Init(std::string &pkgName)
int32_t IpcClientProxy::Init(const std::string &pkgName)
{
if (ipcClientManager_ == nullptr) {
return DEVICEMANAGER_NULLPTR;
return DM_POINT_NULL;
}
return ipcClientManager_->Init(pkgName);
}
int32_t IpcClientProxy::UnInit(std::string &pkgName)
int32_t IpcClientProxy::UnInit(const std::string &pkgName)
{
if (ipcClientManager_ == nullptr) {
return DEVICEMANAGER_NULLPTR;
return DM_POINT_NULL;
}
return ipcClientManager_->UnInit(pkgName);
}
@@ -39,8 +39,8 @@ int32_t IpcClientProxy::UnInit(std::string &pkgName)
int32_t IpcClientProxy::SendRequest(int32_t cmdCode, std::shared_ptr<IpcReq> req, std::shared_ptr<IpcRsp> rsp)
{
if (req == nullptr || rsp == nullptr || ipcClientManager_ == nullptr) {
DMLOG(DM_LOG_INFO, "req,rsp or ipc client is null");
return DEVICEMANAGER_NULLPTR;
LOGI("req,rsp or ipc client is null");
return DM_POINT_NULL;
}
return ipcClientManager_->SendRequest(cmdCode, req, rsp);
}
@@ -4,7 +4,7 @@
* 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
* 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,
@@ -15,27 +15,26 @@
#include "ipc_client_manager.h"
#include "device_manager_errno.h"
#include "device_manager_log.h"
#include "dm_constants.h"
#include "dm_log.h"
#include "ipc_client_stub.h"
#include "ipc_register_listener_req.h"
namespace OHOS {
namespace DistributedHardware {
int32_t IpcClientManager::Init(std::string &pkgName)
int32_t IpcClientManager::Init(const std::string &pkgName)
{
if (IsInit(pkgName)) {
DMLOG(DM_LOG_INFO, "already init");
return DEVICEMANAGER_OK;
LOGI("already init");
return DM_OK;
}
if (serverProxy_.Init() != DEVICEMANAGER_OK) {
DMLOG(DM_LOG_ERROR, "server proxy init failed.");
return DEVICEMANAGER_INIT_FAILED;
if (serverProxy_.Init() != DM_OK) {
LOGE("server proxy init failed.");
return DM_INIT_FAILED;
}
if (IpcClientStub::GetInstance().Init() != DEVICEMANAGER_OK) {
DMLOG(DM_LOG_ERROR, "ipcclientstub init failed.");
return DEVICEMANAGER_INIT_FAILED;
if (IpcClientStub::GetInstance().Init() != DM_OK) {
LOGE("ipcclientstub init failed.");
return DM_INIT_FAILED;
}
std::shared_ptr<IpcRegisterListenerReq> req = std::make_shared<IpcRegisterListenerReq>();
@@ -43,48 +42,48 @@ int32_t IpcClientManager::Init(std::string &pkgName)
req->SetPkgName(pkgName);
req->SetSvcIdentity(IpcClientStub::GetInstance().GetSvcIdentity());
int32_t ret = serverProxy_.SendCmd(REGISTER_DEVICE_MANAGER_LISTENER, req, rsp);
if (ret != DEVICEMANAGER_OK) {
DMLOG(DM_LOG_ERROR, "InitDeviceManager: RegisterDeviceManagerListener Failed with ret %d", ret);
if (ret != DM_OK) {
LOGE("InitDeviceManager: RegisterDeviceManagerListener Failed with ret %d", ret);
return ret;
}
ret = rsp->GetErrCode();
if (ret != DEVICEMANAGER_OK) {
DMLOG(DM_LOG_ERROR, "DeviceManager::InitDeviceManager completed, pkgName: %s, ret=%d", pkgName.c_str(), ret);
if (ret != DM_OK) {
LOGE("DeviceManager::InitDeviceManager completed, pkgName: %s, ret=%d", pkgName.c_str(), ret);
return ret;
}
packageInitSet_.emplace(pkgName);
return DEVICEMANAGER_OK;
return DM_OK;
}
int32_t IpcClientManager::UnInit(std::string &pkgName)
int32_t IpcClientManager::UnInit(const std::string &pkgName)
{
DMLOG(DM_LOG_INFO, "UnInitDeviceManager in, pkgName %s", pkgName.c_str());
LOGI("UnInitDeviceManager in, pkgName %s", pkgName.c_str());
if (!IsInit(pkgName)) {
return DEVICEMANAGER_FAILED;
return DM_FAILED;
}
std::shared_ptr<IpcReq> req = std::make_shared<IpcReq>();
std::shared_ptr<IpcRsp> rsp = std::make_shared<IpcRsp>();
req->SetPkgName(pkgName);
int32_t ret = serverProxy_.SendCmd(UNREGISTER_DEVICE_MANAGER_LISTENER, req, rsp);
if (ret != DEVICEMANAGER_OK) {
DMLOG(DM_LOG_ERROR, "UnRegisterDeviceManagerListener Failed with ret %d", ret);
if (ret != DM_OK) {
LOGE("UnRegisterDeviceManagerListener Failed with ret %d", ret);
return ret;
}
packageInitSet_.erase(pkgName);
DMLOG(DM_LOG_INFO, "UnInitDeviceManager SUCCESS");
return DEVICEMANAGER_OK;
LOGI("UnInitDeviceManager SUCCESS");
return DM_OK;
}
int32_t IpcClientManager::SendRequest(int32_t cmdCode, std::shared_ptr<IpcReq> req, std::shared_ptr<IpcRsp> rsp)
{
std::string pkgName = req->GetPkgName();
if (!IsInit(pkgName)) {
return DEVICEMANAGER_SERVICE_NOT_READY;
return DM_SERVICE_NOT_READY;
}
return serverProxy_.SendCmd(cmdCode, req, rsp);
}
bool IpcClientManager::IsInit(std::string &pkgName)
bool IpcClientManager::IsInit(const std::string &pkgName)
{
return (packageInitSet_.count(pkgName) > 0);
}
@@ -4,7 +4,7 @@
* 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
* 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,
@@ -15,17 +15,16 @@
#include "ipc_client_server_proxy.h"
#include "device_manager_log.h"
#include "device_manager_errno.h"
#include "device_manager_notify.h"
#include "ipc_def.h"
#include "dm_constants.h"
#include "dm_log.h"
#include "ipc_cmd_register.h"
#include "ipc_def.h"
namespace OHOS {
namespace DistributedHardware {
namespace {
const int32_t INVALID_CB_ID = 0xFF;
const int32_t INVALID_CB_ID = 0xFF;
}
static uint32_t g_deathCbId = INVALID_CB_ID;
static SvcIdentity g_svcIdentity;
@@ -43,23 +42,23 @@ int32_t DMDeathCallback(const IpcContext *ctx, void *ipcMsg, IpcIo *data, void *
(void)ipcMsg;
(void)data;
(void)arg;
DMLOG(DM_LOG_INFO, "ATTENTION SERVICE (%s) DEAD !!!\n", DEVICE_MANAGER_SERVICE_NAME);
LOGI("ATTENTION SERVICE (%s) DEAD !!!\n", DEVICE_MANAGER_SERVICE_NAME);
UnregisterDeathCallback(g_svcIdentity, g_deathCbId);
g_deathCbId = INVALID_CB_ID;
g_svcIdentity.handle = 0;
g_svcIdentity.token = 0;
g_svcIdentity.cookie = 0;
DeviceManagerNotify::GetInstance().OnRemoteDied();
return DEVICEMANAGER_OK;
return DM_OK;
}
static int32_t SendCmdResultCb(IOwner owner, int32_t code, IpcIo *reply)
{
(void)code;
int32_t cmdCode = *(int32_t *)owner;
DMLOG(DM_LOG_INFO, "SendCmdResultCb code:%d", cmdCode);
LOGI("SendCmdResultCb code:%d", cmdCode);
(void)IpcCmdRegister::GetInstance().ReadResponse(cmdCode, *reply, pCurRsp);
return DEVICEMANAGER_OK;
return DM_OK;
}
IClientProxy *IpcClientServerProxy::GetServerProxy(void)
@@ -67,14 +66,14 @@ IClientProxy *IpcClientServerProxy::GetServerProxy(void)
IClientProxy *clientProxy = nullptr;
IUnknown *iUnknown = nullptr;
DMLOG(DM_LOG_INFO, "start get client proxy");
LOGI("start get client proxy");
iUnknown = SAMGR_GetInstance()->GetDefaultFeatureApi(DEVICE_MANAGER_SERVICE_NAME);
if (iUnknown == nullptr) {
return nullptr;
}
if (iUnknown->QueryInterface(iUnknown, CLIENT_PROXY_VER, (void **)&clientProxy) != DEVICEMANAGER_OK ||
if (iUnknown->QueryInterface(iUnknown, CLIENT_PROXY_VER, (void **)&clientProxy) != DM_OK ||
clientProxy == nullptr) {
DMLOG(DM_LOG_ERROR, "QueryInterface failed");
LOGE("QueryInterface failed");
}
return clientProxy;
}
@@ -84,52 +83,52 @@ int IpcClientServerProxy::RegisterServerDeathCb(void)
g_svcIdentity = SAMGR_GetRemoteIdentity(DEVICE_MANAGER_SERVICE_NAME, nullptr);
g_deathCbId = INVALID_CB_ID;
if (RegisterDeathCallback(nullptr, g_svcIdentity, DMDeathCallback, nullptr, &g_deathCbId) != EC_SUCCESS) {
DMLOG(DM_LOG_ERROR, "reg death callback failed");
return DEVICEMANAGER_FAILED;
LOGE("reg death callback failed");
return DM_FAILED;
}
return DEVICEMANAGER_OK;
return DM_OK;
}
int32_t IpcClientServerProxy::SendCmd(int32_t cmdCode, std::shared_ptr<IpcReq> req, std::shared_ptr<IpcRsp> rsp)
{
DMLOG(DM_LOG_INFO, "SendCmd:%d", cmdCode);
LOGI("SendCmd:%d", cmdCode);
uint8_t data[MAX_DM_IPC_LEN] = {0};
IpcIo request;
if (IpcCmdRegister::GetInstance().SetRequest(cmdCode, req, request, data, MAX_DM_IPC_LEN) != DEVICEMANAGER_OK) {
return DEVICEMANAGER_FAILED;
if (IpcCmdRegister::GetInstance().SetRequest(cmdCode, req, request, data, MAX_DM_IPC_LEN) != DM_OK) {
return DM_FAILED;
}
{
std::lock_guard<std::mutex> autoLock(lock_);
pCurRsp = rsp;
if (serviceProxy_ != nullptr &&
serviceProxy_->Invoke(serviceProxy_, cmdCode, &request, &cmdCode, SendCmdResultCb) != 0) {
DMLOG(DM_LOG_ERROR, "serviceProxy_ invoke failed.");
return DEVICEMANAGER_FAILED;
LOGE("serviceProxy_ invoke failed.");
return DM_FAILED;
}
}
DMLOG(DM_LOG_INFO, "SendCmd:%d end", cmdCode);
return DEVICEMANAGER_OK;
LOGI("SendCmd:%d end", cmdCode);
return DM_OK;
}
int32_t IpcClientServerProxy::Init(void)
{
if (serviceProxy_ != nullptr) {
DMLOG(DM_LOG_INFO, "ServerProxy already Init");
return DEVICEMANAGER_OK;
LOGI("ServerProxy already Init");
return DM_OK;
}
HOS_SystemInit();
serviceProxy_ = GetServerProxy();
if (serviceProxy_ == nullptr) {
DMLOG(DM_LOG_ERROR, "get ipc client proxy failed");
return DEVICEMANAGER_FAILED;
LOGE("get ipc client proxy failed");
return DM_FAILED;
}
if (RegisterServerDeathCb() != DEVICEMANAGER_OK) {
DMLOG(DM_LOG_ERROR, "register server death cb failed");
return DEVICEMANAGER_FAILED;
if (RegisterServerDeathCb() != DM_OK) {
LOGE("register server death cb failed");
return DM_FAILED;
}
DMLOG(DM_LOG_INFO, "ServerProxyInit ok");
return DEVICEMANAGER_OK;
LOGI("ServerProxyInit ok");
return DM_OK;
}
} // namespace DistributedHardware
} // namespace OHOS
@@ -4,7 +4,7 @@
* 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
* 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,
@@ -15,12 +15,11 @@
#include "ipc_client_stub.h"
#include "device_manager_errno.h"
#include "device_manager_log.h"
#include "device_manager_notify.h"
#include "ipc_def.h"
#include "dm_constants.h"
#include "dm_log.h"
#include "ipc_cmd_register.h"
#include "ipc_def.h"
namespace OHOS {
namespace DistributedHardware {
@@ -30,16 +29,16 @@ static int32_t ClientIpcInterfaceMsgHandle(const IpcContext *ctx, void *ipcMsg,
{
(void)arg;
if (ipcMsg == nullptr || io == nullptr) {
DMLOG(DM_LOG_ERROR, "invalid param");
return DEVICEMANAGER_INVALID_PARAM;
LOGE("invalid param");
return DM_INPUT_PARA_EMPTY;
}
uint32_t code = 0;
GetCode(ipcMsg, &code);
int32_t errCode = DEVICEMANAGER_OK;
int32_t errCode = DM_OK;
errCode = IpcCmdRegister::GetInstance().OnIpcCmd(code, *io);
DMLOG(DM_LOG_INFO, "receive ipc transact code:%u, retCode=%d", code, errCode);
LOGI("receive ipc transact code:%u, retCode=%d", code, errCode);
FreeBuffer(ctx, ipcMsg);
return errCode;
}
@@ -48,14 +47,14 @@ int32_t IpcClientStub::Init()
{
std::lock_guard<std::mutex> autoLock(lock_);
if (bInit) {
return DEVICEMANAGER_OK;
return DM_OK;
}
if (RegisterIpcCallback(ClientIpcInterfaceMsgHandle, 0, IPC_WAIT_FOREVER, &clientIdentity_, nullptr) != 0) {
DMLOG(DM_LOG_ERROR, "register ipc cb failed");
return DEVICEMANAGER_FAILED;
LOGE("register ipc cb failed");
return DM_FAILED;
}
bInit = true;
return DEVICEMANAGER_OK;
return DM_OK;
}
} // namespace DistributedHardware
} // namespace OHOS
@@ -4,7 +4,7 @@
* 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
* 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,
@@ -13,32 +13,27 @@
* limitations under the License.
*/
#include "device_manager_notify.h"
#include "dm_constants.h"
#include "dm_device_info.h"
#include "dm_log.h"
#include "dm_subscribe_info.h"
#include "ipc_authenticate_device_req.h"
#include "ipc_cmd_register.h"
#include "ipc_def.h"
#include "securec.h"
#include "constants.h"
#include "device_manager_errno.h"
#include "device_manager_log.h"
#include "device_manager_notify.h"
#include "dm_device_info.h"
#include "dm_subscribe_info.h"
#include "ipc_get_local_device_info_rsp.h"
#include "ipc_get_trustdevice_req.h"
#include "ipc_get_trustdevice_rsp.h"
#include "ipc_register_listener_req.h"
#include "ipc_start_discovery_req.h"
#include "ipc_stop_discovery_req.h"
#include "ipc_get_trustdevice_req.h"
#include "ipc_get_trustdevice_rsp.h"
#include "ipc_authenticate_device_req.h"
#include "ipc_check_authenticate_req.h"
#include "ipc_get_authenticationparam_rsp.h"
#include "ipc_set_useroperation_req.h"
#include "ipc_verify_authenticate_req.h"
#include "securec.h"
namespace OHOS {
namespace DistributedHardware {
ON_IPC_SET_REQUEST(REGISTER_DEVICE_MANAGER_LISTENER, std::shared_ptr<IpcReq> pBaseReq, IpcIo &request,
uint8_t *buffer, size_t buffLen)
ON_IPC_SET_REQUEST(REGISTER_DEVICE_MANAGER_LISTENER, std::shared_ptr<IpcReq> pBaseReq, IpcIo &request, uint8_t *buffer,
size_t buffLen)
{
std::shared_ptr<IpcRegisterListenerReq> pReq = std::static_pointer_cast<IpcRegisterListenerReq>(pBaseReq);
std::string pkgName = pReq->GetPkgName();
@@ -47,47 +42,47 @@ ON_IPC_SET_REQUEST(REGISTER_DEVICE_MANAGER_LISTENER, std::shared_ptr<IpcReq> pBa
IpcIoInit(&request, buffer, buffLen, 1);
IpcIoPushString(&request, pkgName.c_str());
IpcIoPushSvc(&request, &svcIdentity);
return DEVICEMANAGER_OK;
return DM_OK;
}
ON_IPC_READ_RESPONSE(REGISTER_DEVICE_MANAGER_LISTENER, IpcIo &reply, std::shared_ptr<IpcRsp> pBaseRsp)
{
pBaseRsp->SetErrCode(IpcIoPopInt32(&reply));
return DEVICEMANAGER_OK;
return DM_OK;
}
ON_IPC_SET_REQUEST(UNREGISTER_DEVICE_MANAGER_LISTENER, std::shared_ptr<IpcReq> pBaseReq, IpcIo &request,
uint8_t *buffer, size_t buffLen)
uint8_t *buffer, size_t buffLen)
{
std::string pkgName = pBaseReq->GetPkgName();
IpcIoInit(&request, buffer, buffLen, 0);
IpcIoPushString(&request, pkgName.c_str());
return DEVICEMANAGER_OK;
return DM_OK;
}
ON_IPC_READ_RESPONSE(UNREGISTER_DEVICE_MANAGER_LISTENER, IpcIo &reply, std::shared_ptr<IpcRsp> pBaseRsp)
{
pBaseRsp->SetErrCode(IpcIoPopInt32(&reply));
return DEVICEMANAGER_OK;
return DM_OK;
}
ON_IPC_SET_REQUEST(GET_TRUST_DEVICE_LIST, std::shared_ptr<IpcReq> pBaseReq, IpcIo &request,
uint8_t *buffer, size_t buffLen)
ON_IPC_SET_REQUEST(GET_TRUST_DEVICE_LIST, std::shared_ptr<IpcReq> pBaseReq, IpcIo &request, uint8_t *buffer,
size_t buffLen)
{
std::shared_ptr<IpcGetTrustdeviceReq> pReq = std::static_pointer_cast<IpcGetTrustdeviceReq>(pBaseReq);
std::shared_ptr<IpcGetTrustDeviceReq> pReq = std::static_pointer_cast<IpcGetTrustDeviceReq>(pBaseReq);
std::string pkgName = pReq->GetPkgName();
std::string extra = pReq->GetExtra();
IpcIoInit(&request, buffer, buffLen, 0);
IpcIoPushString(&request, pkgName.c_str());
IpcIoPushString(&request, extra.c_str());
return DEVICEMANAGER_OK;
return DM_OK;
}
ON_IPC_READ_RESPONSE(GET_TRUST_DEVICE_LIST, IpcIo &reply, std::shared_ptr<IpcRsp> pBaseRsp)
{
std::shared_ptr<IpcGetTrustdeviceRsp> pRsp = std::static_pointer_cast<IpcGetTrustdeviceRsp>(pBaseRsp);
std::shared_ptr<IpcGetTrustDeviceRsp> pRsp = std::static_pointer_cast<IpcGetTrustDeviceRsp>(pBaseRsp);
int32_t deviceNum = IpcIoPopInt32(&reply);
uint32_t deviceTotalSize = deviceNum * (int32_t)sizeof(DmDeviceInfo);
@@ -95,9 +90,9 @@ ON_IPC_READ_RESPONSE(GET_TRUST_DEVICE_LIST, IpcIo &reply, std::shared_ptr<IpcRsp
std::vector<DmDeviceInfo> deviceInfoVec;
DmDeviceInfo *pDmDeviceinfo = (DmDeviceInfo *)IpcIoPopFlatObj(&reply, &deviceTotalSize);
if (pDmDeviceinfo == nullptr) {
DMLOG(DM_LOG_ERROR, "GetTrustedDeviceList read node info failed!");
pRsp->SetErrCode(DEVICEMANAGER_IPC_TRANSACTION_FAILED);
return DEVICEMANAGER_IPC_TRANSACTION_FAILED;
LOGE("GetTrustedDeviceList read node info failed!");
pRsp->SetErrCode(DM_IPC_TRANSACTION_FAILED);
return DM_IPC_TRANSACTION_FAILED;
}
for (int32_t i = 0; i < deviceNum; ++i) {
pDmDeviceinfo = pDmDeviceinfo + i;
@@ -106,30 +101,52 @@ ON_IPC_READ_RESPONSE(GET_TRUST_DEVICE_LIST, IpcIo &reply, std::shared_ptr<IpcRsp
pRsp->SetDeviceVec(deviceInfoVec);
}
pRsp->SetErrCode(IpcIoPopInt32(&reply));
return DEVICEMANAGER_OK;
return DM_OK;
}
ON_IPC_SET_REQUEST(START_DEVICE_DISCOVER, std::shared_ptr<IpcReq> pBaseReq, IpcIo &request,
uint8_t *buffer, size_t buffLen)
ON_IPC_SET_REQUEST(GET_LOCAL_DEVICE_INFO, std::shared_ptr<IpcReq> pBaseReq, IpcIo &request, uint8_t *buffer,
size_t buffLen)
{
IpcIoInit(&request, buffer, buffLen, 0);
return DM_OK;
}
ON_IPC_READ_RESPONSE(GET_LOCAL_DEVICE_INFO, IpcIo &reply, std::shared_ptr<IpcRsp> pBaseRsp)
{
std::shared_ptr<IpcGetLocalDeviceInfoRsp> pRsp = std::static_pointer_cast<IpcGetLocalDeviceInfoRsp>(pBaseRsp);
uint32_t size = 0;
DmDeviceInfo *dmDeviceInfo = (DmDeviceInfo *)IpcIoPopFlatObj(&reply, &size);
if (dmDeviceInfo != nullptr) {
pRsp->SetLocalDeviceInfo(*dmDeviceInfo);
}
pRsp->SetErrCode(IpcIoPopInt32(&reply));
return DM_OK;
}
ON_IPC_SET_REQUEST(START_DEVICE_DISCOVER, std::shared_ptr<IpcReq> pBaseReq, IpcIo &request, uint8_t *buffer,
size_t buffLen)
{
std::shared_ptr<IpcStartDiscoveryReq> pReq = std::static_pointer_cast<IpcStartDiscoveryReq>(pBaseReq);
std::string pkgName = pReq->GetPkgName();
std::string extra = pReq->GetExtra();
const DmSubscribeInfo dmSubscribeInfo = pReq->GetSubscribeInfo();
IpcIoInit(&request, buffer, buffLen, 0);
IpcIoPushString(&request, pkgName.c_str());
IpcIoPushString(&request, extra.c_str());
IpcIoPushFlatObj(&request, &dmSubscribeInfo, sizeof(DmSubscribeInfo));
return DEVICEMANAGER_OK;
return DM_OK;
}
ON_IPC_READ_RESPONSE(START_DEVICE_DISCOVER, IpcIo &reply, std::shared_ptr<IpcRsp> pBaseRsp)
{
pBaseRsp->SetErrCode(IpcIoPopInt32(&reply));
return DEVICEMANAGER_OK;
return DM_OK;
}
ON_IPC_SET_REQUEST(STOP_DEVICE_DISCOVER, std::shared_ptr<IpcReq> pBaseReq, IpcIo &request,
uint8_t *buffer, size_t buffLen)
ON_IPC_SET_REQUEST(STOP_DEVICE_DISCOVER, std::shared_ptr<IpcReq> pBaseReq, IpcIo &request, uint8_t *buffer,
size_t buffLen)
{
std::shared_ptr<IpcStopDiscoveryReq> pReq = std::static_pointer_cast<IpcStopDiscoveryReq>(pBaseReq);
std::string pkgName = pReq->GetPkgName();
@@ -138,21 +155,21 @@ ON_IPC_SET_REQUEST(STOP_DEVICE_DISCOVER, std::shared_ptr<IpcReq> pBaseReq, IpcIo
IpcIoInit(&request, buffer, buffLen, 0);
IpcIoPushString(&request, pkgName.c_str());
IpcIoPushUint16(&request, subscribeId);
return DEVICEMANAGER_OK;
return DM_OK;
}
ON_IPC_READ_RESPONSE(STOP_DEVICE_DISCOVER, IpcIo &reply, std::shared_ptr<IpcRsp> pBaseRsp)
{
pBaseRsp->SetErrCode(IpcIoPopInt32(&reply));
return DEVICEMANAGER_OK;
return DM_OK;
}
ON_IPC_SET_REQUEST(AUTHENTICATE_DEVICE, std::shared_ptr<IpcReq> pBaseReq, IpcIo &request,
uint8_t *buffer, size_t buffLen)
ON_IPC_SET_REQUEST(AUTHENTICATE_DEVICE, std::shared_ptr<IpcReq> pBaseReq, IpcIo &request, uint8_t *buffer,
size_t buffLen)
{
std::shared_ptr<IpcAuthenticateDeviceReq> pReq = std::static_pointer_cast<IpcAuthenticateDeviceReq>(pBaseReq);
std::string pkgName = pReq->GetPkgName();
std::string extra = pReq->GetExtra();
std::string extra = pReq->GetExtra();
DmDeviceInfo deviceInfo = pReq->GetDeviceInfo();
IpcIoInit(&request, buffer, buffLen, 0);
@@ -160,30 +177,49 @@ ON_IPC_SET_REQUEST(AUTHENTICATE_DEVICE, std::shared_ptr<IpcReq> pBaseReq, IpcIo
IpcIoPushString(&request, extra.c_str());
IpcIoPushFlatObj(&request, &deviceInfo, sizeof(DmDeviceInfo));
// L1 暂时没有考虑appimage校验(8k限制)
return DEVICEMANAGER_OK;
return DM_OK;
}
ON_IPC_READ_RESPONSE(AUTHENTICATE_DEVICE, IpcIo &reply, std::shared_ptr<IpcRsp> pBaseRsp)
{
pBaseRsp->SetErrCode(IpcIoPopInt32(&reply));
return DEVICEMANAGER_OK;
return DM_OK;
}
ON_IPC_SET_REQUEST(CHECK_AUTHENTICATION, std::shared_ptr<IpcReq> pBaseReq, IpcIo &request,
uint8_t *buffer, size_t buffLen)
ON_IPC_SET_REQUEST(VERIFY_AUTHENTICATION, std::shared_ptr<IpcReq> pBaseReq, IpcIo &request, uint8_t *buffer,
size_t buffLen)
{
std::shared_ptr<IpcCheckAuthenticateReq> pReq = std::static_pointer_cast<IpcCheckAuthenticateReq>(pBaseReq);
std::shared_ptr<IpcVerifyAuthenticateReq> pReq = std::static_pointer_cast<IpcVerifyAuthenticateReq>(pBaseReq);
std::string authPara = pReq->GetAuthPara();
IpcIoInit(&request, buffer, buffLen, 0);
IpcIoPushString(&request, authPara.c_str());
return DEVICEMANAGER_OK;
return DM_OK;
}
ON_IPC_READ_RESPONSE(CHECK_AUTHENTICATION, IpcIo &reply, std::shared_ptr<IpcRsp> pBaseRsp)
ON_IPC_READ_RESPONSE(VERIFY_AUTHENTICATION, IpcIo &reply, std::shared_ptr<IpcRsp> pBaseRsp)
{
pBaseRsp->SetErrCode(IpcIoPopInt32(&reply));
return DEVICEMANAGER_OK;
return DM_OK;
}
ON_IPC_SET_REQUEST(SERVER_USER_AUTH_OPERATION, std::shared_ptr<IpcReq> pBaseReq, IpcIo &request, uint8_t *buffer,
size_t buffLen)
{
std::shared_ptr<IpcGetOperationReq> pReq = std::static_pointer_cast<IpcGetOperationReq>(pBaseReq);
std::string pkgName = pReq->GetPkgName();
int32_t action = pReq->GetOperation();
IpcIoInit(&request, buffer, buffLen, 0);
IpcIoPushString(&request, pkgName.c_str());
IpcIoPushInt32(&request, action);
return DM_OK;
}
ON_IPC_READ_RESPONSE(SERVER_USER_AUTH_OPERATION, IpcIo &reply, std::shared_ptr<IpcRsp> pBaseRsp)
{
pBaseRsp->SetErrCode(IpcIoPopInt32(&reply));
return DM_OK;
}
ON_IPC_CMD(SERVER_DEVICE_STATE_NOTIFY, IpcIo &reply)
@@ -192,9 +228,9 @@ ON_IPC_CMD(SERVER_DEVICE_STATE_NOTIFY, IpcIo &reply)
std::string pkgName = (const char *)IpcIoPopString(&reply, &len);
DmDeviceState deviceState = static_cast<DmDeviceState>(IpcIoPopInt32(&reply));
uint32_t size;
const DmDeviceInfo *deviceInfo = (const DmDeviceInfo*)IpcIoPopFlatObj(&reply, &size);
const DmDeviceInfo *deviceInfo = (const DmDeviceInfo *)IpcIoPopFlatObj(&reply, &size);
if (pkgName == "" || len == 0 || deviceInfo == NULL) {
DMLOG(DM_LOG_ERROR, "OnDeviceOnline, get para failed");
LOGE("OnDeviceOnline, get para failed");
return;
}
switch (deviceState) {
@@ -208,7 +244,7 @@ ON_IPC_CMD(SERVER_DEVICE_STATE_NOTIFY, IpcIo &reply)
DeviceManagerNotify::GetInstance().OnDeviceChanged(pkgName, *deviceInfo);
break;
default:
DMLOG(DM_LOG_ERROR, "unknown device state:%d", deviceState);
LOGE("unknown device state:%d", deviceState);
break;
}
}
@@ -219,9 +255,9 @@ ON_IPC_CMD(SERVER_DEVICE_FOUND, IpcIo &reply)
std::string pkgName = (const char *)IpcIoPopString(&reply, &len);
uint16_t subscribeId = IpcIoPopUint16(&reply);
uint32_t size;
const DmDeviceInfo *deviceInfo = (const DmDeviceInfo*)IpcIoPopFlatObj(&reply, &size);
const DmDeviceInfo *deviceInfo = (const DmDeviceInfo *)IpcIoPopFlatObj(&reply, &size);
if (pkgName == "" || len == 0 || deviceInfo == NULL) {
DMLOG(DM_LOG_ERROR, "OnDeviceChanged, get para failed");
LOGE("OnDeviceChanged, get para failed");
return;
}
DeviceManagerNotify::GetInstance().OnDeviceFound(pkgName, subscribeId, *deviceInfo);
@@ -235,13 +271,13 @@ ON_IPC_CMD(SERVER_DISCOVER_FINISH, IpcIo &reply)
int32_t failedReason = IpcIoPopInt32(&reply);
if (pkgName == "" || len == 0) {
DMLOG(DM_LOG_ERROR, "OnDiscoverySuccess, get para failed");
LOGE("OnDiscoverySuccess, get para failed");
return;
}
if (failedReason == DEVICEMANAGER_OK) {
if (failedReason == DM_OK) {
DeviceManagerNotify::GetInstance().OnDiscoverySuccess(pkgName, subscribeId);
} else {
DeviceManagerNotify::GetInstance().OnDiscoverFailed(pkgName, subscribeId, failedReason);
DeviceManagerNotify::GetInstance().OnDiscoveryFailed(pkgName, subscribeId, failedReason);
}
}
@@ -251,18 +287,18 @@ ON_IPC_CMD(SERVER_AUTH_RESULT, IpcIo &reply)
std::string pkgName = (const char *)IpcIoPopString(&reply, &len);
size_t devIdLen = 0;
std::string deviceId = (const char *)IpcIoPopString(&reply, &devIdLen);
int32_t pinToken = IpcIoPopInt32(&reply);
// int32_t pinToken = IpcIoPopInt32(&reply);
int32_t status = IpcIoPopInt32(&reply);
int32_t reason = IpcIoPopInt32(&reply);
if (pkgName == "" || len == 0 || deviceId == "" || devIdLen == 0) {
DMLOG(DM_LOG_ERROR, "OnAuthResult, get para failed");
LOGE("OnAuthResult, get para failed");
return;
}
DeviceManagerNotify::GetInstance().OnAuthResult(pkgName, deviceId, pinToken, status, reason);
DeviceManagerNotify::GetInstance().OnAuthResult(pkgName, deviceId, nullptr, status, reason);
}
ON_IPC_CMD(SERVER_CHECK_AUTH_RESULT, IpcIo &reply)
ON_IPC_CMD(SERVER_VERIFY_AUTH_RESULT, IpcIo &reply)
{
size_t len = 0;
std::string pkgName = (const char *)IpcIoPopString(&reply, &len);
@@ -272,80 +308,13 @@ ON_IPC_CMD(SERVER_CHECK_AUTH_RESULT, IpcIo &reply)
int32_t flag = IpcIoPopInt32(&reply);
if (pkgName == "" || len == 0 || deviceId == "" || devIdLen == 0) {
DMLOG(DM_LOG_ERROR, "OnAuthResult, get para failed");
LOGE("OnAuthResult, get para failed");
return;
}
DeviceManagerNotify::GetInstance().OnCheckAuthResult(pkgName, deviceId, resultCode, flag);
DeviceManagerNotify::GetInstance().OnVerifyAuthResult(pkgName, deviceId, resultCode, flag);
}
ON_IPC_SET_REQUEST(SERVER_GET_AUTHENTCATION_INFO, std::shared_ptr<IpcReq> pBaseReq, IpcIo& request,
uint8_t *buffer, size_t buffLen)
{
std::shared_ptr<IpcReq> pReq = std::static_pointer_cast<IpcReq>(pBaseReq);
std::string packagename = pReq->GetPkgName();
IpcIoInit(&request, buffer, buffLen, 0);
IpcIoPushString(&request, packagename.c_str());
return DEVICEMANAGER_OK;
}
ON_IPC_READ_RESPONSE(SERVER_GET_AUTHENTCATION_INFO, IpcIo& reply, std::shared_ptr<IpcRsp> pBaseRsp)
{
std::shared_ptr<IpcGetAuthParamRsp> pRsp = std::static_pointer_cast<IpcGetAuthParamRsp>(pBaseRsp);
DmAuthParam authParam = {0};
authParam.direction = IpcIoPopInt32(&reply);
authParam.authType = IpcIoPopInt32(&reply);
if (authParam.direction == AUTH_SESSION_SIDE_CLIENT) {
authParam.pinToken = IpcIoPopInt32(&reply);
pRsp->SetAuthParam(authParam);
return DEVICEMANAGER_OK;
}
size_t PackagerNamelen = 0;
authParam.packageName = strdup((const char *)IpcIoPopString(&reply, &PackagerNamelen));
size_t appNameLen = 0;
authParam.appName = strdup((const char *)IpcIoPopString(&reply, &appNameLen));
size_t appDesLen = 0;
authParam.appDescription = strdup((const char *)IpcIoPopString(&reply, &appDesLen));
authParam.business = IpcIoPopInt32(&reply);
authParam.pincode = IpcIoPopInt32(&reply);
uint32_t appIconLen = IpcIoPopInt32(&reply);
uint8_t *appIconBuffer = nullptr;
uint32_t appThumbnailLen = IpcIoPopInt32(&reply);
uint8_t *appThumbBuffer = nullptr;
if (appIconLen > 0) {
appIconBuffer = (uint8_t *)IpcIoPopFlatObj(&reply, &appIconLen);
}
if (appThumbnailLen > 0) {
appThumbBuffer = (uint8_t *)IpcIoPopFlatObj(&reply, &appThumbnailLen);
}
authParam.imageinfo.Reset(appIconBuffer, appIconLen, appThumbBuffer, appThumbnailLen);
pRsp->SetAuthParam(authParam);
return DEVICEMANAGER_OK;
}
ON_IPC_SET_REQUEST(SERVER_USER_AUTHORIZATION_OPERATION, std::shared_ptr<IpcReq> pBaseReq, IpcIo& request,
uint8_t *buffer, size_t buffLen)
{
std::shared_ptr<IpcGetOperationReq> pReq = std::static_pointer_cast<IpcGetOperationReq>(pBaseReq);
std::string pkgName= pReq->GetPkgName();
int32_t action = pReq->GetOperation();
IpcIoInit(&request, buffer, buffLen, 0);
IpcIoPushString(&request, pkgName.c_str());
IpcIoPushInt32(&request, action);
return DEVICEMANAGER_OK;
}
ON_IPC_READ_RESPONSE(SERVER_USER_AUTHORIZATION_OPERATION, IpcIo& reply, std::shared_ptr<IpcRsp> pBaseRsp)
{
pBaseRsp->SetErrCode(IpcIoPopInt32(&reply));
return DEVICEMANAGER_OK;
}
ON_IPC_CMD(SERVER_DEVICEMANAGER_FA_NOTIFY, IpcIo &reply)
ON_IPC_CMD(SERVER_DEVICE_FA_NOTIFY, IpcIo &reply)
{
size_t len = 0;
std::string packagename = (const char *)IpcIoPopString(&reply, &len);
@@ -4,7 +4,7 @@
* 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
* 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,
@@ -15,68 +15,67 @@
#include "ipc_client_manager.h"
#include "device_manager_notify.h"
#include "dm_constants.h"
#include "dm_log.h"
#include "ipc_client_stub.h"
#include "ipc_register_listener_req.h"
#include "ipc_remote_broker.h"
#include "iremote_object.h"
#include "iservice_registry.h"
#include "system_ability_definition.h"
#include "device_manager_errno.h"
#include "device_manager_log.h"
#include "device_manager_notify.h"
#include "ipc_register_listener_req.h"
namespace OHOS {
namespace DistributedHardware {
void DmDeathRecipient::OnRemoteDied(const wptr<IRemoteObject> &remote)
{
(void)remote;
DMLOG(DM_LOG_WARN, "DmDeathRecipient : OnRemoteDied");
LOGW("DmDeathRecipient : OnRemoteDied");
DeviceManagerNotify::GetInstance().OnRemoteDied();
}
int32_t IpcClientManager::ClientInit()
{
DMLOG(DM_LOG_INFO, "InitDeviceManagerService start");
LOGI("InitDeviceManagerService start");
if (dmInterface_ != nullptr) {
DMLOG(DM_LOG_INFO, "DeviceManagerService Already Init");
return DEVICEMANAGER_OK;
LOGI("DeviceManagerService Already Init");
return DM_OK;
}
auto samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
if (samgr == nullptr) {
DMLOG(DM_LOG_ERROR, "Get SystemAbilityManager Failed");
return DEVICEMANAGER_SERVICE_NOT_READY;
LOGE("Get SystemAbilityManager Failed");
return DM_SERVICE_NOT_READY;
}
auto object = samgr->CheckSystemAbility(DISTRIBUTED_HARDWARE_DEVICEMANAGER_SA_ID);
if (object == nullptr) {
DMLOG(DM_LOG_ERROR, "Get DeviceManager SystemAbility Failed");
return DEVICEMANAGER_SERVICE_NOT_READY;
LOGE("Get DeviceManager SystemAbility Failed");
return DM_SERVICE_NOT_READY;
}
if (dmRecipient_ == nullptr) {
dmRecipient_ = sptr<DmDeathRecipient>(new DmDeathRecipient());
}
if (!object->AddDeathRecipient(dmRecipient_)) {
DMLOG(DM_LOG_ERROR, "InitDeviceManagerService: AddDeathRecipient Failed");
LOGE("InitDeviceManagerService: AddDeathRecipient Failed");
}
dmInterface_ = iface_cast<IpcRemoteBroker>(object);
DMLOG(DM_LOG_INFO, "DeviceManager::InitDeviceManagerService completed");
return DEVICEMANAGER_OK;
LOGI("DeviceManager::InitDeviceManagerService completed");
return DM_OK;
}
int32_t IpcClientManager::Init(std::string &pkgName)
int32_t IpcClientManager::Init(const std::string &pkgName)
{
std::lock_guard<std::mutex> autoLock(lock_);
int32_t ret = ClientInit();
if (ret != DEVICEMANAGER_OK) {
DMLOG(DM_LOG_ERROR, "InitDeviceManager Failed with ret %d", ret);
if (ret != DM_OK) {
LOGE("InitDeviceManager Failed with ret %d", ret);
return ret;
}
if (dmListener_.count(pkgName) > 0) {
DMLOG(DM_LOG_INFO, "dmListener_ Already Init");
return DEVICEMANAGER_OK;
LOGI("dmListener_ Already Init");
return DM_OK;
}
sptr<IpcClientStub> listener = sptr<IpcClientStub>(new IpcClientStub());
@@ -85,25 +84,25 @@ int32_t IpcClientManager::Init(std::string &pkgName)
req->SetPkgName(pkgName);
req->SetListener(listener);
ret = dmInterface_->SendCmd(REGISTER_DEVICE_MANAGER_LISTENER, req, rsp);
if (ret != DEVICEMANAGER_OK) {
DMLOG(DM_LOG_ERROR, "InitDeviceManager: RegisterDeviceManagerListener Failed with ret %d", ret);
if (ret != DM_OK) {
LOGE("InitDeviceManager: RegisterDeviceManagerListener Failed with ret %d", ret);
return ret;
}
ret = rsp->GetErrCode();
if (ret != DEVICEMANAGER_OK) {
if (ret != DM_OK) {
return ret;
}
dmListener_[pkgName] = listener;
DMLOG(DM_LOG_INFO, "completed, pkgName: %s", pkgName.c_str());
return DEVICEMANAGER_OK;
LOGI("completed, pkgName: %s", pkgName.c_str());
return DM_OK;
}
int32_t IpcClientManager::UnInit(std::string &pkgName)
int32_t IpcClientManager::UnInit(const std::string &pkgName)
{
DMLOG(DM_LOG_INFO, "in, pkgName %s", pkgName.c_str());
LOGI("in, pkgName %s", pkgName.c_str());
if (dmInterface_ == nullptr) {
DMLOG(DM_LOG_ERROR, "DeviceManager not Init");
return DEVICEMANAGER_SERVICE_NOT_READY;
LOGE("DeviceManager not Init");
return DM_SERVICE_NOT_READY;
}
std::lock_guard<std::mutex> autoLock(lock_);
@@ -112,8 +111,8 @@ int32_t IpcClientManager::UnInit(std::string &pkgName)
std::shared_ptr<IpcRsp> rsp = std::make_shared<IpcRsp>();
req->SetPkgName(pkgName);
int32_t ret = dmInterface_->SendCmd(UNREGISTER_DEVICE_MANAGER_LISTENER, req, rsp);
if (ret != DEVICEMANAGER_OK) {
DMLOG(DM_LOG_ERROR, "UnRegisterDeviceManagerListener Failed with ret %d", ret);
if (ret != DM_OK) {
LOGE("UnRegisterDeviceManagerListener Failed with ret %d", ret);
return ret;
}
dmListener_.erase(pkgName);
@@ -122,28 +121,30 @@ int32_t IpcClientManager::UnInit(std::string &pkgName)
dmInterface_ = nullptr;
dmRecipient_ = nullptr;
}
DMLOG(DM_LOG_INFO, "completed, pkgName: %s", pkgName.c_str());
return DEVICEMANAGER_OK;
LOGI("completed, pkgName: %s", pkgName.c_str());
return DM_OK;
}
int32_t IpcClientManager::SendRequest(int32_t cmdCode, std::shared_ptr<IpcReq> req, std::shared_ptr<IpcRsp> rsp)
{
LOGI("IpcClientManager::SendRequest in");
std::string pkgName = req->GetPkgName();
if (!IsInit(pkgName)) {
return DEVICEMANAGER_SERVICE_NOT_READY;
LOGE("IpcClientManager::SendRequest DM_SERVICE_NOT_READY");
return DM_SERVICE_NOT_READY;
}
return dmInterface_->SendCmd(cmdCode, req, rsp);
}
bool IpcClientManager::IsInit(std::string &pkgName)
bool IpcClientManager::IsInit(const std::string &pkgName)
{
if (dmInterface_ == nullptr) {
DMLOG(DM_LOG_ERROR, "DeviceManager not Init");
LOGE("DeviceManager not Init");
return false;
}
std::lock_guard<std::mutex> autoLock(lock_);
if (dmListener_.count(pkgName) == 0) {
DMLOG(DM_LOG_ERROR, "dmListener_ not Init for %s", pkgName.c_str());
LOGE("dmListener_ not Init for %s", pkgName.c_str());
return false;
}
return true;
@@ -4,7 +4,7 @@
* 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
* 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,
@@ -15,31 +15,30 @@
#include "ipc_client_server_proxy.h"
#include "dm_constants.h"
#include "dm_log.h"
#include "ipc_cmd_register.h"
#include "ipc_types.h"
#include "device_manager_log.h"
#include "device_manager_errno.h"
namespace OHOS {
namespace DistributedHardware {
int32_t IpcClientServerProxy::SendCmd(int32_t cmdCode, std::shared_ptr<IpcReq> req, std::shared_ptr<IpcRsp> rsp)
{
sptr<IRemoteObject> remote = Remote();
if (remote == nullptr) {
DMLOG(DM_LOG_ERROR, "remote service null");
return DEVICEMANAGER_NULLPTR;
LOGE("remote service null");
return DM_POINT_NULL;
}
MessageParcel data;
MessageParcel reply;
MessageOption option;
if (IpcCmdRegister::GetInstance().SetRequest(cmdCode, req, data) != DEVICEMANAGER_OK) {
return DEVICEMANAGER_FAILED;
if (IpcCmdRegister::GetInstance().SetRequest(cmdCode, req, data) != DM_OK) {
return DM_IPC_SEND_REQUEST_FAILED;
}
if (remote->SendRequest(cmdCode, data, reply, option) != DEVICEMANAGER_OK) {
DMLOG(DM_LOG_ERROR, "SendRequest fail, cmd:%d", cmdCode);
return DEVICEMANAGER_IPC_FAILED;
if (remote->SendRequest(cmdCode, data, reply, option) != DM_OK) {
LOGE("SendRequest fail, cmd:%d", cmdCode);
return DM_IPC_SEND_REQUEST_FAILED;
}
return IpcCmdRegister::GetInstance().ReadResponse(cmdCode, reply, rsp);
}
@@ -4,7 +4,7 @@
* 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
* 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,
@@ -15,31 +15,28 @@
#include "ipc_client_stub.h"
#include "dm_constants.h"
#include "dm_log.h"
#include "ipc_cmd_register.h"
#include "ipc_skeleton.h"
#include "ipc_types.h"
#include "ipc_cmd_register.h"
#include "device_manager_log.h"
#include "device_manager_errno.h"
namespace OHOS {
namespace DistributedHardware {
int32_t IpcClientStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply,
MessageOption &option)
int32_t IpcClientStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
{
DMLOG(DM_LOG_INFO, "code = %d, flags= %d.", code, option.GetFlags());
if (IpcCmdRegister::GetInstance().OnIpcCmd(code, data, reply) == DEVICEMANAGER_OK) {
return DEVICEMANAGER_OK;
LOGI("code = %d, flags= %d.", code, option.GetFlags());
if (IpcCmdRegister::GetInstance().OnIpcCmd(code, data, reply) == DM_OK) {
return DM_OK;
}
DMLOG(DM_LOG_WARN, "unsupport code: %d", code);
LOGW("unsupport code: %d", code);
return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
}
int32_t IpcClientStub::SendCmd(int32_t cmdCode, std::shared_ptr<IpcReq> req, std::shared_ptr<IpcRsp> rsp)
{
DMLOG(DM_LOG_ERROR, "error");
return DEVICEMANAGER_OK;
LOGE("error");
return DM_OK;
}
} // namespace DistributedHardware
} // namespace OHOS
@@ -4,7 +4,7 @@
* 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
* 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,
@@ -13,24 +13,28 @@
* limitations under the License.
*/
#include "ipc_cmd_register.h"
#include "securec.h"
#include "constants.h"
#include "device_manager_errno.h"
#include "device_manager_log.h"
#include "device_manager_notify.h"
#include "dm_constants.h"
#include "dm_device_info.h"
#include "dm_log.h"
#include "ipc_authenticate_device_req.h"
#include "ipc_cmd_register.h"
#include "ipc_def.h"
#include "ipc_register_listener_req.h"
#include "ipc_start_discovery_req.h"
#include "ipc_stop_discovery_req.h"
#include "ipc_get_dmfaparam_rsp.h"
#include "ipc_get_info_by_network_req.h"
#include "ipc_get_info_by_network_rsp.h"
#include "ipc_get_local_device_info_rsp.h"
#include "ipc_get_trustdevice_req.h"
#include "ipc_get_trustdevice_rsp.h"
#include "ipc_authenticate_device_req.h"
#include "ipc_check_authenticate_req.h"
#include "ipc_get_authenticationparam_rsp.h"
#include "ipc_register_listener_req.h"
#include "ipc_req.h"
#include "ipc_rsp.h"
#include "ipc_set_useroperation_req.h"
#include "ipc_start_discovery_req.h"
#include "ipc_stop_discovery_req.h"
#include "ipc_unauthenticate_device_req.h"
#include "ipc_verify_authenticate_req.h"
#include "securec.h"
namespace OHOS {
namespace DistributedHardware {
@@ -40,75 +44,141 @@ ON_IPC_SET_REQUEST(REGISTER_DEVICE_MANAGER_LISTENER, std::shared_ptr<IpcReq> pBa
std::string pkgName = pReq->GetPkgName();
sptr<IRemoteObject> listener = pReq->GetListener();
if (!data.WriteString(pkgName)) {
DMLOG(DM_LOG_ERROR, "write pkgName failed");
return DEVICEMANAGER_FLATTEN_OBJECT;
LOGE("write pkgName failed");
return DM_IPC_TRANSACTION_FAILED;
}
if (!data.WriteRemoteObject(listener)) {
DMLOG(DM_LOG_ERROR, "write listener failed");
return DEVICEMANAGER_FLATTEN_OBJECT;
LOGE("write listener failed");
return DM_IPC_TRANSACTION_FAILED;
}
return DEVICEMANAGER_OK;
return DM_OK;
}
ON_IPC_READ_RESPONSE(REGISTER_DEVICE_MANAGER_LISTENER, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
{
pBaseRsp->SetErrCode(reply.ReadInt32());
return DEVICEMANAGER_OK;
return DM_OK;
}
ON_IPC_SET_REQUEST(UNREGISTER_DEVICE_MANAGER_LISTENER, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
{
std::string pkgName = pBaseReq->GetPkgName();
if (!data.WriteString(pkgName)) {
DMLOG(DM_LOG_ERROR, "write papam failed");
return DEVICEMANAGER_FLATTEN_OBJECT;
LOGE("write papam failed");
return DM_IPC_TRANSACTION_FAILED;
}
return DEVICEMANAGER_OK;
return DM_OK;
}
ON_IPC_READ_RESPONSE(UNREGISTER_DEVICE_MANAGER_LISTENER, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
{
pBaseRsp->SetErrCode(reply.ReadInt32());
return DEVICEMANAGER_OK;
return DM_OK;
}
ON_IPC_SET_REQUEST(GET_TRUST_DEVICE_LIST, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
{
std::shared_ptr<IpcGetTrustdeviceReq> pReq = std::static_pointer_cast<IpcGetTrustdeviceReq>(pBaseReq);
std::shared_ptr<IpcGetTrustDeviceReq> pReq = std::static_pointer_cast<IpcGetTrustDeviceReq>(pBaseReq);
std::string pkgName = pReq->GetPkgName();
std::string extra = pReq->GetExtra();
if (!data.WriteString(pkgName)) {
DMLOG(DM_LOG_ERROR, "write pkg failed");
return DEVICEMANAGER_FLATTEN_OBJECT;
LOGE("write pkg failed");
return DM_IPC_TRANSACTION_FAILED;
}
if (!data.WriteString(extra)) {
DMLOG(DM_LOG_ERROR, "write extra failed");
return DEVICEMANAGER_FLATTEN_OBJECT;
LOGE("write extra failed");
return DM_IPC_TRANSACTION_FAILED;
}
return DEVICEMANAGER_OK;
return DM_OK;
}
ON_IPC_READ_RESPONSE(GET_TRUST_DEVICE_LIST, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
{
std::shared_ptr<IpcGetTrustdeviceRsp> pRsp = std::static_pointer_cast<IpcGetTrustdeviceRsp>(pBaseRsp);
std::shared_ptr<IpcGetTrustDeviceRsp> pRsp = std::static_pointer_cast<IpcGetTrustDeviceRsp>(pBaseRsp);
int32_t deviceNum = reply.ReadInt32();
int32_t deviceTotalSize = deviceNum * (int32_t)sizeof(DmDeviceInfo);
if (deviceTotalSize > 0) {
if (deviceNum > 0) {
std::vector<DmDeviceInfo> deviceInfoVec;
DmDeviceInfo *pDmDeviceinfo = (DmDeviceInfo *)reply.ReadRawData(deviceTotalSize);
if (pDmDeviceinfo == nullptr) {
DMLOG(DM_LOG_ERROR, "GetTrustedDeviceList read node info failed!");
pRsp->SetErrCode(DEVICEMANAGER_IPC_TRANSACTION_FAILED);
return DEVICEMANAGER_IPC_TRANSACTION_FAILED;
}
DmDeviceInfo *pDmDeviceinfo = nullptr;
for (int32_t i = 0; i < deviceNum; ++i) {
pDmDeviceinfo = pDmDeviceinfo + i;
pDmDeviceinfo = nullptr;
pDmDeviceinfo = (DmDeviceInfo *)reply.ReadRawData((int32_t)sizeof(DmDeviceInfo));
if (pDmDeviceinfo == nullptr) {
LOGE("GetTrustedDeviceList read node info failed!");
pRsp->SetErrCode(DM_IPC_TRANSACTION_FAILED);
return DM_IPC_TRANSACTION_FAILED;
}
deviceInfoVec.emplace_back(*pDmDeviceinfo);
}
pRsp->SetDeviceVec(deviceInfoVec);
}
pRsp->SetErrCode(reply.ReadInt32());
return DEVICEMANAGER_OK;
return DM_OK;
}
ON_IPC_SET_REQUEST(GET_LOCAL_DEVICE_INFO, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
{
std::shared_ptr<IpcReq> pReq = std::static_pointer_cast<IpcReq>(pBaseReq);
std::string pkgName = pReq->GetPkgName();
if (!data.WriteString(pkgName)) {
return DM_FLATTEN_OBJECT;
}
return DM_OK;
}
ON_IPC_READ_RESPONSE(GET_LOCAL_DEVICE_INFO, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
{
std::shared_ptr<IpcGetLocalDeviceInfoRsp> pRsp = std::static_pointer_cast<IpcGetLocalDeviceInfoRsp>(pBaseRsp);
DmDeviceInfo *localDeviceInfo = (DmDeviceInfo *)reply.ReadRawData(sizeof(DmDeviceInfo));
if (localDeviceInfo == nullptr) {
LOGE("write subscribe info failed");
}
pRsp->SetLocalDeviceInfo(*localDeviceInfo);
pRsp->SetErrCode(reply.ReadInt32());
return DM_OK;
}
ON_IPC_SET_REQUEST(GET_UDID_BY_NETWORK, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
{
std::shared_ptr<IpcGetInfoByNetWorkReq> pReq = std::static_pointer_cast<IpcGetInfoByNetWorkReq>(pBaseReq);
std::string pkgName = pReq->GetPkgName();
std::string netWorkId = pReq->GetNetWorkId();
if (!data.WriteString(pkgName)) {
return DM_FLATTEN_OBJECT;
}
if (!data.WriteString(netWorkId)) {
return DM_FLATTEN_OBJECT;
}
return DM_OK;
}
ON_IPC_READ_RESPONSE(GET_UDID_BY_NETWORK, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
{
std::shared_ptr<IpcGetInfoByNetWorkRsp> pRsp = std::static_pointer_cast<IpcGetInfoByNetWorkRsp>(pBaseRsp);
pRsp->SetErrCode(reply.ReadInt32());
pRsp->SetUdid(reply.ReadString());
return DM_OK;
}
ON_IPC_SET_REQUEST(GET_UUID_BY_NETWORK, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
{
std::shared_ptr<IpcGetInfoByNetWorkReq> pReq = std::static_pointer_cast<IpcGetInfoByNetWorkReq>(pBaseReq);
std::string pkgName = pReq->GetPkgName();
std::string netWorkId = pReq->GetNetWorkId();
if (!data.WriteString(pkgName)) {
return DM_FLATTEN_OBJECT;
}
if (!data.WriteString(netWorkId)) {
return DM_FLATTEN_OBJECT;
}
return DM_OK;
}
ON_IPC_READ_RESPONSE(GET_UUID_BY_NETWORK, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
{
std::shared_ptr<IpcGetInfoByNetWorkRsp> pRsp = std::static_pointer_cast<IpcGetInfoByNetWorkRsp>(pBaseRsp);
pRsp->SetErrCode(reply.ReadInt32());
pRsp->SetUuid(reply.ReadString());
return DM_OK;
}
ON_IPC_SET_REQUEST(START_DEVICE_DISCOVER, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
@@ -117,20 +187,20 @@ ON_IPC_SET_REQUEST(START_DEVICE_DISCOVER, std::shared_ptr<IpcReq> pBaseReq, Mess
std::string pkgName = pReq->GetPkgName();
const DmSubscribeInfo dmSubscribeInfo = pReq->GetSubscribeInfo();
if (!data.WriteString(pkgName)) {
DMLOG(DM_LOG_ERROR, "write pkgName failed");
return DEVICEMANAGER_FLATTEN_OBJECT;
LOGE("write pkgName failed");
return DM_IPC_FLATTEN_OBJECT;
}
if (!data.WriteRawData(&dmSubscribeInfo, sizeof(DmSubscribeInfo))) {
DMLOG(DM_LOG_ERROR, "write subscribe info failed");
return DEVICEMANAGER_FLATTEN_OBJECT;
LOGE("write subscribe info failed");
return DM_IPC_FLATTEN_OBJECT;
}
return DEVICEMANAGER_OK;
return DM_OK;
}
ON_IPC_READ_RESPONSE(START_DEVICE_DISCOVER, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
{
pBaseRsp->SetErrCode(reply.ReadInt32());
return DEVICEMANAGER_OK;
return DM_OK;
}
ON_IPC_SET_REQUEST(STOP_DEVICE_DISCOVER, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
@@ -139,83 +209,145 @@ ON_IPC_SET_REQUEST(STOP_DEVICE_DISCOVER, std::shared_ptr<IpcReq> pBaseReq, Messa
std::string pkgName = pReq->GetPkgName();
uint16_t subscribeId = pReq->GetSubscribeId();
if (!data.WriteString(pkgName)) {
DMLOG(DM_LOG_ERROR, "write pkgName failed");
return DEVICEMANAGER_FLATTEN_OBJECT;
LOGE("write pkgName failed");
return DM_IPC_FLATTEN_OBJECT;
}
if (!data.WriteInt16(subscribeId)) {
DMLOG(DM_LOG_ERROR, "write subscribeId failed");
return DEVICEMANAGER_FLATTEN_OBJECT;
LOGE("write subscribeId failed");
return DM_IPC_FLATTEN_OBJECT;
}
return DEVICEMANAGER_OK;
return DM_OK;
}
ON_IPC_READ_RESPONSE(STOP_DEVICE_DISCOVER, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
{
pBaseRsp->SetErrCode(reply.ReadInt32());
return DEVICEMANAGER_OK;
return DM_OK;
}
ON_IPC_SET_REQUEST(AUTHENTICATE_DEVICE, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
{
std::shared_ptr<IpcAuthenticateDeviceReq> pReq = std::static_pointer_cast<IpcAuthenticateDeviceReq>(pBaseReq);
std::string pkgName = pReq->GetPkgName();
std::string extra = pReq->GetExtra();
std::string extra = pReq->GetExtra();
int32_t authType = pReq->GetAuthType();
DmDeviceInfo deviceInfo = pReq->GetDeviceInfo();
DmAppImageInfo imageInfo = pReq->GetAppImageInfo();
std::string deviceId = deviceInfo.deviceId;
// DmAppImageInfo imageInfo = pReq->GetAppImageInfo();
if (!data.WriteString(pkgName)) {
DMLOG(DM_LOG_ERROR, "write pkgName failed");
return DEVICEMANAGER_FLATTEN_OBJECT;
LOGE("write pkgName failed");
return DM_IPC_FLATTEN_OBJECT;
}
if (!data.WriteString(extra)) {
DMLOG(DM_LOG_ERROR, "write extra failed");
return DEVICEMANAGER_FLATTEN_OBJECT;
LOGE("write extra failed");
return DM_IPC_FLATTEN_OBJECT;
}
if (!data.WriteRawData(&deviceInfo, sizeof(DmDeviceInfo))) {
DMLOG(DM_LOG_ERROR, "write deviceInfo failed");
return DEVICEMANAGER_FLATTEN_OBJECT;
if (!data.WriteString(deviceId)) {
LOGE("write extra failed");
return DM_IPC_FLATTEN_OBJECT;
}
int32_t appIconLen = imageInfo.GetAppIconLen();
int32_t appThumbnailLen = imageInfo.GetAppThumbnailLen();
if (!data.WriteInt32(appIconLen)) {
DMLOG(DM_LOG_ERROR, "write imageinfo appicon len failed");
return DEVICEMANAGER_FLATTEN_OBJECT;
if (!data.WriteInt32(authType)) {
LOGE("write pkgName failed");
return DM_IPC_FLATTEN_OBJECT;
}
if (!data.WriteInt32(appThumbnailLen)) {
DMLOG(DM_LOG_ERROR, "write imageinfo appThumbnailLen failed");
return DEVICEMANAGER_FLATTEN_OBJECT;
}
if (appIconLen > 0 && !data.WriteRawData(imageInfo.GetAppIcon(), appIconLen)) {
DMLOG(DM_LOG_ERROR, "write imageinfo appIcon failed");
return DEVICEMANAGER_FLATTEN_OBJECT;
}
if (appThumbnailLen > 0 && !data.WriteRawData(imageInfo.GetAppThumbnail(), appThumbnailLen)) {
DMLOG(DM_LOG_ERROR, "write imageinfo appThumbnail failed");
return DEVICEMANAGER_FLATTEN_OBJECT;
}
return DEVICEMANAGER_OK;
return DM_OK;
}
ON_IPC_READ_RESPONSE(AUTHENTICATE_DEVICE, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
{
pBaseRsp->SetErrCode(reply.ReadInt32());
return DEVICEMANAGER_OK;
return DM_OK;
}
ON_IPC_SET_REQUEST(CHECK_AUTHENTICATION, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
ON_IPC_SET_REQUEST(UNAUTHENTICATE_DEVICE, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
{
std::shared_ptr<IpcCheckAuthenticateReq> pReq = std::static_pointer_cast<IpcCheckAuthenticateReq>(pBaseReq);
std::string authPara = pReq->GetAuthPara();
if (!data.WriteString(authPara)) {
return DEVICEMANAGER_FLATTEN_OBJECT;
std::shared_ptr<IpcUnAuthenticateDeviceReq> pReq = std::static_pointer_cast<IpcUnAuthenticateDeviceReq>(pBaseReq);
std::string pkgName = pReq->GetPkgName();
DmDeviceInfo deviceInfo = pReq->GetDeviceInfo();
std::string deviceId = deviceInfo.deviceId;
if (!data.WriteString(pkgName)) {
LOGE("write pkgName failed");
return DM_IPC_FLATTEN_OBJECT;
}
return DEVICEMANAGER_OK;
if (!data.WriteString(deviceId)) {
LOGE("write extra failed");
return DM_IPC_FLATTEN_OBJECT;
}
return DM_OK;
}
ON_IPC_READ_RESPONSE(CHECK_AUTHENTICATION, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
ON_IPC_READ_RESPONSE(UNAUTHENTICATE_DEVICE, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
{
pBaseRsp->SetErrCode(reply.ReadInt32());
return DEVICEMANAGER_OK;
return DM_OK;
}
ON_IPC_SET_REQUEST(VERIFY_AUTHENTICATION, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
{
std::shared_ptr<IpcVerifyAuthenticateReq> pReq = std::static_pointer_cast<IpcVerifyAuthenticateReq>(pBaseReq);
std::string authPara = pReq->GetAuthPara();
if (!data.WriteString(authPara)) {
return DM_IPC_FLATTEN_OBJECT;
}
return DM_OK;
}
ON_IPC_READ_RESPONSE(VERIFY_AUTHENTICATION, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
{
pBaseRsp->SetErrCode(reply.ReadInt32());
return DM_OK;
}
ON_IPC_SET_REQUEST(SERVER_GET_DMFA_INFO, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
{
std::shared_ptr<IpcReq> pReq = std::static_pointer_cast<IpcReq>(pBaseReq);
std::string packagename = pReq->GetPkgName();
if (!data.WriteString(packagename)) {
LOGE("write pkgName failed");
return DM_IPC_FLATTEN_OBJECT;
}
return DM_OK;
}
ON_IPC_READ_RESPONSE(SERVER_GET_DMFA_INFO, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
{
std::shared_ptr<IpcGetDmFaParamRsp> pRsp = std::static_pointer_cast<IpcGetDmFaParamRsp>(pBaseRsp);
DmAuthParam authParam;
authParam.direction = reply.ReadInt32();
authParam.authType = reply.ReadInt32();
authParam.authToken = reply.ReadString();
authParam.packageName = reply.ReadString();
authParam.appName = reply.ReadString();
authParam.appDescription = reply.ReadString();
authParam.business = reply.ReadInt32();
authParam.pincode = reply.ReadInt32();
pRsp->SetDmAuthParam(authParam);
return DM_OK;
}
ON_IPC_SET_REQUEST(SERVER_USER_AUTH_OPERATION, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
{
std::shared_ptr<IpcGetOperationReq> pReq = std::static_pointer_cast<IpcGetOperationReq>(pBaseReq);
std::string pkgName = pReq->GetPkgName();
int32_t action = pReq->GetOperation();
if (!data.WriteString(pkgName)) {
LOGE("write pkgName failed");
return DM_IPC_TRANSACTION_FAILED;
}
if (!data.WriteInt32(action)) {
LOGE("write action failed");
return DM_WRITE_FAILED;
}
return DM_OK;
}
ON_IPC_READ_RESPONSE(SERVER_USER_AUTH_OPERATION, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
{
pBaseRsp->SetErrCode(reply.ReadInt32());
return DM_OK;
}
ON_IPC_CMD(SERVER_DEVICE_STATE_NOTIFY, MessageParcel &data, MessageParcel &reply)
@@ -226,8 +358,8 @@ ON_IPC_CMD(SERVER_DEVICE_STATE_NOTIFY, MessageParcel &data, MessageParcel &reply
size_t deviceSize = sizeof(DmDeviceInfo);
void *deviceInfo = (void *)data.ReadRawData(deviceSize);
if (deviceInfo != nullptr && memcpy_s(&dmDeviceInfo, deviceSize, deviceInfo, deviceSize) != 0) {
reply.WriteInt32(DEVICEMANAGER_COPY_FAILED);
return DEVICEMANAGER_OK;
reply.WriteInt32(DM_IPC_COPY_FAILED);
return DM_OK;
}
switch (deviceState) {
case DEVICE_STATE_ONLINE:
@@ -239,12 +371,15 @@ ON_IPC_CMD(SERVER_DEVICE_STATE_NOTIFY, MessageParcel &data, MessageParcel &reply
case DEVICE_INFO_CHANGED:
DeviceManagerNotify::GetInstance().OnDeviceChanged(pkgName, dmDeviceInfo);
break;
case DEVICE_INFO_READY:
DeviceManagerNotify::GetInstance().OnDeviceReady(pkgName, dmDeviceInfo);
break;
default:
DMLOG(DM_LOG_ERROR, "unknown device state:%d", deviceState);
LOGE("unknown device state:%d", deviceState);
break;
}
reply.WriteInt32(DEVICEMANAGER_OK);
return DEVICEMANAGER_OK;
reply.WriteInt32(DM_OK);
return DM_OK;
}
ON_IPC_CMD(SERVER_DEVICE_FOUND, MessageParcel &data, MessageParcel &reply)
@@ -255,12 +390,12 @@ ON_IPC_CMD(SERVER_DEVICE_FOUND, MessageParcel &data, MessageParcel &reply)
size_t deviceSize = sizeof(DmDeviceInfo);
void *deviceInfo = (void *)data.ReadRawData(deviceSize);
if (deviceInfo != nullptr && memcpy_s(&dmDeviceInfo, deviceSize, deviceInfo, deviceSize) != 0) {
reply.WriteInt32(DEVICEMANAGER_COPY_FAILED);
return DEVICEMANAGER_OK;
reply.WriteInt32(DM_IPC_COPY_FAILED);
return DM_IPC_COPY_FAILED;
}
DeviceManagerNotify::GetInstance().OnDeviceFound(pkgName, subscribeId, dmDeviceInfo);
reply.WriteInt32(DEVICEMANAGER_OK);
return DEVICEMANAGER_OK;
reply.WriteInt32(DM_OK);
return DM_OK;
}
ON_IPC_CMD(SERVER_DISCOVER_FINISH, MessageParcel &data, MessageParcel &reply)
@@ -269,122 +404,48 @@ ON_IPC_CMD(SERVER_DISCOVER_FINISH, MessageParcel &data, MessageParcel &reply)
uint16_t subscribeId = data.ReadInt16();
int32_t failedReason = data.ReadInt32();
if (failedReason == DEVICEMANAGER_OK) {
if (failedReason == DM_OK) {
DeviceManagerNotify::GetInstance().OnDiscoverySuccess(pkgName, subscribeId);
} else {
DeviceManagerNotify::GetInstance().OnDiscoverFailed(pkgName, subscribeId, failedReason);
DeviceManagerNotify::GetInstance().OnDiscoveryFailed(pkgName, subscribeId, failedReason);
}
reply.WriteInt32(DEVICEMANAGER_OK);
return DEVICEMANAGER_OK;
reply.WriteInt32(DM_OK);
return DM_OK;
}
ON_IPC_CMD(SERVER_AUTH_RESULT, MessageParcel &data, MessageParcel &reply)
{
std::string pkgName = data.ReadString();
std::string deviceId = data.ReadString();
int32_t pinToken = data.ReadInt32();
std::string token = data.ReadString();
int32_t status = data.ReadInt32();
int32_t reason = data.ReadInt32();
DeviceManagerNotify::GetInstance().OnAuthResult(pkgName, deviceId, pinToken, status, reason);
reply.WriteInt32(DEVICEMANAGER_OK);
return DEVICEMANAGER_OK;
DeviceManagerNotify::GetInstance().OnAuthResult(pkgName, deviceId, token, status, reason);
reply.WriteInt32(DM_OK);
return DM_OK;
}
ON_IPC_CMD(SERVER_CHECK_AUTH_RESULT, MessageParcel &data, MessageParcel &reply)
ON_IPC_CMD(SERVER_VERIFY_AUTH_RESULT, MessageParcel &data, MessageParcel &reply)
{
std::string pkgName = data.ReadString();
std::string deviceId = data.ReadString();
int32_t resultCode = data.ReadInt32();
int32_t flag = data.ReadInt32();
DeviceManagerNotify::GetInstance().OnCheckAuthResult(pkgName, deviceId, resultCode, flag);
reply.WriteInt32(DEVICEMANAGER_OK);
return DEVICEMANAGER_OK;
DeviceManagerNotify::GetInstance().OnVerifyAuthResult(pkgName, deviceId, resultCode, flag);
reply.WriteInt32(DM_OK);
return DM_OK;
}
ON_IPC_SET_REQUEST(SERVER_GET_AUTHENTCATION_INFO, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
ON_IPC_CMD(SERVER_DEVICE_FA_NOTIFY, MessageParcel &data, MessageParcel &reply)
{
std::shared_ptr<IpcReq> pReq = std::static_pointer_cast<IpcReq>(pBaseReq);
std::string packagename = pReq->GetPkgName();
if (!data.WriteString(packagename)) {
DMLOG(DM_LOG_ERROR, "write pkgName failed");
return DEVICEMANAGER_FLATTEN_OBJECT;
}
return DEVICEMANAGER_OK;
}
ON_IPC_READ_RESPONSE(SERVER_GET_AUTHENTCATION_INFO, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
{
std::shared_ptr<IpcGetAuthParamRsp> pRsp = std::static_pointer_cast<IpcGetAuthParamRsp>(pBaseRsp);
DmAuthParam authParam;
authParam.direction = reply.ReadInt32();
authParam.authType = reply.ReadInt32();
if (authParam.direction == AUTH_SESSION_SIDE_CLIENT) {
authParam.pinToken = reply.ReadInt32();
pRsp->SetAuthParam(authParam);
return DEVICEMANAGER_OK;
}
authParam.packageName = reply.ReadString();
authParam.appName = reply.ReadString();
authParam.appDescription = reply.ReadString();
authParam.business = reply.ReadInt32();
authParam.pincode = reply.ReadInt32();
int32_t appIconLen = reply.ReadInt32();
uint8_t *appIconBuffer = nullptr;
int32_t appThumbnailLen = reply.ReadInt32();
uint8_t *appThumbBuffer = nullptr;
if (appIconLen > 0) {
appIconBuffer = (uint8_t *)reply.ReadRawData(appIconLen);
}
if (appThumbnailLen > 0) {
appThumbBuffer = (uint8_t *)reply.ReadRawData(appThumbnailLen);
}
authParam.imageinfo.Reset(appIconBuffer, appIconLen, appThumbBuffer, appThumbnailLen);
pRsp->SetAuthParam(authParam);
return DEVICEMANAGER_OK;
}
ON_IPC_SET_REQUEST(SERVER_USER_AUTHORIZATION_OPERATION, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
{
std::shared_ptr<IpcGetOperationReq> pReq = std::static_pointer_cast<IpcGetOperationReq>(pBaseReq);
std::string pkgName = pReq->GetPkgName();
int32_t action = pReq->GetOperation();
if (!data.WriteString(pkgName)) {
DMLOG(DM_LOG_ERROR, "write pkgName failed");
return DEVICEMANAGER_FLATTEN_OBJECT;
}
if (!data.WriteInt32(action)) {
DMLOG(DM_LOG_ERROR, "write extra failed");
return DEVICEMANAGER_FLATTEN_OBJECT;
}
return DEVICEMANAGER_OK;
}
ON_IPC_READ_RESPONSE(SERVER_USER_AUTHORIZATION_OPERATION, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
{
pBaseRsp->SetErrCode(reply.ReadInt32());
return DEVICEMANAGER_OK;
}
ON_IPC_CMD(SERVER_DEVICEMANAGER_FA_NOTIFY, MessageParcel &data, MessageParcel &reply)
{
DMLOG(DM_LOG_INFO, "OnFaCallBack");
std::string packagename = data.ReadString();
std::string paramJson = data.ReadString();
DMLOG(DM_LOG_INFO, "OnFaCallBack Packagename is %s", packagename.c_str());
DMLOG(DM_LOG_INFO, "OnFaCallBack Json is %s", paramJson.c_str());
DeviceManagerNotify::GetInstance().OnFaCall(packagename, paramJson);
if (!reply.WriteInt32(DEVICEMANAGER_OK)) {
DMLOG(DM_LOG_ERROR, "write return failed");
return DEVICEMANAGER_FLATTEN_OBJECT;
if (!reply.WriteInt32(DM_OK)) {
LOGE("write return failed");
return DM_WRITE_FAILED;
}
return DEVICEMANAGER_OK;
return DM_OK;
}
} // namespace DistributedHardware
} // namespace OHOS
@@ -4,7 +4,7 @@
* 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
* 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,
@@ -15,65 +15,64 @@
#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"
#include "dm_constants.h"
#include "dm_log.h"
#include "nlohmann/json.hpp"
namespace OHOS {
namespace DistributedHardware {
IMPLEMENT_SINGLE_INSTANCE(DeviceManagerNotify);
void DeviceManagerNotify::RegisterDeathRecipientCallback(std::string &pkgName,
std::shared_ptr<DmInitCallback> dmInitCallback)
void DeviceManagerNotify::RegisterDeathRecipientCallback(const std::string &pkgName,
std::shared_ptr<DmInitCallback> dmInitCallback)
{
std::lock_guard<std::mutex> autoLock(lock_);
dmInitCallback_[pkgName] = dmInitCallback;
}
void DeviceManagerNotify::UnRegisterDeathRecipientCallback(std::string &pkgName)
void DeviceManagerNotify::UnRegisterDeathRecipientCallback(const std::string &pkgName)
{
std::lock_guard<std::mutex> autoLock(lock_);
dmInitCallback_.erase(pkgName);
}
void DeviceManagerNotify::RegisterDeviceStateCallback(std::string &pkgName,
std::shared_ptr<DeviceStateCallback> callback)
void DeviceManagerNotify::RegisterDeviceStateCallback(const std::string &pkgName,
std::shared_ptr<DeviceStateCallback> callback)
{
std::lock_guard<std::mutex> autoLock(lock_);
deviceStateCallback_[pkgName] = callback;
}
void DeviceManagerNotify::UnRegisterDeviceStateCallback(std::string &pkgName)
void DeviceManagerNotify::UnRegisterDeviceStateCallback(const std::string &pkgName)
{
std::lock_guard<std::mutex> autoLock(lock_);
deviceStateCallback_.erase(pkgName);
}
void DeviceManagerNotify::RegisterDiscoverCallback(std::string &pkgName, uint16_t subscribeId,
std::shared_ptr<DiscoverCallback> callback)
void DeviceManagerNotify::RegisterDiscoveryCallback(const std::string &pkgName, uint16_t subscribeId,
std::shared_ptr<DiscoveryCallback> callback)
{
std::lock_guard<std::mutex> autoLock(lock_);
if (deviceDiscoverCallbacks_.count(pkgName) == 0) {
deviceDiscoverCallbacks_[pkgName] = std::map<uint16_t, std::shared_ptr<DiscoverCallback>>();
if (deviceDiscoveryCallbacks_.count(pkgName) == 0) {
deviceDiscoveryCallbacks_[pkgName] = std::map<uint16_t, std::shared_ptr<DiscoveryCallback>>();
}
deviceDiscoverCallbacks_[pkgName][subscribeId] = callback;
deviceDiscoveryCallbacks_[pkgName][subscribeId] = callback;
}
void DeviceManagerNotify::UnRegisterDiscoverCallback(std::string &pkgName, uint16_t subscribeId)
void DeviceManagerNotify::UnRegisterDiscoveryCallback(const std::string &pkgName, uint16_t subscribeId)
{
std::lock_guard<std::mutex> autoLock(lock_);
if (deviceDiscoverCallbacks_.count(pkgName) > 0) {
deviceDiscoverCallbacks_[pkgName].erase(subscribeId);
if (deviceDiscoverCallbacks_[pkgName].empty()) {
deviceDiscoverCallbacks_.erase(pkgName);
if (deviceDiscoveryCallbacks_.count(pkgName) > 0) {
deviceDiscoveryCallbacks_[pkgName].erase(subscribeId);
if (deviceDiscoveryCallbacks_[pkgName].empty()) {
deviceDiscoveryCallbacks_.erase(pkgName);
}
}
}
void DeviceManagerNotify::RegisterAuthenticateCallback(std::string &pkgName, std::string &deviceId,
std::shared_ptr<AuthenticateCallback> callback)
void DeviceManagerNotify::RegisterAuthenticateCallback(const std::string &pkgName, const std::string &deviceId,
std::shared_ptr<AuthenticateCallback> callback)
{
std::lock_guard<std::mutex> autoLock(lock_);
if (authenticateCallback_.count(pkgName) == 0) {
@@ -82,7 +81,7 @@ void DeviceManagerNotify::RegisterAuthenticateCallback(std::string &pkgName, std
authenticateCallback_[pkgName][deviceId] = callback;
}
void DeviceManagerNotify::UnRegisterAuthenticateCallback(std::string &pkgName, std::string &deviceId)
void DeviceManagerNotify::UnRegisterAuthenticateCallback(const std::string &pkgName, const std::string &deviceId)
{
std::lock_guard<std::mutex> autoLock(lock_);
if (authenticateCallback_.count(pkgName) > 0) {
@@ -93,185 +92,192 @@ void DeviceManagerNotify::UnRegisterAuthenticateCallback(std::string &pkgName, s
}
}
void DeviceManagerNotify::UnRegisterPackageCallback(std::string &pkgName)
void DeviceManagerNotify::UnRegisterPackageCallback(const std::string &pkgName)
{
std::lock_guard<std::mutex> autoLock(lock_);
deviceStateCallback_.erase(pkgName);
deviceDiscoverCallbacks_.erase(pkgName);
deviceDiscoveryCallbacks_.erase(pkgName);
authenticateCallback_.erase(pkgName);
dmInitCallback_.erase(pkgName);
}
void DeviceManagerNotify::RegisterCheckAuthenticationCallback(std::string &pkgName, std::string &authPara,
std::shared_ptr<CheckAuthCallback> callback)
void DeviceManagerNotify::RegisterVerifyAuthenticationCallback(const std::string &pkgName, const std::string &authPara,
std::shared_ptr<VerifyAuthCallback> callback)
{
std::lock_guard<std::mutex> autoLock(lock_);
checkauthcallback_[pkgName] = callback;
verifyAuthCallback_[pkgName] = callback;
}
void DeviceManagerNotify::UnRegisterCheckAuthenticationCallback(std::string &pkgName)
void DeviceManagerNotify::UnRegisterVerifyAuthenticationCallback(const std::string &pkgName)
{
std::lock_guard<std::mutex> autoLock(lock_);
checkauthcallback_.erase(pkgName);
verifyAuthCallback_.erase(pkgName);
}
void DeviceManagerNotify::RegisterDeviceManagerFaCallback(std::string &packageName,
std::shared_ptr<DeviceManagerFaCallback> callback)
void DeviceManagerNotify::RegisterDeviceManagerFaCallback(const std::string &pkgName,
std::shared_ptr<DeviceManagerFaCallback> callback)
{
std::lock_guard<std::mutex> autoLock(lock_);
dmFaCallback_[packageName] = callback;
dmFaCallback_[pkgName] = callback;
}
void DeviceManagerNotify::UnRegisterDeviceManagerFaCallback(std::string &pkgName)
void DeviceManagerNotify::UnRegisterDeviceManagerFaCallback(const std::string &pkgName)
{
std::lock_guard<std::mutex> autoLock(lock_);
if (dmFaCallback_.count(pkgName) == 0) {
LOGE("DeviceManager UnRegisterDeviceManagerFaCallback not register");
return;
}
dmFaCallback_.erase(pkgName);
}
void DeviceManagerNotify::OnRemoteDied()
{
DMLOG(DM_LOG_WARN, "DeviceManager : OnRemoteDied");
LOGW("DeviceManager : OnRemoteDied");
for (auto iter : dmInitCallback_) {
iter.second->OnRemoteDied();
}
}
void DeviceManagerNotify::OnDeviceOnline(std::string &pkgName, const DmDeviceInfo &deviceInfo)
void DeviceManagerNotify::OnDeviceOnline(const std::string &pkgName, const DmDeviceInfo &deviceInfo)
{
DMLOG(DM_LOG_INFO, "DeviceManager OnDeviceOnline pkgName:%s", pkgName.c_str());
LOGI("DeviceManager OnDeviceOnline pkgName:%s", pkgName.c_str());
std::lock_guard<std::mutex> autoLock(lock_);
if (deviceStateCallback_.count(pkgName) == 0) {
DMLOG(DM_LOG_ERROR, "DeviceManager OnDeviceOnlinecallback not register");
LOGE("DeviceManager OnDeviceOnlinecallback not register");
return;
}
deviceStateCallback_[pkgName]->OnDeviceOnline(deviceInfo);
}
void DeviceManagerNotify::OnDeviceOffline(std::string &pkgName, const DmDeviceInfo &deviceInfo)
void DeviceManagerNotify::OnDeviceOffline(const std::string &pkgName, const DmDeviceInfo &deviceInfo)
{
DMLOG(DM_LOG_INFO, "DeviceManager OnDeviceOffline pkgName:%s", pkgName.c_str());
LOGI("DeviceManager OnDeviceOffline pkgName:%s", pkgName.c_str());
std::lock_guard<std::mutex> autoLock(lock_);
if (deviceStateCallback_.count(pkgName) == 0) {
DMLOG(DM_LOG_ERROR, "DeviceManager OnDeviceOfflinecallback not register");
LOGE("DeviceManager OnDeviceOfflinecallback not register");
return;
}
deviceStateCallback_[pkgName]->OnDeviceOffline(deviceInfo);
}
void DeviceManagerNotify::OnDeviceChanged(std::string &pkgName, const DmDeviceInfo &deviceInfo)
void DeviceManagerNotify::OnDeviceChanged(const std::string &pkgName, const DmDeviceInfo &deviceInfo)
{
DMLOG(DM_LOG_INFO, "DeviceManager OnDeviceChanged pkgName:%s", pkgName.c_str());
LOGI("DeviceManager OnDeviceChanged pkgName:%s", pkgName.c_str());
std::lock_guard<std::mutex> autoLock(lock_);
if (deviceStateCallback_.count(pkgName) == 0) {
DMLOG(DM_LOG_ERROR, "DeviceManager OnDeviceChangedcallback not register");
LOGE("DeviceManager OnDeviceChangedcallback not register");
return;
}
deviceStateCallback_[pkgName]->OnDeviceChanged(deviceInfo);
}
void DeviceManagerNotify::OnDeviceFound(std::string &pkgName, uint16_t subscribeId,
const DmDeviceInfo &deviceInfo)
void DeviceManagerNotify::OnDeviceReady(const std::string &pkgName, const DmDeviceInfo &deviceInfo)
{
DMLOG(DM_LOG_INFO, "DeviceManager OnDeviceFound pkgName:%s, subscribeId:%d.", pkgName.c_str(),
(int32_t)subscribeId);
LOGI("DeviceManager OnDeviceReady pkgName:%s", pkgName.c_str());
std::lock_guard<std::mutex> autoLock(lock_);
if (deviceDiscoverCallbacks_.count(pkgName) == 0) {
DMLOG(DM_LOG_ERROR, "DeviceManager OnDeviceFound: no register discoverCallback for this package");
if (deviceStateCallback_.count(pkgName) == 0) {
LOGE("DeviceManager OnDeviceReadycallback not register");
return;
}
std::map<uint16_t, std::shared_ptr<DiscoverCallback>> &discoverCallMap = deviceDiscoverCallbacks_[pkgName];
deviceStateCallback_[pkgName]->OnDeviceReady(deviceInfo);
}
void DeviceManagerNotify::OnDeviceFound(const std::string &pkgName, uint16_t subscribeId,
const DmDeviceInfo &deviceInfo)
{
LOGI("DeviceManager OnDeviceFound pkgName:%s, subscribeId:%d.", pkgName.c_str(), (int32_t)subscribeId);
std::lock_guard<std::mutex> autoLock(lock_);
if (deviceDiscoveryCallbacks_.count(pkgName) == 0) {
LOGE("DeviceManager OnDeviceFound: no register DiscoveryCallback for this package");
return;
}
std::map<uint16_t, std::shared_ptr<DiscoveryCallback>> &discoverCallMap = deviceDiscoveryCallbacks_[pkgName];
auto iter = discoverCallMap.find(subscribeId);
if (iter == discoverCallMap.end()) {
DMLOG(DM_LOG_ERROR, "DeviceManager OnDeviceFound: no register discoverCallback for subscribeId %d",
subscribeId);
LOGE("DeviceManager OnDeviceFound: no register DiscoveryCallback for subscribeId %d", subscribeId);
return;
}
iter->second->OnDeviceFound(subscribeId, deviceInfo);
}
void DeviceManagerNotify::OnDiscoverFailed(std::string &pkgName, uint16_t subscribeId, int32_t failedReason)
void DeviceManagerNotify::OnDiscoveryFailed(const 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);
LOGI("DeviceManager OnDiscoveryFailed pkgName:%s, subscribeId %d, reason %d", pkgName.c_str(), subscribeId,
failedReason);
std::lock_guard<std::mutex> autoLock(lock_);
if (deviceDiscoverCallbacks_.count(pkgName) == 0) {
DMLOG(DM_LOG_ERROR, "DeviceManager OnDiscoverFailed: no register discoverCallback for this package");
if (deviceDiscoveryCallbacks_.count(pkgName) == 0) {
LOGE("DeviceManager OnDiscoveryFailed: no register DiscoveryCallback for this package");
return;
}
std::map<uint16_t, std::shared_ptr<DiscoverCallback>> &discoverCallMap = deviceDiscoverCallbacks_[pkgName];
std::map<uint16_t, std::shared_ptr<DiscoveryCallback>> &discoverCallMap = deviceDiscoveryCallbacks_[pkgName];
auto iter = discoverCallMap.find(subscribeId);
if (iter == discoverCallMap.end()) {
DMLOG(DM_LOG_ERROR, "DeviceManager OnDiscoverFailed: no register discoverCallback for subscribeId %d",
subscribeId);
LOGE("DeviceManager OnDiscoveryFailed: no register DiscoveryCallback for subscribeId %d", subscribeId);
return;
}
iter->second->OnDiscoverFailed(subscribeId, failedReason);
iter->second->OnDiscoveryFailed(subscribeId, failedReason);
}
void DeviceManagerNotify::OnDiscoverySuccess(std::string &pkgName, uint16_t subscribeId)
void DeviceManagerNotify::OnDiscoverySuccess(const std::string &pkgName, uint16_t subscribeId)
{
DMLOG(DM_LOG_INFO, "DeviceManager OnDiscoverySuccess pkgName:%s, subscribeId:%d.", pkgName.c_str(),
subscribeId);
LOGI("DeviceManager OnDiscoverySuccess pkgName:%s, subscribeId:%d.", pkgName.c_str(), subscribeId);
std::lock_guard<std::mutex> autoLock(lock_);
if (deviceDiscoverCallbacks_.count(pkgName) == 0) {
DMLOG(DM_LOG_ERROR, "DeviceManager OnDiscoverySuccess: no register discoverCallback for this package");
if (deviceDiscoveryCallbacks_.count(pkgName) == 0) {
LOGE("DeviceManager OnDiscoverySuccess: no register DiscoveryCallback for this package");
return;
}
std::map<uint16_t, std::shared_ptr<DiscoverCallback>> &discoverCallMap = deviceDiscoverCallbacks_[pkgName];
std::map<uint16_t, std::shared_ptr<DiscoveryCallback>> &discoverCallMap = deviceDiscoveryCallbacks_[pkgName];
auto iter = discoverCallMap.find(subscribeId);
if (iter == discoverCallMap.end()) {
DMLOG(DM_LOG_ERROR, "DeviceManager OnDiscoverySuccess: no register discoverCallback for subscribeId %d",
subscribeId);
LOGE("DeviceManager OnDiscoverySuccess: no register DiscoveryCallback 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)
void DeviceManagerNotify::OnAuthResult(const std::string &pkgName, const std::string &deviceId,
const std::string &token, uint32_t status, uint32_t reason)
{
DMLOG(DM_LOG_INFO, "DeviceManagerNotify::OnAuthResult pkgName:%s, status:%d, reason:%d",
pkgName.c_str(), status, reason);
LOGI("DeviceManagerNotify::OnAuthResult pkgName:%s, status:%d, reason:%d", pkgName.c_str(), status, reason);
std::lock_guard<std::mutex> autoLock(lock_);
if (authenticateCallback_.count(pkgName) == 0) {
DMLOG(DM_LOG_ERROR, "DeviceManager OnAuthResult: no register authCallback for this package");
LOGE("DeviceManager OnAuthResult: no register authCallback for this package");
return;
}
std::map<std::string, std::shared_ptr<AuthenticateCallback>> &authCallMap = authenticateCallback_[pkgName];
auto iter = authCallMap.find(deviceId);
if (iter == authCallMap.end()) {
DMLOG(DM_LOG_ERROR, "DeviceManager OnAuthResult: no register authCallback for deviceID ");
LOGE("DeviceManager OnAuthResult: no register authCallback for deviceID ");
return;
}
iter->second->OnAuthResult(deviceId, pinToken, status, reason);
iter->second->OnAuthResult(deviceId, token, 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)
void DeviceManagerNotify::OnVerifyAuthResult(const std::string &pkgName, const 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);
LOGI("DeviceManagerNotify::OnCheckAuthResult pkgName:%s, resultCode:%d, flag:%d", pkgName.c_str(), resultCode,
flag);
std::lock_guard<std::mutex> autoLock(lock_);
if (checkauthcallback_.count(pkgName) == 0) {
DMLOG(DM_LOG_ERROR, "DeviceManager OnCheckAuthResult: no register authCallback for this package");
if (verifyAuthCallback_.count(pkgName) == 0) {
LOGE("DeviceManager OnCheckAuthResult: no register authCallback for this package");
return;
}
checkauthcallback_[pkgName]->OnCheckAuthResult(deviceId, resultCode, flag);
checkauthcallback_.erase(pkgName);
verifyAuthCallback_[pkgName]->OnVerifyAuthResult(deviceId, resultCode, flag);
verifyAuthCallback_.erase(pkgName);
}
void DeviceManagerNotify::OnFaCall(std::string &pkgName, std::string &paramJson)
{
DMLOG(DM_LOG_INFO, "DeviceManager OnFaCallback pkgName:%s", pkgName.c_str());
LOGI("DeviceManager OnFaCallback pkgName:%s", pkgName.c_str());
std::lock_guard<std::mutex> autoLock(lock_);
if (dmFaCallback_.count(pkgName) == 0) {
DMLOG(DM_LOG_ERROR, "DeviceManager DmFaCallback not register");
LOGE("DeviceManager DmFaCallback not register");
return;
}
dmFaCallback_[pkgName]->OnCall(paramJson);
+8 -7
View File
@@ -16,17 +16,18 @@ import("//foundation/distributedhardware/devicemanager/devicemanager.gni")
ohos_shared_library("devicemanager") {
include_dirs = [
"include",
"${common_path}/include",
"${common_path}/include/ipc",
"${utils_path}/include",
"${innerkits_path}/native_cpp/include",
"${innerkits_path}/native_cpp/include/ipc",
"${innerkits_path}/native_cpp/include/ipc/standard",
"//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 = [
@@ -63,4 +64,4 @@ ohos_shared_library("devicemanager") {
group("devicemanager_native_js") {
deps = [ ":devicemanager" ]
}
}
+5 -4
View File
@@ -4,7 +4,7 @@
* 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
* 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,
@@ -13,12 +13,13 @@
* limitations under the License.
*/
#ifndef OHOS_DEVICE_MANAGER_NATIVE_EVENT_H
#define OHOS_DEVICE_MANAGER_NATIVE_EVENT_H
#ifndef OHOS_DM_NATIVE_EVENT_H
#define OHOS_DM_NATIVE_EVENT_H
#include <map>
#include <memory>
#include <string>
#include "napi/native_api.h"
struct DmEventListener {
@@ -41,4 +42,4 @@ protected:
std::map<std::string, std::shared_ptr<DmEventListener>> eventMap_;
};
#endif /* OHOS_DEVICE_MANAGER_NATIVE_EVENT_H */
#endif /* OHOS_DM_NATIVE_EVENT_H */
@@ -4,7 +4,7 @@
* 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
* 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,
@@ -13,20 +13,20 @@
* limitations under the License.
*/
#ifndef OHOS_DEVICE_MANAGER_NATIVE_DEVICEMANAGER_JS_H
#define OHOS_DEVICE_MANAGER_NATIVE_DEVICEMANAGER_JS_H
#ifndef OHOS_DM_NATIVE_DEVICEMANAGER_JS_H
#define OHOS_DM_NATIVE_DEVICEMANAGER_JS_H
#include <memory>
#include <string>
#include "device_manager_callback.h"
#include "dm_app_image_info.h"
#include "dm_device_info.h"
#include "dm_native_event.h"
#include "dm_subscribe_info.h"
#include "napi/native_api.h"
#include "napi/native_node_api.h"
#include "device_manager_callback.h"
#include "dm_native_event.h"
#include "dm_device_info.h"
#include "dm_subscribe_info.h"
#include "nlohmann/json.hpp"
#include "dm_device_info.h"
#define DM_NAPI_BUF_LENGTH (256)
struct AsyncCallbackInfo {
@@ -40,6 +40,22 @@ struct AsyncCallbackInfo {
int32_t status = -1;
};
struct DeviceInfoAsyncCallbackInfo {
napi_env env = nullptr;
napi_async_work asyncWork = nullptr;
std::string bundleName;
size_t bundleNameLen = 0;
OHOS::DistributedHardware::DmDeviceInfo deviceInfo;
std::vector<OHOS::DistributedHardware::DmDeviceInfo> devList;
std::string extra;
// OHOS::DistributedHardware::DmFilterOptions filter;
napi_ref callback = nullptr;
napi_value thisVar = nullptr;
napi_deferred deferred = nullptr;
int32_t status = -1;
int32_t isList = 0;
};
struct AuthAsyncCallbackInfo {
napi_env env = nullptr;
@@ -50,17 +66,16 @@ struct AuthAsyncCallbackInfo {
int32_t authType = -1;
};
enum DmNapiDevStateChangeAction {
ONLINE = 0,
READY = 1,
OFFLINE = 2,
CHANGE = 3
};
enum DmNapiDevStateChangeAction { ONLINE = 0, READY = 1, OFFLINE = 2, CHANGE = 3 };
class DmNapiInitCallback : public OHOS::DistributedHardware::DmInitCallback {
public:
explicit DmNapiInitCallback(std::string &bundleName) : bundleName_(bundleName) {}
virtual ~DmNapiInitCallback() {}
explicit DmNapiInitCallback(std::string &bundleName) : bundleName_(bundleName)
{
}
virtual ~DmNapiInitCallback()
{
}
void OnRemoteDied() override;
private:
@@ -69,8 +84,10 @@ private:
class DmNapiDeviceStateCallback : public OHOS::DistributedHardware::DeviceStateCallback {
public:
explicit DmNapiDeviceStateCallback(std::string &bundleName) : bundleName_(bundleName) {}
virtual ~DmNapiDeviceStateCallback() {};
explicit DmNapiDeviceStateCallback(std::string &bundleName) : bundleName_(bundleName)
{
}
virtual ~DmNapiDeviceStateCallback(){};
void OnDeviceOnline(const OHOS::DistributedHardware::DmDeviceInfo &deviceInfo) override;
void OnDeviceReady(const OHOS::DistributedHardware::DmDeviceInfo &deviceInfo) override;
void OnDeviceOffline(const OHOS::DistributedHardware::DmDeviceInfo &deviceInfo) override;
@@ -80,12 +97,14 @@ private:
std::string bundleName_;
};
class DmNapiDiscoverCallback : public OHOS::DistributedHardware::DiscoverCallback {
class DmNapiDiscoveryCallback : public OHOS::DistributedHardware::DiscoveryCallback {
public:
explicit DmNapiDiscoverCallback(std::string &bundleName) : refCount_(0), bundleName_(bundleName) {}
virtual ~DmNapiDiscoverCallback() {};
explicit DmNapiDiscoveryCallback(std::string &bundleName) : refCount_(0), bundleName_(bundleName)
{
}
virtual ~DmNapiDiscoveryCallback(){};
void OnDeviceFound(uint16_t subscribeId, const OHOS::DistributedHardware::DmDeviceInfo &deviceInfo) override;
void OnDiscoverFailed(uint16_t subscribeId, int32_t failedReason) override;
void OnDiscoveryFailed(uint16_t subscribeId, int32_t failedReason) override;
void OnDiscoverySuccess(uint16_t subscribeId) override;
void IncreaseRefCount();
void DecreaseRefCount();
@@ -96,31 +115,37 @@ private:
std::string bundleName_;
};
class DmNapiAuthenticateCallback : public OHOS::DistributedHardware::AuthenticateCallback {
public:
explicit DmNapiAuthenticateCallback(std::string &bundleName) : bundleName_(bundleName) {}
virtual ~DmNapiAuthenticateCallback() {};
void OnAuthResult(std::string &deviceId, int32_t pinToken, int32_t status, int32_t reason) override;
private:
std::string bundleName_;
};
class DmNapiCheckAuthCallback : public OHOS::DistributedHardware::CheckAuthCallback {
public:
explicit DmNapiCheckAuthCallback(std::string &bundleName) : bundleName_(bundleName) {}
virtual ~DmNapiCheckAuthCallback() {};
void OnCheckAuthResult(std::string &deviceId, int32_t resultCode, int32_t flag) override;
private:
std::string bundleName_;
};
class DmNapiDeviceManagerFaCallback : public OHOS::DistributedHardware::DeviceManagerFaCallback {
public:
explicit DmNapiDeviceManagerFaCallback(std::string &bundleName) : bundleName_(bundleName) {}
virtual ~DmNapiDeviceManagerFaCallback() {};
void OnCall(std::string &paramJson) override;
explicit DmNapiDeviceManagerFaCallback(std::string &bundleName) : bundleName_(bundleName)
{
}
virtual ~DmNapiDeviceManagerFaCallback(){};
void OnCall(const std::string &paramJson) override;
private:
std::string bundleName_;
};
class DmNapiAuthenticateCallback : public OHOS::DistributedHardware::AuthenticateCallback {
public:
explicit DmNapiAuthenticateCallback(std::string &bundleName) : bundleName_(bundleName)
{
}
virtual ~DmNapiAuthenticateCallback(){};
void OnAuthResult(const std::string &deviceId, const std::string &token, int32_t status, int32_t reason) override;
private:
std::string bundleName_;
};
class DmNapiVerifyAuthCallback : public OHOS::DistributedHardware::VerifyAuthCallback {
public:
explicit DmNapiVerifyAuthCallback(std::string &bundleName) : bundleName_(bundleName)
{
}
virtual ~DmNapiVerifyAuthCallback(){};
void OnVerifyAuthResult(const std::string &deviceId, int32_t resultCode, int32_t flag) override;
private:
std::string bundleName_;
@@ -134,58 +159,80 @@ public:
static napi_value Constructor(napi_env env, napi_callback_info info);
static napi_value CreateDeviceManager(napi_env env, napi_callback_info info);
static napi_value ReleaseDeviceManager(napi_env env, napi_callback_info info);
static napi_value SetUserOperationSync(napi_env env, napi_callback_info info);
static napi_value GetTrustedDeviceListSync(napi_env env, napi_callback_info info);
static napi_value GetTrustedDeviceList(napi_env env, napi_callback_info info);
static napi_value GetLocalDeviceInfoSync(napi_env env, napi_callback_info info);
static napi_value GetLocalDeviceInfo(napi_env env, napi_callback_info info);
static napi_value UnAuthenticateDevice(napi_env env, napi_callback_info info);
static napi_value StartDeviceDiscoverSync(napi_env env, napi_callback_info info);
static napi_value StopDeviceDiscoverSync(napi_env env, napi_callback_info info);
static napi_value AuthenticateDevice(napi_env env, napi_callback_info info);
static napi_value VerifyAuthInfo(napi_env env, napi_callback_info info);
static napi_value JsOn(napi_env env, napi_callback_info info);
static napi_value JsOff(napi_env env, napi_callback_info info);
static napi_value SetUserOperationSync(napi_env env, napi_callback_info info);
static napi_value GetAuthenticationParamSync(napi_env env, napi_callback_info info);
static void HandleCreateDmCallBack(const napi_env &env, AsyncCallbackInfo *asCallbackInfo);
static DeviceManagerNapi *GetDeviceManagerNapi(std::string &buldleName);
static void CreateDmCallback(std::string &bundleName, std::string &eventType);
static void ReleaseDmCallback(std::string &bundleName, std::string &eventType);
static void DeviceInfoToJsArray(const napi_env &env,
const std::vector<OHOS::DistributedHardware::DmDeviceInfo>& vecDevInfo,
const int32_t idx, napi_value &arrayResult);
static void DmAuthParamToJsAuthParam(const napi_env &env,
const OHOS::DistributedHardware::DmAuthParam &authParam, napi_value &paramResult);
const std::vector<OHOS::DistributedHardware::DmDeviceInfo> &vecDevInfo,
const int32_t idx, napi_value &arrayResult);
static void DmAuthParamToJsAuthParam(const napi_env &env, const OHOS::DistributedHardware::DmAuthParam &authParam,
napi_value &paramResult);
static void SetValueInt32(const napi_env &env, const std::string &fieldStr, const int32_t intValue,
napi_value &result);
napi_value &result);
static void SetValueUtf8String(const napi_env &env, const std::string &fieldStr, const std::string &str,
napi_value &result);
static void JsObjectToString(const napi_env &env, const napi_value &object,
const std::string &fieldStr, char *dest, const int32_t destLen);
static void JsObjectToBool(const napi_env &env, const napi_value &object,
const std::string &fieldStr, bool& fieldRef);
napi_value &result);
static void JsObjectToString(const napi_env &env, const napi_value &object, const std::string &fieldStr, char *dest,
const int32_t destLen);
static void JsObjectToBool(const napi_env &env, const napi_value &object, const std::string &fieldStr,
bool &fieldRef);
static void JsObjectToInt(const napi_env &env, const napi_value &object, const std::string &fieldStr,
int& fieldRef);
int &fieldRef);
static std::string JsObjectToString(const napi_env &env, const napi_value &object);
static int32_t JsToDmSubscribeInfo(const napi_env &env, const napi_value &object,
OHOS::DistributedHardware::DmSubscribeInfo& info);
OHOS::DistributedHardware::DmSubscribeInfo &info);
static void JsToDmDeviceInfo(const napi_env &env, const napi_value &object,
OHOS::DistributedHardware::DmDeviceInfo& info);
static void JsToDmAppImageInfoAndDmExtra(const napi_env &env, const napi_value &object,
OHOS::DistributedHardware::DmAppImageInfo& appImageInfo, std::string &extra, int32_t &authType);
OHOS::DistributedHardware::DmDeviceInfo &info);
static void JsToDmExtra(const napi_env &env, const napi_value &object, std::string &extra, int32_t &authType);
static void JsToDmAuthInfo(const napi_env &env, const napi_value &object, std::string &extra);
static void JsToDmBuffer(const napi_env &env, const napi_value &object, const std::string &fieldStr,
uint8_t **bufferPtr, int32_t &bufferLen);
uint8_t **bufferPtr, int32_t &bufferLen);
static void JsToJsonObject(const napi_env &env, const napi_value &object, const std::string &fieldStr,
nlohmann::json &jsonObj);
static void JsToDmTokenInfo(const napi_env &env, const napi_value &object,
const std::string &fieldStr, nlohmann::json &jsonObj);
nlohmann::json &jsonObj);
static void JsToDmTokenInfo(const napi_env &env, const napi_value &object, const std::string &fieldStr,
nlohmann::json &jsonObj);
static void JsToDmAuthExtra(const napi_env &env, const napi_value &param, nlohmann::json &jsonObj);
// static void JsToDmFilterOptions(const napi_env &env, const napi_value &object,
// OHOS::DistributedHardware::DmFilterOptions &filterOptions);
static void DmDeviceInfotoJsDeviceInfo(const napi_env &env,
const OHOS::DistributedHardware::DmDeviceInfo &vecDevInfo,
napi_value &result);
void OnDeviceStateChange(DmNapiDevStateChangeAction action,
const OHOS::DistributedHardware::DmDeviceInfo &deviceInfo);
const OHOS::DistributedHardware::DmDeviceInfo &deviceInfo);
void OnDeviceFound(uint16_t subscribeId, const OHOS::DistributedHardware::DmDeviceInfo &deviceInfo);
void OnDiscoverFailed(uint16_t subscribeId, int32_t failedReason);
void OnAuthResult(const std::string &deviceId, int32_t pinToken, int32_t status, int32_t reason);
void OnDiscoveryFailed(uint16_t subscribeId, int32_t failedReason);
void OnAuthResult(const std::string &deviceId, const std::string &token, int32_t status, int32_t reason);
void OnVerifyResult(const std::string &deviceId, int32_t resultCode, int32_t flag);
void OnDmfaCall(const std::string &paramJson);
static void DmAuthParamToJsAuthParamy(const napi_env &env,
const OHOS::DistributedHardware::DmAuthParam &authParam, napi_value &paramResult);
private:
static napi_value JsOffFrench(napi_env env, int32_t num, napi_value thisVar, napi_value argv[]);
static napi_value JsOnFrench(napi_env env, int32_t num, napi_value thisVar, napi_value argv[]);
static void CallAsyncWorkSync(napi_env env, DeviceInfoAsyncCallbackInfo *deviceInfoAsyncCallbackInfo);
static void CallAsyncWork(napi_env env, DeviceInfoAsyncCallbackInfo *deviceInfoAsyncCallbackInfo);
static void CallGetTrustedDeviceListStatusSync(napi_env env, napi_status &status,
DeviceInfoAsyncCallbackInfo *deviceInfoAsyncCallbackInfo);
static void CallGetTrustedDeviceListStatus(napi_env env, napi_status &status,
DeviceInfoAsyncCallbackInfo *deviceInfoAsyncCallbackInfo);
static napi_value CallDeviceList(napi_env env, napi_callback_info info,
DeviceInfoAsyncCallbackInfo *deviceInfoAsyncCallbackInfo);
static void CallGetLocalDeviceInfoSync(napi_env env, napi_status &status,
DeviceInfoAsyncCallbackInfo *deviceInfoAsyncCallbackInfo);
static void CallGetLocalDeviceInfo(napi_env env, napi_status &status,
DeviceInfoAsyncCallbackInfo *deviceInfoAsyncCallbackInfo);
private:
napi_env env_;
@@ -196,4 +243,4 @@ private:
static AuthAsyncCallbackInfo verifyAsyncCallbackInfo_;
};
#endif // OHOS_DEVICE_MANAGER_NATIVE_DEVICEMANAGER_JS_H
#endif // OHOS_DM_NATIVE_DEVICEMANAGER_JS_H
+12 -12
View File
@@ -4,7 +4,7 @@
* 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
* 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,
@@ -15,7 +15,7 @@
#include "dm_native_event.h"
#include "device_manager_log.h"
#include "dm_log.h"
using namespace OHOS::DistributedHardware;
@@ -38,7 +38,7 @@ DmNativeEvent::~DmNativeEvent()
void DmNativeEvent::On(std::string &eventType, napi_value handler)
{
DMLOG(DM_LOG_INFO, "DmNativeEvent On in for event: %s", eventType.c_str());
LOGI("DmNativeEvent On in for event: %s", eventType.c_str());
auto listener = std::make_shared<DmEventListener>();
listener->eventType = eventType;
napi_create_reference(env_, handler, 1, &listener->handlerRef);
@@ -47,17 +47,17 @@ void DmNativeEvent::On(std::string &eventType, napi_value handler)
void DmNativeEvent::Off(std::string &eventType)
{
DMLOG(DM_LOG_INFO, "DmNativeEvent Off in for event: %s", eventType.c_str());
LOGI("DmNativeEvent Off in for event: %s", eventType.c_str());
napi_handle_scope scope = nullptr;
napi_open_handle_scope(env_, &scope);
if (scope == nullptr) {
DMLOG(DM_LOG_ERROR, "scope is nullptr");
LOGE("scope is nullptr");
return;
}
auto iter = eventMap_.find(eventType);
if (iter == eventMap_.end()) {
DMLOG(DM_LOG_ERROR, "eventType %s not find", eventType.c_str());
LOGE("eventType %s not find", eventType.c_str());
return;
}
auto listener = iter->second;
@@ -68,38 +68,38 @@ void DmNativeEvent::Off(std::string &eventType)
void DmNativeEvent::OnEvent(const std::string &eventType, size_t argc, const napi_value *argv)
{
DMLOG(DM_LOG_INFO, "OnEvent for %s", eventType.c_str());
LOGI("OnEvent for %s", eventType.c_str());
napi_handle_scope scope = nullptr;
napi_open_handle_scope(env_, &scope);
if (scope == nullptr) {
DMLOG(DM_LOG_ERROR, "scope is nullptr");
LOGE("scope is nullptr");
return;
}
auto iter = eventMap_.find(eventType);
if (iter == eventMap_.end()) {
DMLOG(DM_LOG_ERROR, "eventType %s not find", eventType.c_str());
LOGE("eventType %s not find", eventType.c_str());
return;
}
auto listener = iter->second;
napi_value thisVar = nullptr;
napi_status status = napi_get_reference_value(env_, thisVarRef_, &thisVar);
if (status != napi_ok) {
DMLOG(DM_LOG_ERROR, "napi_get_reference_value thisVar for %s failed, status=%d", eventType.c_str(), status);
LOGE("napi_get_reference_value thisVar for %s failed, status=%d", eventType.c_str(), status);
return;
}
napi_value handler = nullptr;
status = napi_get_reference_value(env_, listener->handlerRef, &handler);
if (status != napi_ok) {
DMLOG(DM_LOG_ERROR, "napi_get_reference_value handler for %s failed, status=%d", eventType.c_str(), status);
LOGE("napi_get_reference_value handler for %s failed, status=%d", eventType.c_str(), status);
return;
}
napi_value callResult = nullptr;
status = napi_call_function(env_, thisVar, handler, argc, argv, &callResult);
if (status != napi_ok) {
DMLOG(DM_LOG_ERROR, "napi_call_function for %s failed, status=%d", eventType.c_str(), status);
LOGE("napi_call_function for %s failed, status=%d", eventType.c_str(), status);
return;
}
napi_close_handle_scope(env_, scope);
File diff suppressed because it is too large Load Diff
+4 -3
View File
@@ -12,8 +12,7 @@
"device_manager.h",
"device_manager_callback.h",
"dm_device_info.h",
"dm_subscribe_info.h",
"dm_app_image_info.h"
"dm_subscribe_info.h"
]
}
}
@@ -23,7 +22,9 @@
"//foundation/distributedhardware/devicemanager/interfaces/inner_kits/native_cpp:devicemanagersdk",
"//foundation/distributedhardware/devicemanager/interfaces/kits/js:devicemanager_native_js",
"//foundation/distributedhardware/devicemanager/services/devicemanagerservice:devicemanagerservice",
"//foundation/distributedhardware/devicemanager/sa_profile:dm_sa_profile"
"//foundation/distributedhardware/devicemanager/sa_profile:dm_sa_profile",
"//foundation/distributedhardware/devicemanager/ext/pin_auth:devicemanagerext_pin_auth",
"//foundation/distributedhardware/devicemanager/ext/profile:devicemanagerext_profile"
],
"test_list": [
"//foundation/distributedhardware/devicemanager/test:test"
+4 -4
View File
@@ -15,12 +15,12 @@
-->
<info>
<process>foundation</process>
<systemability> <!-- Declare a sytem ability and its profile -->
<systemability> <!-- Declare a system ability and its profile -->
<name>4802</name> <!-- Declare the name of system ability -->
<libpath>libdevicemanagerservice.z.so</libpath> <!-- Declare the path of .so file which includes the system ability; Note: 1 .so file can have 1 to N system abilities. -->
<!--<depend></depend> --> <!-- Declare the name of system abilities which the system ability depends on, using ";" as separator among names. If there are dependencies, it needs to check if all those dependencies are avliable in service manager before starting the system ability. -->
<!--<depend-time-out></depend-time-out> --> <!-- Check all dependencies are avaliable before the timeout period ended. The MAX_DEPENDENCY_TIMEOUT is 60s. -->
<run-on-create>true</run-on-create> <!-- "true" means the system ability would start imediately, "false" means the system ability would start on demand. -->
<!--<depend></depend> --> <!-- Declare the name of system abilities which the system ability depends on, using ";" as separator among names. If there are dependencies, it needs to check if all those dependencies are available in service manager before starting the system ability. -->
<!--<depend-time-out></depend-time-out> --> <!-- Check all dependencies are available before the timeout period ended. The MAX_DEPENDENCY_TIMEOUT is 60s. -->
<run-on-create>true</run-on-create> <!-- "true" means the system ability would start immediately, "false" means the system ability would start on demand. -->
<distributed>false</distributed> <!-- "true" means the system ability supports distributed scheduling while "false" is not. -->
<dump-level>1</dump-level> <!-- Declare the dump level. 1-high; 2-media; 3-low -->
</systemability>
-190
View File
@@ -1,190 +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.
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)) {
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"
}
}
@@ -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_DM_ABILITY_MANAGER_H
#define OHOS_DM_ABILITY_MANAGER_H
#include <string>
#include <vector>
#include <mutex>
#include <semaphore.h>
#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
@@ -1,96 +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_HICHAIN_CONNECTOR_H
#define OHOS_HICHAIN_CONNECTOR_H
#include <string>
#include <memory>
#include <cstdint>
#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, int32_t operationCode, const char *returnData);
static void onError(int64_t requestId, int32_t operationCode, int32_t errorCode, const char *errorReturn);
static char *onRequest(int64_t requestId, int32_t operationCode, const char *reqParams);
};
class HichainConnector {
DECLARE_SINGLE_INSTANCE(HichainConnector);
public:
int32_t Init();
bool OnTransmit(int64_t requestId, const uint8_t *data, uint32_t dataLen);
int64_t GenRequestId();
void RegisterConnectorCallback(std::shared_ptr<HichainConnectorCallback> callback);
int32_t CreateGroup(int64_t requestId, const std::string &groupName);
int32_t AddMemeber(std::string deviceId, std::shared_ptr<MsgResponseAuth> msgResponseAuth);
void GetRelatedGroups(std::string DeviceId, std::vector<GroupInfo> &groupList);
void SyncGroups(std::string deviceId, std::vector<std::string> &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<GroupInfo> &groupList, std::vector<std::string> &syncGroupList);
void OnMemberJoin(int64_t requestId, int32_t status);
int32_t GetGroupInfo(std::string queryParams, std::vector<GroupInfo> &groupList);
int32_t IsGroupCreated(std::string groupName, GroupInfo &groupInfo);
private:
std::string GetConnectPara(std::string deviceId, std::shared_ptr<MsgResponseAuth> msgResponseAuth);
bool IsGroupInfoInvalid(GroupInfo &group);
private:
std::shared_ptr<HichainConnectorCallback> hichainConnectorCallback_ = nullptr;
const DeviceGroupManager *deviceGroupManager_ = nullptr;
DeviceAuthCallback deviceAuthCallback_ ;
};
} // namespace DistributedHardware
} // namespace OHOS
#endif // OHOS_HICHAIN_ADAPTER_H
@@ -1,50 +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_IPC_SERVER_ADAPTER_H
#define OHOS_DEVICE_MANAGER_IPC_SERVER_ADAPTER_H
#include <string>
#include "dm_app_image_info.h"
#include "dm_device_info.h"
#include "dm_subscribe_info.h"
#include "hichain_connector.h"
#include "single_instance.h"
#include "softbus_adapter.h"
namespace OHOS {
namespace DistributedHardware {
class IpcServerAdapter {
DECLARE_SINGLE_INSTANCE(IpcServerAdapter);
public:
int32_t ModuleInit();
int32_t GetTrustedDeviceList(std::string &pkgName, std::string &extra, DmDeviceInfo **info, int32_t *infoNum);
int32_t StartDeviceDiscovery(std::string &pkgName, 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);
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_IPC_SERVER_ADAPTER_H
@@ -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_IPC_SERVER_LISTENER_ADAPTER_H
#define OHOS_DEVICE_MANAGER_IPC_SERVER_LISTENER_ADAPTER_H
#include "discovery_service.h"
#include "ipc_server_listener.h"
#include "single_instance.h"
#include "dm_device_info.h"
namespace OHOS {
namespace DistributedHardware {
class IpcServerListenerAdapter {
DECLARE_SINGLE_INSTANCE(IpcServerListenerAdapter);
public:
void OnDeviceStateChange(DmDeviceState state, DmDeviceInfo &deviceInfo);
void OnDeviceFound(std::string &pkgName, uint16_t originId, DmDeviceInfo &deviceInfo);
void OnDiscoverFailed(std::string &pkgName, uint16_t originId, DiscoveryFailReason failReason);
void OnDiscoverySuccess(std::string &pkgName, uint16_t originId);
void OnAuthResult(std::string &pkgName, std::string &deviceId, int32_t pinToken, uint32_t status, uint32_t reason);
void OnCheckAuthResult(std::string &deviceId, int32_t resultCode, int32_t flag);
void OnFaCall(std::string &pkgName, std::string &paramJson);
private:
IpcServerListener ipcServerListener_;
};
} // namespace DistributedHardware
} // namespace OHOS
#endif // OHOS_DEVICE_MANAGER_IPC_SERVER_LISTENER_ADAPTER_H
@@ -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_IPC_SERVER_LISTENER_H
#define OHOS_DEVICE_MANAGER_IPC_SERVER_LISTENER_H
#include <memory>
#include "ipc_req.h"
#include "ipc_rsp.h"
#include "ipc_server_listenermgr.h"
namespace OHOS {
namespace DistributedHardware {
class IpcServerListener {
public:
IpcServerListener() = default;
virtual ~IpcServerListener() = default;
public:
int32_t SendRequest(int32_t cmdCode, std::shared_ptr<IpcReq> req, std::shared_ptr<IpcRsp> rsp);
int32_t SendAll(int32_t cmdCode, std::shared_ptr<IpcReq> req, std::shared_ptr<IpcRsp> rsp);
private:
void CommonSvcToIdentity(CommonSvcId *svcId, SvcIdentity *identity);
int32_t GetIdentityByPkgName(std::string &name, SvcIdentity *svc);
};
} // namespace DistributedHardware
} // namespace OHOS
#endif // OHOS_DEVICE_MANAGER_IPC_SERVER_LISTENER_H
@@ -1,50 +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_IPC_SERVER_LISTENER_MGR_H
#define OHOS_DEVICE_MANAGER_IPC_SERVER_LISTENER_MGR_H
#include <cstdint>
#include <string>
#include <map>
#include <mutex>
#include "liteipc_adapter.h"
#include "single_instance.h"
namespace OHOS {
namespace DistributedHardware {
typedef struct CommonSvcId {
uint32_t handle;
uint32_t token;
uint32_t cookie;
IpcContext *ipcCtx;
uint32_t cbId;
}CommonSvcId;
class IpcServerListenermgr {
DECLARE_SINGLE_INSTANCE(IpcServerListenermgr);
public:
int32_t RegisterListener(std::string &pkgName, const CommonSvcId *svcId);
int32_t GetListenerByPkgName(std::string &pkgName, CommonSvcId *svcId);
int32_t UnregisterListener(std::string &pkgName);
const std::map<std::string, CommonSvcId> &GetAllListeners();
private:
std::map<std::string, CommonSvcId> dmListenerMap_;
std::mutex lock_;
};
} // namespace DistributedHardware
} // namespace OHOS
#endif // OHOS_DEVICE_MANAGER_IPC_SERVER_LISTENER_MGR_H
@@ -1,26 +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_IPC_SERVER_STUB_H
#define OHOS_DEVICE_MANAGER_IPC_SERVER_STUB_H
#include <cstdint>
#include "liteipc_adapter.h"
int32_t IpcServerStubInit(void);
int32_t RegisterDeviceManagerListener(IpcIo *req, IpcIo *reply);
int32_t UnRegisterDeviceManagerListener(IpcIo *req, IpcIo *reply);
#endif // OHOS_DEVICE_MANAGER_IPC_SERVER_STUB_H
@@ -1,35 +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_IPC_SERVER_CLIENT_PROXY_H
#define OHOS_DEVICE_MANAGER_IPC_SERVER_CLIENT_PROXY_H
#include "ipc_remote_broker.h"
#include "iremote_proxy.h"
namespace OHOS {
namespace DistributedHardware {
class IpcServerClientProxy : public IRemoteProxy<IpcRemoteBroker> {
public:
explicit IpcServerClientProxy(const sptr<IRemoteObject> &impl)
: IRemoteProxy<IpcRemoteBroker>(impl) {};
~IpcServerClientProxy() {};
int32_t SendCmd(int32_t cmdCode, std::shared_ptr<IpcReq> req, std::shared_ptr<IpcRsp> rsp) override;
private:
static inline BrokerDelegator<IpcServerClientProxy> delegator_;
};
} // namespace DistributedHardware
} // namespace OHOS
#endif // OHOS_DEVICE_MANAGER_IPC_SERVER_CLIENT_PROXY_H
@@ -1,36 +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_IPC_SERVER_LISTENER_H
#define OHOS_DEVICE_MANAGER_IPC_SERVER_LISTENER_H
#include <cstdint>
#include "ipc_req.h"
#include "ipc_rsp.h"
namespace OHOS {
namespace DistributedHardware {
class IpcServerListener {
public:
IpcServerListener() = default;
virtual ~IpcServerListener() = default;
public:
int32_t SendRequest(int32_t cmdCode, std::shared_ptr<IpcReq> req, std::shared_ptr<IpcRsp> rsp);
int32_t SendAll(int32_t cmdCode, std::shared_ptr<IpcReq> req, std::shared_ptr<IpcRsp> rsp);
};
} // namespace DistributedHardware
} // namespace OHOS
#endif // OHOS_DEVICE_MANAGER_IPC_SERVER_LISTENER_H
@@ -1,76 +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_IPC_SERVER_STUB_H
#define OHOS_DEVICE_MANAGER_IPC_SERVER_STUB_H
#include <memory>
#include <mutex>
#include <map>
#include <tuple>
#include <vector>
#include "nlohmann/json.hpp"
#include "system_ability.h"
#include "thread_pool.h"
#include "iremote_stub.h"
#include "ipc_remote_broker.h"
#include "single_instance.h"
#include "hichain_connector.h"
namespace OHOS {
namespace DistributedHardware {
enum class ServiceRunningState {
STATE_NOT_START,
STATE_RUNNING
};
class AppDeathRecipient : public IRemoteObject::DeathRecipient {
public:
void OnRemoteDied(const wptr<IRemoteObject> &remote) override;
AppDeathRecipient() = default;
~AppDeathRecipient() = default;
};
class IpcServerStub : public SystemAbility, public IRemoteStub<IpcRemoteBroker> {
DECLARE_SYSTEM_ABILITY(IpcServerStub);
DECLARE_SINGLE_INSTANCE_BASE(IpcServerStub);
public:
void OnStart() override;
void OnStop() override;
int32_t OnRemoteRequest(uint32_t code,
MessageParcel &data, MessageParcel &reply, MessageOption &option) override;
int32_t SendCmd(int32_t cmdCode, std::shared_ptr<IpcReq> req, std::shared_ptr<IpcRsp> rsp) override;
int32_t RegisterDeviceManagerListener(std::string &pkgName, sptr<IRemoteObject> listener);
int32_t UnRegisterDeviceManagerListener(std::string &pkgName);
ServiceRunningState QueryServiceState() const;
const std::map<std::string, sptr<IRemoteObject>> &GetDmListener();
const sptr<IpcRemoteBroker> GetDmListener(std::string pkgName) const;
private:
IpcServerStub();
~IpcServerStub() = default;
bool Init();
private:
bool registerToService_;
ServiceRunningState state_;
std::mutex listenerLock_;
std::map<std::string, sptr<AppDeathRecipient>> appRecipient_;
std::map<std::string, sptr<IRemoteObject>> dmListener_;
};
} // namespace DistributedHardware
} // namespace OHOS
#endif // OHOS_DEVICE_MANAGER_IPC_SERVER_STUB_H
@@ -1,46 +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_MSG_CODEC_H
#define OHOS_MSG_CODEC_H
#include <vector>
#include <string>
#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<std::string> &groupIdList, std::string &deviceId);
static std::vector<std::string> 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<MsgRequestAuth> DecodeRequestAuth(std::string &jsonStr,
std::shared_ptr<MsgRequestAuth> msgRequestAuth);
static std::shared_ptr<MsgResponseAuth> DecodeResponseAuth(std::string &jsonStr);
static std::shared_ptr<MsgSyncGroup> DecodeSyncGroup(std::string &jsonStr);
};
}
}
#endif
@@ -1,48 +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_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<MsgHead> Decode(nlohmann::json &json);
int32_t GetMsgType();
private:
int32_t mMsgType_;
std::string mItfVer_;
};
}
}
#endif
@@ -1,79 +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_MSG_REQUEST_AUTH_H
#define OHOS_MSG_REQUEST_AUTH_H
#include <vector>
#include <string>
#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<std::string> Encode();
static std::shared_ptr<MsgRequestAuth> Decode(nlohmann::json &json, std::shared_ptr<MsgRequestAuth> msgIn);
static void SetThumbnailSize(nlohmann::json &json, std::shared_ptr<MsgRequestAuth> msg);
int32_t GetMsgSlice();
int32_t GetMsgCnt();
std::string GetRequestDeviceId();
public:
std::shared_ptr<MsgHead> 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<MsgRequestAuth> 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<MsgRequestAuth> 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<MsgRequestAuth> msg);
};
}
}
#endif
@@ -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 OHOS_MSG_RESPONSE_AUTH_H
#define OHOS_MSG_RESPONSE_AUTH_H
#include <vector>
#include <string>
#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<std::string> GetSyncGroupList();
private:
std::shared_ptr<MsgHead> 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<std::string> mSyncGroupList_;
};
}
}
#endif
@@ -1,45 +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_MSG_SYNC_GROUP_H
#define OHOS_MSG_SYNC_GROUP_H
#include <vector>
#include <string>
#include "nlohmann/json.hpp"
#include "msg_head.h"
namespace OHOS {
namespace DistributedHardware {
class MsgSyncGroup {
public:
MsgSyncGroup() {};
MsgSyncGroup(std::vector<std::string> &groupList, std::string &deviceId);
~MsgSyncGroup() = default;
void Encode(nlohmann::json &json);
int32_t Decode(nlohmann::json &json);
std::string GetDeviceId();
std::vector<std::string> GetGroupIdList();
private:
std::shared_ptr<MsgHead> mHead_;
std::string mDeviceId_;
std::vector<std::string> mGroupIdList_;
};
}
}
#endif
@@ -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_AUTH_MANAGER_H
#define OHOS_AUTH_MANAGER_H
#include <map>
#include <string>
#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<RequestSession> mPendingReqSessionPtr_ {nullptr};
std::shared_ptr<ResponseSession> mPendingRespSessionPtr {};
std::map<std::string, std::shared_ptr<RequestSession>> mWaitScanReqSessionMap_ = {};
};
}
}
#endif
@@ -1,86 +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_REQUEST_SESSION_H
#define OHOS_REQUEST_SESSION_H
#include <string>
#include <vector>
#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<std::string> 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<std::string> &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<MsgResponseAuth> responseMsgPtr_;
};
}
}
#endif
@@ -1,81 +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_RESPONSE_SESSION_H
#define OHOS_RESPONSE_SESSION_H
#include <string>
#include <vector>
#include <mutex>
#include <semaphore.h>
#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<ResponseSession> {
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<MsgRequestAuth> mMsgRequestAuthPtr_;
int64_t mChannelId_;
int32_t mPincode_;
int32_t mSessionStatus_;
std::shared_ptr<DmTimer> mReceiveTimerPtr_;
std::shared_ptr<DmTimer> mMemberJoinTimerPtr_;
};
} // namespace DistributedHardware
} // namespace OHOS
#endif
@@ -1,78 +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_SOFTBUS_ADAPTER_H
#define OHOS_DEVICE_MANAGER_SOFTBUS_ADAPTER_H
#include <string>
#include <mutex>
#include <map>
#include <memory>
#include <vector>
#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(int32_t publishId);
static void OnPublishFail(int32_t 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 OnSoftBusDeviceOnline(NodeBasicInfo *info);
static void OnSoftbusDeviceOffline(NodeBasicInfo *info);
static void OnSoftbusDeviceInfoChanged(NodeBasicInfoType type, NodeBasicInfo *info);
static void OnSoftbusDeviceFound(const DeviceInfo *device);
static void OnSoftbusDiscoverFailed(int32_t subscribeId, DiscoveryFailReason failReason);
static void OnSoftbusDiscoverySuccess(int32_t 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<std::string, std::vector<std::shared_ptr<SubscribeInfoAdapter>>> subscribeInfos_;
static std::map<std::string, std::shared_ptr<DeviceInfo>> discoverDeviceInfoMap_;
static std::vector<std::shared_ptr<DeviceInfo>> 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
@@ -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_SOFTBUS_SESSION_H
#define OHOS_DEVICE_MANAGER_SOFTBUS_SESSION_H
#include <set>
#include <vector>
#include <string>
#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();
int32_t OnSessionOpened(int32_t sessionId, int32_t result);
void OnSessionClosed(int32_t sessionId);
void OnBytesReceived(int32_t sessionId, const void *data, uint32_t dataLen);
void CloseSession(int32_t sessionId);
int32_t SendMessages(const char *deviceId, std::vector<std::string> &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<int32_t> sessionIdSet_;
std::vector<std::string> messages_ {};
};
} // namespace DistributedHardware
} // namespace OHOS
#endif // OHOS_DEVICE_MANAGER_SOFTBUS_SESSION_H
@@ -1,71 +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 TIMER_H
#define TIMER_H
#include <string>
#include <errno.h>
#include <sys/epoll.h>
#include <stdint.h>
#include <stdio.h>
#include <thread>
#include <unistd.h>
#include <cstdio>
#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];
struct epoll_event mEv_;
struct epoll_event mEvents_[MAXEVENTS];
int32_t mEpFd_;
std::thread mThread_;
std::string mTimerName_;
};
}
}
#endif
@@ -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.
*/
#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 += timeout_s;
sem_timedwait(&mSem_, &ts);
}
void DmAbilityManager::StartAbilityDone()
{
mStatus_ = AbilityStatus::ABILITY_STATUS_SUCCESS;
sem_post(&mSem_);
}
}
}
@@ -1,97 +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.
*/
#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 faild");
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 += timeout_s;
sem_timedwait(&mSem_, &ts);
}
void DmAbilityManager::StartAbilityDone()
{
mStatus_ = AbilityStatus::ABILITY_STATUS_SUCCESS;
sem_post(&mSem_);
}
}
}
@@ -1,490 +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.
*/
#include "hichain_connector.h"
#include <cstdlib>
#include <ctime>
#include <functional>
#include <securec.h>
#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"
#include "ipc_server_listener_adapter.h"
#include "ipc_check_authenticate_req.h"
#include "softbus_session.h"
#include "auth_manager.h"
#include "ipc_server_stub.h"
#include "dm_ability_manager.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<std::string>();
}
if (jsonObject.find(FIELD_GROUP_ID) != jsonObject.end()) {
groupInfo.groupId = jsonObject.at(FIELD_GROUP_ID).get<std::string>();
}
if (jsonObject.find(FIELD_GROUP_OWNER) != jsonObject.end()) {
groupInfo.groupOwner = jsonObject.at(FIELD_GROUP_OWNER).get<std::string>();
}
if (jsonObject.find(FIELD_GROUP_TYPE) != jsonObject.end()) {
groupInfo.groupType = jsonObject.at(FIELD_GROUP_TYPE).get<int32_t>();
}
if (jsonObject.find(FIELD_GROUP_VISIBILITY) != jsonObject.end()) {
groupInfo.groupVisibility = jsonObject.at(FIELD_GROUP_VISIBILITY).get<int32_t>();
}
}
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)
{
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 ret = deviceGroupManager_->createGroup(requestId, DEVICE_MANAGER_APP.c_str(), jsonObj.dump().c_str());
if (ret != 0) {
DMLOG(DM_LOG_ERROR, "Faild 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<GroupInfo> groupList;
if (GetGroupInfo(queryParams, groupList)) {
groupInfo = groupList[0];
return true;
}
return false;
}
int32_t HichainConnector::GetGroupInfo(std::string queryParams, std::vector<GroupInfo> &groupList)
{
char *groupVec = nullptr;
uint32_t num = 0;
int32_t ret = deviceGroupManager_->getGroupInfo(DEVICE_MANAGER_APP.c_str(), queryParams.c_str(), &groupVec, &num);
if (ret != 0) {
DMLOG(DM_LOG_ERROR, "HichainConnector::GetGroupInfo faild , ret: %d.", ret);
return false;
}
if (groupVec == nullptr) {
DMLOG(DM_LOG_ERROR, "HichainConnector::GetGroupInfo faild , 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<GroupInfo> groupInfos = jsonObject.get<std::vector<GroupInfo>>();
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<HichainConnectorCallback> callback)
{
hichainConnectorCallback_ = callback;
}
void HichainConnector::OnGroupCreated(int64_t requestId, const std::string &returnData)
{
if (hichainConnectorCallback_ == nullptr) {
DMLOG(DM_LOG_ERROR, "HichainConnector::OnGroupCreated hichainConnectorCallback_ not registe.");
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<std::string>();
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 registe.");
return;
}
hichainConnectorCallback_->OnMemberJoin(requestId, status);
}
int32_t HichainConnector::AddMemeber(std::string deviceId, std::shared_ptr<MsgResponseAuth> 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();
DMLOG(DM_LOG_INFO, "HichainConnector::AddMemeber completed");
return deviceGroupManager_->addMemberToGroup(msgResponseAuth->GetRequestId(), DEVICE_MANAGER_APP.c_str(),
tmpStr.c_str());
}
std::string HichainConnector::GetConnectPara(std::string deviceId, std::shared_ptr<MsgResponseAuth> 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<GroupInfo> &groupList)
{
DMLOG(DM_LOG_INFO, "HichainConnector::GetRelatedGroups Start to get local related groups.");
uint32_t groupNum = 0;
char *returnGroups = nullptr;
int32_t ret = deviceGroupManager_->getRelatedGroups(DEVICE_MANAGER_APP.c_str(), deviceId.c_str(),
&returnGroups, &groupNum);
if (ret != 0) {
DMLOG(DM_LOG_ERROR, "HichainConnector::GetRelatedGroups faild , ret: %d.", ret);
return;
}
if (returnGroups == nullptr) {
DMLOG(DM_LOG_ERROR, "HichainConnector::GetRelatedGroups faild , 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<GroupInfo> groupInfos = jsonObject.get<std::vector<GroupInfo>>();
if (groupInfos.size() == 0) {
DMLOG(DM_LOG_ERROR, "HichainConnector::GetRelatedGroups group failed, groupInfos is empty.");
return;
}
groupList = groupInfos;
return;
}
void HichainConnector::GetSyncGroupList(std::vector<GroupInfo> &groupList, std::vector<std::string> &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<std::string> &remoteGroupIdList)
{
std::vector<GroupInfo> 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 ret = deviceGroupManager_->deleteMemberFromGroup(requestId, DEVICE_MANAGER_APP.c_str(),
deleteParams.c_str());
if (ret != 0) {
DMLOG(DM_LOG_ERROR, "HichainConnector::DelMemberFromGroup faild , ret: %d.", ret);
return ret;
}
return 0;
}
void HichainConnector::DeleteGroup(std::string &groupId)
{
int64_t requestId = GenRequestId();
nlohmann::json jsonObj;
jsonObj[FIELD_GROUP_ID] = groupId;
std::string disbandParams = jsonObj.dump();
int32_t ret = deviceGroupManager_->deleteGroup(requestId, DEVICE_MANAGER_APP.c_str(), disbandParams.c_str());
if (ret != 0) {
DMLOG(DM_LOG_ERROR, "HichainConnector::DeleteGroup faild , ret: %d.", ret);
}
}
void HichainAuthenCallBack::onFinish(int64_t requestId, int32_t 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, int32_t operationCode, int32_t 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, int32_t 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;
}
}
}
@@ -1,198 +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.
*/
#include <random>
#include "securec.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 "ipc_server_adapter.h"
#include "ipc_server_listener.h"
namespace OHOS {
namespace DistributedHardware {
IMPLEMENT_SINGLE_INSTANCE(IpcServerAdapter);
int32_t IpcServerAdapter::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 IpcServerAdapter::GenRandInt(int32_t randMin, int32_t randMax)
{
std::random_device randDevice;
std::mt19937 genRand(randDevice());
std::uniform_int_distribution<int> disRand(randMin, randMax);
return disRand(genRand);
}
int32_t IpcServerAdapter::ModuleInit()
{
if (SoftbusAdapter::Init() != DEVICEMANAGER_OK) {
DMLOG(DM_LOG_ERROR, "softbus adapter init failed");
return DEVICEMANAGER_INIT_FAILED;
}
if (HichainConnector::GetInstance().Init() != DEVICEMANAGER_OK) {
DMLOG(DM_LOG_ERROR, "hichain connector init failed");
return DEVICEMANAGER_INIT_FAILED;
}
return DEVICEMANAGER_OK;
}
int32_t IpcServerAdapter::GetTrustedDeviceList(std::string &pkgName, std::string &extra,
DmDeviceInfo **info, int32_t *infoNum)
{
if (info == nullptr || infoNum == nullptr) {
return DEVICEMANAGER_NULLPTR;
}
DMLOG(DM_LOG_INFO, "In, pkgName: %s", pkgName.c_str());
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;
}
FreeNodeInfo(nodeInfo);
DMLOG(DM_LOG_INFO, "success, pkgName:%s, deviceCount %d", pkgName.c_str(), *infoNum);
return DEVICEMANAGER_OK;
}
int32_t IpcServerAdapter::StartDeviceDiscovery(std::string &pkgName, 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 IpcServerAdapter::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 IpcServerAdapter::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 IpcServerAdapter::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);
}
int32_t IpcServerAdapter::GetAuthenticationParam(std::string &pkgName, DmAuthParam &authParam)
{
if (pkgName.empty()) {
DMLOG(DM_LOG_ERROR, "invalid para");
return DEVICEMANAGER_INVALID_VALUE;
}
DmAbilityManager::GetInstance().StartAbilityDone();
AuthManager::GetInstance().GetAuthenticationParam(authParam);
return DEVICEMANAGER_OK;
}
int32_t IpcServerAdapter::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;
}
} // namespace DistributedHardware
} // namespace OHOS
@@ -1,128 +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.
*/
#include "ipc_server_listener_adapter.h"
#include <memory>
#include "securec.h"
#include "device_manager_errno.h"
#include "device_manager_log.h"
#include "anonymous_string.h"
#include "ipc_notify_auth_result_req.h"
#include "ipc_notify_check_auth_result_req.h"
#include "ipc_notify_device_found_req.h"
#include "ipc_notify_device_state_req.h"
#include "ipc_notify_discover_result_req.h"
#include "ipc_notify_dmfa_result_req.h"
namespace OHOS {
namespace DistributedHardware {
IMPLEMENT_SINGLE_INSTANCE(IpcServerListenerAdapter);
void IpcServerListenerAdapter::OnDeviceStateChange(DmDeviceState state, DmDeviceInfo &deviceInfo)
{
DMLOG(DM_LOG_INFO, "OnDeviceStateChange");
std::shared_ptr<IpcNotifyDeviceStateReq> pReq = std::make_shared<IpcNotifyDeviceStateReq>();
std::shared_ptr<IpcRsp> pRsp = std::make_shared<IpcRsp>();
pReq->SetDeviceState(state);
pReq->SetDeviceInfo(deviceInfo);
ipcServerListener_.SendAll(SERVER_DEVICE_STATE_NOTIFY, pReq, pRsp);
}
void IpcServerListenerAdapter::OnDeviceFound(std::string &pkgName, uint16_t originId,
DmDeviceInfo &deviceInfo)
{
DMLOG(DM_LOG_INFO, "call OnDeviceFound for %s, originId %d, deviceId %s",
pkgName.c_str(), originId, GetAnonyString(std::string(deviceInfo.deviceId)).c_str());
std::shared_ptr<IpcNotifyDeviceFoundReq> pReq = std::make_shared<IpcNotifyDeviceFoundReq>();
std::shared_ptr<IpcRsp> pRsp = std::make_shared<IpcRsp>();
pReq->SetPkgName(pkgName);
pReq->SetSubscribeId(originId);
pReq->SetDeviceInfo(deviceInfo);
ipcServerListener_.SendRequest(SERVER_DEVICE_FOUND, pReq, pRsp);
}
void IpcServerListenerAdapter::OnDiscoverFailed(std::string &pkgName, uint16_t originId,
DiscoveryFailReason failReason)
{
DMLOG(DM_LOG_INFO, "OnDiscoverFailed");
std::shared_ptr<IpcNotifyDiscoverResultReq> pReq = std::make_shared<IpcNotifyDiscoverResultReq>();
std::shared_ptr<IpcRsp> pRsp = std::make_shared<IpcRsp>();
pReq->SetPkgName(pkgName);
pReq->SetSubscribeId(originId);
pReq->SetResult(failReason);
ipcServerListener_.SendRequest(SERVER_DISCOVER_FINISH, pReq, pRsp);
}
void IpcServerListenerAdapter::OnDiscoverySuccess(std::string &pkgName, uint16_t originId)
{
DMLOG(DM_LOG_INFO, "OnDiscoverySuccess");
std::shared_ptr<IpcNotifyDiscoverResultReq> pReq = std::make_shared<IpcNotifyDiscoverResultReq>();
std::shared_ptr<IpcRsp> pRsp = std::make_shared<IpcRsp>();
pReq->SetPkgName(pkgName);
pReq->SetSubscribeId(originId);
pReq->SetResult(DEVICEMANAGER_OK);
ipcServerListener_.SendRequest(SERVER_DISCOVER_FINISH, pReq, pRsp);
}
void IpcServerListenerAdapter::OnAuthResult(std::string &pkgName, std::string &deviceId, int32_t pinToken,
uint32_t status, uint32_t reason)
{
DMLOG(DM_LOG_INFO, "%s, package: %s, deviceId: %s", __FUNCTION__, pkgName.c_str(),
GetAnonyString(deviceId).c_str());
std::shared_ptr<IpcNotifyAuthResultReq> pReq = std::make_shared<IpcNotifyAuthResultReq>();
std::shared_ptr<IpcRsp> pRsp = std::make_shared<IpcRsp>();
pReq->SetPkgName(pkgName);
pReq->SetDeviceId(deviceId);
pReq->SetPinToken(pinToken);
pReq->SetStatus(status);
pReq->SetReason(reason);
ipcServerListener_.SendRequest(SERVER_AUTH_RESULT, pReq, pRsp);
}
void IpcServerListenerAdapter::OnCheckAuthResult(std::string &authParam, int32_t resultCode,
int32_t flag)
{
DMLOG(DM_LOG_INFO, "OnCheckResult, authParam: %s, errorCode: %d",
GetAnonyString(authParam).c_str(), resultCode);
std::shared_ptr<IpcNotifyCheckAuthResultReq> pReq = std::make_shared<IpcNotifyCheckAuthResultReq>();
std::shared_ptr<IpcRsp> pRsp = std::make_shared<IpcRsp>();
pReq->SetDeviceId(authParam);
pReq->SetResult(resultCode);
pReq->SetFlag(flag);
ipcServerListener_.SendAll(SERVER_CHECK_AUTH_RESULT, pReq, pRsp);
}
void IpcServerListenerAdapter::OnFaCall(std::string &pkgName, std::string &paramJson)
{
DMLOG(DM_LOG_INFO, "OnFaCall in");
std::shared_ptr<IpcNotifyDMFAResultReq> pReq = std::make_shared<IpcNotifyDMFAResultReq>();
std::shared_ptr<IpcRsp> pRsp = std::make_shared<IpcRsp>();
pReq->SetPkgName(pkgName);
pReq->SetJsonParam(paramJson);
ipcServerListener_.SendRequest(SERVER_DEVICEMANAGER_FA_NOTIFY, pReq, pRsp);
}
} // namespace DistributedHardware
} // namespace OHOS

Some files were not shown because too many files have changed in this diff Show More