1e75ebbc8Sopenharmony_ci/** 2e75ebbc8Sopenharmony_ci * Copyright (c) 2021-2022 Huawei Device Co., Ltd. 3e75ebbc8Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4e75ebbc8Sopenharmony_ci * you may not use this file except in compliance with the License. 5e75ebbc8Sopenharmony_ci * You may obtain a copy of the License at 6e75ebbc8Sopenharmony_ci * 7e75ebbc8Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8e75ebbc8Sopenharmony_ci * 9e75ebbc8Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10e75ebbc8Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11e75ebbc8Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12e75ebbc8Sopenharmony_ci * See the License for the specific language governing permissions and 13e75ebbc8Sopenharmony_ci * limitations under the License. 14e75ebbc8Sopenharmony_ci */ 15e75ebbc8Sopenharmony_ciimport AbilityManager from './abilitymanager/abilityManager' 16e75ebbc8Sopenharmony_ci 17e75ebbc8Sopenharmony_ci/** 18e75ebbc8Sopenharmony_ci * Resource util 19e75ebbc8Sopenharmony_ci */ 20e75ebbc8Sopenharmony_ciexport class ResourceUtil { 21e75ebbc8Sopenharmony_ci private resMgr; 22e75ebbc8Sopenharmony_ci 23e75ebbc8Sopenharmony_ci /** 24e75ebbc8Sopenharmony_ci * Initialize ResourceManager 25e75ebbc8Sopenharmony_ci */ 26e75ebbc8Sopenharmony_ci async initResourceManager(abilityName?: string): Promise<void> { 27e75ebbc8Sopenharmony_ci if (!this.resMgr) { 28e75ebbc8Sopenharmony_ci 29e75ebbc8Sopenharmony_ci let context; 30e75ebbc8Sopenharmony_ci if(abilityName === AbilityManager.ABILITY_NAME_NOTIFICATION_MANAGEMENT) { 31e75ebbc8Sopenharmony_ci context = AbilityManager.getAbilityContext(abilityName); 32e75ebbc8Sopenharmony_ci } else { 33e75ebbc8Sopenharmony_ci context = AbilityManager.getContext(abilityName); 34e75ebbc8Sopenharmony_ci } 35e75ebbc8Sopenharmony_ci this.resMgr = await context.resourceManager; 36e75ebbc8Sopenharmony_ci } 37e75ebbc8Sopenharmony_ci return this.resMgr; 38e75ebbc8Sopenharmony_ci } 39e75ebbc8Sopenharmony_ci 40e75ebbc8Sopenharmony_ci /** 41e75ebbc8Sopenharmony_ci * Get string value from NormalResource instance 42e75ebbc8Sopenharmony_ci * 43e75ebbc8Sopenharmony_ci * @param resource - NormalResource instance 44e75ebbc8Sopenharmony_ci */ 45e75ebbc8Sopenharmony_ci async getString(resource): Promise<string> { 46e75ebbc8Sopenharmony_ci return await this.resMgr.getString(resource.id); 47e75ebbc8Sopenharmony_ci } 48e75ebbc8Sopenharmony_ci 49e75ebbc8Sopenharmony_ci /** 50e75ebbc8Sopenharmony_ci * Get direction value from NormalResource instance 51e75ebbc8Sopenharmony_ci * 52e75ebbc8Sopenharmony_ci * @param resource - NormalResource instance 53e75ebbc8Sopenharmony_ci */ 54e75ebbc8Sopenharmony_ci async getConfiguration(): Promise<string> { 55e75ebbc8Sopenharmony_ci return await this.resMgr.getConfiguration(); 56e75ebbc8Sopenharmony_ci } 57e75ebbc8Sopenharmony_ci} 58e75ebbc8Sopenharmony_ci 59e75ebbc8Sopenharmony_cilet resourceUtil = new ResourceUtil(); 60e75ebbc8Sopenharmony_ci 61e75ebbc8Sopenharmony_ciexport default resourceUtil as ResourceUtil;