Advertisement
Guest User

Untitled

a guest
Dec 30th, 2014
773
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.95 KB | None | 0 0
  1. public enum PartitionType {
  2. BOOT, RECOVERY, FOTA
  3. }
  4.  
  5. private String[] bootPartitionNames = new String[] { "boot", "kernel", "LX" };
  6. private String[] recoveryPartitionNames = new String[] { "recovery", "SS" };
  7. private String[] fotaPartitionNames = new String[] { "FOTAKernel" };
  8.  
  9. public String getPartitionName(PartitionType partition) {
  10. /*
  11. * Read out partitions from /dev/block/platform. That is the easiest way
  12. * and reading fstab is not always possible.
  13. */
  14. if ((partition == PartitionType.BOOT && bootPartition == null)
  15. || (partition == PartitionType.RECOVERY && recoveryPartition == null)
  16. || (partition == PartitionType.FOTA && fotaPartition == null)) {
  17.  
  18. String[] partitionNames = null;
  19. switch (partition) {
  20. case BOOT:
  21. partitionNames = bootPartitionNames;
  22. break;
  23. case RECOVERY:
  24. partitionNames = recoveryPartitionNames;
  25. break;
  26. case FOTA:
  27. partitionNames = fotaPartitionNames;
  28. break;
  29. }
  30.  
  31. if (partitionNames != null) {
  32. String path = mUtils.existFile(PARTITON_PATH + "/omap") ? PARTITON_PATH
  33. + "/omap"
  34. : PARTITON_PATH;
  35. if (mUtils.existFile(path)) {
  36. File[] platforms = new File(path).listFiles();
  37. if (platforms.length > 0) for (File platform : platforms)
  38. if (platform.isDirectory()) for (File emmc : platform
  39. .listFiles())
  40. if (emmc.getName().equals("by-name")) for (File part : emmc
  41. .listFiles())
  42. for (String names : partitionNames)
  43. if (names.equals(part.getName())
  44. || names.toUpperCase().equals(
  45. part.getName())) {
  46. if (partition == PartitionType.BOOT) bootPartition = part
  47. .getAbsolutePath();
  48. if (partition == PartitionType.RECOVERY) recoveryPartition = part
  49. .getAbsolutePath();
  50. if (partition == PartitionType.FOTA) fotaPartition = part
  51. .getAbsolutePath();
  52. }
  53. }
  54. }
  55. }
  56.  
  57. if (partition == PartitionType.BOOT) return bootPartition;
  58. if (partition == PartitionType.RECOVERY) return recoveryPartition;
  59. if (partition == PartitionType.FOTA) return fotaPartition;
  60. return null;
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement