blob: 9607c806884309a38e7f3c859d84137958ff46c7 [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 = [
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
27def usage():
28 print "usage: fill_screens.py -- fills up the launcher db"
29
30
31def make_dir():
32 shutil.rmtree(DIR, True)
33 os.makedirs(DIR)
34
35def 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
44def 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
53def 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
81def 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
90if __name__=="__main__":
91 main(sys.argv)