!8200 feature: dm set local device display name

Merge pull request !8200 from ym/master
This commit is contained in:
openharmony_ci 2024-11-01 13:31:52 +00:00 committed by Gitee
commit f45935a6cc
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
44 changed files with 243 additions and 979 deletions

View File

@ -70,6 +70,7 @@
"i18n",
"init",
"ipc",
"i18n",
"openssl",
"os_account",
"relational_store",

View File

@ -27,16 +27,11 @@ typedef enum {
DEVICE_NAME_TYPE_NICK_NAME,
} DeviceNameType;
typedef void (*LnnDeviceNameHandler)(DeviceNameType type, const char *deviceName);
int32_t LnnGetSettingDeviceName(char *deviceName, uint32_t len);
int32_t LnnGetUnifiedDisplayDeviceName(char *unifiedDisplayName, uint32_t len);
int32_t LnnGetUnifiedDeviceName(char *unifiedName, uint32_t len);
int32_t LnnGetUnifiedDefaultDeviceName(char *unifiedDefaultName, uint32_t len);
int32_t LnnGetSettingNickName(const char *defaultName, const char *unifiedName, char *nickName, uint32_t len);
int32_t LnnGetDeviceDisplayName(const char *nickName, const char *defaultName, char *deviceName, uint32_t len);
int32_t LnnInitGetDeviceName(LnnDeviceNameHandler handler);
int32_t LnnInitDeviceNameMonitorImpl(void);
void RegisterNameMonitor(void);
#ifdef __cplusplus
}

View File

