blob: f4c9914cb69fa24f675523e31f0923adb87fb63c [file] [log] [blame]
Winson022e7072020-01-28 10:52:58 -08001/*
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
17package android.content.pm.parsing.component;
18
19import android.annotation.NonNull;
20import android.annotation.Nullable;
21import android.content.IntentFilter;
22import android.content.pm.parsing.ParsingPackage;
Winson727da642020-03-10 15:25:32 -070023import android.content.pm.parsing.ParsingPackageUtils;
24import android.content.pm.parsing.result.ParseInput;
25import android.content.pm.parsing.result.ParseResult;
Winson022e7072020-01-28 10:52:58 -080026import android.content.res.Configuration;
27import android.content.res.Resources;
28import android.content.res.TypedArray;
29import android.content.res.XmlResourceParser;
30import android.os.Build;
31import android.util.Slog;
32
33import com.android.internal.annotations.VisibleForTesting;
Winson022e7072020-01-28 10:52:58 -080034
35import org.xmlpull.v1.XmlPullParserException;
36
37import java.io.IOException;
38
39/** @hide */
40class ParsedMainComponentUtils {
41
42 private static final String TAG = ParsingPackageUtils.TAG;
43
44 @NonNull
45 @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE)
46 static <Component extends ParsedMainComponent> ParseResult<Component> parseMainComponent(
47 Component component, String tag, String[] separateProcesses, ParsingPackage pkg,
48 TypedArray array, int flags, boolean useRoundIcon, ParseInput input,
49 int bannerAttr, int descriptionAttr, @Nullable Integer directBootAwareAttr,
50 @Nullable Integer enabledAttr, int iconAttr, int labelAttr, int logoAttr, int nameAttr,
51 @Nullable Integer processAttr, int roundIconAttr, @Nullable Integer splitNameAttr) {
52 ParseResult<Component> result = ParsedComponentUtils.parseComponent(component, tag, pkg,
53 array, useRoundIcon, input, bannerAttr, descriptionAttr, iconAttr, labelAttr,
54 logoAttr, nameAttr, roundIconAttr);
55 if (result.isError()) {
56 return result;
57 }
58
59 if (directBootAwareAttr != null) {
60 component.directBootAware = array.getBoolean(directBootAwareAttr, false);
61 if (component.isDirectBootAware()) {
62 pkg.setPartiallyDirectBootAware(true);
63 }
64 }
65
66 if (enabledAttr != null) {
67 component.enabled = array.getBoolean(enabledAttr, true);
68 }
69
70 if (processAttr != null) {
71 CharSequence processName;
72 if (pkg.getTargetSdkVersion() >= Build.VERSION_CODES.FROYO) {
73 processName = array.getNonConfigurationString(processAttr,
74 Configuration.NATIVE_CONFIG_VERSION);
75 } else {
76 // Some older apps have been seen to use a resource reference
77 // here that on older builds was ignored (with a warning). We
78 // need to continue to do this for them so they don't break.
79 processName = array.getNonResourceString(processAttr);
80 }
81
82 // Backwards-compat, ignore error
83 ParseResult<String> processNameResult = ComponentParseUtils.buildProcessName(
84 pkg.getPackageName(), pkg.getProcessName(), processName, flags,
85 separateProcesses, input);
Winson727da642020-03-10 15:25:32 -070086 if (processNameResult.isError()) {
87 return input.error(processNameResult);
Winson022e7072020-01-28 10:52:58 -080088 }
Winson727da642020-03-10 15:25:32 -070089
90 component.setProcessName(processNameResult.getResult());
Winson022e7072020-01-28 10:52:58 -080091 }
92
93 if (splitNameAttr != null) {
94 component.splitName = array.getNonConfigurationString(splitNameAttr, 0);
95 }
96
97 return input.success(component);
98 }
99
100 static ParseResult<ParsedIntentInfo> parseIntentFilter(
101 ParsedMainComponent mainComponent,
102 ParsingPackage pkg, Resources resources, XmlResourceParser parser,
103 boolean visibleToEphemeral, boolean allowGlobs, boolean allowAutoVerify,
104 boolean allowImplicitEphemeralVisibility, boolean failOnNoActions,
105 ParseInput input) throws IOException, XmlPullParserException {
106 ParseResult<ParsedIntentInfo> intentResult = ParsedIntentInfoUtils.parseIntentInfo(
107 mainComponent.getName(), pkg, resources, parser, allowGlobs,
108 allowAutoVerify, input);
109 if (intentResult.isError()) {
110 return input.error(intentResult);
111 }
112
113 ParsedIntentInfo intent = intentResult.getResult();
114 int actionCount = intent.countActions();
115 if (actionCount == 0 && failOnNoActions) {
116 Slog.w(TAG, "No actions in " + parser.getName() + " at " + pkg.getBaseCodePath() + " "
117 + parser.getPositionDescription());
118 // Backward-compat, do not actually fail
119 return input.success(null);
120 }
121
122 int intentVisibility;
123 if (visibleToEphemeral) {
124 intentVisibility = IntentFilter.VISIBILITY_EXPLICIT;
125 } else if (allowImplicitEphemeralVisibility
126 && ComponentParseUtils.isImplicitlyExposedIntent(intent)){
127 intentVisibility = IntentFilter.VISIBILITY_IMPLICIT;
128 } else {
129 intentVisibility = IntentFilter.VISIBILITY_NONE;
130 }
131 intent.setVisibilityToInstantApp(intentVisibility);
132
133 return input.success(intentResult.getResult());
134 }
135
136}