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