@ -18,210 +18,16 @@
#include <securec.h>
#include "anonymizer.h"
#include "data_ability_observer_stub.h"
#include "datashare_helper.h"
#include "datashare_predicates.h"
#include "datashare_result_set.h"
#include "lnn_async_callback_utils.h"
#include "lnn_devicename_info.h"
#include "lnn_log.h"
#include "iservice_registry.h"
#include "message_handler.h"
#include "softbus_bus_center.h"
#include "softbus_def.h"
#include "softbus_errcode.h"
#include "system_ability_definition.h"
#include "uri.h"
#include "lnn_ohos_account_adapter.h"
#include "locale_config.h"
static LnnDeviceNameHandler g_eventHandler = nullptr;
namespace OHOS {
namespace BusCenter {
static const std::string SETTINGS_DATA_BASE_URI =
"datashare:///com.ohos.settingsdata/entry/settingsdata/SETTINGSDATA?Proxy=true";
static const std::string SETTINGS_DATA_SECURE_URI =
"datashare:///com.ohos.settingsdata/entry/settingsdata/USER_SETTINGSDATA_SECURE_";
static constexpr const char *SETTINGS_DATA_EXT_URI = "datashare:///com.ohos.settingsdata.DataAbility";
static constexpr const char *SETTINGS_DATA_FIELD_KEYWORD = "KEYWORD";
static constexpr const char *SETTINGS_DATA_FIELD_VALUE = "VALUE";
static constexpr const char *PREDICATES_STRING = "settings.general.device_name";
static constexpr const char *USER_DEFINED_STRING = "settings.general.user_defined_device_name";
static const uint32_t SOFTBUS_SA_ID = 4700;
class LnnSettingDataEventMonitor : public AAFwk::DataAbilityObserverStub {
public:
void OnChange() override;
};
void LnnSettingDataEventMonitor::OnChange()
{
LNN_LOGI(LNN_STATE, "device name change");
if (g_eventHandler != nullptr) {
g_eventHandler(DEVICE_NAME_TYPE_DEV_NAME, nullptr);
}
}
std::shared_ptr<DataShare::DataShareHelper> CreateDataShareHelperInstance(void)
{
sptr<ISystemAbilityManager> saManager = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
if (saManager == nullptr) {
LNN_LOGE(LNN_STATE, "saManager NULL");
return nullptr;
}
sptr<IRemoteObject> remoteObject = saManager->GetSystemAbility(SOFTBUS_SA_ID);
if (remoteObject == nullptr) {
LNN_LOGE(LNN_STATE, "remoteObject NULL");
return nullptr;
}
return DataShare::DataShareHelper::Creator(remoteObject, SETTINGS_DATA_BASE_URI, SETTINGS_DATA_EXT_URI);
}
static int32_t GetDeviceNameFromDataShareHelper(std::shared_ptr<DataShare::DataShareHelper> &dataShareHelper,
std::shared_ptr<Uri> &uri, const char *key, char *deviceName, uint32_t len)
{
int32_t numRows = 0;
std::string val;
std::vector<std::string> columns;
columns.emplace_back(SETTINGS_DATA_FIELD_VALUE);
DataShare::DataSharePredicates predicates;
predicates.EqualTo(SETTINGS_DATA_FIELD_KEYWORD, key);
auto resultSet = dataShareHelper->Query(*uri, predicates, columns);
if (resultSet == nullptr) {
LNN_LOGE(LNN_STATE, "query fail.");
return SOFTBUS_ERR;
}
resultSet->GetRowCount(numRows);
if (numRows <= 0) {
LNN_LOGE(LNN_STATE, "row zero.");
resultSet->Close();
return SOFTBUS_ERR;
}
int columnIndex;
resultSet->GoToFirstRow();
resultSet->GetColumnIndex(SETTINGS_DATA_FIELD_VALUE, columnIndex);
if (resultSet->GetString(columnIndex, val) != SOFTBUS_OK) {
LNN_LOGE(LNN_STATE, "GetString val fail");
resultSet->Close();
return SOFTBUS_ERR;
}
if (strncpy_s(deviceName, len, val.c_str(), strlen(val.c_str())) != EOK) {
LNN_LOGE(LNN_STATE, "strncpy_s fail.");
resultSet->Close();
return SOFTBUS_ERR;
}
char *anonyDeviceName = NULL;
Anonymize(deviceName, &anonyDeviceName);
LNN_LOGI(LNN_STATE, "deviceName=%{public}s.", AnonymizeWrapper(anonyDeviceName));
AnonymizeFree(anonyDeviceName);
resultSet->Close();
return SOFTBUS_OK;
}
static int32_t GetDefaultDeviceName(std::shared_ptr<DataShare::DataShareHelper> &dataShareHelper,
char *deviceName, uint32_t len)
{
std::shared_ptr<Uri> uri = std::make_shared<Uri>(SETTINGS_DATA_BASE_URI + "&key=" + PREDICATES_STRING);
LNN_LOGI(LNN_STATE, "get default deviceName");
return GetDeviceNameFromDataShareHelper(dataShareHelper, uri, PREDICATES_STRING, deviceName, len);
}
static int32_t GetUserDefinedDeviceName(std::shared_ptr<DataShare::DataShareHelper> &dataShareHelper,
char *deviceName, uint32_t len)
{
int32_t osAccountId = GetActiveOsAccountIds();
if (osAccountId == SOFTBUS_ERR) {
return SOFTBUS_NO_INIT;
}
std::string accountIdStr = std::to_string(osAccountId);
std::shared_ptr<Uri> uri = std::make_shared<Uri>(SETTINGS_DATA_SECURE_URI + accountIdStr + "?Proxy=true&key=" +
USER_DEFINED_STRING);
LNN_LOGI(LNN_STATE, "get user defined deviceName, accountIdStr=%{public}s", accountIdStr.c_str());
return GetDeviceNameFromDataShareHelper(dataShareHelper, uri, USER_DEFINED_STRING, deviceName, len);
}
static void RegisterNameMonitorHelper(void)
{
auto dataShareHelper = OHOS::BusCenter::CreateDataShareHelperInstance();
if (dataShareHelper == nullptr) {
LNN_LOGE(LNN_STATE, "CreateDataShareHelperInstance fail.");
return;
}
auto uri = std::make_shared<Uri>(SETTINGS_DATA_BASE_URI + "&key=" + PREDICATES_STRING);
sptr<LnnSettingDataEventMonitor> settingDataObserver = std::make_unique<LnnSettingDataEventMonitor>().release();
dataShareHelper->RegisterObserver(*uri, settingDataObserver);
int32_t osAccountId = GetActiveOsAccountIds();
if (osAccountId == SOFTBUS_ERR) {
return;
}
std::string accountIdStr = std::to_string(osAccountId);
uri = std::make_shared<Uri>(SETTINGS_DATA_SECURE_URI + accountIdStr + "?Proxy=true&key=" + USER_DEFINED_STRING);
dataShareHelper->RegisterObserver(*uri, settingDataObserver);
dataShareHelper->Release();
LNN_LOGI(LNN_STATE, "success");
}
}
}
int32_t LnnGetSettingDeviceName(char *deviceName, uint32_t len)
{
if (deviceName == NULL) {
LNN_LOGE(LNN_STATE, "invalid para");
return SOFTBUS_ERR;
}
auto dataShareHelper = OHOS::BusCenter::CreateDataShareHelperInstance();
if (dataShareHelper == nullptr) {
LNN_LOGE(LNN_STATE, "CreateDataShareHelperInstance fail.");
return SOFTBUS_NO_INIT;
}
int32_t ret = OHOS::BusCenter::GetUserDefinedDeviceName(dataShareHelper, deviceName, len);
if (ret == SOFTBUS_NO_INIT) {
LNN_LOGI(LNN_STATE, "account not ready, try again");
dataShareHelper->Release();
return ret;
}
if (ret == SOFTBUS_OK) {
char *anonyDeviceName = NULL;
Anonymize(deviceName, &anonyDeviceName);
LNN_LOGI(LNN_STATE, "get user defined deviceName=%{public}s", AnonymizeWrapper(anonyDeviceName));
AnonymizeFree(anonyDeviceName);
dataShareHelper->Release();
return SOFTBUS_OK;
}
ret = OHOS::BusCenter::GetDefaultDeviceName(dataShareHelper, deviceName, len);
char *anonyDeviceName = NULL;
Anonymize(deviceName, &anonyDeviceName);
LNN_LOGI(LNN_STATE, "get default deviceName=%{public}s, ret=%{public}d", AnonymizeWrapper(anonyDeviceName), ret);
AnonymizeFree(anonyDeviceName);
dataShareHelper->Release();
return ret;
}
int32_t LnnInitGetDeviceName(LnnDeviceNameHandler handler)
{
if (handler == NULL) {
LNN_LOGE(LNN_INIT, "handler is null");
return SOFTBUS_ERR;
}
g_eventHandler = handler;
return SOFTBUS_OK;
}
int32_t LnnInitDeviceNameMonitorImpl(void)
{
UpdateDeviceName(NULL);
return SOFTBUS_OK;
}
void RegisterNameMonitor(void)
{
OHOS::BusCenter::RegisterNameMonitorHelper();
}
static constexpr const char *INTERNAL_NAME_CONCAT_STRING = "";
static constexpr const char *EXTERNAL_NAME_CONCAT_STRING = "-";
int32_t LnnGetUnifiedDeviceName(char *unifiedName, uint32_t len)
{
@ -246,11 +52,39 @@ int32_t LnnGetSettingNickName(const char *defaultName, const char *unifiedName,
return SOFTBUS_NOT_IMPLEMENT;
}
static bool IsZHLanguage()
{
std::string language = OHOS::Global::I18n::LocaleConfig::GetSystemLanguage();
return "zh-Hans" == language || "zh-Hant" == language;
}
int32_t LnnGetDeviceDisplayName(const char *nickName, const char *defaultName, char *deviceName, uint32_t len)
{
(void)nickName;
(void)defaultName;
(void)deviceName;
(void)len;
return SOFTBUS_NOT_IMPLEMENT;
if (nickName == nullptr || defaultName == nullptr || deviceName == nullptr) {
LNN_LOGE(LNN_STATE, "param is invalid.");
return SOFTBUS_INVALID_PARAM;
}
char devName[DEVICE_NAME_BUF_LEN] = {0};
if (IsZHLanguage()) {
if (sprintf_s(devName, DEVICE_NAME_BUF_LEN, "%s%s%s", nickName,
INTERNAL_NAME_CONCAT_STRING, defaultName) < 0) {
LNN_LOGE(LNN_STATE, "sprintf_s devName fail.");
return SOFTBUS_SPRINTF_ERR;
}
} else {
if (sprintf_s(devName, DEVICE_NAME_BUF_LEN, "%s%s%s", nickName,
EXTERNAL_NAME_CONCAT_STRING, defaultName) < 0) {
LNN_LOGE(LNN_STATE, "sprintf_s devName fail.");
return SOFTBUS_SPRINTF_ERR;
}
}
if (strcpy_s(deviceName, len, devName) != EOK) {
LNN_LOGE(LNN_STATE, "strcpy_s devName fail.");
return SOFTBUS_STRCPY_ERR;
}
char *anonyDeviceName = NULL;
Anonymize(deviceName, &anonyDeviceName);
LNN_LOGD(LNN_STATE, "deviceName=%{public}s.", AnonymizeWrapper(anonyDeviceName));
AnonymizeFree(anonyDeviceName);
return SOFTBUS_OK;
}

View File

@ -16,28 +16,6 @@
#include "softbus_errcode.h"
int32_t LnnGetSettingDeviceName(char *deviceName, uint32_t len)
{
(void)deviceName;
(void)len;
return SOFTBUS_ERR;
}
int32_t LnnInitGetDeviceName(LnnDeviceNameHandler handler)
{
(void)handler;
return SOFTBUS_OK;
}
int32_t LnnInitDeviceNameMonitorImpl(void)
{
return SOFTBUS_OK;
}
void RegisterNameMonitor(void)
{
}
int32_t LnnGetUnifiedDisplayDeviceName(char *unifiedDisplayName, uint32_t len)
{
(void)unifiedDisplayName;

View File

@ -96,6 +96,7 @@ if (defined(ohos_lite)) {
"ability_runtime:dataobs_manager",
"data_share:datashare_common",
"data_share:datashare_consumer",
"i18n:intl_util",
"relational_store:native_dataability",
"relational_store:native_rdb",
]

View File

@ -2102,7 +2102,8 @@ int32_t UnpackDeviceInfoMessage(const DevInfoData *devInfo, NodeInfo *nodeInfo,
if (LnnGetLocalNumInfo(NUM_KEY_STATE_VERSION, &stateVersion) == SOFTBUS_OK) {
nodeInfo->localStateVersion = stateVersion;
}
if (IsFeatureSupport(nodeInfo->feature, BIT_SUPPORT_UNIFORM_NAME_CAPABILITY)) {
if (IsFeatureSupport(nodeInfo->feature, BIT_SUPPORT_UNIFORM_NAME_CAPABILITY) &&
nodeInfo->deviceInfo.osType != OH_OS_TYPE) {
UpdatePeerDeviceName(nodeInfo);
}
nodeInfo->updateTimestamp = SoftBusGetSysTimeMs();

View File

@ -64,6 +64,7 @@ int32_t LnnIpcNotifyTimeSyncResult(
int32_t LnnIpcShiftLNNGear(const char *pkgName, const char *callerId, const char *targetNetworkId,
const GearMode *mode);
int32_t LnnIpcSyncTrustedRelationShip(const char *pkgName, const char *msg, uint32_t msgLen);
int32_t LnnIpcSetLocalDeviceName(const char *pkgName, const char *displayName);
void BusCenterServerDeathCallback(const char *pkgName);

View File

@ -233,3 +233,11 @@ void BusCenterServerDeathCallback(const char *pkgName)
{
(void)pkgName;
}
int32_t LnnIpcSetLocalDeviceName(const char *pkgName, const char *displayName)
{
(void)pkgName;
(void)displayName;
LNN_LOGI(LNN_EVENT, "not implement");
return SOFTBUS_OK;
}

View File

@ -489,3 +489,11 @@ void BusCenterServerDeathCallback(const char *pkgName)
{
(void)pkgName;
}
int32_t LnnIpcSetLocalDeviceName(const char *pkgName, const char *displayName)
{
(void)pkgName;
(void)displayName;
LNN_LOGI(LNN_EVENT, "not implement");
return SOFTBUS_OK;
}

View File

@ -23,6 +23,7 @@
#include "bus_center_client_proxy.h"
#include "bus_center_manager.h"
#include "lnn_connection_addr_utils.h"
#include "lnn_devicename_info.h"
#include "lnn_distributed_net_ledger.h"
#include "lnn_fast_offline.h"
#include "lnn_heartbeat_ctrl.h"
@ -436,6 +437,11 @@ int32_t LnnIpcSyncTrustedRelationShip(const char *pkgName, const char *msg, uint
return LnnSyncTrustedRelationShip(pkgName, msg, msgLen);
}
int32_t LnnIpcSetLocalDeviceName(const char *pkgName, const char *displayName)
{
return LnnSetLocalDeviceName(pkgName, displayName);
}
int32_t LnnIpcNotifyJoinResult(void *addr, uint32_t addrTypeLen, const char *networkId,
int32_t retCode)
{

View File

@ -23,7 +23,7 @@
extern "C" {
#endif
void UpdateDeviceName(void *p);
int32_t LnnSetLocalDeviceName(const char *pkgName, const char *displayName);
int32_t LnnInitDevicename(void);
void LnnDeinitDevicename(void);

View File

@ -42,15 +42,9 @@
#include "softbus_adapter_json.h"
#include "message_handler.h"
#define DELAY_LEN 1000
#define MAX_TRY 10
#define KEY_NICK_NAME "KEY_NICK_NAME"
#define KEY_ACCOUNT "KEY_ACCOUNT"
static int32_t g_tryGetDevnameNums = 0;
static bool g_needSubscribeAccount = false;
static void UpdataLocalFromSetting(void *p);
static int32_t LnnSyncDeviceName(const char *networkId)
{
const char *deviceName = NULL;
@ -72,40 +66,6 @@ static int32_t LnnSyncDeviceName(const char *networkId)
return SOFTBUS_OK;
}
static int32_t LnnSyncDeviceNickName(const char *networkId)
{
int64_t accountId = 0;
const NodeInfo *info = LnnGetLocalNodeInfo();
if (info == NULL) {
LNN_LOGE(LNN_BUILDER, "get local nodeInfo fail");
return SOFTBUS_ERR;
}
(void)GetCurrentAccount(&accountId);
JsonObj *json = JSON_CreateObject();
if (json == NULL) {
return SOFTBUS_ERR;
}
if (!JSON_AddStringToObject(json, KEY_NICK_NAME, info->deviceInfo.nickName) ||
!JSON_AddInt64ToObject(json, KEY_ACCOUNT, accountId)) {
LNN_LOGE(LNN_BUILDER, "sync device name fail");
JSON_Delete(json);
return SOFTBUS_ERR;
}
char *msg = JSON_PrintUnformatted(json);
JSON_Delete(json);
if (msg == NULL) {
return SOFTBUS_ERR;
}
if (LnnSendSyncInfoMsg(LNN_INFO_TYPE_NICK_NAME, networkId, (const uint8_t *)msg,
strlen(msg) + 1, NULL) != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "send sync nickName fail");
JSON_Free(msg);
return SOFTBUS_ERR;
}
JSON_Free(msg);
return SOFTBUS_OK;
}
static void OnReceiveDeviceName(LnnSyncInfoType type, const char *networkId, const uint8_t *msg, uint32_t len)
{
char udid[UDID_BUF_LEN];
@ -264,28 +224,32 @@ static void OnReceiveDeviceNickName(LnnSyncInfoType type, const char *networkId,
NickNameMsgProc(networkId, accountId, nickName);
}
static void HandlerGetDeviceName(const char *deviceName)
int32_t LnnSetLocalDeviceName(const char *pkgName, const char *displayName)
{
int32_t infoNum = 0;
NodeBasicInfo *info = NULL;
char name[DEVICE_NAME_BUF_LEN] = {0};
if (LnnGetSettingDeviceName(name, DEVICE_NAME_BUF_LEN) != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "set device name fail");
return;
(void)pkgName;
if (displayName == NULL) {
LNN_LOGE(LNN_BUILDER, "invalid param");
return SOFTBUS_INVALID_PARAM;
}
if (LnnSetLocalStrInfo(STRING_KEY_DEV_NAME, name) != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "set device name fail");
char localDevName[DEVICE_NAME_BUF_LEN] = {0};
if (LnnGetLocalStrInfo(STRING_KEY_DEV_NAME, localDevName, sizeof(localDevName)) != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "get local devcice name failed");
return SOFTBUS_NETWORK_GET_NODE_INFO_ERR;
}
char unifiedName[DEVICE_NAME_BUF_LEN] = {0};
if (LnnGetUnifiedDeviceName(unifiedName, DEVICE_NAME_BUF_LEN) == SOFTBUS_OK) {
if (LnnSetLocalUnifiedName(unifiedName) != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "set device unifiedName fail");
}
if (strcmp(localDevName, displayName) == 0) {
LNN_LOGI(LNN_BUILDER, "device name not change, ignore this msg");
return SOFTBUS_OK;
}
if (LnnSetLocalStrInfo(STRING_KEY_DEV_NAME, displayName) != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "set local devcice name failed");
return SOFTBUS_NETWORK_SET_NODE_INFO_ERR;
}
DiscDeviceInfoChanged(TYPE_LOCAL_DEVICE_NAME);
int32_t infoNum = 0;
NodeBasicInfo *info = NULL;
if (LnnGetAllOnlineNodeInfo(&info, &infoNum) != SOFTBUS_OK) {
LNN_LOGI(LNN_BUILDER, "get online node fail");
return;
return SOFTBUS_NETWORK_GET_ALL_NODE_INFO_ERR;
}
for (int32_t i = 0; i < infoNum; i++) {
if (LnnIsLSANode(&info[i])) {
@ -296,222 +260,8 @@ static void HandlerGetDeviceName(const char *deviceName)
}
}
SoftBusFree(info);
}
static bool IsDeviceNeedSyncNickName(const char *networkId)
{
NodeInfo nodeInfo;
(void)memset_s(&nodeInfo, sizeof(NodeInfo), 0, sizeof(NodeInfo));
if (LnnGetRemoteNodeInfoById(networkId, CATEGORY_NETWORK_ID, &nodeInfo) != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "get node info fail");
return false;
}
return IsFeatureSupport(nodeInfo.feature, BIT_SUPPORT_UNIFORM_NAME_CAPABILITY);
}
static void NotifyNickNameChange(void)
{
NodeBasicInfo *info = NULL;
int32_t infoNum = 0;
if (LnnGetAllOnlineNodeInfo(&info, &infoNum) != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "get online node fail");
return;
}
for (int32_t i = 0; i < infoNum; i++) {
if (!IsDeviceNeedSyncNickName(info[i].networkId)) {
continue;
}
if (LnnSyncDeviceNickName(info[i].networkId) != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "LnnSyncDeviceNickName fail");
}
}
SoftBusFree(info);
}
static void HandlerGetDeviceNickName(const char *displayName)
{
(void)displayName;
char nickName[DEVICE_NAME_BUF_LEN] = {0};
NodeInfo *localNodeInfo = (NodeInfo *)LnnGetLocalNodeInfo();
if (localNodeInfo == NULL) {
LNN_LOGE(LNN_BUILDER, "local devinfo nullptr");
return;
}
char unifiedName[DEVICE_NAME_BUF_LEN] = {0};
if (LnnGetUnifiedDeviceName(unifiedName, DEVICE_NAME_BUF_LEN) != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "get device unified name fail");
return;
}
if (strlen(localNodeInfo->deviceInfo.unifiedName) != 0) {
if (LnnSetLocalUnifiedName(unifiedName) != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "set device unifiedName fail");
}
}
char unifiedDefault[DEVICE_NAME_BUF_LEN] = {0};
if (LnnGetUnifiedDefaultDeviceName(unifiedDefault, DEVICE_NAME_BUF_LEN) != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "get defaultDeviceName fail");
return;
}
if (strlen(unifiedDefault) != 0) {
if (LnnSetLocalStrInfo(STRING_KEY_DEV_UNIFIED_DEFAULT_NAME, unifiedDefault) != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "set device unifiedDefaultName fail");
}
}
if (LnnGetSettingNickName(unifiedDefault, unifiedName,
nickName, DEVICE_NAME_BUF_LEN) != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "get nickName fail");
return;
}
if (strlen(nickName) == 0) {
if (strcpy_s(localNodeInfo->deviceInfo.nickName, DEVICE_NAME_BUF_LEN, "") != EOK) {
LNN_LOGE(LNN_BUILDER, "strcpy fail");
}
} else {
if (LnnSetLocalStrInfo(STRING_KEY_DEV_NICK_NAME, nickName) != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "set device nickName fail");
}
}
NotifyNickNameChange();
}
static void LnnHandlerGetDeviceName(DeviceNameType type, const char *name)
{
if (type == DEVICE_NAME_TYPE_DEV_NAME) {
HandlerGetDeviceName(name);
} else if (type == DEVICE_NAME_TYPE_NICK_NAME) {
HandlerGetDeviceNickName(name);
} else {
LNN_LOGW(LNN_BUILDER, "invalid type=%{public}d", type);
}
LnnNotifyLocalNetworkIdChanged();
}
static void UpdateLocalExtendDeviceName(const char *deviceName, char *unifiedName, char *unifiedDefaultName,
char *nickName)
{
if (LnnGetUnifiedDeviceName(unifiedName, DEVICE_NAME_BUF_LEN) == SOFTBUS_OK && strlen(unifiedName) != 0) {
if (LnnSetLocalStrInfo(STRING_KEY_DEV_UNIFIED_NAME, unifiedName) != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "UpdateLocalFromSetting set unified name fail");
}
}
if (LnnGetUnifiedDefaultDeviceName(unifiedDefaultName, DEVICE_NAME_BUF_LEN) == SOFTBUS_OK &&
strlen(unifiedDefaultName) != 0) {
if (LnnSetLocalStrInfo(STRING_KEY_DEV_UNIFIED_DEFAULT_NAME, unifiedDefaultName) != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "UpdateLocalFromSetting set default unified name fail");
}
}
if (LnnGetSettingNickName(deviceName, unifiedName, nickName, DEVICE_NAME_BUF_LEN) == SOFTBUS_OK &&
strlen(nickName) != 0) {
if (LnnSetLocalStrInfo(STRING_KEY_DEV_NICK_NAME, nickName) != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "UpdateLocalFromSetting set nick name fail");
}
}
}
static void AccountBootEventHandle(const char *key, const char *value, void *context)
{
(void)context;
LNN_LOGI(LNN_EVENT, "account is ready, key=%{public}s, value=%{public}s", key, value);
if (strcmp(key, BOOTEVENT_ACCOUNT_READY) != 0 || strcmp(value, "true") != 0) {
return;
}
g_tryGetDevnameNums = 0;
g_needSubscribeAccount = false;
int32_t ret = LnnAsyncCallbackDelayHelper(GetLooper(LOOP_TYPE_DEFAULT), UpdataLocalFromSetting, NULL, 0);
if (ret != SOFTBUS_OK) {
LNN_LOGE(LNN_EVENT, "async call boot event fail");
}
}
static void DumpLocalExtendDeviceName(const char *deviceName, const char *unifiedName, const char *unifiedDefaultName,
const char *nickName)
{
char *anonyDeviceName = NULL;
Anonymize(deviceName, &anonyDeviceName);
char *anonyUnifiedName = NULL;
Anonymize(unifiedName, &anonyUnifiedName);
char *anonyUnifiedDefaultName = NULL;
Anonymize(unifiedDefaultName, &anonyUnifiedDefaultName);
char *anonyNickName = NULL;
Anonymize(nickName, &anonyNickName);
LNN_LOGI(LNN_BUILDER, "UpdateLocalFromSetting done, deviceName=%{public}s, unifiedName=%{public}s, "
"unifiedDefaultName=%{public}s, nickName=%{public}s",
AnonymizeWrapper(anonyDeviceName), AnonymizeWrapper(anonyUnifiedName),
AnonymizeWrapper(anonyUnifiedDefaultName), AnonymizeWrapper(anonyNickName));
AnonymizeFree(anonyDeviceName);
AnonymizeFree(anonyUnifiedName);
AnonymizeFree(anonyUnifiedDefaultName);
AnonymizeFree(anonyNickName);
}
static void UpdataLocalFromSetting(void *p)
{
(void)p;
char deviceName[DEVICE_NAME_BUF_LEN] = {0};
char unifiedName[DEVICE_NAME_BUF_LEN] = {0};
char unifiedDefaultName[DEVICE_NAME_BUF_LEN] = {0};
char nickName[DEVICE_NAME_BUF_LEN] = {0};
if (LnnGetSettingDeviceName(deviceName, DEVICE_NAME_BUF_LEN) != SOFTBUS_OK) {
g_tryGetDevnameNums++;
LNN_LOGI(LNN_BUILDER, "g_tryGetDevnameNums=%{public}d, needSubscribe=%{public}d",
g_tryGetDevnameNums, g_needSubscribeAccount);
if (g_tryGetDevnameNums < MAX_TRY) {
SoftBusLooper *looper = GetLooper(LOOP_TYPE_DEFAULT);
if (looper == NULL) {
LNN_LOGE(LNN_BUILDER, "looper is null");
return;
}
int ret = LnnAsyncCallbackDelayHelper(looper, UpdataLocalFromSetting, NULL, DELAY_LEN);
if (ret != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "init UpdataLocalFromSetting fail");
}
return;
}
if (!g_needSubscribeAccount) {
LNN_LOGE(LNN_BUILDER, "update device name fail");
RegisterNameMonitor();
return;
}
LNN_LOGI(LNN_BUILDER, "account or database not ready, retry after account ready");
if (LnnSubscribeAccountBootEvent(AccountBootEventHandle) != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "watch account server fail");
RegisterNameMonitor();
}
return;
}
if (LnnSetLocalStrInfo(STRING_KEY_DEV_NAME, deviceName) != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "UpdataLocalFromSetting set device name fail");
}
UpdateLocalExtendDeviceName(deviceName, unifiedName, unifiedDefaultName, nickName);
RegisterNameMonitor();
DiscDeviceInfoChanged(TYPE_LOCAL_DEVICE_NAME);
LnnNotifyLocalNetworkIdChanged();
DumpLocalExtendDeviceName(deviceName, unifiedName, unifiedDefaultName, nickName);
}
static void RegisterDeviceNameHandle(void)
{
LnnInitGetDeviceName(LnnHandlerGetDeviceName);
}
void UpdateDeviceName(void *p)
{
g_needSubscribeAccount = true;
RegisterDeviceNameHandle();
UpdataLocalFromSetting(p);
}
static void LnnAccountStateChangeHandler(const LnnEventBasicInfo *info)
{
if (info == NULL || info->event != LNN_EVENT_ACCOUNT_CHANGED) {
LNN_LOGE(LNN_BUILDER, "invalid param");
return;
}
const LnnMonitorHbStateChangedEvent *event = (const LnnMonitorHbStateChangedEvent *)info;
SoftBusAccountState accountState = (SoftBusAccountState)event->status;
LNN_LOGD(LNN_BUILDER, "account state=%{public}d", accountState);
HandlerGetDeviceNickName(NULL);
return;
return SOFTBUS_OK;
}
int32_t LnnInitDevicename(void)
@ -520,16 +270,11 @@ int32_t LnnInitDevicename(void)
if (ret != SOFTBUS_OK) {
return ret;
}
if (LnnRegisterEventHandler(LNN_EVENT_ACCOUNT_CHANGED, LnnAccountStateChangeHandler) != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "regist account change evt handler fail");
return SOFTBUS_ERR;
}
return LnnRegSyncInfoHandler(LNN_INFO_TYPE_NICK_NAME, OnReceiveDeviceNickName);
}
void LnnDeinitDevicename(void)
{
(void)LnnUnregSyncInfoHandler(LNN_INFO_TYPE_DEVICE_NAME, OnReceiveDeviceName);
LnnUnregisterEventHandler(LNN_EVENT_ACCOUNT_CHANGED, LnnAccountStateChangeHandler);
(void)LnnUnregSyncInfoHandler(LNN_INFO_TYPE_NICK_NAME, OnReceiveDeviceNickName);
}

