Android 的manifest解析

  1. import android.os.Parcel;

  2. import android.os.Parcelable;

  3. import android.util.Printer;

  4. import java.text.Collator;

  5. import java.util.Comparator;

  6. /**

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

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

  9. *  tag.

  10. */

  11. public class ApplicationInfo extends PackageItemInfo implements Parcelable {

  12. /**

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

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

  15. * from the “taskAffinity” attribute.

  16. */

  17. public String taskAffinity;

  18. /**

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

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

  21. */

  22. public String permission;

  23. /**

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

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

  26. packageName.

  27. */

  28. public String processName;

  29. /**

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

  31. * attribute.

  32. */

  33. public String className;

  34. /**

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

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

  37. * or, if not set, 0.

  38. */

  39. public int descriptionRes;

  40. /**

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

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

  43. * or, if not set, 0.

  44. */

  45. public int theme;

  46. /**

  47. * Class implementing the Application’s manage space

  48. * functionality.  From the “manageSpaceActivity”

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

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

  51. */

  52. public String manageSpaceActivityName;

  53. /**

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

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

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

  57. *

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

  59. */

  60. public String backupAgentName;

  61. /**

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

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

  64. * activity’s manifest.

  65. */

  66. public int uiOptions = 0;

  67. /**

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

  69. * device’s system image.

  70. */

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

  72. /**

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

  74. * allow debugging of its

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

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

  77. * android:debuggable} of the  tag.

  78. */

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

  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  tag.

  85. */

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

  87. /**

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

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

  90. * android:persistent} of the  tag.

  91. */

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

  93. /**

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

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

  96. * device is running in factory test mode.

  97. */

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

  99. /**

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

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

  102. * android:allowTaskReparenting} of the  tag.

  103. */

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

  105. /**

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

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

  108. * android:allowClearUserData} of the  tag.

  109. */

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

  111. /**

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

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

  114. */

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

  116. /**

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

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

  119. * android:testOnly} to be true.

  120. */

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

  122. /**

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

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

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

  126. * android:smallScreens}.

  127. */

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

  129. /**

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

  131. * displayed on normal screens.  Corresponds to

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

  133. * android:normalScreens}.

  134. */

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

  136. /**

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

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

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

  140. * android:largeScreens}.

  141. */

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

  143. /**

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

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

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

  147. * android:resizeable}.

  148. */

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

  150. /**

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

  152. * accomodate different screen densities.  Corresponds to

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

  154. * android:anyDensity}.

  155. */

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

  157. /**

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

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

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

  161. * android:vmSafeMode} of the  tag.

  162. */

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

  164. /**

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

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

  167. *

  168. Comes from the

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

  170. * attribute of the  tag.

  171. */

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

  173. /**

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

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

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

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

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

  179. *

  180. If

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

  182. * is set to false or no

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

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

  185. *

  186. Comes from the

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

  188. * attribute of the  tag.

  189. */

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

  191. /**

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

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

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

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

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

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

  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_restoreAnyVersion android:restoreAnyVersion}

  207. * attribute of the  tag.

  208. */

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

  210. /**

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

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

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

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

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

  216. * but its persistent data is not removed.

  217. */

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

  219. /**

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

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

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

  223. * android:xlargeScreens}.

  224. */

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

  226. /**

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

  228. * large heap for its processes.  Corresponds to

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

  230. * android:largeHeap}.

  231. */

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

  233. /**

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

  235. * the stopped state.

  236. */

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

  238. /**

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

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

  241. *

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

  243. * activity’s manifest.

  244. *

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

  246. */

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

  248. /**

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

  250. * installed for the calling user.

  251. */

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

  253. /**

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

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

  256. * exist on the device.

  257. */

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

  259. /**

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

  261. * installed using the forward lock option.

  262. *

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

  264. *

  265. * {@hide}

  266. */

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

  268. /**

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

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

  271. * the normal application lifecycle.

  272. *

  273. Comes from the

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

  275. * attribute of the  tag.

  276. *

  277. * {@hide}

  278. */

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

  280. /**

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

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

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

  284. * {@link #FLAG_ALLOW_TASK_REPARENTING}

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

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

  287. * {@link #FLAG_SUPPORTS_NORMAL_SCREENS},

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

  289. * {@link #FLAG_RESIZEABLE_FOR_SCREENS},

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

  291. * {@link #FLAG_INSTALLED}.

  292. */

  293. public int flags = 0;

  294. /**

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

  296. * nothing has been specified.  Comes from

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

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

  299. */

  300. public int requiresSmallestWidthDp = 0;

  301. /**

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

  303. * nothing has been specified.  Comes from

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

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

  306. */

  307. public int compatibleWidthLimitDp = 0;

  308. /**

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

  310. * nothing has been specified.  Comes from

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

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

  313. */

  314. public int largestWidthLimitDp = 0;

  315. /**

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

  317. */

  318. public String sourceDir;

  319. /**

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

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

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

  323. */

  324. public String publicSourceDir;

  325. /**

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

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

  328. * otherwise it is null.

  329. *

  330. * {@hide}

  331. */

  332. public String[] resourceDirs;

  333. /**

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

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

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

  337. * the structure.

  338. */

  339. public String[] sharedLibraryFiles;

  340. /**

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

  342. * data.

  343. */

  344. public String dataDir;

  345. /**

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

  347. */

  348. public String nativeLibraryDir;

  349. /**

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

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

  352. * the same uid).

  353. */

  354. public int uid;

  355. /**

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

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

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

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

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

  361. * behavior was introduced.

  362. */

  363. public int targetSdkVersion;

  364. /**

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

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

  367. */

  368. public boolean enabled = true;

  369. /**

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

  371. * @hide

  372. */

  373. public int enabledSetting = PackageManager.COMPONENT_ENABLED_STATE_DEFAULT;

  374. /**

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

  376. * @hide

  377. */

  378. public int installLocation = PackageInfo.INSTALL_LOCATION_UNSPECIFIED;

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

  380. super.dumpFront(pw, prefix);

  381. if (className != null) {

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

  383. }

  384. if (permission != null) {

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

  386. }

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

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

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

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

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

  392. + " compatibleWidthLimitDp=" + compatibleWidthLimitDp

  393. + " largestWidthLimitDp=" + largestWidthLimitDp);

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

  395. if (sourceDir == null) {

  396. if (publicSourceDir != null) {

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

  398. }

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

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

  401. }

  402. if (resourceDirs != null) {

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

  404. }

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

  406. if (sharedLibraryFiles != null) {

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

  408. }

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

  410. if (manageSpaceActivityName != null) {

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

  412. }

  413. if (descriptionRes != 0) {

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

  415. }

  416. if (uiOptions != 0) {

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

  418. }

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

  420. super.dumpBack(pw, prefix);

  421. }

  422. /**

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

  424. * @hide

  425. */

  426. public boolean hasRtlSupport() {

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

  428. }

  429. public static class DisplayNameComparator

  430. implements Comparator {

  431. public DisplayNameComparator(PackageManager pm) {

  432. mPM = pm;

  433. }

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

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

  436. if (sa == null) {

  437. sa = aa.packageName;

  438. }

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

  440. if (sb == null) {

  441. sb = ab.packageName;

  442. }

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

  444. }

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

  446. private PackageManager   mPM;

  447. }

  448. public ApplicationInfo() {

  449. }

  450. public ApplicationInfo(ApplicationInfo orig) {

  451. super(orig);

  452. taskAffinity = orig.taskAffinity;

  453. permission = orig.permission;

  454. processName = orig.processName;

  455. className = orig.className;

  456. theme = orig.theme;

  457. flags = orig.flags;

  458. requiresSmallestWidthDp = orig.requiresSmallestWidthDp;

  459. compatibleWidthLimitDp = orig.compatibleWidthLimitDp;

  460. largestWidthLimitDp = orig.largestWidthLimitDp;

  461. sourceDir = orig.sourceDir;

  462. publicSourceDir = orig.publicSourceDir;

  463. nativeLibraryDir = orig.nativeLibraryDir;

  464. resourceDirs = orig.resourceDirs;

  465. sharedLibraryFiles = orig.sharedLibraryFiles;

  466. dataDir = orig.dataDir;

  467. uid = orig.uid;

  468. targetSdkVersion = orig.targetSdkVersion;

  469. enabled = orig.enabled;

  470. enabledSetting = orig.enabledSetting;

  471. installLocation = orig.installLocation;

  472. manageSpaceActivityName = orig.manageSpaceActivityName;

  473. descriptionRes = orig.descriptionRes;

  474. uiOptions = orig.uiOptions;

  475. backupAgentName = orig.backupAgentName;

  476. }

  477. public String toString() {

  478. return “ApplicationInfo{”

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

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

  481. }

  482. public int describeContents() {

  483. return 0;

  484. }

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

  486. super.writeToParcel(dest, parcelableFlags);

  487. dest.writeString(taskAffinity);

  488. dest.writeString(permission);

  489. dest.writeString(processName);

  490. dest.writeString(className);

  491. dest.writeInt(theme);

  492. dest.writeInt(flags);

  493. dest.writeInt(requiresSmallestWidthDp);

  494. dest.writeInt(compatibleWidthLimitDp);

  495. dest.writeInt(largestWidthLimitDp);

  496. dest.writeString(sourceDir);

  497. dest.writeString(publicSourceDir);

  498. dest.writeString(nativeLibraryDir);

  499. dest.writeStringArray(resourceDirs);

  500. dest.writeStringArray(sharedLibraryFiles);

  501. dest.writeString(dataDir);

  502. dest.writeInt(uid);

  503. dest.writeInt(targetSdkVersion);

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

  505. dest.writeInt(enabledSetting);

  506. dest.writeInt(installLocation);

  507. dest.writeString(manageSpaceActivityName);

  508. dest.writeString(backupAgentName);

  509. dest.writeInt(descriptionRes);

  510. dest.writeInt(uiOptions);

  511. }

  512. public static final Parcelable.Creator CREATOR

  513. = new Parcelable.Creator() {

  514. public ApplicationInfo createFromParcel(Parcel source) {

  515. return new ApplicationInfo(source);

  516. }

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

  518. return new ApplicationInfo[size];

  519. }

  520. };

  521. private ApplicationInfo(Parcel source) {

  522. super(source);

  523. taskAffinity = source.readString();

  524. permission = source.readString();

  525. processName = source.readString();

  526. className = source.readString();

  527. theme = source.readInt();

  528. flags = source.readInt();

  529. requiresSmallestWidthDp = source.readInt();

  530. compatibleWidthLimitDp = source.readInt();

  531. largestWidthLimitDp = source.readInt();

  532. sourceDir = source.readString();

  533. publicSourceDir = source.readString();

  534. nativeLibraryDir = source.readString();

  535. resourceDirs = source.readStringArray();

  536. sharedLibraryFiles = source.readStringArray();

  537. dataDir = source.readString();

  538. uid = source.readInt();

  539. targetSdkVersion = source.readInt();

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

  541. enabledSetting = source.readInt();

  542. installLocation = source.readInt();

  543. manageSpaceActivityName = source.readString();

  544. backupAgentName = source.readString();

  545. descriptionRes = source.readInt();

  546. uiOptions = source.readInt();

  547. }

  548. /**

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

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

  551. * the application.

  552. *

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

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

  555. *

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

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

  558. */

  559. public CharSequence loadDescription(PackageManager pm) {

  560. if (descriptionRes != 0) {

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

  562. if (label != null) {

  563. return label;

  564. }

  565. }

  566. return null;

  567. }

  568. /**

  569. * Disable compatibility mode

  570. *

  571. * @hide

  572. */

  573. public void disableCompatibilityMode() {

  574. flags |= (FLAG_SUPPORTS_LARGE_SCREENS | FLAG_SUPPORTS_NORMAL_SCREENS |

  575. FLAG_SUPPORTS_SMALL_SCREENS | FLAG_RESIZEABLE_FOR_SCREENS |

  576. FLAG_SUPPORTS_SCREEN_DENSITIES | FLAG_SUPPORTS_XLARGE_SCREENS);

  577. }

  578. /**

  579. * @hide

  580. */

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

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

  583. && isPackageUnavailable(pm)) {

  584. return Resources.getSystem().getDrawable(

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

  586. }

  587. return pm.getDefaultActivityIcon();

  588. }

  589. private boolean isPackageUnavailable(PackageManager pm) {

  590. try {

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

  592. } catch (NameNotFoundException ex) {

  593. return true;

  594. }

  595. }

  596. /**

  597. * @hide

  598. */

  599. @Override protected ApplicationInfo getApplicationInfo() {

  600. return this;

  601. }

  602. }

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();

  81. icon = orig.icon;

  82. logo = orig.logo;

  83. metaData = orig.metaData;

  84. }

  85. /**

  86. * Retrieve the current textual label associated with this item.  This

  87. * will call back on the given PackageManager to load the label from

  88. * the application.

  89. *

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

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

  92. *

  93. * @return Returns a CharSequence containing the item’s label.  If the

  94. * item does not have a label, its name is returned.

  95. */

  96. public CharSequence loadLabel(PackageManager pm) {

  97. if (nonLocalizedLabel != null) {

  98. return nonLocalizedLabel;

  99. }

  100. if (labelRes != 0) {

  101. CharSequence label = pm.getText(packageName, labelRes, getApplicationInfo());

  102. if (label != null) {

  103. return label.toString().trim();

  104. }

  105. }

  106. if (name != null) {

  107. return name;

  108. }

  109. return packageName;

  110. }

  111. /**

  112. * Retrieve the current graphical icon associated with this item.  This

  113. * will call back on the given PackageManager to load the icon from

  114. * the application.

  115. *

  116. * @param pm A PackageManager from which the icon can be loaded; usually

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

  118. *

  119. * @return Returns a Drawable containing the item’s icon.  If the

  120. * item does not have an icon, the item’s default icon is returned

  121. * such as the default activity icon.

  122. */

  123. public Drawable loadIcon(PackageManager pm) {

  124. if (icon != 0) {

  125. Drawable dr = pm.getDrawable(packageName, icon, getApplicationInfo());

  126. if (dr != null) {

  127. return dr;

  128. }

  129. }

  130. return loadDefaultIcon(pm);

  131. }

  132. /**

  133. * Retrieve the default graphical icon associated with this item.

  134. *

  135. * @param pm A PackageManager from which the icon can be loaded; usually

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

  137. *

  138. * @return Returns a Drawable containing the item’s default icon

  139. * such as the default activity icon.

  140. *

  141. * @hide

  142. */

  143. protected Drawable loadDefaultIcon(PackageManager pm) {

  144. return pm.getDefaultActivityIcon();

  145. }

  146. /**

  147. * Retrieve the current graphical logo associated with this item. This

  148. * will call back on the given PackageManager to load the logo from

  149. * the application.

  150. *

  151. * @param pm A PackageManager from which the logo can be loaded; usually

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

  153. *

  154. * @return Returns a Drawable containing the item’s logo. If the item

  155. * does not have a logo, this method will return null.

  156. */

  157. public Drawable loadLogo(PackageManager pm) {

  158. if (logo != 0) {

  159. Drawable d = pm.getDrawable(packageName, logo, getApplicationInfo());

  160. if (d != null) {

  161. return d;

  162. }

  163. }

  164. return loadDefaultLogo(pm);

  165. }

  166. /**

  167. * Retrieve the default graphical logo associated with this item.

  168. *

  169. * @param pm A PackageManager from which the logo can be loaded; usually

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

  171. *

  172. * @return Returns a Drawable containing the item’s default logo

  173. * or null if no default logo is available.

  174. *

  175. * @hide

  176. */

  177. protected Drawable loadDefaultLogo(PackageManager pm) {

  178. return null;

  179. }

  180. /**

  181. * Load an XML resource attached to the meta-data of this item.  This will

  182. * retrieved the name meta-data entry, and if defined call back on the

  183. * given PackageManager to load its XML file from the application.

  184. *

  185. * @param pm A PackageManager from which the XML can be loaded; usually

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

  187. * @param name Name of the meta-date you would like to load.

  188. *

  189. * @return Returns an XmlPullParser you can use to parse the XML file

  190. * assigned as the given meta-data.  If the meta-data name is not defined

  191. * or the XML resource could not be found, null is returned.

  192. */

  193. public XmlResourceParser loadXmlMetaData(PackageManager pm, String name) {

  194. if (metaData != null) {

  195. int resid = metaData.getInt(name);

  196. if (resid != 0) {

  197. return pm.getXml(packageName, resid, getApplicationInfo());

  198. }

  199. }

  200. return null;

  201. }

  202. protected void dumpFront(Printer pw, String prefix) {

  203. if (name != null) {

  204. pw.println(prefix + “name=” + name);

  205. }

  206. pw.println(prefix + “packageName=” + packageName);

  207. if (labelRes != 0 || nonLocalizedLabel != null || icon != 0) {

  208. pw.println(prefix + “labelRes=0x” + Integer.toHexString(labelRes)

  209. + " nonLocalizedLabel=" + nonLocalizedLabel

  210. + " icon=0x" + Integer.toHexString(icon));

  211. }

  212. }

  213. protected void dumpBack(Printer pw, String prefix) {

  214. // no back here

  215. }

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

  217. dest.writeString(name);

  218. dest.writeString(packageName);

  219. dest.writeInt(labelRes);

  220. TextUtils.writeToParcel(nonLocalizedLabel, dest, parcelableFlags);

  221. dest.writeInt(icon);

