Merge lp:~pedronis/ubuntu-push/rtm-track-wlan-killstate-instead into lp:ubuntu-push/krillin-rtm

Proposed by Samuele Pedroni
Status: Merged
Approved by: Ricardo Salveti
Approved revision: 147
Merged at revision: 147
Proposed branch: lp:~pedronis/ubuntu-push/rtm-track-wlan-killstate-instead
Merge into: lp:ubuntu-push/krillin-rtm
Diff against target: 612 lines (+280/-38)
8 files modified
bus/connectivity/connectivity_test.go (+4/-0)
bus/endpoint.go (+43/-0)
bus/testing/testing_endpoint.go (+10/-0)
bus/testing/testing_endpoint_test.go (+19/-0)
bus/urfkill/urfkill.go (+70/-6)
bus/urfkill/urfkill.go_test.go (+107/-10)
poller/poller.go (+15/-16)
poller/poller_test.go (+12/-6)
To merge this branch: bzr merge lp:~pedronis/ubuntu-push/rtm-track-wlan-killstate-instead
Reviewer Review Type Date Requested Status
Ricardo Salveti (community) Approve
Review via email: mp+257887@code.launchpad.net

Commit message

switch poller to use killswitch state for WLAN instead of misleading NM property (fixes lp:1446584)

Description of the change

switch poller to use killswitch state for WLAN instead of misleading NM property

To post a comment you must log in.
Revision history for this message
Ricardo Salveti (rsalveti) wrote :

