diff --git a/bundle.json b/bundle.json index b1da5cfc8c0849484de8bbf92b01a0fa207e59eb..38c6b7a5038587abd5f4b151318ed7fb37c5433a 100644 --- a/bundle.json +++ b/bundle.json @@ -58,7 +58,9 @@ "node", "jsoncpp", "access_token", - "hiappevent" + "hiappevent", + "bundle_framework", + "safwk" ] }, "build": { diff --git a/frameworks/js/napi/http/http_exec/src/http_exec.cpp b/frameworks/js/napi/http/http_exec/src/http_exec.cpp index 553edc02fdeeab2418bede0d94c2ef7082b32d2c..c15f0f6e49d4860648adf88bbe8dece1f82741c5 100755 --- a/frameworks/js/napi/http/http_exec/src/http_exec.cpp +++ b/frameworks/js/napi/http/http_exec/src/http_exec.cpp @@ -280,7 +280,9 @@ bool HttpExec::AddCurlHandle(CURL *handle, RequestContext *context) #if HAS_NETMANAGER_BASE std::stringstream name; - name << HTTP_REQ_TRACE_NAME << "_" << std::this_thread::get_id(); + auto isDebugMode = NapiUtils::IsDebugMode(); + auto urlWithoutParam = NapiUtils::removeUrlParameters(context->options.GetUrl()); + name << HTTP_REQ_TRACE_NAME << "_" << std::this_thread::get_id() << (isDebugMode ? ("_" + urlWithoutParam) : ""); SetTraceOptions(handle, context); SetServerSSLCertOption(handle, context); diff --git a/utils/napi_utils/BUILD.gn b/utils/napi_utils/BUILD.gn index 604c836185ea3c1a5461480f0ab9df392bbd0836..970e517e1992fbb773605977ebde47b3e0d74f7c 100644 --- a/utils/napi_utils/BUILD.gn +++ b/utils/napi_utils/BUILD.gn @@ -54,6 +54,10 @@ ohos_static_library("napi_utils") { "c_utils:utils", "hilog:libhilog", "napi:ace_napi", + "samgr:samgr_proxy", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", + "safwk:system_ability_fwk", ] if (!build_ohos_sdk) { diff --git a/utils/napi_utils/include/napi_utils.h b/utils/napi_utils/include/napi_utils.h index ea99529ae47612d2a7b8fbe226fe58bbe390d793..1d522870b6f911331456e335e42f550bb1a5ee17 100644 --- a/utils/napi_utils/include/napi_utils.h +++ b/utils/napi_utils/include/napi_utils.h @@ -182,6 +182,10 @@ uint64_t CreateUvHandlerQueue(napi_env env); void HookForEnvCleanup(void *data); void SetEnvValid(napi_env env); bool IsEnvValid(napi_env env); + +bool IsDebugMode(); + +std::string removeUrlParameters(const std::string& url); } // namespace OHOS::NetStack::NapiUtils #endif /* COMMUNICATIONNETSTACK_NETSTACK_NAPI_UTILS_H */ diff --git a/utils/napi_utils/src/napi_utils.cpp b/utils/napi_utils/src/napi_utils.cpp index 47afe60d75cd65b648ade64bd12f2e60a4ee01b3..6ffcc92443e361bb43f7be5a55d761964118816c 100644 --- a/utils/napi_utils/src/napi_utils.cpp +++ b/utils/napi_utils/src/napi_utils.cpp @@ -33,6 +33,10 @@ #include "netstack_log.h" #include "node_api.h" +#include "bundle_mgr_interface.h" +#include "iservice_registry.h" +#include "system_ability_definition.h" + namespace OHOS::NetStack::NapiUtils { static constexpr const char *GLOBAL_JSON = "JSON"; @@ -948,4 +952,46 @@ bool IsEnvValid(napi_env env) } return true; } + + +bool IsDebugMode() +{ + sptr systemAbilityManager = + SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + if (systemAbilityManager == nullptr) { + NETSTACK_LOGE("IsDebugMode failed to get system ability mgr."); + return false; + } + + sptr remoteObject = systemAbilityManager->GetSystemAbility(BUNDLE_MGR_SERVICE_SYS_ABILITY_ID); + if (remoteObject == nullptr) { + NETSTACK_LOGE("IsDebugMode failed to get bundle manager proxy."); + return false; + } + + sptr bundleMgrProxy = iface_cast(remoteObject); + if (bundleMgrProxy == nullptr) { + NETSTACK_LOGE("IsDebugMode failed to get bundle manager proxy."); + return false; + } + + AppExecFwk::BundleInfo bundleInfo; + constexpr auto flag = static_cast(AppExecFwk::GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_APPLICATION); + const auto res = bundleMgrProxy->GetBundleInfoForSelf(flag, bundleInfo); + NETSTACK_LOGI("IsDebugMode GetBundleInfoForSelf res = %{public}d", res); + + const auto appProvisionType = bundleInfo.applicationInfo.appProvisionType; + NETSTACK_LOGI("IsDebugMode appProvisionType = %{public}s", appProvisionType.c_str()); + + return (appProvisionType == "debug") ? true : false; +} + +std::string removeUrlParameters(const std::string& url) { + size_t questionMarkPos = url.find('?'); + if (questionMarkPos == std::string::npos) { + return url; + } + return url.substr(0, questionMarkPos); +} + } // namespace OHOS::NetStack::NapiUtils