Merge lp:~tiagosh/telephony-service/sim-lock into lp:telephony-service

Proposed by Tiago Salem Herrmann
Status: Merged
Approved by: Gustavo Pichorim Boiko
Approved revision: 946
Merged at revision: 947
Proposed branch: lp:~tiagosh/telephony-service/sim-lock
Merge into: lp:telephony-service
Diff against target: 264 lines (+122/-4)
7 files modified
indicator/textchannelobserver.cpp (+89/-2)
indicator/textchannelobserver.h (+1/-0)
libtelephonyservice/accountentry.cpp (+15/-1)
libtelephonyservice/accountentry.h (+3/-0)
libtelephonyservice/chatmanager.cpp (+5/-1)
libtelephonyservice/telepathyhelper.cpp (+8/-0)
libtelephonyservice/telepathyhelper.h (+1/-0)
To merge this branch: bzr merge lp:~tiagosh/telephony-service/sim-lock
Reviewer Review Type Date Requested Status
Gustavo Pichorim Boiko (community) Approve
PS Jenkins bot continuous-integration Approve
Review via email: mp+235505@code.launchpad.net

Commit message

Add simLocked() property to AccountEntry.

Description of the change

Add simLocked() property to AccountEntry.

--Checklist--
Are there any related MPs required for this MP to build/function as expected? Please list.
https://code.launchpad.net/~tiagosh/telepathy-ofono/sim-lock/+merge/235506

Is your branch in sync with latest trunk (e.g. bzr pull lp:trunk -> no changes)
Yes

Did you perform an exploratory manual test run of your code change and any related functionality on device or emulator?
Yes

Did you successfully run all tests found in your component's Test Plan (https://wiki.ubuntu.com/Process/Merges/TestPlan/telephony-service) on device or emulator?
Yes

If you changed the UI, was the change specified/approved by design?
N/A

If you changed UI labels, did you update the pot file?
Will be done later.

If you changed the packaging (debian), did you add a core-dev as a reviewer to this MP?
N/A

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
943. By Tiago Salem Herrmann

use status() instead of statusMessage()

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
944. By Tiago Salem Herrmann

add method to invoke the dialog to unlock sim cards

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
945. By Tiago Salem Herrmann

fix return type

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
946. By Tiago Salem Herrmann

ad failed messages to the history-service and notify users
about the failure

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Gustavo Pichorim Boiko (boiko) wrote :

Did you perform an exploratory manual test run of the code change and any related functionality on device or emulator?
Yes

Did CI run pass? If not, please explain why.
Yes

Have you checked that submitter has accurately filled out the submitter checklist and has taken no shortcut?
Yes

Code looks good and works as expected!

review: Approve
947. By Tiago Salem Herrmann

prevent empty accountId's

948. By Tiago Salem Herrmann

