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..327b389cae022d48d2a4ac4c6d29080adb83189e 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,13 @@ 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(); + if (context == nullptr) { + NETSTACK_LOGE("context nullptr"); + return false; + } + 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..934c81e1ff57e3738315a43a5f3f9509389d920f 100644 --- a/utils/napi_utils/BUILD.gn +++ b/utils/napi_utils/BUILD.gn @@ -69,7 +69,13 @@ ohos_static_library("napi_utils") { global_parts_info.communication_netmanager_base && is_ohos && is_standard_system && !is_arkui_x && product_name != "ohos-sdk") { defines = [ "HAS_NETMANAGER_BASE=1" ] - external_deps += [ "ffrt:libffrt" ] + external_deps += [ + "ffrt:libffrt", + "samgr:samgr_proxy", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", + "safwk:system_ability_fwk", + ] } else { defines = [ "HAS_NETMANAGER_BASE=0" ] } diff --git a/utils/napi_utils/include/napi_utils.h b/utils/napi_utils/include/napi_utils.h index ea99529ae47612d2a7b8fbe226fe58bbe390d793..789cf7322cd5af5a40498a1959443da2ee3714f1 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..eaf5c3420957b8e33b928850e74128edf37209dd 100644 --- a/utils/napi_utils/src/napi_utils.cpp +++ b/utils/napi_utils/src/napi_utils.cpp @@ -33,6 +33,12 @@ #include "netstack_log.h" #include "node_api.h" +#if HAS_NETMANAGER_BASE +#include "bundle_mgr_interface.h" +#include "iservice_registry.h" +#include "system_ability_definition.h" +#endif + namespace OHOS::NetStack::NapiUtils { static constexpr const char *GLOBAL_JSON = "JSON"; @@ -948,4 +954,49 @@ bool IsEnvValid(napi_env env) } return true; } + +bool IsDebugMode() +{ +#if HAS_NETMANAGER_BASE + 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; +#else + return true; +#endif +} + +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