1 #!/usr/bin/env python2.5
18 CONTAINER_DESKTOP = -100
19 CONTAINER_HOTSEAT = -101
22 AUTO_FILE = DIR + "/launcher.db"
23 INDEX_FILE = DIR + "/index.html"
26 print "usage: print_db.py launcher.db <4x4|5x5|5x6|...> -- prints a launcher.db with"
27 print " the specified grid size (rows x cols)"
28 print "usage: print_db.py <4x4|5x5|5x6|...> -- adb pulls a launcher.db from a device"
29 print " and prints it with the specified grid size (rows x cols)"
31 print "The dump will be created in a directory called db_files in cwd."
32 print "This script will delete any db_files directory you have now"
36 shutil.rmtree(DIR, True)
39 def adb_root_remount():
41 os.system("adb remount")
44 print "pull_file: " + fn
45 rv = os.system("adb pull"
46 + " /data/data/com.android.launcher3/databases/launcher.db"
49 print "adb pull failed"
52 def get_favorites(conn):
54 c.execute("SELECT * FROM favorites")
55 columns = [d[0] for d in c.description]
61 def get_screens(conn):
63 c.execute("SELECT * FROM workspaceScreens")
64 columns = [d[0] for d in c.description]
70 def print_intent(out, id, i, cell):
72 out.write("""<span class="intent" title="%s">shortcut</span>""" % (
73 cgi.escape(cell, True)
77 def print_icon(out, id, i, cell):
79 icon_fn = "icon_%d.png" % id
80 out.write("""<img style="width: 3em; height: 3em;" src="%s">""" % ( icon_fn ))
81 f = file(DIR + "/" + icon_fn, "w")
85 def print_icon_type(out, id, i, cell):
87 out.write("Application (%d)" % cell)
89 out.write("Shortcut (%d)" % cell)
91 out.write("Folder (%d)" % cell)
93 out.write("Widget (%d)" % cell)
95 out.write("%d" % cell)
97 def print_cell(out, id, i, cell):
99 out.write(cgi.escape(unicode(cell)))
102 "intent": print_intent,
104 "iconType": print_icon_type
107 def render_cell_info(out, cell, occupied):
109 out.write(" <td width=%d height=%d></td>\n" %
110 (CELL_SIZE, CELL_SIZE))
111 elif cell == occupied:
114 cellX = cell["cellX"]
115 cellY = cell["cellY"]
116 spanX = cell["spanX"]
117 spanY = cell["spanY"]
118 intent = cell["intent"]
120 title = "title=\"%s\"" % cgi.escape(cell["intent"], True)
123 out.write((" <td colspan=%d rowspan=%d width=%d height=%d"
124 + " bgcolor=#dddddd align=center valign=middle %s>") % (
126 (CELL_SIZE*spanX), (CELL_SIZE*spanY),
128 itemType = cell["itemType"]
130 out.write("""<img style="width: 4em; height: 4em;" src="icon_%d.png">\n""" % ( cell["_id"] ))
132 out.write(cgi.escape(cell["title"]) + " <br/><i>(app)</i>")
134 out.write("""<img style="width: 4em; height: 4em;" src="icon_%d.png">\n""" % ( cell["_id"] ))
136 out.write(cgi.escape(cell["title"]) + " <br/><i>(shortcut)</i>")
138 out.write("""<i>folder</i>""")
140 out.write("<i>widget %d</i><br/>\n" % cell["appWidgetId"])
142 out.write("<b>unknown type: %d</b>" % itemType)
145 def render_screen_info(out, screen):
147 out.write("<td>%s</td>" % (screen["_id"]))
148 out.write("<td>%s</td>" % (screen["screenRank"]))
151 def process_file(fn):
152 global SCREENS, COLUMNS, ROWS, HOTSEAT_SIZE
153 print "process_file: " + fn
154 conn = sqlite3.connect(fn)
155 columns,rows = get_favorites(conn)
156 screenCols, screenRows = get_screens(conn)
158 data = [dict(zip(columns,row)) for row in rows]
159 screenData = [dict(zip(screenCols, screenRow)) for screenRow in screenRows]
161 # Calculate the proper number of screens, columns, and rows in this db
166 if d["spanX"] is None:
168 if d["spanY"] is None:
170 if d["container"] == CONTAINER_DESKTOP:
171 if d["screen"] not in screensIdMap:
172 screensIdMap.append(d["screen"])
173 COLUMNS = max(COLUMNS, d["cellX"] + d["spanX"])
174 ROWS = max(ROWS, d["cellX"] + d["spanX"])
175 elif d["container"] == CONTAINER_HOTSEAT:
176 hotseatIdMap.append(d["screen"])
177 HOTSEAT_SIZE = max(HOTSEAT_SIZE, d["screen"] + 1)
178 SCREENS = len(screensIdMap)
180 out = codecs.open(INDEX_FILE, encoding="utf-8", mode="w")
183 <style type="text/css">
193 out.write("<b>Favorites table</b><br/>\n")
195 <table border=1 cellspacing=0 cellpadding=4>
200 print_functions.append(FUNCTIONS.get(col, print_cell))
201 for i in range(0,len(columns)):
203 out.write(""" <th>%s</th>
212 for i in range(0,len(row)):
214 # row[0] is always _id
215 out.write(""" <td>""")
216 print_functions[i](out, row[0], row, cell)
221 out.write("""</table>
225 out.write("<br/><b>Screens</b><br/>\n")
226 out.write("<table class=layout border=1 cellspacing=0 cellpadding=4>\n")
227 out.write("<tr><td>Screen ID</td><td>Rank</td></tr>\n")
228 for screen in screenData:
229 render_screen_info(out, screen)
230 out.write("</table>\n")
234 for i in range(0, HOTSEAT_SIZE):
237 if row["container"] != CONTAINER_HOTSEAT:
239 screen = row["screen"]
240 hotseat[screen] = row
241 out.write("<br/><b>Hotseat</b><br/>\n")
242 out.write("<table class=layout border=1 cellspacing=0 cellpadding=4>\n")
244 render_cell_info(out, cell, None)
245 out.write("</table>\n")
249 for i in range(0,SCREENS):
251 for j in range(0,ROWS):
253 for k in range(0,COLUMNS):
256 screens.append(screen)
257 occupied = "occupied"
260 if row["container"] != CONTAINER_DESKTOP:
262 screen = screens[screensIdMap.index(row["screen"])]
267 for j in range(cellY, cellY+spanY):
268 for k in range(cellX, cellX+spanX):
269 screen[j][k] = occupied
270 screen[cellY][cellX] = row
272 for screen in screens:
273 out.write("<br/><b>Screen %d</b><br/>\n" % i)
274 out.write("<table class=layout border=1 cellspacing=0 cellpadding=4>\n")
278 render_cell_info(out, cell, occupied)
280 out.write("</table>\n")
290 def updateDeviceClassConstants(str):
291 global SCREENS, COLUMNS, ROWS, HOTSEAT_SIZE
292 match = re.search(r"(\d+)x(\d+)", str)
294 COLUMNS = int(match.group(1))
295 ROWS = int(match.group(2))
296 HOTSEAT_SIZE = 2 * int(COLUMNS / 2)
301 if len(argv) == 1 or (len(argv) == 2 and updateDeviceClassConstants(argv[1])):
305 process_file(AUTO_FILE)
306 elif len(argv) == 2 or (len(argv) == 3 and updateDeviceClassConstants(argv[2])):
308 process_file(argv[1])
312 if __name__=="__main__":