use cancel icon

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'indicator/textchannelobserver.cpp'
2--- indicator/textchannelobserver.cpp 2014-09-17 20:17:39 +0000
3+++ indicator/textchannelobserver.cpp 2014-10-07 16:32:37 +0000
4@@ -58,6 +58,7 @@
5 QString eventId;
6 QString alias;
7 QString message;
8+ TextChannelObserver *observer;
9 QMap<NotifyNotification*, NotificationData*> *notificationList;
10 };
11
12@@ -70,7 +71,7 @@
13 qDebug() << accountId << data;
14 NotificationData *notificationData = (NotificationData*) data;
15 if (notificationData != NULL) {
16- ChatManager::instance()->sendMessage(QStringList() << notificationData->phoneNumber, notificationData->text, accountId);
17+ notificationData->observer->sendMessage(QStringList() << notificationData->phoneNumber, notificationData->text, accountId);
18 }
19
20 notify_notification_close(notification, &error);
21@@ -161,6 +162,91 @@
22 mNotifications.clear();
23 }
24
25+void TextChannelObserver::sendMessage(const QStringList &phoneNumbers, const QString &text, const QString &accountId)
26+{
27+ AccountEntry *account = TelepathyHelper::instance()->accountForId(accountId);
28+ if (!account || accountId.isEmpty()) {
29+ // fallback to the default account
30+ if (TelepathyHelper::instance()->defaultMessagingAccount() && TelepathyHelper::instance()->accounts().size() > 1) {
31+ account = TelepathyHelper::instance()->defaultMessagingAccount();
32+ } else if (TelepathyHelper::instance()->accounts().size() > 0) {
33+ account = TelepathyHelper::instance()->accounts()[0];
34+ }
35+ }
36+
37+ if (!account) {
38+ // we could not find any account, but in theory this case can never happen
39+ return;
40+ }
41+
42+ // check if the account is available
43+ if (!account->connected()) {
44+ History::Thread thread = History::Manager::instance()->threadForParticipants(account->accountId(),
45+ History::EventTypeText,
46+ phoneNumbers,
47+ History::MatchPhoneNumber,
48+ true);
49+ History::TextEvent textEvent(account->accountId(),
50+ thread.threadId(),
51+ QByteArray(QDateTime::currentDateTime().toString("yyyy-MM-ddTHH:mm:ss.zzz").toUtf8()).toHex(),
52+ "self",
53+ QDateTime::currentDateTime(),
54+ false,
55+ text,
56+ History::MessageTypeText,
57+ History::MessageStatusPermanentlyFailed);
58+ History::Events events;
59+ events.append(textEvent);
60+
61+ History::Manager::instance()->writeEvents(events);
62+
63+ QString failureMessage;
64+ if (account->simLocked()) {
65+ failureMessage = C::gettext("Unlock your sim card and try again from the messaging application.");
66+ } else if (TelepathyHelper::instance()->flightMode()) {
67+ failureMessage = C::gettext("Deactivate flight mode and try again from the messaging application.");
68+ } else {
69+ // generic error
70+ failureMessage = C::gettext("Try again from the messaging application.");
71+ }
72+
73+ // notify user about the failure
74+ GIcon *icon = g_themed_icon_new("cancel");
75+ NotifyNotification *notification = notify_notification_new(C::gettext("The message could not be sent"),
76+ failureMessage.toStdString().c_str(),
77+ g_icon_to_string(icon));
78+ NotificationData *data = new NotificationData();
79+ data->phoneNumber = phoneNumbers[0];
80+ data->message = text;
81+ data->notificationList = &mNotifications;
82+ mNotifications.insert(notification, data);
83+
84+ // add the callback action
85+ notify_notification_add_action (notification,
86+ "notification_action",
87+ C::gettext("View message"),
88+ notification_action,
89+ data,
90+ NULL /* will be deleted when closed */);
91+
92+ notify_notification_set_hint_string(notification,
93+ "x-canonical-switch-to-application",
94+ "true");
95+
96+ g_signal_connect(notification, "closed", G_CALLBACK(notification_closed), &mNotifications);
97+
98+ GError *error = NULL;
99+ if (!notify_notification_show(notification, &error)) {
100+ qWarning() << "Failed to show message notification:" << error->message;
101+ g_error_free (error);
102+ }
103+
104+ return;
105+ }
106+
107+ ChatManager::instance()->sendMessage(phoneNumbers, text, accountId);
108+}
109+
110 void TextChannelObserver::showNotificationForFlashMessage(const Tp::ReceivedMessage &message)
111 {
112 Tp::ContactPtr contact = message.sender();
113@@ -420,6 +506,7 @@
114 NotificationData *data = new NotificationData();
115 data->phoneNumber = phoneNumber;
116 data->text = reply;
117+ data->observer = this;
118 mNotifications.insert(notification, data);
119
120 Q_FOREACH(AccountEntry *account, TelepathyHelper::instance()->accounts()) {
121@@ -444,7 +531,7 @@
122 return;
123 }
124
125- ChatManager::instance()->sendMessage(QStringList() << phoneNumber, reply);
126+ sendMessage(QStringList() << phoneNumber, reply, "");
127 }
128
129 void TextChannelObserver::onMessageRead(const QString &phoneNumber, const QString &encodedMessageId)
130
131=== modified file 'indicator/textchannelobserver.h'
132--- indicator/textchannelobserver.h 2014-09-17 19:32:38 +0000
133+++ indicator/textchannelobserver.h 2014-10-07 16:32:37 +0000
134@@ -39,6 +39,7 @@
135
136 public Q_SLOTS:
137 void onTextChannelAvailable(Tp::TextChannelPtr textChannel);
138+ void sendMessage(const QStringList &phoneNumbers, const QString &text, const QString &accountId);
139
140 protected:
141 void showNotificationForMessage(const Tp::ReceivedMessage &message);
142
143=== modified file 'libtelephonyservice/accountentry.cpp'
144--- libtelephonyservice/accountentry.cpp 2014-09-16 15:35:04 +0000
145+++ libtelephonyservice/accountentry.cpp 2014-10-07 16:32:37 +0000
146@@ -55,11 +55,20 @@
147 }
148 Tp::Presence presence = mAccount->connection()->selfContact()->presence();
149 if (presence.type() == Tp::ConnectionPresenceTypeAvailable) {
150- return mAccount->connection()->selfContact()->presence().statusMessage();
151+ return presence.statusMessage();
152 }
153 return QString::null;
154 }
155
156+bool AccountEntry::simLocked() const
157+{
158+ if (mAccount.isNull() || mAccount->connection().isNull() || mAccount->connection()->selfContact().isNull()) {
159+ return false;
160+ }
161+ Tp::Presence presence = mAccount->connection()->selfContact()->presence();
162+ return (presence.type() == Tp::ConnectionPresenceTypeAway && presence.status() == "simlocked");
163+}
164+
165 void AccountEntry::setDisplayName(const QString &name)
166 {
167 if (mAccount.isNull()) {
168@@ -165,6 +174,10 @@
169 connect(mAccount->connection()->selfContact().data(),
170 SIGNAL(presenceChanged(Tp::Presence)),
171 SIGNAL(networkNameChanged()));
172+
173+ connect(mAccount->connection()->selfContact().data(),
174+ SIGNAL(presenceChanged(Tp::Presence)),
175+ SIGNAL(simLockedChanged()));
176 }
177
178 void AccountEntry::onConnectionChanged()
179@@ -236,6 +249,7 @@
180
181 Q_EMIT networkNameChanged();
182 Q_EMIT connectedChanged();
183+ Q_EMIT simLockedChanged();
184 }
185
186 void AccountEntry::onEmergencyNumbersChanged(const QStringList &numbers)
187
188=== modified file 'libtelephonyservice/accountentry.h'
189--- libtelephonyservice/accountentry.h 2014-09-16 10:45:43 +0000
190+++ libtelephonyservice/accountentry.h 2014-10-07 16:32:37 +0000
191@@ -42,12 +42,14 @@
192 Q_PROPERTY(uint voicemailCount READ voicemailCount NOTIFY voicemailCountChanged)
193 Q_PROPERTY(bool voicemailIndicator READ voicemailIndicator NOTIFY voicemailIndicatorChanged)
194 Q_PROPERTY(QString networkName READ networkName NOTIFY networkNameChanged)
195+ Q_PROPERTY(bool simLocked READ simLocked NOTIFY simLockedChanged)
196
197 public:
198 explicit AccountEntry(const Tp::AccountPtr &account, QObject *parent = 0);
199 QString accountId() const;
200 QString displayName() const;
201 QString networkName() const;
202+ bool simLocked() const;
203 void setDisplayName(const QString &name);
204 bool connected() const;
205 QStringList emergencyNumbers() const;
206@@ -61,6 +63,7 @@
207 void accountIdChanged();
208 void displayNameChanged();
209 void networkNameChanged();
210+ void simLockedChanged();
211 void connectedChanged();
212 void emergencyNumbersChanged();
213 void voicemailNumberChanged();
214
215=== modified file 'libtelephonyservice/chatmanager.cpp'
216--- libtelephonyservice/chatmanager.cpp 2014-09-11 18:12:50 +0000
217+++ libtelephonyservice/chatmanager.cpp 2014-10-07 16:32:37 +0000
218@@ -115,7 +115,7 @@
219 void ChatManager::sendMessage(const QStringList &phoneNumbers, const QString &message, const QString &accountId)
220 {
221 AccountEntry *account;
222- if (accountId.isNull()) {
223+ if (accountId.isNull() || accountId.isEmpty()) {
224 account = TelepathyHelper::instance()->defaultMessagingAccount();
225 if (!account) {
226 account = TelepathyHelper::instance()->accounts()[0];
227@@ -124,6 +124,10 @@
228 account = TelepathyHelper::instance()->accountForId(accountId);
229 }
230
231+ if (!account) {
232+ return;
233+ }
234+
235 QDBusInterface *phoneAppHandler = TelepathyHelper::instance()->handlerInterface();
236 phoneAppHandler->call("SendMessage", phoneNumbers, message, account->accountId());
237 }
238
239=== modified file 'libtelephonyservice/telepathyhelper.cpp'
240--- libtelephonyservice/telepathyhelper.cpp 2014-08-15 21:16:57 +0000
241+++ libtelephonyservice/telepathyhelper.cpp 2014-10-07 16:32:37 +0000
242@@ -454,3 +454,11 @@
243 }
244 }
245
246+void TelepathyHelper::unlockSimCards() const
247+{
248+ QDBusInterface connectivityIface("com.ubuntu.connectivity1",
249+ "/com/ubuntu/connectivity1/Private",
250+ "com.ubuntu.connectivity1.Private");
251+ connectivityIface.asyncCall("UnlockAllModems");
252+}
253+
254
255=== modified file 'libtelephonyservice/telepathyhelper.h'
256--- libtelephonyservice/telepathyhelper.h 2014-08-22 19:01:46 +0000
257+++ libtelephonyservice/telepathyhelper.h 2014-10-07 16:32:37 +0000
258@@ -75,6 +75,7 @@
259 AccountEntry *accountForConnection(const Tp::ConnectionPtr &connection) const;
260 Q_INVOKABLE AccountEntry *accountForId(const QString &accountId) const;
261 Q_INVOKABLE void setDefaultAccount(AccountType type, AccountEntry* account);
262+ Q_INVOKABLE void unlockSimCards() const;
263
264 void registerClient(Tp::AbstractClient *client, QString name);
265

Subscribers

People subscribed via source and target branches