ApplicationInfo.java revision 851a54143c15a1c33361efae2db3f7f45059b472
1package android.content.pm; 2 3import android.os.Parcel; 4import android.os.Parcelable; 5import android.util.Printer; 6 7import java.text.Collator; 8import 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 */ 15public 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 * Value for {@link #flags}: this is set if this application has been 118 * install as an update to a built-in system application. 119 */ 120 public static final int FLAG_UPDATED_SYSTEM_APP = 1<<7; 121 122 /** 123 * Value for {@link #flags}: this is set of the application has set 124 * its android:targetSdkVersion to something >= the current SDK version. 125 */ 126 public static final int FLAG_TARGETS_SDK = 1<<8; 127 128 /** 129 * Flags associated with the application. Any combination of 130 * {@link #FLAG_SYSTEM}, {@link #FLAG_DEBUGGABLE}, {@link #FLAG_HAS_CODE}, 131 * {@link #FLAG_PERSISTENT}, {@link #FLAG_FACTORY_TEST}, and 132 * {@link #FLAG_ALLOW_TASK_REPARENTING} 133 * {@link #FLAG_ALLOW_CLEAR_USER_DATA}, {@link #FLAG_UPDATED_SYSTEM_APP}, 134 * {@link #FLAG_TARGETS_SDK}. 135 */ 136 public int flags = 0; 137 138 /** 139 * Full path to the location of this package. 140 */ 141 public String sourceDir; 142 143 /** 144 * Full path to the location of the publicly available parts of this package (i.e. the resources 145 * and manifest). For non-forward-locked apps this will be the same as {@link #sourceDir). 146 */ 147 public String publicSourceDir; 148 149 /** 150 * Paths to all shared libraries this application is linked against. This 151 * field is only set if the {@link PackageManager#GET_SHARED_LIBRARY_FILES 152 * PackageManager.GET_SHARED_LIBRARY_FILES} flag was used when retrieving 153 * the structure. 154 */ 155 public String[] sharedLibraryFiles; 156 157 /** 158 * Full path to a directory assigned to the package for its persistent 159 * data. 160 */ 161 public String dataDir; 162 163 /** 164 * The kernel user-ID that has been assigned to this application; 165 * currently this is not a unique ID (multiple applications can have 166 * the same uid). 167 */ 168 public int uid; 169 170 171 /** 172 * The list of densities in DPI that application supprots. This 173 * field is only set if the {@link PackageManager#GET_SUPPORTS_DENSITIES} flag was 174 * used when retrieving the structure. 175 */ 176 public int[] supportsDensities; 177 178 /** 179 * When false, indicates that all components within this application are 180 * considered disabled, regardless of their individually set enabled status. 181 */ 182 public boolean enabled = true; 183 184 public void dump(Printer pw, String prefix) { 185 super.dumpFront(pw, prefix); 186 pw.println(prefix + "className=" + className); 187 pw.println(prefix + "permission=" + permission 188 + " uid=" + uid); 189 pw.println(prefix + "taskAffinity=" + taskAffinity); 190 pw.println(prefix + "theme=0x" + Integer.toHexString(theme)); 191 pw.println(prefix + "flags=0x" + Integer.toHexString(flags) 192 + " processName=" + processName); 193 pw.println(prefix + "sourceDir=" + sourceDir); 194 pw.println(prefix + "publicSourceDir=" + publicSourceDir); 195 pw.println(prefix + "sharedLibraryFiles=" + sharedLibraryFiles); 196 pw.println(prefix + "dataDir=" + dataDir); 197 pw.println(prefix + "enabled=" + enabled); 198 pw.println(prefix + "manageSpaceActivityName="+manageSpaceActivityName); 199 pw.println(prefix + "description=0x"+Integer.toHexString(descriptionRes)); 200 pw.println(prefix + "supportsDensities=" + supportsDensities); 201 super.dumpBack(pw, prefix); 202 } 203 204 public static class DisplayNameComparator 205 implements Comparator<ApplicationInfo> { 206 public DisplayNameComparator(PackageManager pm) { 207 mPM = pm; 208 } 209 210 public final int compare(ApplicationInfo aa, ApplicationInfo ab) { 211 CharSequence sa = mPM.getApplicationLabel(aa); 212 if (sa == null) { 213 sa = aa.packageName; 214 } 215 CharSequence sb = mPM.getApplicationLabel(ab); 216 if (sb == null) { 217 sb = ab.packageName; 218 } 219 220 return sCollator.compare(sa.toString(), sb.toString()); 221 } 222 223 private final Collator sCollator = Collator.getInstance(); 224 private PackageManager mPM; 225 } 226 227 public ApplicationInfo() { 228 } 229 230 public ApplicationInfo(ApplicationInfo orig) { 231 super(orig); 232 taskAffinity = orig.taskAffinity; 233 permission = orig.permission; 234 processName = orig.processName; 235 className = orig.className; 236 theme = orig.theme; 237 flags = orig.flags; 238 sourceDir = orig.sourceDir; 239 publicSourceDir = orig.publicSourceDir; 240 sharedLibraryFiles = orig.sharedLibraryFiles; 241 dataDir = orig.dataDir; 242 uid = orig.uid; 243 enabled = orig.enabled; 244 manageSpaceActivityName = orig.manageSpaceActivityName; 245 descriptionRes = orig.descriptionRes; 246 supportsDensities = orig.supportsDensities; 247 } 248 249 250 public String toString() { 251 return "ApplicationInfo{" 252 + Integer.toHexString(System.identityHashCode(this)) 253 + " " + packageName + "}"; 254 } 255 256 public int describeContents() { 257 return 0; 258 } 259 260 public void writeToParcel(Parcel dest, int parcelableFlags) { 261 super.writeToParcel(dest, parcelableFlags); 262 dest.writeString(taskAffinity); 263 dest.writeString(permission); 264 dest.writeString(processName); 265 dest.writeString(className); 266 dest.writeInt(theme); 267 dest.writeInt(flags); 268 dest.writeString(sourceDir); 269 dest.writeString(publicSourceDir); 270 dest.writeStringArray(sharedLibraryFiles); 271 dest.writeString(dataDir); 272 dest.writeInt(uid); 273 dest.writeInt(enabled ? 1 : 0); 274 dest.writeString(manageSpaceActivityName); 275 dest.writeInt(descriptionRes); 276 dest.writeIntArray(supportsDensities); 277 } 278 279 public static final Parcelable.Creator<ApplicationInfo> CREATOR 280 = new Parcelable.Creator<ApplicationInfo>() { 281 public ApplicationInfo createFromParcel(Parcel source) { 282 return new ApplicationInfo(source); 283 } 284 public ApplicationInfo[] newArray(int size) { 285 return new ApplicationInfo[size]; 286 } 287 }; 288 289 private ApplicationInfo(Parcel source) { 290 super(source); 291 taskAffinity = source.readString(); 292 permission = source.readString(); 293 processName = source.readString(); 294 className = source.readString(); 295 theme = source.readInt(); 296 flags = source.readInt(); 297 sourceDir = source.readString(); 298 publicSourceDir = source.readString(); 299 sharedLibraryFiles = source.readStringArray(); 300 dataDir = source.readString(); 301 uid = source.readInt(); 302 enabled = source.readInt() != 0; 303 manageSpaceActivityName = source.readString(); 304 descriptionRes = source.readInt(); 305 supportsDensities = source.createIntArray(); 306 } 307 308 /** 309 * Retrieve the textual description of the application. This 310 * will call back on the given PackageManager to load the description from 311 * the application. 312 * 313 * @param pm A PackageManager from which the label can be loaded; usually 314 * the PackageManager from which you originally retrieved this item. 315 * 316 * @return Returns a CharSequence containing the application's description. 317 * If there is no description, null is returned. 318 */ 319 public CharSequence loadDescription(PackageManager pm) { 320 if (descriptionRes != 0) { 321 CharSequence label = pm.getText(packageName, descriptionRes, null); 322 if (label != null) { 323 return label; 324 } 325 } 326 return null; 327 } 328} 329