Good, works as expected, tested on krillin.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bus/connectivity/connectivity_test.go'
2--- bus/connectivity/connectivity_test.go 2015-03-26 15:57:45 +0000
3+++ bus/connectivity/connectivity_test.go 2015-04-30 13:18:14 +0000
4@@ -196,6 +196,10 @@
5 return nil, nil
6 }
7
8+func (rep *racyEndpoint) WatchProperties(f func(map[string]dbus.Variant, []string), d func()) (bus.Cancellable, error) {
9+ return nil, nil
10+}
11+
12 func (*racyEndpoint) Close() {}
13 func (*racyEndpoint) Dial() error { return nil }
14 func (*racyEndpoint) String() string { return "racyEndpoint" }
15
16=== modified file 'bus/endpoint.go'
17--- bus/endpoint.go 2015-03-26 15:57:45 +0000
18+++ bus/endpoint.go 2015-04-30 13:18:14 +0000
19@@ -49,6 +49,7 @@
20 Call(member string, args []interface{}, rvs ...interface{}) error
21 GetProperty(property string) (interface{}, error)
22 SetProperty(property string, suffix string, value interface{}) error
23+ WatchProperties(f func(map[string]dbus.Variant, []string), d func()) (Cancellable, error)
24 Dial() error
25 Close()
26 String() string
27@@ -195,6 +196,48 @@
28 return err
29 }
30
31+// WatchProperties() sets up a watch for
32+// org.freedesktop.DBus.Properties PropertiesChanged signal for the
33+// path and interface provided when creating the endpoint, and then
34+// calls f() with the unpacked value. If it's unable to set up the
35+// watch it returns an error. If the watch fails once established, d()
36+// is called. Typically f() sends the values over a channel, and d()
37+// would close the channel.
38+//
39+// XXX: untested
40+func (endp *endpoint) WatchProperties(f func(map[string]dbus.Variant, []string), d func()) (Cancellable, error) {
41+ watch, err := endp.proxy.WatchSignal("org.freedesktop.DBus.Properties", "PropertiesChanged")
42+ if err != nil {
43+ endp.log.Debugf("failed to set up the watch: %s", err)
44+ return nil, err
45+ }
46+
47+ go func() {
48+ for {
49+ msg, ok := <-watch.C
50+ if !ok {
51+ break
52+ }
53+ var intfName string
54+ var changed map[string]dbus.Variant
55+ var invalidated []string
56+ if err := msg.Args(&intfName, &changed, &invalidated); err != nil {
57+ endp.log.Errorf("unexpected values from Properties watch")
58+ break
59+ }
60+ if intfName != endp.addr.Interface {
61+ // ignore
62+ continue
63+ }
64+ f(changed, invalidated)
65+ }
66+ endp.log.Debugf("got not-OK from Properties watch")
67+ d()
68+ }()
69+
70+ return watch, nil
71+}
72+
73 // Close the connection to dbus.
74 //
75 // XXX: untested
76
77=== modified file 'bus/testing/testing_endpoint.go'
78--- bus/testing/testing_endpoint.go 2015-02-26 19:36:57 +0000
79+++ bus/testing/testing_endpoint.go 2015-04-30 13:18:14 +0000
80@@ -154,6 +154,16 @@
81 }
82 }
83
84+// See Endpoint's WatchProperties.
85+func (tc *testingEndpoint) WatchProperties(f func(map[string]dbus.Variant, []string), d func()) (bus.Cancellable, error) {
86+ translate := func(vals ...interface{}) {
87+ changed := vals[0].(map[string]dbus.Variant)
88+ invalidated := vals[1].([]string)
89+ f(changed, invalidated)
90+ }
91+ return tc.WatchSignal("PropertiesChanged", translate, d)
92+}
93+
94 // See Endpoint's Call. This Call will check its condition to decide whether
95 // to return an error, or the first of its return values
96 func (tc *testingEndpoint) Call(member string, args []interface{}, rvs ...interface{}) error {
97
98=== modified file 'bus/testing/testing_endpoint_test.go'
99--- bus/testing/testing_endpoint_test.go 2015-02-26 19:36:57 +0000
100+++ bus/testing/testing_endpoint_test.go 2015-04-30 13:18:14 +0000
101@@ -20,6 +20,7 @@
102 "testing"
103 "time"
104
105+ "launchpad.net/go-dbus/v1"
106 . "launchpad.net/gocheck"
107
108 "launchpad.net/ubuntu-push/bus"
109@@ -203,6 +204,24 @@
110 c.Check(e, NotNil)
111 }
112
113+// Test that WatchProperties() with a positive condition sends the
114+// provided return values over the channel.
115+func (s *TestingEndpointSuite) TestWatchProperties(c *C) {
116+ var m, n int32 = 42, 17
117+ endp := NewMultiValuedTestingEndpoint(nil, condition.Work(true),
118+ []interface{}{map[string]dbus.Variant{"s": dbus.Variant{m}}, []string{}},
119+ []interface{}{map[string]dbus.Variant{"s": dbus.Variant{n}}, []string{}},
120+ )
121+ ch := make(chan int32)
122+ w, e := endp.WatchProperties(func(changed map[string]dbus.Variant, nvalited []string) {
123+ ch <- changed["s"].Value.(int32)
124+ }, func() { close(ch) })
125+ c.Assert(e, IsNil)
126+ defer w.Cancel()
127+ c.Check(<-ch, Equals, m)
128+ c.Check(<-ch, Equals, n)
129+}
130+
131 // Test Dial() with a non-working bus fails
132 func (s *TestingBusSuite) TestDialNoWork(c *C) {
133 endp := NewTestingEndpoint(condition.Work(false), nil)
134
135=== modified file 'bus/urfkill/urfkill.go'
136--- bus/urfkill/urfkill.go 2015-03-30 12:05:10 +0000
137+++ bus/urfkill/urfkill.go 2015-04-30 13:18:14 +0000
138@@ -19,7 +19,7 @@
139 package urfkill
140
141 import (
142- //"launchpad.net/go-dbus/v1"
143+ "launchpad.net/go-dbus/v1"
144
145 "launchpad.net/ubuntu-push/bus"
146 "launchpad.net/ubuntu-push/logger"
147@@ -32,26 +32,49 @@
148 Name: "org.freedesktop.URfkill",
149 }
150
151+// URfkill lives on a well-knwon bus.Address
152+var WLANKillswitchBusAddress bus.Address = bus.Address{
153+ Interface: "org.freedesktop.URfkill.Killswitch",
154+ Path: "/org/freedesktop/URfkill/WLAN",
155+ Name: "org.freedesktop.URfkill",
156+}
157+
158 /*****************************************************************
159 * URfkill (and its implementation)
160 */
161
162+type KillswitchState int32
163+
164+const (
165+ KillswitchStateUnblocked KillswitchState = 0
166+ KillswitchStateSoftBlocked KillswitchState = 1
167+ KillswitchStateHardBlocked KillswitchState = 2
168+)
169+
170 type URfkill interface {
171 // IsFlightMode returns flight mode state.
172 IsFlightMode() bool
173 // WatchFlightMode listens for changes to URfkill's flight
174 // mode state, and sends them out over the channel returned.
175 WatchFlightMode() (<-chan bool, bus.Cancellable, error)
176+ // GetWLANKillswitchState fetches and returns URfkill's
177+ // WLAN killswitch state.
178+ GetWLANKillswitchState() KillswitchState
179+ // WatchWLANKillswitchState listens for changes of URfkill's
180+ // WLAN killswtich state, and sends them out over the channel returned.
181+ WatchWLANKillswitchState() (<-chan KillswitchState, bus.Cancellable, error)
182 }
183
184 type uRfkill struct {
185- bus bus.Endpoint
186- log logger.Logger
187+ bus bus.Endpoint
188+ wlanKillswitch bus.Endpoint
189+ log logger.Logger
190 }
191
192-// New returns a new URfkill that'll use the provided bus.Endpoint
193-func New(endp bus.Endpoint, log logger.Logger) URfkill {
194- return &uRfkill{endp, log}
195+// New returns a new URfkill that'll use the provided bus.Endpoints
196+// for BusAddress and WLANKillswitchBusAddress
197+func New(endp bus.Endpoint, wlanKillswitch bus.Endpoint, log logger.Logger) URfkill {
198+ return &uRfkill{endp, wlanKillswitch, log}
199 }
200
201 // ensure uRfkill implements URfkill
202@@ -92,3 +115,44 @@
203
204 return ch, w, nil
205 }
206+
207+func (ur *uRfkill) GetWLANKillswitchState() KillswitchState {
208+ got, err := ur.wlanKillswitch.GetProperty("state")
209+ if err != nil {
210+ ur.log.Errorf("failed getting WLANKillswitchState: %s", err)
211+ ur.log.Debugf("defaulting WLANKillswitchState to true")
212+ return KillswitchStateUnblocked
213+ }
214+
215+ v, ok := got.(int32)
216+ if !ok {
217+ ur.log.Errorf("got weird WLANKillswitchState: %#v", got)
218+ return KillswitchStateUnblocked
219+ }
220+
221+ return KillswitchState(v)
222+}
223+
224+func (ur *uRfkill) WatchWLANKillswitchState() (<-chan KillswitchState, bus.Cancellable, error) {
225+ ch := make(chan KillswitchState)
226+ w, err := ur.wlanKillswitch.WatchProperties(
227+ func(changed map[string]dbus.Variant, invalidated []string) {
228+ v, ok := changed["state"]
229+ if !ok {
230+ return
231+ }
232+ st, ok := v.Value.(int32)
233+ if !ok {
234+ ur.log.Errorf("got weird WLANKillswitchState via PropertiesChanged: %#v", v)
235+ return
236+ }
237+ ur.log.Debugf("got WLANKillswitchState change: %v", st)
238+ ch <- KillswitchState(st)
239+ }, func() { close(ch) })
240+ if err != nil {
241+ ur.log.Debugf("failed to set up the watch: %s", err)
242+ return nil, nil, err
243+ }
244+
245+ return ch, w, nil
246+}
247
248=== modified file 'bus/urfkill/urfkill.go_test.go'
249--- bus/urfkill/urfkill.go_test.go 2015-03-30 12:05:10 +0000
250+++ bus/urfkill/urfkill.go_test.go 2015-04-30 13:18:14 +0000
251@@ -19,7 +19,7 @@
252 import (
253 "testing"
254
255- //"launchpad.net/go-dbus/v1"
256+ "launchpad.net/go-dbus/v1"
257 . "launchpad.net/gocheck"
258
259 testingbus "launchpad.net/ubuntu-push/bus/testing"
260@@ -42,14 +42,14 @@
261 }
262
263 func (s *URSuite) TestNew(c *C) {
264- ur := New(testingbus.NewTestingEndpoint(nil, condition.Work(true)), s.log)
265+ ur := New(testingbus.NewTestingEndpoint(nil, condition.Work(true)), nil, s.log)
266 c.Check(ur, NotNil)
267 }
268
269 // IsFlightMode returns the right state when everything works
270 func (s *URSuite) TestIsFlightMode(c *C) {
271 endp := testingbus.NewTestingEndpoint(nil, condition.Work(true), true)
272- ur := New(endp, s.log)
273+ ur := New(endp, nil, s.log)
274 state := ur.IsFlightMode()
275 c.Check(state, Equals, true)
276 callArgs := testingbus.GetCallArgs(endp)
277@@ -60,7 +60,7 @@
278
279 // IsFlightMode returns the right state when dbus fails
280 func (s *URSuite) TestIsFlightModeFail(c *C) {
281- ur := New(testingbus.NewTestingEndpoint(nil, condition.Work(false)), s.log)
282+ ur := New(testingbus.NewTestingEndpoint(nil, condition.Work(false)), nil, s.log)
283 state := ur.IsFlightMode()
284 c.Check(state, Equals, false)
285 }
286@@ -68,14 +68,14 @@
287 // IsFlightMode returns the right state when dbus works but delivers
288 // rubbish values
289 func (s *URSuite) TestIsFlightModeRubbishValues(c *C) {
290- ur := New(testingbus.NewTestingEndpoint(nil, condition.Work(true), "broken"), s.log)
291+ ur := New(testingbus.NewTestingEndpoint(nil, condition.Work(true), "broken"), nil, s.log)
292 state := ur.IsFlightMode()
293 c.Check(state, Equals, false)
294 }
295
296 // IsFlightMode returns the right state when dbus works but delivers a rubbish structure
297 func (s *URSuite) TestIsFlightModeRubbishStructure(c *C) {
298- ur := New(testingbus.NewMultiValuedTestingEndpoint(nil, condition.Work(true), []interface{}{}), s.log)
299+ ur := New(testingbus.NewMultiValuedTestingEndpoint(nil, condition.Work(true), []interface{}{}), nil, s.log)
300 state := ur.IsFlightMode()
301 c.Check(state, Equals, false)
302 }
303@@ -83,7 +83,7 @@
304 // WatchFightMode sends a stream of states over the channel
305 func (s *URSuite) TestWatchFlightMode(c *C) {
306 tc := testingbus.NewTestingEndpoint(nil, condition.Work(true), false, true, false)
307- ur := New(tc, s.log)
308+ ur := New(tc, nil, s.log)
309 ch, w, err := ur.WatchFlightMode()
310 c.Assert(err, IsNil)
311 defer w.Cancel()
312@@ -93,7 +93,7 @@
313
314 // WatchFlightMode returns on error if the dbus call fails
315 func (s *URSuite) TestWatchFlightModeFails(c *C) {
316- ur := New(testingbus.NewTestingEndpoint(nil, condition.Work(false)), s.log)
317+ ur := New(testingbus.NewTestingEndpoint(nil, condition.Work(false)), nil, s.log)
318 _, _, err := ur.WatchFlightMode()
319 c.Check(err, NotNil)
320 }
321@@ -101,7 +101,7 @@
322 // WatchFlightMode calls close on its channel when the watch bails
323 func (s *URSuite) TestWatchFlightModeClosesOnWatchBail(c *C) {
324 tc := testingbus.NewTestingEndpoint(nil, condition.Work(true))
325- ur := New(tc, s.log)
326+ ur := New(tc, nil, s.log)
327 ch, w, err := ur.WatchFlightMode()
328 c.Assert(err, IsNil)
329 defer w.Cancel()
330@@ -112,10 +112,107 @@
331 // WatchFlightMode survives rubbish values
332 func (s *URSuite) TestWatchFlightModeSurvivesRubbishValues(c *C) {
333 tc := testingbus.NewTestingEndpoint(nil, condition.Work(true), "gorp")
334- ur := New(tc, s.log)
335+ ur := New(tc, nil, s.log)
336 ch, w, err := ur.WatchFlightMode()
337 c.Assert(err, IsNil)
338 defer w.Cancel()
339 _, ok := <-ch
340 c.Check(ok, Equals, false)
341 }
342+
343+// GetWLANKillState returns the right state when everything works
344+func (s *URSuite) TestGetWLANKillState(c *C) {
345+ ur := New(nil, testingbus.NewTestingEndpoint(nil, condition.Work(true), KillswitchStateSoftBlocked), s.log)
346+ st := ur.GetWLANKillswitchState()
347+ c.Check(st, Equals, KillswitchStateSoftBlocked)
348+}
349+
350+// GetWLANKillswitchState returns the right state when dbus fails
351+func (s *URSuite) TestGetWLANKillswitchStateFail(c *C) {
352+ ur := New(nil, testingbus.NewTestingEndpoint(nil, condition.Work(false)), s.log)
353+ st := ur.GetWLANKillswitchState()
354+ c.Check(st, Equals, KillswitchStateUnblocked)
355+}
356+
357+// GetWLANKillswitchState returns the right state when dbus works but delivers rubbish values
358+func (s *URSuite) TestGetWLANKillswitchStateRubbishValues(c *C) {
359+ ur := New(nil, testingbus.NewTestingEndpoint(nil, condition.Work(true), "broken"), s.log)
360+ st := ur.GetWLANKillswitchState()
361+ c.Check(st, Equals, KillswitchStateUnblocked)
362+}
363+
364+// GetWLANKillswitchState returns the right state when dbus works but delivers a rubbish structure
365+func (s *URSuite) TestGetWLANKillswitchStateRubbishStructure(c *C) {
366+ ur := New(nil, testingbus.NewMultiValuedTestingEndpoint(nil, condition.Work(true), []interface{}{}), s.log)
367+ st := ur.GetWLANKillswitchState()
368+ c.Check(st, Equals, KillswitchStateUnblocked)
369+}
370+
371+func mkWLANKillswitchStateMap(st KillswitchState) map[string]dbus.Variant {
372+ m := make(map[string]dbus.Variant)
373+ m["state"] = dbus.Variant{int32(st)}
374+ return m
375+}
376+
377+// WatchWLANKillswitchState sends a stream of WLAN killswitch states over the channel
378+func (s *URSuite) TestWatchWLANKillswitchState(c *C) {
379+ tc := testingbus.NewMultiValuedTestingEndpoint(nil, condition.Work(true),
380+ []interface{}{mkWLANKillswitchStateMap(KillswitchStateUnblocked), []string{}},
381+ []interface{}{mkWLANKillswitchStateMap(KillswitchStateHardBlocked), []string{}},
382+ []interface{}{mkWLANKillswitchStateMap(KillswitchStateUnblocked), []string{}},
383+ )
384+ ur := New(nil, tc, s.log)
385+ ch, w, err := ur.WatchWLANKillswitchState()
386+ c.Assert(err, IsNil)
387+ defer w.Cancel()
388+ l := []KillswitchState{<-ch, <-ch, <-ch}
389+ c.Check(l, DeepEquals, []KillswitchState{KillswitchStateUnblocked, KillswitchStateHardBlocked, KillswitchStateUnblocked})
390+}
391+
392+// WatchWLANKillswitchState returns on error if the dbus call fails
393+func (s *URSuite) TestWatchWLANKillswitchStateFails(c *C) {
394+ ur := New(nil, testingbus.NewTestingEndpoint(nil, condition.Work(false)), s.log)
395+ _, _, err := ur.WatchWLANKillswitchState()
396+ c.Check(err, NotNil)
397+}
398+
399+// WatchWLANKillswitchState calls close on its channel when the watch bails
400+func (s *URSuite) TestWatchWLANKillswitchStateClosesOnWatchBail(c *C) {
401+ tc := testingbus.NewTestingEndpoint(nil, condition.Work(true))
402+ ur := New(nil, tc, s.log)
403+ ch, w, err := ur.WatchWLANKillswitchState()
404+ c.Assert(err, IsNil)
405+ defer w.Cancel()
406+ _, ok := <-ch
407+ c.Check(ok, Equals, false)
408+}
409+
410+// WatchWLANKillswitchState ignores non-WLAN-killswitch PropertiesChanged
411+func (s *URSuite) TestWatchWLANKillswitchStateIgnoresIrrelevant(c *C) {
412+ tc := testingbus.NewMultiValuedTestingEndpoint(nil, condition.Work(true),
413+ []interface{}{map[string]dbus.Variant{"foo": dbus.Variant{}}, []string{}},
414+ []interface{}{mkWLANKillswitchStateMap(KillswitchStateUnblocked), []string{}},
415+ )
416+ ur := New(nil, tc, s.log)
417+ ch, w, err := ur.WatchWLANKillswitchState()
418+ c.Assert(err, IsNil)
419+ defer w.Cancel()
420+ v, ok := <-ch
421+ c.Check(ok, Equals, true)
422+ c.Check(v, Equals, KillswitchStateUnblocked)
423+}
424+
425+// WatchWLANKillswitchState ignores rubbish WLAN killswitch state
426+func (s *URSuite) TestWatchWLANKillswitchStateIgnoresRubbishValues(c *C) {
427+ tc := testingbus.NewMultiValuedTestingEndpoint(nil, condition.Work(true),
428+ []interface{}{map[string]dbus.Variant{"state": dbus.Variant{-12}}, []string{}},
429+ []interface{}{mkWLANKillswitchStateMap(KillswitchStateSoftBlocked), []string{}},
430+ )
431+ ur := New(nil, tc, s.log)
432+ ch, w, err := ur.WatchWLANKillswitchState()
433+ c.Assert(err, IsNil)
434+ defer w.Cancel()
435+ v, ok := <-ch
436+ c.Check(ok, Equals, true)
437+ c.Check(v, Equals, KillswitchStateSoftBlocked)
438+}
439
440=== modified file 'poller/poller.go'
441--- poller/poller.go 2015-03-31 09:31:28 +0000
442+++ poller/poller.go 2015-04-30 13:18:14 +0000
443@@ -25,7 +25,6 @@
444 "time"
445
446 "launchpad.net/ubuntu-push/bus"
447- "launchpad.net/ubuntu-push/bus/networkmanager"
448 "launchpad.net/ubuntu-push/bus/polld"
449 "launchpad.net/ubuntu-push/bus/powerd"
450 "launchpad.net/ubuntu-push/bus/urfkill"
451@@ -68,7 +67,6 @@
452 type poller struct {
453 times Times
454 log logger.Logger
455- nm networkmanager.NetworkManager
456 powerd powerd.Powerd
457 polld polld.Polld
458 urfkill urfkill.URfkill
459@@ -103,18 +101,13 @@
460 if p.powerd != nil || p.polld != nil {
461 return ErrAlreadyStarted
462 }
463- nmEndp := bus.SystemBus.Endpoint(networkmanager.BusAddress, p.log)
464 powerdEndp := bus.SystemBus.Endpoint(powerd.BusAddress, p.log)
465 polldEndp := bus.SessionBus.Endpoint(polld.BusAddress, p.log)
466 urEndp := bus.SystemBus.Endpoint(urfkill.BusAddress, p.log)
467+ urWLANKillswitchEndp := bus.SystemBus.Endpoint(urfkill.WLANKillswitchBusAddress, p.log)
468 var wg sync.WaitGroup
469 wg.Add(4)
470 go func() {
471- n := util.NewAutoRedialer(nmEndp).Redial()
472- p.log.Debugf("NetworkManager dialed on try %d", n)
473- wg.Done()
474- }()
475- go func() {
476 n := util.NewAutoRedialer(powerdEndp).Redial()
477 p.log.Debugf("powerd dialed on try %d", n)
478 wg.Done()
479@@ -129,12 +122,16 @@
480 p.log.Debugf("URfkill dialed on try %d", n)
481 wg.Done()
482 }()
483+ go func() {
484+ n := util.NewAutoRedialer(urWLANKillswitchEndp).Redial()
485+ p.log.Debugf("URfkill (WLAN killswitch) dialed on try %d", n)
486+ wg.Done()
487+ }()
488 wg.Wait()
489
490- p.nm = networkmanager.New(nmEndp, p.log)
491 p.powerd = powerd.New(powerdEndp, p.log)
492 p.polld = polld.New(polldEndp, p.log)
493- p.urfkill = urfkill.New(urEndp, p.log)
494+ p.urfkill = urfkill.New(urEndp, urWLANKillswitchEndp, p.log)
495
496 // busy sleep loop to workaround go's timer/sleep
497 // not accounting for time when the system is suspended
498@@ -157,7 +154,7 @@
499 if p.log == nil {
500 return ErrUnconfigured
501 }
502- if p.nm == nil || p.powerd == nil || p.polld == nil || p.urfkill == nil {
503+ if p.powerd == nil || p.polld == nil || p.urfkill == nil {
504 return ErrNotStarted
505 }
506 wakeupCh, err := p.powerd.WatchWakeups()
507@@ -169,18 +166,18 @@
508 return err
509 }
510 flightMode := p.urfkill.IsFlightMode()
511- wirelessEnabled := p.nm.GetWirelessEnabled()
512+ wlanKillswitchState := p.urfkill.GetWLANKillswitchState()
513 flightModeCh, _, err := p.urfkill.WatchFlightMode()
514 if err != nil {
515 return err
516 }
517- wirelessEnabledCh, _, err := p.nm.WatchWirelessEnabled()
518+ wlanKillswitchStateCh, _, err := p.urfkill.WatchWLANKillswitchState()
519 if err != nil {
520 return err
521 }
522
523 filteredWakeUpCh := make(chan bool)
524- go p.control(wakeupCh, filteredWakeUpCh, flightMode, flightModeCh, wirelessEnabled, wirelessEnabledCh)
525+ go p.control(wakeupCh, filteredWakeUpCh, flightMode, flightModeCh, wlanKillswitchState, wlanKillswitchStateCh)
526 go p.run(filteredWakeUpCh, doneCh)
527 return nil
528 }
529@@ -198,7 +195,8 @@
530 return t, cookie, err
531 }
532
533-func (p *poller) control(wakeupCh <-chan bool, filteredWakeUpCh chan<- bool, flightMode bool, flightModeCh <-chan bool, wirelessEnabled bool, wirelessEnabledCh <-chan bool) {
534+func (p *poller) control(wakeupCh <-chan bool, filteredWakeUpCh chan<- bool, flightMode bool, flightModeCh <-chan bool, wlanKillswitchState urfkill.KillswitchState, wlanKillswitchStateCh <-chan urfkill.KillswitchState) {
535+ wirelessEnabled := wlanKillswitchState == urfkill.KillswitchStateUnblocked
536 dontPoll := flightMode && !wirelessEnabled
537 var t time.Time
538 cookie := ""
539@@ -237,7 +235,8 @@
540 }
541 }
542 case flightMode = <-flightModeCh:
543- case wirelessEnabled = <-wirelessEnabledCh:
544+ case wlanKillswitchState = <-wlanKillswitchStateCh:
545+ wirelessEnabled = wlanKillswitchState == urfkill.KillswitchStateUnblocked
546 }
547 newDontPoll := flightMode && !wirelessEnabled
548 p.log.Debugf("control: flightMode:%v wirelessEnabled:%v prevDontPoll:%v dontPoll:%v wakeupReq:%v holdsWakeLock:%v", flightMode, wirelessEnabled, dontPoll, newDontPoll, !t.IsZero(), holdsWakeLock)
549
550=== modified file 'poller/poller_test.go'
551--- poller/poller_test.go 2015-03-30 15:59:19 +0000
552+++ poller/poller_test.go 2015-04-30 13:18:14 +0000
553@@ -21,6 +21,7 @@
554
555 . "launchpad.net/gocheck"
556
557+ "launchpad.net/ubuntu-push/bus/urfkill"
558 "launchpad.net/ubuntu-push/client/session"
559 helpers "launchpad.net/ubuntu-push/testing"
560 )
561@@ -90,6 +91,11 @@
562 s.myd = &myD{}
563 }
564
565+const (
566+ wlanOn = urfkill.KillswitchStateUnblocked
567+ wlanOff = urfkill.KillswitchStateSoftBlocked
568+)
569+
570 func (s *PrSuite) TestStep(c *C) {
571 p := &poller{
572 times: Times{},
573@@ -111,7 +117,7 @@
574 ch := make(chan string)
575 // now, run
576 filteredWakeUpCh := make(chan bool)
577- go p.control(wakeupCh, filteredWakeUpCh, false, nil, true, nil)
578+ go p.control(wakeupCh, filteredWakeUpCh, false, nil, wlanOn, nil)
579 go func() { ch <- p.step(filteredWakeUpCh, doneCh, "old cookie") }()
580 select {
581 case s := <-ch:
582@@ -138,8 +144,8 @@
583 filteredWakeUpCh := make(chan bool)
584 s.myd.watchWakeCh = make(chan bool, 1)
585 flightModeCh := make(chan bool)
586- wirelessModeCh := make(chan bool)
587- go p.control(wakeUpCh, filteredWakeUpCh, false, flightModeCh, true, wirelessModeCh)
588+ wlanKillswitchStateCh := make(chan urfkill.KillswitchState)
589+ go p.control(wakeUpCh, filteredWakeUpCh, false, flightModeCh, wlanOn, wlanKillswitchStateCh)
590
591 // works
592 err := p.requestWakeup()
593@@ -157,17 +163,17 @@
594
595 // flight mode
596 flightModeCh <- true
597- wirelessModeCh <- false
598+ wlanKillswitchStateCh <- wlanOff
599 err = p.requestWakeup()
600 c.Assert(err, IsNil)
601 c.Check(s.myd.watchWakeCh, HasLen, 0)
602
603 // wireless on
604- wirelessModeCh <- true
605+ wlanKillswitchStateCh <- wlanOn
606 c.Check(<-s.myd.watchWakeCh, Equals, true)
607
608 // wireless off
609- wirelessModeCh <- false
610+ wlanKillswitchStateCh <- wlanOff
611 // pending wakeup was cleared
612 c.Check(<-s.myd.watchWakeCh, Equals, false)
613

Subscribers

People subscribed via source and target branches