Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Commit

Permalink
Merge pull request #18094 from EragonJ/v1.4-bug-962927
Browse files Browse the repository at this point in the history
Merge pull request #16014 from EragonJ/bug-962927
  • Loading branch information
EragonJ committed Apr 9, 2014
2 parents 8c90b65 + ed10a75 commit e1936c7
Show file tree
Hide file tree
Showing 8 changed files with 122 additions and 19 deletions.
1 change: 1 addition & 0 deletions apps/settings/js/call_iccs.js
Expand Up @@ -12,6 +12,7 @@ var IccHandlerForCallSettings = (function(window, document, undefined) {
var CARDSTATE_MAPPING = {
'pinRequired' : 'simCardLockedMsg',
'pukRequired' : 'simCardLockedMsg',
'permanentBlocked': 'simCardBlockedMsg',
'networkLocked' : 'simLockedPhone',
'serviceProviderLocked' : 'simLockedPhone',
'corporateLocked' : 'simLockedPhone',
Expand Down
1 change: 1 addition & 0 deletions apps/settings/js/carrier_iccs.js
Expand Up @@ -12,6 +12,7 @@ var IccHandlerForCarrierSettings = (function(window, document, undefined) {
var CARDSTATE_MAPPING = {
'pinRequired' : 'simCardLockedMsg',
'pukRequired' : 'simCardLockedMsg',
'permanentBlocked': 'simCardBlockedMsg',
'networkLocked' : 'simLockedPhone',
'serviceProviderLocked' : 'simLockedPhone',
'corporateLocked' : 'simLockedPhone',
Expand Down
51 changes: 40 additions & 11 deletions apps/settings/js/simcard_manager.js
Expand Up @@ -36,6 +36,7 @@

this.addVoiceChangeEventOnConns();
this.addCardStateChangeEventOnIccs();
this.addLocalizedChangeEventOnIccs();

// because in fugu, airplaneMode will not change cardState
// but we still have to make UI consistent. In this way,
Expand Down Expand Up @@ -173,7 +174,7 @@
},
initSimCardManagerUI: function() {
this.initSimCardsUI();
this.initSelectOptionsUI();
this.updateSelectOptionsUI();

// we only inject basic DOM from templates before
// , so we have to map UI to its info
Expand Down Expand Up @@ -208,28 +209,27 @@
localize(this.simManagerSecurityDesc);
}
},
initSelectOptionsUI: function() {

updateSelectOptionsUI: function() {
var firstCardInfo = this.simcards[0].getInfo();
var secondCardInfo = this.simcards[1].getInfo();

// two cards all are not absent, we have to update separately
if (!firstCardInfo.absent && !secondCardInfo.absent) {
SimSettingsHelper.getCardIndexFrom('outgoingCall',
function(cardIndex) {
this.initSelectOptionUI('outgoingCall', cardIndex,
this.updateSelectOptionUI('outgoingCall', cardIndex,
this.simManagerOutgoingCallSelect);
}.bind(this));

SimSettingsHelper.getCardIndexFrom('outgoingMessages',
function(cardIndex) {
this.initSelectOptionUI('outgoingMessages', cardIndex,
this.updateSelectOptionUI('outgoingMessages', cardIndex,
this.simManagerOutgoingMessagesSelect);
}.bind(this));

SimSettingsHelper.getCardIndexFrom('outgoingData',
function(cardIndex) {
this.initSelectOptionUI('outgoingData', cardIndex,
this.updateSelectOptionUI('outgoingData', cardIndex,
this.simManagerOutgoingDataSelect);
}.bind(this));
} else {
Expand Down Expand Up @@ -257,15 +257,21 @@
this.simManagerOutgoingDataSelect.disabled = true;

// then change related UI
this.initSelectOptionUI('outgoingCall', selectedCardIndex,
this.updateSelectOptionUI('outgoingCall', selectedCardIndex,
this.simManagerOutgoingCallSelect);
this.initSelectOptionUI('outgoingMessages', selectedCardIndex,
this.updateSelectOptionUI('outgoingMessages', selectedCardIndex,
this.simManagerOutgoingMessagesSelect);
this.initSelectOptionUI('outgoingData', selectedCardIndex,
this.updateSelectOptionUI('outgoingData', selectedCardIndex,
this.simManagerOutgoingDataSelect);
}
},
initSelectOptionUI: function(storageKey, selectedCardIndex, selectDOM) {
updateSelectOptionUI: function(storageKey, selectedCardIndex, selectDOM) {
// We have to remove old options first
while (selectDOM.firstChild) {
selectDOM.removeChild(selectDOM.firstChild);
}

// then insert the new ones
this.simcards.forEach(function(simcard, index) {
var simcardInfo = simcard.getInfo();
var option = document.createElement('option');
Expand Down Expand Up @@ -297,7 +303,6 @@
}
},
isSimCardLocked: function(cardState) {

var lockedState = [
'pinRequired',
'pukRequired',
Expand All @@ -309,6 +314,12 @@
// make sure the card is in locked mode or not
return lockedState.indexOf(cardState) !== -1;
},
isSimCardBlocked: function(cardState) {
var uselessState = [
'permanentBlocked'
];
return uselessState.indexOf(cardState) !== -1;
},
addVoiceChangeEventOnConns: function() {
var conns = window.navigator.mozMobileConnections;
for (var i = 0; i < conns.length; i++) {
Expand All @@ -328,13 +339,29 @@
}
}
},
addLocalizedChangeEventOnIccs: function() {
var conns = window.navigator.mozMobileConnections;
window.addEventListener('localized', function() {
for (var i = 0; i < conns.length; i++) {
var iccId = conns[i].iccId;
this.updateCardStateWithUI(i, iccId);
}
}.bind(this));
},
addChangeEventOnIccByIccId: function(iccId) {
var self = this;
var icc = window.navigator.mozIccManager.getIccById(iccId);
if (icc) {
icc.addEventListener('cardstatechange', function() {
var cardIndex = self.getCardIndexByIccId(iccId);
self.updateCardStateWithUI(cardIndex, iccId);

// If we make PUK locked for more than 10 times,
// we sould get `permanentBlocked` state, in this way
// we have to update select/options
if (self.isSimCardBlocked(icc.cardState)) {
self.updateSelectOptionsUI();
}
});
}
},
Expand Down Expand Up @@ -375,6 +402,8 @@

if (this.isSimCardLocked(cardState)) {
simcard.setState('locked');
} else if (this.isSimCardBlocked(cardState)) {
simcard.setState('blocked');
} else {
// TODO:
// we have to call Gecko API here to make sure the
Expand Down
22 changes: 21 additions & 1 deletion apps/settings/js/simcard_manager_simcard_helper.js
Expand Up @@ -15,7 +15,18 @@
var SimUIModel = function(cardIndex) {
this.cardIndex = cardIndex;

// state list
/*
* We have following states and would try to reflect them on
* related UI. Take `locked` state for example, it doesn't mean
* that this SIm is locked (we have to access icc.cardState
* to make sure the SIM is locked), instead, it means that
* SimCardManager has to show a small `locker` icon on the screen.
*
* The reason why we need this Model is because UX needs different
* look and feel based on different cardState, in this way, I
* think this would be better to use separate propeties to reflect
* each UI on the screen so that we can change them easily.
*/
this.enabled = false;
this.absent = false;
this.locked = false;
Expand Down Expand Up @@ -56,6 +67,15 @@
this.operator = _('sim-pin-locked');
break;

case 'blocked':
this.enabled = true;
this.absent = true;
this.locked = false;
this.number = '';
this.operator = '';
this.name = _('noSimCard');
break;

case 'normal':
this.enabled = true;
this.absent = false;
Expand Down
1 change: 1 addition & 0 deletions apps/settings/js/telephony_items_handler.js
Expand Up @@ -31,6 +31,7 @@ var TelephonyItemsHandler = (function(window, document, undefined) {
var CARD_STATE_MAPPING = {
'pinRequired' : 'simCardLockedMsg',
'pukRequired' : 'simCardLockedMsg',
'permanentBlocked': 'simCardBlockedMsg',
'networkLocked' : 'simLockedPhone',
'serviceProviderLocked' : 'simLockedPhone',
'corporateLocked' : 'simLockedPhone',
Expand Down
1 change: 1 addition & 0 deletions apps/settings/locales/settings.en-US.properties
Expand Up @@ -764,6 +764,7 @@ pinAttemptMsg3[many]=You have {{n}} tries left to enter the correct code before
pinAttemptMsg3[other]=You have {{n}} tries left to enter the correct code before locking the SIM card.
pinLastChanceMsg=This is your last chance to enter the correct PIN. Otherwise, you must enter the PUK code to use this SIM card.
simCardLockedMsg=The SIM card is locked.
simCardBlockedMsg=The SIM card is blocked.
enterPukMsg=You must enter the Personal Unlocking Key (PUK) code for the SIM card. Refer to your SIM card documentation or contact your carrier for more information.
enterPuk2Msg=You must enter the Personal Unlocking Key (PUK2) code for the SIM card. Refer to your SIM card documentation or contact your carrier for more information.
pukErrorMsg=The PUK code is incorrect.
Expand Down
20 changes: 19 additions & 1 deletion apps/settings/test/unit/simcard_manager_simcard_helper_test.js
@@ -1,3 +1,5 @@
/* global requireApp, mocha, suite, suiteSetup, suiteTeardown,
setup, MockL10n, SimUIModel, assert, test */
'use strict';

requireApp('settings/test/unit/mock_l10n.js');
Expand Down Expand Up @@ -51,7 +53,7 @@ suite('SimUIModel', function() {
});
});

suite('lock state > ', function() {
suite('locked state > ', function() {
setup(function() {
fakeSimcard.setState('locked');
});
Expand All @@ -67,6 +69,22 @@ suite('SimUIModel', function() {
});
});

suite('blocked state > ', function() {
setup(function() {
fakeSimcard.setState('blocked');
});

test('set state to blocked successfully', function() {
var cardInfo = fakeSimcard.getInfo();
assert.isTrue(cardInfo.enabled);
assert.isTrue(cardInfo.absent);
assert.isFalse(cardInfo.locked);
assert.equal(cardInfo.name, 'noSimCard');
assert.equal(cardInfo.number, '');
assert.equal(cardInfo.operator, '');
});
});

suite('normal state > ', function() {
var fakeNumber = '0123456789';
var fakeOperator = 'chunghwa telecom';
Expand Down
44 changes: 38 additions & 6 deletions apps/settings/test/unit/simcard_manager_test.js
Expand Up @@ -519,20 +519,20 @@ suite('SimCardManager > ', function() {
suite('initSimCardManagerUI > ', function() {
setup(function() {
this.sinon.stub(SimCardManager, 'initSimCardsUI');
this.sinon.stub(SimCardManager, 'initSelectOptionsUI');
this.sinon.stub(SimCardManager, 'updateSelectOptionsUI');
this.sinon.stub(SimCardManager, 'updateSimCardsUI');
this.sinon.stub(SimCardManager, 'updateSimSecurityUI');
SimCardManager.initSimCardManagerUI();
});
test('all related methods are exectued', function() {
assert.ok(SimCardManager.initSimCardsUI.called);
assert.ok(SimCardManager.initSelectOptionsUI.called);
assert.ok(SimCardManager.updateSelectOptionsUI.called);
assert.ok(SimCardManager.updateSimCardsUI.called);
assert.ok(SimCardManager.updateSimSecurityUI.called);
});
});

suite('initSelectOptionUI > ', function() {
suite('updateSelectOptionUI > ', function() {
var selectedIndex = 1;
var fakeSelect;

Expand All @@ -544,19 +544,19 @@ suite('SimCardManager > ', function() {
});
test('if storageKey is outgoingCall, we would add "always ask" option',
function() {
SimCardManager.initSelectOptionUI('outgoingCall',
SimCardManager.updateSelectOptionUI('outgoingCall',
selectedIndex, fakeSelect);
assert.equal(fakeSelect.length, 3);
});
test('if storageKey is outgoingMessages, we would add "always ask" option',
function() {
SimCardManager.initSelectOptionUI('outgoingMessages',
SimCardManager.updateSelectOptionUI('outgoingMessages',
selectedIndex, fakeSelect);
assert.equal(fakeSelect.length, 3);
});
test('if storageKey is outgoingData, we won\'t add "always ask" option',
function() {
SimCardManager.initSelectOptionUI('outgoingData',
SimCardManager.updateSelectOptionUI('outgoingData',
selectedIndex, fakeSelect);
assert.equal(fakeSelect.length, 2);
});
Expand Down Expand Up @@ -629,6 +629,38 @@ suite('SimCardManager > ', function() {
});
});

suite('We can change options when simcard is blocked', function() {
var fakeLockedIccId = '123456789';

suiteSetup(function() {
sinon.stub(SimCardManager, 'updateCardStateWithUI');
sinon.stub(SimCardManager, 'updateSelectOptionsUI');

window.navigator.mozIccManager.addIcc(fakeLockedIccId, {
'cardState' : 'permanentBlocked'
});

SimCardManager.addChangeEventOnIccByIccId(fakeLockedIccId);

var callback =
window.navigator.mozIccManager.getIccById(
fakeLockedIccId
)._eventListeners.cardstatechange[0];
callback();
});

suiteTeardown(function() {
SimCardManager.updateCardStateWithUI.restore();
SimCardManager.updateSelectOptionsUI.restore();
window.navigator.mozIccManager.removeIcc(fakeLockedIccId);
});

test('change successfully', function() {
assert.isTrue(SimCardManager.updateCardStateWithUI.called);
assert.isTrue(SimCardManager.updateSelectOptionsUI.called);
});
});

// helpers
function initCards(count) {
SimCardManager.simcards = [];
Expand Down

0 comments on commit e1936c7

Please sign in to comment.