View File

@ -221,10 +221,6 @@ int32_t LnnInitEventMoniterDelay(void)
LNN_LOGE(LNN_LEDGER, "delay init LnnInitCommonEventMonitorImpl fail");
return SOFTBUS_ERR;
}
if (LnnInitDeviceNameMonitorImpl() != SOFTBUS_OK) {
LNN_LOGE(LNN_LEDGER, "delay init LnnInitDeviceNameMonitorImpl fail");
return SOFTBUS_ERR;
}
LnnInitOOBEStateMonitorImpl();
return SOFTBUS_OK;
}

View File

@ -118,6 +118,7 @@ static ApiNameIdMap g_apiNameIdMapTbl[] = {
{SERVER_SYNC_TRUSTED_RELATION, "SyncTrustedRelationShip"},
{SERVER_RIPPLE_STATS, "RippleStats"},
{SERVER_CTRL_LNN_BLE_HB, "CtrlLNNBleHb"},
{SERVER_SET_DEV_NAME, "SetLocalDeviceName"},
};
typedef struct {

View File

@ -83,6 +83,7 @@ enum SoftBusFuncId {
SERVER_UNREG_DATA_LEVEL_CHANGE_CB,
SERVER_SET_DATA_LEVEL,
SERVER_CTRL_LNN_BLE_HB,
SERVER_SET_DEV_NAME,
CLIENT_ON_CHANNEL_OPENED = 256,
CLIENT_ON_CHANNEL_OPENFAILED,

View File

@ -74,6 +74,7 @@ public:
virtual int32_t GetBusCenterExObj(sptr<IRemoteObject> &object);
virtual int32_t EvaluateQos(const char *peerNetworkId, TransDataType dataType, const QosTV *qos,
uint32_t qosCount) = 0;
virtual int32_t SetLocalDeviceName(const char *pkgName, const char *displayName);
public:
DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.ISoftBusServer");

View File

@ -73,6 +73,7 @@ public:
int32_t GetBusCenterExObj(sptr<IRemoteObject> &object) override;
int32_t EvaluateQos(const char *peerNetworkId, TransDataType dataType, const QosTV *qos,
uint32_t qosCount) override;
int32_t SetLocalDeviceName(const char *pkgName, const char *displayName) override;
protected:
void OnStart() override;

View File

@ -73,6 +73,7 @@ private:
int32_t SyncTrustedRelationShipInner(MessageParcel &data, MessageParcel &reply);
int32_t GetSoftbusSpecObjectInner(MessageParcel &data, MessageParcel &reply);
int32_t GetBusCenterExObjInner(MessageParcel &data, MessageParcel &reply);
int32_t SetDeviceNameInner(MessageParcel &data, MessageParcel &reply);
void InitMemberFuncMap();
void InitMemberPermissionMap();

View File

@ -121,4 +121,12 @@ int32_t ISoftBusServer::GetBusCenterExObj(sptr<IRemoteObject> &object)
COMM_LOGE(COMM_SVC, "GetBusCenterExObj ipc default impl");
return SOFTBUS_IPC_ERR;
}
int32_t ISoftBusServer::SetLocalDeviceName(const char *pkgName, const char *displayName)
{
(void)pkgName;
(void)displayName;
COMM_LOGE(COMM_SVC, "ipc default impl");
return SOFTBUS_IPC_ERR;
}
} // namespace OHOS

