OSDN Git Service

merge in ics-release history after reset to master
[android-x86/packages-apps-Trebuchet.git] / fill_screens.py
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 = [
18   "com.google.android.apps.books/com.google.android.apps.books.app.BooksActivity",
19   "com.android.calculator2/com.android.calculator2.Calculator",
20   "com.google.android.camera/com.android.camera.Camera",
21   "com.google.android.carhome/com.google.android.carhome.CarHome",
22   "com.android.providers.downloads.ui/com.android.providers.downloads.ui.DownloadList",
23   "com.google.android.gallery3d/com.android.gallery3d.app.Gallery",
24   "com.google.android.apps.maps/com.google.android.maps.MapsActivity"
25 ]
26
27 def usage():
28   print "usage: fill_screens.py -- fills up the launcher db"
29
30
31 def make_dir():
32   shutil.rmtree(DIR, True)
33   os.makedirs(DIR)
34
35 def pull_file(fn):
36   print "pull_file: " + fn
37   rv = os.system("adb pull"
38     + " /data/data/com.android.launcher/databases/launcher.db"
39     + " " + fn);
40   if rv != 0:
41     print "adb pull failed"
42     sys.exit(1)
43
44 def push_file(fn):
45   print "push_file: " + fn
46   rv = os.system("adb push"
47     + " " + fn
48     + " /data/data/com.android.launcher/databases/launcher.db")
49   if rv != 0:
50     print "adb push failed"
51     sys.exit(1)
52
53 def process_file(fn):
54   print "process_file: " + fn
55   conn = sqlite3.connect(fn)
56   c = conn.cursor()
57   c.execute("DELETE FROM favorites")
58
59   intentFormat = "#Intent;action=android.intent.action.MAIN;category=android.intent.category.LAUNCHER;launchFlags=0x10200000;component=%s;end"
60
61   id = 0;
62   for s in range(SCREENS):
63     for x in range(ROWS):
64       for y in range(COLUMNS):
65         id += 1
66         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)"
67         insert = insert % (id, "title", "", -100, s, x, y, 1, 1, 2, -1, 0)
68         c.execute(insert)
69         folder_id = id
70
71         for z in range(15):
72           id += 1
73           intent = intentFormat % (APPLICATION_COMPONENTS[id % len(APPLICATION_COMPONENTS)])
74           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)"
75           insert = insert % (id, "title", intent, folder_id, 0, 0, 0, 1, 1, 0, -1, 0)
76           c.execute(insert)
77
78   conn.commit()
79   c.close()
80
81 def main(argv):
82   if len(argv) == 1:
83     make_dir()
84     pull_file(AUTO_FILE)
85     process_file(AUTO_FILE)
86     push_file(AUTO_FILE)
87   else:
88     usage()
89
90 if __name__=="__main__":
91   main(sys.argv)