Merge lp:~jonas-drange/ubuntu-system-settings/apn-no-overwrite-1415495 into lp:ubuntu-system-settings

Proposed by Jonas G. Drange
Status: Merged
Approved by: Ken VanDine
Approved revision: 1358
Merged at revision: 1358
Proposed branch: lp:~jonas-drange/ubuntu-system-settings/apn-no-overwrite-1415495
Merge into: lp:ubuntu-system-settings
Diff against target: 130 lines (+42/-36)
1 file modified
plugins/cellular/PageChooseApn.qml (+42/-36)
To merge this branch: bzr merge lp:~jonas-drange/ubuntu-system-settings/apn-no-overwrite-1415495
Reviewer Review Type Date Requested Status
Ken VanDine Approve
PS Jenkins bot continuous-integration Approve
Review via email: mp+254000@code.launchpad.net

Commit message

[cellular] apn page does not overwrite empty, provisioned contexts

Description of the change

What changed:
The current APN page made the assumption that an empty internet context was really a recently added custom context. I have made this logic more precise by using a temporary event handler on ConnectionManager's contextAdded.

How to test:

If you have special a special APN configuration, please back up the gprs file.

1. Stop ofono (sudo service ofono stop)
2. Edit /var/lib/ofono/<IMSI>/gprs, let it look like this [1].
3. Start ofono (sudo service ofono start)
4. Wait 5 secs. Confirm that the output of /usr/share/ofono/scripts/list-contexts is what you'd expect.
5. Enter the APN page
6. Add a custom context and confirm it is not overwriting anything.

[1] https://launchpadlibrarian.net/196032938/gprs

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Ken VanDine (ken-vandine) wrote :

Looks good and works as described.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'plugins/cellular/PageChooseApn.qml'
2--- plugins/cellular/PageChooseApn.qml 2015-02-16 14:02:22 +0000
3+++ plugins/cellular/PageChooseApn.qml 2015-03-25 15:10:25 +0000
4@@ -52,31 +52,6 @@
5 property bool __suppressActivation : true;
6 property bool __haveCustomContexts : false;
7
8- function isEmptyCustom (type, ctx)
9- {
10- /* OK, this sucks _hard_,
11- * QOfono does not return the added context, so instead we have to "figure it out"
12- * by looking for "contextAdded" for totally empty context with default Name values.
13- * LP(#1361864)
14- */
15-
16- var targetName = "";
17- var targetAccessPointName = "";
18- if (type === "internet") {
19- targetName = "Internet";
20- targetAccessPointName = "";
21- } else if (type == "mms") {
22- targetName = "MMS";
23- targetAccessPointName = "";
24- }
25-
26- if (ctx.type === type &&
27- ctx.name === targetName &&
28- ctx.accessPointName === targetAccessPointName)
29- return true;
30- return false;
31- }
32-
33 function updateContexts(contexts)
34 {
35 var tmp = contexts || sim.connMan.contexts.slice(0);
36@@ -113,7 +88,6 @@
37 if (mContexts[currentValue] !== undefined) {
38 throw "updateContexts: added is broken";
39 }
40-
41 var ctx = connCtx.createObject(parent,
42 {
43 "contextPath": currentValue
44@@ -138,15 +112,26 @@
45
46 // expects updateContexts() to have ran before executing.
47 function checkAndCreateCustomContexts() {
48+
49+ // When a context is added, we assume it is a custom one.
50+ function addedCustomContext (path) {
51+
52+ // We do not have a QML object representing this context,
53+ // so we ask updateContexts to create one.
54+ if (!d.mContexts[path]) {
55+ d.updateContexts();
56+ }
57+ d.mContexts[path].name = mCustomContextNameInternet;
58+ sim.connMan.contextAdded.disconnect(addedCustomContext);
59+ }
60+
61 var customInternet = Object.keys(mContexts).filter(function (i) {
62 var ctx = mContexts[i];
63- return ctx.name === mCustomContextNameInternet ||
64- isEmptyCustom("internet", ctx);
65+ return ctx.name === mCustomContextNameInternet;
66 });
67 var customMms = Object.keys(mContexts).filter(function (i) {
68 var ctx = mContexts[i];
69- return ctx.name === mCustomContextNameMms ||
70- isEmptyCustom("mms", ctx);
71+ return ctx.name === mCustomContextNameMms;
72 });
73
74 // make sure there is only one context per type
75@@ -167,6 +152,9 @@
76
77 if (customInternet.length === 0) {
78 sim.connMan.addContext("internet");
79+ sim.connMan.contextAdded.connect(addedCustomContext);
80+ } else {
81+ d.__haveCustomContexts = true;
82 }
83
84 // @bug don't create the custom MMS context
85@@ -304,9 +292,12 @@
86
87 onActiveChanged: if (type === "internet") internetApnSelector.updateSelectedIndex()
88 onNameChanged: {
89- if (name === "Internet") {
90- this.name = d.mCustomContextNameInternet;
91- } else if (name === "MMS") {
92+
93+ if (name === d.mCustomContextNameInternet) {
94+ d.__haveCustomContexts = true;
95+ }
96+
97+ if (name === "MMS") {
98 this.name = d.mCustomContextNameMms;
99 this.accessPointName = d.pendingCustomMmsData["accessPointName"];
100 this.username = d.pendingCustomMmsData["username"];
101@@ -434,12 +425,27 @@
102 text: i18n.tr("Custom Internet APN…")
103 width: parent.width - units.gu(4)
104 onClicked: {
105- if (!d.__haveCustomContexts) {
106+
107+ function contextAdded (path) {
108+ d.updateContexts();
109+
110+ if (d.mContexts[path]) {
111+ d.mCustomContextInternet = d.mContexts[path];
112+ }
113+ d.openApnEditor("internet")
114+ d.contextsChanged.disconnect(contextAdded);
115+ }
116+
117+ if (d.__haveCustomContexts) {
118+ d.openApnEditor("internet")
119+ } else {
120 d.checkAndCreateCustomContexts();
121 d.__haveCustomContexts = true;
122+
123+ // We defer opening the editor until we have
124+ // added the custom context to mContexts
125+ sim.connMan.contextAdded.connect(contextAdded);
126 }
127-
128- d.openApnEditor("internet")
129 }
130 }
131

Subscribers

People subscribed via source and target branches