Merge lp:~unity-api-team/indicator-network/fix_unlock_all into lp:indicator-network/14.10

Proposed by Antti Kaijanmäki
Status: Merged
Approved by: Charles Kerr
Approved revision: 448
Merged at revision: 448
Proposed branch: lp:~unity-api-team/indicator-network/fix_unlock_all
Merge into: lp:indicator-network/14.10
Diff against target: 311 lines (+59/-112)
4 files modified
src/indicator/modem-manager.cpp (+6/-14)
src/indicator/sim-unlock-dialog.cpp (+28/-79)
src/indicator/sim-unlock-dialog.h (+3/-10)
src/notify-cpp/snapdecision/sim-unlock.cpp (+22/-9)
To merge this branch: bzr merge lp:~unity-api-team/indicator-network/fix_unlock_all
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Charles Kerr (community) Approve
Review via email: mp+238350@code.launchpad.net

Commit message

Fix UnlockAllModems.

To post a comment you must log in.
Revision history for this message
Charles Kerr (charlesk) wrote :

This patch is kind of tortured, but after talking it through with Antti I agree this is a good approach given the tight schedule and the need to know that the patch should be safe.

It would be preferable if a future revision fixes the workarounds described in the comment in SimUnlockDialog::Private::reset()

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Michael Terry (mterry) wrote :

