Commit 62027920 authored by Steven Bennetts's avatar Steven Bennetts Committed by Commit Bot

Settings > Network > SIM lock dialog: fix egde cases and cleanup

Bug: 814274,784804
Cq-Include-Trybots: master.tryserver.chromium.linux:closure_compilation
Change-Id: I50c412d8ff26b5c78fb48834215d0d43277996a6
Reviewed-on: https://chromium-review.googlesource.com/1091804Reviewed-by: default avatarBen Chan <benchan@chromium.org>
Commit-Queue: Steven Bennetts <stevenjb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#566609}
parent 6a353124
......@@ -95,7 +95,7 @@
on-close="onEnterPinDialogClose_">
<div slot="title">[[i18n('networkSimEnterPinTitle')]]</div>
<div slot="body">
<network-password-input id="enterPin"
<network-password-input id="enterPin" value="{{pin_}}"
label="[[i18n('networkSimEnterPin')]]">
<iron-a11y-keys keys="enter" on-keys-pressed="sendEnterPin_">
</iron-a11y-keys>
......@@ -108,7 +108,8 @@
<paper-button class="cancel-button" on-tap="closeDialogs_">
[[i18n('cancel')]]
</paper-button>
<paper-button on-tap="sendEnterPin_" disabled="[[inProgress_]]">
<paper-button class="action-button" on-tap="sendEnterPin_"
disabled="[[!enterPinEnabled_]]">
[[i18n('networkSimEnter')]]
</paper-button>
</div>
......@@ -119,13 +120,13 @@
on-close="onChangePinDialogClose_">
<div slot="title">[[i18n('networkSimChangePinTitle')]]</div>
<div slot="body">
<network-password-input id="changePinOld"
<network-password-input id="changePinOld" value="{{pin_}}"
label="[[i18n('networkSimEnterOldPin')]]">
</network-password-input>
<network-password-input id="changePinNew1"
<network-password-input id="changePinNew1" value="{{pin_new1_}}"
label="[[i18n('networkSimEnterNewPin')]]">
</network-password-input>
<network-password-input id="changePinNew2"
<network-password-input id="changePinNew2" value="{{pin_new2_}}"
label="[[i18n('networkSimReEnterNewPin')]]">
<iron-a11y-keys keys="enter" on-keys-pressed="sendChangePin_">
</iron-a11y-keys>
......@@ -139,7 +140,7 @@
[[i18n('cancel')]]
</paper-button>
<paper-button class="action-button" on-tap="sendChangePin_"
disabled="[[inProgress_]]">
disabled="[[!changePinEnabled_]]">
[[i18n('networkSimChange')]]
</paper-button>
</div>
......@@ -150,7 +151,7 @@
on-close="onUnlockPinDialogClose_">
<div slot="title">[[i18n('networkSimLockedTitle')]]</div>
<div slot="body">
<network-password-input id="unlockPin"
<network-password-input id="unlockPin" value="{{pin_}}"
label="[[i18n('networkSimEnterPin')]]">
<iron-a11y-keys keys="enter" on-keys-pressed="sendUnlockPin_">
</iron-a11y-keys>
......@@ -163,7 +164,8 @@
<paper-button class="cancel-button" on-tap="closeDialogs_">
[[i18n('cancel')]]
</paper-button>
<paper-button on-tap="sendUnlockPin_" disabled="[[inProgress_]]">
<paper-button class="action-button" on-tap="sendUnlockPin_"
disabled="[[!enterPinEnabled_]]">
[[i18n('networkSimUnlock')]]
</paper-button>
</div>
......@@ -177,13 +179,13 @@
<div>
Enter the 8-digit PIN Unblocking Key provided by your carrier
</div>
<network-password-input id="unlockPuk"
<network-password-input id="unlockPuk" value="{{puk_}}"
label="[[i18n('networkSimEnterPuk')]]">
</network-password-input>
<network-password-input id="unlockPin1"
<network-password-input id="unlockPin1" value="{{pin_new1_}}"
label="[[i18n('networkSimEnterNewPin')]]">
</network-password-input>
<network-password-input id="unlockPin2"
<network-password-input id="unlockPin2" value="{{pin_new2_}}"
label="[[i18n('networkSimReEnterNewPin')]]">
<iron-a11y-keys keys="enter" on-keys-pressed="sendUnlockPuk_">
</iron-a11y-keys>
......@@ -199,7 +201,8 @@
<paper-button class="cancel-button" on-tap="closeDialogs_">
[[i18n('cancel')]]
</paper-button>
<paper-button on-tap="sendUnlockPuk_" disabled="[[inProgress_]]">
<paper-button class="action-button" on-tap="sendUnlockPuk_"
disabled="[[!enterPukEnabled_]]">
[[i18n('networkSimUnlock')]]
</paper-button>
</div>
......
......@@ -70,6 +70,7 @@ Polymer({
inProgress_: {
type: Boolean,
value: false,
observer: 'pinOrProgressChange_',
},
/**
......@@ -80,6 +81,35 @@ Polymer({
type: Object,
value: ErrorType.NONE,
},
/**
* Properties enabling pin/puk enter/change buttons.
* @private
*/
enterPinEnabled_: Boolean,
changePinEnabled_: Boolean,
changePukEnabled_: Boolean,
/**
* Properties reflecting pin/puk inputs.
* @private
*/
pin_: {
type: String,
observer: 'pinOrProgressChange_',
},
pin_new1_: {
type: String,
observer: 'pinOrProgressChange_',
},
pin_new2_: {
type: String,
observer: 'pinOrProgressChange_',
},
puk_: {
type: String,
observer: 'pinOrProgressChange_',
},
},
/** @private {boolean} */
......@@ -88,6 +118,14 @@ Polymer({
/** @private {boolean|undefined} */
setLockEnabled_: undefined,
/** @private {boolean} */
simUnlockSent_: false,
/** @override */
attached: function() {
this.simUnlockSent_ = false;
},
/** @override */
detached: function() {
this.closeDialogs_();
......@@ -107,6 +145,18 @@ Polymer({
this.$.unlockPukDialog.close();
},
/** @private */
focusDialogInput_: function() {
if (this.$.enterPinDialog.open)
this.$.enterPin.focus();
else if (this.$.changePinDialog.open)
this.$.changePinOld.focus()();
else if (this.$.unlockPinDialog.open)
this.$.unlockPin.focus();
else if (this.$.unlockPukDialog.open)
this.$.unlockPuk.focus();
},
/** @private */
networkPropertiesChanged_: function() {
if (!this.networkProperties || !this.networkProperties.Cellular)
......@@ -147,6 +197,15 @@ Polymer({
}, TOGGLE_DEBOUNCE_MS);
},
/** @private */
pinOrProgressChange_: function() {
this.enterPinEnabled_ = !this.inProgress_ && !!this.pin_;
this.changePinEnabled_ = !this.inProgress_ && !!this.pin_ &&
!!this.pin_new1_ && !!this.pin_new2_;
this.changePukEnabled_ = !this.inProgress_ && !!this.puk_ &&
!!this.pin_new1_ && !!this.pin_new2_;
},
/** @private */
pukRequiredChanged_: function() {
if (this.$.unlockPukDialog.open) {
......@@ -200,37 +259,73 @@ Polymer({
});
},
/** @private */
setInProgress_: function() {
this.error_ = ErrorType.NONE;
this.inProgress_ = true;
this.simUnlockSent_ = true;
},
/**
* Sends the PIN value from the Enter PIN dialog.
* @param {!Event} event
* @param {!CrOnc.CellularSimState} simState
* @private
*/
sendEnterPin_: function(event) {
event.stopPropagation();
setCellularSimState_: function(simState) {
var guid = (this.networkProperties && this.networkProperties.GUID) || '';
var pin = this.$.enterPin.value;
if (!this.validatePin_(pin)) {
this.onEnterPinDialogCancel_();
return;
}
var simState = /** @type {!CrOnc.CellularSimState} */ ({
currentPin: pin,
requirePin: this.sendSimLockEnabled_,
});
this.inProgress_ = true;
this.setInProgress_();
this.networkingPrivate.setCellularSimState(guid, simState, () => {
this.inProgress_ = false;
if (chrome.runtime.lastError) {
this.error_ = ErrorType.INCORRECT_PIN;
this.$.enterPin.focus();
this.focusDialogInput_();
} else {
this.error_ = ErrorType.NONE;
this.closeDialogs_();
this.delayUpdateLockEnabled_();
}
});
},
/**
* @param {string} pin
* @param {string|undefined} puk
* @private
*/
unlockCellularSim_: function(pin, puk) {
var guid = (this.networkProperties && this.networkProperties.GUID) || '';
this.setInProgress_();
this.networkingPrivate.unlockCellularSim(guid, pin, puk, () => {
this.inProgress_ = false;
if (chrome.runtime.lastError) {
this.error_ = puk ? ErrorType.INCORRECT_PUK : ErrorType.INCORRECT_PIN;
this.focusDialogInput_();
} else {
this.error_ = ErrorType.NONE;
this.$.enterPinDialog.close();
this.$.closeDialogs_();
this.delayUpdateLockEnabled_();
}
});
},
/**
* Sends the PIN value from the Enter PIN dialog.
* @param {!Event} event
* @private
*/
sendEnterPin_: function(event) {
event.stopPropagation();
if (!this.enterPinEnabled_)
return;
var pin = this.$.enterPin.value;
if (!this.validatePin_(pin))
return;
var simState = /** @type {!CrOnc.CellularSimState} */ ({
currentPin: pin,
requirePin: this.sendSimLockEnabled_,
});
this.setCellularSimState_(simState);
},
/**
* Opens the Change PIN dialog.
* @param {!Event} event
......@@ -257,28 +352,15 @@ Polymer({
*/
sendChangePin_: function(event) {
event.stopPropagation();
var guid = (this.networkProperties && this.networkProperties.GUID) || '';
var newPin = this.$.changePinNew1.value;
if (!this.validatePin_(newPin, this.$.changePinNew2.value))
return;
var simState = /** @type {!CrOnc.CellularSimState} */ ({
requirePin: true,
currentPin: this.$.changePinOld.value,
newPin: newPin
});
this.inProgress_ = true;
this.networkingPrivate.setCellularSimState(guid, simState, () => {
this.inProgress_ = false;
if (chrome.runtime.lastError) {
this.error_ = ErrorType.INCORRECT_PIN;
this.$.changePinOld.focus();
} else {
this.error_ = ErrorType.NONE;
this.$.changePinDialog.close();
this.delayUpdateLockEnabled_();
}
});
this.setCellularSimState_(simState);
},
/**
......@@ -302,23 +384,10 @@ Polymer({
*/
sendUnlockPin_: function(event) {
event.stopPropagation();
var guid = (this.networkProperties && this.networkProperties.GUID) || '';
var pin = this.$.unlockPin.value;
if (!this.validatePin_(pin))
return;
this.inProgress_ = true;
this.networkingPrivate.unlockCellularSim(guid, pin, '', () => {
this.inProgress_ = false;
if (chrome.runtime.lastError) {
this.error_ = ErrorType.INCORRECT_PIN;
this.$.unlockPin.focus();
} else {
this.error_ = ErrorType.NONE;
this.$.unlockPinDialog.close();
this.delayUpdateLockEnabled_();
}
});
this.unlockCellularSim_(pin, '');
},
/** @private */
......@@ -350,26 +419,13 @@ Polymer({
*/
sendUnlockPuk_: function(event) {
event.stopPropagation();
var guid = (this.networkProperties && this.networkProperties.GUID) || '';
var puk = this.$.unlockPuk.value;
if (!this.validatePuk_(puk))
return;
var pin = this.$.unlockPin1.value;
if (!this.validatePin_(pin, this.$.unlockPin2.value))
return;
this.inProgress_ = true;
this.networkingPrivate.unlockCellularSim(guid, pin, puk, () => {
this.inProgress_ = false;
if (chrome.runtime.lastError) {
this.error_ = ErrorType.INCORRECT_PUK;
this.$.unlockPuk.focus();
} else {
this.error_ = ErrorType.NONE;
this.$.unlockPukDialog.close();
this.delayUpdateLockEnabled_();
}
});
this.unlockCellularSim_(pin, puk);
},
/**
......@@ -414,7 +470,7 @@ Polymer({
msg = 'Invalid PUK.';
else
return 'UNKNOWN ERROR';
var retriesLeft =
var retriesLeft = this.simUnlockSent_ &&
this.get('Cellular.SIMLockStatus.RetriesLeft', this.networkProperties);
if (retriesLeft) {
msg += ' Retries left: ' + retriesLeft.toString();
......@@ -432,6 +488,8 @@ Polymer({
* @private
*/
validatePin_: function(pin1, opt_pin2) {
if (!pin1.length)
return false;
if (pin1.length < PIN_MIN_LENGTH) {
this.error_ = ErrorType.INVALID_PIN;
return false;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment