diff --git a/interfaces/cj/kits/src/device_manager_utils.cpp b/interfaces/cj/kits/src/device_manager_utils.cpp index f7c89749f28f9abca65671017c04a5def64a1415..b81e2ed43ae16f26c7919666912d103d1d9ba148 100644 --- a/interfaces/cj/kits/src/device_manager_utils.cpp +++ b/interfaces/cj/kits/src/device_manager_utils.cpp @@ -188,23 +188,23 @@ void DmFfiBindTargetCallback::OnBindResult(const PeerTargetId &targetId, int32_t const std::string &GetDeviceTypeById(DmDeviceType type) { const static std::pair mapArray[] = { - {DEVICE_TYPE_UNKNOWN, DEVICE_TYPE_UNKNOWN_STRING}, - {DEVICE_TYPE_PHONE, DEVICE_TYPE_PHONE_STRING}, - {DEVICE_TYPE_PAD, DEVICE_TYPE_PAD_STRING}, - {DEVICE_TYPE_TV, DEVICE_TYPE_TV_STRING}, - {DEVICE_TYPE_CAR, DEVICE_TYPE_CAR_STRING}, - {DEVICE_TYPE_WATCH, DEVICE_TYPE_WATCH_STRING}, - {DEVICE_TYPE_WIFI_CAMERA, DEVICE_TYPE_WIFICAMERA_STRING}, - {DEVICE_TYPE_PC, DEVICE_TYPE_PC_STRING}, - {DEVICE_TYPE_SMART_DISPLAY, DEVICE_TYPE_SMART_DISPLAY_STRING}, - {DEVICE_TYPE_2IN1, DEVICE_TYPE_2IN1_STRING}, + {DEVICE_TYPE_UNKNOWN, std::string(DEVICE_TYPE_UNKNOWN_STRING)}, + {DEVICE_TYPE_PHONE, std::string(DEVICE_TYPE_PHONE_STRING)}, + {DEVICE_TYPE_PAD, std::string(DEVICE_TYPE_PAD_STRING)}, + {DEVICE_TYPE_TV, std::string(DEVICE_TYPE_TV_STRING)}, + {DEVICE_TYPE_CAR, std::string(DEVICE_TYPE_CAR_STRING)}, + {DEVICE_TYPE_WATCH, std::string(DEVICE_TYPE_WATCH_STRING)}, + {DEVICE_TYPE_WIFI_CAMERA, std::string(DEVICE_TYPE_WIFICAMERA_STRING)}, + {DEVICE_TYPE_PC, std::string(DEVICE_TYPE_PC_STRING)}, + {DEVICE_TYPE_SMART_DISPLAY, std::string(DEVICE_TYPE_SMART_DISPLAY_STRING)}, + {DEVICE_TYPE_2IN1, std::string(DEVICE_TYPE_2IN1_STRING)}, }; for (const auto& item : mapArray) { if (item.first == type) { return item.second; } } - return DEVICE_TYPE_UNKNOWN_STRING; + return std::string(DEVICE_TYPE_UNKNOWN_STRING); } char *MallocCStr(const char *in) diff --git a/interfaces/inner_kits/native_cpp/include/dm_device_info.h b/interfaces/inner_kits/native_cpp/include/dm_device_info.h index 00d087fcbd26773ccd73e26acac0b5785ad89e6a..4fa27ac36f94bf7aeb2bae477a1892d2cfeea2d8 100644 --- a/interfaces/inner_kits/native_cpp/include/dm_device_info.h +++ b/interfaces/inner_kits/native_cpp/include/dm_device_info.h @@ -347,16 +347,16 @@ typedef enum { MAX = 9, } DmCommonNotifyEvent; -const std::string DEVICE_TYPE_UNKNOWN_STRING = "UNKNOWN"; -const std::string DEVICE_TYPE_PHONE_STRING = "PHONE"; -const std::string DEVICE_TYPE_PAD_STRING = "PAD"; -const std::string DEVICE_TYPE_TV_STRING = "TV"; -const std::string DEVICE_TYPE_CAR_STRING = "CAR"; -const std::string DEVICE_TYPE_WATCH_STRING = "WATCH"; -const std::string DEVICE_TYPE_WIFICAMERA_STRING = "WiFiCamera"; -const std::string DEVICE_TYPE_PC_STRING = "PC"; -const std::string DEVICE_TYPE_SMART_DISPLAY_STRING = "SMART_DISPLAY"; -const std::string DEVICE_TYPE_2IN1_STRING = "2IN1"; +constexpr const char* DEVICE_TYPE_UNKNOWN_STRING = "UNKNOWN"; +constexpr const char* DEVICE_TYPE_PHONE_STRING = "PHONE"; +constexpr const char* DEVICE_TYPE_PAD_STRING = "PAD"; +constexpr const char* DEVICE_TYPE_TV_STRING = "TV"; +constexpr const char* DEVICE_TYPE_CAR_STRING = "CAR"; +constexpr const char* DEVICE_TYPE_WATCH_STRING = "WATCH"; +constexpr const char* DEVICE_TYPE_WIFICAMERA_STRING = "WiFiCamera"; +constexpr const char* DEVICE_TYPE_PC_STRING = "PC"; +constexpr const char* DEVICE_TYPE_SMART_DISPLAY_STRING = "SMART_DISPLAY"; +constexpr const char* DEVICE_TYPE_2IN1_STRING = "2IN1"; typedef struct DmAccessCaller { std::string accountId; diff --git a/interfaces/kits/js4.0/src/dm_native_util.cpp b/interfaces/kits/js4.0/src/dm_native_util.cpp index 8b08c668a1d786f0b71cc9f4ef85c5d12ca1cbbe..da5e313cd9a39064b39dbb0e8228b6d725af1316 100644 --- a/interfaces/kits/js4.0/src/dm_native_util.cpp +++ b/interfaces/kits/js4.0/src/dm_native_util.cpp @@ -127,23 +127,23 @@ int32_t GetIntFromJsObj(const napi_env &env, const napi_value &object, const std std::string GetDeviceTypeById(DmDeviceType type) { const static std::pair mapArray[] = { - {DEVICE_TYPE_UNKNOWN, DEVICE_TYPE_UNKNOWN_STRING}, - {DEVICE_TYPE_PHONE, DEVICE_TYPE_PHONE_STRING}, - {DEVICE_TYPE_PAD, DEVICE_TYPE_PAD_STRING}, - {DEVICE_TYPE_TV, DEVICE_TYPE_TV_STRING}, - {DEVICE_TYPE_CAR, DEVICE_TYPE_CAR_STRING}, - {DEVICE_TYPE_WATCH, DEVICE_TYPE_WATCH_STRING}, - {DEVICE_TYPE_WIFI_CAMERA, DEVICE_TYPE_WIFICAMERA_STRING}, - {DEVICE_TYPE_PC, DEVICE_TYPE_PC_STRING}, - {DEVICE_TYPE_SMART_DISPLAY, DEVICE_TYPE_SMART_DISPLAY_STRING}, - {DEVICE_TYPE_2IN1, DEVICE_TYPE_2IN1_STRING}, + {DEVICE_TYPE_UNKNOWN, std::string(DEVICE_TYPE_UNKNOWN_STRING)}, + {DEVICE_TYPE_PHONE, std::string(DEVICE_TYPE_PHONE_STRING)}, + {DEVICE_TYPE_PAD, std::string(DEVICE_TYPE_PAD_STRING)}, + {DEVICE_TYPE_TV, std::string(DEVICE_TYPE_TV_STRING)}, + {DEVICE_TYPE_CAR, std::string(DEVICE_TYPE_CAR_STRING)}, + {DEVICE_TYPE_WATCH, std::string(DEVICE_TYPE_WATCH_STRING)}, + {DEVICE_TYPE_WIFI_CAMERA, std::string(DEVICE_TYPE_WIFICAMERA_STRING)}, + {DEVICE_TYPE_PC, std::string(DEVICE_TYPE_PC_STRING)}, + {DEVICE_TYPE_SMART_DISPLAY, std::string(DEVICE_TYPE_SMART_DISPLAY_STRING)}, + {DEVICE_TYPE_2IN1, std::string(DEVICE_TYPE_2IN1_STRING)}, }; for (const auto& item : mapArray) { if (item.first == type) { return item.second; } } - return DEVICE_TYPE_UNKNOWN_STRING; + return std::string(DEVICE_TYPE_UNKNOWN_STRING); } bool CheckArgsVal(napi_env env, bool assertion, const std::string ¶m, const std::string &msg)