• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     public static final String TAG = "PackageParsing";
37 
38     public static final String ANDROID_RES_NAMESPACE = "http://schemas.android.com/apk/res/android";
39 
40     public static final int DEFAULT_MIN_SDK_VERSION = 1;
41     public static final int DEFAULT_TARGET_SDK_VERSION = 0;
42 
43     @Nullable
buildClassName(String pkg, CharSequence clsSeq)44     public static String buildClassName(String pkg, CharSequence clsSeq) {
45         if (clsSeq == null || clsSeq.length() <= 0) {
46             return null;
47         }
48         String cls = clsSeq.toString();
49         char c = cls.charAt(0);
50         if (c == '.') {
51             return pkg + cls;
52         }
53         if (cls.indexOf('.') < 0) {
54             StringBuilder b = new StringBuilder(pkg);
55             b.append('.');
56             b.append(cls);
57             return b.toString();
58         }
59         return cls;
60     }
61 
62     @NonNull
unknownTag(String parentTag, ParsingPackage pkg, XmlResourceParser parser, ParseInput input)63     public static ParseResult unknownTag(String parentTag, ParsingPackage pkg,
64             XmlResourceParser parser, ParseInput input) throws IOException, XmlPullParserException {
65         if (PackageParser.RIGID_PARSER) {
66             return input.error("Bad element under " + parentTag + ": " + parser.getName());
67         }
68         Slog.w(TAG, "Unknown element under " + parentTag + ": "
69                 + parser.getName() + " at " + pkg.getBaseApkPath() + " "
70                 + parser.getPositionDescription());
71         XmlUtils.skipCurrentTag(parser);
72         return input.success(null); // Type doesn't matter
73     }
74 }
75