The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | package android.content.pm; |
| 2 | |
| 3 | import android.os.Parcel; |
| 4 | import android.os.Parcelable; |
| 5 | import android.util.Printer; |
| 6 | |
| 7 | import java.text.Collator; |
| 8 | import java.util.Comparator; |
| 9 | |
| 10 | /** |
| 11 | * Information you can retrieve about a particular application. This |
| 12 | * corresponds to information collected from the AndroidManifest.xml's |
| 13 | * <application> tag. |
| 14 | */ |
| 15 | public class ApplicationInfo extends PackageItemInfo implements Parcelable { |
| 16 | |
| 17 | /** |
| 18 | * Default task affinity of all activities in this application. See |
| 19 | * {@link ActivityInfo#taskAffinity} for more information. This comes |
| 20 | * from the "taskAffinity" attribute. |
| 21 | */ |
| 22 | public String taskAffinity; |
| 23 | |
| 24 | /** |
| 25 | * Optional name of a permission required to be able to access this |
| 26 | * application's components. From the "permission" attribute. |
| 27 | */ |
| 28 | public String permission; |
| 29 | |
| 30 | /** |
| 31 | * The name of the process this application should run in. From the |
| 32 | * "process" attribute or, if not set, the same as |
| 33 | * <var>packageName</var>. |
| 34 | */ |
| 35 | public String processName; |
| 36 | |
| 37 | /** |
| 38 | * Class implementing the Application object. From the "class" |
| 39 | * attribute. |
| 40 | */ |
| 41 | public String className; |
| 42 | |
| 43 | /** |
| 44 | * A style resource identifier (in the package's resources) of the |
| 45 | * description of an application. From the "description" attribute |
| 46 | * or, if not set, 0. |
| 47 | */ |
| 48 | public int descriptionRes; |
| 49 | |
| 50 | /** |
| 51 | * A style resource identifier (in the package's resources) of the |
| 52 | * default visual theme of the application. From the "theme" attribute |
| 53 | * or, if not set, 0. |
| 54 | */ |
| 55 | public int theme; |
| 56 | |
| 57 | /** |
| 58 | * Class implementing the Application's manage space |
| 59 | * functionality. From the "manageSpaceActivity" |
| 60 | * attribute. This is an optional attribute and will be null if |
| 61 | * application's dont specify it in their manifest |
| 62 | */ |
| 63 | public String manageSpaceActivityName; |
| 64 | |
| 65 | /** |
| 66 | * Value for {@link #flags}: if set, this application is installed in the |
| 67 | * device's system image. |
| 68 | */ |
| 69 | public static final int FLAG_SYSTEM = 1<<0; |
| 70 | |
| 71 | /** |
| 72 | * Value for {@link #flags}: set to true if this application would like to |
| 73 | * allow debugging of its |
| 74 | * code, even when installed on a non-development system. Comes |
| 75 | * from {@link android.R.styleable#AndroidManifestApplication_debuggable |
| 76 | * android:debuggable} of the <application> tag. |
| 77 | */ |
| 78 | public static final int FLAG_DEBUGGABLE = 1<<1; |
| 79 | |
| 80 | /** |
| 81 | * Value for {@link #flags}: set to true if this application has code |
| 82 | * associated with it. Comes |
| 83 | * from {@link android.R.styleable#AndroidManifestApplication_hasCode |
| 84 | * android:hasCode} of the <application> tag. |
| 85 | */ |
| 86 | public static final int FLAG_HAS_CODE = 1<<2; |
| 87 | |
| 88 | /** |
| 89 | * Value for {@link #flags}: set to true if this application is persistent. |
| 90 | * Comes from {@link android.R.styleable#AndroidManifestApplication_persistent |
| 91 | * android:persistent} of the <application> tag. |
| 92 | */ |
| 93 | public static final int FLAG_PERSISTENT = 1<<3; |
| 94 | |
| 95 | /** |
| 96 | * Value for {@link #flags}: set to true iif this application holds the |
| 97 | * {@link android.Manifest.permission#FACTORY_TEST} permission and the |
| 98 | * device is running in factory test mode. |
| 99 | */ |
| 100 | public static final int FLAG_FACTORY_TEST = 1<<4; |
| 101 | |
| 102 | /** |
| 103 | * Value for {@link #flags}: default value for the corresponding ActivityInfo flag. |
| 104 | * Comes from {@link android.R.styleable#AndroidManifestApplication_allowTaskReparenting |
| 105 | * android:allowTaskReparenting} of the <application> tag. |
| 106 | */ |
| 107 | public static final int FLAG_ALLOW_TASK_REPARENTING = 1<<5; |
| 108 | |
| 109 | /** |
| 110 | * Value for {@link #flags}: default value for the corresponding ActivityInfo flag. |
| 111 | * Comes from {@link android.R.styleable#AndroidManifestApplication_allowClearUserData |
| 112 | * android:allowClearUserData} of the <application> tag. |
| 113 | */ |
| 114 | public static final int FLAG_ALLOW_CLEAR_USER_DATA = 1<<6; |
| 115 | |
| 116 | |
| 117 | /** |
| 118 | * Value for {@link #flags}: default value for the corresponding ActivityInfo flag. |
| 119 | * {@hide} |
| 120 | */ |
| 121 | public static final int FLAG_UPDATED_SYSTEM_APP = 1<<7; |
| 122 | |
| 123 | /** |
| 124 | * Flags associated with the application. Any combination of |
| 125 | * {@link #FLAG_SYSTEM}, {@link #FLAG_DEBUGGABLE}, {@link #FLAG_HAS_CODE}, |
| 126 | * {@link #FLAG_PERSISTENT}, {@link #FLAG_FACTORY_TEST}, and |
| 127 | * {@link #FLAG_ALLOW_TASK_REPARENTING} |
| 128 | * {@link #FLAG_ALLOW_CLEAR_USER_DATA}. |
| 129 | */ |
| 130 | public int flags = 0; |
| 131 | |
| 132 | /** |
| 133 | * Full path to the location of this package. |
| 134 | */ |
| 135 | public String sourceDir; |
| 136 | |
| 137 | /** |
| 138 | * Full path to the location of the publicly available parts of this package (i.e. the resources |
| 139 | * and manifest). For non-forward-locked apps this will be the same as {@link #sourceDir). |
| 140 | */ |
| 141 | public String publicSourceDir; |
| 142 | |
| 143 | /** |
| 144 | * Paths to all shared libraries this application is linked against. This |
| 145 | * field is only set if the {@link PackageManager#GET_SHARED_LIBRARY_FILES |
| 146 | * PackageManager.GET_SHARED_LIBRARY_FILES} flag was used when retrieving |
| 147 | * the structure. |
| 148 | */ |
| 149 | public String[] sharedLibraryFiles; |
| 150 | |
| 151 | /** |
| 152 | * Full path to a directory assigned to the package for its persistent |
| 153 | * data. |
| 154 | */ |
| 155 | public String dataDir; |
| 156 | |
| 157 | /** |
| 158 | * The kernel user-ID that has been assigned to this application; |
| 159 | * currently this is not a unique ID (multiple applications can have |
| 160 | * the same uid). |
| 161 | */ |
| 162 | public int uid; |
| 163 | |
Mitsuru Oshima | 8d11267 | 2009-04-27 12:01:23 -0700 | [diff] [blame^] | 164 | |
| 165 | /** |
| 166 | * The list of densities in DPI that application supprots. This |
| 167 | * field is only set if the {@link PackageManager#GET_SUPPORTS_DENSITIES} flag was |
| 168 | * used when retrieving the structure. |
| 169 | */ |
| 170 | public int[] supportsDensities; |
| 171 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 172 | /** |
| 173 | * When false, indicates that all components within this application are |
| 174 | * considered disabled, regardless of their individually set enabled status. |
| 175 | */ |
| 176 | public boolean enabled = true; |
| 177 | |
| 178 | public void dump(Printer pw, String prefix) { |
| 179 | super.dumpFront(pw, prefix); |
| 180 | pw.println(prefix + "className=" + className); |
| 181 | pw.println(prefix + "permission=" + permission |
| 182 | + " uid=" + uid); |
| 183 | pw.println(prefix + "taskAffinity=" + taskAffinity); |
| 184 | pw.println(prefix + "theme=0x" + Integer.toHexString(theme)); |
| 185 | pw.println(prefix + "flags=0x" + Integer.toHexString(flags) |
| 186 | + " processName=" + processName); |
| 187 | pw.println(prefix + "sourceDir=" + sourceDir); |
| 188 | pw.println(prefix + "publicSourceDir=" + publicSourceDir); |
| 189 | pw.println(prefix + "sharedLibraryFiles=" + sharedLibraryFiles); |
| 190 | pw.println(prefix + "dataDir=" + dataDir); |
| 191 | pw.println(prefix + "enabled=" + enabled); |
Mitsuru Oshima | 8d11267 | 2009-04-27 12:01:23 -0700 | [diff] [blame^] | 192 | pw.println(prefix + "manageSpaceActivityName="+manageSpaceActivityName); |
| 193 | pw.println(prefix + "description=0x"+Integer.toHexString(descriptionRes)); |
| 194 | pw.println(prefix + "supportsDensities=" + supportsDensities); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 195 | super.dumpBack(pw, prefix); |
| 196 | } |
| 197 | |
| 198 | public static class DisplayNameComparator |
| 199 | implements Comparator<ApplicationInfo> { |
| 200 | public DisplayNameComparator(PackageManager pm) { |
| 201 | mPM = pm; |
| 202 | } |
| 203 | |
| 204 | public final int compare(ApplicationInfo aa, ApplicationInfo ab) { |
| 205 | CharSequence sa = mPM.getApplicationLabel(aa); |
| 206 | if (sa == null) { |
| 207 | sa = aa.packageName; |
| 208 | } |
| 209 | CharSequence sb = mPM.getApplicationLabel(ab); |
| 210 | if (sb == null) { |
| 211 | sb = ab.packageName; |
| 212 | } |
| 213 | |
| 214 | return sCollator.compare(sa.toString(), sb.toString()); |
| 215 | } |
| 216 | |
| 217 | private final Collator sCollator = Collator.getInstance(); |
| 218 | private PackageManager mPM; |
| 219 | } |
| 220 | |
| 221 | public ApplicationInfo() { |
| 222 | } |
| 223 | |
| 224 | public ApplicationInfo(ApplicationInfo orig) { |
| 225 | super(orig); |
| 226 | taskAffinity = orig.taskAffinity; |
| 227 | permission = orig.permission; |
| 228 | processName = orig.processName; |
| 229 | className = orig.className; |
| 230 | theme = orig.theme; |
| 231 | flags = orig.flags; |
| 232 | sourceDir = orig.sourceDir; |
| 233 | publicSourceDir = orig.publicSourceDir; |
| 234 | sharedLibraryFiles = orig.sharedLibraryFiles; |
| 235 | dataDir = orig.dataDir; |
| 236 | uid = orig.uid; |
| 237 | enabled = orig.enabled; |
| 238 | manageSpaceActivityName = orig.manageSpaceActivityName; |
| 239 | descriptionRes = orig.descriptionRes; |
Mitsuru Oshima | 8d11267 | 2009-04-27 12:01:23 -0700 | [diff] [blame^] | 240 | supportsDensities = orig.supportsDensities; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 241 | } |
| 242 | |
| 243 | |
| 244 | public String toString() { |
| 245 | return "ApplicationInfo{" |
| 246 | + Integer.toHexString(System.identityHashCode(this)) |
| 247 | + " " + packageName + "}"; |
| 248 | } |
| 249 | |
| 250 | public int describeContents() { |
| 251 | return 0; |
| 252 | } |
| 253 | |
| 254 | public void writeToParcel(Parcel dest, int parcelableFlags) { |
| 255 | super.writeToParcel(dest, parcelableFlags); |
| 256 | dest.writeString(taskAffinity); |
| 257 | dest.writeString(permission); |
| 258 | dest.writeString(processName); |
| 259 | dest.writeString(className); |
| 260 | dest.writeInt(theme); |
| 261 | dest.writeInt(flags); |
| 262 | dest.writeString(sourceDir); |
| 263 | dest.writeString(publicSourceDir); |
| 264 | dest.writeStringArray(sharedLibraryFiles); |
| 265 | dest.writeString(dataDir); |
| 266 | dest.writeInt(uid); |
| 267 | dest.writeInt(enabled ? 1 : 0); |
| 268 | dest.writeString(manageSpaceActivityName); |
| 269 | dest.writeInt(descriptionRes); |
Mitsuru Oshima | 8d11267 | 2009-04-27 12:01:23 -0700 | [diff] [blame^] | 270 | dest.writeIntArray(supportsDensities); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 271 | } |
| 272 | |
| 273 | public static final Parcelable.Creator<ApplicationInfo> CREATOR |
| 274 | = new Parcelable.Creator<ApplicationInfo>() { |
| 275 | public ApplicationInfo createFromParcel(Parcel source) { |
| 276 | return new ApplicationInfo(source); |
| 277 | } |
| 278 | public ApplicationInfo[] newArray(int size) { |
| 279 | return new ApplicationInfo[size]; |
| 280 | } |
| 281 | }; |
| 282 | |
| 283 | private ApplicationInfo(Parcel source) { |
| 284 | super(source); |
| 285 | taskAffinity = source.readString(); |
| 286 | permission = source.readString(); |
| 287 | processName = source.readString(); |
| 288 | className = source.readString(); |
| 289 | theme = source.readInt(); |
| 290 | flags = source.readInt(); |
| 291 | sourceDir = source.readString(); |
| 292 | publicSourceDir = source.readString(); |
| 293 | sharedLibraryFiles = source.readStringArray(); |
| 294 | dataDir = source.readString(); |
| 295 | uid = source.readInt(); |
| 296 | enabled = source.readInt() != 0; |
| 297 | manageSpaceActivityName = source.readString(); |
| 298 | descriptionRes = source.readInt(); |
Mitsuru Oshima | 8d11267 | 2009-04-27 12:01:23 -0700 | [diff] [blame^] | 299 | supportsDensities = source.createIntArray(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 300 | } |
Mitsuru Oshima | 8d11267 | 2009-04-27 12:01:23 -0700 | [diff] [blame^] | 301 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 302 | /** |
| 303 | * Retrieve the textual description of the application. This |
| 304 | * will call back on the given PackageManager to load the description from |
| 305 | * the application. |
| 306 | * |
| 307 | * @param pm A PackageManager from which the label can be loaded; usually |
| 308 | * the PackageManager from which you originally retrieved this item. |
| 309 | * |
| 310 | * @return Returns a CharSequence containing the application's description. |
| 311 | * If there is no description, null is returned. |
| 312 | */ |
| 313 | public CharSequence loadDescription(PackageManager pm) { |
| 314 | if (descriptionRes != 0) { |
| 315 | CharSequence label = pm.getText(packageName, descriptionRes, null); |
| 316 | if (label != null) { |
| 317 | return label; |
| 318 | } |
| 319 | } |
| 320 | return null; |
| 321 | } |
| 322 | } |