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 | |
Artur Satayev | e23a0eb | 2019-12-10 17:47:52 +0000 | [diff] [blame] | 19 | import android.compat.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; |
| 23 | import 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 | */ |
| 33 | public 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 Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 48 | * 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 Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 54 | * 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 Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 61 | * 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] | 62 | * overridden by the one in its parent {@link ApplicationInfo}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 63 | */ |
| 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 | * <activity>, <receiver>, <service>, or |
| 70 | * <provider> tag. |
| 71 | */ |
| 72 | public boolean exported = false; |
Jeff Sharkey | e17ac15 | 2015-11-06 22:40:29 -0800 | [diff] [blame] | 73 | |
| 74 | /** |
Jeff Sharkey | 8a372a0 | 2016-03-16 16:25:45 -0600 | [diff] [blame] | 75 | * 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] | 76 | * safely run before the user has entered their credentials (such as a lock |
| 77 | * pattern or PIN). |
| 78 | */ |
Jeff Sharkey | 8a372a0 | 2016-03-16 16:25:45 -0600 | [diff] [blame] | 79 | public boolean directBootAware = false; |
| 80 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 81 | public ComponentInfo() { |
| 82 | } |
| 83 | |
| 84 | public ComponentInfo(ComponentInfo orig) { |
| 85 | super(orig); |
| 86 | applicationInfo = orig.applicationInfo; |
| 87 | processName = orig.processName; |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 88 | splitName = orig.splitName; |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 89 | descriptionRes = orig.descriptionRes; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 90 | enabled = orig.enabled; |
| 91 | exported = orig.exported; |
Kweku Adams | 091fa30 | 2019-06-17 15:59:01 -0700 | [diff] [blame] | 92 | directBootAware = orig.directBootAware; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 93 | } |
| 94 | |
Todd Kennedy | 6e40395 | 2018-05-03 10:05:04 +0100 | [diff] [blame] | 95 | /** @hide */ |
| 96 | @Override public CharSequence loadUnsafeLabel(PackageManager pm) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 97 | 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 Onorato | a85a915 | 2011-01-07 20:48:00 -0800 | [diff] [blame] | 119 | |
| 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 Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 126 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 127 | /** |
| 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 Powell | 04fe6eb | 2013-05-31 14:39:48 -0700 | [diff] [blame] | 137 | |
| 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 Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 148 | |
Jose Lima | f78e312 | 2014-03-06 12:13:15 -0800 | [diff] [blame] | 149 | /** |
| 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 Sharkey | 5217cac | 2015-12-20 15:34:01 -0700 | [diff] [blame] | 160 | /** {@hide} */ |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 161 | @UnsupportedAppUsage |
Jeff Sharkey | 5217cac | 2015-12-20 15:34:01 -0700 | [diff] [blame] | 162 | public ComponentName getComponentName() { |
| 163 | return new ComponentName(packageName, name); |
| 164 | } |
| 165 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 166 | protected void dumpFront(Printer pw, String prefix) { |
| 167 | super.dumpFront(pw, prefix); |
Dianne Hackborn | 6ac42ae | 2015-12-08 17:22:10 -0800 | [diff] [blame] | 168 | if (processName != null && !packageName.equals(processName)) { |
| 169 | pw.println(prefix + "processName=" + processName); |
| 170 | } |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 171 | if (splitName != null) { |
| 172 | pw.println(prefix + "splitName=" + splitName); |
| 173 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 174 | pw.println(prefix + "enabled=" + enabled + " exported=" + exported |
Jeff Sharkey | 8a372a0 | 2016-03-16 16:25:45 -0600 | [diff] [blame] | 175 | + " directBootAware=" + directBootAware); |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 176 | if (descriptionRes != 0) { |
| 177 | pw.println(prefix + "description=" + descriptionRes); |
| 178 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 179 | } |
Dianne Hackborn | 6ac42ae | 2015-12-08 17:22:10 -0800 | [diff] [blame] | 180 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 181 | protected void dumpBack(Printer pw, String prefix) { |
Dianne Hackborn | 6ac42ae | 2015-12-08 17:22:10 -0800 | [diff] [blame] | 182 | dumpBack(pw, prefix, DUMP_FLAG_ALL); |
| 183 | } |
Yohei Yukawa | 8f27217 | 2017-08-31 00:26:01 -0700 | [diff] [blame] | 184 | |
| 185 | void dumpBack(Printer pw, String prefix, int dumpFlags) { |
| 186 | if ((dumpFlags & DUMP_FLAG_APPLICATION) != 0) { |
Dianne Hackborn | 6ac42ae | 2015-12-08 17:22:10 -0800 | [diff] [blame] | 187 | if (applicationInfo != null) { |
| 188 | pw.println(prefix + "ApplicationInfo:"); |
Yohei Yukawa | 8f27217 | 2017-08-31 00:26:01 -0700 | [diff] [blame] | 189 | applicationInfo.dump(pw, prefix + " ", dumpFlags); |
Dianne Hackborn | 6ac42ae | 2015-12-08 17:22:10 -0800 | [diff] [blame] | 190 | } else { |
| 191 | pw.println(prefix + "ApplicationInfo: null"); |
| 192 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 193 | } |
| 194 | super.dumpBack(pw, prefix); |
| 195 | } |
Dianne Hackborn | 6ac42ae | 2015-12-08 17:22:10 -0800 | [diff] [blame] | 196 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 197 | public void writeToParcel(Parcel dest, int parcelableFlags) { |
| 198 | super.writeToParcel(dest, parcelableFlags); |
Makoto Onuki | 2d80ca0 | 2020-02-12 14:20:36 -0800 | [diff] [blame] | 199 | applicationInfo.writeToParcel(dest, parcelableFlags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 200 | dest.writeString(processName); |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 201 | dest.writeString(splitName); |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 202 | dest.writeInt(descriptionRes); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 203 | dest.writeInt(enabled ? 1 : 0); |
| 204 | dest.writeInt(exported ? 1 : 0); |
Jeff Sharkey | 8a372a0 | 2016-03-16 16:25:45 -0600 | [diff] [blame] | 205 | dest.writeInt(directBootAware ? 1 : 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 206 | } |
Jeff Brown | 0733079 | 2010-03-30 19:57:08 -0700 | [diff] [blame] | 207 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 208 | protected ComponentInfo(Parcel source) { |
| 209 | super(source); |
Makoto Onuki | 2d80ca0 | 2020-02-12 14:20:36 -0800 | [diff] [blame] | 210 | applicationInfo = ApplicationInfo.CREATOR.createFromParcel(source); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 211 | processName = source.readString(); |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 212 | splitName = source.readString(); |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 213 | descriptionRes = source.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 214 | enabled = (source.readInt() != 0); |
| 215 | exported = (source.readInt() != 0); |
Kweku Adams | 091fa30 | 2019-06-17 15:59:01 -0700 | [diff] [blame] | 216 | directBootAware = (source.readInt() != 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 217 | } |
Jeff Sharkey | 8a372a0 | 2016-03-16 16:25:45 -0600 | [diff] [blame] | 218 | |
Jeff Brown | 0733079 | 2010-03-30 19:57:08 -0700 | [diff] [blame] | 219 | /** |
| 220 | * @hide |
| 221 | */ |
Alexandra Gherghina | a709314 | 2014-07-30 13:43:39 +0100 | [diff] [blame] | 222 | @Override |
| 223 | public Drawable loadDefaultIcon(PackageManager pm) { |
Jeff Brown | 0733079 | 2010-03-30 19:57:08 -0700 | [diff] [blame] | 224 | return applicationInfo.loadIcon(pm); |
| 225 | } |
| 226 | |
| 227 | /** |
| 228 | * @hide |
| 229 | */ |
Jose Lima | f78e312 | 2014-03-06 12:13:15 -0800 | [diff] [blame] | 230 | @Override protected Drawable loadDefaultBanner(PackageManager pm) { |
| 231 | return applicationInfo.loadBanner(pm); |
| 232 | } |
| 233 | |
| 234 | /** |
| 235 | * @hide |
| 236 | */ |
Adam Powell | 81cd2e9 | 2010-04-21 16:35:18 -0700 | [diff] [blame] | 237 | @Override |
| 238 | protected Drawable loadDefaultLogo(PackageManager pm) { |
| 239 | return applicationInfo.loadLogo(pm); |
| 240 | } |
| 241 | |
| 242 | /** |
| 243 | * @hide |
| 244 | */ |
Jeff Brown | 0733079 | 2010-03-30 19:57:08 -0700 | [diff] [blame] | 245 | @Override protected ApplicationInfo getApplicationInfo() { |
| 246 | return applicationInfo; |
| 247 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 248 | } |