From 4e24ad0d6019b50bcf550b5ae05628ff6982dd6c Mon Sep 17 00:00:00 2001 From: renguang1116 Date: Mon, 25 Jul 2022 10:05:57 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E3=80=90=E4=BB=BB=E5=8A=A1=E3=80=91?= =?UTF-8?q?=E4=BC=98=E5=8C=96DM=E5=86=85=E5=AD=98=E5=8D=A0=E7=94=A8=20Sign?= =?UTF-8?q?ed-off-by:=20renguang1116=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/include/dm_constants.h | 184 +++++++++--------- ext/pin_auth/src/pin_auth.cpp | 2 +- ext/pin_auth/src/standard/pin_auth_ui.cpp | 8 +- .../native_cpp/src/device_manager_impl.cpp | 38 ++-- .../src/authentication/dm_auth_manager.cpp | 47 +++-- .../showconfirm/standard/show_confirm.cpp | 2 +- .../src/config/dm_config_manager.cpp | 22 +-- .../src/credential/dm_credential_manager.cpp | 4 +- .../dependency/hichain/hichain_connector.cpp | 51 ++--- .../dependency/softbus/softbus_connector.cpp | 14 +- .../dependency/softbus/softbus_session.cpp | 5 +- .../src/device_manager_service_impl.cpp | 40 ++-- .../devicestate/dm_device_state_manager.cpp | 4 +- .../src/discovery/dm_discovery_manager.cpp | 6 +- .../service/src/device_manager_service.cpp | 6 +- .../src/device_manager_service_listener.cpp | 2 +- .../service/src/softbus/softbus_listener.cpp | 40 ++-- test/unittest/UTTest_dm_timer.cpp | 16 +- test/unittest/UTTest_softbus_connector.cpp | 6 +- utils/include/dfx/dm_dfx_constants.h | 74 +++---- 20 files changed, 291 insertions(+), 280 deletions(-) diff --git a/common/include/dm_constants.h b/common/include/dm_constants.h index 1ef1c5543..96cc09edc 100755 --- a/common/include/dm_constants.h +++ b/common/include/dm_constants.h @@ -19,25 +19,25 @@ #include #ifdef __LP64__ -const std::string LIB_LOAD_PATH = "/system/lib64/"; +constexpr const char* LIB_LOAD_PATH = "/system/lib64/"; #else -const std::string LIB_LOAD_PATH = "/system/lib/"; +constexpr const char* LIB_LOAD_PATH = "/system/lib/"; #endif namespace OHOS { namespace DistributedHardware { -const std::string DM_PKG_NAME = "ohos.distributedhardware.devicemanager"; -const std::string DM_SESSION_NAME = "ohos.distributedhardware.devicemanager.resident"; +constexpr const char* DM_PKG_NAME = "ohos.distributedhardware.devicemanager"; +constexpr const char* DM_SESSION_NAME = "ohos.distributedhardware.devicemanager.resident"; -const std::string DISCOVER_STATUS_KEY = "persist.distributed_hardware.device_manager.discover_status"; -const std::string DISCOVER_STATUS_ON = "1"; -const std::string DISCOVER_STATUS_OFF = "0"; -const std::string AUTH_LOAD_JSON_KEY = "devicemanager_auth_components"; -const std::string ADAPTER_LOAD_JSON_KEY = "devicemanager_adapter_components"; -const std::string AUTH_JSON_TYPE_KEY = "AUTHENTICATE"; -const std::string CPYPTO_JSON_TYPE_KEY = "CPYPTO"; -const std::string PROFILE_JSON_TYPE_KEY = "PROFILE"; -const std::string DECISION_JSON_TYPE_KEY = "DECISION"; +constexpr const char* DISCOVER_STATUS_KEY = "persist.distributed_hardware.device_manager.discover_status"; +constexpr const char* DISCOVER_STATUS_ON = "1"; +constexpr const char* DISCOVER_STATUS_OFF = "0"; +constexpr const char* AUTH_LOAD_JSON_KEY = "devicemanager_auth_components"; +constexpr const char* ADAPTER_LOAD_JSON_KEY = "devicemanager_adapter_components"; +constexpr const char* AUTH_JSON_TYPE_KEY = "AUTHENTICATE"; +constexpr const char* CPYPTO_JSON_TYPE_KEY = "CPYPTO"; +constexpr const char* PROFILE_JSON_TYPE_KEY = "PROFILE"; +constexpr const char* DECISION_JSON_TYPE_KEY = "DECISION"; const int32_t DM_NAPI_SUBSCRIBE_CAPABILITY_DDMP = 0; const int32_t DM_NAPI_SUBSCRIBE_CAPABILITY_OSD = 1; @@ -49,6 +49,9 @@ const int32_t DISCOVER_STATUS_LEN = 20; const int32_t COMMON_CALLBACK_MAX_SIZE = 200; const uint32_t MAX_LOAD_VALUE = 3; +const int32_t DM_AUTH_TYPE_MAX = 4; +const int32_t DM_AUTH_TYPE_MIN = 1; + enum { DM_OK = 0, ERR_DM_FAILED = -20000, @@ -82,45 +85,40 @@ enum { ERR_DM_ENCRYPT_FAILED = -20028, }; -const std::string TARGET_PKG_NAME_KEY = "targetPkgName"; -const std::string HOST_PKG_NAME_KEY = "hostPackageName"; -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_LOCAL_DEVICE_ID = "LOCALDEVICEID"; -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_CRYPTO_SUPPORT = "CRYPTOSUPPORT"; -const std::string TAG_CRYPTO_NAME = "CRYPTONAME"; -const std::string TAG_CRYPTO_VERSION = "CRYPTOVERSION"; -const std::string TAG_VER = "ITF_VER"; -const std::string TAG_TYPE = "MSG_TYPE"; -const std::string DM_ITF_VER_1_0 = "1.0"; -const std::string DM_ITF_VER = "1.1"; -const std::string TAG = "DM_MSG_CODEC"; -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 = "appThumbnailKey"; -const std::string APP_THUMBNAIL_LEN = "appThumbnailLen"; -const std::string APP_THUMBNAIL = "appThumbnail"; -const std::string CANCEL_DISPLAY_KEY = "cancelPinCodeDisplay"; +constexpr const char* TARGET_PKG_NAME_KEY = "targetPkgName"; +constexpr const char* TAG_REQUESTER = "REQUESTER"; +constexpr const char* TAG_TOKEN = "TOKEN"; +constexpr const char* TAG_HOST = "HOST"; +constexpr const char* TAG_TARGET = "TARGET"; +constexpr const char* TAG_VISIBILITY = "VISIBILITY"; +constexpr const char* TAG_GROUPIDS = "GROUPIDLIST"; +constexpr const char* TAG_REPLY = "REPLY"; +constexpr const char* TAG_NET_ID = "NETID"; +constexpr const char* TAG_GROUP_ID = "groupId"; +constexpr const char* TAG_GROUP_NAME = "GROUPNAME"; +constexpr const char* TAG_REQUEST_ID = "REQUESTID"; +constexpr const char* TAG_DEVICE_ID = "DEVICEID"; +constexpr const char* TAG_LOCAL_DEVICE_ID = "LOCALDEVICEID"; +constexpr const char* TAG_DEVICE_TYPE = "DEVICETYPE"; +constexpr const char* TAG_APP_NAME = "APPNAME"; +constexpr const char* TAG_APP_DESCRIPTION = "APPDESC"; +constexpr const char* TAG_APP_ICON = "APPICON"; +constexpr const char* TAG_APP_THUMBNAIL = "APPTHUM"; +constexpr const char* TAG_INDEX = "INDEX"; +constexpr const char* TAG_SLICE_NUM = "SLICE"; +constexpr const char* TAG_THUMBNAIL_SIZE = "THUMSIZE"; +constexpr const char* TAG_AUTH_TYPE = "AUTHTYPE"; +constexpr const char* TAG_CRYPTO_SUPPORT = "CRYPTOSUPPORT"; +constexpr const char* TAG_CRYPTO_NAME = "CRYPTONAME"; +constexpr const char* TAG_CRYPTO_VERSION = "CRYPTOVERSION"; +constexpr const char* TAG_VER = "ITF_VER"; +constexpr const char* TAG_TYPE = "MSG_TYPE"; +constexpr const char* DM_ITF_VER = "1.1"; +constexpr const char* APP_NAME_KEY = "appName"; +constexpr const char* APP_DESCRIPTION_KEY = "appDescription"; +constexpr const char* APP_ICON_KEY = "appIcon"; +constexpr const char* APP_THUMBNAIL = "appThumbnail"; +constexpr const char* CANCEL_DISPLAY_KEY = "cancelPinCodeDisplay"; const int32_t MSG_MAX_SIZE = 45 * 1024; const int32_t AUTH_REPLY_ACCEPT = 0; const int32_t ENCRYPT_TAG_LEN = 32; @@ -134,14 +132,14 @@ const int32_t BUSINESS_FA_MIRGRATION = 0; const int32_t BUSINESS_RESOURCE_ACCESS = 1; // json -const std::string AUTH_TYPE = "authType"; -const std::string TOKEN = "token"; -const std::string PIN_TOKEN = "pinToken"; -const std::string PIN_CODE_KEY = "pinCode"; -const std::string NFC_CODE_KEY = "nfcCode"; -const std::string QR_CODE_KEY = "qrCode"; -const std::string TAG_AUTH_TOKEN = "authToken"; -const std::string VERIFY_FAILED = "verifyFailed"; +constexpr const char* AUTH_TYPE = "authType"; +constexpr const char* TOKEN = "token"; +constexpr const char* PIN_TOKEN = "pinToken"; +constexpr const char* PIN_CODE_KEY = "pinCode"; +constexpr const char* NFC_CODE_KEY = "nfcCode"; +constexpr const char* QR_CODE_KEY = "qrCode"; +constexpr const char* TAG_AUTH_TOKEN = "authToken"; +constexpr const char* VERIFY_FAILED = "verifyFailed"; const int32_t AUTH_TYPE_PIN = 1; const int32_t AUTH_TYPE_SCAN = 2; const int32_t AUTH_TYPE_TOUCH = 3; @@ -172,37 +170,35 @@ const int64_t MAX_REQUEST_ID = 9999999999; const int32_t FIELD_EXPIRE_TIME_VALUE = 7; const int32_t GROUP_VISIBILITY_IS_PUBLIC = -1; const int32_t GROUP_VISIBILITY_IS_PRIVATE = 0; -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"; +constexpr const char* DEVICE_ID = "DEVICE_ID"; +constexpr const char* WIFI_IP = "WIFI_IP"; +constexpr const char* WIFI_PORT = "WIFI_PORT"; +constexpr const char* BR_MAC = "BR_MAC"; +constexpr const char* BLE_MAC = "BLE_MAC"; +constexpr const char* ETH_IP = "ETH_IP"; +constexpr const char* ETH_PORT = "ETH_PORT"; // ACE const int32_t ACE_X = 50; const int32_t ACE_Y = 300; const int32_t ACE_WIDTH = 580; const int32_t ACE_HEIGHT = 520; -const std::string EVENT_CONFIRM = "EVENT_CONFIRM"; -const std::string EVENT_CANCEL = "EVENT_CANCEL"; -const std::string EVENT_INIT = "EVENT_INIT"; -const std::string EVENT_CONFIRM_CODE = "0"; -const std::string EVENT_CANCEL_CODE = "1"; -const std::string EVENT_INIT_CODE = "2"; +constexpr const char* EVENT_CONFIRM = "EVENT_CONFIRM"; +constexpr const char* EVENT_CANCEL = "EVENT_CANCEL"; +constexpr const char* EVENT_INIT = "EVENT_INIT"; +constexpr const char* EVENT_CONFIRM_CODE = "0"; +constexpr const char* EVENT_CANCEL_CODE = "1"; +constexpr const char* EVENT_INIT_CODE = "2"; // timer -const std::string TIMER_PREFIX = "deviceManagerTimer:"; -const std::string AUTHENTICATE_TIMEOUT_TASK = TIMER_PREFIX + "authenticate"; -const std::string NEGOTIATE_TIMEOUT_TASK = TIMER_PREFIX + "negotiate"; -const std::string CONFIRM_TIMEOUT_TASK = TIMER_PREFIX + "confirm"; -const std::string SHOW_TIMEOUT_TASK = TIMER_PREFIX + "show"; -const std::string INPUT_TIMEOUT_TASK = TIMER_PREFIX + "input"; -const std::string ADD_TIMEOUT_TASK = TIMER_PREFIX + "add"; -const std::string WAIT_NEGOTIATE_TIMEOUT_TASK = TIMER_PREFIX + "waitNegotiate"; -const std::string WAIT_REQUEST_TIMEOUT_TASK = TIMER_PREFIX + "waitRequest"; -const std::string STATE_TIMER_PREFIX = "stateTimer_"; +constexpr const char* AUTHENTICATE_TIMEOUT_TASK = "deviceManagerTimer:authenticate"; +constexpr const char* NEGOTIATE_TIMEOUT_TASK = "deviceManagerTimer:negotiate"; +constexpr const char* CONFIRM_TIMEOUT_TASK = "deviceManagerTimer:confirm"; +constexpr const char* INPUT_TIMEOUT_TASK = "deviceManagerTimer:input"; +constexpr const char* ADD_TIMEOUT_TASK = "deviceManagerTimer:add"; +constexpr const char* WAIT_NEGOTIATE_TIMEOUT_TASK = "deviceManagerTimer:waitNegotiate"; +constexpr const char* WAIT_REQUEST_TIMEOUT_TASK = "deviceManagerTimer:waitRequest"; +constexpr const char* STATE_TIMER_PREFIX = "deviceManagerTimer:stateTimer_"; const int32_t TIMER_PREFIX_LENGTH = 19; const int32_t TIMER_DEFAULT = 0; const int32_t NO_TIMER = -1; @@ -213,17 +209,17 @@ const int32_t SEC_TO_MM = 1000; const int32_t MAX_EVENTS = 5; // credential -const std::string FIELD_CREDENTIAL = "credential"; -const std::string FIELD_CREDENTIAL_VERSION = "version"; -const std::string FIELD_DEVICE_PK = "devicePk"; -const std::string FIELD_SERVER_PK = "serverPk"; -const std::string FIELD_PKINFO_SIGNATURE = "pkInfoSignature"; -const std::string FIELD_PKINFO = "pkInfo"; -const std::string FIELD_PROCESS_TYPE = "processType"; -const std::string FIELD_AUTH_TYPE = "authType"; -const std::string FIELD_CREDENTIAL_DATA = "credentialData"; -const std::string FIELD_CREDENTIAL_ID = "credentialId"; -const std::string FIELD_PEER_CREDENTIAL_INFO = "peerCredentialInfo"; +constexpr const char* FIELD_CREDENTIAL = "credential"; +constexpr const char* FIELD_CREDENTIAL_VERSION = "version"; +constexpr const char* FIELD_DEVICE_PK = "devicePk"; +constexpr const char* FIELD_SERVER_PK = "serverPk"; +constexpr const char* FIELD_PKINFO_SIGNATURE = "pkInfoSignature"; +constexpr const char* FIELD_PKINFO = "pkInfo"; +constexpr const char* FIELD_PROCESS_TYPE = "processType"; +constexpr const char* FIELD_AUTH_TYPE = "authType"; +constexpr const char* FIELD_CREDENTIAL_DATA = "credentialData"; +constexpr const char* FIELD_CREDENTIAL_ID = "credentialId"; +constexpr const char* FIELD_PEER_CREDENTIAL_INFO = "peerCredentialInfo"; const int32_t SAME_ACCOUNT_TYPE = 1; const int32_t CROSS_ACCOUNT_TYPE = 2; const int32_t PIN_CODE_NETWORK = 0; diff --git a/ext/pin_auth/src/pin_auth.cpp b/ext/pin_auth/src/pin_auth.cpp index 5ae4f09a8..913e03aae 100644 --- a/ext/pin_auth/src/pin_auth.cpp +++ b/ext/pin_auth/src/pin_auth.cpp @@ -58,7 +58,7 @@ int32_t PinAuth::VerifyAuthentication(std::string &authToken, const std::string { times_ += 1; if (authParam.length() == 1) { - if (authParam == EVENT_CONFIRM_CODE) { + if (authParam == std::string(EVENT_CONFIRM_CODE)) { return DM_OK; } LOGE("Peer rejection"); diff --git a/ext/pin_auth/src/standard/pin_auth_ui.cpp b/ext/pin_auth/src/standard/pin_auth_ui.cpp index f554a8484..e9ba47b7a 100644 --- a/ext/pin_auth/src/standard/pin_auth_ui.cpp +++ b/ext/pin_auth/src/standard/pin_auth_ui.cpp @@ -46,10 +46,10 @@ int32_t PinAuthUi::ShowPinDialog(int32_t code, std::shared_ptr au OHOS::Rosen::WindowType::WINDOW_TYPE_SYSTEM_ALARM_WINDOW, ACE_X, ACE_Y, ACE_WIDTH, ACE_HEIGHT, [authManager](int32_t id, const std::string& event, const std::string& params) { - if (params == EVENT_INIT_CODE) { + if (params == std::string(EVENT_INIT_CODE)) { authManager->SetPageId(id); } - if (params == EVENT_CANCEL_CODE) { + if (params == std::string(EVENT_CANCEL_CODE)) { LOGI("CancelDialog start id:%d,event:%s,params:%s", id, event.c_str(), params.c_str()); Ace::UIServiceMgrClient::GetInstance()->CancelDialog(id); } @@ -76,9 +76,9 @@ int32_t PinAuthUi::InputPinDialog(std::shared_ptr authManager) OHOS::Rosen::WindowType::WINDOW_TYPE_SYSTEM_ALARM_WINDOW, ACE_X, ACE_Y, ACE_WIDTH, ACE_HEIGHT, [authManager](int32_t id, const std::string& event, const std::string& params) { - if (event == EVENT_INIT) { + if (event == std::string(EVENT_INIT)) { authManager->SetPageId(id); - } else if (event == EVENT_CONFIRM) { + } else if (event == std::string(EVENT_CONFIRM)) { LOGI("On confirm event for page id:%d, params:%s", id, params.c_str()); if (params.length() <= DEFAULT_PIN_CODE_LENGTH) { authManager->AddMember(std::stoi(params)); diff --git a/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp b/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp index 1e5ec4c82..c9618a264 100644 --- a/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp +++ b/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp @@ -52,7 +52,7 @@ DeviceManagerImpl &DeviceManagerImpl::GetInstance() int32_t DeviceManagerImpl::InitDeviceManager(const std::string &pkgName, std::shared_ptr dmInitCallback) { LOGI("DeviceManager::InitDeviceManager start, pkgName: %s", pkgName.c_str()); - DmTraceStart(DM_HITRACE_INIT); + DmTraceStart(std::string(DM_HITRACE_INIT)); if (pkgName.empty() || dmInitCallback == nullptr) { LOGE("InitDeviceManager error: Invalid parameter"); return ERR_DM_INPUT_PARAMETER_EMPTY; @@ -74,14 +74,16 @@ int32_t DeviceManagerImpl::InitDeviceManager(const std::string &pkgName, std::sh } if (ret != DM_OK) { LOGE("InitDeviceManager error: proxy init failed ret: %d", ret); - SysEventWrite(DM_INIT_DEVICE_MANAGER_FAILED, DM_HISYEVENT_FAULT, DM_INIT_DEVICE_MANAGER_FAILED_MSG); + SysEventWrite(std::string(DM_INIT_DEVICE_MANAGER_FAILED), DM_HISYEVENT_FAULT, + std::string(DM_INIT_DEVICE_MANAGER_FAILED_MSG)); return ERR_DM_INIT_FAILED; } DeviceManagerNotify::GetInstance().RegisterDeathRecipientCallback(pkgName, dmInitCallback); DmTraceEnd(); LOGI("InitDeviceManager success"); - SysEventWrite(DM_INIT_DEVICE_MANAGER_SUCCESS, DM_HISYEVENT_BEHAVIOR, DM_INIT_DEVICE_MANAGER_SUCCESS_MSG); + SysEventWrite(std::string(DM_INIT_DEVICE_MANAGER_SUCCESS), DM_HISYEVENT_BEHAVIOR, + std::string(DM_INIT_DEVICE_MANAGER_SUCCESS_MSG)); return DM_OK; } @@ -137,7 +139,7 @@ int32_t DeviceManagerImpl::GetTrustedDeviceList(const std::string &pkgName, cons int32_t DeviceManagerImpl::GetLocalDeviceInfo(const std::string &pkgName, DmDeviceInfo &info) { LOGI("DeviceManager::GetLocalDeviceInfo start, pkgName: %s", pkgName.c_str()); - DmTraceStart(DM_HITRACE_GET_LOCAL_DEVICE_INFO); + DmTraceStart(std::string(DM_HITRACE_GET_LOCAL_DEVICE_INFO)); std::shared_ptr req = std::make_shared(); std::shared_ptr rsp = std::make_shared(); req->SetPkgName(pkgName); @@ -150,14 +152,16 @@ int32_t DeviceManagerImpl::GetLocalDeviceInfo(const std::string &pkgName, DmDevi ret = rsp->GetErrCode(); if (ret != DM_OK) { LOGI("GetLocalDeviceInfo error: failed ret: %d", ret); - SysEventWrite(GET_LOCAL_DEVICE_INFO_FAILED, DM_HISYEVENT_BEHAVIOR, GET_LOCAL_DEVICE_INFO_FAILED_MSG); + SysEventWrite(std::string(GET_LOCAL_DEVICE_INFO_FAILED), DM_HISYEVENT_BEHAVIOR, + std::string(GET_LOCAL_DEVICE_INFO_FAILED_MSG)); return ERR_DM_IPC_RESPOND_FAILED; } info = rsp->GetLocalDeviceInfo(); DmTraceEnd(); LOGI("GetLocalDeviceInfo completed,pkgname%s", req->GetPkgName().c_str()); - SysEventWrite(GET_LOCAL_DEVICE_INFO_SUCCESS, DM_HISYEVENT_BEHAVIOR, GET_LOCAL_DEVICE_INFO_SUCCESS_MSG); + SysEventWrite(std::string(GET_LOCAL_DEVICE_INFO_SUCCESS), DM_HISYEVENT_BEHAVIOR, + std::string(GET_LOCAL_DEVICE_INFO_SUCCESS_MSG)); return DM_OK; } @@ -197,7 +201,7 @@ int32_t DeviceManagerImpl::StartDeviceDiscovery(const std::string &pkgName, cons const std::string &extra, std::shared_ptr callback) { LOGI("DeviceManager::StartDeviceDiscovery start, pkgName: %s", pkgName.c_str()); - DmTraceStart(DM_HITRACE_START_DEVICE); + DmTraceStart(std::string(DM_HITRACE_START_DEVICE)); if (pkgName.empty() || callback == nullptr) { LOGE("StartDeviceDiscovery error: Invalid para"); return ERR_DM_INPUT_PARAMETER_EMPTY; @@ -220,13 +224,15 @@ int32_t DeviceManagerImpl::StartDeviceDiscovery(const std::string &pkgName, cons ret = rsp->GetErrCode(); if (ret != DM_OK) { LOGE("StartDeviceDiscovery error: Failed with ret %d", ret); - SysEventWrite(START_DEVICE_DISCOVERY_FAILED, DM_HISYEVENT_BEHAVIOR, START_DEVICE_DISCOVERY_FAILED_MSG); + SysEventWrite(std::string(START_DEVICE_DISCOVERY_FAILED), DM_HISYEVENT_BEHAVIOR, + std::string(START_DEVICE_DISCOVERY_FAILED_MSG)); return ret; } DmTraceEnd(); LOGI("StartDeviceDiscovery completed, pkgName: %s", pkgName.c_str()); - SysEventWrite(START_DEVICE_DISCOVERY_SUCCESS, DM_HISYEVENT_BEHAVIOR, START_DEVICE_DISCOVERY_SUCCESS_MSG); + SysEventWrite(std::string(START_DEVICE_DISCOVERY_SUCCESS), DM_HISYEVENT_BEHAVIOR, + std::string(START_DEVICE_DISCOVERY_SUCCESS_MSG)); return DM_OK; } @@ -265,7 +271,7 @@ int32_t DeviceManagerImpl::AuthenticateDevice(const std::string &pkgName, int32_ std::shared_ptr callback) { LOGI("DeviceManager::AuthenticateDevice start , pkgName: %s", pkgName.c_str()); - DmTraceStart(DM_HITRACE_AUTH_TO_CONSULT); + DmTraceStart(std::string(DM_HITRACE_AUTH_TO_CONSULT)); if (pkgName.empty()) { LOGE("AuthenticateDevice error: Invalid para"); return ERR_DM_INPUT_PARAMETER_EMPTY; @@ -282,10 +288,12 @@ int32_t DeviceManagerImpl::AuthenticateDevice(const std::string &pkgName, int32_ int32_t ret = ipcClientProxy_->SendRequest(AUTHENTICATE_DEVICE, req, rsp); if (ret != DM_OK) { LOGE("AuthenticateDevice error: Send Request failed ret: %d", ret); - SysEventWrite(DM_SEND_REQUEST_FAILED, DM_HISYEVENT_BEHAVIOR, DM_SEND_REQUEST_FAILED_MSG); + SysEventWrite(std::string(DM_SEND_REQUEST_FAILED), DM_HISYEVENT_BEHAVIOR, + std::string(DM_SEND_REQUEST_FAILED_MSG)); return ERR_DM_IPC_SEND_REQUEST_FAILED; } - SysEventWrite(DM_SEND_REQUEST_SUCCESS, DM_HISYEVENT_BEHAVIOR, DM_SEND_REQUEST_SUCCESS_MSG); + SysEventWrite(std::string(DM_SEND_REQUEST_SUCCESS), DM_HISYEVENT_BEHAVIOR, + std::string(DM_SEND_REQUEST_SUCCESS_MSG)); ret = rsp->GetErrCode(); if (ret != DM_OK) { @@ -318,10 +326,12 @@ int32_t DeviceManagerImpl::UnAuthenticateDevice(const std::string &pkgName, cons ret = rsp->GetErrCode(); if (ret != DM_OK) { LOGE("UnAuthenticateDevice error: Failed with ret %d", ret); - SysEventWrite(UNAUTHENTICATE_DEVICE_FAILED, DM_HISYEVENT_BEHAVIOR, UNAUTHENTICATE_DEVICE_FAILED_MSG); + SysEventWrite(std::string(UNAUTHENTICATE_DEVICE_FAILED), DM_HISYEVENT_BEHAVIOR, + std::string(UNAUTHENTICATE_DEVICE_FAILED_MSG)); return ERR_DM_IPC_RESPOND_FAILED; } - SysEventWrite(UNAUTHENTICATE_DEVICE_SUCCESS, DM_HISYEVENT_BEHAVIOR, UNAUTHENTICATE_DEVICE_SUCCESS_MSG); + SysEventWrite(std::string(UNAUTHENTICATE_DEVICE_SUCCESS), DM_HISYEVENT_BEHAVIOR, + std::string(UNAUTHENTICATE_DEVICE_SUCCESS_MSG)); LOGI("UnAuthenticateDevice completed, pkgName: %s", pkgName.c_str()); return DM_OK; diff --git a/services/implementation/src/authentication/dm_auth_manager.cpp b/services/implementation/src/authentication/dm_auth_manager.cpp index ce134e4e6..499d82ca4 100644 --- a/services/implementation/src/authentication/dm_auth_manager.cpp +++ b/services/implementation/src/authentication/dm_auth_manager.cpp @@ -61,7 +61,20 @@ int32_t DmAuthManager::AuthenticateDevice(const std::string &pkgName, int32_t au const std::string &extra) { LOGI("DmAuthManager::AuthenticateDevice start auth type %d", authType); + if (authType < DM_AUTH_TYPE_MIN || authType > DM_AUTH_TYPE_MAX) { + LOGE("AuthenticateDevice failed, authType is illegal"); + return ERR_DM_AUTH_FAILED; + } + if (pkgName.empty() || deviceId.empty() || extra.empty()) { + LOGE("DmAuthManager::AuthenticateDevice failed, pkgName is %s, deviceId is %s, extra is %s", + pkgName.c_str(), deviceId.c_str(), extra.c_str()); + return ERR_DM_INPUT_PARAMETER_EMPTY; + } std::shared_ptr authentication = authenticationMap_[authType]; + if (listener_ == nullptr) { + LOGE("DmAuthManager::AuthenticateDevice is empty nullptr"); + return ERR_DM_INPUT_PARAMETER_EMPTY; + } if (authentication == nullptr) { LOGE("DmAuthManager::AuthenticateDevice authType %d not support.", authType); listener_->OnAuthResult(pkgName, deviceId, "", AuthState::AUTH_REQUEST_INIT, ERR_DM_UNSUPPORTED_AUTH_TYPE); @@ -89,7 +102,7 @@ int32_t DmAuthManager::AuthenticateDevice(const std::string &pkgName, int32_t au if (timer_ == nullptr) { timer_ = std::make_shared(); } - timer_->StartTimer(AUTHENTICATE_TIMEOUT_TASK, AUTHENTICATE_TIMEOUT, + timer_->StartTimer(std::string(AUTHENTICATE_TIMEOUT_TASK), AUTHENTICATE_TIMEOUT, [this] (std::string name) { DmAuthManager::HandleAuthenticateTimeout(name); }); @@ -162,7 +175,7 @@ int32_t DmAuthManager::VerifyAuthentication(const std::string &authParam) LOGE("authResponseContext_ is not init"); return ERR_DM_AUTH_NOT_START; } - timer_->DeleteTimer(INPUT_TIMEOUT_TASK); + timer_->DeleteTimer(std::string(INPUT_TIMEOUT_TASK)); int32_t ret = authPtr_->VerifyAuthentication(authResponseContext_->authToken, authParam); switch (ret) { case DM_OK: @@ -193,11 +206,11 @@ void DmAuthManager::OnSessionOpened(int32_t sessionId, int32_t sessionSide, int3 authResponseState_->Enter(); authResponseContext_ = std::make_shared(); timer_ = std::make_shared(); - timer_->StartTimer(AUTHENTICATE_TIMEOUT_TASK, AUTHENTICATE_TIMEOUT, + timer_->StartTimer(std::string(AUTHENTICATE_TIMEOUT_TASK), AUTHENTICATE_TIMEOUT, [this] (std::string name) { DmAuthManager::HandleAuthenticateTimeout(name); }); - timer_->StartTimer(WAIT_NEGOTIATE_TIMEOUT_TASK, WAIT_NEGOTIATE_TIMEOUT, + timer_->StartTimer(std::string(WAIT_NEGOTIATE_TIMEOUT_TASK), WAIT_NEGOTIATE_TIMEOUT, [this] (std::string name) { DmAuthManager::HandleAuthenticateTimeout(name); }); @@ -280,7 +293,7 @@ void DmAuthManager::OnDataReceived(const int32_t sessionId, const std::string me switch (authResponseContext_->msgType) { case MSG_TYPE_NEGOTIATE: if (authResponseState_->GetStateType() == AuthState::AUTH_RESPONSE_INIT) { - timer_->DeleteTimer(WAIT_NEGOTIATE_TIMEOUT_TASK); + timer_->DeleteTimer(std::string(WAIT_NEGOTIATE_TIMEOUT_TASK)); authResponseState_->TransitionTo(std::make_shared()); } else { LOGE("Device manager auth state error"); @@ -288,7 +301,7 @@ void DmAuthManager::OnDataReceived(const int32_t sessionId, const std::string me break; case MSG_TYPE_REQ_AUTH: if (authResponseState_->GetStateType() == AuthState::AUTH_RESPONSE_NEGOTIATE) { - timer_->DeleteTimer(WAIT_REQUEST_TIMEOUT_TASK); + timer_->DeleteTimer(std::string(WAIT_REQUEST_TIMEOUT_TASK)); authResponseState_->TransitionTo(std::make_shared()); } else { LOGE("Device manager auth state error"); @@ -351,14 +364,14 @@ void DmAuthManager::OnMemberJoin(int64_t requestId, int32_t status) LOGI("DmAuthManager OnMemberJoin start authTimes %d", authTimes_); if (authRequestState_ != nullptr) { authTimes_++; - timer_->DeleteTimer(ADD_TIMEOUT_TASK); + timer_->DeleteTimer(std::string(ADD_TIMEOUT_TASK)); if (status != DM_OK || authResponseContext_->requestId != requestId) { if (authRequestState_ != nullptr && authTimes_ >= MAX_AUTH_TIMES) { authResponseContext_->state = AuthState::AUTH_REQUEST_JOIN; authRequestContext_->reason = ERR_DM_INPUT_PARAMETER_EMPTY; authRequestState_->TransitionTo(std::make_shared()); } else { - timer_->StartTimer(INPUT_TIMEOUT_TASK, INPUT_TIMEOUT, + timer_->StartTimer(std::string(INPUT_TIMEOUT_TASK), INPUT_TIMEOUT, [this] (std::string name) { DmAuthManager::HandleAuthenticateTimeout(name); }); @@ -421,7 +434,7 @@ void DmAuthManager::StartNegotiate(const int32_t &sessionId) authMessageProcessor_->SetResponseContext(authResponseContext_); std::string message = authMessageProcessor_->CreateSimpleMessage(MSG_TYPE_NEGOTIATE); softbusConnector_->GetSoftbusSession()->SendData(sessionId, message); - timer_->StartTimer(NEGOTIATE_TIMEOUT_TASK, NEGOTIATE_TIMEOUT, + timer_->StartTimer(std::string(NEGOTIATE_TIMEOUT_TASK), NEGOTIATE_TIMEOUT, [this] (std::string name) { DmAuthManager::HandleAuthenticateTimeout(name); }); @@ -469,7 +482,7 @@ void DmAuthManager::RespNegotiate(const int32_t &sessionId) jsonObject[TAG_CRYPTO_SUPPORT] = false; message = jsonObject.dump(); softbusConnector_->GetSoftbusSession()->SendData(sessionId, message); - timer_->StartTimer(WAIT_REQUEST_TIMEOUT_TASK, WAIT_REQUEST_TIMEOUT, + timer_->StartTimer(std::string(WAIT_REQUEST_TIMEOUT_TASK), WAIT_REQUEST_TIMEOUT, [this] (std::string name) { DmAuthManager::HandleAuthenticateTimeout(name); }); @@ -482,7 +495,7 @@ void DmAuthManager::SendAuthRequest(const int32_t &sessionId) return; } LOGI("DmAuthManager::EstablishAuthChannel session id"); - timer_->DeleteTimer(NEGOTIATE_TIMEOUT_TASK); + timer_->DeleteTimer(std::string(NEGOTIATE_TIMEOUT_TASK)); if (authResponseContext_->cryptoSupport) { isCryptoSupport_ = true; } @@ -494,7 +507,7 @@ void DmAuthManager::SendAuthRequest(const int32_t &sessionId) for (auto msg : messageList) { softbusConnector_->GetSoftbusSession()->SendData(sessionId, msg); } - timer_->StartTimer(CONFIRM_TIMEOUT_TASK, CONFIRM_TIMEOUT, + timer_->StartTimer(std::string(CONFIRM_TIMEOUT_TASK), CONFIRM_TIMEOUT, [this] (std::string name) { DmAuthManager::HandleAuthenticateTimeout(name); }); @@ -526,9 +539,9 @@ void DmAuthManager::StartRespAuthProcess() return; } LOGI("DmAuthManager::StartRespAuthProcess", authResponseContext_->sessionId); - timer_->DeleteTimer(CONFIRM_TIMEOUT_TASK); + timer_->DeleteTimer(std::string(CONFIRM_TIMEOUT_TASK)); if (authResponseContext_->reply == USER_OPERATION_TYPE_ALLOW_AUTH) { - timer_->StartTimer(INPUT_TIMEOUT_TASK, INPUT_TIMEOUT, + timer_->StartTimer(std::string(INPUT_TIMEOUT_TASK), INPUT_TIMEOUT, [this] (std::string name) { DmAuthManager::HandleAuthenticateTimeout(name); }); @@ -561,7 +574,7 @@ int32_t DmAuthManager::AddMember(int32_t pinCode) return ERR_DM_FAILED; } LOGI("DmAuthManager::AddMember start group id %s", authResponseContext_->groupId.c_str()); - timer_->DeleteTimer(INPUT_TIMEOUT_TASK); + timer_->DeleteTimer(std::string(INPUT_TIMEOUT_TASK)); nlohmann::json jsonObject; jsonObject[TAG_GROUP_ID] = authResponseContext_->groupId; jsonObject[TAG_GROUP_NAME] = authResponseContext_->groupName; @@ -569,7 +582,7 @@ int32_t DmAuthManager::AddMember(int32_t pinCode) jsonObject[TAG_REQUEST_ID] = authResponseContext_->requestId; jsonObject[TAG_DEVICE_ID] = authResponseContext_->deviceId; std::string connectInfo = jsonObject.dump(); - timer_->StartTimer(ADD_TIMEOUT_TASK, ADD_TIMEOUT, + timer_->StartTimer(std::string(ADD_TIMEOUT_TASK), ADD_TIMEOUT, [this] (std::string name) { DmAuthManager::HandleAuthenticateTimeout(name); }); @@ -595,7 +608,7 @@ int32_t DmAuthManager::JoinNetwork() return ERR_DM_FAILED; } LOGI("DmAuthManager JoinNetwork start"); - timer_->DeleteTimer(AUTHENTICATE_TIMEOUT_TASK); + timer_->DeleteTimer(std::string(AUTHENTICATE_TIMEOUT_TASK)); authResponseContext_->state = AuthState::AUTH_REQUEST_FINISH; authRequestContext_->reason = DM_OK; authRequestState_->TransitionTo(std::make_shared()); diff --git a/services/implementation/src/authentication/showconfirm/standard/show_confirm.cpp b/services/implementation/src/authentication/showconfirm/standard/show_confirm.cpp index e7c59fb74..497264d82 100644 --- a/services/implementation/src/authentication/showconfirm/standard/show_confirm.cpp +++ b/services/implementation/src/authentication/showconfirm/standard/show_confirm.cpp @@ -48,7 +48,7 @@ void ShowConfirm::ShowConfirmDialog(const std::string ¶ms, std::shared_ptrSetPageId(id); } else { diff --git a/services/implementation/src/config/dm_config_manager.cpp b/services/implementation/src/config/dm_config_manager.cpp index 3de12c2fa..4e07cfc3d 100644 --- a/services/implementation/src/config/dm_config_manager.cpp +++ b/services/implementation/src/config/dm_config_manager.cpp @@ -72,12 +72,11 @@ DmConfigManager::DmConfigManager() LOGE("adapter json config string parse error"); break; } - const char *jsonKey = ADAPTER_LOAD_JSON_KEY.c_str(); - if (!adapterJsonObject.contains(jsonKey)) { + if (!adapterJsonObject.contains(ADAPTER_LOAD_JSON_KEY)) { LOGE("adapter json config string key not exist"); break; } - auto soLoadInfo = adapterJsonObject[jsonKey].get>(); + auto soLoadInfo = adapterJsonObject[ADAPTER_LOAD_JSON_KEY].get>(); for (uint32_t i = 0; i < soLoadInfo.size(); i++) { if (soLoadInfo[i].name.size() == 0 || soLoadInfo[i].type.size() == 0 || soLoadInfo[i].version.size() == 0 || soLoadInfo[i].funcName.size() == 0 || soLoadInfo[i].soName.size() == 0 || @@ -85,7 +84,7 @@ DmConfigManager::DmConfigManager() LOGE("adapter json config string exist invalid members"); continue; } - soLoadInfo[i].soPath = LIB_LOAD_PATH; + soLoadInfo[i].soPath = std::string(LIB_LOAD_PATH); soAdapterLoadInfo_[soLoadInfo[i].soName] = soLoadInfo[i]; LOGI("soAdapterLoadInfo name is: %s", soLoadInfo[i].name.c_str()); LOGI("soAdapterLoadInfo type is: %s", soLoadInfo[i].type.c_str()); @@ -102,12 +101,11 @@ DmConfigManager::DmConfigManager() LOGE("auth json config string parse error!\n"); break; } - const char *jsonKey = AUTH_LOAD_JSON_KEY.c_str(); - if (!authJsonObject.contains(jsonKey)) { + if (!authJsonObject.contains(AUTH_LOAD_JSON_KEY)) { LOGE("auth json config string key not exist!\n"); break; } - auto soLoadInfo = authJsonObject[jsonKey].get>(); + auto soLoadInfo = authJsonObject[AUTH_LOAD_JSON_KEY].get>(); for (uint32_t i = 0; i < soLoadInfo.size(); i++) { if (soLoadInfo[i].name.size() == 0 || soLoadInfo[i].type.size() == 0 || soLoadInfo[i].version.size() == 0 || soLoadInfo[i].funcName.size() == 0 || soLoadInfo[i].soName.size() == 0 || @@ -115,7 +113,7 @@ DmConfigManager::DmConfigManager() LOGE("adapter json config string exist invalid members"); continue; } - soLoadInfo[i].soPath = LIB_LOAD_PATH; + soLoadInfo[i].soPath = std::string(LIB_LOAD_PATH); soAuthLoadInfo_[soLoadInfo[i].authType] = soLoadInfo[i]; LOGI("soAuthLoadInfo name is: %s", soLoadInfo[i].name.c_str()); LOGI("soAuthLoadInfo type is: %s", soLoadInfo[i].type.c_str()); @@ -155,7 +153,7 @@ std::shared_ptr DmConfigManager::GetDecisionAdapter(const std: return nullptr; } auto soInfoIter = soAdapterLoadInfo_.find(soName); - if (soInfoIter == soAdapterLoadInfo_.end() || (soInfoIter->second).type != DECISION_JSON_TYPE_KEY) { + if (soInfoIter == soAdapterLoadInfo_.end() || (soInfoIter->second).type != std::string(DECISION_JSON_TYPE_KEY)) { LOGE("not find so info or type key not match"); return nullptr; } @@ -193,7 +191,7 @@ std::shared_ptr DmConfigManager::GetProfileAdapter(const std::s } auto soInfoIter = soAdapterLoadInfo_.find(soName); - if (soInfoIter == soAdapterLoadInfo_.end() || (soInfoIter->second).type != PROFILE_JSON_TYPE_KEY) { + if (soInfoIter == soAdapterLoadInfo_.end() || (soInfoIter->second).type != std::string(PROFILE_JSON_TYPE_KEY)) { LOGE("not find so info or type key not match"); return nullptr; } @@ -231,7 +229,7 @@ std::shared_ptr DmConfigManager::GetCryptoAdapter(const std::str } auto soInfoIter = soAdapterLoadInfo_.find(soName); - if (soInfoIter == soAdapterLoadInfo_.end() || (soInfoIter->second).type != CPYPTO_JSON_TYPE_KEY) { + if (soInfoIter == soAdapterLoadInfo_.end() || (soInfoIter->second).type != std::string(CPYPTO_JSON_TYPE_KEY)) { LOGE("not find so info or type key not match"); return nullptr; } @@ -269,7 +267,7 @@ void DmConfigManager::GetAuthAdapter(std::mapsecond).type != AUTH_JSON_TYPE_KEY) { + if ((iter->second).type != std::string(AUTH_JSON_TYPE_KEY)) { LOGE("type key not match"); continue; } diff --git a/services/implementation/src/credential/dm_credential_manager.cpp b/services/implementation/src/credential/dm_credential_manager.cpp index c600471ce..ab2c3f7d2 100644 --- a/services/implementation/src/credential/dm_credential_manager.cpp +++ b/services/implementation/src/credential/dm_credential_manager.cpp @@ -147,13 +147,13 @@ int32_t DmCredentialManager::ImportLocalCredential(const std::string &credential } std::string userId = jsonObject[FIELD_USER_ID]; requestId_ = GenRandLongLong(MIN_REQUEST_ID, MAX_REQUEST_ID); - nlohmann::json creArray = jsonObject[FIELD_CREDENTIAL_DATA.c_str()]; + nlohmann::json creArray = jsonObject[FIELD_CREDENTIAL_DATA]; if (!creArray.is_array()) { LOGI("ImportLocalCredential credentialData is not a array object!"); return ERR_DM_FAILED; } std::vector vecCredentialData = - jsonObject[FIELD_CREDENTIAL_DATA.c_str()].get>(); + jsonObject[FIELD_CREDENTIAL_DATA].get>(); if (vecCredentialData.size() != 1) { LOGI("ImportLocalCredential credentialData err"); return ERR_DM_FAILED; diff --git a/services/implementation/src/dependency/hichain/hichain_connector.cpp b/services/implementation/src/dependency/hichain/hichain_connector.cpp index 29d2a9be4..be896d0dc 100644 --- a/services/implementation/src/dependency/hichain/hichain_connector.cpp +++ b/services/implementation/src/dependency/hichain/hichain_connector.cpp @@ -15,14 +15,14 @@ #include "hichain_connector.h" -#include - #include #include #include +#include #include "dm_anonymous.h" #include "dm_constants.h" +#include "dm_dfx_constants.h" #include "dm_hisysevent.h" #include "dm_log.h" #include "dm_random.h" @@ -30,6 +30,7 @@ #include "multiple_user_connector.h" #include "nlohmann/json.hpp" #include "parameter.h" +#include "unistd.h" namespace OHOS { namespace DistributedHardware { @@ -81,7 +82,7 @@ HiChainConnector::HiChainConnector() LOGI("HiChainConnector::constructor, failed to init group manager!"); return; } - deviceGroupManager_->regCallback(DM_PKG_NAME.c_str(), &deviceAuthCallback_); + deviceGroupManager_->regCallback(DM_PKG_NAME, &deviceAuthCallback_); LOGI("HiChainConnector::constructor success."); } @@ -130,7 +131,7 @@ int32_t HiChainConnector::CreateGroup(int64_t requestId, const std::string &grou return ERR_DM_FAILED; } - int32_t ret = deviceGroupManager_->createGroup(userId, requestId, DM_PKG_NAME.c_str(), jsonObj.dump().c_str()); + int32_t ret = deviceGroupManager_->createGroup(userId, requestId, DM_PKG_NAME, jsonObj.dump().c_str()); if (ret != 0) { LOGE("Failed to start CreateGroup task, ret: %d, requestId %lld.", ret, requestId); return ERR_DM_CREATE_GROUP_FAILED; @@ -182,7 +183,7 @@ bool HiChainConnector::GetGroupInfo(const std::string &queryParams, std::vector< LOGE("get current process account user id failed"); return false; } - int32_t ret = deviceGroupManager_->getGroupInfo(userId, DM_PKG_NAME.c_str(), queryParams.c_str(), &groupVec, &num); + int32_t ret = deviceGroupManager_->getGroupInfo(userId, DM_PKG_NAME, queryParams.c_str(), &groupVec, &num); if (ret != 0) { LOGE("HiChainConnector::GetGroupInfo failed , ret: %d.", ret); return false; @@ -217,7 +218,7 @@ int32_t HiChainConnector::GetGroupInfo(const int32_t userId, const std::string & { char *groupVec = nullptr; uint32_t num = 0; - int32_t ret = deviceGroupManager_->getGroupInfo(userId, DM_PKG_NAME.c_str(), queryParams.c_str(), &groupVec, &num); + int32_t ret = deviceGroupManager_->getGroupInfo(userId, DM_PKG_NAME, queryParams.c_str(), &groupVec, &num); if (ret != 0) { LOGE("HiChainConnector::GetGroupInfo failed , ret: %d.", ret); return false; @@ -280,7 +281,7 @@ int32_t HiChainConnector::AddMember(const std::string &deviceId, const std::stri LOGE("get current process account user id failed"); return ERR_DM_FAILED; } - int32_t ret = deviceGroupManager_->addMemberToGroup(userId, requestId, DM_PKG_NAME.c_str(), tmpStr.c_str()); + int32_t ret = deviceGroupManager_->addMemberToGroup(userId, requestId, DM_PKG_NAME, tmpStr.c_str()); LOGI("HiChainConnector::AddMember completed"); return ret; } @@ -294,14 +295,16 @@ void HiChainConnector::onFinish(int64_t requestId, int operationCode, const char LOGI("HiChainConnector::onFinish reqId:%lld, operation:%d", requestId, operationCode); if (operationCode == GroupOperationCode::MEMBER_JOIN) { LOGI("Add Member To Group success"); - SysEventWrite(ADD_HICHAIN_GROUP_SUCCESS, DM_HISYEVENT_BEHAVIOR, ADD_HICHAIN_GROUP_SUCCESS_MSG); + SysEventWrite(std::string(ADD_HICHAIN_GROUP_SUCCESS), DM_HISYEVENT_BEHAVIOR, + std::string(ADD_HICHAIN_GROUP_SUCCESS_MSG)); if (hiChainConnectorCallback_ != nullptr) { hiChainConnectorCallback_->OnMemberJoin(requestId, DM_OK); } } if (operationCode == GroupOperationCode::GROUP_CREATE) { LOGI("Create group success"); - SysEventWrite(DM_CREATE_GROUP_SUCCESS, DM_HISYEVENT_BEHAVIOR, DM_CREATE_GROUP_SUCCESS_MSG); + SysEventWrite(std::string(DM_CREATE_GROUP_SUCCESS), DM_HISYEVENT_BEHAVIOR, + std::string(DM_CREATE_GROUP_SUCCESS_MSG)); if (networkStyle_ == CREDENTIAL_NETWORK) { if (hiChainResCallback_ != nullptr) { int32_t importAction = 0; @@ -339,14 +342,16 @@ void HiChainConnector::onError(int64_t requestId, int operationCode, int errorCo LOGI("HichainAuthenCallBack::onError reqId:%lld, operation:%d, errorCode:%d.", requestId, operationCode, errorCode); if (operationCode == GroupOperationCode::MEMBER_JOIN) { LOGE("Add Member To Group failed"); - SysEventWrite(ADD_HICHAIN_GROUP_FAILED, DM_HISYEVENT_BEHAVIOR, ADD_HICHAIN_GROUP_FAILED_MSG); + SysEventWrite(std::string(ADD_HICHAIN_GROUP_FAILED), DM_HISYEVENT_BEHAVIOR, + std::string(ADD_HICHAIN_GROUP_FAILED_MSG)); if (hiChainConnectorCallback_ != nullptr) { hiChainConnectorCallback_->OnMemberJoin(requestId, ERR_DM_FAILED); } } if (operationCode == GroupOperationCode::GROUP_CREATE) { LOGE("Create group failed"); - SysEventWrite(DM_CREATE_GROUP_FAILED, DM_HISYEVENT_BEHAVIOR, DM_CREATE_GROUP_FAILED_MSG); + SysEventWrite(std::string(DM_CREATE_GROUP_FAILED), DM_HISYEVENT_BEHAVIOR, + std::string(DM_CREATE_GROUP_FAILED_MSG)); if (networkStyle_ == CREDENTIAL_NETWORK) { if (hiChainResCallback_ != nullptr) { int32_t importAction = 0; @@ -435,7 +440,7 @@ int32_t HiChainConnector::GetRelatedGroups(const std::string &deviceId, std::vec return ERR_DM_FAILED; } int32_t ret = - deviceGroupManager_->getRelatedGroups(userId, DM_PKG_NAME.c_str(), deviceId.c_str(), &returnGroups, &groupNum); + deviceGroupManager_->getRelatedGroups(userId, DM_PKG_NAME, deviceId.c_str(), &returnGroups, &groupNum); if (ret != 0) { LOGE("HiChainConnector::GetRelatedGroups failed , ret: %d.", ret); return ERR_DM_FAILED; @@ -499,7 +504,7 @@ bool HiChainConnector::IsDevicesInGroup(const std::string &hostDevice, const std bool HiChainConnector::IsGroupInfoInvalid(GroupInfo &group) { if (group.groupType == GROUP_TYPE_IDENTICAL_ACCOUNT_GROUP || group.groupVisibility == GROUP_VISIBILITY_PUBLIC || - group.groupOwner != DM_PKG_NAME) { + group.groupOwner != std::string(DM_PKG_NAME)) { return true; } return false; @@ -535,8 +540,7 @@ int32_t HiChainConnector::DelMemberFromGroup(const std::string &groupId, const s LOGE("get current process account user id failed"); return ERR_DM_FAILED; } - int32_t ret = deviceGroupManager_->deleteMemberFromGroup(userId, requestId, - DM_PKG_NAME.c_str(), deleteParams.c_str()); + int32_t ret = deviceGroupManager_->deleteMemberFromGroup(userId, requestId, DM_PKG_NAME, deleteParams.c_str()); if (ret != 0) { LOGE("HiChainConnector::DelMemberFromGroup failed , ret: %d.", ret); return ret; @@ -556,7 +560,7 @@ int32_t HiChainConnector::DeleteGroup(std::string &groupId) return ERR_DM_FAILED; } - int32_t ret = deviceGroupManager_->deleteGroup(userId, requestId, DM_PKG_NAME.c_str(), disbandParams.c_str()); + int32_t ret = deviceGroupManager_->deleteGroup(userId, requestId, DM_PKG_NAME, disbandParams.c_str()); if (ret != 0) { LOGE("HiChainConnector::DeleteGroup failed , ret: %d.", ret); return ERR_DM_FAILED; @@ -570,7 +574,7 @@ int32_t HiChainConnector::DeleteGroup(const int32_t userId, std::string &groupId nlohmann::json jsonObj; jsonObj[FIELD_GROUP_ID] = groupId; std::string disbandParams = jsonObj.dump(); - int32_t ret = deviceGroupManager_->deleteGroup(userId, requestId, DM_PKG_NAME.c_str(), disbandParams.c_str()); + int32_t ret = deviceGroupManager_->deleteGroup(userId, requestId, DM_PKG_NAME, disbandParams.c_str()); if (ret != 0) { LOGE("HiChainConnector::DeleteGroup failed , ret: %d.", ret); return ERR_DM_FAILED; @@ -611,7 +615,7 @@ int32_t HiChainConnector::DeleteGroup(int64_t requestId_, const std::string &use LOGE("get current process account user id failed"); return ERR_DM_FAILED; } - int32_t ret = deviceGroupManager_->deleteGroup(osAccountUserId, requestId_, DM_PKG_NAME.c_str(), + int32_t ret = deviceGroupManager_->deleteGroup(osAccountUserId, requestId_, DM_PKG_NAME, disbandParams.c_str()); if (ret != 0) { LOGE("HiChainConnector::DeleteGroup failed , ret: %d.", ret); @@ -641,7 +645,7 @@ int32_t HiChainConnector::DeleteTimeOutGroup(const char* deviceId) char localDeviceId[DEVICE_UUID_LENGTH] = {0}; GetDevUdid(localDeviceId, DEVICE_UUID_LENGTH); for (auto &group : peerGroupInfoList) { - if (deviceGroupManager_->isDeviceInGroup(userId, DM_PKG_NAME.c_str(), group.groupId.c_str(), localDeviceId)) { + if (deviceGroupManager_->isDeviceInGroup(userId, DM_PKG_NAME, group.groupId.c_str(), localDeviceId)) { DeleteGroup(group.groupId); return DM_OK; } @@ -707,8 +711,7 @@ int32_t HiChainConnector::CreateGroup(int64_t requestId, int32_t authType, const return ERR_DM_FAILED; } LOGI("[DM] createParams:%s", jsonObj.dump().c_str()); - int32_t ret = deviceGroupManager_->createGroup(osAccountUserId, requestId, DM_PKG_NAME.c_str(), - jsonObj.dump().c_str()); + int32_t ret = deviceGroupManager_->createGroup(osAccountUserId, requestId, DM_PKG_NAME, jsonObj.dump().c_str()); if (ret != DM_OK) { LOGE("Failed to start CreateGroup task, ret: %d, requestId %lld.", ret, requestId); return ERR_DM_CREATE_GROUP_FAILED; @@ -814,8 +817,7 @@ int32_t HiChainConnector::addMultiMembers(const int32_t groupType, const std::st return ERR_DM_FAILED; } - int32_t ret = deviceGroupManager_->addMultiMembersToGroup(osAccountUserId, - DM_PKG_NAME.c_str(), addParams.c_str()); + int32_t ret = deviceGroupManager_->addMultiMembersToGroup(osAccountUserId, DM_PKG_NAME, addParams.c_str()); if (ret!= DM_OK) { LOGE("HiChainConnector::addMultiMemberstoGroup failure! ret=%d", ret); return ret; @@ -838,8 +840,7 @@ int32_t HiChainConnector::deleteMultiMembers(const int32_t groupType, const std: return ERR_DM_FAILED; } - int32_t ret = deviceGroupManager_->delMultiMembersFromGroup(osAccountUserId, - DM_PKG_NAME.c_str(), deleteParams.c_str()); + int32_t ret = deviceGroupManager_->delMultiMembersFromGroup(osAccountUserId, DM_PKG_NAME, deleteParams.c_str()); if (ret != DM_OK) { LOGE("HiChainConnector::deleteMultiMembers failure!, ret=%d", ret); return ret; diff --git a/services/implementation/src/dependency/softbus/softbus_connector.cpp b/services/implementation/src/dependency/softbus/softbus_connector.cpp index 606101371..1f9172c12 100644 --- a/services/implementation/src/dependency/softbus/softbus_connector.cpp +++ b/services/implementation/src/dependency/softbus/softbus_connector.cpp @@ -86,7 +86,7 @@ int32_t SoftbusConnector::StartDiscovery(const DmSubscribeInfo &dmSubscribeInfo) subscribeInfo.capability = dmSubscribeInfo.capability; subscribeInfo.capabilityData = nullptr; subscribeInfo.dataLen = 0; - int32_t ret = ::StartDiscovery(DM_PKG_NAME.c_str(), &subscribeInfo, &softbusDiscoveryCallback_); + int32_t ret = ::StartDiscovery(DM_PKG_NAME, &subscribeInfo, &softbusDiscoveryCallback_); if (ret != 0) { LOGE("StartDiscovery failed with ret %d.", ret); return ERR_DM_DISCOVERY_FAILED; @@ -97,7 +97,7 @@ int32_t SoftbusConnector::StartDiscovery(const DmSubscribeInfo &dmSubscribeInfo) int32_t SoftbusConnector::StopDiscovery(uint16_t subscribeId) { LOGI("StopDiscovery begin, subscribeId:%d", (int32_t)subscribeId); - int32_t ret = ::StopDiscovery(DM_PKG_NAME.c_str(), subscribeId); + int32_t ret = ::StopDiscovery(DM_PKG_NAME, subscribeId); if (ret != 0) { LOGE("StopDiscovery failed with ret %d", ret); return ERR_DM_DISCOVERY_FAILED; @@ -111,7 +111,7 @@ int32_t SoftbusConnector::GetUdidByNetworkId(const char *networkId, std::string LOGI("GetUdidByNetworkId begin"); uint8_t mUdid[UDID_BUF_LEN] = {0}; int32_t ret = - GetNodeKeyInfo(DM_PKG_NAME.c_str(), networkId, NodeDeviceInfoKey::NODE_KEY_UDID, mUdid, sizeof(mUdid)); + GetNodeKeyInfo(DM_PKG_NAME, networkId, NodeDeviceInfoKey::NODE_KEY_UDID, mUdid, sizeof(mUdid)); if (ret != DM_OK) { LOGE("GetUdidByNetworkId GetNodeKeyInfo failed"); return ERR_DM_FAILED; @@ -126,7 +126,7 @@ int32_t SoftbusConnector::GetUuidByNetworkId(const char *networkId, std::string LOGI("GetUuidByNetworkId begin"); uint8_t mUuid[UUID_BUF_LEN] = {0}; int32_t ret = - GetNodeKeyInfo(DM_PKG_NAME.c_str(), networkId, NodeDeviceInfoKey::NODE_KEY_UUID, mUuid, sizeof(mUuid)); + GetNodeKeyInfo(DM_PKG_NAME, networkId, NodeDeviceInfoKey::NODE_KEY_UUID, mUuid, sizeof(mUuid)); if (ret != DM_OK) { LOGE("GetUuidByNetworkId GetNodeKeyInfo failed"); return ERR_DM_FAILED; @@ -140,7 +140,7 @@ bool SoftbusConnector::IsDeviceOnLine(const std::string &deviceId) { NodeBasicInfo *info = nullptr; int32_t infoNum = 0; - if (GetAllNodeDeviceInfo(DM_PKG_NAME.c_str(), &info, &infoNum) != DM_OK) { + if (GetAllNodeDeviceInfo(DM_PKG_NAME, &info, &infoNum) != DM_OK) { LOGE("GetAllNodeDeviceInfo failed"); return false; } @@ -158,7 +158,7 @@ bool SoftbusConnector::IsDeviceOnLine(const std::string &deviceId) break; } uint8_t udid[UDID_BUF_LEN] = {0}; - int32_t ret = GetNodeKeyInfo(DM_PKG_NAME.c_str(), networkId.c_str(), NodeDeviceInfoKey::NODE_KEY_UDID, udid, + int32_t ret = GetNodeKeyInfo(DM_PKG_NAME, networkId.c_str(), NodeDeviceInfoKey::NODE_KEY_UDID, udid, sizeof(udid)); if (ret != DM_OK) { LOGE("DM_IsDeviceOnLine GetNodeKeyInfo failed"); @@ -308,7 +308,7 @@ void SoftbusConnector::HandleDeviceOnline(const DmDeviceInfo &info) } uint8_t udid[UDID_BUF_LEN] = {0}; int32_t ret = - GetNodeKeyInfo(DM_PKG_NAME.c_str(), info.networkId, NodeDeviceInfoKey::NODE_KEY_UDID, udid, sizeof(udid)); + GetNodeKeyInfo(DM_PKG_NAME, info.networkId, NodeDeviceInfoKey::NODE_KEY_UDID, udid, sizeof(udid)); if (ret != DM_OK) { LOGE("GetNodeKeyInfo failed"); return; diff --git a/services/implementation/src/dependency/softbus/softbus_session.cpp b/services/implementation/src/dependency/softbus/softbus_session.cpp index 7a49e6cdd..a4423e7d7 100644 --- a/services/implementation/src/dependency/softbus/softbus_session.cpp +++ b/services/implementation/src/dependency/softbus/softbus_session.cpp @@ -17,6 +17,7 @@ #include "dm_anonymous.h" #include "dm_constants.h" +#include "dm_dfx_constants.h" #include "dm_hitrace.h" #include "dm_log.h" #include "nlohmann/json.hpp" @@ -49,7 +50,7 @@ int32_t SoftbusSession::UnRegisterSessionCallback() int32_t SoftbusSession::OpenAuthSession(const std::string &deviceId) { LOGI("SoftbusSession::OpenAuthSession"); - DmTraceStart(DM_HITRACE_AUTH_TO_OPPEN_SESSION); + DmTraceStart(std::string(DM_HITRACE_AUTH_TO_OPPEN_SESSION)); int32_t sessionId = -1; std::string connectAddr; ConnectionAddr *addrInfo = SoftbusConnector::GetConnectAddr(deviceId, connectAddr); @@ -57,7 +58,7 @@ int32_t SoftbusSession::OpenAuthSession(const std::string &deviceId) LOGE("GetConnectAddr error"); return sessionId; } - sessionId = ::OpenAuthSession(DM_SESSION_NAME.c_str(), addrInfo, 1, nullptr); + sessionId = ::OpenAuthSession(DM_SESSION_NAME, addrInfo, 1, nullptr); if (sessionId < 0) { LOGE("open session error, ret:%d", sessionId); return sessionId; diff --git a/services/implementation/src/device_manager_service_impl.cpp b/services/implementation/src/device_manager_service_impl.cpp index ad4a51811..9a6d68b41 100644 --- a/services/implementation/src/device_manager_service_impl.cpp +++ b/services/implementation/src/device_manager_service_impl.cpp @@ -159,13 +159,14 @@ int32_t DeviceManagerServiceImpl::AuthenticateDevice(const std::string &pkgName, LOGI("The caller does not have permission to call"); return ERR_DM_NO_PERMISSION; } - if (pkgName.empty()) { - LOGE("AuthenticateDevice failed, pkgName is empty"); + if (pkgName.empty() || deviceId.empty() || extra.empty()) { + LOGE("DeviceManagerServiceImpl::AuthenticateDevice failed, pkgName is %s, deviceId is %s, extra is %s", + pkgName.c_str(), deviceId.c_str(), extra.c_str()); return ERR_DM_INPUT_PARAMETER_EMPTY; } - if (deviceId.empty()) { - LOGE("AuthenticateDevice failed, deviceId is empty"); - return ERR_DM_INPUT_PARAMETER_EMPTY; + if (authType < DM_AUTH_TYPE_MIN || authType > DM_AUTH_TYPE_MAX) { + LOGE("AuthenticateDevice failed, authType is illegal"); + return ERR_DM_UNSUPPORTED_AUTH_TYPE; } return authMgr_->AuthenticateDevice(pkgName, authType, deviceId, extra); } @@ -176,12 +177,9 @@ int32_t DeviceManagerServiceImpl::UnAuthenticateDevice(const std::string &pkgNam LOGI("The caller does not have permission to call"); return ERR_DM_NO_PERMISSION; } - if (pkgName.empty()) { - LOGE("UnAuthenticateDevice failed, pkgName is empty"); - return ERR_DM_INPUT_PARAMETER_EMPTY; - } - if (deviceId.empty()) { - LOGE("UnAuthenticateDevice failed, deviceId is empty"); + if (pkgName.empty() || deviceId.empty()) { + LOGE("DeviceManagerServiceImpl::AuthenticateDevice failed, pkgName is %s, deviceId is %s", + pkgName.c_str(), deviceId.c_str()); return ERR_DM_INPUT_PARAMETER_EMPTY; } return authMgr_->UnAuthenticateDevice(pkgName, deviceId); @@ -288,12 +286,9 @@ int32_t DeviceManagerServiceImpl::RequestCredential(const std::string &reqJsonSt int32_t DeviceManagerServiceImpl::ImportCredential(const std::string &pkgName, const std::string &credentialInfo) { - if (pkgName.empty()) { - LOGE("ImportCredential failed, pkgName is empty"); - return ERR_DM_INPUT_PARAMETER_EMPTY; - } - if (credentialInfo.empty()) { - LOGE("credentialInfo is empty"); + if (pkgName.empty() || credentialInfo.empty()) { + LOGE("DeviceManagerServiceImpl::ImportCredential failed, pkgName is %s, credentialInfo is %s", + pkgName.c_str(), credentialInfo.c_str()); return ERR_DM_INPUT_PARAMETER_EMPTY; } if (credentialMgr_== nullptr) { @@ -305,12 +300,9 @@ int32_t DeviceManagerServiceImpl::ImportCredential(const std::string &pkgName, c int32_t DeviceManagerServiceImpl::DeleteCredential(const std::string &pkgName, const std::string &deleteInfo) { - if (pkgName.empty()) { - LOGE("DeleteCredential failed, pkgName is empty"); - return ERR_DM_INPUT_PARAMETER_EMPTY; - } - if (deleteInfo.empty()) { - LOGE("deleteInfo is empty"); + if (pkgName.empty() || deleteInfo.empty()) { + LOGE("DeviceManagerServiceImpl::DeleteCredential failed, pkgName is %s, deleteInfo is %s", + pkgName.c_str(), deleteInfo.c_str()); return ERR_DM_INPUT_PARAMETER_EMPTY; } if (credentialMgr_== nullptr) { @@ -351,4 +343,4 @@ extern "C" IDeviceManagerServiceImpl *CreateDMServiceObject(void) return new DeviceManagerServiceImpl; } } // namespace DistributedHardware -} // namespace OHOS \ No newline at end of file +} // namespace OHOS diff --git a/services/implementation/src/devicestate/dm_device_state_manager.cpp b/services/implementation/src/devicestate/dm_device_state_manager.cpp index 1032a6a0f..75cf5d8ef 100644 --- a/services/implementation/src/devicestate/dm_device_state_manager.cpp +++ b/services/implementation/src/devicestate/dm_device_state_manager.cpp @@ -212,7 +212,7 @@ void DmDeviceStateManager::OnProfileReady(const std::string &pkgName, const std: int32_t DmDeviceStateManager::RegisterSoftbusStateCallback() { if (softbusConnector_ != nullptr) { - return softbusConnector_->RegisterSoftbusStateCallback(DM_PKG_NAME, shared_from_this()); + return softbusConnector_->RegisterSoftbusStateCallback(std::string(DM_PKG_NAME), shared_from_this()); } return DM_OK; } @@ -270,7 +270,7 @@ void DmDeviceStateManager::RegisterOffLineTimer(const DmDeviceInfo &deviceInfo) if (timer_ == nullptr) { timer_ = std::make_shared(); } - std::string timerName = TIMER_PREFIX + STATE_TIMER_PREFIX + std::to_string(cumulativeQuantity_++); + std::string timerName = std::string(STATE_TIMER_PREFIX) + std::to_string(cumulativeQuantity_++); StateTimerInfo stateTimer = { .timerName = timerName, .netWorkId = deviceInfo.deviceId, diff --git a/services/implementation/src/discovery/dm_discovery_manager.cpp b/services/implementation/src/discovery/dm_discovery_manager.cpp index 9dd3bdbfb..9c2908958 100644 --- a/services/implementation/src/discovery/dm_discovery_manager.cpp +++ b/services/implementation/src/discovery/dm_discovery_manager.cpp @@ -21,7 +21,7 @@ namespace OHOS { namespace DistributedHardware { -const std::string DISCOVERY_TIMEOUT_TASK = TIMER_PREFIX + "discovery"; +constexpr const char* DISCOVERY_TIMEOUT_TASK = "deviceManagerTimer:discovery"; const int32_t DISCOVERY_TIMEOUT = 120; DmDiscoveryManager::DmDiscoveryManager(std::shared_ptr softbusConnector, @@ -58,7 +58,7 @@ int32_t DmDiscoveryManager::StartDeviceDiscovery(const std::string &pkgName, con if (timer_ == nullptr) { timer_ = std::make_shared(); } - timer_->StartTimer(DISCOVERY_TIMEOUT_TASK, DISCOVERY_TIMEOUT, + timer_->StartTimer(std::string(DISCOVERY_TIMEOUT_TASK), DISCOVERY_TIMEOUT, [this] (std::string name) { DmDiscoveryManager::HandleDiscoveryTimeout(name); }); @@ -74,7 +74,7 @@ int32_t DmDiscoveryManager::StopDeviceDiscovery(const std::string &pkgName, uint if (!discoveryContextMap_.empty()) { discoveryContextMap_.erase(pkgName); softbusConnector_->UnRegisterSoftbusDiscoveryCallback(pkgName); - timer_->DeleteTimer(DISCOVERY_TIMEOUT_TASK); + timer_->DeleteTimer(std::string(DISCOVERY_TIMEOUT_TASK)); } return softbusConnector_->StopDiscovery(subscribeId); } diff --git a/services/service/src/device_manager_service.cpp b/services/service/src/device_manager_service.cpp index fc30c42c7..870bfd681 100644 --- a/services/service/src/device_manager_service.cpp +++ b/services/service/src/device_manager_service.cpp @@ -23,7 +23,7 @@ #include "permission_manager.h" #include "dm_distributed_hardware_load.h" -const std::string LIB_IMPL_NAME = "libdevicemanagerserviceimpl.z.so"; +constexpr const char* LIB_IMPL_NAME = "libdevicemanagerserviceimpl.z.so"; namespace OHOS { namespace DistributedHardware { @@ -35,7 +35,7 @@ DeviceManagerService::~DeviceManagerService() if (dmServiceImpl_ != nullptr) { dmServiceImpl_->Release(); } - std::string soPathName = LIB_LOAD_PATH + LIB_IMPL_NAME; + std::string soPathName = std::string(LIB_LOAD_PATH) + std::string(LIB_IMPL_NAME); void *so_handle = dlopen(soPathName.c_str(), RTLD_NOW | RTLD_NOLOAD); if (so_handle != nullptr) { dlclose(so_handle); @@ -288,7 +288,7 @@ bool DeviceManagerService::IsDMServiceImplReady() return true; } - std::string soName = LIB_LOAD_PATH + LIB_IMPL_NAME; + std::string soName = std::string(LIB_LOAD_PATH) + std::string(LIB_IMPL_NAME); void *so_handle = dlopen(soName.c_str(), RTLD_NOW | RTLD_NOLOAD); if (so_handle == nullptr) { so_handle = dlopen(soName.c_str(), RTLD_NOW); diff --git a/services/service/src/device_manager_service_listener.cpp b/services/service/src/device_manager_service_listener.cpp index 32d6f516d..42b016f50 100644 --- a/services/service/src/device_manager_service_listener.cpp +++ b/services/service/src/device_manager_service_listener.cpp @@ -37,7 +37,7 @@ void DeviceManagerServiceListener::OnDeviceStateChange(const std::string &pkgNam pReq->SetPkgName(pkgName); pReq->SetDeviceState(state); pReq->SetDeviceInfo(info); - if (pkgName == DM_PKG_NAME) { + if (pkgName == std::string(DM_PKG_NAME)) { ipcServerListener_.SendAll(SERVER_DEVICE_STATE_NOTIFY, pReq, pRsp); } else { ipcServerListener_.SendRequest(SERVER_DEVICE_STATE_NOTIFY, pReq, pRsp); diff --git a/services/service/src/softbus/softbus_listener.cpp b/services/service/src/softbus/softbus_listener.cpp index e4b5c5e1c..e9a4f36db 100644 --- a/services/service/src/softbus/softbus_listener.cpp +++ b/services/service/src/softbus/softbus_listener.cpp @@ -75,7 +75,7 @@ SoftbusListener::SoftbusListener() .OnBytesReceived = SoftbusListener::OnBytesReceived, .OnMessageReceived = nullptr, .OnStreamReceived = nullptr}; - int32_t ret = CreateSessionServer(DM_PKG_NAME.c_str(), DM_SESSION_NAME.c_str(), &sessionListener); + int32_t ret = CreateSessionServer(DM_PKG_NAME, DM_SESSION_NAME, &sessionListener); if (ret != DM_OK) { LOGE("CreateSessionServer failed"); } else { @@ -86,7 +86,7 @@ SoftbusListener::SoftbusListener() SoftbusListener::~SoftbusListener() { - RemoveSessionServer(DM_PKG_NAME.c_str(), DM_SESSION_NAME.c_str()); + RemoveSessionServer(DM_PKG_NAME, DM_SESSION_NAME); LOGI("SoftbusListener destructor"); } @@ -95,7 +95,7 @@ int32_t SoftbusListener::Init() int32_t ret; int32_t retryTimes = 0; do { - ret = RegNodeDeviceStateCb(DM_PKG_NAME.c_str(), &softbusNodeStateCb_); + ret = RegNodeDeviceStateCb(DM_PKG_NAME, &softbusNodeStateCb_); if (ret != DM_OK) { ++retryTimes; LOGE("RegNodeDeviceStateCb failed with ret %d, retryTimes %d", ret, retryTimes); @@ -112,37 +112,37 @@ int32_t SoftbusListener::Init() dmPublishInfo.capabilityData = nullptr; dmPublishInfo.dataLen = 0; #if (defined(__LITEOS_M__) || defined(LITE_DEVICE)) - ret = PublishService(DM_PKG_NAME.c_str(), &dmPublishInfo, &softbusPublishCallback_); + ret = PublishService(DM_PKG_NAME, &dmPublishInfo, &softbusPublishCallback_); if (ret == DM_OK) { publishStatus = ALLOW_BE_DISCOVERY; } #else char discoverStatus[DISCOVER_STATUS_LEN + 1] = {0}; - ret = GetParameter(DISCOVER_STATUS_KEY.c_str(), "not exist", discoverStatus, DISCOVER_STATUS_LEN); + ret = GetParameter(DISCOVER_STATUS_KEY, "not exist", discoverStatus, DISCOVER_STATUS_LEN); if (strcmp(discoverStatus, "not exist") == 0) { - ret = SetParameter(DISCOVER_STATUS_KEY.c_str(), DISCOVER_STATUS_ON.c_str()); + ret = SetParameter(DISCOVER_STATUS_KEY, DISCOVER_STATUS_ON); LOGI("service set parameter result is : %d", ret); - ret = PublishService(DM_PKG_NAME.c_str(), &dmPublishInfo, &softbusPublishCallback_); + ret = PublishService(DM_PKG_NAME, &dmPublishInfo, &softbusPublishCallback_); if (ret == DM_OK) { publishStatus = ALLOW_BE_DISCOVERY; } LOGI("service publish result is : %d", ret); - } else if (ret >= 0 && strcmp(discoverStatus, DISCOVER_STATUS_ON.c_str()) == 0) { - ret = PublishService(DM_PKG_NAME.c_str(), &dmPublishInfo, &softbusPublishCallback_); + } else if (ret >= 0 && strcmp(discoverStatus, DISCOVER_STATUS_ON) == 0) { + ret = PublishService(DM_PKG_NAME, &dmPublishInfo, &softbusPublishCallback_); if (ret == DM_OK) { publishStatus = ALLOW_BE_DISCOVERY; } LOGI("service publish result is : %d", ret); - } else if (ret >= 0 && strcmp(discoverStatus, DISCOVER_STATUS_OFF.c_str()) == 0) { - ret = UnPublishService(DM_PKG_NAME.c_str(), DISTRIBUTED_HARDWARE_DEVICEMANAGER_SA_ID); + } else if (ret >= 0 && strcmp(discoverStatus, DISCOVER_STATUS_OFF) == 0) { + ret = UnPublishService(DM_PKG_NAME, DISTRIBUTED_HARDWARE_DEVICEMANAGER_SA_ID); if (ret == DM_OK) { publishStatus = NOT_ALLOW_BE_DISCOVERY; } LOGI("service unpublish result is : %d", ret); } - ret = WatchParameter(DISCOVER_STATUS_KEY.c_str(), &SoftbusListener::OnParameterChgCallback, nullptr); + ret = WatchParameter(DISCOVER_STATUS_KEY, &SoftbusListener::OnParameterChgCallback, nullptr); #endif return ret; } @@ -152,7 +152,7 @@ int32_t SoftbusListener::GetTrustedDeviceList(std::vector &deviceI LOGI("SoftbusListener::GetTrustDevices start"); int32_t infoNum = 0; NodeBasicInfo *nodeInfo = nullptr; - int32_t ret = GetAllNodeDeviceInfo(DM_PKG_NAME.c_str(), &nodeInfo, &infoNum); + int32_t ret = GetAllNodeDeviceInfo(DM_PKG_NAME, &nodeInfo, &infoNum); if (ret != 0) { LOGE("GetAllNodeDeviceInfo failed with ret %d", ret); return ERR_DM_FAILED; @@ -179,7 +179,7 @@ int32_t SoftbusListener::GetLocalDeviceInfo(DmDeviceInfo &deviceInfo) { LOGI("SoftbusListener::GetLocalDeviceInfo start"); NodeBasicInfo nodeBasicInfo; - int32_t ret = GetLocalNodeDeviceInfo(DM_PKG_NAME.c_str(), &nodeBasicInfo); + int32_t ret = GetLocalNodeDeviceInfo(DM_PKG_NAME, &nodeBasicInfo); if (ret != 0) { LOGE("GetLocalNodeDeviceInfo failed with ret %d", ret); return ERR_DM_FAILED; @@ -194,7 +194,7 @@ int32_t SoftbusListener::GetUdidByNetworkId(const char *networkId, std::string & LOGI("GetUdidByNetworkId begin"); uint8_t mUdid[UDID_BUF_LEN] = {0}; int32_t ret = - GetNodeKeyInfo(DM_PKG_NAME.c_str(), networkId, NodeDeviceInfoKey::NODE_KEY_UDID, mUdid, sizeof(mUdid)); + GetNodeKeyInfo(DM_PKG_NAME, networkId, NodeDeviceInfoKey::NODE_KEY_UDID, mUdid, sizeof(mUdid)); if (ret != DM_OK) { LOGE("GetUdidByNetworkId GetNodeKeyInfo failed"); return ERR_DM_FAILED; @@ -209,7 +209,7 @@ int32_t SoftbusListener::GetUuidByNetworkId(const char *networkId, std::string & LOGI("GetUuidByNetworkId begin"); uint8_t mUuid[UUID_BUF_LEN] = {0}; int32_t ret = - GetNodeKeyInfo(DM_PKG_NAME.c_str(), networkId, NodeDeviceInfoKey::NODE_KEY_UUID, mUuid, sizeof(mUuid)); + GetNodeKeyInfo(DM_PKG_NAME, networkId, NodeDeviceInfoKey::NODE_KEY_UUID, mUuid, sizeof(mUuid)); if (ret != DM_OK) { LOGE("GetUuidByNetworkId GetNodeKeyInfo failed"); return ERR_DM_FAILED; @@ -278,7 +278,7 @@ int32_t SoftbusListener::CovertNodeBasicInfoToDmDevice(const NodeBasicInfo &node void SoftbusListener::OnParameterChgCallback(const char *key, const char *value, void *context) { - if (strcmp(value, DISCOVER_STATUS_ON.c_str()) == 0 && publishStatus != ALLOW_BE_DISCOVERY) { + if (strcmp(value, DISCOVER_STATUS_ON) == 0 && publishStatus != ALLOW_BE_DISCOVERY) { PublishInfo dmPublishInfo; dmPublishInfo.publishId = DISTRIBUTED_HARDWARE_DEVICEMANAGER_SA_ID; dmPublishInfo.mode = DiscoverMode::DISCOVER_MODE_ACTIVE; @@ -287,13 +287,13 @@ void SoftbusListener::OnParameterChgCallback(const char *key, const char *value, dmPublishInfo.capability = DM_CAPABILITY_OSD; dmPublishInfo.capabilityData = nullptr; dmPublishInfo.dataLen = 0; - int32_t ret = PublishService(DM_PKG_NAME.c_str(), &dmPublishInfo, &softbusPublishCallback_); + int32_t ret = PublishService(DM_PKG_NAME, &dmPublishInfo, &softbusPublishCallback_); if (ret == DM_OK) { publishStatus = ALLOW_BE_DISCOVERY; } LOGI("service publish result is : %d", ret); - } else if (strcmp(value, DISCOVER_STATUS_OFF.c_str()) == 0 && publishStatus != NOT_ALLOW_BE_DISCOVERY) { - int32_t ret = UnPublishService(DM_PKG_NAME.c_str(), DISTRIBUTED_HARDWARE_DEVICEMANAGER_SA_ID); + } else if (strcmp(value, DISCOVER_STATUS_OFF) == 0 && publishStatus != NOT_ALLOW_BE_DISCOVERY) { + int32_t ret = UnPublishService(DM_PKG_NAME, DISTRIBUTED_HARDWARE_DEVICEMANAGER_SA_ID); if (ret == DM_OK) { publishStatus = NOT_ALLOW_BE_DISCOVERY; } diff --git a/test/unittest/UTTest_dm_timer.cpp b/test/unittest/UTTest_dm_timer.cpp index 178fe1234..bce913001 100644 --- a/test/unittest/UTTest_dm_timer.cpp +++ b/test/unittest/UTTest_dm_timer.cpp @@ -50,20 +50,20 @@ static void TimeOut(std::string timerName) {} */ HWTEST_F(TimeHeapTest, StartTimer_001, testing::ext::TestSize.Level0) { - std::string name = AUTHENTICATE_TIMEOUT_TASK; + std::string name = std::string(AUTHENTICATE_TIMEOUT_TASK); int32_t timeout = 10; std::shared_ptr timer = std::make_shared(); int32_t ret = timer->StartTimer("", timeout, TimeOut); EXPECT_EQ(ERR_DM_INPUT_PARAMETER_EMPTY, ret); - ret = timer->StartTimer(AUTHENTICATE_TIMEOUT_TASK, 400, TimeOut); + ret = timer->StartTimer(std::string(AUTHENTICATE_TIMEOUT_TASK), 400, TimeOut); EXPECT_EQ(ERR_DM_INPUT_PARAMETER_EMPTY, ret); - ret = timer->StartTimer(AUTHENTICATE_TIMEOUT_TASK, -20, TimeOut); + ret = timer->StartTimer(std::string(AUTHENTICATE_TIMEOUT_TASK), -20, TimeOut); EXPECT_EQ(ERR_DM_INPUT_PARAMETER_EMPTY, ret); - ret = timer->StartTimer(AUTHENTICATE_TIMEOUT_TASK, timeout, nullptr); + ret = timer->StartTimer(std::string(AUTHENTICATE_TIMEOUT_TASK), timeout, nullptr); EXPECT_EQ(ERR_DM_INPUT_PARAMETER_EMPTY, ret); } @@ -75,7 +75,7 @@ HWTEST_F(TimeHeapTest, StartTimer_001, testing::ext::TestSize.Level0) */ HWTEST_F(TimeHeapTest, StartTimer_002, testing::ext::TestSize.Level0) { - std::string name = AUTHENTICATE_TIMEOUT_TASK; + std::string name = std::string(AUTHENTICATE_TIMEOUT_TASK); std::string name2 = "test2"; int32_t timeOut = 10; int32_t timeOut2 = 40; @@ -95,7 +95,7 @@ HWTEST_F(TimeHeapTest, StartTimer_002, testing::ext::TestSize.Level0) */ HWTEST_F(TimeHeapTest, DeleteTimer_001, testing::ext::TestSize.Level0) { - std::string name = AUTHENTICATE_TIMEOUT_TASK; + std::string name = std::string(AUTHENTICATE_TIMEOUT_TASK); std::shared_ptr timer = std::make_shared(); int32_t ret = timer->DeleteTimer(""); EXPECT_EQ(ERR_DM_INPUT_PARAMETER_EMPTY, ret); @@ -112,7 +112,7 @@ HWTEST_F(TimeHeapTest, DeleteTimer_001, testing::ext::TestSize.Level0) */ HWTEST_F(TimeHeapTest, DeleteTimer_002, testing::ext::TestSize.Level0) { - std::string name = AUTHENTICATE_TIMEOUT_TASK; + std::string name = std::string(AUTHENTICATE_TIMEOUT_TASK); int32_t timeOut = 10; std::shared_ptr timer = std::make_shared(); timer->StartTimer(name, timeOut, TimeOut); @@ -128,7 +128,7 @@ HWTEST_F(TimeHeapTest, DeleteTimer_002, testing::ext::TestSize.Level0) */ HWTEST_F(TimeHeapTest, DeleteAll_001, testing::ext::TestSize.Level0) { - std::string name = AUTHENTICATE_TIMEOUT_TASK; + std::string name = std::string(AUTHENTICATE_TIMEOUT_TASK); int32_t timeOut = 10; std::shared_ptr timer = std::make_shared(); int32_t ret = timer->DeleteAll(); diff --git a/test/unittest/UTTest_softbus_connector.cpp b/test/unittest/UTTest_softbus_connector.cpp index 0188a30fd..371c59046 100644 --- a/test/unittest/UTTest_softbus_connector.cpp +++ b/test/unittest/UTTest_softbus_connector.cpp @@ -587,8 +587,8 @@ HWTEST_F(SoftbusConnectorTest, OnSoftBusDeviceOnline_003, testing::ext::TestSize .deviceName = "123456", .deviceTypeId = 1 }; - std::string oldName = DM_PKG_NAME; - std::string DM_PKG_NAME = "com.ohos.test"; + std::string oldName = std::string(DM_PKG_NAME); + std::string pkgName = "com.ohos.test"; softbusListener->OnSoftBusDeviceOnline(&info); bool ret = false; if (listener->ipcServerListener_.req_ != nullptr) { @@ -596,7 +596,7 @@ HWTEST_F(SoftbusConnectorTest, OnSoftBusDeviceOnline_003, testing::ext::TestSize ret = true; } EXPECT_EQ(ret, false); - DM_PKG_NAME = oldName; + pkgName = oldName; } /** diff --git a/utils/include/dfx/dm_dfx_constants.h b/utils/include/dfx/dm_dfx_constants.h index 32dad7ae9..6d7d94bcf 100644 --- a/utils/include/dfx/dm_dfx_constants.h +++ b/utils/include/dfx/dm_dfx_constants.h @@ -29,43 +29,43 @@ const int DM_HISYEVENT_SECURITY = 3; const int DM_HISYEVENT_BEHAVIOR = 4; // HisysEvent state -const std::string DM_INIT_DEVICE_MANAGER_SUCCESS = "DM_INIT_DEVICE_MANAGER_SUCCESS"; -const std::string DM_INIT_DEVICE_MANAGER_FAILED = "DM_INIT_DEVICE_MANAGER_FAILED"; -const std::string START_DEVICE_DISCOVERY_SUCCESS = "START_DEVICE_DISCOVERY_SUCCESS"; -const std::string START_DEVICE_DISCOVERY_FAILED = "START_DEVICE_DISCOVERY_FAILED"; -const std::string GET_LOCAL_DEVICE_INFO_SUCCESS = "GET_LOCAL_DEVICE_INFO_SUCCESS"; -const std::string GET_LOCAL_DEVICE_INFO_FAILED = "GET_LOCAL_DEVICE_INFO_FAILED"; -const std::string DM_SEND_REQUEST_SUCCESS = "DM_SEND_REQUEST_SUCCESS"; -const std::string DM_SEND_REQUEST_FAILED = "DM_SEND_REQUEST_FAILED"; -const std::string ADD_HICHAIN_GROUP_SUCCESS = "ADD_HICHAIN_GROUP_SUCCESS"; -const std::string ADD_HICHAIN_GROUP_FAILED = "ADD_HICHAIN_GROUP_FAILED"; -const std::string DM_CREATE_GROUP_SUCCESS = "DM_CREATE_GROUP_SUCCESS"; -const std::string DM_CREATE_GROUP_FAILED = "DM_CREATE_GROUP_FAILED"; -const std::string UNAUTHENTICATE_DEVICE_SUCCESS = "UNAUTHENTICATE_DEVICE_SUCCESS"; -const std::string UNAUTHENTICATE_DEVICE_FAILED = "UNAUTHENTICATE_DEVICE_FAILED"; +constexpr const char* DM_INIT_DEVICE_MANAGER_SUCCESS = "DM_INIT_DEVICE_MANAGER_SUCCESS"; +constexpr const char* DM_INIT_DEVICE_MANAGER_FAILED = "DM_INIT_DEVICE_MANAGER_FAILED"; +constexpr const char* START_DEVICE_DISCOVERY_SUCCESS = "START_DEVICE_DISCOVERY_SUCCESS"; +constexpr const char* START_DEVICE_DISCOVERY_FAILED = "START_DEVICE_DISCOVERY_FAILED"; +constexpr const char* GET_LOCAL_DEVICE_INFO_SUCCESS = "GET_LOCAL_DEVICE_INFO_SUCCESS"; +constexpr const char* GET_LOCAL_DEVICE_INFO_FAILED = "GET_LOCAL_DEVICE_INFO_FAILED"; +constexpr const char* DM_SEND_REQUEST_SUCCESS = "DM_SEND_REQUEST_SUCCESS"; +constexpr const char* DM_SEND_REQUEST_FAILED = "DM_SEND_REQUEST_FAILED"; +constexpr const char* ADD_HICHAIN_GROUP_SUCCESS = "ADD_HICHAIN_GROUP_SUCCESS"; +constexpr const char* ADD_HICHAIN_GROUP_FAILED = "ADD_HICHAIN_GROUP_FAILED"; +constexpr const char* DM_CREATE_GROUP_SUCCESS = "DM_CREATE_GROUP_SUCCESS"; +constexpr const char* DM_CREATE_GROUP_FAILED = "DM_CREATE_GROUP_FAILED"; +constexpr const char* UNAUTHENTICATE_DEVICE_SUCCESS = "UNAUTHENTICATE_DEVICE_SUCCESS"; +constexpr const char* UNAUTHENTICATE_DEVICE_FAILED = "UNAUTHENTICATE_DEVICE_FAILED"; // HisysEvent msg -const std::string DM_INIT_DEVICE_MANAGER_SUCCESS_MSG = "init devicemanager success."; -const std::string DM_INIT_DEVICE_MANAGER_FAILED_MSG = "init devicemanager failed."; -const std::string START_DEVICE_DISCOVERY_SUCCESS_MSG = "device manager discovery success."; -const std::string START_DEVICE_DISCOVERY_FAILED_MSG = "device manager discovery failed."; -const std::string GET_LOCAL_DEVICE_INFO_SUCCESS_MSG = "get local device info success."; -const std::string GET_LOCAL_DEVICE_INFO_FAILED_MSG = "get local device info failed."; -const std::string DM_SEND_REQUEST_SUCCESS_MSG = "send request success."; -const std::string DM_SEND_REQUEST_FAILED_MSG = "send request failed."; -const std::string ADD_HICHAIN_GROUP_SUCCESS_MSG = "dm add member to group success."; -const std::string ADD_HICHAIN_GROUP_FAILED_MSG = "dm add member to group failed."; -const std::string DM_CREATE_GROUP_SUCCESS_MSG = "dm create group success."; -const std::string DM_CREATE_GROUP_FAILED_MSG = "dm create group failed."; -const std::string UNAUTHENTICATE_DEVICE_SUCCESS_MSG = "unauthenticate device success."; -const std::string UNAUTHENTICATE_DEVICE_FAILED_MSG = "unauthenticate device failed."; +constexpr const char* DM_INIT_DEVICE_MANAGER_SUCCESS_MSG = "init devicemanager success."; +constexpr const char* DM_INIT_DEVICE_MANAGER_FAILED_MSG = "init devicemanager failed."; +constexpr const char* START_DEVICE_DISCOVERY_SUCCESS_MSG = "device manager discovery success."; +constexpr const char* START_DEVICE_DISCOVERY_FAILED_MSG = "device manager discovery failed."; +constexpr const char* GET_LOCAL_DEVICE_INFO_SUCCESS_MSG = "get local device info success."; +constexpr const char* GET_LOCAL_DEVICE_INFO_FAILED_MSG = "get local device info failed."; +constexpr const char* DM_SEND_REQUEST_SUCCESS_MSG = "send request success."; +constexpr const char* DM_SEND_REQUEST_FAILED_MSG = "send request failed."; +constexpr const char* ADD_HICHAIN_GROUP_SUCCESS_MSG = "dm add member to group success."; +constexpr const char* ADD_HICHAIN_GROUP_FAILED_MSG = "dm add member to group failed."; +constexpr const char* DM_CREATE_GROUP_SUCCESS_MSG = "dm create group success."; +constexpr const char* DM_CREATE_GROUP_FAILED_MSG = "dm create group failed."; +constexpr const char* UNAUTHENTICATE_DEVICE_SUCCESS_MSG = "unauthenticate device success."; +constexpr const char* UNAUTHENTICATE_DEVICE_FAILED_MSG = "unauthenticate device failed."; // dfx hitrace -const std::string DM_HITRACE_START_DEVICE = "DM_HITRACE_START_DEVICE"; -const std::string DM_HITRACE_GET_LOCAL_DEVICE_INFO = "DM_HITRACE_GET_LOCAL_DEVICE_INFO"; -const std::string DM_HITRACE_AUTH_TO_CONSULT = "DM_HITRACE_AUTH_TO_CONSULT"; -const std::string DM_HITRACE_AUTH_TO_OPPEN_SESSION = "DM_HITRACE_AUTH_TO_OPPEN_SESSION"; -const std::string DM_HITRACE_INIT = "DM_HITRACE_INIT"; +constexpr const char* DM_HITRACE_START_DEVICE = "DM_HITRACE_START_DEVICE"; +constexpr const char* DM_HITRACE_GET_LOCAL_DEVICE_INFO = "DM_HITRACE_GET_LOCAL_DEVICE_INFO"; +constexpr const char* DM_HITRACE_AUTH_TO_CONSULT = "DM_HITRACE_AUTH_TO_CONSULT"; +constexpr const char* DM_HITRACE_AUTH_TO_OPPEN_SESSION = "DM_HITRACE_AUTH_TO_OPPEN_SESSION"; +constexpr const char* DM_HITRACE_INIT = "DM_HITRACE_INIT"; // HiDumper Flag enum class HidumperFlag { @@ -76,13 +76,13 @@ enum class HidumperFlag { }; // HiDumper info -const std::string ARGS_HELP_INFO = "-help"; -const std::string HIDUMPER_GET_TRUSTED_LIST_INFO = "-getTrustlist"; +constexpr const char* ARGS_HELP_INFO = "-help"; +constexpr const char* HIDUMPER_GET_TRUSTED_LIST_INFO = "-getTrustlist"; // HiDumper command const std::unordered_map MAP_ARGS = { - { ARGS_HELP_INFO, HidumperFlag::HIDUMPER_GET_HELP }, - { HIDUMPER_GET_TRUSTED_LIST_INFO, HidumperFlag::HIDUMPER_GET_TRUSTED_LIST }, + { std::string(ARGS_HELP_INFO), HidumperFlag::HIDUMPER_GET_HELP }, + { std::string(HIDUMPER_GET_TRUSTED_LIST_INFO), HidumperFlag::HIDUMPER_GET_TRUSTED_LIST }, }; // HiDumper device type -- Gitee From 714f36ee7fef17f6f984369c4ddc02127c7e187f Mon Sep 17 00:00:00 2001 From: renguang1116 Date: Mon, 25 Jul 2022 17:23:18 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E3=80=90Codex=E3=80=91=E6=B8=85=E7=90=86?= =?UTF-8?q?=E4=B8=8D=E5=AE=89=E5=85=A8=E5=87=BD=E6=95=B0=20Signed-off-by:?= =?UTF-8?q?=20renguang1116=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../device_manager_fa_test/device_manager_fa_test.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/benchmarktest/device_manager_fa_test/device_manager_fa_test.cpp b/test/benchmarktest/device_manager_fa_test/device_manager_fa_test.cpp index 8e049bad1..48c861dee 100644 --- a/test/benchmarktest/device_manager_fa_test/device_manager_fa_test.cpp +++ b/test/benchmarktest/device_manager_fa_test/device_manager_fa_test.cpp @@ -233,7 +233,7 @@ BENCHMARK_F(DeviceDiscoveryTest, StartDeviceDiscoveryTestCase)( subInfo.freq = DM_HIGH; subInfo.isSameAccount = false; subInfo.isWakeRemote = false; - strcpy(subInfo.capability, DM_CAPABILITY_OSD); + strcpy_s(subInfo.capability, DM_MAX_DEVICE_CAPABILITY_LEN, DM_CAPABILITY_OSD); std::shared_ptr callback = std::make_shared(); int32_t ret = DeviceManager::GetInstance().StartDeviceDiscovery(packageName, subInfo, extra, callback); @@ -261,7 +261,7 @@ BENCHMARK_F(DeviceDiscoveryTest, StoptDeviceDiscoveryTestCase)( subInfo.freq = DM_HIGH; subInfo.isSameAccount = false; subInfo.isWakeRemote = false; - strcpy(subInfo.capability, DM_CAPABILITY_OSD); + strcpy_s(subInfo.capability, DM_MAX_DEVICE_CAPABILITY_LEN, DM_CAPABILITY_OSD); std::shared_ptr callback = std::make_shared(); int32_t ret = DeviceManager::GetInstance().StartDeviceDiscovery(pkgName, subInfo, extra, callback); -- Gitee