blob: 29612c25d0cd48fa247fc450fa6656ada45a0c2e [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
Mathew Inwood5c0d3542018-08-14 13:54:31 +010019import android.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;
Christopher Tateb9116762015-09-09 18:46:31 -070023import android.os.Parcelable;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080024import android.util.Printer;
25
26/**
27 * Base class containing information common to all application components
28 * ({@link ActivityInfo}, {@link ServiceInfo}). This class is not intended
29 * to be used by itself; it is simply here to share common definitions
30 * between all application components. As such, it does not itself
31 * implement Parcelable, but does provide convenience methods to assist
32 * in the implementation of Parcelable in subclasses.
33 */
34public class ComponentInfo extends PackageItemInfo {
35 /**
36 * Global information about the application/package this component is a
37 * part of.
38 */
39 public ApplicationInfo applicationInfo;
40
41 /**
42 * The name of the process this component should run in.
43 * From the "android:process" attribute or, if not set, the same
44 * as <var>applicationInfo.processName</var>.
45 */
46 public String processName;
47
48 /**
Adam Lesinski4e862812016-11-21 16:02:24 -080049 * The name of the split in which this component is declared.
50 * Null if the component was declared in the base APK.
51 */
52 public String splitName;
53
54 /**
Dianne Hackborn8aa2e892010-01-22 11:31:30 -080055 * A string resource identifier (in the package's resources) containing
56 * a user-readable description of the component. From the "description"
57 * attribute or, if not set, 0.
58 */
59 public int descriptionRes;
60
61 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080062 * Indicates whether or not this component may be instantiated. Note that this value can be
Adam Lesinski4e862812016-11-21 16:02:24 -080063 * overridden by the one in its parent {@link ApplicationInfo}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080064 */
65 public boolean enabled = true;
66
67 /**
68 * Set to true if this component is available for use by other applications.
69 * Comes from {@link android.R.attr#exported android:exported} of the
70 * &lt;activity&gt;, &lt;receiver&gt;, &lt;service&gt;, or
71 * &lt;provider&gt; tag.
72 */
73 public boolean exported = false;
Jeff Sharkeye17ac152015-11-06 22:40:29 -080074
75 /**
Jeff Sharkey8a372a02016-03-16 16:25:45 -060076 * Indicates if this component is aware of direct boot lifecycle, and can be
Jeff Sharkeye17ac152015-11-06 22:40:29 -080077 * safely run before the user has entered their credentials (such as a lock
78 * pattern or PIN).
79 */
Jeff Sharkey8a372a02016-03-16 16:25:45 -060080 public boolean directBootAware = false;
81
82 /** @removed */
83 @Deprecated
Jeff Sharkeye17ac152015-11-06 22:40:29 -080084 public boolean encryptionAware = false;
85
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080086 public ComponentInfo() {
87 }
88
89 public ComponentInfo(ComponentInfo orig) {
90 super(orig);
91 applicationInfo = orig.applicationInfo;
92 processName = orig.processName;
Adam Lesinski4e862812016-11-21 16:02:24 -080093 splitName = orig.splitName;
Dianne Hackborn8aa2e892010-01-22 11:31:30 -080094 descriptionRes = orig.descriptionRes;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080095 enabled = orig.enabled;
96 exported = orig.exported;
Jeff Sharkey8a372a02016-03-16 16:25:45 -060097 encryptionAware = directBootAware = orig.directBootAware;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080098 }
99
Todd Kennedy6e403952018-05-03 10:05:04 +0100100 /** @hide */
101 @Override public CharSequence loadUnsafeLabel(PackageManager pm) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800102 if (nonLocalizedLabel != null) {
103 return nonLocalizedLabel;
104 }
105 ApplicationInfo ai = applicationInfo;
106 CharSequence label;
107 if (labelRes != 0) {
108 label = pm.getText(packageName, labelRes, ai);
109 if (label != null) {
110 return label;
111 }
112 }
113 if (ai.nonLocalizedLabel != null) {
114 return ai.nonLocalizedLabel;
115 }
116 if (ai.labelRes != 0) {
117 label = pm.getText(packageName, ai.labelRes, ai);
118 if (label != null) {
119 return label;
120 }
121 }
122 return name;
123 }
Joe Onoratoa85a9152011-01-07 20:48:00 -0800124
125 /**
126 * Return whether this component and its enclosing application are enabled.
127 */
128 public boolean isEnabled() {
129 return enabled && applicationInfo.enabled;
130 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800131
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800132 /**
133 * Return the icon resource identifier to use for this component. If
134 * the component defines an icon, that is used; else, the application
135 * icon is used.
136 *
137 * @return The icon associated with this component.
138 */
139 public final int getIconResource() {
140 return icon != 0 ? icon : applicationInfo.icon;
141 }
Adam Powell04fe6eb2013-05-31 14:39:48 -0700142
143 /**
144 * Return the logo resource identifier to use for this component. If
145 * the component defines a logo, that is used; else, the application
146 * logo is used.
147 *
148 * @return The logo associated with this component.
149 */
150 public final int getLogoResource() {
151 return logo != 0 ? logo : applicationInfo.logo;
152 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800153
Jose Limaf78e3122014-03-06 12:13:15 -0800154 /**
155 * Return the banner resource identifier to use for this component. If the
156 * component defines a banner, that is used; else, the application banner is
157 * used.
158 *
159 * @return The banner associated with this component.
160 */
161 public final int getBannerResource() {
162 return banner != 0 ? banner : applicationInfo.banner;
163 }
164
Jeff Sharkey5217cac2015-12-20 15:34:01 -0700165 /** {@hide} */
Mathew Inwood5c0d3542018-08-14 13:54:31 +0100166 @UnsupportedAppUsage
Jeff Sharkey5217cac2015-12-20 15:34:01 -0700167 public ComponentName getComponentName() {
168 return new ComponentName(packageName, name);
169 }
170
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800171 protected void dumpFront(Printer pw, String prefix) {
172 super.dumpFront(pw, prefix);
Dianne Hackborn6ac42ae2015-12-08 17:22:10 -0800173 if (processName != null && !packageName.equals(processName)) {
174 pw.println(prefix + "processName=" + processName);
175 }
Adam Lesinski4e862812016-11-21 16:02:24 -0800176 if (splitName != null) {
177 pw.println(prefix + "splitName=" + splitName);
178 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800179 pw.println(prefix + "enabled=" + enabled + " exported=" + exported
Jeff Sharkey8a372a02016-03-16 16:25:45 -0600180 + " directBootAware=" + directBootAware);
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800181 if (descriptionRes != 0) {
182 pw.println(prefix + "description=" + descriptionRes);
183 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800184 }
Dianne Hackborn6ac42ae2015-12-08 17:22:10 -0800185
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800186 protected void dumpBack(Printer pw, String prefix) {
Dianne Hackborn6ac42ae2015-12-08 17:22:10 -0800187 dumpBack(pw, prefix, DUMP_FLAG_ALL);
188 }
Yohei Yukawa8f272172017-08-31 00:26:01 -0700189
190 void dumpBack(Printer pw, String prefix, int dumpFlags) {
191 if ((dumpFlags & DUMP_FLAG_APPLICATION) != 0) {
Dianne Hackborn6ac42ae2015-12-08 17:22:10 -0800192 if (applicationInfo != null) {
193 pw.println(prefix + "ApplicationInfo:");
Yohei Yukawa8f272172017-08-31 00:26:01 -0700194 applicationInfo.dump(pw, prefix + " ", dumpFlags);
Dianne Hackborn6ac42ae2015-12-08 17:22:10 -0800195 } else {
196 pw.println(prefix + "ApplicationInfo: null");
197 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800198 }
199 super.dumpBack(pw, prefix);
200 }
Dianne Hackborn6ac42ae2015-12-08 17:22:10 -0800201
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800202 public void writeToParcel(Parcel dest, int parcelableFlags) {
203 super.writeToParcel(dest, parcelableFlags);
Christopher Tateb9116762015-09-09 18:46:31 -0700204 if ((parcelableFlags & Parcelable.PARCELABLE_ELIDE_DUPLICATES) != 0) {
205 dest.writeInt(0);
206 } else {
207 dest.writeInt(1);
208 applicationInfo.writeToParcel(dest, parcelableFlags);
209 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800210 dest.writeString(processName);
Adam Lesinski4e862812016-11-21 16:02:24 -0800211 dest.writeString(splitName);
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800212 dest.writeInt(descriptionRes);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800213 dest.writeInt(enabled ? 1 : 0);
214 dest.writeInt(exported ? 1 : 0);
Jeff Sharkey8a372a02016-03-16 16:25:45 -0600215 dest.writeInt(directBootAware ? 1 : 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800216 }
Jeff Brown07330792010-03-30 19:57:08 -0700217
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800218 protected ComponentInfo(Parcel source) {
219 super(source);
Christopher Tateb9116762015-09-09 18:46:31 -0700220 final boolean hasApplicationInfo = (source.readInt() != 0);
221 if (hasApplicationInfo) {
222 applicationInfo = ApplicationInfo.CREATOR.createFromParcel(source);
223 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800224 processName = source.readString();
Adam Lesinski4e862812016-11-21 16:02:24 -0800225 splitName = source.readString();
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800226 descriptionRes = source.readInt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800227 enabled = (source.readInt() != 0);
228 exported = (source.readInt() != 0);
Jeff Sharkey8a372a02016-03-16 16:25:45 -0600229 encryptionAware = directBootAware = (source.readInt() != 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800230 }
Jeff Sharkey8a372a02016-03-16 16:25:45 -0600231
Jeff Brown07330792010-03-30 19:57:08 -0700232 /**
233 * @hide
234 */
Alexandra Gherghinaa7093142014-07-30 13:43:39 +0100235 @Override
236 public Drawable loadDefaultIcon(PackageManager pm) {
Jeff Brown07330792010-03-30 19:57:08 -0700237 return applicationInfo.loadIcon(pm);
238 }
239
240 /**
241 * @hide
242 */
Jose Limaf78e3122014-03-06 12:13:15 -0800243 @Override protected Drawable loadDefaultBanner(PackageManager pm) {
244 return applicationInfo.loadBanner(pm);
245 }
246
247 /**
248 * @hide
249 */
Adam Powell81cd2e92010-04-21 16:35:18 -0700250 @Override
251 protected Drawable loadDefaultLogo(PackageManager pm) {
252 return applicationInfo.loadLogo(pm);
253 }
254
255 /**
256 * @hide
257 */
Jeff Brown07330792010-03-30 19:57:08 -0700258 @Override protected ApplicationInfo getApplicationInfo() {
259 return applicationInfo;
260 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800261}