Commit ba443b15 authored by Regan Hsu's avatar Regan Hsu Committed by Commit Bot

[CellularSetupUi] Create new CellularSetup and rename old to PsimFlowUi.

* Renames CellularSetup Polymer component to PsimFlowUi.
* CellularSetup now includes an IronPages element that can switch
  between the PsimFlowUi, EsimFlowUi (to be written), and
  SetupFlowSelectionPage (to be written).
* Moves ButtonBar into new CellularSetup.

Bug: 1093185
Change-Id: I69bc4fd331cedab6cc28b4068ed613a6ad097656
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2324068Reviewed-by: default avatarKyle Horimoto <khorimoto@chromium.org>
Reviewed-by: default avatarAzeem Arshad <azeemarshad@chromium.org>
Commit-Queue: Regan Hsu <hsuregan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#793720}
parent 02f92da5
...@@ -14,6 +14,7 @@ js_type_check("closure_compile") { ...@@ -14,6 +14,7 @@ js_type_check("closure_compile") {
":final_page", ":final_page",
":mojo_interface_provider", ":mojo_interface_provider",
":provisioning_page", ":provisioning_page",
":psim_flow_ui",
":sim_detect_page", ":sim_detect_page",
":webview_post_util", ":webview_post_util",
] ]
...@@ -53,9 +54,8 @@ js_library("final_page") { ...@@ -53,9 +54,8 @@ js_library("final_page") {
deps = [ ":base_page" ] deps = [ ":base_page" ]
} }
js_library("cellular_setup") { js_library("psim_flow_ui") {
deps = [ deps = [
":button_bar",
":final_page", ":final_page",
":mojo_interface_provider", ":mojo_interface_provider",
":provisioning_page", ":provisioning_page",
...@@ -65,6 +65,13 @@ js_library("cellular_setup") { ...@@ -65,6 +65,13 @@ js_library("cellular_setup") {
] ]
} }
js_library("cellular_setup") {
deps = [
":button_bar",
":psim_flow_ui",
]
}
js_library("mojo_interface_provider") { js_library("mojo_interface_provider") {
deps = [ deps = [
"//chromeos/services/cellular_setup/public/mojom:mojom_js_library_for_compile", "//chromeos/services/cellular_setup/public/mojom:mojom_js_library_for_compile",
......
<link rel="import" href="../../../html/polymer.html"> <link rel="import" href="../../../html/polymer.html">
<link rel="import" href="../../../html/i18n_behavior.html">
<link rel="import" href="mojo_interface_provider.html">
<link rel="import" href="button_bar.html"> <link rel="import" href="button_bar.html">
<link rel="import" href="sim_detect_page.html"> <link rel="import" href="psim_flow_ui.html">
<link rel="import" href="provisioning_page.html">
<link rel="import" href="final_page.html">
<link rel="import" href="chrome://resources/polymer/v1_0/iron-flex-layout/iron-flex-layout.html">
<link rel="import" href="chrome://resources/polymer/v1_0/iron-flex-layout/iron-flex-layout-classes.html">
<link rel="import" href="chrome://resources/polymer/v1_0/iron-pages/iron-pages.html"> <link rel="import" href="chrome://resources/polymer/v1_0/iron-pages/iron-pages.html">
<dom-module id="cellular-setup"> <dom-module id="cellular-setup">
<template> <template>
<style include="iron-flex"> <style>
:host { :host {
display: flex;
flex: 1 1 auto; flex: 1 1 auto;
flex-direction: column;
padding: 10px; padding: 10px;
} }
iron-pages {
display: flex;
flex: 1 1 auto;
}
</style> </style>
<iron-pages attr-for-selected="is" <iron-pages attr-for-selected="is"
selected="[[selectedPageName_]]" selected="[[selectedPageName_]]">
selected-item="{{selectedPage_}}"> <!-- TODO(hsuregan): Implement <setup-flow-selection>. -->
<sim-detect-page show-error="[[showError_]]"></sim-detect-page> <psim-flow-ui></psim-flow-ui>
<provisioning-page show-error="{{showError_}}" <!-- TODO(hsuregan): Implement <esim-flow>. -->
cellular-metadata="[[cellularMetadata_]]"
on-carrier-portal-loaded="onCarrierPortalLoaded_"
on-carrier-portal-result="onCarrierPortalResult_">
</provisioning-page>
<final-page show-error="[[showError_]]"></final-page>
</iron-pages> </iron-pages>
<button-bar show-try-again-button="[[showTryAgainButton_]]" <button-bar show-try-again-button="[[showTryAgainButton_]]"
show-finish-button="[[showFinishButton_]]" show-finish-button="[[showFinishButton_]]"
show-cancel-button="[[showCancelButton_]]"></button-bar> show-cancel-button="[[showCancelButton_]]">
</button-bar>
</template> </template>
<script src="cellular_setup.js"> <script src="cellular_setup.js">
</script> </script>
......
// Copyright 2019 The Chromium Authors. All rights reserved. // Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
cr.define('cellularSetup', function() { cr.define('cellularSetup', function() {
/** @enum{string} */ /** @enum{string} */
const PageName = { const CellularSetupPageName = {
SIM_DETECT: 'sim-detect-page', PSIM_FLOW_UI: 'psim-flow-ui',
PROVISIONING: 'provisioning-page',
FINAL: 'final-page',
}; };
/** @enum{string} */
const State = {
IDLE: 'idle',
STARTING_ACTIVATION: 'starting-activation',
WAITING_FOR_ACTIVATION_TO_START: 'waiting-for-activation-to-start',
TIMEOUT_START_ACTIVATION: 'timeout-start-activation',
WAITING_FOR_PORTAL_TO_LOAD: 'waiting-for-portal-to-load',
TIMEOUT_PORTAL_LOAD: 'timeout-portal-load',
WAITING_FOR_USER_PAYMENT: 'waiting-for-user-payment',
WAITING_FOR_ACTIVATION_TO_FINISH: 'waiting-for-activation-to-finish',
TIMEOUT_FINISH_ACTIVATION: 'timeout-finish-activation',
ACTIVATION_SUCCESS: 'activation-success',
ALREADY_ACTIVATED: 'already-activated',
ACTIVATION_FAILURE: 'activation-failure',
};
/**
* @param {!cellularSetup.State} state
* @return {?number} The time delta, in ms, for the timeout corresponding to
* |state|. If no timeout is applicable for this state, null is returned.
*/
function getTimeoutMsForState(state) {
// In some cases, starting activation may require power-cycling the device's
// modem, a process that can take several seconds.
if (state === State.STARTING_ACTIVATION) {
return 10000; // 10 seconds.
}
// The portal is a website served by the mobile carrier.
if (state === State.WAITING_FOR_PORTAL_TO_LOAD) {
return 10000; // 10 seconds.
}
// Finishing activation only requires sending a D-Bus message to Shill.
if (state === State.WAITING_FOR_ACTIVATION_TO_FINISH) {
return 1000; // 1 second.
}
// No other states require timeouts.
return null;
}
return { return {
PageName: PageName, CellularSetupPageName: CellularSetupPageName,
State: State,
getTimeoutMsForState: getTimeoutMsForState
}; };
}); });
/** /**
* Root element for the cellular setup flow. This element interacts with the * @fileoverview Root element for the cellular setup flow. This element wraps
* CellularSetup service to carry out the activation flow. It contains * the psim setup flow, esim setup flow, and setup flow selection page.
* navigation buttons and sub-pages corresponding to each step of the flow.
*/ */
Polymer({ Polymer({
is: 'cellular-setup', is: 'cellular-setup',
behaviors: [I18nBehavior],
properties: { properties: {
/** @private {!cellularSetup.State} */
state_: {
type: String,
value: cellularSetup.State.IDLE,
},
/** /**
* Element name of the current selected sub-page. * Element name of the current selected sub-page.
* @private {!cellularSetup.PageName} * @private {!cellularSetup.CellularSetupPageName}
*/ */
selectedPageName_: { selectedPageName_: {
type: String, type: String,
value: cellularSetup.PageName.SIM_DETECT, value: cellularSetup.CellularSetupPageName.PSIM_FLOW_UI,
notify: true, notify: true,
}, }
/**
* DOM Element for the current selected sub-page.
* @private {!SimDetectPageElement|!ProvisioningPageElement|
* !FinalPageElement}
*/
selectedPage_: Object,
/**
* Whether error state should be shown for the current page.
* @private {boolean}
*/
showError_: {type: Boolean, value: false},
/**
* Cellular metadata received via the onActivationStarted() callback. If
* that callback has not occurred, this field is null.
* @private {?chromeos.cellularSetup.mojom.CellularMetadata}
*/
cellularMetadata_: {
type: Object,
value: null,
},
/**
* Whether try again should be shown in the button bar.
* @private {boolean}
*/
showTryAgainButton_: {type: Boolean, value: false},
/**
* Whether finish button should be shown in the button bar.
* @private {boolean}
*/
showFinishButton_: {type: Boolean, value: false},
/**
* Whether cancel button should be shown in the button bar.
* @private {boolean}
*/
showCancelButton_: {type: Boolean, value: false}
}, },
observers: [
'updateShowError_(state_)',
'updateSelectedPage_(state_)',
'handleStateChange_(state_)',
],
listeners: { listeners: {
'backward-nav-requested': 'onBackwardNavRequested_', 'backward-nav-requested': 'onBackwardNavRequested_',
'retry-requested': 'onRetryRequested_', 'retry-requested': 'onRetryRequested_',
'complete-flow-requested': 'onCompleteFlowRequested_', 'complete-flow-requested': 'onCompleteFlowRequested_',
}, },
/**
* Provides an interface to the CellularSetup Mojo service.
* @private {?cellular_setup.MojoInterfaceProvider}
*/
mojoInterfaceProvider_: null,
/**
* Delegate responsible for routing activation started/finished events.
* @private {?chromeos.cellularSetup.mojom.ActivationDelegateReceiver}
*/
activationDelegateReceiver_: null,
/**
* The timeout ID corresponding to a timeout for the current state. If no
* timeout is active, this value is null.
* @private {?number}
*/
currentTimeoutId_: null,
/**
* Handler used to communicate state updates back to the CellularSetup
* service.
* @private {?chromeos.cellularSetup.mojom.CarrierPortalHandlerRemote}
*/
carrierPortalHandler_: null,
/** @override */
created() {
this.mojoInterfaceProvider_ =
cellular_setup.MojoInterfaceProviderImpl.getInstance();
},
/** @override */
ready() {
this.state_ = cellularSetup.State.STARTING_ACTIVATION;
},
/**
* Overrides chromeos.cellularSetup.mojom.ActivationDelegateInterface.
* @param {!chromeos.cellularSetup.mojom.CellularMetadata} metadata
* @private
*/
onActivationStarted(metadata) {
this.clearTimer_();
this.cellularMetadata_ = metadata;
this.state_ = cellularSetup.State.WAITING_FOR_PORTAL_TO_LOAD;
},
/**
* Overrides chromeos.cellularSetup.mojom.ActivationDelegateInterface.
* @param {!chromeos.cellularSetup.mojom.ActivationResult} result
* @private
*/
onActivationFinished(result) {
this.closeActivationConnection_();
const ActivationResult = chromeos.cellularSetup.mojom.ActivationResult;
switch (result) {
case ActivationResult.kSuccessfullyStartedActivation:
this.state_ = cellularSetup.State.ALREADY_ACTIVATED;
break;
case ActivationResult.kAlreadyActivated:
this.state_ = cellularSetup.State.ACTIVATION_SUCCESS;
break;
case ActivationResult.kFailedToActivate:
this.state_ = cellularSetup.State.ACTIVATION_FAILURE;
break;
default:
assertNotReached();
}
},
/** @private */
updateShowError_() {
switch (this.state_) {
case cellularSetup.State.TIMEOUT_START_ACTIVATION:
case cellularSetup.State.TIMEOUT_PORTAL_LOAD:
case cellularSetup.State.TIMEOUT_FINISH_ACTIVATION:
case cellularSetup.State.ACTIVATION_FAILURE:
this.showError_ = true;
return;
default:
this.showError_ = false;
return;
}
},
/** @private */
updateSelectedPage_() {
switch (this.state_) {
case cellularSetup.State.IDLE:
case cellularSetup.State.STARTING_ACTIVATION:
case cellularSetup.State.WAITING_FOR_ACTIVATION_TO_START:
case cellularSetup.State.TIMEOUT_START_ACTIVATION:
this.selectedPageName_ = cellularSetup.PageName.SIM_DETECT;
return;
case cellularSetup.State.WAITING_FOR_PORTAL_TO_LOAD:
case cellularSetup.State.TIMEOUT_PORTAL_LOAD:
case cellularSetup.State.WAITING_FOR_USER_PAYMENT:
this.selectedPageName_ = cellularSetup.PageName.PROVISIONING;
return;
case cellularSetup.State.WAITING_FOR_ACTIVATION_TO_FINISH:
case cellularSetup.State.TIMEOUT_FINISH_ACTIVATION:
case cellularSetup.State.ACTIVATION_SUCCESS:
case cellularSetup.State.ALREADY_ACTIVATED:
case cellularSetup.State.ACTIVATION_FAILURE:
this.selectedPageName_ = cellularSetup.PageName.FINAL;
return;
default:
assertNotReached();
}
},
/** @private */
handleStateChange_() {
// Since the state has changed, the previous state did not time out, so
// clear any active timeout.
this.clearTimer_();
// If the new state has an associated timeout, set it.
const timeoutMs = cellularSetup.getTimeoutMsForState(this.state_);
if (timeoutMs !== null) {
this.currentTimeoutId_ =
setTimeout(this.onTimeout_.bind(this), timeoutMs);
}
if (this.state_ === cellularSetup.State.STARTING_ACTIVATION) {
this.startActivation_();
return;
}
},
/** @private */
onTimeout_() {
// The activation attempt failed, so close the connection to the service.
this.closeActivationConnection_();
switch (this.state_) {
case cellularSetup.State.STARTING_ACTIVATION:
this.state_ = cellularSetup.State.TIMEOUT_START_ACTIVATION;
return;
case cellularSetup.State.WAITING_FOR_PORTAL_TO_LOAD:
this.state_ = cellularSetup.State.TIMEOUT_PORTAL_LOAD;
return;
case cellularSetup.State.WAITING_FOR_ACTIVATION_TO_FINISH:
this.state_ = cellularSetup.State.TIMEOUT_FINISH_ACTIVATION;
return;
default:
// Only the above states are expected to time out.
assertNotReached();
}
},
/** @private */
startActivation_() {
assert(!this.activationDelegateReceiver_);
this.activationDelegateReceiver_ =
new chromeos.cellularSetup.mojom.ActivationDelegateReceiver(
/**
* @type {!chromeos.cellularSetup.mojom.ActivationDelegateInterface}
*/
(this));
this.mojoInterfaceProvider_.getMojoServiceRemote()
.startActivation(
this.activationDelegateReceiver_.$.bindNewPipeAndPassRemote())
.then(
/**
* @param {!chromeos.cellularSetup.
* mojom.CellularSetup_StartActivation_ResponseParams}
* params
*/
(params) => {
this.carrierPortalHandler_ = params.observer;
});
},
/** @private */
closeActivationConnection_() {
assert(!!this.activationDelegateReceiver_);
this.activationDelegateReceiver_.$.close();
this.activationDelegateReceiver_ = null;
this.carrierPortalHandler_ = null;
this.cellularMetadata_ = null;
},
/** @private */
clearTimer_() {
if (this.currentTimeoutId_) {
clearTimeout(this.currentTimeoutId_);
}
this.currentTimeoutId_ = null;
},
/** @private */
onCarrierPortalLoaded_() {
this.state_ = cellularSetup.State.WAITING_FOR_USER_PAYMENT;
this.carrierPortalHandler_.onCarrierPortalStatusChange(
chromeos.cellularSetup.mojom.CarrierPortalStatus
.kPortalLoadedWithoutPaidUser);
},
/**
* @param {!CustomEvent<boolean>} event
* @private
*/
onCarrierPortalResult_(event) {
const success = event.detail;
this.state_ = success ? cellularSetup.State.ACTIVATION_SUCCESS :
cellularSetup.State.ACTIVATION_FAILURE;
},
/** @private */ /** @private */
onBackwardNavRequested_() { onBackwardNavRequested_() {
// TODO(azeemarshad): Add back navigation. // TODO(crbug.com/1093185): Add back navigation.
}, },
/** @private */ /** @private */
onRetryRequested_() { onRetryRequested_() {
// TODO(azeemarshad): Add try again logic. // TODO(crbug.com/1093185): Add try again logic.
}, },
/** @private */ /** @private */
onCompleteFlowRequested__() { onCompleteFlowRequested_() {
// TODO(azeemarshad): Add completion logic. // TODO(crbug.com/1093185): Add completion logic.
}, },
}); });
<link rel="import" href="../../../html/polymer.html">
<link rel="import" href="../../../html/i18n_behavior.html">
<link rel="import" href="mojo_interface_provider.html">
<link rel="import" href="sim_detect_page.html">
<link rel="import" href="provisioning_page.html">
<link rel="import" href="final_page.html">
<link rel="import" href="chrome://resources/polymer/v1_0/iron-flex-layout/iron-flex-layout.html">
<link rel="import" href="chrome://resources/polymer/v1_0/iron-flex-layout/iron-flex-layout-classes.html">
<link rel="import" href="chrome://resources/polymer/v1_0/iron-pages/iron-pages.html">
<dom-module id="psim-flow-ui">
<template>
<style include="iron-flex">
:host {
display: flex;
flex: 1 1 auto;
flex-direction: column;
}
</style>
<iron-pages attr-for-selected="is"
selected="[[selectedPSimPageName_]]"
selected-item="{{selectedPage_}}">
<sim-detect-page show-error="[[showError_]]"></sim-detect-page>
<provisioning-page show-error="{{showError_}}"
cellular-metadata="[[cellularMetadata_]]"
on-carrier-portal-loaded="onCarrierPortalLoaded_"
on-carrier-portal-result="onCarrierPortalResult_">
</provisioning-page>
<final-page show-error="[[showError_]]"></final-page>
</iron-pages>
</template>
<script src="psim_flow_ui.js">
</script>
</dom-module>
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
cr.define('cellularSetup', function() {
/** @enum{string} */
const PSimPageName = {
SIM_DETECT: 'sim-detect-page',
PROVISIONING: 'provisioning-page',
FINAL: 'final-page',
};
/** @enum{string} */
const PSimUIState = {
IDLE: 'idle',
STARTING_ACTIVATION: 'starting-activation',
WAITING_FOR_ACTIVATION_TO_START: 'waiting-for-activation-to-start',
TIMEOUT_START_ACTIVATION: 'timeout-start-activation',
WAITING_FOR_PORTAL_TO_LOAD: 'waiting-for-portal-to-load',
TIMEOUT_PORTAL_LOAD: 'timeout-portal-load',
WAITING_FOR_USER_PAYMENT: 'waiting-for-user-payment',
WAITING_FOR_ACTIVATION_TO_FINISH: 'waiting-for-activation-to-finish',
TIMEOUT_FINISH_ACTIVATION: 'timeout-finish-activation',
ACTIVATION_SUCCESS: 'activation-success',
ALREADY_ACTIVATED: 'already-activated',
ACTIVATION_FAILURE: 'activation-failure',
};
/**
* @param {!cellularSetup.PSimUIState} state
* @return {?number} The time delta, in ms, for the timeout corresponding to
* |state|. If no timeout is applicable for this state, null is returned.
*/
function getTimeoutMsForPSimUIState(state) {
// In some cases, starting activation may require power-cycling the device's
// modem, a process that can take several seconds.
if (state === PSimUIState.STARTING_ACTIVATION) {
return 10000; // 10 seconds.
}
// The portal is a website served by the mobile carrier.
if (state === PSimUIState.WAITING_FOR_PORTAL_TO_LOAD) {
return 10000; // 10 seconds.
}
// Finishing activation only requires sending a D-Bus message to Shill.
if (state === PSimUIState.WAITING_FOR_ACTIVATION_TO_FINISH) {
return 1000; // 1 second.
}
// No other states require timeouts.
return null;
}
return {
PSimPageName: PSimPageName,
PSimUIState: PSimUIState,
getTimeoutMsForPSimUIState: getTimeoutMsForPSimUIState
};
});
/**
* Root element for the pSIM cellular setup flow. This element interacts with
* the CellularSetup service to carry out the psim activation flow. It contains
* navigation buttons and sub-pages corresponding to each step of the flow.
*/
Polymer({
is: 'psim-flow-ui',
behaviors: [I18nBehavior],
properties: {
/** @private {!cellularSetup.PSimUIState} */
state_: {
type: String,
value: cellularSetup.PSimUIState.IDLE,
},
/**
* Element name of the current selected sub-page.
* @private {!cellularSetup.PSimPageName}
*/
selectedPSimPageName_: {
type: String,
value: cellularSetup.PSimPageName.SIM_DETECT,
notify: true,
},
/**
* DOM Element for the current selected sub-page.
* @private {!SimDetectPageElement|!ProvisioningPageElement|
* !FinalPageElement}
*/
selectedPage_: Object,
/**
* Whether error state should be shown for the current page.
* @private {boolean}
*/
showError_: {type: Boolean, value: false},
/**
* Cellular metadata received via the onActivationStarted() callback. If
* that callback has not occurred, this field is null.
* @private {?chromeos.cellularSetup.mojom.CellularMetadata}
*/
cellularMetadata_: {
type: Object,
value: null,
},
/**
* Whether try again should be shown in the button bar.
* @private {boolean}
*/
showTryAgainButton_: {type: Boolean, value: false},
/**
* Whether finish button should be shown in the button bar.
* @private {boolean}
*/
showFinishButton_: {type: Boolean, value: false},
/**
* Whether cancel button should be shown in the button bar.
* @private {boolean}
*/
showCancelButton_: {type: Boolean, value: false}
},
observers: [
'updateShowError_(state_)',
'updateSelectedPage_(state_)',
'handlePSimUIStateChange_(state_)',
],
/**
* Provides an interface to the CellularSetup Mojo service.
* @private {?cellular_setup.MojoInterfaceProvider}
*/
mojoInterfaceProvider_: null,
/**
* Delegate responsible for routing activation started/finished events.
* @private {?chromeos.cellularSetup.mojom.ActivationDelegateReceiver}
*/
activationDelegateReceiver_: null,
/**
* The timeout ID corresponding to a timeout for the current state. If no
* timeout is active, this value is null.
* @private {?number}
*/
currentTimeoutId_: null,
/**
* Handler used to communicate state updates back to the CellularSetup
* service.
* @private {?chromeos.cellularSetup.mojom.CarrierPortalHandlerRemote}
*/
carrierPortalHandler_: null,
/** @override */
created() {
this.mojoInterfaceProvider_ =
cellular_setup.MojoInterfaceProviderImpl.getInstance();
},
/** @override */
ready() {
this.state_ = cellularSetup.PSimUIState.STARTING_ACTIVATION;
},
/**
* Overrides chromeos.cellularSetup.mojom.ActivationDelegateInterface.
* @param {!chromeos.cellularSetup.mojom.CellularMetadata} metadata
* @private
*/
onActivationStarted(metadata) {
this.clearTimer_();
this.cellularMetadata_ = metadata;
this.state_ = cellularSetup.PSimUIState.WAITING_FOR_PORTAL_TO_LOAD;
},
/**
* Overrides chromeos.cellularSetup.mojom.ActivationDelegateInterface.
* @param {!chromeos.cellularSetup.mojom.ActivationResult} result
* @private
*/
onActivationFinished(result) {
this.closeActivationConnection_();
const ActivationResult = chromeos.cellularSetup.mojom.ActivationResult;
switch (result) {
case ActivationResult.kSuccessfullyStartedActivation:
this.state_ = cellularSetup.PSimUIState.ALREADY_ACTIVATED;
break;
case ActivationResult.kAlreadyActivated:
this.state_ = cellularSetup.PSimUIState.ACTIVATION_SUCCESS;
break;
case ActivationResult.kFailedToActivate:
this.state_ = cellularSetup.PSimUIState.ACTIVATION_FAILURE;
break;
default:
assertNotReached();
}
},
/** @private */
updateShowError_() {
switch (this.state_) {
case cellularSetup.PSimUIState.TIMEOUT_START_ACTIVATION:
case cellularSetup.PSimUIState.TIMEOUT_PORTAL_LOAD:
case cellularSetup.PSimUIState.TIMEOUT_FINISH_ACTIVATION:
case cellularSetup.PSimUIState.ACTIVATION_FAILURE:
this.showError_ = true;
return;
default:
this.showError_ = false;
return;
}
},
/** @private */
updateSelectedPage_() {
switch (this.state_) {
case cellularSetup.PSimUIState.IDLE:
case cellularSetup.PSimUIState.STARTING_ACTIVATION:
case cellularSetup.PSimUIState.WAITING_FOR_ACTIVATION_TO_START:
case cellularSetup.PSimUIState.TIMEOUT_START_ACTIVATION:
this.selectedPSimPageName_ = cellularSetup.PSimPageName.SIM_DETECT;
return;
case cellularSetup.PSimUIState.WAITING_FOR_PORTAL_TO_LOAD:
case cellularSetup.PSimUIState.TIMEOUT_PORTAL_LOAD:
case cellularSetup.PSimUIState.WAITING_FOR_USER_PAYMENT:
this.selectedPSimPageName_ = cellularSetup.PSimPageName.PROVISIONING;
return;
case cellularSetup.PSimUIState.WAITING_FOR_ACTIVATION_TO_FINISH:
case cellularSetup.PSimUIState.TIMEOUT_FINISH_ACTIVATION:
case cellularSetup.PSimUIState.ACTIVATION_SUCCESS:
case cellularSetup.PSimUIState.ALREADY_ACTIVATED:
case cellularSetup.PSimUIState.ACTIVATION_FAILURE:
this.selectedPSimPageName_ = cellularSetup.PSimPageName.FINAL;
return;
default:
assertNotReached();
}
},
/** @private */
handlePSimUIStateChange_() {
// Since the state has changed, the previous state did not time out, so
// clear any active timeout.
this.clearTimer_();
// If the new state has an associated timeout, set it.
const timeoutMs = cellularSetup.getTimeoutMsForPSimUIState(this.state_);
if (timeoutMs !== null) {
this.currentTimeoutId_ =
setTimeout(this.onTimeout_.bind(this), timeoutMs);
}
if (this.state_ === cellularSetup.PSimUIState.STARTING_ACTIVATION) {
this.startActivation_();
return;
}
},
/** @private */
onTimeout_() {
// The activation attempt failed, so close the connection to the service.
this.closeActivationConnection_();
switch (this.state_) {
case cellularSetup.PSimUIState.STARTING_ACTIVATION:
this.state_ = cellularSetup.PSimUIState.TIMEOUT_START_ACTIVATION;
return;
case cellularSetup.PSimUIState.WAITING_FOR_PORTAL_TO_LOAD:
this.state_ = cellularSetup.PSimUIState.TIMEOUT_PORTAL_LOAD;
return;
case cellularSetup.PSimUIState.WAITING_FOR_ACTIVATION_TO_FINISH:
this.state_ = cellularSetup.PSimUIState.TIMEOUT_FINISH_ACTIVATION;
return;
default:
// Only the above states are expected to time out.
assertNotReached();
}
},
/** @private */
startActivation_() {
assert(!this.activationDelegateReceiver_);
this.activationDelegateReceiver_ =
new chromeos.cellularSetup.mojom.ActivationDelegateReceiver(
/**
* @type {!chromeos.cellularSetup.mojom.ActivationDelegateInterface}
*/
(this));
this.mojoInterfaceProvider_.getMojoServiceRemote()
.startActivation(
this.activationDelegateReceiver_.$.bindNewPipeAndPassRemote())
.then(
/**
* @param {!chromeos.cellularSetup.
* mojom.CellularSetup_StartActivation_ResponseParams}
* params
*/
(params) => {
this.carrierPortalHandler_ = params.observer;
});
},
/** @private */
closeActivationConnection_() {
assert(!!this.activationDelegateReceiver_);
this.activationDelegateReceiver_.$.close();
this.activationDelegateReceiver_ = null;
this.carrierPortalHandler_ = null;
this.cellularMetadata_ = null;
},
/** @private */
clearTimer_() {
if (this.currentTimeoutId_) {
clearTimeout(this.currentTimeoutId_);
}
this.currentTimeoutId_ = null;
},
/** @private */
onCarrierPortalLoaded_() {
this.state_ = cellularSetup.PSimUIState.WAITING_FOR_USER_PAYMENT;
this.carrierPortalHandler_.onCarrierPortalStatusChange(
chromeos.cellularSetup.mojom.CarrierPortalStatus
.kPortalLoadedWithoutPaidUser);
},
/**
* @param {!CustomEvent<boolean>} event
* @private
*/
onCarrierPortalResult_(event) {
const success = event.detail;
this.state_ = success ? cellularSetup.PSimUIState.ACTIVATION_SUCCESS :
cellularSetup.PSimUIState.ACTIVATION_FAILURE;
},
});
...@@ -134,6 +134,12 @@ ...@@ -134,6 +134,12 @@
<structure name="IDR_WEBUI_CHROMEOS_CELLULAR_SETUP_CELLULAR_SETUP_JS" <structure name="IDR_WEBUI_CHROMEOS_CELLULAR_SETUP_CELLULAR_SETUP_JS"
file="cr_components/chromeos/cellular_setup/cellular_setup.js" file="cr_components/chromeos/cellular_setup/cellular_setup.js"
type="chrome_html" /> type="chrome_html" />
<structure name="IDR_WEBUI_CHROMEOS_CELLULAR_SETUP_PSIM_FLOW_HTML"
file="cr_components/chromeos/cellular_setup/psim_flow_ui.html"
type="chrome_html" />
<structure name="IDR_WEBUI_CHROMEOS_CELLULAR_SETUP_PSIM_FLOW_JS"
file="cr_components/chromeos/cellular_setup/psim_flow_ui.js"
type="chrome_html" />
<structure name="IDR_WEBUI_CHROMEOS_CELLULAR_SETUP_MOJO_INTERFACE_PROVIDER_HTML" <structure name="IDR_WEBUI_CHROMEOS_CELLULAR_SETUP_MOJO_INTERFACE_PROVIDER_HTML"
file="cr_components/chromeos/cellular_setup/mojo_interface_provider.html" file="cr_components/chromeos/cellular_setup/mojo_interface_provider.html"
type="chrome_html" /> type="chrome_html" />
......
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