自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。

深知大多数初中级Android工程师,想要提升技能,往往是自己摸索成长或者是报班学习,但对于培训机构动则近万的学费,着实压力不小。自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!

因此收集整理了一份《2024年Android移动开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。

img

img

img

img

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上Android开发知识点,真正体系化!

由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且会持续更新!

如果你觉得这些内容对你有帮助,可以扫码获取!!(备注:Android)

总结

笔者之前工作是在金融公司可能并不是特别追求技术,而笔者又是喜欢追求技术的人,所以格格不入,只能把目标放在互联网大厂了。也希望大家都去敢于尝试和追逐自己的梦想!
BATJ大厂Android高频面试题

觉得有收获的记得点赞,关注+收藏哦!你们的点赞就是我的动力!

《互联网大厂面试真题解析、进阶开发核心学习笔记、全套讲解视频、实战项目源码讲义》点击传送门即可获取!

" + Integer.toHexString(labelRes)

  1. + " nonLocalizedLabel=" + nonLocalizedLabel

  2. + " icon=0x" + Integer.toHexString(icon));

  3. }

  4. }

  5. protected void dumpBack(Printer pw, String prefix) {

  6. // no back here

  7. }

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

  9. dest.writeString(name);

  10. dest.writeString(packageName);

  11. dest.writeInt(labelRes);

  12. TextUtils.writeToParcel(nonLocalizedLabel, dest, parcelableFlags);

  13. dest.writeInt(icon);

