Merge lp:~phablet-team/nuntium/update-july-first into lp:nuntium/packaging

Proposed by Alfonso Sanchez-Beato
Status: Merged
Approved by: Manuel de la Peña
Approved revision: 101
Merged at revision: 101
Proposed branch: lp:~phablet-team/nuntium/update-july-first
Merge into: lp:nuntium/packaging
Diff against target: 221 lines (+92/-36)
3 files modified
debian/changelog (+6/-0)
ofono/context_test.go (+10/-14)
ofono/modem.go (+76/-22)
To merge this branch: bzr merge lp:~phablet-team/nuntium/update-july-first
Reviewer Review Type Date Requested Status
Manuel de la Peña (community) Approve
Review via email: mp+263468@code.launchpad.net

Commit message

Use proxy and proxy port from ofono Settings property (LP: #1417976)

Description of the change

Use proxy and proxy port from ofono Settings property (LP: #1417976)

To post a comment you must log in.
Revision history for this message
Manuel de la Peña (mandel) wrote :

Looks good after comparing the diff with the one in github.

review: Approve
102. By Alfonso Sanchez-Beato

Refresh context properties after (de)activation

Refresh context properties after changing the Active property, as some
of them are dynamic and change after context activation / deactivation.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'debian/changelog'
2--- debian/changelog 2015-06-15 08:52:13 +0000
3+++ debian/changelog 2015-07-01 16:34:14 +0000
4@@ -1,3 +1,9 @@
5+nuntium (1.4+15.10.20150701-0ubuntu1) UNRELEASED; urgency=medium
6+
7+ * Use proxy and proxy port from ofono Settings property (LP: #1417976)
8+
9+ -- Alfonso Sanchez-Beato (email Canonical) <alfonso.sanchez-beato@canonical.com> Wed, 01 Jul 2015 09:16:06 +0200
10+
11 nuntium (1.4+15.10.20150615-0ubuntu1) wily; urgency=medium
12
13 [ Alfonso Sanchez-Beato (email Canonical) ]
14
15=== modified file 'ofono/context_test.go'
16--- ofono/context_test.go 2015-05-20 12:32:08 +0000
17+++ ofono/context_test.go 2015-07-01 16:34:14 +0000
18@@ -23,7 +23,6 @@
19
20 import (
21 "errors"
22- "fmt"
23
24 "launchpad.net/go-dbus/v1"
25 . "launchpad.net/gocheck"
26@@ -332,6 +331,12 @@
27 ObjectPath: "/ril_0/context1",
28 Properties: makeGenericContextProperty("Context1", contextTypeInternet, true, true, true, false),
29 }
30+ m := make(map[interface{}]interface{})
31+ pr := dbus.Variant{proxy.Host}
32+ pr_pt := dbus.Variant{uint16(proxy.Port)}
33+ m["Proxy"] = &pr
34+ m["ProxyPort"] = &pr_pt
35+ context.Properties["Settings"] = dbus.Variant{m}
36
37 p, err := context.GetProxy()
38 c.Assert(err, IsNil)
39@@ -349,24 +354,15 @@
40 c.Check(p, DeepEquals, ProxyInfo{})
41 }
42
43-func (s *ContextTestSuite) TestGetProxyWithHTTP(c *C) {
44- context := OfonoContext{
45- ObjectPath: "/ril_0/context1",
46- Properties: makeGenericContextProperty("Context1", contextTypeInternet, true, true, true, false),
47- }
48- context.Properties["MessageProxy"] = dbus.Variant{fmt.Sprintf("http://%s:%d", proxy.Host, proxy.Port)}
49-
50- p, err := context.GetProxy()
51- c.Assert(err, IsNil)
52- c.Check(p, DeepEquals, proxy)
53-}
54-
55 func (s *ContextTestSuite) TestGetProxyNoPort(c *C) {
56 context := OfonoContext{
57 ObjectPath: "/ril_0/context1",
58 Properties: makeGenericContextProperty("Context1", contextTypeInternet, true, true, true, false),
59 }
60- context.Properties["MessageProxy"] = dbus.Variant{fmt.Sprintf("http://%s", proxy.Host)}
61+ m := make(map[interface{}]interface{})
62+ pr := dbus.Variant{proxy.Host}
63+ m["Proxy"] = &pr
64+ context.Properties["Settings"] = dbus.Variant{m}
65
66 p, err := context.GetProxy()
67 c.Assert(err, IsNil)
68
69=== modified file 'ofono/modem.go'
70--- ofono/modem.go 2015-06-12 12:48:00 +0000
71+++ ofono/modem.go 2015-07-01 16:34:14 +0000
72@@ -25,10 +25,7 @@
73 "errors"
74 "fmt"
75 "log"
76- "net"
77 "reflect"
78- "strconv"
79- "strings"
80 "time"
81
82 "launchpad.net/go-dbus/v1"
83@@ -70,6 +67,11 @@
84 Port uint64
85 }
86
87+const PROP_SETTINGS = "Settings"
88+const SETTINGS_PROXY = "Proxy"
89+const SETTINGS_PROXYPORT = "ProxyPort"
90+const DBUS_CALL_GET_PROPERTIES = "GetProperties"
91+
92 func (p ProxyInfo) String() string {
93 return fmt.Sprintf("%s:%d", p.Host, p.Port)
94 }
95@@ -284,7 +286,18 @@
96 return false
97 }
98
99-func (context OfonoContext) toggleActive(state bool, conn *dbus.Connection) error {
100+func (context *OfonoContext) getContextProperties(conn *dbus.Connection) {
101+ ctxObj := conn.Object(OFONO_SENDER, context.ObjectPath)
102+ if reply, err := ctxObj.Call(CONNECTION_CONTEXT_INTERFACE, DBUS_CALL_GET_PROPERTIES); err == nil {
103+ if err := reply.Args(&context.Properties); err != nil {
104+ log.Println("Cannot retrieve properties for", context.ObjectPath, err)
105+ }
106+ } else {
107+ log.Println("Cannot get properties for", context.ObjectPath, err)
108+ }
109+}
110+
111+func (context *OfonoContext) toggleActive(state bool, conn *dbus.Connection) error {
112 log.Println("Trying to set Active property to", state, "for context on", state, context.ObjectPath)
113 obj := conn.Object("org.ofono", context.ObjectPath)
114 for i := 0; i < 3; i++ {
115@@ -302,6 +315,8 @@
116 obj.Call(CONNECTION_CONTEXT_INTERFACE, "SetProperty",
117 "Preferred", dbus.Variant{true})
118 }
119+ // Refresh context properties
120+ context.getContextProperties(conn)
121 return nil
122 }
123 }
124@@ -355,6 +370,54 @@
125 return ""
126 }
127
128+func (oContext OfonoContext) settingsProxy() string {
129+ v, ok := oContext.Properties[PROP_SETTINGS]
130+ if !ok {
131+ return ""
132+ }
133+
134+ settings, ok := v.Value.(map[interface{}]interface{})
135+ if !ok {
136+ return ""
137+ }
138+
139+ proxy_v, ok := settings[SETTINGS_PROXY]
140+ if !ok {
141+ return ""
142+ }
143+
144+ proxy, ok := proxy_v.(*dbus.Variant).Value.(string)
145+ if !ok {
146+ return ""
147+ }
148+
149+ return proxy
150+}
151+
152+func (oContext OfonoContext) settingsProxyPort() uint64 {
153+ v, ok := oContext.Properties[PROP_SETTINGS]
154+ if !ok {
155+ return 80
156+ }
157+
158+ settings, ok := v.Value.(map[interface{}]interface{})
159+ if !ok {
160+ return 80
161+ }
162+
163+ port_v, ok := settings[SETTINGS_PROXYPORT]
164+ if !ok {
165+ return 80
166+ }
167+
168+ port, ok := port_v.(*dbus.Variant).Value.(uint16)
169+ if !ok {
170+ return 80
171+ }
172+
173+ return uint64(port)
174+}
175+
176 func (oContext OfonoContext) GetMessageCenter() (string, error) {
177 if oContext.hasMessageCenter() {
178 return oContext.messageCenter(), nil
179@@ -364,25 +427,16 @@
180 }
181
182 func (oContext OfonoContext) GetProxy() (proxyInfo ProxyInfo, err error) {
183- proxy := oContext.messageProxy()
184+ proxy := oContext.settingsProxy()
185 // we need to support empty proxies
186 if proxy == "" {
187- return proxyInfo, nil
188- }
189- if strings.HasPrefix(proxy, "http://") {
190- proxy = proxy[len("http://"):]
191- }
192- var portString string
193- proxyInfo.Host, portString, err = net.SplitHostPort(proxy)
194- if err != nil {
195- proxyInfo.Host = proxy
196- proxyInfo.Port = 80
197- return proxyInfo, nil
198- }
199- proxyInfo.Port, err = strconv.ParseUint(portString, 0, 64)
200- if err != nil {
201- return proxyInfo, err
202- }
203+ log.Println("No proxy in ofono settings")
204+ return proxyInfo, nil
205+ }
206+
207+ proxyInfo.Host = proxy
208+ proxyInfo.Port = oContext.settingsProxyPort()
209+
210 return proxyInfo, nil
211 }
212
213@@ -427,7 +481,7 @@
214 func (modem *Modem) getProperty(interfaceName, propertyName string) (*dbus.Variant, error) {
215 errorString := "Cannot retrieve %s from %s for %s: %s"
216 rilObj := modem.conn.Object(OFONO_SENDER, modem.Modem)
217- if reply, err := rilObj.Call(interfaceName, "GetProperties"); err == nil {
218+ if reply, err := rilObj.Call(interfaceName, DBUS_CALL_GET_PROPERTIES); err == nil {
219 var property PropertiesType
220 if err := reply.Args(&property); err != nil {
221 return nil, fmt.Errorf(errorString, propertyName, interfaceName, modem.Modem, err)

Subscribers

People subscribed via source and target branches

to all changes: