1 /* 2 * Copyright (c) 2024 Huawei Device Co., Ltd.. All rights reserved. 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 "text_bundle_config_parser.h" 17 18 #ifdef OHOS_TEXT_ENABLE 19 #include "application_info.h" 20 #include "hap_module_info.h" 21 #include "iservice_registry.h" 22 #include "system_ability_definition.h" 23 #include "utils/text_log.h" 24 #endif 25 26 namespace OHOS { 27 namespace Rosen { 28 namespace SPText { 29 #ifdef OHOS_TEXT_ENABLE IsMetaDataExistInModule(const std::string & metaData)30bool TextBundleConfigParser::IsMetaDataExistInModule(const std::string& metaData) 31 { 32 auto bundleMgr = GetSystemAbilityManager(); 33 if (bundleMgr == nullptr) { 34 TEXT_LOGE("Bundle manager is nullptr"); 35 return false; 36 } 37 38 AppExecFwk::BundleInfo bundleInfo; 39 ErrCode errCode = bundleMgr->GetBundleInfoForSelf( 40 static_cast<int32_t>(AppExecFwk::GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_HAP_MODULE) | 41 static_cast<int32_t>(AppExecFwk::GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_METADATA), 42 bundleInfo); 43 if (FAILED(errCode)) { 44 TEXT_LOGE("Get bundle info for self failed, errcode: %{public}x", errCode); 45 return false; 46 } 47 48 for (const auto& info : bundleInfo.hapModuleInfos) { 49 for (const auto& data : info.metadata) { 50 if (data.name == metaData) { 51 return true; 52 } 53 } 54 } 55 56 return false; 57 } 58 GetSystemAbilityManager()59sptr<AppExecFwk::IBundleMgr> TextBundleConfigParser::GetSystemAbilityManager() 60 { 61 auto systemAbilityManager = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); 62 if (systemAbilityManager == nullptr) { 63 TEXT_LOGE("System ability manager is nullptr"); 64 return nullptr; 65 } 66 67 sptr<IRemoteObject> remoteObject = systemAbilityManager->GetSystemAbility(BUNDLE_MGR_SERVICE_SYS_ABILITY_ID); 68 if (remoteObject == nullptr) { 69 TEXT_LOGE("Remote object is nullptr"); 70 return nullptr; 71 } 72 73 return iface_cast<AppExecFwk::IBundleMgr>(remoteObject); 74 } 75 #endif 76 IsAdapterTextHeightEnabled()77bool TextBundleConfigParser::IsAdapterTextHeightEnabled() 78 { 79 #ifdef OHOS_TEXT_ENABLE 80 static bool adapterTextHeight = []() { 81 const std::string ADAPTER_TEXT_HEIGHT_META_DATA = "ohos.graphics2d.text.adapter_text_height"; 82 auto enabled = IsMetaDataExistInModule(ADAPTER_TEXT_HEIGHT_META_DATA); 83 TEXT_LOGI("Adapter text height enabled: %{public}d", enabled); 84 return enabled; 85 }(); 86 return adapterTextHeight; 87 #else 88 return false; 89 #endif 90 } 91 } // namespace SPText 92 } // namespace Rosen 93 } // namespace OHOS