1 /* 2 * Copyright (c) 2025 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #include "http_utils.h" 17 18 #if HAS_NETMANAGER_BASE 19 #include "bundle_mgr_interface.h" 20 #include "iservice_registry.h" 21 #include "system_ability_definition.h" 22 #include "netstack_log.h" 23 #endif 24 25 namespace OHOS::NetStack::HttpUtils { IsDebugMode()26bool IsDebugMode() 27 { 28 #if HAS_NETMANAGER_BASE 29 sptr<ISystemAbilityManager> systemAbilityManager = 30 SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); 31 if (systemAbilityManager == nullptr) { 32 NETSTACK_LOGE("IsDebugMode failed to get system ability mgr."); 33 return false; 34 } 35 36 sptr<IRemoteObject> remoteObject = systemAbilityManager->GetSystemAbility(BUNDLE_MGR_SERVICE_SYS_ABILITY_ID); 37 if (remoteObject == nullptr) { 38 NETSTACK_LOGE("IsDebugMode failed to get bundle manager proxy."); 39 return false; 40 } 41 42 sptr<AppExecFwk::IBundleMgr> bundleMgrProxy = iface_cast<AppExecFwk::IBundleMgr>(remoteObject); 43 if (bundleMgrProxy == nullptr) { 44 NETSTACK_LOGE("IsDebugMode failed to get bundle manager proxy."); 45 return false; 46 } 47 48 AppExecFwk::BundleInfo bundleInfo; 49 constexpr auto flag = static_cast<uint32_t>(AppExecFwk::GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_APPLICATION); 50 const auto res = bundleMgrProxy->GetBundleInfoForSelf(flag, bundleInfo); 51 NETSTACK_LOGI("IsDebugMode GetBundleInfoForSelf res = %{public}d", res); 52 53 const auto appProvisionType = bundleInfo.applicationInfo.appProvisionType; 54 NETSTACK_LOGI("IsDebugMode appProvisionType = %{public}s", appProvisionType.c_str()); 55 return (appProvisionType == "debug") ? true : false; 56 #else 57 return true; 58 #endif 59 } 60 RemoveUrlParameters(const std::string & url)61std::string RemoveUrlParameters(const std::string& url) 62 { 63 size_t questionMarkPos = url.find('?'); 64 if (questionMarkPos == std::string::npos) { 65 return url; 66 } 67 return url.substr(0, questionMarkPos); 68 } 69 } // namespace OHOS::NetStack::HttpUtils