| Adam Cohen | 1982c4b | 2011-08-25 13:49:43 -0700 | [diff] [blame] | 1 | #!/usr/bin/env python2.5 | 
 | 2 |  | 
 | 3 | import cgi | 
 | 4 | import os | 
 | 5 | import shutil | 
 | 6 | import sys | 
 | 7 | import sqlite3 | 
 | 8 |  | 
 | 9 | SCREENS = 5 | 
 | 10 | COLUMNS = 4 | 
 | 11 | ROWS = 4 | 
 | 12 | CELL_SIZE = 110 | 
 | 13 |  | 
 | 14 | DIR = "db_files" | 
 | 15 | AUTO_FILE = "launcher.db" | 
 | 16 |  | 
 | 17 | APPLICATION_COMPONENTS = [ | 
| Adam Cohen | 1982c4b | 2011-08-25 13:49:43 -0700 | [diff] [blame] | 18 |   "com.android.calculator2/com.android.calculator2.Calculator", | 
| Adam Cohen | 1982c4b | 2011-08-25 13:49:43 -0700 | [diff] [blame] | 19 |   "com.android.providers.downloads.ui/com.android.providers.downloads.ui.DownloadList", | 
| Michael Jurka | b964f9c | 2011-09-27 22:10:05 -0700 | [diff] [blame] | 20 |   "com.android.settings/com.android.settings.Settings", | 
 | 21 |   "com.android.mms/com.android.mms.ui.ConversationList", | 
 | 22 |   "com.android.contacts/com.android.contacts.activities.PeopleActivity", | 
| Chiao Cheng | f043f80 | 2012-08-21 13:35:10 -0700 | [diff] [blame] | 23 |   "com.android.dialer/com.android.dialer.DialtactsActivity" | 
| Adam Cohen | 1982c4b | 2011-08-25 13:49:43 -0700 | [diff] [blame] | 24 | ] | 
 | 25 |  | 
 | 26 | def usage(): | 
 | 27 |   print "usage: fill_screens.py -- fills up the launcher db" | 
 | 28 |  | 
 | 29 |  | 
 | 30 | def make_dir(): | 
 | 31 |   shutil.rmtree(DIR, True) | 
 | 32 |   os.makedirs(DIR) | 
 | 33 |  | 
 | 34 | def pull_file(fn): | 
 | 35 |   print "pull_file: " + fn | 
 | 36 |   rv = os.system("adb pull" | 
 | 37 |     + " /data/data/com.android.launcher/databases/launcher.db" | 
 | 38 |     + " " + fn); | 
 | 39 |   if rv != 0: | 
 | 40 |     print "adb pull failed" | 
 | 41 |     sys.exit(1) | 
 | 42 |  | 
 | 43 | def push_file(fn): | 
 | 44 |   print "push_file: " + fn | 
 | 45 |   rv = os.system("adb push" | 
 | 46 |     + " " + fn | 
 | 47 |     + " /data/data/com.android.launcher/databases/launcher.db") | 
 | 48 |   if rv != 0: | 
 | 49 |     print "adb push failed" | 
 | 50 |     sys.exit(1) | 
 | 51 |  | 
 | 52 | def process_file(fn): | 
 | 53 |   print "process_file: " + fn | 
 | 54 |   conn = sqlite3.connect(fn) | 
 | 55 |   c = conn.cursor() | 
 | 56 |   c.execute("DELETE FROM favorites") | 
 | 57 |  | 
 | 58 |   intentFormat = "#Intent;action=android.intent.action.MAIN;category=android.intent.category.LAUNCHER;launchFlags=0x10200000;component=%s;end" | 
 | 59 |  | 
 | 60 |   id = 0; | 
 | 61 |   for s in range(SCREENS): | 
 | 62 |     for x in range(ROWS): | 
 | 63 |       for y in range(COLUMNS): | 
 | 64 |         id += 1 | 
 | 65 |         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)" | 
 | 66 |         insert = insert % (id, "title", "", -100, s, x, y, 1, 1, 2, -1, 0) | 
 | 67 |         c.execute(insert) | 
 | 68 |         folder_id = id | 
 | 69 |  | 
 | 70 |         for z in range(15): | 
 | 71 |           id += 1 | 
 | 72 |           intent = intentFormat % (APPLICATION_COMPONENTS[id % len(APPLICATION_COMPONENTS)]) | 
 | 73 |           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)" | 
 | 74 |           insert = insert % (id, "title", intent, folder_id, 0, 0, 0, 1, 1, 0, -1, 0) | 
 | 75 |           c.execute(insert) | 
 | 76 |  | 
 | 77 |   conn.commit() | 
 | 78 |   c.close() | 
 | 79 |  | 
 | 80 | def main(argv): | 
 | 81 |   if len(argv) == 1: | 
 | 82 |     make_dir() | 
 | 83 |     pull_file(AUTO_FILE) | 
 | 84 |     process_file(AUTO_FILE) | 
 | 85 |     push_file(AUTO_FILE) | 
 | 86 |   else: | 
 | 87 |     usage() | 
 | 88 |  | 
 | 89 | if __name__=="__main__": | 
 | 90 |   main(sys.argv) |