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; 18 19 import android.annotation.NonNull; 20 import android.annotation.Nullable; 21 import android.content.pm.PackageParser; 22 import android.content.pm.parsing.result.ParseInput; 23 import android.content.pm.parsing.result.ParseResult; 24 import android.content.res.XmlResourceParser; 25 import android.util.Slog; 26 27 import com.android.internal.util.XmlUtils; 28 29 import org.xmlpull.v1.XmlPullParserException; 30 31 import java.io.IOException; 32 33 /** @hide **/ 34 public class ParsingUtils { 35 36 // TODO(b/135203078): Consolidate log tags 37 public static final String TAG = "PackageParsing"; 38 39 @Nullable buildClassName(String pkg, CharSequence clsSeq)40 public static String buildClassName(String pkg, CharSequence clsSeq) { 41 if (clsSeq == null || clsSeq.length() <= 0) { 42 return null; 43 } 44 String cls = clsSeq.toString(); 45 char c = cls.charAt(0); 46 if (c == '.') { 47 return pkg + cls; 48 } 49 if (cls.indexOf('.') < 0) { 50 StringBuilder b = new StringBuilder(pkg); 51 b.append('.'); 52 b.append(cls); 53 return b.toString(); 54 } 55 return cls; 56 } 57 58 @NonNull unknownTag(String parentTag, ParsingPackage pkg, XmlResourceParser parser, ParseInput input)59 public static ParseResult unknownTag(String parentTag, ParsingPackage pkg, 60 XmlResourceParser parser, ParseInput input) throws IOException, XmlPullParserException { 61 if (PackageParser.RIGID_PARSER) { 62 return input.error("Bad element under " + parentTag + ": " + parser.getName()); 63 } 64 Slog.w(TAG, "Unknown element under " + parentTag + ": " 65 + parser.getName() + " at " + pkg.getBaseCodePath() + " " 66 + parser.getPositionDescription()); 67 XmlUtils.skipCurrentTag(parser); 68 return input.success(null); // Type doesn't matter 69 } 70 } 71