1 /* 2 * Copyright (C) 2020 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.pm.parsing.component; 18 19 import android.annotation.NonNull; 20 import android.content.pm.parsing.ParsingPackage; 21 import android.content.res.Resources; 22 import android.content.res.TypedArray; 23 import android.content.res.XmlResourceParser; 24 25 import com.android.internal.R; 26 import android.content.pm.parsing.result.ParseInput; 27 import android.content.pm.parsing.result.ParseResult; 28 29 import org.xmlpull.v1.XmlPullParserException; 30 31 import java.io.IOException; 32 33 /** @hide */ 34 public class ParsedInstrumentationUtils { 35 36 @NonNull parseInstrumentation(ParsingPackage pkg, Resources res, XmlResourceParser parser, boolean useRoundIcon, ParseInput input)37 public static ParseResult<ParsedInstrumentation> parseInstrumentation(ParsingPackage pkg, 38 Resources res, XmlResourceParser parser, boolean useRoundIcon, 39 ParseInput input) throws IOException, XmlPullParserException { 40 ParsedInstrumentation 41 instrumentation = new ParsedInstrumentation(); 42 String tag = "<" + parser.getName() + ">"; 43 44 TypedArray sa = res.obtainAttributes(parser, R.styleable.AndroidManifestInstrumentation); 45 try { 46 ParseResult<ParsedInstrumentation> result = ParsedComponentUtils.parseComponent( 47 instrumentation, tag, pkg, sa, useRoundIcon, input, 48 R.styleable.AndroidManifestInstrumentation_banner, 49 null /*descriptionAttr*/, 50 R.styleable.AndroidManifestInstrumentation_icon, 51 R.styleable.AndroidManifestInstrumentation_label, 52 R.styleable.AndroidManifestInstrumentation_logo, 53 R.styleable.AndroidManifestInstrumentation_name, 54 R.styleable.AndroidManifestInstrumentation_roundIcon); 55 if (result.isError()) { 56 return result; 57 } 58 59 // @formatter:off 60 // Note: don't allow this value to be a reference to a resource 61 // that may change. 62 instrumentation.setTargetPackage(sa.getNonResourceString(R.styleable.AndroidManifestInstrumentation_targetPackage)); 63 instrumentation.setTargetProcesses(sa.getNonResourceString(R.styleable.AndroidManifestInstrumentation_targetProcesses)); 64 instrumentation.handleProfiling = sa.getBoolean(R.styleable.AndroidManifestInstrumentation_handleProfiling, false); 65 instrumentation.functionalTest = sa.getBoolean(R.styleable.AndroidManifestInstrumentation_functionalTest, false); 66 // @formatter:on 67 } finally { 68 sa.recycle(); 69 } 70 71 return ComponentParseUtils.parseAllMetaData(pkg, res, parser, tag, instrumentation, 72 input); 73 } 74 } 75