View File

@ -427,4 +427,9 @@ int32_t SoftBusServer::EvaluateQos(const char *peerNetworkId, TransDataType data
ConvertQosInfo(qos, qosCount, &qosInfo);
return LnnQueryLaneResource(&info, &qosInfo);
}
int32_t SoftBusServer::SetLocalDeviceName(const char *pkgName, const char *displayName)
{
return LnnIpcSetLocalDeviceName(pkgName, displayName);
}
} // namespace OHOS

View File

@ -56,6 +56,7 @@ namespace OHOS {
constexpr int32_t MSG_MAX_SIZE = 1024 * 2;
static const char *DB_PACKAGE_NAME = "distributeddata-default";
static const char *DM_PACKAGE_NAME = "ohos.distributedhardware.devicemanager";
constexpr int32_t DEVICE_NAME_SIZE_MAX = 128;
}
@ -176,6 +177,7 @@ void SoftBusServerStub::InitMemberFuncMap()
memberFuncMap_[SERVER_RIPPLE_STATS] = &SoftBusServerStub::RippleStatsInner;
memberFuncMap_[SERVER_GET_SOFTBUS_SPEC_OBJECT] = &SoftBusServerStub::GetSoftbusSpecObjectInner;
memberFuncMap_[SERVER_GET_BUS_CENTER_EX_OBJ] = &SoftBusServerStub::GetBusCenterExObjInner;
memberFuncMap_[SERVER_SET_DEV_NAME] = &SoftBusServerStub::SetDeviceNameInner;
}
void SoftBusServerStub::InitMemberPermissionMap()
@ -220,6 +222,7 @@ void SoftBusServerStub::InitMemberPermissionMap()
memberPermissionMap_[SERVER_GET_SOFTBUS_SPEC_OBJECT] = OHOS_PERMISSION_DISTRIBUTED_DATASYNC;
memberPermissionMap_[SERVER_GET_BUS_CENTER_EX_OBJ] = OHOS_PERMISSION_DISTRIBUTED_SOFTBUS_CENTER;
memberPermissionMap_[SERVER_EVALUATE_QOS] = OHOS_PERMISSION_DISTRIBUTED_DATASYNC;
memberPermissionMap_[SERVER_SET_DEV_NAME] = OHOS_PERMISSION_DISTRIBUTED_SOFTBUS_CENTER;
}
int32_t SoftBusServerStub::OnRemoteRequest(
@ -1644,4 +1647,30 @@ int32_t SoftBusServerStub::GetBusCenterExObjInner(MessageParcel &data, MessagePa
}
return SOFTBUS_OK;
}
int32_t SoftBusServerStub::SetDeviceNameInner(MessageParcel &data, MessageParcel &reply)
{
COMM_LOGD(COMM_SVC, "enter");
const char *pkgName = data.ReadCString();
if (pkgName == nullptr || strnlen(pkgName, PKG_NAME_SIZE_MAX) >= PKG_NAME_SIZE_MAX) {
COMM_LOGE(COMM_SVC, "read pkgName failed!");
return SOFTBUS_TRANS_PROXY_READCSTRING_FAILED;
}
if (strcmp(DM_PACKAGE_NAME, pkgName) != 0) {
COMM_LOGE(COMM_SVC, "read pkgName invalid!");
return SOFTBUS_INVALID_PARAM;
}
SoftbusRecordCalledApiInfo(pkgName, SERVER_SET_DEV_NAME);
const char *displayName = data.ReadCString();
if (displayName == nullptr || strnlen(displayName, DEVICE_NAME_SIZE_MAX) >= DEVICE_NAME_SIZE_MAX) {
COMM_LOGE(COMM_SVC, "read displayName failed!");
return SOFTBUS_TRANS_PROXY_READCSTRING_FAILED;
}
int32_t retReply = SetLocalDeviceName(pkgName, displayName);
if (!reply.WriteInt32(retReply)) {
COMM_LOGE(COMM_SVC, "write reply failed");
return SOFTBUS_TRANS_PROXY_WRITEINT_FAILED;
}
return SOFTBUS_OK;
}
} // namespace OHOS

View File

@ -933,6 +933,21 @@ int32_t ShiftLNNGear(const char *pkgName, const char *callerId, const char *targ
* @version 1.0
*/
int32_t SyncTrustedRelationShip(const char *pkgName, const char *msg, uint32_t msgLen);
/**
* @brief For dm use only. Set local device display name.
*
* @param pkgName Indicates the pointer to the caller ID, for example, the package name.
* For the same caller, the value of this parameter must be the same for all functions.
* @param displayName Indicates the pointer to the local device display name.
*
* @return Returns <b>0</b> if the call is success; returns any other value if it fails.
*
* @since 1.0
* @version 1.0
*/
int32_t SetLocalDeviceName(const char *pkgName, const char *displayName);
#ifdef __cplusplus
}
#endif

View File

@ -52,6 +52,7 @@ int32_t ServerIpcGetAllMetaNodeInfo(const char *pkgName, MetaNodeInfo *infos, in
int32_t ServerIpcShiftLNNGear(const char *pkgName, const char *callerId, const char *targetNetworkId,
const GearMode *mode);
int32_t ServerIpcSyncTrustedRelationShip(const char *pkgName, const char *msg, uint32_t msgLen);
int32_t ServerIpcSetLocalDeviceName(const char *pkgName, const char *displayName);
#ifdef __cplusplus
#if __cplusplus

View File

@ -142,4 +142,11 @@ int32_t ServerIpcSyncTrustedRelationShip(const char *pkgName, const char *msg, u
(void)msg;
(void)msgLen;
return SOFTBUS_FUNC_NOT_SUPPORT;
}
int32_t ServerIpcSetLocalDeviceName(const char *pkgName, const char *displayName)
{
(void)pkgName;
(void)displayName;
return SOFTBUS_FUNC_NOT_SUPPORT;
}

View File

@ -773,4 +773,11 @@ int32_t ServerIpcSyncTrustedRelationShip(const char *pkgName, const char *msg, u
(void)msg;
(void)msgLen;
return SOFTBUS_FUNC_NOT_SUPPORT;
}
int32_t ServerIpcSetLocalDeviceName(const char *pkgName, const char *displayName)
{
(void)pkgName;
(void)displayName;
return SOFTBUS_FUNC_NOT_SUPPORT;
}

View File

@ -69,6 +69,7 @@ public:
int32_t GetBusCenterExObj(sptr<IRemoteObject> &object) override;
int32_t EvaluateQos(const char *peerNetworkId, TransDataType dataType, const QosTV *qos,
uint32_t qosCount) override;
int32_t SetLocalDeviceName(const char *pkgName, const char *displayName) override;
int32_t BusCenterServerProxyStandardInit(void);
void BusCenterServerProxyStandardDeInit(void);

View File

@ -317,4 +317,18 @@ int32_t ServerIpcSyncTrustedRelationShip(const char *pkgName, const char *msg, u
LNN_LOGE(LNN_EVENT, "SyncTrustedRelationShip failed");
}
return ret;
}
int32_t ServerIpcSetLocalDeviceName(const char *pkgName, const char *displayName)
{
LNN_LOGI(LNN_EVENT, "enter");
if (g_serverProxy == nullptr && BusCenterServerProxyInit() != SOFTBUS_OK) {
LNN_LOGE(LNN_EVENT, "g_serverProxy is nullptr");
return SOFTBUS_SERVER_NOT_INIT;
}
int32_t ret = g_serverProxy->SetLocalDeviceName(pkgName, displayName);
if (ret != SOFTBUS_OK) {
LNN_LOGE(LNN_EVENT, "SetLocalDeviceName failed, ret=%{public}d", ret);
}
return ret;
}

View File

@ -1104,4 +1104,44 @@ int32_t BusCenterServerProxy::EvaluateQos(const char *peerNetworkId, TransDataTy
(void)qosCount;
return SOFTBUS_OK;
}
int32_t BusCenterServerProxy::SetLocalDeviceName(const char *pkgName, const char *displayName)
{
if (pkgName == nullptr || displayName == nullptr) {
LNN_LOGE(LNN_EVENT, "params are nullptr");
return SOFTBUS_INVALID_PARAM;
}
sptr<IRemoteObject> remote = GetSystemAbility();
if (remote == nullptr) {
LNN_LOGE(LNN_EVENT, "remote is nullptr");
return SOFTBUS_TRANS_PROXY_REMOTE_NULL;
}
MessageParcel data;
if (!data.WriteInterfaceToken(GetDescriptor())) {
LNN_LOGE(LNN_EVENT, "write InterfaceToken failed");
return SOFTBUS_TRANS_PROXY_WRITEINT_FAILED;
}
if (!data.WriteCString(pkgName)) {
LNN_LOGE(LNN_EVENT, "write pkg name failed");
return SOFTBUS_TRANS_PROXY_WRITEINT_FAILED;
}
if (!data.WriteCString(displayName)) {
LNN_LOGE(LNN_EVENT, "write displayName failed");
return SOFTBUS_TRANS_PROXY_WRITEINT_FAILED;
}
MessageParcel reply;
MessageOption option;
int32_t ret = remote->SendRequest(SERVER_SET_DEV_NAME, data, reply, option);
if (ret != SOFTBUS_OK) {
LNN_LOGE(LNN_EVENT, "send request failed, ret=%{public}d", ret);
return SOFTBUS_IPC_ERR;
}
int32_t serverRet = 0;
if (!reply.ReadInt32(serverRet)) {
LNN_LOGE(LNN_EVENT, "read serverRet failed");
return SOFTBUS_TRANS_PROXY_READINT_FAILED;
}
return serverRet;
}
} // namespace OHOS

