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 | |
| 19 | import android.graphics.drawable.Drawable; |
| 20 | import android.os.Parcel; |
| 21 | import android.util.Printer; |
| 22 | |
| 23 | /** |
| 24 | * Base class containing information common to all application components |
| 25 | * ({@link ActivityInfo}, {@link ServiceInfo}). This class is not intended |
| 26 | * to be used by itself; it is simply here to share common definitions |
| 27 | * between all application components. As such, it does not itself |
| 28 | * implement Parcelable, but does provide convenience methods to assist |
| 29 | * in the implementation of Parcelable in subclasses. |
| 30 | */ |
| 31 | public class ComponentInfo extends PackageItemInfo { |
| 32 | /** |
| 33 | * Global information about the application/package this component is a |
| 34 | * part of. |
| 35 | */ |
| 36 | public ApplicationInfo applicationInfo; |
| 37 | |
| 38 | /** |
| 39 | * The name of the process this component should run in. |
| 40 | * From the "android:process" attribute or, if not set, the same |
| 41 | * as <var>applicationInfo.processName</var>. |
| 42 | */ |
| 43 | public String processName; |
| 44 | |
| 45 | /** |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 46 | * A string resource identifier (in the package's resources) containing |
| 47 | * a user-readable description of the component. From the "description" |
| 48 | * attribute or, if not set, 0. |
| 49 | */ |
| 50 | public int descriptionRes; |
| 51 | |
| 52 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 53 | * Indicates whether or not this component may be instantiated. Note that this value can be |
| 54 | * overriden by the one in its parent {@link ApplicationInfo}. |
| 55 | */ |
| 56 | public boolean enabled = true; |
| 57 | |
| 58 | /** |
| 59 | * Set to true if this component is available for use by other applications. |
| 60 | * Comes from {@link android.R.attr#exported android:exported} of the |
| 61 | * <activity>, <receiver>, <service>, or |
| 62 | * <provider> tag. |
| 63 | */ |
| 64 | public boolean exported = false; |
| 65 | |
| 66 | public ComponentInfo() { |
| 67 | } |
| 68 | |
| 69 | public ComponentInfo(ComponentInfo orig) { |
| 70 | super(orig); |
| 71 | applicationInfo = orig.applicationInfo; |
| 72 | processName = orig.processName; |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 73 | descriptionRes = orig.descriptionRes; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 74 | enabled = orig.enabled; |
| 75 | exported = orig.exported; |
| 76 | } |
| 77 | |
| 78 | @Override public CharSequence loadLabel(PackageManager pm) { |
| 79 | if (nonLocalizedLabel != null) { |
| 80 | return nonLocalizedLabel; |
| 81 | } |
| 82 | ApplicationInfo ai = applicationInfo; |
| 83 | CharSequence label; |
| 84 | if (labelRes != 0) { |
| 85 | label = pm.getText(packageName, labelRes, ai); |
| 86 | if (label != null) { |
| 87 | return label; |
| 88 | } |
| 89 | } |
| 90 | if (ai.nonLocalizedLabel != null) { |
| 91 | return ai.nonLocalizedLabel; |
| 92 | } |
| 93 | if (ai.labelRes != 0) { |
| 94 | label = pm.getText(packageName, ai.labelRes, ai); |
| 95 | if (label != null) { |
| 96 | return label; |
| 97 | } |
| 98 | } |
| 99 | return name; |
| 100 | } |
Joe Onorato | a85a915 | 2011-01-07 20:48:00 -0800 | [diff] [blame] | 101 | |
| 102 | /** |
| 103 | * Return whether this component and its enclosing application are enabled. |
| 104 | */ |
| 105 | public boolean isEnabled() { |
| 106 | return enabled && applicationInfo.enabled; |
| 107 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 108 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 109 | /** |
| 110 | * Return the icon resource identifier to use for this component. If |
| 111 | * the component defines an icon, that is used; else, the application |
| 112 | * icon is used. |
| 113 | * |
| 114 | * @return The icon associated with this component. |
| 115 | */ |
| 116 | public final int getIconResource() { |
| 117 | return icon != 0 ? icon : applicationInfo.icon; |
| 118 | } |
Adam Powell | 04fe6eb | 2013-05-31 14:39:48 -0700 | [diff] [blame] | 119 | |
| 120 | /** |
| 121 | * Return the logo resource identifier to use for this component. If |
| 122 | * the component defines a logo, that is used; else, the application |
| 123 | * logo is used. |
| 124 | * |
| 125 | * @return The logo associated with this component. |
| 126 | */ |
| 127 | public final int getLogoResource() { |
| 128 | return logo != 0 ? logo : applicationInfo.logo; |
| 129 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 130 | |
| 131 | protected void dumpFront(Printer pw, String prefix) { |
| 132 | super.dumpFront(pw, prefix); |
| 133 | pw.println(prefix + "enabled=" + enabled + " exported=" + exported |
| 134 | + " processName=" + processName); |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 135 | if (descriptionRes != 0) { |
| 136 | pw.println(prefix + "description=" + descriptionRes); |
| 137 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 138 | } |
| 139 | |
| 140 | protected void dumpBack(Printer pw, String prefix) { |
| 141 | if (applicationInfo != null) { |
| 142 | pw.println(prefix + "ApplicationInfo:"); |
| 143 | applicationInfo.dump(pw, prefix + " "); |
| 144 | } else { |
| 145 | pw.println(prefix + "ApplicationInfo: null"); |
| 146 | } |
| 147 | super.dumpBack(pw, prefix); |
| 148 | } |
| 149 | |
| 150 | public void writeToParcel(Parcel dest, int parcelableFlags) { |
| 151 | super.writeToParcel(dest, parcelableFlags); |
| 152 | applicationInfo.writeToParcel(dest, parcelableFlags); |
| 153 | dest.writeString(processName); |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 154 | dest.writeInt(descriptionRes); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 155 | dest.writeInt(enabled ? 1 : 0); |
| 156 | dest.writeInt(exported ? 1 : 0); |
| 157 | } |
Jeff Brown | 0733079 | 2010-03-30 19:57:08 -0700 | [diff] [blame] | 158 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 159 | protected ComponentInfo(Parcel source) { |
| 160 | super(source); |
| 161 | applicationInfo = ApplicationInfo.CREATOR.createFromParcel(source); |
| 162 | processName = source.readString(); |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 163 | descriptionRes = source.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 164 | enabled = (source.readInt() != 0); |
| 165 | exported = (source.readInt() != 0); |
| 166 | } |
Jeff Brown | 0733079 | 2010-03-30 19:57:08 -0700 | [diff] [blame] | 167 | |
| 168 | /** |
| 169 | * @hide |
| 170 | */ |
| 171 | @Override protected Drawable loadDefaultIcon(PackageManager pm) { |
| 172 | return applicationInfo.loadIcon(pm); |
| 173 | } |
| 174 | |
| 175 | /** |
| 176 | * @hide |
| 177 | */ |
Adam Powell | 81cd2e9 | 2010-04-21 16:35:18 -0700 | [diff] [blame] | 178 | @Override |
| 179 | protected Drawable loadDefaultLogo(PackageManager pm) { |
| 180 | return applicationInfo.loadLogo(pm); |
| 181 | } |
| 182 | |
| 183 | /** |
| 184 | * @hide |
| 185 | */ |
Jeff Brown | 0733079 | 2010-03-30 19:57:08 -0700 | [diff] [blame] | 186 | @Override protected ApplicationInfo getApplicationInfo() { |
| 187 | return applicationInfo; |
| 188 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 189 | } |