diff --git a/services/bundlemgr/src/hidump_helper.cpp b/services/bundlemgr/src/hidump_helper.cpp index a4b32d20..5b48ae41 100644 --- a/services/bundlemgr/src/hidump_helper.cpp +++ b/services/bundlemgr/src/hidump_helper.cpp @@ -25,6 +25,7 @@ const int32_t MIN_ARGS_SIZE = 1; const int32_t MAX_ARGS_SIZE = 2; const int32_t FIRST_PARAM = 0; const int32_t SECOND_PARAM = 1; +const int32_t NON_ANONYMIZE_LEN = 4; const std::string ARGS_HELP = "-h"; const std::string ARGS_ABILITY = "-ability"; const std::string ARGS_ABILITY_LIST = "-ability-list"; @@ -42,6 +43,22 @@ const std::unordered_map ARGS_MAP = { { ARGS_BUNDLE_LIST, HidumpFlag::GET_BUNDLE_LIST }, { ARGS_DEVICEID, HidumpFlag::GET_DEVICEID }, }; + +std::string AnonymizeDeviceId(const std::string &deviceId) +{ + int32_t totalLen = static_cast(strlen(deviceId.c_str())); + int32_t anonymizeCharNum = totalLen - NON_ANONYMIZE_LEN - NON_ANONYMIZE_LEN; + if (anonymizeCharNum <= 0) { + return deviceId; + } + + std::string newDeviceId; + newDeviceId + .append(deviceId.substr(0, NON_ANONYMIZE_LEN)) + .append(anonymizeCharNum, '*') + .append(deviceId.substr(totalLen - NON_ANONYMIZE_LEN, NON_ANONYMIZE_LEN)); + return newDeviceId; +} } HidumpHelper::HidumpHelper(const std::weak_ptr &dataMgr) @@ -364,7 +381,7 @@ ErrCode HidumpHelper::GetAllDeviced(std::string &result) } for (auto deviceId : deviceIds) { - result.append(deviceId); + result.append(AnonymizeDeviceId(deviceId)); result.append("\n"); }