Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 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 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17 | package android.content.pm; |
| 18 | |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 19 | import android.annotation.UnsupportedAppUsage; |
Jeff Sharkey | 5217cac | 2015-12-20 15:34:01 -0700 | [diff] [blame] | 20 | import android.content.ComponentName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 21 | import android.graphics.drawable.Drawable; |
| 22 | import android.os.Parcel; |
Christopher Tate | b911676 | 2015-09-09 18:46:31 -0700 | [diff] [blame] | 23 | import android.os.Parcelable; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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 | /** |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 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 | /** |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 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 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 62 | * Indicates whether or not this component may be instantiated. Note that this value can be |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 63 | * overridden by the one in its parent {@link ApplicationInfo}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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 | * <activity>, <receiver>, <service>, or |
| 71 | * <provider> tag. |
| 72 | */ |
| 73 | public boolean exported = false; |
Jeff Sharkey | e17ac15 | 2015-11-06 22:40:29 -0800 | [diff] [blame] | 74 | |
| 75 | /** |
Jeff Sharkey | 8a372a0 | 2016-03-16 16:25:45 -0600 | [diff] [blame] | 76 | * Indicates if this component is aware of direct boot lifecycle, and can be |
Jeff Sharkey | e17ac15 | 2015-11-06 22:40:29 -0800 | [diff] [blame] | 77 | * safely run before the user has entered their credentials (such as a lock |
| 78 | * pattern or PIN). |
| 79 | */ |
Jeff Sharkey | 8a372a0 | 2016-03-16 16:25:45 -0600 | [diff] [blame] | 80 | public boolean directBootAware = false; |
| 81 | |
| 82 | /** @removed */ |
| 83 | @Deprecated |
Jeff Sharkey | e17ac15 | 2015-11-06 22:40:29 -0800 | [diff] [blame] | 84 | public boolean encryptionAware = false; |
| 85 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 86 | public ComponentInfo() { |
| 87 | } |
| 88 | |
| 89 | public ComponentInfo(ComponentInfo orig) { |
| 90 | super(orig); |
| 91 | applicationInfo = orig.applicationInfo; |
| 92 | processName = orig.processName; |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 93 | splitName = orig.splitName; |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 94 | descriptionRes = orig.descriptionRes; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 95 | enabled = orig.enabled; |
| 96 | exported = orig.exported; |
Jeff Sharkey | 8a372a0 | 2016-03-16 16:25:45 -0600 | [diff] [blame] | 97 | encryptionAware = directBootAware = orig.directBootAware; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 98 | } |
| 99 | |
Todd Kennedy | 6e40395 | 2018-05-03 10:05:04 +0100 | [diff] [blame] | 100 | /** @hide */ |
| 101 | @Override public CharSequence loadUnsafeLabel(PackageManager pm) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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 | } |
Joe Onorato | a85a915 | 2011-01-07 20:48:00 -0800 | [diff] [blame] | 124 | |
| 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 Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 131 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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 | */ |
| 139 | public final int getIconResource() { |
| 140 | return icon != 0 ? icon : applicationInfo.icon; |
| 141 | } |
Adam Powell | 04fe6eb | 2013-05-31 14:39:48 -0700 | [diff] [blame] | 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 | */ |
| 150 | public final int getLogoResource() { |
| 151 | return logo != 0 ? logo : applicationInfo.logo; |
| 152 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 153 | |
Jose Lima | f78e312 | 2014-03-06 12:13:15 -0800 | [diff] [blame] | 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 | */ |
| 161 | public final int getBannerResource() { |
| 162 | return banner != 0 ? banner : applicationInfo.banner; |
| 163 | } |
| 164 | |
Jeff Sharkey | 5217cac | 2015-12-20 15:34:01 -0700 | [diff] [blame] | 165 | /** {@hide} */ |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 166 | @UnsupportedAppUsage |
Jeff Sharkey | 5217cac | 2015-12-20 15:34:01 -0700 | [diff] [blame] | 167 | public ComponentName getComponentName() { |
| 168 | return new ComponentName(packageName, name); |
| 169 | } |
| 170 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 171 | protected void dumpFront(Printer pw, String prefix) { |
| 172 | super.dumpFront(pw, prefix); |
Dianne Hackborn | 6ac42ae | 2015-12-08 17:22:10 -0800 | [diff] [blame] | 173 | if (processName != null && !packageName.equals(processName)) { |
| 174 | pw.println(prefix + "processName=" + processName); |
| 175 | } |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 176 | if (splitName != null) { |
| 177 | pw.println(prefix + "splitName=" + splitName); |
| 178 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 179 | pw.println(prefix + "enabled=" + enabled + " exported=" + exported |
Jeff Sharkey | 8a372a0 | 2016-03-16 16:25:45 -0600 | [diff] [blame] | 180 | + " directBootAware=" + directBootAware); |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 181 | if (descriptionRes != 0) { |
| 182 | pw.println(prefix + "description=" + descriptionRes); |
| 183 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 184 | } |
Dianne Hackborn | 6ac42ae | 2015-12-08 17:22:10 -0800 | [diff] [blame] | 185 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 186 | protected void dumpBack(Printer pw, String prefix) { |
Dianne Hackborn | 6ac42ae | 2015-12-08 17:22:10 -0800 | [diff] [blame] | 187 | dumpBack(pw, prefix, DUMP_FLAG_ALL); |
| 188 | } |
Yohei Yukawa | 8f27217 | 2017-08-31 00:26:01 -0700 | [diff] [blame] | 189 | |
| 190 | void dumpBack(Printer pw, String prefix, int dumpFlags) { |
| 191 | if ((dumpFlags & DUMP_FLAG_APPLICATION) != 0) { |
Dianne Hackborn | 6ac42ae | 2015-12-08 17:22:10 -0800 | [diff] [blame] | 192 | if (applicationInfo != null) { |
| 193 | pw.println(prefix + "ApplicationInfo:"); |
Yohei Yukawa | 8f27217 | 2017-08-31 00:26:01 -0700 | [diff] [blame] | 194 | applicationInfo.dump(pw, prefix + " ", dumpFlags); |
Dianne Hackborn | 6ac42ae | 2015-12-08 17:22:10 -0800 | [diff] [blame] | 195 | } else { |
| 196 | pw.println(prefix + "ApplicationInfo: null"); |
| 197 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 198 | } |
| 199 | super.dumpBack(pw, prefix); |
| 200 | } |
Dianne Hackborn | 6ac42ae | 2015-12-08 17:22:10 -0800 | [diff] [blame] | 201 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 202 | public void writeToParcel(Parcel dest, int parcelableFlags) { |
| 203 | super.writeToParcel(dest, parcelableFlags); |
Christopher Tate | b911676 | 2015-09-09 18:46:31 -0700 | [diff] [blame] | 204 | 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 Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 210 | dest.writeString(processName); |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 211 | dest.writeString(splitName); |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 212 | dest.writeInt(descriptionRes); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 213 | dest.writeInt(enabled ? 1 : 0); |
| 214 | dest.writeInt(exported ? 1 : 0); |
Jeff Sharkey | 8a372a0 | 2016-03-16 16:25:45 -0600 | [diff] [blame] | 215 | dest.writeInt(directBootAware ? 1 : 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 216 | } |
Jeff Brown | 0733079 | 2010-03-30 19:57:08 -0700 | [diff] [blame] | 217 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 218 | protected ComponentInfo(Parcel source) { |
| 219 | super(source); |
Christopher Tate | b911676 | 2015-09-09 18:46:31 -0700 | [diff] [blame] | 220 | final boolean hasApplicationInfo = (source.readInt() != 0); |
| 221 | if (hasApplicationInfo) { |
| 222 | applicationInfo = ApplicationInfo.CREATOR.createFromParcel(source); |
| 223 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 224 | processName = source.readString(); |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 225 | splitName = source.readString(); |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 226 | descriptionRes = source.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 227 | enabled = (source.readInt() != 0); |
| 228 | exported = (source.readInt() != 0); |
Jeff Sharkey | 8a372a0 | 2016-03-16 16:25:45 -0600 | [diff] [blame] | 229 | encryptionAware = directBootAware = (source.readInt() != 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 230 | } |
Jeff Sharkey | 8a372a0 | 2016-03-16 16:25:45 -0600 | [diff] [blame] | 231 | |
Jeff Brown | 0733079 | 2010-03-30 19:57:08 -0700 | [diff] [blame] | 232 | /** |
| 233 | * @hide |
| 234 | */ |
Alexandra Gherghina | a709314 | 2014-07-30 13:43:39 +0100 | [diff] [blame] | 235 | @Override |
| 236 | public Drawable loadDefaultIcon(PackageManager pm) { |
Jeff Brown | 0733079 | 2010-03-30 19:57:08 -0700 | [diff] [blame] | 237 | return applicationInfo.loadIcon(pm); |
| 238 | } |
| 239 | |
| 240 | /** |
| 241 | * @hide |
| 242 | */ |
Jose Lima | f78e312 | 2014-03-06 12:13:15 -0800 | [diff] [blame] | 243 | @Override protected Drawable loadDefaultBanner(PackageManager pm) { |
| 244 | return applicationInfo.loadBanner(pm); |
| 245 | } |
| 246 | |
| 247 | /** |
| 248 | * @hide |
| 249 | */ |
Adam Powell | 81cd2e9 | 2010-04-21 16:35:18 -0700 | [diff] [blame] | 250 | @Override |
| 251 | protected Drawable loadDefaultLogo(PackageManager pm) { |
| 252 | return applicationInfo.loadLogo(pm); |
| 253 | } |
| 254 | |
| 255 | /** |
| 256 | * @hide |
| 257 | */ |
Jeff Brown | 0733079 | 2010-03-30 19:57:08 -0700 | [diff] [blame] | 258 | @Override protected ApplicationInfo getApplicationInfo() { |
| 259 | return applicationInfo; |
| 260 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 261 | } |