fill_screens.py 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #!/usr/bin/env python2.5
  2. import cgi
  3. import os
  4. import shutil
  5. import sys
  6. import sqlite3
  7. SCREENS = 5
  8. COLUMNS = 4
  9. ROWS = 4
  10. CELL_SIZE = 110
  11. DIR = "db_files"
  12. AUTO_FILE = "launcher.db"
  13. APPLICATION_COMPONENTS = [
  14. "com.android.calculator2/com.android.calculator2.Calculator",
  15. "com.android.providers.downloads.ui/com.android.providers.downloads.ui.DownloadList",
  16. "com.android.settings/com.android.settings.Settings",
  17. "com.android.mms/com.android.mms.ui.ConversationList",
  18. "com.android.contacts/com.android.contacts.activities.PeopleActivity",
  19. "com.android.dialer/com.android.dialer.DialtactsActivity"
  20. ]
  21. def usage():
  22. print "usage: fill_screens.py -- fills up the launcher db"
  23. def make_dir():
  24. shutil.rmtree(DIR, True)
  25. os.makedirs(DIR)
  26. def pull_file(fn):
  27. print "pull_file: " + fn
  28. rv = os.system("adb pull"
  29. + " /data/data/com.android.launcher/databases/launcher.db"
  30. + " " + fn);
  31. if rv != 0:
  32. print "adb pull failed"
  33. sys.exit(1)
  34. def push_file(fn):
  35. print "push_file: " + fn
  36. rv = os.system("adb push"
  37. + " " + fn
  38. + " /data/data/com.android.launcher/databases/launcher.db")
  39. if rv != 0:
  40. print "adb push failed"
  41. sys.exit(1)
  42. def process_file(fn):
  43. print "process_file: " + fn
  44. conn = sqlite3.connect(fn)
  45. c = conn.cursor()
  46. c.execute("DELETE FROM favorites")
  47. intentFormat = "#Intent;action=android.intent.action.MAIN;category=android.intent.category.LAUNCHER;launchFlags=0x10200000;component=%s;end"
  48. id = 0;
  49. for s in range(SCREENS):
  50. for x in range(ROWS):
  51. for y in range(COLUMNS):
  52. id += 1
  53. insert = "INSERT into favorites (_id, title, intent, container, screen, cellX, cellY, spanX, spanY, itemType, appWidgetId, iconType) VALUES (%d, '%s', '%s', %d, %d, %d, %d, %d, %d, %d, %d, %d)"
  54. insert = insert % (id, "title", "", -100, s, x, y, 1, 1, 2, -1, 0)
  55. c.execute(insert)
  56. folder_id = id
  57. for z in range(15):
  58. id += 1
  59. intent = intentFormat % (APPLICATION_COMPONENTS[id % len(APPLICATION_COMPONENTS)])
  60. insert = "INSERT into favorites (_id, title, intent, container, screen, cellX, cellY, spanX, spanY, itemType, appWidgetId, iconType) VALUES (%d, '%s', '%s', %d, %d, %d, %d, %d, %d, %d, %d, %d)"
  61. insert = insert % (id, "title", intent, folder_id, 0, 0, 0, 1, 1, 0, -1, 0)
  62. c.execute(insert)
  63. conn.commit()
  64. c.close()
  65. def main(argv):
  66. if len(argv) == 1:
  67. make_dir()
  68. pull_file(AUTO_FILE)
  69. process_file(AUTO_FILE)
  70. push_file(AUTO_FILE)
  71. else:
  72. usage()
  73. if __name__=="__main__":
  74. main(sys.argv)