I tested this and it worked for me. But obviously not a code review or anything.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/indicator/modem-manager.cpp'
2--- src/indicator/modem-manager.cpp 2014-10-10 20:33:13 +0000
3+++ src/indicator/modem-manager.cpp 2014-10-14 20:06:14 +0000
4@@ -67,19 +67,11 @@
5 m_dbus.reset(new core::dbus::DBus(m_bus));
6
7 m_unlockDialog = std::make_shared<SimUnlockDialog>();
8- m_unlockDialog->state().changed().connect([this](SimUnlockDialog::State state){
9- switch (state) {
10- case SimUnlockDialog::State::unlocking:
11- case SimUnlockDialog::State::changingPin:
12- // don't care
13- break;
14- case SimUnlockDialog::State::ready:
15- if (!m_pendingUnlocks.empty()) {
16- auto modem = m_pendingUnlocks.front();
17- m_pendingUnlocks.pop_front();
18- m_unlockDialog->unlock(modem);
19- }
20- break;
21+ m_unlockDialog->ready().connect([this](){
22+ if (!m_pendingUnlocks.empty()) {
23+ auto modem = m_pendingUnlocks.front();
24+ m_pendingUnlocks.pop_front();
25+ m_unlockDialog->unlock(modem);
26 }
27 });
28
29@@ -196,7 +188,7 @@
30 || std::count(d->m_pendingUnlocks.begin(), d->m_pendingUnlocks.end(), modem) != 0)
31 return;
32
33- if (d->m_unlockDialog->state().get() == SimUnlockDialog::State::ready
34+ if (d->m_unlockDialog->state() == SimUnlockDialog::State::ready
35 && d->m_pendingUnlocks.size() == 0)
36 d->m_unlockDialog->unlock(modem);
37 else
38
39=== modified file 'src/indicator/sim-unlock-dialog.cpp'
40--- src/indicator/sim-unlock-dialog.cpp 2014-10-07 17:42:56 +0000
41+++ src/indicator/sim-unlock-dialog.cpp 2014-10-14 20:06:14 +0000
42@@ -85,6 +85,7 @@
43 };
44 EnterPinStates m_enterPinState;
45
46+ core::Signal<void> m_ready;
47 core::Property<State> m_state;
48 Modem::Ptr m_modem;
49
50@@ -100,6 +101,9 @@
51
52 core::Property<bool> m_showSimIdentifiers;
53
54+ /// @todo see comment in reset()
55+ bool m_doCleanUp;
56+
57 bool sendEnterPin(std::string pin)
58 {
59 int retries = -1;
60@@ -216,8 +220,13 @@
61 };
62
63 SimUnlockDialog::Private::Private()
64+ : m_doCleanUp{true}
65 {
66 m_sd = std::make_shared<notify::snapdecision::SimUnlock>();
67+ m_sd->cancelled().connect(std::bind(&Private::cancelled, this));
68+ m_sd->pinEntered().connect(std::bind(&Private::pinEntered, this, std::placeholders::_1));
69+ m_sd->closed().connect(std::bind(&Private::closed, this));
70+
71 m_showSimIdentifiers.set(false);
72 reset();
73 }
74@@ -370,8 +379,7 @@
75 void
76 SimUnlockDialog::Private::reset()
77 {
78- /** @todo
79- * bug in dbus-cpp :/
80+ /** @bug in properties-cpp :/
81 * can't disconnect here as the reset() is called from pinEnterer() and
82 * we can't disconnect a signal inside one of it's handlers right now.
83 * uncomment this code once dbus-cpp is fixed.
84@@ -389,6 +397,9 @@
85 m_enterPinState = EnterPinStates::initial;
86
87 m_state.set(State::ready);
88+ m_doCleanUp = false;
89+ m_ready();
90+ m_doCleanUp = true;
91 }
92
93 SimUnlockDialog::SimUnlockDialog()
94@@ -410,9 +421,11 @@
95 d->m_state.set(State::unlocking);
96
97 /// @todo delayed disconnections, see comment in reset()
98- for (auto &c : d->m_connections)
99- c.disconnect();
100- d->m_connections.clear();
101+ if (d->m_doCleanUp) {
102+ for (auto &c : d->m_connections)
103+ c.disconnect();
104+ d->m_connections.clear();
105+ }
106
107 auto retries = modem->retries().get();
108 auto type = modem->requiredPin().get();
109@@ -434,15 +447,6 @@
110 c = modem->retries().changed().connect(std::bind(&Private::update, d.get()));
111 d->m_connections.push_back(c);
112
113- c = d->m_sd->cancelled().connect(std::bind(&Private::cancelled, d.get()));
114- d->m_connections.push_back(c);
115-
116- c = d->m_sd->pinEntered().connect(std::bind(&Private::pinEntered, d.get(), std::placeholders::_1));
117- d->m_connections.push_back(c);
118-
119- c = d->m_sd->closed().connect(std::bind(&Private::closed, d.get()));
120- d->m_connections.push_back(c);
121-
122 int pinRetries = -1;
123 int pukRetries = -1;
124
125@@ -470,67 +474,6 @@
126 }
127
128 void
129-SimUnlockDialog::changePin(Modem::Ptr modem)
130-{
131- /// @todo do we need this?
132- if (d->m_modem)
133- throw std::logic_error("Unlocking already in progress.");
134-
135- if (modem->simStatus().get() != Modem::SimStatus::ready)
136- throw std::logic_error("SIM is not ready");
137-
138- d->m_modem = modem;
139- d->m_state.set(State::changingPin);
140-
141- if (d->m_modem)
142- throw std::logic_error("Unlocking already in progress.");
143-
144- auto c = d->m_sd->cancelled().connect(std::bind(&Private::cancelled, d.get()));
145- d->m_connections.push_back(c);
146-
147- c = d->m_sd->closed().connect(std::bind(&Private::closed, d.get()));
148- d->m_connections.push_back(c);
149-
150- /// @todo add SIM identifier
151- d->m_sd->title().set(_("Enter SIM PIN"));
152- d->m_sd->body().set("");
153- d->m_sd->pinMinMax().set({4,8});
154- d->m_sd->show();
155-
156- std::string currentPin;
157- std::string newPin;
158-
159- c = d->m_sd->pinEntered().connect([this, &currentPin, &newPin](std::string pin){
160- if (currentPin.empty()) {
161- currentPin = pin;
162- d->m_sd->title().set(_("Enter new PIN code"));
163- /// @todo make sure the dialog can't be cancelled from this point onward
164- } else if (newPin.empty()) {
165- newPin = pin;
166- d->m_sd->title().set(_("Confirm new PIN code"));
167- } else {
168- // we have the current PIN and the newPin and confirmed pin is provided as argument pin
169- if (newPin != pin) {
170- newPin.clear();
171- d->m_sd->showError(_("PIN codes did not match."));
172- d->m_sd->title().set(_("Enter new PIN code"));
173- } else {
174- if (d->m_modem->changePin(Modem::PinType::pin, currentPin, newPin)) {
175- currentPin.clear();
176- newPin.clear();
177- /// @todo make sure the dialog can be cancelled again
178- d->m_sd->showError(_("Failed to change PIN.")); /// @todo instruct that the current pin was most probably wrong.
179- d->m_sd->title().set(_("Enter SIM PIN"));
180- } else {
181- d->m_sd->close();
182- }
183- }
184- }
185- });
186- d->m_connections.push_back(c);
187-}
188-
189-void
190 SimUnlockDialog::cancel()
191 {
192 d->m_sd->close();
193@@ -542,10 +485,16 @@
194 return d->m_modem;
195 }
196
197-core::Property<SimUnlockDialog::State> &
198-SimUnlockDialog::state()
199-{
200- return d->m_state;
201+SimUnlockDialog::State
202+SimUnlockDialog::state() const
203+{
204+ return d->m_state.get();
205+}
206+
207+core::Signal<void> &
208+SimUnlockDialog::ready()
209+{
210+ return d->m_ready;
211 }
212
213 core::Property<bool> &
214
215=== modified file 'src/indicator/sim-unlock-dialog.h'
216--- src/indicator/sim-unlock-dialog.h 2014-10-07 08:29:33 +0000
217+++ src/indicator/sim-unlock-dialog.h 2014-10-14 20:06:14 +0000
218@@ -41,20 +41,13 @@
219
220 void unlock(Modem::Ptr modem);
221
222- /**
223- * there must be no other operation active on the dialog
224- * modem has to be on ready state, i.e. it has to be unlocked before
225- * changing the pin.
226- *
227- * @param modem
228- */
229- void changePin(Modem::Ptr modem);
230-
231 void cancel();
232
233 Modem::Ptr modem();
234
235- core::Property<State> &state();
236+ State state() const;
237+ core::Signal<void> &ready();
238+
239 core::Property<bool> &showSimIdentifiers();
240 };
241
242
243=== modified file 'src/notify-cpp/snapdecision/sim-unlock.cpp'
244--- src/notify-cpp/snapdecision/sim-unlock.cpp 2014-10-07 17:24:22 +0000
245+++ src/notify-cpp/snapdecision/sim-unlock.cpp 2014-10-14 20:06:14 +0000
246@@ -34,6 +34,7 @@
247 public:
248
249 Notification::Ptr m_notification;
250+ Notification::Ptr m_pending;
251
252 core::Property<std::string> m_title;
253 core::Property<std::string> m_body;
254@@ -45,6 +46,8 @@
255
256 std::shared_ptr<SessionBus> m_sessionBus;
257
258+ std::map<std::string, Variant> m_modelPaths;
259+
260 Action::Ptr m_notifyAction;
261 Action::Ptr m_pinMinMaxAction;
262 Action::Ptr m_popupAction;
263@@ -59,6 +62,21 @@
264 std::function<void()> m_pendingErrorClosed;
265 std::function<void()> m_pendingPopupClosed;
266
267+ void resetNotification(const std::string &title,
268+ const std::string &body)
269+ {
270+ m_pending = m_notification;
271+ m_notification = std::make_shared<notify::Notification>(title, body, "");
272+ m_notification->setHintString("x-canonical-snap-decisions", "true");
273+ m_notification->setHint("x-canonical-snap-decisions-timeout", TypedVariant<std::int32_t>(std::numeric_limits<std::int32_t>::max()));
274+ m_notification->setHint("x-canonical-private-menu-model", TypedVariant<std::map<std::string, Variant>>(m_modelPaths));
275+ m_notification->closed().connect([this]()
276+ {
277+ resetNotification(m_title.get(), m_body.get());
278+ m_closed();
279+ });
280+ }
281+
282 Private(const std::string &title,
283 const std::string &body,
284 std::pair<std::uint8_t, std::uint8_t> pinMinMax)
285@@ -78,10 +96,9 @@
286 std::map<std::string, Variant> modelActions;
287 modelActions["notifications"] = TypedVariant<std::string>(actionPath);
288
289- std::map<std::string, Variant> modelPaths;
290- modelPaths["busName"] = TypedVariant<std::string>(m_sessionBus->address());
291- modelPaths["menuPath"] = TypedVariant<std::string>(menuPath);
292- modelPaths["actions"] = TypedVariant<std::map<std::string, Variant>>(modelActions);
293+ m_modelPaths["busName"] = TypedVariant<std::string>(m_sessionBus->address());
294+ m_modelPaths["menuPath"] = TypedVariant<std::string>(menuPath);
295+ m_modelPaths["actions"] = TypedVariant<std::map<std::string, Variant>>(modelActions);
296
297 m_menu = std::make_shared<Menu>();
298 m_menuItem = std::make_shared<MenuItem>("", "notifications.simunlock");
299@@ -141,11 +158,7 @@
300 m_menuExporter = std::make_shared<MenuExporter>(m_sessionBus, menuPath, m_menu);
301 m_actionGroupExporter = std::make_shared<ActionGroupExporter>(m_sessionBus, m_actionGroup, actionPath);
302
303- m_notification = std::make_shared<notify::Notification>(title, body, "");
304- m_notification->setHintString("x-canonical-snap-decisions", "true");
305- m_notification->setHint("x-canonical-snap-decisions-timeout", TypedVariant<std::int32_t>(std::numeric_limits<std::int32_t>::max()));
306- m_notification->setHint("x-canonical-private-menu-model", TypedVariant<std::map<std::string, Variant>>(modelPaths));
307- m_notification->closed().connect([this](){ m_closed(); });
308+ resetNotification(title, body);
309
310 m_title.changed().connect([this](const std::string &value){
311 m_notification->summary().set(value);

Subscribers

People subscribed via source and target branches