Android 的manifest解析

  1. gids = source.createIntArray();

  2. activities = source.createTypedArray(ActivityInfo.CREATOR);

  3. receivers = source.createTypedArray(ActivityInfo.CREATOR);

  4. services = source.createTypedArray(ServiceInfo.CREATOR);

  5. providers = source.createTypedArray(ProviderInfo.CREATOR);

  6. instrumentation = source.createTypedArray(InstrumentationInfo.CREATOR);

  7. permissions = source.createTypedArray(PermissionInfo.CREATOR);

  8. requestedPermissions = source.createStringArray();

  9. requestedPermissionsFlags = source.createIntArray();

  10. signatures = source.createTypedArray(Signature.CREATOR);

  11. configPreferences = source.createTypedArray(ConfigurationInfo.CREATOR);

  12. reqFeatures = source.createTypedArray(FeatureInfo.CREATOR);

  13. installLocation = source.readInt();

  14. }

  15. }

ApplicationInfo.java源码:

[java]  view plain copy 外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传 外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

  1. /*

  2. * Copyright © 2007 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. package android.content.pm;

  17. import android.content.pm.PackageManager.NameNotFoundException;

  18. import android.content.res.Resources;

  19. import android.graphics.drawable.Drawable;

  20. import android.os.Parcel;

  21. import android.os.Parcelable;

  22. import android.util.Printer;

  23. import java.text.Collator;

  24. import java.util.Comparator;

  25. /**

  26. * Information you can retrieve about a particular application.  This

  27. * corresponds to information collected from the AndroidManifest.xml’s

  28. *  tag.

  29. */

  30. public class ApplicationInfo extends PackageItemInfo implements Parcelable {

  31. /**

  32. * Default task affinity of all activities in this application. See

  33. * {@link ActivityInfo#taskAffinity} for more information.  This comes

  34. * from the “taskAffinity” attribute.

  35. */

  36. public String taskAffinity;

  37. /**

  38. * Optional name of a permission required to be able to access this

  39. * application’s components.  From the “permission” attribute.

  40. */

  41. public String permission;

  42. /**

  43. * The name of the process this application should run in.  From the

  44. * “process” attribute or, if not set, the same as

  45. packageName.

  46. */

  47. public String processName;

  48. /**

  49. * Class implementing the Application object.  From the “class”

  50. * attribute.

  51. */

  52. public String className;

  53. /**

  54. * A style resource identifier (in the package’s resources) of the

  55. * description of an application.  From the “description” attribute

  56. * or, if not set, 0.

  57. */

  58. public int descriptionRes;

  59. /**

  60. * A style resource identifier (in the package’s resources) of the

  61. * default visual theme of the application.  From the “theme” attribute

  62. * or, if not set, 0.

  63. */

  64. public int theme;

  65. /**

  66. * Class implementing the Application’s manage space

  67. * functionality.  From the “manageSpaceActivity”

  68. * attribute. This is an optional attribute and will be null if

  69. * applications don’t specify it in their manifest

  70. */

  71. public String manageSpaceActivityName;

  72. /**

  73. * Class implementing the Application’s backup functionality.  From

  74. * the “backupAgent” attribute.  This is an optional attribute and

  75. * will be null if the application does not specify it in its manifest.

  76. *

  77. If android:allowBackup is set to false, this attribute is ignored.

  78. */

  79. public String backupAgentName;

  80. /**

  81. * The default extra UI options for activities in this application.

  82. * Set from the {@link android.R.attr#uiOptions} attribute in the

  83. * activity’s manifest.

  84. */

  85. public int uiOptions = 0;

  86. /**

  87. * Value for {@link #flags}: if set, this application is installed in the

  88. * device’s system image.

  89. */

  90. public static final int FLAG_SYSTEM = 1<<0;

  91. /**

  92. * Value for {@link #flags}: set to true if this application would like to

  93. * allow debugging of its

  94. * code, even when installed on a non-development system.  Comes

  95. * from {@link android.R.styleable#AndroidManifestApplication_debuggable

  96. * android:debuggable} of the  tag.

  97. */

  98. public static final int FLAG_DEBUGGABLE = 1<<1;

  99. /**

  100. * Value for {@link #flags}: set to true if this application has code

  101. * associated with it.  Comes

  102. * from {@link android.R.styleable#AndroidManifestApplication_hasCode

  103. * android:hasCode} of the  tag.

  104. */

  105. public static final int FLAG_HAS_CODE = 1<<2;

  106. /**

  107. * Value for {@link #flags}: set to true if this application is persistent.

  108. * Comes from {@link android.R.styleable#AndroidManifestApplication_persistent

  109. * android:persistent} of the  tag.

  110. */

  111. public static final int FLAG_PERSISTENT = 1<<3;

  112. /**

  113. * Value for {@link #flags}: set to true if this application holds the

  114. * {@link android.Manifest.permission#FACTORY_TEST} permission and the

  115. * device is running in factory test mode.

  116. */

  117. public static final int FLAG_FACTORY_TEST = 1<<4;

  118. /**

  119. * Value for {@link #flags}: default value for the corresponding ActivityInfo flag.

  120. * Comes from {@link android.R.styleable#AndroidManifestApplication_allowTaskReparenting

  121. * android:allowTaskReparenting} of the  tag.

  122. */

  123. public static final int FLAG_ALLOW_TASK_REPARENTING = 1<<5;

  124. /**

  125. * Value for {@link #flags}: default value for the corresponding ActivityInfo flag.

  126. * Comes from {@link android.R.styleable#AndroidManifestApplication_allowClearUserData

  127. * android:allowClearUserData} of the  tag.

  128. */

  129. public static final int FLAG_ALLOW_CLEAR_USER_DATA = 1<<6;

  130. /**

  131. * Value for {@link #flags}: this is set if this application has been

  132. * install as an update to a built-in system application.

  133. */

  134. public static final int FLAG_UPDATED_SYSTEM_APP = 1<<7;

  135. /**

  136. * Value for {@link #flags}: this is set of the application has specified

  137. * {@link android.R.styleable#AndroidManifestApplication_testOnly

  138. * android:testOnly} to be true.

  139. */

  140. public static final int FLAG_TEST_ONLY = 1<<8;

  141. /**

  142. * Value for {@link #flags}: true when the application’s window can be

  143. * reduced in size for smaller screens.  Corresponds to

  144. * {@link android.R.styleable#AndroidManifestSupportsScreens_smallScreens

  145. * android:smallScreens}.

  146. */

  147. public static final int FLAG_SUPPORTS_SMALL_SCREENS = 1<<9;

  148. /**

  149. * Value for {@link #flags}: true when the application’s window can be

  150. * displayed on normal screens.  Corresponds to

  151. * {@link android.R.styleable#AndroidManifestSupportsScreens_normalScreens

  152. * android:normalScreens}.

  153. */

  154. public static final int FLAG_SUPPORTS_NORMAL_SCREENS = 1<<10;

  155. /**

  156. * Value for {@link #flags}: true when the application’s window can be

  157. * increased in size for larger screens.  Corresponds to

  158. * {@link android.R.styleable#AndroidManifestSupportsScreens_largeScreens

  159. * android:largeScreens}.

  160. */

  161. public static final int FLAG_SUPPORTS_LARGE_SCREENS = 1<<11;

  162. /**

  163. * Value for {@link #flags}: true when the application knows how to adjust

  164. * its UI for different screen sizes.  Corresponds to

  165. * {@link android.R.styleable#AndroidManifestSupportsScreens_resizeable

  166. * android:resizeable}.

  167. */

  168. public static final int FLAG_RESIZEABLE_FOR_SCREENS = 1<<12;

  169. /**

  170. * Value for {@link #flags}: true when the application knows how to

  171. * accomodate different screen densities.  Corresponds to

  172. * {@link android.R.styleable#AndroidManifestSupportsScreens_anyDensity

  173. * android:anyDensity}.

  174. */

  175. public static final int FLAG_SUPPORTS_SCREEN_DENSITIES = 1<<13;

  176. /**

  177. * Value for {@link #flags}: set to true if this application would like to

  178. * request the VM to operate under the safe mode. Comes from

  179. * {@link android.R.styleable#AndroidManifestApplication_vmSafeMode

  180. * android:vmSafeMode} of the  tag.

  181. */

  182. public static final int FLAG_VM_SAFE_MODE = 1<<14;

  183. /**

  184. * Value for {@link #flags}: set to false if the application does not wish

  185. * to permit any OS-driven backups of its data; true otherwise.

  186. *

  187. Comes from the

  188. * {@link android.R.styleable#AndroidManifestApplication_allowBackup android:allowBackup}

  189. * attribute of the  tag.

  190. */

  191. public static final int FLAG_ALLOW_BACKUP = 1<<15;

  192. /**

  193. * Value for {@link #flags}: set to false if the application must be kept

  194. * in memory following a full-system restore operation; true otherwise.

  195. * Ordinarily, during a full system restore operation each application is shut down

  196. * following execution of its agent’s onRestore() method.  Setting this attribute to

  197. false prevents this.  Most applications will not need to set this attribute.

  198. *

  199. If

  200. * {@link android.R.styleable#AndroidManifestApplication_allowBackup android:allowBackup}

  201. * is set to false or no

  202. * {@link android.R.styleable#AndroidManifestApplication_backupAgent android:backupAgent}

  203. * is specified, this flag will be ignored.

  204. *

  205. Comes from the

  206. * {@link android.R.styleable#AndroidManifestApplication_killAfterRestore android:killAfterRestore}

  207. * attribute of the  tag.

  208. */

  209. public static final int FLAG_KILL_AFTER_RESTORE = 1<<16;

  210. /**

  211. * Value for {@link #flags}: Set to true if the application’s backup

  212. * agent claims to be able to handle restore data even “from the future,”

  213. * i.e. from versions of the application with a versionCode greater than

  214. * the one currently installed on the device.  Use with caution!  By default

  215. * this attribute is false and the Backup Manager will ensure that data

  216. * from “future” versions of the application are never supplied during a restore operation.

  217. *

  218. If

  219. * {@link android.R.styleable#AndroidManifestApplication_allowBackup android:allowBackup}

  220. * is set to false or no

  221. * {@link android.R.styleable#AndroidManifestApplication_backupAgent android:backupAgent}

  222. * is specified, this flag will be ignored.

  223. *

  224. Comes from the

  225. * {@link android.R.styleable#AndroidManifestApplication_restoreAnyVersion android:restoreAnyVersion}

  226. * attribute of the  tag.

  227. */

  228. public static final int FLAG_RESTORE_ANY_VERSION = 1<<17;

  229. /**

  230. * Value for {@link #flags}: Set to true if the application is

  231. * currently installed on external/removable/unprotected storage.  Such

  232. * applications may not be available if their storage is not currently

  233. * mounted.  When the storage it is on is not available, it will look like

  234. * the application has been uninstalled (its .apk is no longer available)

  235. * but its persistent data is not removed.

  236. */

  237. public static final int FLAG_EXTERNAL_STORAGE = 1<<18;

  238. /**

  239. * Value for {@link #flags}: true when the application’s window can be

  240. * increased in size for extra large screens.  Corresponds to

  241. * {@link android.R.styleable#AndroidManifestSupportsScreens_xlargeScreens

  242. * android:xlargeScreens}.

  243. */

  244. public static final int FLAG_SUPPORTS_XLARGE_SCREENS = 1<<19;

  245. /**

  246. * Value for {@link #flags}: true when the application has requested a

  247. * large heap for its processes.  Corresponds to

  248. * {@link android.R.styleable#AndroidManifestApplication_largeHeap

  249. * android:largeHeap}.

  250. */

  251. public static final int FLAG_LARGE_HEAP = 1<<20;

  252. /**

  253. * Value for {@link #flags}: true if this application’s package is in

  254. * the stopped state.

  255. */

  256. public static final int FLAG_STOPPED = 1<<21;

  257. /**

  258. * Value for {@link #flags}: true  when the application is willing to support

  259. * RTL (right to left). All activities will inherit this value.

  260. *

  261. * Set from the {@link android.R.attr#supportsRtl} attribute in the

  262. * activity’s manifest.

  263. *

  264. * Default value is false (no support for RTL).

  265. */

  266. public static final int FLAG_SUPPORTS_RTL = 1<<22;

  267. /**

  268. * Value for {@link #flags}: true if the application is currently

  269. * installed for the calling user.

  270. */

  271. public static final int FLAG_INSTALLED = 1<<23;

  272. /**

  273. * Value for {@link #flags}: true if the application only has its

  274. * data installed; the application package itself does not currently

  275. * exist on the device.

  276. */

  277. public static final int FLAG_IS_DATA_ONLY = 1<<24;

  278. /**

  279. * Value for {@link #flags}: Set to true if the application has been

  280. * installed using the forward lock option.

  281. *

  282. * NOTE: DO NOT CHANGE THIS VALUE!  It is saved in packages.xml.

  283. *

  284. * {@hide}

  285. */

  286. public static final int FLAG_FORWARD_LOCK = 1<<29;

  287. /**

  288. * Value for {@link #flags}: set to true if the application

  289. * has reported that it is heavy-weight, and thus can not participate in

  290. * the normal application lifecycle.

  291. *

  292. Comes from the

  293. * {@link android.R.styleable#AndroidManifestApplication_cantSaveState android:cantSaveState}

  294. * attribute of the  tag.

  295. *

  296. * {@hide}

  297. */

  298. public static final int FLAG_CANT_SAVE_STATE = 1<<28;

  299. /**

  300. * Flags associated with the application.  Any combination of

  301. * {@link #FLAG_SYSTEM}, {@link #FLAG_DEBUGGABLE}, {@link #FLAG_HAS_CODE},

  302. * {@link #FLAG_PERSISTENT}, {@link #FLAG_FACTORY_TEST}, and

  303. * {@link #FLAG_ALLOW_TASK_REPARENTING}

  304. * {@link #FLAG_ALLOW_CLEAR_USER_DATA}, {@link #FLAG_UPDATED_SYSTEM_APP},

  305. * {@link #FLAG_TEST_ONLY}, {@link #FLAG_SUPPORTS_SMALL_SCREENS},

  306. * {@link #FLAG_SUPPORTS_NORMAL_SCREENS},

  307. * {@link #FLAG_SUPPORTS_LARGE_SCREENS}, {@link #FLAG_SUPPORTS_XLARGE_SCREENS},

  308. * {@link #FLAG_RESIZEABLE_FOR_SCREENS},

  309. * {@link #FLAG_SUPPORTS_SCREEN_DENSITIES}, {@link #FLAG_VM_SAFE_MODE},

  310. * {@link #FLAG_INSTALLED}.

  311. */

  312. public int flags = 0;

  313. /**

  314. * The required smallest screen width the application can run on.  If 0,

  315. * nothing has been specified.  Comes from

  316. * {@link android.R.styleable#AndroidManifestSupportsScreens_requiresSmallestWidthDp

  317. * android:requiresSmallestWidthDp} attribute of the  tag.

  318. */

  319. public int requiresSmallestWidthDp = 0;

  320. /**

  321. * The maximum smallest screen width the application is designed for.  If 0,

  322. * nothing has been specified.  Comes from

  323. * {@link android.R.styleable#AndroidManifestSupportsScreens_compatibleWidthLimitDp

  324. * android:compatibleWidthLimitDp} attribute of the  tag.

  325. */

  326. public int compatibleWidthLimitDp = 0;

  327. /**

  328. * The maximum smallest screen width the application will work on.  If 0,

  329. * nothing has been specified.  Comes from

  330. * {@link android.R.styleable#AndroidManifestSupportsScreens_largestWidthLimitDp

  331. * android:largestWidthLimitDp} attribute of the  tag.

  332. */

  333. public int largestWidthLimitDp = 0;

  334. /**

  335. * Full path to the location of this package.

  336. */

  337. public String sourceDir;

  338. /**

  339. * Full path to the location of the publicly available parts of this

  340. * package (i.e. the primary resource package and manifest).  For

  341. * non-forward-locked apps this will be the same as {@link #sourceDir).

  342. */

  343. public String publicSourceDir;

  344. /**

  345. * Full paths to the locations of extra resource packages this application

  346. * uses. This field is only used if there are extra resource packages,

  347. * otherwise it is null.

  348. *

  349. * {@hide}

  350. */

  351. public String[] resourceDirs;

  352. /**

  353. * Paths to all shared libraries this application is linked against.  This

  354. * field is only set if the {@link PackageManager#GET_SHARED_LIBRARY_FILES

  355. * PackageManager.GET_SHARED_LIBRARY_FILES} flag was used when retrieving

  356. * the structure.

  357. */

  358. public String[] sharedLibraryFiles;

  359. /**

  360. * Full path to a directory assigned to the package for its persistent

  361. * data.

  362. */

  363. public String dataDir;

  364. /**

  365. * Full path to the directory where native JNI libraries are stored.

  366. */

  367. public String nativeLibraryDir;

  368. /**

  369. * The kernel user-ID that has been assigned to this application;

  370. * currently this is not a unique ID (multiple applications can have

  371. * the same uid).

  372. */

  373. public int uid;

  374. /**

  375. * The minimum SDK version this application targets.  It may run on earlier

  376. * versions, but it knows how to work with any new behavior added at this

  377. * version.  Will be {@link android.os.Build.VERSION_CODES#CUR_DEVELOPMENT}

  378. * if this is a development build and the app is targeting that.  You should

  379. * compare that this number is >= the SDK version number at which your

  380. * behavior was introduced.

  381. */

  382. public int targetSdkVersion;

  383. /**

  384. * When false, indicates that all components within this application are

  385. * considered disabled, regardless of their individually set enabled status.

  386. */

  387. public boolean enabled = true;

  388. /**

  389. * For convenient access to the current enabled setting of this app.

  390. * @hide

  391. */

  392. public int enabledSetting = PackageManager.COMPONENT_ENABLED_STATE_DEFAULT;

  393. /**

  394. * For convenient access to package’s install location.

  395. * @hide

  396. */

  397. public int installLocation = PackageInfo.INSTALL_LOCATION_UNSPECIFIED;

  398. public void dump(Printer pw, String prefix) {

  399. super.dumpFront(pw, prefix);

  400. if (className != null) {

  401. pw.println(prefix + “className=” + className);

  402. }

  403. if (permission != null) {

  404. pw.println(prefix + “permission=” + permission);

  405. }

  406. pw.println(prefix + “processName=” + processName);

  407. pw.println(prefix + “taskAffinity=” + taskAffinity);

  408. pw.println(prefix + “uid=” + uid + " flags=0x" + Integer.toHexString(flags)

  409. + " theme=0x" + Integer.toHexString(theme));

  410. pw.println(prefix + “requiresSmallestWidthDp=” + requiresSmallestWidthDp

  411. + " compatibleWidthLimitDp=" + compatibleWidthLimitDp

  412. + " largestWidthLimitDp=" + largestWidthLimitDp);

  413. pw.println(prefix + “sourceDir=” + sourceDir);

  414. if (sourceDir == null) {

  415. if (publicSourceDir != null) {

  416. pw.println(prefix + “publicSourceDir=” + publicSourceDir);

  417. }

  418. } else if (!sourceDir.equals(publicSourceDir)) {

  419. pw.println(prefix + “publicSourceDir=” + publicSourceDir);

  420. }

  421. if (resourceDirs != null) {

  422. pw.println(prefix + “resourceDirs=” + resourceDirs);

  423. }

  424. pw.println(prefix + “dataDir=” + dataDir);

  425. if (sharedLibraryFiles != null) {

  426. pw.println(prefix + “sharedLibraryFiles=” + sharedLibraryFiles);

  427. }

  428. pw.println(prefix + “enabled=” + enabled + " targetSdkVersion=" + targetSdkVersion);

  429. if (manageSpaceActivityName != null) {

  430. pw.println(prefix + “manageSpaceActivityName=”+manageSpaceActivityName);

  431. }

  432. if (descriptionRes != 0) {

  433. pw.println(prefix + “description=0x”+Integer.toHexString(descriptionRes));

  434. }

  435. if (uiOptions != 0) {

  436. pw.println(prefix + “uiOptions=0x” + Integer.toHexString(uiOptions));

  437. }

  438. pw.println(prefix + “supportsRtl=” + (hasRtlSupport() ? “true” : “false”));

  439. super.dumpBack(pw, prefix);

  440. }

  441. /**

  442. * @return true if “supportsRtl” has been set to true in the AndroidManifest

  443. * @hide

  444. */

  445. public boolean hasRtlSupport() {

  446. return (flags & FLAG_SUPPORTS_RTL) == FLAG_SUPPORTS_RTL;

  447. }

  448. public static class DisplayNameComparator

  449. implements Comparator {

  450. public DisplayNameComparator(PackageManager pm) {

  451. mPM = pm;

  452. }

  453. public final int compare(ApplicationInfo aa, ApplicationInfo ab) {

  454. CharSequence  sa = mPM.getApplicationLabel(aa);

  455. if (sa == null) {

  456. sa = aa.packageName;

  457. }

  458. CharSequence  sb = mPM.getApplicationLabel(ab);

  459. if (sb == null) {

  460. sb = ab.packageName;

  461. }

  462. return sCollator.compare(sa.toString(), sb.toString());

  463. }

  464. private final Collator   sCollator = Collator.getInstance();

  465. private PackageManager   mPM;

  466. }

  467. public ApplicationInfo() {

  468. }

  469. public ApplicationInfo(ApplicationInfo orig) {

  470. super(orig);

  471. taskAffinity = orig.taskAffinity;

  472. permission = orig.permission;

  473. processName = orig.processName;

  474. className = orig.className;

  475. theme = orig.theme;

  476. flags = orig.flags;

  477. requiresSmallestWidthDp = orig.requiresSmallestWidthDp;

  478. compatibleWidthLimitDp = orig.compatibleWidthLimitDp;

  479. largestWidthLimitDp = orig.largestWidthLimitDp;

  480. sourceDir = orig.sourceDir;

  481. publicSourceDir = orig.publicSourceDir;

  482. nativeLibraryDir = orig.nativeLibraryDir;

  483. resourceDirs = orig.resourceDirs;

  484. sharedLibraryFiles = orig.sharedLibraryFiles;

  485. dataDir = orig.dataDir;

  486. uid = orig.uid;

  487. targetSdkVersion = orig.targetSdkVersion;

  488. enabled = orig.enabled;

  489. enabledSetting = orig.enabledSetting;

  490. installLocation = orig.installLocation;

  491. manageSpaceActivityName = orig.manageSpaceActivityName;

  492. descriptionRes = orig.descriptionRes;

  493. uiOptions = orig.uiOptions;

  494. backupAgentName = orig.backupAgentName;

  495. }

  496. public String toString() {

  497. return “ApplicationInfo{”

  498. + Integer.toHexString(System.identityHashCode(this))

  499. + " " + packageName + “}”;

  500. }

  501. public int describeContents() {

  502. return 0;

  503. }

  504. public void writeToParcel(Parcel dest, int parcelableFlags) {

  505. super.writeToParcel(dest, parcelableFlags);

  506. dest.writeString(taskAffinity);

  507. dest.writeString(permission);

  508. dest.writeString(processName);

  509. dest.writeString(className);

  510. dest.writeInt(theme);

  511. dest.writeInt(flags);

  512. dest.writeInt(requiresSmallestWidthDp);

  513. dest.writeInt(compatibleWidthLimitDp);

  514. dest.writeInt(largestWidthLimitDp);

  515. dest.writeString(sourceDir);

  516. dest.writeString(publicSourceDir);

  517. dest.writeString(nativeLibraryDir);

  518. dest.writeStringArray(resourceDirs);

  519. dest.writeStringArray(sharedLibraryFiles);

  520. dest.writeString(dataDir);

  521. dest.writeInt(uid);

  522. dest.writeInt(targetSdkVersion);

  523. dest.writeInt(enabled ? 1 : 0);

  524. dest.writeInt(enabledSetting);

  525. dest.writeInt(installLocation);

  526. dest.writeString(manageSpaceActivityName);

  527. dest.writeString(backupAgentName);

  528. dest.writeInt(descriptionRes);

  529. dest.writeInt(uiOptions);

  530. }

  531. public static final Parcelable.Creator CREATOR

  532. = new Parcelable.Creator() {

  533. public ApplicationInfo createFromParcel(Parcel source) {

  534. return new ApplicationInfo(source);

  535. }

  536. public ApplicationInfo[] newArray(int size) {

  537. return new ApplicationInfo[size];

  538. }

  539. };

  540. private ApplicationInfo(Parcel source) {

  541. super(source);

  542. taskAffinity = source.readString();

  543. permission = source.readString();

  544. processName = source.readString();

  545. className = source.readString();

  546. theme = source.readInt();

  547. flags = source.readInt();

  548. requiresSmallestWidthDp = source.readInt();

  549. compatibleWidthLimitDp = source.readInt();

  550. largestWidthLimitDp = source.readInt();

  551. sourceDir = source.readString();

  552. publicSourceDir = source.readString();

  553. nativeLibraryDir = source.readString();

  554. resourceDirs = source.readStringArray();

  555. sharedLibraryFiles = source.readStringArray();

  556. dataDir = source.readString();

  557. uid = source.readInt();

  558. targetSdkVersion = source.readInt();

  559. enabled = source.readInt() != 0;

  560. enabledSetting = source.readInt();

  561. installLocation = source.readInt();

  562. manageSpaceActivityName = source.readString();

  563. backupAgentName = source.readString();

  564. descriptionRes = source.readInt();

  565. uiOptions = source.readInt();

  566. }

  567. /**

  568. * Retrieve the textual description of the application.  This

  569. * will call back on the given PackageManager to load the description from

  570. * the application.

  571. *

  572. * @param pm A PackageManager from which the label can be loaded; usually

  573. * the PackageManager from which you originally retrieved this item.

  574. *

  575. * @return Returns a CharSequence containing the application’s description.

  576. * If there is no description, null is returned.

  577. */

  578. public CharSequence loadDescription(PackageManager pm) {

  579. if (descriptionRes != 0) {

  580. CharSequence label = pm.getText(packageName, descriptionRes, this);

  581. if (label != null) {

  582. return label;

  583. }

  584. }

  585. return null;

  586. }

  587. /**

  588. * Disable compatibility mode

  589. *

  590. * @hide

  591. */

  592. public void disableCompatibilityMode() {

  593. flags |= (FLAG_SUPPORTS_LARGE_SCREENS | FLAG_SUPPORTS_NORMAL_SCREENS |

  594. FLAG_SUPPORTS_SMALL_SCREENS | FLAG_RESIZEABLE_FOR_SCREENS |

  595. FLAG_SUPPORTS_SCREEN_DENSITIES | FLAG_SUPPORTS_XLARGE_SCREENS);

  596. }

  597. /**

  598. * @hide

  599. */

  600. @Override protected Drawable loadDefaultIcon(PackageManager pm) {

  601. if ((flags & FLAG_EXTERNAL_STORAGE) != 0

  602. && isPackageUnavailable(pm)) {

  603. return Resources.getSystem().getDrawable(

  604. com.android.internal.R.drawable.sym_app_on_sd_unavailable_icon);

  605. }

  606. return pm.getDefaultActivityIcon();

  607. }

  608. private boolean isPackageUnavailable(PackageManager pm) {

  609. try {

  610. return pm.getPackageInfo(packageName, 0) == null;

  611. } catch (NameNotFoundException ex) {

  612. return true;

  613. }

  614. }

  615. /**

  616. * @hide

  617. */

  618. @Override protected ApplicationInfo getApplicationInfo() {

  619. return this;

  620. }

  621. }