View File

@ -54,6 +54,7 @@ int32_t GetAllMetaNodeInfoInner(const char *pkgName, MetaNodeInfo *infos, int32_
int32_t ShiftLNNGearInner(const char *pkgName, const char *callerId, const char *targetNetworkId,
const GearMode *mode);
int32_t SyncTrustedRelationShipInner(const char *pkgName, const char *msg, uint32_t msgLen);
int32_t SetLocalDeviceNameInner(const char *pkgName, const char *displayName);
int32_t LnnOnJoinResult(void *addr, const char *networkId, int32_t retCode);
int32_t LnnOnLeaveResult(const char *networkId, int32_t retCode);

View File

@ -1036,6 +1036,11 @@ int32_t SyncTrustedRelationShipInner(const char *pkgName, const char *msg, uint3
return ServerIpcSyncTrustedRelationShip(pkgName, msg, msgLen);
}
int32_t SetLocalDeviceNameInner(const char *pkgName, const char *displayName)
{
return ServerIpcSetLocalDeviceName(pkgName, displayName);
}
NO_SANITIZE("cfi") int32_t LnnOnJoinResult(void *addr, const char *networkId, int32_t retCode)
{
JoinLNNCbListItem *item = NULL;

View File

@ -577,4 +577,18 @@ int32_t SyncTrustedRelationShip(const char *pkgName, const char *msg, uint32_t m
return ret;
}
return SyncTrustedRelationShipInner(pkgName, msg, msgLen);
}
int32_t SetLocalDeviceName(const char *pkgName, const char *displayName)
{
if (!IsValidString(pkgName, PKG_NAME_SIZE_MAX - 1) || !IsValidString(displayName, DEVICE_NAME_BUF_LEN - 1)) {
LNN_LOGE(LNN_STATE, "invalid SetLocalDeviceName para");
return SOFTBUS_INVALID_PARAM;
}
int32_t ret = CommonInit(pkgName);
if (ret != SOFTBUS_OK) {
LNN_LOGE(LNN_STATE, "common init fail, ret=%{public}d", ret);
return ret;
}
return SetLocalDeviceNameInner(pkgName, displayName);
}

View File

@ -26,6 +26,7 @@
"SetFileSendListener";
"ShiftLNNGear";
"SyncTrustedRelationShip";
"SetLocalDeviceName";
"GetNodeKeyInfo";
"GetSessionKey";
"SendFile";

View File

@ -85,6 +85,9 @@ ohos_unittest("LnnKSettingDataEventMonitorTest") {
"kv_store:distributeddata_inner",
"samgr:samgr_proxy",
]
if (is_standard_system) {
external_deps += [ "i18n:intl_util" ]
}
}
ohos_unittest("AdapterDsoftbusRsaCryptoTest") {

View File

@ -51,10 +51,5 @@ int32_t GetActiveOsAccountIds(void)
{
return GetSettingDataEventMonitorDepsInterface()->GetActiveOsAccountIds();
}
void UpdateDeviceName(void *p)
{
return GetSettingDataEventMonitorDepsInterface()->UpdateDeviceName(p);
}
}
} // namespace OHOS

View File

@ -32,7 +32,6 @@ public:
virtual SoftBusLooper *GetLooper(int32_t looper) = 0;
virtual int32_t LnnAsyncCallbackHelper(SoftBusLooper *looper, LnnAsyncCallbackFunc callback, void *para) = 0;
virtual int32_t GetActiveOsAccountIds(void) = 0;
virtual void UpdateDeviceName(void *p) = 0;
};
class SettingDataEventMonitorDepsInterfaceMock : public SettingDataEventMonitorDepsInterface {
@ -43,7 +42,6 @@ public:
MOCK_METHOD1(GetLooper, SoftBusLooper * (int));
MOCK_METHOD3(LnnAsyncCallbackHelper, int32_t (SoftBusLooper *, LnnAsyncCallbackFunc, void *));
MOCK_METHOD0(GetActiveOsAccountIds, int32_t (void));
MOCK_METHOD1(UpdateDeviceName, void (void *));
};
} // namespace OHOS
#endif // LNN_SETTINGDATA_EVENT_MONITOR_DEPS_MOCK_H

View File

@ -39,8 +39,6 @@ using namespace std;
using namespace testing;
using namespace testing::ext;
namespace OHOS {
constexpr char *DEVICE_NAME1 = nullptr;
const char *DEVICE_NAME2 = "ABCDEFG";
const char *NICK_NAME = "TEST_NICK_NAME";
const char *DEFAULT_NAME = "TEST_DEFAULT_NAME";
@ -64,31 +62,6 @@ void LnnSettingdataEventMonitorTest::TearDown(void)
{
}
/*
* @tc.name: LnnGetSettingDeviceNameTest001
* @tc.desc:
* @tc.type: FUNC
* @tc.require: 1
*/
HWTEST_F(LnnSettingdataEventMonitorTest, LnnGetSettingDeviceNameTest001, TestSize.Level1)
{
int32_t ret = LnnGetSettingDeviceName(DEVICE_NAME1, DEVICE_NAME_BUF_LEN);
EXPECT_NE(ret, SOFTBUS_OK);
}
/*
* @tc.name: LnnGetSettingDeviceNameTest002
* @tc.desc:
* @tc.type: FUNC
* @tc.require: 1
*/
HWTEST_F(LnnSettingdataEventMonitorTest, LnnGetSettingDeviceNameTest002, TestSize.Level1)
{
LnnDeviceNameHandler handler = NULL;
int32_t ret = LnnInitGetDeviceName(handler);
EXPECT_NE(ret, SOFTBUS_OK);
}
/*
* @tc.name: LnnGetSettingDeviceNameTest003
* @tc.desc:
@ -102,32 +75,4 @@ HWTEST_F(LnnSettingdataEventMonitorTest, LnnGetSettingDeviceNameTest003, TestSiz
int32_t ret = LnnGetDeviceDisplayName(NICK_NAME, DEFAULT_NAME, deviceName, DEVICE_NAME_BUF_LEN);
EXPECT_EQ(ret, SOFTBUS_NOT_IMPLEMENT);
}
/*
* @tc.name: LnnGetSettingDeviceNameTest004
* @tc.desc:
* @tc.type: FUNC
* @tc.require: 1
*/
HWTEST_F(LnnSettingdataEventMonitorTest, LnnGetSettingDeviceNameTest004, TestSize.Level1)
{
NiceMock<SettingDataEventMonitorDepsInterfaceMock> SettingDataEventMonitorMock;
int32_t ret = LnnInitDeviceNameMonitorImpl();
EXPECT_EQ(ret, SOFTBUS_OK);
}
/*
* @tc.name: LnnGetSettingDeviceNameTest005
* @tc.desc:
* @tc.type: FUNC
* @tc.require: 1
*/
HWTEST_F(LnnSettingdataEventMonitorTest, LnnGetSettingDeviceNameTest005, TestSize.Level1)
{
NiceMock<SettingDataEventMonitorDepsInterfaceMock> SettingDataEventMonitorMock;
SoftBusLooper loop;
EXPECT_CALL(SettingDataEventMonitorMock, GetLooper(_)).WillRepeatedly(Return(&loop));
int32_t ret = LnnInitDeviceNameMonitorImpl();
EXPECT_EQ(ret, SOFTBUS_OK);
}
}

View File

@ -61,7 +61,6 @@ class NetBuilderDepsInterface {
public:
NetBuilderDepsInterface() {};
virtual ~NetBuilderDepsInterface() {};
virtual int32_t LnnGetSettingDeviceName(char *deviceName, uint32_t len) = 0;
virtual int32_t AuthGetDeviceUuid(int64_t authId, char *uuid, uint16_t size) = 0;
virtual int32_t LnnDeleteMetaInfo(const char *udid, AuthLinkType type) = 0;
virtual int32_t TransGetConnByChanId(int32_t channelId, int32_t channelType, int32_t* connId) = 0;
@ -207,7 +206,6 @@ class NetBuilderDepsInterfaceMock : public NetBuilderDepsInterface {
public:
NetBuilderDepsInterfaceMock();
~NetBuilderDepsInterfaceMock() override;
MOCK_METHOD2(LnnGetSettingDeviceName, int32_t (char *, uint32_t));
MOCK_METHOD3(AuthGetDeviceUuid, int32_t (int64_t, char*, uint16_t));
MOCK_METHOD2(LnnDeleteMetaInfo, int32_t (const char *, AuthLinkType));
MOCK_METHOD3(TransGetConnByChanId, int32_t (int32_t, int32_t, int32_t *));

View File

@ -56,11 +56,9 @@ public:
uint8_t relation, bool isJoin) = 0;
virtual void LnnNotifyMasterNodeChanged(bool isMaster, const char* masterNodeUdid,
int32_t weight) = 0;
virtual int32_t LnnInitGetDeviceName(LnnDeviceNameHandler handler) = 0;
virtual void RegisterNameMonitor(void) = 0;
virtual void LnnUnregisterEventHandler(LnnEventType event, LnnEventHandler handler) = 0;
virtual int32_t LnnOfflineTimingByHeartbeat(const char *networkId, ConnectionAddrType addrType) = 0;
virtual int32_t LnnGetSettingDeviceName(char *deviceName, uint32_t len) = 0;
virtual uint32_t AuthGenRequestId(void) = 0;
virtual void AuthHandleLeaveLNN(AuthHandle authHandle) = 0;
virtual int32_t AuthGetDeviceUuid(int64_t authId, char *uuid, uint16_t size) = 0;
@ -110,11 +108,9 @@ public:
MOCK_METHOD1(LnnNotifyBtStateChangeEvent, void (void *));
MOCK_METHOD4(LnnNotifyLnnRelationChanged, void (const char *, ConnectionAddrType, uint8_t, bool));
MOCK_METHOD3(LnnNotifyMasterNodeChanged, void (bool, const char*, int32_t));
MOCK_METHOD1(LnnInitGetDeviceName, int32_t (LnnDeviceNameHandler));
MOCK_METHOD0(RegisterNameMonitor, void (void));
MOCK_METHOD2(LnnUnregisterEventHandler, void (LnnEventType, LnnEventHandler));
MOCK_METHOD2(LnnOfflineTimingByHeartbeat, int32_t (const char *, ConnectionAddrType));
MOCK_METHOD2(LnnGetSettingDeviceName, int32_t (char *, uint32_t));
MOCK_METHOD0(AuthGenRequestId, uint32_t ());
MOCK_METHOD1(AuthHandleLeaveLNN, void (AuthHandle));
MOCK_METHOD3(AuthGetDeviceUuid, int32_t (int64_t, char*, uint16_t));
@ -143,10 +139,8 @@ public:
MOCK_METHOD3(SoftbusGetConfig, int32_t (ConfigType, unsigned char *, uint32_t));
MOCK_METHOD1(LnnSubscribeAccountBootEvent, int32_t (AccountEventHandle handle));
static int32_t ActionOfLnnRegisterEventHandler(LnnEventType event, LnnEventHandler handler);
static int32_t ActionOfLnnInitGetDeviceName(LnnDeviceNameHandler handler);
static int32_t ActionOfLnnGetSettingDeviceName(char *deviceName, uint32_t len);
static inline std::map<LnnEventType, LnnEventHandler> g_lnnEventHandlers;
static inline LnnDeviceNameHandler g_deviceNameHandler;
};
} // namespace OHOS
#endif // LNN_SERVICE_MOCK_H

