1 #!/usr/bin/env python2.5
17 CONTAINER_DESKTOP = -100
18 CONTAINER_HOTSEAT = -101
21 AUTO_FILE = DIR + "/launcher.db"
22 INDEX_FILE = DIR + "/index.html"
25 print "usage: print_db.py launcher.db <sw600|sw720> -- prints a launcher.db"
26 print "usage: print_db.py <sw600|sw720> -- adb pulls a launcher.db from a device"
27 print " and prints it"
29 print "The dump will be created in a directory called db_files in cwd."
30 print "This script will delete any db_files directory you have now"
34 shutil.rmtree(DIR, True)
37 def adb_root_remount():
39 os.system("adb remount")
42 print "pull_file: " + fn
43 rv = os.system("adb pull"
44 + " /data/data/com.google.android.googlequicksearchbox/databases/launcher.db"
47 print "adb pull failed"
50 def get_favorites(conn):
52 c.execute("SELECT * FROM favorites")
53 columns = [d[0] for d in c.description]
59 def get_screens(conn):
61 c.execute("SELECT * FROM workspaceScreens")
62 columns = [d[0] for d in c.description]
68 def print_intent(out, id, i, cell):
70 out.write("""<span class="intent" title="%s">shortcut</span>""" % (
71 cgi.escape(cell, True)
75 def print_icon(out, id, i, cell):
77 icon_fn = "icon_%d.png" % id
78 out.write("""<img style="width: 3em; height: 3em;" src="%s">""" % ( icon_fn ))
79 f = file(DIR + "/" + icon_fn, "w")
83 def print_icon_type(out, id, i, cell):
85 out.write("Application (%d)" % cell)
87 out.write("Shortcut (%d)" % cell)
89 out.write("Folder (%d)" % cell)
91 out.write("Widget (%d)" % cell)
93 out.write("%d" % cell)
95 def print_cell(out, id, i, cell):
97 out.write(cgi.escape(unicode(cell)))
100 "intent": print_intent,
102 "iconType": print_icon_type
105 def render_cell_info(out, cell, occupied):
107 out.write(" <td width=%d height=%d></td>\n" %
108 (CELL_SIZE, CELL_SIZE))
109 elif cell == occupied:
112 cellX = cell["cellX"]
113 cellY = cell["cellY"]
114 spanX = cell["spanX"]
115 spanY = cell["spanY"]
116 intent = cell["intent"]
118 title = "title=\"%s\"" % cgi.escape(cell["intent"], True)
121 out.write((" <td colspan=%d rowspan=%d width=%d height=%d"
122 + " bgcolor=#dddddd align=center valign=middle %s>") % (
124 (CELL_SIZE*spanX), (CELL_SIZE*spanY),
126 itemType = cell["itemType"]
128 out.write("""<img style="width: 4em; height: 4em;" src="icon_%d.png">\n""" % ( cell["_id"] ))
130 out.write(cgi.escape(cell["title"]) + " <br/><i>(app)</i>")
132 out.write("""<img style="width: 4em; height: 4em;" src="icon_%d.png">\n""" % ( cell["_id"] ))
134 out.write(cgi.escape(cell["title"]) + " <br/><i>(shortcut)</i>")
136 out.write("""<i>folder</i>""")
138 out.write("<i>widget %d</i><br/>\n" % cell["appWidgetId"])
140 out.write("<b>unknown type: %d</b>" % itemType)
143 def render_screen_info(out, screen):
145 out.write("<td>%s</td>" % (screen["_id"]))
146 out.write("<td>%s</td>" % (screen["screenRank"]))
149 def process_file(fn):
150 global SCREENS, COLUMNS, ROWS, HOTSEAT_SIZE
151 print "process_file: " + fn
152 conn = sqlite3.connect(fn)
153 columns,rows = get_favorites(conn)
154 screenCols, screenRows = get_screens(conn)
156 data = [dict(zip(columns,row)) for row in rows]
157 screenData = [dict(zip(screenCols, screenRow)) for screenRow in screenRows]
159 # Calculate the proper number of screens, columns, and rows in this db
164 if d["spanX"] is None:
166 if d["spanY"] is None:
168 if d["container"] == CONTAINER_DESKTOP:
169 if d["screen"] not in screensIdMap:
170 screensIdMap.append(d["screen"])
171 COLUMNS = max(COLUMNS, d["cellX"] + d["spanX"])
172 ROWS = max(ROWS, d["cellX"] + d["spanX"])
173 elif d["container"] == CONTAINER_HOTSEAT:
174 hotseatIdMap.append(d["screen"])
175 HOTSEAT_SIZE = max(HOTSEAT_SIZE, d["screen"] + 1)
176 SCREENS = len(screensIdMap)
178 out = codecs.open(INDEX_FILE, encoding="utf-8", mode="w")
181 <style type="text/css">
191 out.write("<b>Favorites table</b><br/>\n")
193 <table border=1 cellspacing=0 cellpadding=4>
198 print_functions.append(FUNCTIONS.get(col, print_cell))
199 for i in range(0,len(columns)):
201 out.write(""" <th>%s</th>
210 for i in range(0,len(row)):
212 # row[0] is always _id
213 out.write(""" <td>""")
214 print_functions[i](out, row[0], row, cell)
219 out.write("""</table>
223 out.write("<br/><b>Screens</b><br/>\n")
224 out.write("<table class=layout border=1 cellspacing=0 cellpadding=4>\n")
225 out.write("<tr><td>Screen ID</td><td>Rank</td></tr>\n")
226 for screen in screenData:
227 render_screen_info(out, screen)
228 out.write("</table>\n")
232 for i in range(0, HOTSEAT_SIZE):
235 if row["container"] != CONTAINER_HOTSEAT:
237 screen = row["screen"]
238 hotseat[screen] = row
239 out.write("<br/><b>Hotseat</b><br/>\n")
240 out.write("<table class=layout border=1 cellspacing=0 cellpadding=4>\n")
242 render_cell_info(out, cell, None)
243 out.write("</table>\n")
247 for i in range(0,SCREENS):
249 for j in range(0,ROWS):
251 for k in range(0,COLUMNS):
254 screens.append(screen)
255 occupied = "occupied"
258 if row["container"] != CONTAINER_DESKTOP:
260 screen = screens[screensIdMap.index(row["screen"])]
265 for j in range(cellY, cellY+spanY):
266 for k in range(cellX, cellX+spanX):
267 screen[j][k] = occupied
268 screen[cellY][cellX] = row
270 for screen in screens:
271 out.write("<br/><b>Screen %d</b><br/>\n" % i)
272 out.write("<table class=layout border=1 cellspacing=0 cellpadding=4>\n")
276 render_cell_info(out, cell, occupied)
278 out.write("</table>\n")
288 def updateDeviceClassConstants(str):
289 global SCREENS, COLUMNS, ROWS, HOTSEAT_SIZE
290 devClass = str.lower()
291 if devClass == "sw600":
296 elif devClass == "sw720":
304 if len(argv) == 1 or (len(argv) == 2 and updateDeviceClassConstants(argv[1])):
308 process_file(AUTO_FILE)
309 elif len(argv) == 2 or (len(argv) == 3 and updateDeviceClassConstants(argv[2])):
311 process_file(argv[1])
315 if __name__=="__main__":