PackageItemInfo.java源码:

[java]  view plain copy 外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传 外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

  1. /*

  2. * Copyright © 2007 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. package android.content.pm;

  17. import android.content.res.XmlResourceParser;

  18. import android.graphics.drawable.Drawable;

  19. import android.os.Bundle;

  20. import android.os.Parcel;

  21. import android.text.TextUtils;

  22. import android.util.Printer;

  23. import java.text.Collator;

  24. import java.util.Comparator;

  25. /**

  26. * Base class containing information common to all package items held by

  27. * the package manager.  This provides a very common basic set of attributes:

  28. * a label, icon, and meta-data.  This class is not intended

  29. * to be used by itself; it is simply here to share common definitions

  30. * between all items returned by the package manager.  As such, it does not

  31. * itself implement Parcelable, but does provide convenience methods to assist

  32. * in the implementation of Parcelable in subclasses.

  33. */

  34. public class PackageItemInfo {

  35. /**

  36. * Public name of this item. From the “android:name” attribute.

  37. */

  38. public String name;

  39. /**

  40. * Name of the package that this item is in.

  41. */

  42. public String packageName;

  43. /**

  44. * A string resource identifier (in the package’s resources) of this

  45. * component’s label.  From the “label” attribute or, if not set, 0.

  46. */

  47. public int labelRes;

  48. /**

  49. * The string provided in the AndroidManifest file, if any.  You

  50. * probably don’t want to use this.  You probably want

  51. * {@link PackageManager#getApplicationLabel}

  52. */

  53. public CharSequence nonLocalizedLabel;

  54. /**

  55. * A drawable resource identifier (in the package’s resources) of this

  56. * component’s icon.  From the “icon” attribute or, if not set, 0.

  57. */

  58. public int icon;

  59. /**

  60. * A drawable resource identifier (in the package’s resources) of this

  61. * component’s logo. Logos may be larger/wider than icons and are

  62. * displayed by certain UI elements in place of a name or name/icon

  63. * combination. From the “logo” attribute or, if not set, 0.

  64. */

  65. public int logo;

  66. /**

  67. * Additional meta-data associated with this component.  This field

  68. * will only be filled in if you set the

  69. * {@link PackageManager#GET_META_DATA} flag when requesting the info.

  70. */

  71. public Bundle metaData;

  72. public PackageItemInfo() {

  73. }

  74. public PackageItemInfo(PackageItemInfo orig) {

  75. name = orig.name;

  76. if (name != null) name = name.trim();

  77. packageName = orig.packageName;

  78. labelRes = orig.labelRes;

  79. nonLocalizedLabel = orig.nonLocalizedLabel;

  80. if (nonLocalizedLabel != null) nonLocalizedLabel = nonLocalizedLabel.toString().trim();  
    .  You

  81. * probably don’t want to use this.  You probably want

  82. * {@link PackageManager#getApplicationLabel}

  83. */

  84. public CharSequence nonLocalizedLabel;

  85. /**

  86. * A drawable resource identifier (in the package’s resources) of this

  87. * component’s icon.  From the “icon” attribute or, if not set, 0.

  88. */

  89. public int icon;

  90. /**

  91. * A drawable resource identifier (in the package’s resources) of this

  92. * component’s logo. Logos may be larger/wider than icons and are

  93. * displayed by certain UI elements in place of a name or name/icon

  94. * combination. From the “logo” attribute or, if not set, 0.

  95. */

  96. public int logo;

  97. /**

  98. * Additional meta-data associated with this component.  This field

  99. * will only be filled in if you set the

  100. * {@link PackageManager#GET_META_DATA} flag when requesting the info.

  101. */

  102. public Bundle metaData;

  103. public PackageItemInfo() {

  104. }

  105. public PackageItemInfo(PackageItemInfo orig) {

  106. name = orig.name;

  107. if (name != null) name = name.trim();

  108. packageName = orig.packageName;

  109. labelRes = orig.labelRes;

  110. nonLocalizedLabel = orig.nonLocalizedLabel;

  111. if (nonLocalizedLabel != null) nonLocalizedLabel = nonLocalizedLabel.toString().trim();

  • 13
    点赞
  • 22
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值