2010-09-30 08:43:46 +08:00
|
|
|
#!/usr/bin/env python2.5
|
|
|
|
|
|
|
|
import cgi
|
2013-07-13 04:41:18 +08:00
|
|
|
import codecs
|
2010-09-30 08:43:46 +08:00
|
|
|
import os
|
2013-07-13 04:41:18 +08:00
|
|
|
import pprint
|
2015-09-15 02:51:41 +08:00
|
|
|
import re
|
2010-09-30 08:43:46 +08:00
|
|
|
import shutil
|
|
|
|
import sys
|
|
|
|
import sqlite3
|
|
|
|
|
2013-07-13 04:41:18 +08:00
|
|
|
SCREENS = 0
|
2010-09-30 08:43:46 +08:00
|
|
|
COLUMNS = 4
|
|
|
|
ROWS = 4
|
2013-07-13 04:41:18 +08:00
|
|
|
HOTSEAT_SIZE = 4
|
2010-09-30 08:43:46 +08:00
|
|
|
CELL_SIZE = 110
|
|
|
|
|
2013-07-13 04:41:18 +08:00
|
|
|
CONTAINER_DESKTOP = -100
|
|
|
|
CONTAINER_HOTSEAT = -101
|
|
|
|
|
2010-09-30 08:43:46 +08:00
|
|
|
DIR = "db_files"
|
|
|
|
AUTO_FILE = DIR + "/launcher.db"
|
|
|
|
INDEX_FILE = DIR + "/index.html"
|
|
|
|
|
|
|
|
def usage():
|
2015-09-15 02:51:41 +08:00
|
|
|
print "usage: print_db.py launcher.db <4x4|5x5|5x6|...> -- prints a launcher.db with"
|
|
|
|
print " the specified grid size (rows x cols)"
|
|
|
|
print "usage: print_db.py <4x4|5x5|5x6|...> -- adb pulls a launcher.db from a device"
|
|
|
|
print " and prints it with the specified grid size (rows x cols)"
|
2010-09-30 08:43:46 +08:00
|
|
|
print
|
|
|
|
print "The dump will be created in a directory called db_files in cwd."
|
|
|
|
print "This script will delete any db_files directory you have now"
|
|
|
|
|
|
|
|
|
|
|
|
def make_dir():
|
|
|
|
shutil.rmtree(DIR, True)
|
|
|
|
os.makedirs(DIR)
|
|
|
|
|
2013-08-21 05:37:16 +08:00
|
|
|
def adb_root_remount():
|
|
|
|
os.system("adb root")
|
|
|
|
os.system("adb remount")
|
|
|
|
|
2010-09-30 08:43:46 +08:00
|
|
|
def pull_file(fn):
|
|
|
|
print "pull_file: " + fn
|
|
|
|
rv = os.system("adb pull"
|
2015-09-15 02:51:41 +08:00
|
|
|
+ " /data/data/com.android.launcher3/databases/launcher.db"
|
2010-09-30 08:43:46 +08:00
|
|
|
+ " " + fn);
|
|
|
|
if rv != 0:
|
|
|
|
print "adb pull failed"
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
def get_favorites(conn):
|
|
|
|
c = conn.cursor()
|
|
|
|
c.execute("SELECT * FROM favorites")
|
|
|
|
columns = [d[0] for d in c.description]
|
|
|
|
rows = []
|
|
|
|
for row in c:
|
|
|
|
rows.append(row)
|
|
|
|
return columns,rows
|
|
|
|
|
2013-08-21 05:37:16 +08:00
|
|
|
def get_screens(conn):
|
|
|
|
c = conn.cursor()
|
|
|
|
c.execute("SELECT * FROM workspaceScreens")
|
|
|
|
columns = [d[0] for d in c.description]
|
|
|
|
rows = []
|
|
|
|
for row in c:
|
|
|
|
rows.append(row)
|
|
|
|
return columns,rows
|
|
|
|
|
2010-09-30 08:43:46 +08:00
|
|
|
def print_intent(out, id, i, cell):
|
|
|
|
if cell:
|
|
|
|
out.write("""<span class="intent" title="%s">shortcut</span>""" % (
|
|
|
|
cgi.escape(cell, True)
|
|
|
|
))
|
|
|
|
|
|
|
|
|
|
|
|
def print_icon(out, id, i, cell):
|
|
|
|
if cell:
|
|
|
|
icon_fn = "icon_%d.png" % id
|
2013-07-13 04:41:18 +08:00
|
|
|
out.write("""<img style="width: 3em; height: 3em;" src="%s">""" % ( icon_fn ))
|
2010-09-30 08:43:46 +08:00
|
|
|
f = file(DIR + "/" + icon_fn, "w")
|
|
|
|
f.write(cell)
|
|
|
|
f.close()
|
|
|
|
|
2013-07-13 04:41:18 +08:00
|
|
|
def print_icon_type(out, id, i, cell):
|
|
|
|
if cell == 0:
|
|
|
|
out.write("Application (%d)" % cell)
|
|
|
|
elif cell == 1:
|
|
|
|
out.write("Shortcut (%d)" % cell)
|
|
|
|
elif cell == 2:
|
|
|
|
out.write("Folder (%d)" % cell)
|
|
|
|
elif cell == 4:
|
|
|
|
out.write("Widget (%d)" % cell)
|
|
|
|
elif cell:
|
|
|
|
out.write("%d" % cell)
|
|
|
|
|
2010-09-30 08:43:46 +08:00
|
|
|
def print_cell(out, id, i, cell):
|
|
|
|
if not cell is None:
|
2013-07-13 04:41:18 +08:00
|
|
|
out.write(cgi.escape(unicode(cell)))
|
2010-09-30 08:43:46 +08:00
|
|
|
|
|
|
|
FUNCTIONS = {
|
|
|
|
"intent": print_intent,
|
2013-07-13 04:41:18 +08:00
|
|
|
"icon": print_icon,
|
|
|
|
"iconType": print_icon_type
|
2010-09-30 08:43:46 +08:00
|
|
|
}
|
|
|
|
|
2011-08-25 02:32:02 +08:00
|
|
|
def render_cell_info(out, cell, occupied):
|
|
|
|
if cell is None:
|
|
|
|
out.write(" <td width=%d height=%d></td>\n" %
|
|
|
|
(CELL_SIZE, CELL_SIZE))
|
|
|
|
elif cell == occupied:
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
cellX = cell["cellX"]
|
|
|
|
cellY = cell["cellY"]
|
|
|
|
spanX = cell["spanX"]
|
|
|
|
spanY = cell["spanY"]
|
|
|
|
intent = cell["intent"]
|
|
|
|
if intent:
|
|
|
|
title = "title=\"%s\"" % cgi.escape(cell["intent"], True)
|
|
|
|
else:
|
|
|
|
title = ""
|
|
|
|
out.write((" <td colspan=%d rowspan=%d width=%d height=%d"
|
|
|
|
+ " bgcolor=#dddddd align=center valign=middle %s>") % (
|
|
|
|
spanX, spanY,
|
|
|
|
(CELL_SIZE*spanX), (CELL_SIZE*spanY),
|
|
|
|
title))
|
|
|
|
itemType = cell["itemType"]
|
|
|
|
if itemType == 0:
|
2013-07-13 04:41:18 +08:00
|
|
|
out.write("""<img style="width: 4em; height: 4em;" src="icon_%d.png">\n""" % ( cell["_id"] ))
|
2011-08-25 02:32:02 +08:00
|
|
|
out.write("<br/>\n")
|
|
|
|
out.write(cgi.escape(cell["title"]) + " <br/><i>(app)</i>")
|
|
|
|
elif itemType == 1:
|
2013-07-13 04:41:18 +08:00
|
|
|
out.write("""<img style="width: 4em; height: 4em;" src="icon_%d.png">\n""" % ( cell["_id"] ))
|
2011-08-25 02:32:02 +08:00
|
|
|
out.write("<br/>\n")
|
|
|
|
out.write(cgi.escape(cell["title"]) + " <br/><i>(shortcut)</i>")
|
|
|
|
elif itemType == 2:
|
|
|
|
out.write("""<i>folder</i>""")
|
|
|
|
elif itemType == 4:
|
|
|
|
out.write("<i>widget %d</i><br/>\n" % cell["appWidgetId"])
|
|
|
|
else:
|
|
|
|
out.write("<b>unknown type: %d</b>" % itemType)
|
|
|
|
out.write("</td>\n")
|
|
|
|
|
2013-08-21 05:37:16 +08:00
|
|
|
def render_screen_info(out, screen):
|
|
|
|
out.write("<tr>")
|
|
|
|
out.write("<td>%s</td>" % (screen["_id"]))
|
|
|
|
out.write("<td>%s</td>" % (screen["screenRank"]))
|
|
|
|
out.write("</tr>")
|
|
|
|
|
2010-09-30 08:43:46 +08:00
|
|
|
def process_file(fn):
|
2013-07-13 04:41:18 +08:00
|
|
|
global SCREENS, COLUMNS, ROWS, HOTSEAT_SIZE
|
2010-09-30 08:43:46 +08:00
|
|
|
print "process_file: " + fn
|
|
|
|
conn = sqlite3.connect(fn)
|
|
|
|
columns,rows = get_favorites(conn)
|
2013-08-21 05:37:16 +08:00
|
|
|
screenCols, screenRows = get_screens(conn)
|
2013-07-13 04:41:18 +08:00
|
|
|
|
2010-09-30 08:43:46 +08:00
|
|
|
data = [dict(zip(columns,row)) for row in rows]
|
2013-08-21 05:37:16 +08:00
|
|
|
screenData = [dict(zip(screenCols, screenRow)) for screenRow in screenRows]
|
2010-09-30 08:43:46 +08:00
|
|
|
|
2013-07-13 04:41:18 +08:00
|
|
|
# Calculate the proper number of screens, columns, and rows in this db
|
|
|
|
screensIdMap = []
|
|
|
|
hotseatIdMap = []
|
|
|
|
HOTSEAT_SIZE = 0
|
|
|
|
for d in data:
|
2013-08-10 07:06:38 +08:00
|
|
|
if d["spanX"] is None:
|
|
|
|
d["spanX"] = 1
|
|
|
|
if d["spanY"] is None:
|
|
|
|
d["spanY"] = 1
|
2013-07-13 04:41:18 +08:00
|
|
|
if d["container"] == CONTAINER_DESKTOP:
|
|
|
|
if d["screen"] not in screensIdMap:
|
|
|
|
screensIdMap.append(d["screen"])
|
|
|
|
COLUMNS = max(COLUMNS, d["cellX"] + d["spanX"])
|
|
|
|
ROWS = max(ROWS, d["cellX"] + d["spanX"])
|
|
|
|
elif d["container"] == CONTAINER_HOTSEAT:
|
|
|
|
hotseatIdMap.append(d["screen"])
|
|
|
|
HOTSEAT_SIZE = max(HOTSEAT_SIZE, d["screen"] + 1)
|
|
|
|
SCREENS = len(screensIdMap)
|
|
|
|
|
|
|
|
out = codecs.open(INDEX_FILE, encoding="utf-8", mode="w")
|
2010-09-30 08:43:46 +08:00
|
|
|
out.write("""<html>
|
|
|
|
<head>
|
|
|
|
<style type="text/css">
|
|
|
|
.intent {
|
|
|
|
font-style: italic;
|
|
|
|
}
|
|
|
|
</style>
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
""")
|
|
|
|
|
|
|
|
# Data table
|
|
|
|
out.write("<b>Favorites table</b><br/>\n")
|
|
|
|
out.write("""<html>
|
|
|
|
<table border=1 cellspacing=0 cellpadding=4>
|
|
|
|
<tr>
|
|
|
|
""")
|
|
|
|
print_functions = []
|
|
|
|
for col in columns:
|
|
|
|
print_functions.append(FUNCTIONS.get(col, print_cell))
|
|
|
|
for i in range(0,len(columns)):
|
|
|
|
col = columns[i]
|
|
|
|
out.write(""" <th>%s</th>
|
|
|
|
""" % ( col ))
|
|
|
|
out.write("""
|
|
|
|
</tr>
|
|
|
|
""")
|
2013-07-13 04:41:18 +08:00
|
|
|
|
2010-09-30 08:43:46 +08:00
|
|
|
for row in rows:
|
|
|
|
out.write("""<tr>
|
|
|
|
""")
|
|
|
|
for i in range(0,len(row)):
|
|
|
|
cell = row[i]
|
|
|
|
# row[0] is always _id
|
|
|
|
out.write(""" <td>""")
|
|
|
|
print_functions[i](out, row[0], row, cell)
|
|
|
|
out.write("""</td>
|
|
|
|
""")
|
|
|
|
out.write("""</tr>
|
|
|
|
""")
|
|
|
|
out.write("""</table>
|
|
|
|
""")
|
|
|
|
|
2013-08-21 05:37:16 +08:00
|
|
|
# Screens
|
|
|
|
out.write("<br/><b>Screens</b><br/>\n")
|
|
|
|
out.write("<table class=layout border=1 cellspacing=0 cellpadding=4>\n")
|
|
|
|
out.write("<tr><td>Screen ID</td><td>Rank</td></tr>\n")
|
|
|
|
for screen in screenData:
|
|
|
|
render_screen_info(out, screen)
|
|
|
|
out.write("</table>\n")
|
|
|
|
|
2011-08-25 02:32:02 +08:00
|
|
|
# Hotseat
|
|
|
|
hotseat = []
|
|
|
|
for i in range(0, HOTSEAT_SIZE):
|
|
|
|
hotseat.append(None)
|
|
|
|
for row in data:
|
2013-07-13 04:41:18 +08:00
|
|
|
if row["container"] != CONTAINER_HOTSEAT:
|
2011-08-25 02:32:02 +08:00
|
|
|
continue
|
|
|
|
screen = row["screen"]
|
|
|
|
hotseat[screen] = row
|
|
|
|
out.write("<br/><b>Hotseat</b><br/>\n")
|
|
|
|
out.write("<table class=layout border=1 cellspacing=0 cellpadding=4>\n")
|
|
|
|
for cell in hotseat:
|
|
|
|
render_cell_info(out, cell, None)
|
|
|
|
out.write("</table>\n")
|
|
|
|
|
2010-09-30 08:43:46 +08:00
|
|
|
# Pages
|
|
|
|
screens = []
|
|
|
|
for i in range(0,SCREENS):
|
|
|
|
screen = []
|
|
|
|
for j in range(0,ROWS):
|
|
|
|
m = []
|
|
|
|
for k in range(0,COLUMNS):
|
|
|
|
m.append(None)
|
|
|
|
screen.append(m)
|
|
|
|
screens.append(screen)
|
|
|
|
occupied = "occupied"
|
|
|
|
for row in data:
|
|
|
|
# desktop
|
2013-07-13 04:41:18 +08:00
|
|
|
if row["container"] != CONTAINER_DESKTOP:
|
2010-09-30 08:43:46 +08:00
|
|
|
continue
|
2013-07-13 04:41:18 +08:00
|
|
|
screen = screens[screensIdMap.index(row["screen"])]
|
2010-09-30 08:43:46 +08:00
|
|
|
cellX = row["cellX"]
|
|
|
|
cellY = row["cellY"]
|
|
|
|
spanX = row["spanX"]
|
|
|
|
spanY = row["spanY"]
|
|
|
|
for j in range(cellY, cellY+spanY):
|
|
|
|
for k in range(cellX, cellX+spanX):
|
|
|
|
screen[j][k] = occupied
|
|
|
|
screen[cellY][cellX] = row
|
|
|
|
i=0
|
|
|
|
for screen in screens:
|
|
|
|
out.write("<br/><b>Screen %d</b><br/>\n" % i)
|
|
|
|
out.write("<table class=layout border=1 cellspacing=0 cellpadding=4>\n")
|
|
|
|
for m in screen:
|
|
|
|
out.write(" <tr>\n")
|
|
|
|
for cell in m:
|
2011-08-25 02:32:02 +08:00
|
|
|
render_cell_info(out, cell, occupied)
|
2010-09-30 08:43:46 +08:00
|
|
|
out.write("</tr>\n")
|
|
|
|
out.write("</table>\n")
|
|
|
|
i=i+1
|
|
|
|
|
|
|
|
out.write("""
|
|
|
|
</body>
|
|
|
|
</html>
|
|
|
|
""")
|
|
|
|
|
|
|
|
out.close()
|
|
|
|
|
2013-07-13 04:41:18 +08:00
|
|
|
def updateDeviceClassConstants(str):
|
|
|
|
global SCREENS, COLUMNS, ROWS, HOTSEAT_SIZE
|
2015-09-15 02:51:41 +08:00
|
|
|
match = re.search(r"(\d+)x(\d+)", str)
|
|
|
|
if match:
|
|
|
|
COLUMNS = int(match.group(1))
|
|
|
|
ROWS = int(match.group(2))
|
|
|
|
HOTSEAT_SIZE = 2 * int(COLUMNS / 2)
|
2013-07-13 04:41:18 +08:00
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
2010-09-30 08:43:46 +08:00
|
|
|
def main(argv):
|
2013-07-13 04:41:18 +08:00
|
|
|
if len(argv) == 1 or (len(argv) == 2 and updateDeviceClassConstants(argv[1])):
|
2010-09-30 08:43:46 +08:00
|
|
|
make_dir()
|
2013-08-21 05:37:16 +08:00
|
|
|
adb_root_remount()
|
2010-09-30 08:43:46 +08:00
|
|
|
pull_file(AUTO_FILE)
|
|
|
|
process_file(AUTO_FILE)
|
2013-07-13 04:41:18 +08:00
|
|
|
elif len(argv) == 2 or (len(argv) == 3 and updateDeviceClassConstants(argv[2])):
|
2010-09-30 08:43:46 +08:00
|
|
|
make_dir()
|
|
|
|
process_file(argv[1])
|
|
|
|
else:
|
|
|
|
usage()
|
|
|
|
|
|
|
|
if __name__=="__main__":
|
|
|
|
main(sys.argv)
|