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

Proposed by Jonas G. Drange
Status: Merged
Approved by: Ken VanDine
Approved revision: 1006
Merged at revision: 1006
Proposed branch: lp:~jonas-drange/ubuntu-system-settings/apn-no-overwrite-1415495-rtm
Merge into: lp:ubuntu-system-settings/rtm-14.09
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-rtm
Reviewer Review Type Date Requested Status
Ken VanDine Approve
PS Jenkins bot continuous-integration Approve
Review via email: mp+254129@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/APN was really a recently added custom context/APNs (by the user). I have made this logic more precise by using a temporary event handler on ConnectionManager's contextAdded.

How to test:

Note: If you have special a special APN configuration, please back up the gprs file at /var/lib/ofono/<IMSI>/gprs

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)

Note: If you have a krillin device, you need to set env vars to start ofono.
sudo service ofono start OFONO_RIL_DEVICE=mtk OFONO_RIL_NUM_SIM_SLOTS=2

Note: If you have an arale device, you just need:
sudo service ofono start OFONO_RIL_DEVICE=mtk

4. Wait 5 secs. Confirm that the output of /usr/share/ofono/scripts/list-contexts/APNs are what you'd expect.
5. Enter the APN page
6. Add a custom context/APN and confirm it is not overwriting anything; or, that the output of $ /usr/share/ofono/scripts/list-contexts # looks like [2].

[1] https://launchpadlibrarian.net/196032938/gprs
[2] http://pastebin.ubuntu.com/10712804/

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

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'plugins/cellular/PageChooseApn.qml'
--- plugins/cellular/PageChooseApn.qml 2015-02-16 13:45:07 +0000
+++ plugins/cellular/PageChooseApn.qml 2015-03-25 17:50:05 +0000
@@ -52,31 +52,6 @@
52 property bool __suppressActivation : true;52 property bool __suppressActivation : true;
53 property bool __haveCustomContexts : false;53 property bool __haveCustomContexts : false;
5454
55 function isEmptyCustom (type, ctx)
56 {
57 /* OK, this sucks _hard_,
58 * QOfono does not return the added context, so instead we have to "figure it out"
59 * by looking for "contextAdded" for totally empty context with default Name values.
60 * LP(#1361864)
61 */
62
63 var targetName = "";
64 var targetAccessPointName = "";
65 if (type === "internet") {
66 targetName = "Internet";
67 targetAccessPointName = "";
68 } else if (type == "mms") {
69 targetName = "MMS";
70 targetAccessPointName = "";
71 }
72
73 if (ctx.type === type &&
74 ctx.name === targetName &&
75 ctx.accessPointName === targetAccessPointName)
76 return true;
77 return false;
78 }
79
80 function updateContexts(contexts)55 function updateContexts(contexts)
81 {56 {
82 var tmp = contexts || sim.connMan.contexts.slice(0);57 var tmp = contexts || sim.connMan.contexts.slice(0);
@@ -113,7 +88,6 @@
113 if (mContexts[currentValue] !== undefined) {88 if (mContexts[currentValue] !== undefined) {
114 throw "updateContexts: added is broken";89 throw "updateContexts: added is broken";
115 }90 }
116
117 var ctx = connCtx.createObject(parent,91 var ctx = connCtx.createObject(parent,
118 {92 {
119 "contextPath": currentValue93 "contextPath": currentValue
@@ -138,15 +112,26 @@
138112
139 // expects updateContexts() to have ran before executing.113 // expects updateContexts() to have ran before executing.
140 function checkAndCreateCustomContexts() {114 function checkAndCreateCustomContexts() {
115
116 // When a context is added, we assume it is a custom one.
117 function addedCustomContext (path) {
118
119 // We do not have a QML object representing this context,
120 // so we ask updateContexts to create one.
121 if (!d.mContexts[path]) {
122 d.updateContexts();
123 }
124 d.mContexts[path].name = mCustomContextNameInternet;
125 sim.connMan.contextAdded.disconnect(addedCustomContext);
126 }
127
141 var customInternet = Object.keys(mContexts).filter(function (i) {128 var customInternet = Object.keys(mContexts).filter(function (i) {
142 var ctx = mContexts[i];129 var ctx = mContexts[i];
143 return ctx.name === mCustomContextNameInternet ||130 return ctx.name === mCustomContextNameInternet;
144 isEmptyCustom("internet", ctx);
145 });131 });
146 var customMms = Object.keys(mContexts).filter(function (i) {132 var customMms = Object.keys(mContexts).filter(function (i) {
147 var ctx = mContexts[i];133 var ctx = mContexts[i];
148 return ctx.name === mCustomContextNameMms ||134 return ctx.name === mCustomContextNameMms;
149 isEmptyCustom("mms", ctx);
150 });135 });
151136
152 // make sure there is only one context per type137 // make sure there is only one context per type
@@ -167,6 +152,9 @@
167152
168 if (customInternet.length === 0) {153 if (customInternet.length === 0) {
169 sim.connMan.addContext("internet");154 sim.connMan.addContext("internet");
155 sim.connMan.contextAdded.connect(addedCustomContext);
156 } else {
157 d.__haveCustomContexts = true;
170 }158 }
171159
172 // @bug don't create the custom MMS context160 // @bug don't create the custom MMS context
@@ -304,9 +292,12 @@
304292
305 onActiveChanged: if (type === "internet") internetApnSelector.updateSelectedIndex()293 onActiveChanged: if (type === "internet") internetApnSelector.updateSelectedIndex()
306 onNameChanged: {294 onNameChanged: {
307 if (name === "Internet") {295
308 this.name = d.mCustomContextNameInternet;296 if (name === d.mCustomContextNameInternet) {
309 } else if (name === "MMS") {297 d.__haveCustomContexts = true;
298 }
299
300 if (name === "MMS") {
310 this.name = d.mCustomContextNameMms;301 this.name = d.mCustomContextNameMms;
311 this.accessPointName = d.pendingCustomMmsData["accessPointName"];302 this.accessPointName = d.pendingCustomMmsData["accessPointName"];
312 this.username = d.pendingCustomMmsData["username"];303 this.username = d.pendingCustomMmsData["username"];
@@ -434,12 +425,27 @@
434 text: i18n.tr("Custom Internet APN…")425 text: i18n.tr("Custom Internet APN…")
435 width: parent.width - units.gu(4)426 width: parent.width - units.gu(4)
436 onClicked: {427 onClicked: {
437 if (!d.__haveCustomContexts) {428
429 function contextAdded (path) {
430 d.updateContexts();
431
432 if (d.mContexts[path]) {
433 d.mCustomContextInternet = d.mContexts[path];
434 }
435 d.openApnEditor("internet")
436 d.contextsChanged.disconnect(contextAdded);
437 }
438
439 if (d.__haveCustomContexts) {
440 d.openApnEditor("internet")
441 } else {
438 d.checkAndCreateCustomContexts();442 d.checkAndCreateCustomContexts();
439 d.__haveCustomContexts = true;443 d.__haveCustomContexts = true;
444
445 // We defer opening the editor until we have
446 // added the custom context to mContexts
447 sim.connMan.contextAdded.connect(contextAdded);
440 }448 }
441
442 d.openApnEditor("internet")
443 }449 }
444 }450 }
445451

Subscribers

People subscribed via source and target branches