Debian Codegraph @

core/java/android/content/pm/ComponentInfo.java

raw symbols SCIP
1 /*
2 * Copyright (C) 2008 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;
18
19 import android.annotation.SuppressLint;
20 import android.app.Activity;
21 import android.app.Service;
22 import android.compat.annotation.UnsupportedAppUsage;
23 import android.content.BroadcastReceiver;
24 import android.content.ComponentName;
25 import android.content.ContentResolver;
26 import android.content.Context;
27 import android.graphics.drawable.Drawable;
28 import android.os.Build;
29 import android.os.Parcel;
30 import android.util.Printer;
31
32 /**
33 * Base class containing information common to all application components
34 * ({@link ActivityInfo}, {@link ServiceInfo}). This class is not intended
35 * to be used by itself; it is simply here to share common definitions
36 * between all application components. As such, it does not itself
37 * implement Parcelable, but does provide convenience methods to assist
38 * in the implementation of Parcelable in subclasses.
39 */
40 public class ComponentInfo extends PackageItemInfo {
41 /**
42 * Global information about the application/package this component is a
43 * part of.
44 */
45 public ApplicationInfo applicationInfo;
46
47 /**
48 * The name of the process this component should run in.
49 * From the "android:process" attribute or, if not set, the same
50 * as <var>applicationInfo.processName</var>.
51 */
52 public String processName;
53
54 /**
55 * The name of the split in which this component is declared.
56 * Null if the component was declared in the base APK.
57 */
58 public String splitName;
59
60 /**
61 * Set of attribution tags that should be automatically applied to this
62 * component.
63 * <p>
64 * When this component represents an {@link Activity}, {@link Service},
65 * {@link ContentResolver} or {@link BroadcastReceiver}, each instance will
66 * be automatically configured with {@link Context#createAttributionContext}
67 * using the first attribution tag contained here.
68 * <p>
69 * Additionally, when this component represents a {@link BroadcastReceiver}
70 * and the sender of a broadcast requires the receiver to hold one or more
71 * specific permissions, those permission checks will be performed using
72 * each of the attributions tags contained here.
73 *
74 * @see Context#createAttributionContext(String)
75 */
76 @SuppressLint({"MissingNullability", "MutableBareField"})
77 public String[] attributionTags;
78
79 /**
80 * A string resource identifier (in the package's resources) containing
81 * a user-readable description of the component. From the "description"
82 * attribute or, if not set, 0.
83 */
84 public int descriptionRes;
85
86 /**
87 * Indicates whether or not this component may be instantiated. Note that this value can be
88 * overridden by the one in its parent {@link ApplicationInfo}.
89 */
90 public boolean enabled = true;
91
92 /**
93 * Set to true if this component is available for use by other applications.
94 * Comes from {@link android.R.attr#exported android:exported} of the
95 * &lt;activity&gt;, &lt;receiver&gt;, &lt;service&gt;, or
96 * &lt;provider&gt; tag.
97 */
98 public boolean exported = false;
99
100 /**
101 * Indicates if this component is aware of direct boot lifecycle, and can be
102 * safely run before the user has entered their credentials (such as a lock
103 * pattern or PIN).
104 */
105 public boolean directBootAware = false;
106
107 public ComponentInfo() {
108 }
109
110 public ComponentInfo(ComponentInfo orig) {
111 super(orig);
112 applicationInfo = orig.applicationInfo;
113 processName = orig.processName;
114 splitName = orig.splitName;
115 attributionTags = orig.attributionTags;
116 descriptionRes = orig.descriptionRes;
117 enabled = orig.enabled;
118 exported = orig.exported;
119 directBootAware = orig.directBootAware;
120 }
121
122 /** @hide */
123 @Override public CharSequence loadUnsafeLabel(PackageManager pm) {
124 if (nonLocalizedLabel != null) {
125 return nonLocalizedLabel;
126 }
127 ApplicationInfo ai = applicationInfo;
128 CharSequence label;
129 if (labelRes != 0) {
130 label = pm.getText(packageName, labelRes, ai);
131 if (label != null) {
132 return label;
133 }
134 }
135 if (ai.nonLocalizedLabel != null) {
136 return ai.nonLocalizedLabel;
137 }
138 if (ai.labelRes != 0) {
139 label = pm.getText(packageName, ai.labelRes, ai);
140 if (label != null) {
141 return label;
142 }
143 }
144 return name;
145 }
146
147 /**
148 * Return whether this component and its enclosing application are enabled.
149 */
150 public boolean isEnabled() {
151 return enabled && applicationInfo.enabled;
152 }
153
154 /**
155 * Return the icon resource identifier to use for this component. If
156 * the component defines an icon, that is used; else, the application
157 * icon is used.
158 *
159 * @return The icon associated with this component.
160 */
161 public final int getIconResource() {
162 return icon != 0 ? icon : applicationInfo.icon;
163 }
164
165 /**
166 * Return the logo resource identifier to use for this component. If
167 * the component defines a logo, that is used; else, the application
168 * logo is used.
169 *
170 * @return The logo associated with this component.
171 */
172 public final int getLogoResource() {
173 return logo != 0 ? logo : applicationInfo.logo;
174 }
175
176 /**
177 * Return the banner resource identifier to use for this component. If the
178 * component defines a banner, that is used; else, the application banner is
179 * used.
180 *
181 * @return The banner associated with this component.
182 */
183 public final int getBannerResource() {
184 return banner != 0 ? banner : applicationInfo.banner;
185 }
186
187 /** {@hide} */
188 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
189 public ComponentName getComponentName() {
190 return new ComponentName(packageName, name);
191 }
192
193 protected void dumpFront(Printer pw, String prefix) {
194 super.dumpFront(pw, prefix);
195 if (processName != null && !packageName.equals(processName)) {
196 pw.println(prefix + "processName=" + processName);
197 }
198 if (splitName != null) {
199 pw.println(prefix + "splitName=" + splitName);
200 }
201 if (attributionTags != null && attributionTags.length > 0) {
202 StringBuilder tags = new StringBuilder();
203 tags.append(attributionTags[0]);
204 for (int i = 1; i < attributionTags.length; i++) {
205 tags.append(", ");
206 tags.append(attributionTags[i]);
207 }
208 pw.println(prefix + "attributionTags=[" + tags + "]");
209 }
210 pw.println(prefix + "enabled=" + enabled + " exported=" + exported
211 + " directBootAware=" + directBootAware);
212 if (descriptionRes != 0) {
213 pw.println(prefix + "description=" + descriptionRes);
214 }
215 }
216
217 protected void dumpBack(Printer pw, String prefix) {
218 dumpBack(pw, prefix, DUMP_FLAG_ALL);
219 }
220
221 void dumpBack(Printer pw, String prefix, int dumpFlags) {
222 if ((dumpFlags & DUMP_FLAG_APPLICATION) != 0) {
223 if (applicationInfo != null) {
224 pw.println(prefix + "ApplicationInfo:");
225 applicationInfo.dump(pw, prefix + " ", dumpFlags);
226 } else {
227 pw.println(prefix + "ApplicationInfo: null");
228 }
229 }
230 super.dumpBack(pw, prefix);
231 }
232
233 public void writeToParcel(Parcel dest, int parcelableFlags) {
234 super.writeToParcel(dest, parcelableFlags);
235 applicationInfo.writeToParcel(dest, parcelableFlags);
236 dest.writeString8(processName);
237 dest.writeString8(splitName);
238 dest.writeString8Array(attributionTags);
239 dest.writeInt(descriptionRes);
240 dest.writeInt(enabled ? 1 : 0);
241 dest.writeInt(exported ? 1 : 0);
242 dest.writeInt(directBootAware ? 1 : 0);
243 }
244
245 protected ComponentInfo(Parcel source) {
246 super(source);
247 applicationInfo = ApplicationInfo.CREATOR.createFromParcel(source);
248 processName = source.readString8();
249 splitName = source.readString8();
250 attributionTags = source.createString8Array();
251 descriptionRes = source.readInt();
252 enabled = (source.readInt() != 0);
253 exported = (source.readInt() != 0);
254 directBootAware = (source.readInt() != 0);
255 }
256
257 /**
258 * @hide
259 */
260 @Override
261 public Drawable loadDefaultIcon(PackageManager pm) {
262 return applicationInfo.loadIcon(pm);
263 }
264
265 /**
266 * @hide
267 */
268 @Override protected Drawable loadDefaultBanner(PackageManager pm) {
269 return applicationInfo.loadBanner(pm);
270 }
271
272 /**
273 * @hide
274 */
275 @Override
276 protected Drawable loadDefaultLogo(PackageManager pm) {
277 return applicationInfo.loadLogo(pm);
278 }
279
280 /**
281 * @hide
282 */
283 @Override protected ApplicationInfo getApplicationInfo() {
284 return applicationInfo;
285 }
286 }