View File

@ -59,48 +59,6 @@ void LNNDeviceNameInfoTest::TearDown()
{
}
/*
* @tc.name: LNN_UPDATE_DEVICE_NAME_TEST_001
* @tc.desc: no retry
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(LNNDeviceNameInfoTest, LNN_UPDATE_DEVICE_NAME_TEST_001, TestSize.Level1)
{
NiceMock<LnnNetLedgertInterfaceMock> ledgerMock;
NiceMock<LnnServicetInterfaceMock> serviceMock;
NiceMock<LnnConnectInterfaceMock> connMock;
EXPECT_CALL(serviceMock, LnnGetSettingDeviceName).WillRepeatedly(
LnnServicetInterfaceMock::ActionOfLnnGetSettingDeviceName);
EXPECT_CALL(ledgerMock, LnnSetLocalStrInfo).WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(ledgerMock, LnnGetAllOnlineAndMetaNodeInfo).WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(ledgerMock, LnnGetLocalNodeInfo).WillRepeatedly(Return(info));
EXPECT_CALL(ledgerMock, LnnGetDeviceName).WillRepeatedly(Return(DEVICE_NAME1));
EXPECT_CALL(ledgerMock, LnnGetDeviceName).WillRepeatedly(Return(DEVICE_NAME2));
EXPECT_CALL(serviceMock, LnnInitGetDeviceName).WillRepeatedly(
LnnServicetInterfaceMock::ActionOfLnnInitGetDeviceName);
EXPECT_CALL(serviceMock, RegisterNameMonitor).WillRepeatedly(Return());
EXPECT_CALL(connMock, DiscDeviceInfoChanged).WillRepeatedly(Return());
UpdateDeviceName(nullptr);
LnnDeviceNameHandler HandlerGetDeviceName = LnnServicetInterfaceMock::g_deviceNameHandler;
HandlerGetDeviceName(DEVICE_NAME_TYPE_DEV_NAME, nullptr);
}
/*
* @tc.name: LNN_UPDATE_DEVICE_NAME_TEST_002
* @tc.desc: looper is null
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(LNNDeviceNameInfoTest, LNN_UPDATE_DEVICE_NAME_TEST_002, TestSize.Level1)
{
NiceMock<LnnServicetInterfaceMock> serviceMock;
EXPECT_CALL(serviceMock, LnnInitGetDeviceName).WillRepeatedly(
LnnServicetInterfaceMock::ActionOfLnnInitGetDeviceName);
EXPECT_CALL(serviceMock, LnnGetSettingDeviceName(_, _)).WillRepeatedly(Return(SOFTBUS_ERR));
UpdateDeviceName(nullptr);
}
/*
* @tc.name: ON_RECEIVE_DEVICE_NAME_TEST_001
* @tc.desc: on receive device name test
@ -132,25 +90,6 @@ HWTEST_F(LNNDeviceNameInfoTest, ON_RECEIVE_DEVICE_NAME_TEST_001, TestSize.Level1
OnReceiveDeviceName(LNN_INFO_TYPE_DEVICE_NAME, NETWORKID, reinterpret_cast<uint8_t *>(msg), strlen(msg) + 1);
}
/*
* @tc.name: LNN_ACCOUNT_STATE_CHANGE_HANDLER_TEST_001
* @tc.desc: lnn account state change handler test
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(LNNDeviceNameInfoTest, LNN_ACCOUNT_STATE_CHANGE_HANDLER_TEST_001, TestSize.Level1)
{
NiceMock<LnnNetLedgertInterfaceMock> ledgerMock;
EXPECT_CALL(ledgerMock, LnnGetLocalNodeInfo).WillRepeatedly(Return(nullptr));
LnnEventBasicInfo info1;
info1.event = LNN_EVENT_TYPE_MAX;
LnnAccountStateChangeHandler(nullptr);
LnnAccountStateChangeHandler(&info1);
info1.event = LNN_EVENT_ACCOUNT_CHANGED;
LnnAccountStateChangeHandler(&info1);
LnnAccountStateChangeHandler(&info1);
}
/*
* @tc.name: ON_RECEIVE_DEVICE_NICK_NAME_TEST_001
* @tc.desc: on receive device nick name test
@ -178,33 +117,6 @@ HWTEST_F(LNNDeviceNameInfoTest, ON_RECEIVE_DEVICE_NICK_NAME_TEST_001, TestSize.L
OnReceiveDeviceNickName(LNN_INFO_TYPE_NICK_NAME, NETWORKID, reinterpret_cast<uint8_t *>(msg3), strlen(msg3) + 1);
}
/*
* @tc.name: LNN_HANDLER_GET_DEVICE_NAME_TEST_001
* @tc.desc: lnn handler get device name test
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(LNNDeviceNameInfoTest, LNN_HANDLER_GET_DEVICE_NAME_TEST_001, TestSize.Level1)
{
NiceMock<LnnNetLedgertInterfaceMock> ledgerMock;
NiceMock<LnnServicetInterfaceMock> serviceMock;
NiceMock<LnnConnectInterfaceMock> connMock;
EXPECT_CALL(connMock, DiscDeviceInfoChanged).WillRepeatedly(Return());
EXPECT_CALL(serviceMock, LnnGetSettingDeviceName)
.WillOnce(Return(SOFTBUS_ERR))
.WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(serviceMock, LnnNotifyLocalNetworkIdChanged).WillRepeatedly(Return());
EXPECT_CALL(ledgerMock, LnnSetLocalStrInfo).WillOnce(Return(SOFTBUS_ERR))
.WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(ledgerMock, LnnGetAllOnlineNodeInfo).WillRepeatedly(Return(SOFTBUS_ERR));
LnnHandlerGetDeviceName(DEVICE_NAME_TYPE_DEV_NAME, "deviceName");
LnnHandlerGetDeviceName(DEVICE_NAME_TYPE_DEV_NAME, "deviceName");
LnnHandlerGetDeviceName(DEVICE_NAME_TYPE_DEV_NAME, "deviceName");
LnnHandlerGetDeviceName(DEVICE_NAME_TYPE_DEV_NAME, "deviceName");
EXPECT_CALL(ledgerMock, LnnGetLocalNodeInfo).WillOnce(Return(nullptr));
LnnHandlerGetDeviceName(DEVICE_NAME_TYPE_NICK_NAME, "deviceName");
}
/*
* @tc.name: LNN_SYNC_DEVICE_NAME_TEST_001
* @tc.desc: lnn sync device name test
@ -232,31 +144,6 @@ HWTEST_F(LNNDeviceNameInfoTest, LNN_SYNC_DEVICE_NAME_TEST_001, TestSize.Level1)
EXPECT_TRUE(ret == SOFTBUS_OK);
}
/*
* @tc.name: LNN_SYNC_DEVICE_NICK_NAME_TEST_001
* @tc.desc: lnn sync device nick name test
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(LNNDeviceNameInfoTest, LNN_SYNC_DEVICE_NICK_NAME_TEST_001, TestSize.Level1)
{
NodeInfo nodeInfo;
NiceMock<LnnNetLedgertInterfaceMock> ledgerMock;
EXPECT_CALL(ledgerMock, LnnGetLocalNodeInfo).WillOnce(Return(nullptr))
.WillRepeatedly(Return(&nodeInfo));
NiceMock<LnnServicetInterfaceMock> serviceMock;
EXPECT_CALL(serviceMock, GetCurrentAccount).WillRepeatedly(Return(0));
NiceMock<LnnSyncInfoInterfaceMock> lnnSyncInfoMock;
EXPECT_CALL(lnnSyncInfoMock, LnnSendSyncInfoMsg).WillOnce(Return(SOFTBUS_ERR))
.WillRepeatedly(Return(SOFTBUS_OK));
int32_t ret = LnnSyncDeviceNickName(NETWORKID);
EXPECT_TRUE(ret == SOFTBUS_ERR);
ret = LnnSyncDeviceNickName(NETWORKID);
EXPECT_TRUE(ret == SOFTBUS_ERR);
ret = LnnSyncDeviceNickName(NETWORKID);
EXPECT_TRUE(ret == SOFTBUS_OK);
}
/*
* @tc.name: NICK_NAME_MSG_PROC_TEST_001
* @tc.desc: nick name msg proc test
@ -326,209 +213,9 @@ HWTEST_F(LNNDeviceNameInfoTest, NOTIFY_DEVICE_DISPLAY_NAME_CHANGE_TEST_001, Test
NotifyDeviceDisplayNameChange(NETWORKID, NODE_UDID);
}
/*
* @tc.name: IS_DEVICE_NEED_SYNC_NICK_NAME_TEST_001
* @tc.desc: Is Device Need Sync Nick Name test
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(LNNDeviceNameInfoTest, IS_DEVICE_NEED_SYNC_NICK_NAME_TEST_001, TestSize.Level1)
{
NiceMock<LnnNetLedgertInterfaceMock> ledgerMock;
EXPECT_CALL(ledgerMock, LnnGetRemoteNodeInfoById)
.WillOnce(Return(SOFTBUS_OK))
.WillRepeatedly(Return(SOFTBUS_ERR));
NiceMock<LnnServicetInterfaceMock> serviceMock;
EXPECT_CALL(serviceMock, IsFeatureSupport).WillRepeatedly(Return(false));
bool ret = IsDeviceNeedSyncNickName(NETWORKID);
EXPECT_FALSE(ret);
ret = IsDeviceNeedSyncNickName(NETWORKID);
EXPECT_FALSE(ret);
}
/*
* @tc.name: NOTIFY_NICK_NAME_CHANGE_TEST_001
* @tc.desc: NotifyNickNameChange test
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(LNNDeviceNameInfoTest, NOTIFY_NICK_NAME_CHANGE_TEST_001, TestSize.Level1)
{
NiceMock<LnnNetLedgertInterfaceMock> ledgerMock;
EXPECT_CALL(ledgerMock, LnnGetAllOnlineNodeInfo)
.WillOnce(Return(SOFTBUS_ERR))
.WillRepeatedly(LnnNetLedgertInterfaceMock::ActionOfLnnGetAllOnline);
EXPECT_CALL(ledgerMock, LnnGetRemoteNodeInfoById).WillOnce(Return(SOFTBUS_ERR));
NotifyNickNameChange();
NotifyNickNameChange();
EXPECT_CALL(ledgerMock, LnnGetRemoteNodeInfoById).WillRepeatedly(Return(SOFTBUS_OK));
NiceMock<LnnServicetInterfaceMock> serviceMock;
EXPECT_CALL(serviceMock, IsFeatureSupport).WillRepeatedly(Return(true));
EXPECT_CALL(ledgerMock, LnnGetLocalNodeInfo).WillOnce(Return(nullptr));
NotifyNickNameChange();
}
/*
* @tc.name: HANDLER_GET_DEVICE_NICK_NAME_TEST_001
* @tc.desc: HandlerGetDeviceNickName test
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(LNNDeviceNameInfoTest, HANDLER_GET_DEVICE_NICK_NAME_TEST_001, TestSize.Level1)
{
NodeInfo localNodeInfo1 = { .deviceInfo.unifiedName = "", };
NodeInfo localNodeInfo2 = { .deviceInfo.unifiedName = "nickName", };
NiceMock<LnnNetLedgertInterfaceMock> ledgerMock;
NiceMock<LnnServicetInterfaceMock> serviceMock;
EXPECT_CALL(ledgerMock, LnnGetLocalNodeInfo).WillOnce(Return(nullptr));
HandlerGetDeviceNickName(nullptr);
EXPECT_CALL(ledgerMock, LnnGetLocalNodeInfo).WillOnce(Return(&localNodeInfo1));
EXPECT_CALL(serviceMock, LnnGetUnifiedDeviceName).WillOnce(Return(SOFTBUS_ERR));
HandlerGetDeviceNickName(nullptr);
EXPECT_CALL(ledgerMock, LnnGetLocalNodeInfo).WillOnce(Return(&localNodeInfo1));
EXPECT_CALL(serviceMock, LnnGetUnifiedDeviceName).WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(serviceMock, LnnGetUnifiedDefaultDeviceName).WillOnce(Return(SOFTBUS_ERR));
HandlerGetDeviceNickName(nullptr);
EXPECT_CALL(ledgerMock, LnnGetLocalNodeInfo).WillOnce(Return(&localNodeInfo1));
const char *tmp = "";
EXPECT_CALL(serviceMock, LnnGetUnifiedDefaultDeviceName)
.WillOnce(DoAll(SetArgPointee<0>(*(const_cast<char *>(tmp))), Return(SOFTBUS_OK)));
EXPECT_CALL(serviceMock, LnnGetSettingNickName).WillOnce(Return(SOFTBUS_ERR));
HandlerGetDeviceNickName(nullptr);
EXPECT_CALL(ledgerMock, LnnGetLocalNodeInfo).WillOnce(Return(&localNodeInfo1));
EXPECT_CALL(serviceMock, LnnGetUnifiedDefaultDeviceName)
.WillOnce(DoAll(SetArgPointee<0>(*(const_cast<char *>(tmp))), Return(SOFTBUS_OK)));
EXPECT_CALL(serviceMock, LnnGetSettingNickName)
.WillOnce(DoAll(SetArgPointee<2>(*(const_cast<char *>(tmp))), Return(SOFTBUS_OK)));
EXPECT_CALL(ledgerMock, LnnGetAllOnlineNodeInfo).WillRepeatedly(Return(SOFTBUS_ERR));
HandlerGetDeviceNickName(nullptr);
const char *unifiedDefault = "unifiedDefault";
const char *nickName = "nickName";
EXPECT_CALL(ledgerMock, LnnGetLocalNodeInfo).WillRepeatedly(Return(&localNodeInfo2));
EXPECT_CALL(serviceMock, LnnSetLocalUnifiedName).WillOnce(Return(SOFTBUS_ERR));
EXPECT_CALL(serviceMock, LnnGetUnifiedDefaultDeviceName)
.WillOnce(DoAll(SetArgPointee<0>(*(const_cast<char *>(unifiedDefault))), Return(SOFTBUS_OK)));
EXPECT_CALL(ledgerMock, LnnSetLocalStrInfo)
.WillOnce(Return(SOFTBUS_ERR))
.WillOnce(Return(SOFTBUS_ERR));
EXPECT_CALL(serviceMock, LnnGetSettingNickName)
.WillOnce(DoAll(SetArgPointee<2>(*(const_cast<char *>(nickName))), Return(SOFTBUS_OK)));
HandlerGetDeviceNickName(nullptr);
EXPECT_CALL(serviceMock, LnnSetLocalUnifiedName).WillOnce(Return(SOFTBUS_OK));
EXPECT_CALL(serviceMock, LnnGetUnifiedDefaultDeviceName)
.WillOnce(DoAll(SetArgPointee<0>(*(const_cast<char *>(unifiedDefault))), Return(SOFTBUS_OK)));
EXPECT_CALL(ledgerMock, LnnSetLocalStrInfo)
.WillOnce(Return(SOFTBUS_OK))
.WillOnce(Return(SOFTBUS_OK));
EXPECT_CALL(serviceMock, LnnGetSettingNickName)
.WillOnce(DoAll(SetArgPointee<2>(*(const_cast<char *>(nickName))), Return(SOFTBUS_OK)));
HandlerGetDeviceNickName(nullptr);
}
/*
* @tc.name: UPDATA_LOCAL_FROM_SETTING_TEST_001
* @tc.desc: UpdataLocalFromSetting test
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(LNNDeviceNameInfoTest, UPDATA_LOCAL_FROM_SETTING_TEST_001, TestSize.Level1)
{
NiceMock<LnnServicetInterfaceMock> serviceMock;
const char *deviceName = "deviceName";
EXPECT_CALL(serviceMock, LnnGetSettingDeviceName)
.WillOnce(DoAll(SetArgPointee<0>(*(const_cast<char *>(deviceName))), Return(SOFTBUS_OK)));
NiceMock<LnnNetLedgertInterfaceMock> ledgerMock;
EXPECT_CALL(ledgerMock, LnnSetLocalStrInfo)
.WillOnce(Return(SOFTBUS_ERR));
EXPECT_CALL(serviceMock, LnnGetUnifiedDeviceName).WillOnce(Return(SOFTBUS_ERR));
EXPECT_CALL(serviceMock, LnnGetUnifiedDefaultDeviceName).WillOnce(Return(SOFTBUS_ERR));
EXPECT_CALL(serviceMock, LnnGetSettingNickName).WillOnce(Return(SOFTBUS_ERR));
EXPECT_CALL(serviceMock, RegisterNameMonitor).WillRepeatedly(Return());
NiceMock<LnnConnectInterfaceMock> connMock;
EXPECT_CALL(connMock, DiscDeviceInfoChanged).WillRepeatedly(Return());
EXPECT_CALL(serviceMock, LnnNotifyLocalNetworkIdChanged).WillRepeatedly(Return());
UpdataLocalFromSetting(nullptr);
EXPECT_CALL(serviceMock, LnnGetSettingDeviceName)
.WillOnce(DoAll(SetArgPointee<0>(*(const_cast<char *>(deviceName))), Return(SOFTBUS_OK)));
EXPECT_CALL(ledgerMock, LnnSetLocalStrInfo)
.WillOnce(Return(SOFTBUS_OK));
const char *tmp = "";
EXPECT_CALL(serviceMock, LnnGetUnifiedDeviceName)
.WillOnce(DoAll(SetArgPointee<0>(*(const_cast<char *>(tmp))), Return(SOFTBUS_OK)));
EXPECT_CALL(serviceMock, LnnGetUnifiedDefaultDeviceName)
.WillOnce(DoAll(SetArgPointee<0>(*(const_cast<char *>(tmp))), Return(SOFTBUS_OK)));
EXPECT_CALL(serviceMock, LnnGetSettingNickName)
.WillOnce(DoAll(SetArgPointee<2>(*(const_cast<char *>(tmp))), Return(SOFTBUS_OK)));
UpdataLocalFromSetting(nullptr);
}
/*
* @tc.name: UPDATA_LOCAL_FROM_SETTING_TEST_002
* @tc.desc: UpdataLocalFromSetting test
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(LNNDeviceNameInfoTest, UPDATA_LOCAL_FROM_SETTING_TEST_002, TestSize.Level1)
{
NiceMock<LnnServicetInterfaceMock> serviceMock;
const char *deviceName = "deviceName";
NiceMock<LnnNetLedgertInterfaceMock> ledgerMock;
const char *nickName = "nickName";
EXPECT_CALL(serviceMock, RegisterNameMonitor).WillRepeatedly(Return());
NiceMock<LnnConnectInterfaceMock> connMock;
EXPECT_CALL(connMock, DiscDeviceInfoChanged).WillRepeatedly(Return());
EXPECT_CALL(serviceMock, LnnNotifyLocalNetworkIdChanged).WillRepeatedly(Return());
EXPECT_CALL(serviceMock, LnnGetSettingDeviceName)
.WillRepeatedly(DoAll(SetArgPointee<0>(*(const_cast<char *>(deviceName))), Return(SOFTBUS_OK)));
EXPECT_CALL(ledgerMock, LnnSetLocalStrInfo)
.WillOnce(Return(SOFTBUS_OK))
.WillRepeatedly(Return(SOFTBUS_ERR));
EXPECT_CALL(serviceMock, LnnGetUnifiedDeviceName)
.WillRepeatedly(DoAll(SetArgPointee<0>(*(const_cast<char *>(deviceName))), Return(SOFTBUS_OK)));
EXPECT_CALL(serviceMock, LnnGetUnifiedDefaultDeviceName)
.WillRepeatedly(DoAll(SetArgPointee<0>(*(const_cast<char *>(deviceName))), Return(SOFTBUS_OK)));
EXPECT_CALL(serviceMock, LnnGetSettingNickName)
.WillRepeatedly(DoAll(SetArgPointee<2>(*(const_cast<char *>(nickName))), Return(SOFTBUS_OK)));
UpdataLocalFromSetting(nullptr);
}
/*
* @tc.name: UPDATA_LOCAL_FROM_SETTING_TEST_003
* @tc.desc: UpdataLocalFromSetting test
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(LNNDeviceNameInfoTest, UPDATA_LOCAL_FROM_SETTING_TEST_003, TestSize.Level1)
{
NiceMock<LnnServicetInterfaceMock> serviceMock;
const char *deviceName = "deviceName";
NiceMock<LnnNetLedgertInterfaceMock> ledgerMock;
const char *nickName = "nickName";
EXPECT_CALL(serviceMock, LnnGetSettingDeviceName)
.WillOnce(DoAll(SetArgPointee<0>(*(const_cast<char *>(deviceName))), Return(SOFTBUS_OK)))
.WillRepeatedly(Return(SOFTBUS_ERR));
EXPECT_CALL(ledgerMock, LnnSetLocalStrInfo)
.WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(serviceMock, LnnGetUnifiedDeviceName)
.WillRepeatedly(DoAll(SetArgPointee<0>(*(const_cast<char *>(deviceName))), Return(SOFTBUS_OK)));
EXPECT_CALL(serviceMock, LnnGetUnifiedDefaultDeviceName)
.WillRepeatedly(DoAll(SetArgPointee<0>(*(const_cast<char *>(deviceName))), Return(SOFTBUS_OK)));
EXPECT_CALL(serviceMock, LnnGetSettingNickName)
.WillRepeatedly(DoAll(SetArgPointee<2>(*(const_cast<char *>(nickName))), Return(SOFTBUS_OK)));
EXPECT_CALL(serviceMock, RegisterNameMonitor).WillRepeatedly(Return());
NiceMock<LnnConnectInterfaceMock> connMock;
EXPECT_CALL(connMock, DiscDeviceInfoChanged).WillRepeatedly(Return());
EXPECT_CALL(serviceMock, LnnNotifyLocalNetworkIdChanged).WillRepeatedly(Return());
UpdataLocalFromSetting(nullptr);
UpdataLocalFromSetting(nullptr);
}
/*
* @tc.name: LNN_INIT_DEVICE_NAME_TEST_001
* @tc.desc: UpdataLocalFromSetting test
* @tc.desc: LnnInitDevicename test
* @tc.type: FUNC
* @tc.require:
*/
@ -539,11 +226,8 @@ HWTEST_F(LNNDeviceNameInfoTest, LNN_INIT_DEVICE_NAME_TEST_001, TestSize.Level1)
.WillRepeatedly(Return(SOFTBUS_OK));
int32_t ret = LnnInitDevicename();
EXPECT_EQ(ret, SOFTBUS_ERR);
NiceMock<LnnServicetInterfaceMock> serviceMock;
EXPECT_CALL(serviceMock, LnnRegisterEventHandler).WillOnce(Return(SOFTBUS_ERR))
.WillRepeatedly(Return(SOFTBUS_OK));
ret = LnnInitDevicename();
EXPECT_EQ(ret, SOFTBUS_ERR);
EXPECT_EQ(ret, SOFTBUS_OK);
ret = LnnInitDevicename();
EXPECT_EQ(ret, SOFTBUS_OK);
}

