blob: a88779261e0db836d0d8adb45b7ff667562b15c6 [file] [log] [blame]
Adam Cohen1982c4b2011-08-25 13:49:43 -07001#!/usr/bin/env python2.5
2
3import cgi
4import os
5import shutil
6import sys
7import sqlite3
8
9SCREENS = 5
10COLUMNS = 4
11ROWS = 4
12CELL_SIZE = 110
13
14DIR = "db_files"
15AUTO_FILE = "launcher.db"
16
17APPLICATION_COMPONENTS = [
Adam Cohen1982c4b2011-08-25 13:49:43 -070018 "com.android.calculator2/com.android.calculator2.Calculator",
Adam Cohen1982c4b2011-08-25 13:49:43 -070019 "com.android.providers.downloads.ui/com.android.providers.downloads.ui.DownloadList",
Michael Jurkab964f9c2011-09-27 22:10:05 -070020 "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 Chengf043f802012-08-21 13:35:10 -070023 "com.android.dialer/com.android.dialer.DialtactsActivity"
Adam Cohen1982c4b2011-08-25 13:49:43 -070024]
25
26def usage():
27 print "usage: fill_screens.py -- fills up the launcher db"
28
29
30def make_dir():
31 shutil.rmtree(DIR, True)
32 os.makedirs(DIR)
33
34def 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
43def 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
52def 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
80def 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
89if __name__=="__main__":
90 main(sys.argv)