• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.UnsupportedAppUsage;
20 import android.content.ComponentName;
21 import android.graphics.drawable.Drawable;
22 import android.os.Parcel;
23 import android.os.Parcelable;
24 import 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  */
34 public 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     /**
49      * 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     /**
55      * 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     /**
62      * Indicates whether or not this component may be instantiated.  Note that this value can be
63      * overridden by the one in its parent {@link ApplicationInfo}.
64      */
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;
74 
75     /**
76      * Indicates if this component is aware of direct boot lifecycle, and can be
77      * safely run before the user has entered their credentials (such as a lock
78      * pattern or PIN).
79      */
80     public boolean directBootAware = false;
81 
82     /** @removed */
83     @Deprecated
84     public boolean encryptionAware = false;
85 
ComponentInfo()86     public ComponentInfo() {
87     }
88 
ComponentInfo(ComponentInfo orig)89     public ComponentInfo(ComponentInfo orig) {
90         super(orig);
91         applicationInfo = orig.applicationInfo;
92         processName = orig.processName;
93         splitName = orig.splitName;
94         descriptionRes = orig.descriptionRes;
95         enabled = orig.enabled;
96         exported = orig.exported;
97         encryptionAware = directBootAware = orig.directBootAware;
98     }
99 
100     /** @hide */
loadUnsafeLabel(PackageManager pm)101     @Override public CharSequence loadUnsafeLabel(PackageManager pm) {
102         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     }
124 
125     /**
126      * Return whether this component and its enclosing application are enabled.
127      */
isEnabled()128     public boolean isEnabled() {
129         return enabled && applicationInfo.enabled;
130     }
131 
132     /**
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      */
getIconResource()139     public final int getIconResource() {
140         return icon != 0 ? icon : applicationInfo.icon;
141     }
142 
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      */
getLogoResource()150     public final int getLogoResource() {
151         return logo != 0 ? logo : applicationInfo.logo;
152     }
153 
154     /**
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      */
getBannerResource()161     public final int getBannerResource() {
162         return banner != 0 ? banner : applicationInfo.banner;
163     }
164 
165     /** {@hide} */
166     @UnsupportedAppUsage
getComponentName()167     public ComponentName getComponentName() {
168         return new ComponentName(packageName, name);
169     }
170 
dumpFront(Printer pw, String prefix)171     protected void dumpFront(Printer pw, String prefix) {
172         super.dumpFront(pw, prefix);
173         if (processName != null && !packageName.equals(processName)) {
174             pw.println(prefix + "processName=" + processName);
175         }
176         if (splitName != null) {
177             pw.println(prefix + "splitName=" + splitName);
178         }
179         pw.println(prefix + "enabled=" + enabled + " exported=" + exported
180                 + " directBootAware=" + directBootAware);
181         if (descriptionRes != 0) {
182             pw.println(prefix + "description=" + descriptionRes);
183         }
184     }
185 
dumpBack(Printer pw, String prefix)186     protected void dumpBack(Printer pw, String prefix) {
187         dumpBack(pw, prefix, DUMP_FLAG_ALL);
188     }
189 
dumpBack(Printer pw, String prefix, int dumpFlags)190     void dumpBack(Printer pw, String prefix, int dumpFlags) {
191         if ((dumpFlags & DUMP_FLAG_APPLICATION) != 0) {
192             if (applicationInfo != null) {
193                 pw.println(prefix + "ApplicationInfo:");
194                 applicationInfo.dump(pw, prefix + "  ", dumpFlags);
195             } else {
196                 pw.println(prefix + "ApplicationInfo: null");
197             }
198         }
199         super.dumpBack(pw, prefix);
200     }
201 
writeToParcel(Parcel dest, int parcelableFlags)202     public void writeToParcel(Parcel dest, int parcelableFlags) {
203         super.writeToParcel(dest, parcelableFlags);
204         if ((parcelableFlags & Parcelable.PARCELABLE_ELIDE_DUPLICATES) != 0) {
205             dest.writeInt(0);
206         } else {
207             dest.writeInt(1);
208             applicationInfo.writeToParcel(dest, parcelableFlags);
209         }
210         dest.writeString(processName);
211         dest.writeString(splitName);
212         dest.writeInt(descriptionRes);
213         dest.writeInt(enabled ? 1 : 0);
214         dest.writeInt(exported ? 1 : 0);
215         dest.writeInt(directBootAware ? 1 : 0);
216     }
217 
ComponentInfo(Parcel source)218     protected ComponentInfo(Parcel source) {
219         super(source);
220         final boolean hasApplicationInfo = (source.readInt() != 0);
221         if (hasApplicationInfo) {
222             applicationInfo = ApplicationInfo.CREATOR.createFromParcel(source);
223         }
224         processName = source.readString();
225         splitName = source.readString();
226         descriptionRes = source.readInt();
227         enabled = (source.readInt() != 0);
228         exported = (source.readInt() != 0);
229         encryptionAware = directBootAware = (source.readInt() != 0);
230     }
231 
232     /**
233      * @hide
234      */
235     @Override
loadDefaultIcon(PackageManager pm)236     public Drawable loadDefaultIcon(PackageManager pm) {
237         return applicationInfo.loadIcon(pm);
238     }
239 
240     /**
241      * @hide
242      */
loadDefaultBanner(PackageManager pm)243     @Override protected Drawable loadDefaultBanner(PackageManager pm) {
244         return applicationInfo.loadBanner(pm);
245     }
246 
247     /**
248      * @hide
249      */
250     @Override
loadDefaultLogo(PackageManager pm)251     protected Drawable loadDefaultLogo(PackageManager pm) {
252         return applicationInfo.loadLogo(pm);
253     }
254 
255     /**
256      * @hide
257      */
getApplicationInfo()258     @Override protected ApplicationInfo getApplicationInfo() {
259         return applicationInfo;
260     }
261 }
262