1 /* 2 * Copyright (C) 2022 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package android.content.res; 18 19 import java.util.Map; 20 21 /** Stub class to compile the linter for host execution. */ 22 public final class Resources { 23 /** Constant used in the Safety Center config parser. */ 24 public static final int ID_NULL = 0; 25 26 private static final String STRING_TYPE = "string"; 27 28 private final String mPackageName; 29 private final Map<String, Integer> mNameToIndex; 30 private final Map<Integer, String> mIndexToValue; 31 32 /** Class used in the Safety Center config parser. */ Resources( String packageName, Map<String, Integer> nameToIndex, Map<Integer, String> indexToValue)33 public Resources( 34 String packageName, 35 Map<String, Integer> nameToIndex, 36 Map<Integer, String> indexToValue) { 37 mPackageName = packageName; 38 mNameToIndex = nameToIndex; 39 mIndexToValue = indexToValue; 40 } 41 42 /** This exception is thrown by the resource APIs when a requested resource can not be found. */ 43 public static final class NotFoundException extends RuntimeException { NotFoundException()44 public NotFoundException() {} 45 } 46 47 /** Method used in the Safety Center config parser. */ getIdentifier(String name, String defType, String defPackage)48 public int getIdentifier(String name, String defType, String defPackage) { 49 if (!mPackageName.equals(defPackage) 50 || !STRING_TYPE.equals(defType) 51 || !mNameToIndex.containsKey(name)) { 52 return ID_NULL; 53 } 54 return mNameToIndex.get(name); 55 } 56 57 /** Method used in the Safety Center config parser. */ getString(int id)58 public String getString(int id) { 59 if (mIndexToValue.containsKey(id)) { 60 return mIndexToValue.get(id); 61 } 62 throw new NotFoundException(); 63 } 64 } 65