自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。

深知大多数初中级Android工程师,想要提升技能,往往是自己摸索成长或者是报班学习,但对于培训机构动则近万的学费,着实压力不小。自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!

因此收集整理了一份《2024年Android移动开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。

[外链图片转存中…(img-DMXHOIUQ-1713151895731)]

[外链图片转存中…(img-PRoL6nQq-1713151895732)]

[外链图片转存中…(img-foFsEFlw-1713151895732)]

[外链图片转存中…(img-VRhb2B0D-1713151895732)]

[外链图片转存中…(img-zKXlAMf3-1713151895732)]

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上Android开发知识点,真正体系化!

由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且会持续更新!

如果你觉得这些内容对你有帮助,可以扫码获取!!(备注:Android)

总结

笔者之前工作是在金融公司可能并不是特别追求技术,而笔者又是喜欢追求技术的人,所以格格不入,只能把目标放在互联网大厂了。也希望大家都去敢于尝试和追逐自己的梦想!
BATJ大厂Android高频面试题

[外链图片转存中…(img-4CxITU33-1713151895733)]

[外链图片转存中…(img-VXhBXNeV-1713151895733)]

[外链图片转存中…(img-n05wOjQS-1713151895733)]

[外链图片转存中…(img-D2Pr1LjI-1713151895733)]

觉得有收获的记得点赞,关注+收藏哦!你们的点赞就是我的动力!

《互联网大厂面试真题解析、进阶开发核心学习笔记、全套讲解视频、实战项目源码讲义》点击传送门即可获取!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值