View File

@ -75,11 +75,6 @@ int32_t NetBuilderDepsInterfaceMock::ActionOfLnnGetAllOnlineNodeInfo(NodeBasicIn
}
extern "C" {
int32_t LnnGetSettingDeviceName(char *deviceName, uint32_t len)
{
return GetNetBuilderDepsInterface()->LnnGetSettingDeviceName(deviceName, len);
}
int32_t AuthGetDeviceUuid(int64_t authId, char *uuid, uint16_t size)
{
return GetNetBuilderDepsInterface()->AuthGetDeviceUuid(authId, uuid, size);

View File

@ -98,11 +98,6 @@ void LnnNotifyMasterNodeChanged(bool isMaster, const char* masterNodeUdid, int32
return GetServiceInterface()->LnnNotifyMasterNodeChanged(isMaster, masterNodeUdid, weight);
}
int32_t LnnInitGetDeviceName(LnnDeviceNameHandler handler)
{
return GetServiceInterface()->LnnInitGetDeviceName(handler);
}
void RegisterNameMonitor(void)
{
return GetServiceInterface()->RegisterNameMonitor();
@ -118,11 +113,6 @@ int32_t LnnOfflineTimingByHeartbeat(const char *networkId, ConnectionAddrType ad
return GetServiceInterface()->LnnOfflineTimingByHeartbeat(networkId, addrType);
}
int32_t LnnGetSettingDeviceName(char *deviceName, uint32_t len)
{
return GetServiceInterface()->LnnGetSettingDeviceName(deviceName, len);
}
uint32_t AuthGenRequestId(void)
{
return GetServiceInterface()->AuthGenRequestId();
@ -269,15 +259,6 @@ int32_t LnnServicetInterfaceMock::ActionOfLnnRegisterEventHandler(LnnEventType e
return SOFTBUS_OK;
}
int32_t LnnServicetInterfaceMock::ActionOfLnnInitGetDeviceName(LnnDeviceNameHandler handler)
{
if (handler == NULL) {
return SOFTBUS_INVALID_PARAM;
}
g_deviceNameHandler = handler;
return SOFTBUS_OK;
}
int32_t LnnServicetInterfaceMock::ActionOfLnnGetSettingDeviceName(char *deviceName, uint32_t len)
{
if (deviceName == NULL) {

View File

@ -33,30 +33,4 @@ AuthChannelInterfaceMock::~AuthChannelInterfaceMock()
{
g_authChannelInterface = nullptr;
}
static AuthChannelInterface *GetAuthChannelInterface()
{
return reinterpret_cast<AuthChannelInterface *>(g_authChannelInterface);
}
extern "C" {
int32_t LnnInitGetDeviceName(LnnDeviceNameHandler handler)
{
return GetAuthChannelInterface()->LnnInitGetDeviceName(handler);
}
int32_t LnnGetSettingDeviceName(char *deviceName, uint32_t len)
{
return GetAuthChannelInterface()->LnnGetSettingDeviceName(deviceName, len);
}
int32_t AuthChannelInterfaceMock::ActionOfLnnInitGetDeviceName(LnnDeviceNameHandler handler)
{
if (handler == NULL) {
return SOFTBUS_INVALID_PARAM;
}
g_deviceNameHandler = handler;
return SOFTBUS_OK;
}
}
}

View File

@ -26,18 +26,12 @@ class AuthChannelInterface {
public:
AuthChannelInterface() {};
virtual ~AuthChannelInterface() {};
virtual int32_t LnnInitGetDeviceName(LnnDeviceNameHandler handler) = 0;
virtual int32_t LnnGetSettingDeviceName(char *deviceName, uint32_t len) = 0;
};
class AuthChannelInterfaceMock : public AuthChannelInterface {
public:
AuthChannelInterfaceMock();
~AuthChannelInterfaceMock() override;
MOCK_METHOD1(LnnInitGetDeviceName, int32_t (LnnDeviceNameHandler));
MOCK_METHOD2(LnnGetSettingDeviceName, int32_t (char *, uint32_t));
static int32_t ActionOfLnnInitGetDeviceName(LnnDeviceNameHandler handler);
static inline LnnDeviceNameHandler g_deviceNameHandler;
};
} // namespace OHOS
#endif // AUTH_CHANNEL_MOCK_H

View File

@ -69,10 +69,6 @@ public:
void TransAuthChannelTest::SetUpTestCase(void)
{
NiceMock<AuthChannelInterfaceMock> AuthChannelMock;
EXPECT_CALL(AuthChannelMock, LnnInitGetDeviceName).WillRepeatedly(
AuthChannelInterfaceMock::ActionOfLnnInitGetDeviceName);
EXPECT_CALL(AuthChannelMock, LnnGetSettingDeviceName(_, _)).WillRepeatedly(Return(SOFTBUS_OK));
SoftbusConfigInit();
LooperInit();
ConnServerInit();
@ -329,10 +325,6 @@ HWTEST_F(TransAuthChannelTest, OnAuthChannelDataRecvTest001, TestSize.Level1)
data->data = (uint8_t *)TEST_AUTH_DATA;
data->len = strlen(TEST_AUTH_DATA) + 1;
data->flag = AUTH_CHANNEL_REQ;
NiceMock<AuthChannelInterfaceMock> AuthChannelMock;
EXPECT_CALL(AuthChannelMock, LnnInitGetDeviceName).WillRepeatedly(
AuthChannelInterfaceMock::ActionOfLnnInitGetDeviceName);
EXPECT_CALL(AuthChannelMock, LnnGetSettingDeviceName(_, _)).WillRepeatedly(Return(SOFTBUS_INVALID_PARAM));
OnAuthChannelDataRecv(authId, data);
data->flag = AUTH_CHANNEL_REPLY;
@ -510,8 +502,6 @@ HWTEST_F(TransAuthChannelTest, OperateAuthChannelInfoTest004, TestSize.Level1)
*/
HWTEST_F(TransAuthChannelTest, NotifyOpenAuthChannelSuccessTest001, TestSize.Level1)
{
NiceMock<AuthChannelInterfaceMock> AuthChannelMock;
EXPECT_CALL(AuthChannelMock, LnnGetSettingDeviceName(_, _)).WillRepeatedly(Return(SOFTBUS_INVALID_PARAM));
bool isServer = true;
int32_t ret = TransAuthInit(callback);
ASSERT_EQ(ret, SOFTBUS_OK);
@ -547,8 +537,6 @@ HWTEST_F(TransAuthChannelTest, NotifyOpenAuthChannelFailedTest001, TestSize.Leve
*/
HWTEST_F(TransAuthChannelTest, NofifyCloseAuthChannelTest001, TestSize.Level1)
{
NiceMock<AuthChannelInterfaceMock> AuthChannelMock;
EXPECT_CALL(AuthChannelMock, LnnGetSettingDeviceName(_, _)).WillRepeatedly(Return(SOFTBUS_INVALID_PARAM));
int32_t ret = TransAuthInit(callback);
ASSERT_EQ(ret, SOFTBUS_OK);
ret = NofifyCloseAuthChannel(g_pkgName, TRANS_TEST_PID, TRANS_TEST_CHANNEL_ID);
@ -625,8 +613,6 @@ HWTEST_F(TransAuthChannelTest, CopyPeerAppInfoTest001, TestSize.Level1)
*/
HWTEST_F(TransAuthChannelTest, OnRequsetUpdateAuthChannelTest001, TestSize.Level1)
{
NiceMock<AuthChannelInterfaceMock> AuthChannelMock;
EXPECT_CALL(AuthChannelMock, LnnGetSettingDeviceName(_, _)).WillRepeatedly(Return(SOFTBUS_INVALID_PARAM));
int32_t ret = TransSessionMgrInit();
ASSERT_EQ(ret, SOFTBUS_OK);
ret = TransAuthInit(callback);
@ -677,8 +663,6 @@ HWTEST_F(TransAuthChannelTest, OnRequsetUpdateAuthChannelTest001, TestSize.Level
*/
HWTEST_F(TransAuthChannelTest, OnRequsetUpdateAuthChannelTest002, TestSize.Level1)
{
NiceMock<AuthChannelInterfaceMock> AuthChannelMock;
EXPECT_CALL(AuthChannelMock, LnnGetSettingDeviceName(_, _)).WillRepeatedly(Return(SOFTBUS_INVALID_PARAM));
int32_t ret = TransSessionMgrInit();
ASSERT_EQ(ret, SOFTBUS_OK);
ret = TransAuthInit(callback);
@ -737,10 +721,6 @@ HWTEST_F(TransAuthChannelTest, OnRecvAuthChannelRequestTest001, TestSize.Level1)
*/
HWTEST_F(TransAuthChannelTest, OnRecvAuthChannelRequestTest002, TestSize.Level1)
{
NiceMock<AuthChannelInterfaceMock> AuthChannelMock;
EXPECT_CALL(AuthChannelMock, LnnInitGetDeviceName).WillRepeatedly(
AuthChannelInterfaceMock::ActionOfLnnInitGetDeviceName);
EXPECT_CALL(AuthChannelMock, LnnGetSettingDeviceName(_, _)).WillRepeatedly(Return(SOFTBUS_INVALID_PARAM));
cJSON *msg = cJSON_CreateObject();
AppInfo *appInfo = (AppInfo*)SoftBusCalloc(sizeof(AppInfo));
ASSERT_TRUE(appInfo != nullptr);
@ -781,10 +761,6 @@ HWTEST_F(TransAuthChannelTest, OnRecvAuthChannelRequestTest002, TestSize.Level1)
*/
HWTEST_F(TransAuthChannelTest, OnRecvAuthChannelRequestTest003, TestSize.Level1)
{
NiceMock<AuthChannelInterfaceMock> AuthChannelMock;
EXPECT_CALL(AuthChannelMock, LnnInitGetDeviceName).WillRepeatedly(
AuthChannelInterfaceMock::ActionOfLnnInitGetDeviceName);
EXPECT_CALL(AuthChannelMock, LnnGetSettingDeviceName(_, _)).WillRepeatedly(Return(SOFTBUS_INVALID_PARAM));
int32_t ret = TransSessionMgrInit();
ASSERT_EQ(ret, SOFTBUS_OK);
ret = TransAuthInit(callback);