Merge lp:~boiko/telephony-service/rtm-fix_multiple_ofono_accounts into lp:telephony-service/rtm-14.09

Proposed by Gustavo Pichorim Boiko
Status: Merged
Approved by: Gustavo Pichorim Boiko
Approved revision: 946
Merged at revision: 946
Proposed branch: lp:~boiko/telephony-service/rtm-fix_multiple_ofono_accounts
Merge into: lp:telephony-service/rtm-14.09
Diff against target: 158 lines (+113/-28)
1 file modified
tools/ofono-setup (+113/-28)
To merge this branch: bzr merge lp:~boiko/telephony-service/rtm-fix_multiple_ofono_accounts
Reviewer Review Type Date Requested Status
Gustavo Pichorim Boiko (community) Approve
Review via email: mp+256936@code.launchpad.net

Commit message

Add sanity check to ofono-setup.

Description of the change

Add sanity check to ofono-setup.

To post a comment you must log in.
Revision history for this message
Gustavo Pichorim Boiko (boiko) wrote :

Code cherry-picked from vivid and already reviewed there. Approving MR.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'tools/ofono-setup'
2--- tools/ofono-setup 2015-02-10 17:39:57 +0000
3+++ tools/ofono-setup 2015-04-21 13:49:28 +0000
4@@ -1,41 +1,126 @@
5 #!/bin/sh
6
7+get_telepathy_ofono_accounts()
8+{
9+ mc-tool list | grep "^ofono/ofono/" | sort
10+}
11+
12+check_mission_control_running() {
13+ # "mc-tool list" returns failure when no accounts are found, so we
14+ # check if mission control is running via dbus directly
15+ dbus-send --print-reply --reply-timeout=2000 --session --dest=org.freedesktop.Telepathy.AccountManager /org/freedesktop/Telepathy/AccountManager org.freedesktop.DBus.Properties.GetAll string:org.freedesktop.Telepathy.AccountManager | grep ValidAccounts 2>&1 > /dev/null
16+}
17+
18+get_modem_objpath_for_account() {
19+ echo "$(mc-tool show $1 | sed -n 's,.*modem-objpath = \(.*\)$,\1,p')"
20+}
21+
22+existing_account_for_modem_objpath() {
23+ modem_obj_path=$1
24+ for account in $EXISTING_OFONO_ACCOUNTS; do
25+ if [ "$(get_modem_objpath_for_account $account)" = "$modem_obj_path" ]; then
26+ echo "$account"
27+ fi
28+ done
29+}
30+
31 # do not wait for a network connection to launch the connection managers
32 dconf write /org/gnome/empathy/use-conn false 2>&1 > /dev/null
33
34-# check if there is a tp-ofono account already
35-# for now assume that if there is at least one account, the system is properly configured.
36-mc-tool show ofono/ofono/account0 2>&1 > /dev/null
37-
38-# if there is not, create accounts and enable them
39-if [ $? -eq 1 ]; then
40- # check if there is at least one modem
41- if [ "$(getprop rild.libpath '')" == "" ]; then
42- exit 0
43- fi
44- LAST_MODEM="`expr $(getprop ril.num_slots 1) - 1`"
45- # get the translated default sim card name from the telephony-service po files.
46- SIM_NAME=$(gettext -d telephony-service "SIM %1")
47- GSETTINGS_ARRAY="{"
48-
49- # and for each modem found create a telepathy account
50- for INDEX in $(seq 0 $LAST_MODEM); do
51+retries=0
52+# make sure telepathy is correctly running before we setup the accounts
53+while ! check_mission_control_running; do
54+ retries=$((retries+1))
55+ echo "can't connect to mission-control via dbus, retrying $retries"
56+ if [ "$retries" -eq "10" ]; then
57+ echo "maximum retries reached, aborting"
58+ exit 1
59+ fi
60+ sleep 1
61+done
62+
63+EXISTING_OFONO_ACCOUNTS=$(get_telepathy_ofono_accounts)
64+
65+# iterate over all accounts to find duplicates
66+for account in $EXISTING_OFONO_ACCOUNTS; do
67+ remove=0
68+ modem_obj_path=$(get_modem_objpath_for_account $account)
69+ if [ -e $modem_obj_path ]; then
70+ # skip accounts with empty modem-objpath if any
71+ echo "account with empty modem-objpath found, removing it: $account"
72+ mc-tool remove $account 2>&1 > /dev/null
73+ continue
74+ fi
75+ for account2 in $EXISTING_OFONO_ACCOUNTS; do
76+ # ignore if same account and set flag to remove next ones
77+ if [ "$account" = "$account2" ]; then
78+ remove=1
79+ continue;
80+ fi
81+ # check if this account was not removed already by this loop
82+ mc-tool show $account2 2>&1 > /dev/null
83+ if [ $? = 1 ]; then
84+ continue
85+ fi
86+ # check if modem-objpath is repeated
87+ if [ "$(get_modem_objpath_for_account $account2)" = "$modem_obj_path" ]; then
88+ echo "found duplicate account: $account2 modem: $modem_obj_path"
89+ mc-tool remove $account2 2>&1 > /dev/null
90+ fi
91+ done
92+done
93+
94+# refresh account list after duplicates are removed
95+EXISTING_OFONO_ACCOUNTS=$(get_telepathy_ofono_accounts)
96+EXISTING_OFONO_ACCOUNTS_COUNT=$(get_telepathy_ofono_accounts | wc -l)
97+MODEM_COUNT=0
98+
99+# check if there is at least one modem
100+if [ "$(getprop rild.libpath '')" != "" ]; then
101+ MODEM_COUNT=$(getprop ril.num_slots 1)
102+fi
103+
104+if [ "$MODEM_COUNT" != "$EXISTING_OFONO_ACCOUNTS_COUNT" ]; then
105+ echo "modem count: $MODEM_COUNT"
106+ echo "existing ofono accounts: $EXISTING_OFONO_ACCOUNTS_COUNT"
107+ GSETTINGS_ARRAY="{"
108+
109+ LAST_MODEM_INDEX="`expr $MODEM_COUNT - 1`"
110+ # check if all modems belong to at least one existing account
111+ for INDEX in $(seq 0 $LAST_MODEM_INDEX); do
112+ MODEM_OBJPATH=/ril_$INDEX
113+
114+ # get previous name from gsettings if any
115+ EXISTING_NAME=$(python3 -c "array=$(gsettings get com.ubuntu.phone sim-names); print (array[\"$MODEM_OBJPATH\"])")
116+ if [ -n "$EXISTING_NAME" ]; then
117+ NAME=$EXISTING_NAME
118+ else
119+ SIM_NAME=$(gettext -d telephony-service "SIM %1")
120+ # replace the %1 with the actual index
121+ NAME=$(echo $SIM_NAME | sed "s/%1$/$(($INDEX+1))/")
122+ fi
123+
124+ if [ "" = "$(existing_account_for_modem_objpath $MODEM_OBJPATH)" ]; then
125+ echo "no account found for modem $MODEM_OBJPATH"
126 ACCOUNT="account$INDEX"
127 echo "creating ofono/ofono/$ACCOUNT"
128- mc-tool add ofono/ofono $ACCOUNT string:modem-objpath=/ril_$INDEX
129+ mc-tool add ofono/ofono $ACCOUNT string:modem-objpath=$MODEM_OBJPATH
130 echo "enabling ofono/ofono/$ACCOUNT"
131 mc-tool enable ofono/ofono/$ACCOUNT
132 mc-tool auto-connect ofono/ofono/$ACCOUNT
133- # replace the %1 with the actual index
134- NAME=$(echo $SIM_NAME | sed "s/%1$/$(($INDEX+1))/")
135 mc-tool display ofono/ofono/$ACCOUNT "$NAME"
136 # append this entry to the gsettings array
137- GSETTINGS_ARRAY="$GSETTINGS_ARRAY '/ril_$INDEX': '$NAME',"
138- done
139- # remove the last "," if present
140- GSETTINGS_ARRAY="$(echo $GSETTINGS_ARRAY | sed 's/,$//g')}"
141- # set names in gsettings
142- gsettings set com.ubuntu.phone sim-names "$GSETTINGS_ARRAY"
143+ GSETTINGS_ARRAY="$GSETTINGS_ARRAY '$MODEM_OBJPATH': '$NAME',"
144+ else
145+ echo "account found for modem $MODEM_OBJPATH"
146+ # this account already exists, just take the name from gsettings
147+ GSETTINGS_ARRAY="$GSETTINGS_ARRAY '$MODEM_OBJPATH': '$NAME',"
148+ fi
149+ done
150+ # remove the last "," if present
151+ GSETTINGS_ARRAY="$(echo $GSETTINGS_ARRAY | sed 's/,$//g')}"
152+ # set names in gsettings
153+ gsettings set com.ubuntu.phone sim-names "$GSETTINGS_ARRAY"
154+else
155+ echo "sanity check passed"
156 fi
157-
158-echo 'ofono accounts initialized'

Subscribers

People subscribed via source and target branches