-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
contactsproviderutils.sh
83 lines (67 loc) · 2.06 KB
/
contactsproviderutils.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# Shell utility functions for contactsprovider developers.
# sudo apt-get install rlwrap to have a more fully featured sqlite CLI
# sudo apt-get install sqlitebrowser to explore the database with GUI
CONTACTS_DB="contacts2.db"
function contacts-pull () {
adb root && adb wait-for-device
dir=$(get-dir $1)
package=$(get-package)
if [ -f "$dir/$CONTACTS_DB" ]; then
rm "$dir/$CONTACTS_DB"
fi
if [ -f "$dir/$CONTACTS_DB-wal" ]; then
rm "$dir/$CONTACTS_DB-wal"
fi
adb pull /data/user/0/$package/databases/$CONTACTS_DB $dir/$CONTACTS_DB
adb pull /data/user/0/$package/databases/$CONTACTS_DB-wal $dir/$CONTACTS_DB-wal
}
function get-dir (){
if [ -z "$1" ]
then
dir=$(pwd)
else
dir=$1
fi
echo "$dir"
}
function sqlite3-pull () {
dir="$(get-dir $1)"
contacts-pull $dir
rlwrap sqlite3 $dir/$CONTACTS_DB
}
function sqlitebrowser-pull () {
dir="$(get-dir $1)"
contacts-pull $dir
sqlitebrowser $dir/$CONTACTS_DB
}
function sqlite3-push () {
adb root && adb wait-for-device
if [ -z "$1" ]
then
dir=$(pwd)
else
dir=$1
fi
package=$(get-package)
adb push $dir/$CONTACTS_DB /data/user/0/$package/databases/$CONTACTS_DB
adb push $dir/$CONTACTS_DB-wal /data/user/0/$package/databases/$CONTACTS_DB-wal
sqlite3-trigger-upgrade
}
function sqlite3-trigger-upgrade () {
package=$(get-package)
# Doesn't actually upgrade the db because db version is hardcoded in code
# It however triggers upgrade path
check_string="/data/user/0/$package/databases/$CONTACTS_DB \"pragma user_version\""
version=$(adb shell sqlite3 $check_string)
echo "Old version: $version"
version=$((version+1))
upgrade_string="/data/user/0/$package/databases/$CONTACTS_DB \"pragma user_version=$version\""
adb shell sqlite3 $upgrade_string
version=$(adb shell sqlite3 $check_string)
echo "New version: $version"
adb shell am force-stop $package
}
function get-package() {
echo "com.android.providers.contacts"
}
set +x # disable debugging