blob: 362098c447cea0a46e803dcc9c6af15afd6c3c9a [file] [log] [blame]
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001/*
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
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080017package android.content.pm;
18
Artur Satayeve23a0eb2019-12-10 17:47:52 +000019import android.compat.annotation.UnsupportedAppUsage;
Jeff Sharkey5217cac2015-12-20 15:34:01 -070020import android.content.ComponentName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080021import android.graphics.drawable.Drawable;
22import android.os.Parcel;
23import android.util.Printer;
24
25/**
26 * Base class containing information common to all application components
27 * ({@link ActivityInfo}, {@link ServiceInfo}). This class is not intended
28 * to be used by itself; it is simply here to share common definitions
29 * between all application components. As such, it does not itself
30 * implement Parcelable, but does provide convenience methods to assist
31 * in the implementation of Parcelable in subclasses.
32 */
33public class ComponentInfo extends PackageItemInfo {
34 /**
35 * Global information about the application/package this component is a
36 * part of.
37 */
38 public ApplicationInfo applicationInfo;
39
40 /**
41 * The name of the process this component should run in.
42 * From the "android:process" attribute or, if not set, the same
43 * as <var>applicationInfo.processName</var>.
44 */
45 public String processName;
46
47 /**
Adam Lesinski4e862812016-11-21 16:02:24 -080048 * The name of the split in which this component is declared.
49 * Null if the component was declared in the base APK.
50 */
51 public String splitName;
52
53 /**
Dianne Hackborn8aa2e892010-01-22 11:31:30 -080054 * A string resource identifier (in the package's resources) containing
55 * a user-readable description of the component. From the "description"
56 * attribute or, if not set, 0.
57 */
58 public int descriptionRes;
59
60 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080061 * Indicates whether or not this component may be instantiated. Note that this value can be
Adam Lesinski4e862812016-11-21 16:02:24 -080062 * overridden by the one in its parent {@link ApplicationInfo}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080063 */
64 public boolean enabled = true;
65
66 /**
67 * Set to true if this component is available for use by other applications.
68 * Comes from {@link android.R.attr#exported android:exported} of the
69 * &lt;activity&gt;, &lt;receiver&gt;, &lt;service&gt;, or
70 * &lt;provider&gt; tag.
71 */
72 public boolean exported = false;
Jeff Sharkeye17ac152015-11-06 22:40:29 -080073
74 /**
Jeff Sharkey8a372a02016-03-16 16:25:45 -060075 * Indicates if this component is aware of direct boot lifecycle, and can be
Jeff Sharkeye17ac152015-11-06 22:40:29 -080076 * safely run before the user has entered their credentials (such as a lock
77 * pattern or PIN).
78 */
Jeff Sharkey8a372a02016-03-16 16:25:45 -060079 public boolean directBootAware = false;
80
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080081 public ComponentInfo() {
82 }
83
84 public ComponentInfo(ComponentInfo orig) {
85 super(orig);
86 applicationInfo = orig.applicationInfo;
87 processName = orig.processName;
Adam Lesinski4e862812016-11-21 16:02:24 -080088 splitName = orig.splitName;
Dianne Hackborn8aa2e892010-01-22 11:31:30 -080089 descriptionRes = orig.descriptionRes;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080090 enabled = orig.enabled;
91 exported = orig.exported;
Kweku Adams091fa302019-06-17 15:59:01 -070092 directBootAware = orig.directBootAware;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080093 }
94
Todd Kennedy6e403952018-05-03 10:05:04 +010095 /** @hide */
96 @Override public CharSequence loadUnsafeLabel(PackageManager pm) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080097 if (nonLocalizedLabel != null) {
98 return nonLocalizedLabel;
99 }
100 ApplicationInfo ai = applicationInfo;
101 CharSequence label;
102 if (labelRes != 0) {
103 label = pm.getText(packageName, labelRes, ai);
104 if (label != null) {
105 return label;
106 }
107 }
108 if (ai.nonLocalizedLabel != null) {
109 return ai.nonLocalizedLabel;
110 }
111 if (ai.labelRes != 0) {
112 label = pm.getText(packageName, ai.labelRes, ai);
113 if (label != null) {
114 return label;
115 }
116 }
117 return name;
118 }
Joe Onoratoa85a9152011-01-07 20:48:00 -0800119
120 /**
121 * Return whether this component and its enclosing application are enabled.
122 */
123 public boolean isEnabled() {
124 return enabled && applicationInfo.enabled;
125 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800126
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800127 /**
128 * Return the icon resource identifier to use for this component. If
129 * the component defines an icon, that is used; else, the application
130 * icon is used.
131 *
132 * @return The icon associated with this component.
133 */
134 public final int getIconResource() {
135 return icon != 0 ? icon : applicationInfo.icon;
136 }
Adam Powell04fe6eb2013-05-31 14:39:48 -0700137
138 /**
139 * Return the logo resource identifier to use for this component. If
140 * the component defines a logo, that is used; else, the application
141 * logo is used.
142 *
143 * @return The logo associated with this component.
144 */
145 public final int getLogoResource() {
146 return logo != 0 ? logo : applicationInfo.logo;
147 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800148
Jose Limaf78e3122014-03-06 12:13:15 -0800149 /**
150 * Return the banner resource identifier to use for this component. If the
151 * component defines a banner, that is used; else, the application banner is
152 * used.
153 *
154 * @return The banner associated with this component.
155 */
156 public final int getBannerResource() {
157 return banner != 0 ? banner : applicationInfo.banner;
158 }
159
Jeff Sharkey5217cac2015-12-20 15:34:01 -0700160 /** {@hide} */
Mathew Inwood5c0d3542018-08-14 13:54:31 +0100161 @UnsupportedAppUsage
Jeff Sharkey5217cac2015-12-20 15:34:01 -0700162 public ComponentName getComponentName() {
163 return new ComponentName(packageName, name);
164 }
165
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800166 protected void dumpFront(Printer pw, String prefix) {
167 super.dumpFront(pw, prefix);
Dianne Hackborn6ac42ae2015-12-08 17:22:10 -0800168 if (processName != null && !packageName.equals(processName)) {
169 pw.println(prefix + "processName=" + processName);
170 }
Adam Lesinski4e862812016-11-21 16:02:24 -0800171 if (splitName != null) {
172 pw.println(prefix + "splitName=" + splitName);
173 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800174 pw.println(prefix + "enabled=" + enabled + " exported=" + exported
Jeff Sharkey8a372a02016-03-16 16:25:45 -0600175 + " directBootAware=" + directBootAware);
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800176 if (descriptionRes != 0) {
177 pw.println(prefix + "description=" + descriptionRes);
178 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800179 }
Dianne Hackborn6ac42ae2015-12-08 17:22:10 -0800180
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800181 protected void dumpBack(Printer pw, String prefix) {
Dianne Hackborn6ac42ae2015-12-08 17:22:10 -0800182 dumpBack(pw, prefix, DUMP_FLAG_ALL);
183 }
Yohei Yukawa8f272172017-08-31 00:26:01 -0700184
185 void dumpBack(Printer pw, String prefix, int dumpFlags) {
186 if ((dumpFlags & DUMP_FLAG_APPLICATION) != 0) {
Dianne Hackborn6ac42ae2015-12-08 17:22:10 -0800187 if (applicationInfo != null) {
188 pw.println(prefix + "ApplicationInfo:");
Yohei Yukawa8f272172017-08-31 00:26:01 -0700189 applicationInfo.dump(pw, prefix + " ", dumpFlags);
Dianne Hackborn6ac42ae2015-12-08 17:22:10 -0800190 } else {
191 pw.println(prefix + "ApplicationInfo: null");
192 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800193 }
194 super.dumpBack(pw, prefix);
195 }
Dianne Hackborn6ac42ae2015-12-08 17:22:10 -0800196
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800197 public void writeToParcel(Parcel dest, int parcelableFlags) {
198 super.writeToParcel(dest, parcelableFlags);
Makoto Onuki2d80ca02020-02-12 14:20:36 -0800199 applicationInfo.writeToParcel(dest, parcelableFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800200 dest.writeString(processName);
Adam Lesinski4e862812016-11-21 16:02:24 -0800201 dest.writeString(splitName);
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800202 dest.writeInt(descriptionRes);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800203 dest.writeInt(enabled ? 1 : 0);
204 dest.writeInt(exported ? 1 : 0);
Jeff Sharkey8a372a02016-03-16 16:25:45 -0600205 dest.writeInt(directBootAware ? 1 : 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800206 }
Jeff Brown07330792010-03-30 19:57:08 -0700207
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800208 protected ComponentInfo(Parcel source) {
209 super(source);
Makoto Onuki2d80ca02020-02-12 14:20:36 -0800210 applicationInfo = ApplicationInfo.CREATOR.createFromParcel(source);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800211 processName = source.readString();
Adam Lesinski4e862812016-11-21 16:02:24 -0800212 splitName = source.readString();
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800213 descriptionRes = source.readInt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800214 enabled = (source.readInt() != 0);
215 exported = (source.readInt() != 0);
Kweku Adams091fa302019-06-17 15:59:01 -0700216 directBootAware = (source.readInt() != 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800217 }
Jeff Sharkey8a372a02016-03-16 16:25:45 -0600218
Jeff Brown07330792010-03-30 19:57:08 -0700219 /**
220 * @hide
221 */
Alexandra Gherghinaa7093142014-07-30 13:43:39 +0100222 @Override
223 public Drawable loadDefaultIcon(PackageManager pm) {
Jeff Brown07330792010-03-30 19:57:08 -0700224 return applicationInfo.loadIcon(pm);
225 }
226
227 /**
228 * @hide
229 */
Jose Limaf78e3122014-03-06 12:13:15 -0800230 @Override protected Drawable loadDefaultBanner(PackageManager pm) {
231 return applicationInfo.loadBanner(pm);
232 }
233
234 /**
235 * @hide
236 */
Adam Powell81cd2e92010-04-21 16:35:18 -0700237 @Override
238 protected Drawable loadDefaultLogo(PackageManager pm) {
239 return applicationInfo.loadLogo(pm);
240 }
241
242 /**
243 * @hide
244 */
Jeff Brown07330792010-03-30 19:57:08 -0700245 @Override protected ApplicationInfo getApplicationInfo() {
246 return applicationInfo;
247 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800248}