Commit 3d5ab8c0 authored by Azeem Arshad's avatar Azeem Arshad Committed by Chromium LUCI CQ

[CrOS Cellular] Use external euicc flag to switch Euicc

This CL adds a getEuicc utility method that automatically
selects the Euicc object to be used based on the useExternalEuicc
flag.

Fixed: 1166697
Change-Id: Ia6d962275365f6a347ee6687fe78a497eb5c79b2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2630739
Commit-Queue: Azeem Arshad <azeemarshad@chromium.org>
Reviewed-by: default avatarKyle Horimoto <khorimoto@chromium.org>
Cr-Commit-Position: refs/heads/master@{#844351}
parent e62e05f2
......@@ -223,6 +223,7 @@ js_library("cellular_networks_list") {
js_library("esim_rename_dialog") {
deps = [
"//ui/webui/resources/cr_components/chromeos/cellular_setup:esim_manager_utils",
"//ui/webui/resources/cr_components/chromeos/cellular_setup:mojo_interface_provider",
"//ui/webui/resources/cr_components/chromeos/network:mojo_interface_provider",
"//ui/webui/resources/cr_elements/cr_dialog:cr_dialog",
......@@ -233,6 +234,7 @@ js_library("esim_rename_dialog") {
js_library("esim_remove_profile_dialog") {
deps = [
"//ui/webui/resources/cr_components/chromeos/cellular_setup:esim_manager_utils",
"//ui/webui/resources/cr_components/chromeos/cellular_setup:mojo_interface_provider",
"//ui/webui/resources/cr_components/chromeos/network:mojo_interface_provider",
"//ui/webui/resources/cr_elements/cr_dialog:cr_dialog",
......@@ -542,6 +544,7 @@ js_library("cellular_networks_list.m") {
js_library("esim_rename_dialog.m") {
sources = [ "$root_gen_dir/chrome/browser/resources/settings/chromeos/internet_page/esim_rename_dialog.m.js" ]
deps = [
"//ui/webui/resources/cr_components/chromeos/cellular_setup:esim_manager_utils.m",
"//ui/webui/resources/cr_components/chromeos/cellular_setup:mojo_interface_provider.m",
"//ui/webui/resources/cr_components/chromeos/network:mojo_interface_provider.m",
"//ui/webui/resources/cr_elements/cr_dialog:cr_dialog.m",
......@@ -554,6 +557,7 @@ js_library("esim_rename_dialog.m") {
js_library("esim_remove_profile_dialog.m") {
sources = [ "$root_gen_dir/chrome/browser/resources/settings/chromeos/internet_page/esim_remove_profile_dialog.m.js" ]
deps = [
"//ui/webui/resources/cr_components/chromeos/cellular_setup:esim_manager_utils.m",
"//ui/webui/resources/cr_components/chromeos/cellular_setup:mojo_interface_provider.m",
"//ui/webui/resources/cr_components/chromeos/network:mojo_interface_provider.m",
"//ui/webui/resources/cr_elements/cr_dialog:cr_dialog.m",
......
......@@ -161,17 +161,13 @@ Polymer({
/** @private */
fetchESimPendingProfileList_() {
cellular_setup.getESimManagerRemote()
.getAvailableEuiccs()
.then(response => {
if (response.euiccs.length > 0) {
// Use first available euicc as current. Only single Euicc modules are
// currently supported.
this.euicc_ = response.euiccs[0];
return this.fetchESimPendingProfileListForEuicc_(this.euicc_);
}
this.euicc_ = null;
});
cellular_setup.getEuicc().then(euicc => {
if (!euicc) {
return;
}
this.euicc_ = euicc;
this.fetchESimPendingProfileListForEuicc_(euicc);
});
},
/**
......
<link rel="import" href="chrome://resources/html/polymer.html">
<link rel="import" href="chrome://resources/cr_components/chromeos/cellular_setup/esim_manager_utils.html">
<link rel="import" href="chrome://resources/cr_components/chromeos/cellular_setup/mojo_interface_provider.html">
<link rel="import" href="chrome://resources/cr_components/chromeos/network/mojo_interface_provider.html">
<link rel="import" href="chrome://resources/cr_elements/cr_dialog/cr_dialog.html">
......
......@@ -61,8 +61,11 @@ Polymer({
/** @private */
async init_() {
const response = await this.eSimManagerRemote_.getAvailableEuiccs();
const euicc = response.euiccs[0];
const euicc = await cellular_setup.getEuicc();
if (!euicc) {
console.error('No Euiccs found');
return;
}
const esimProfilesRemotes = await euicc.getProfileList();
......
<link rel="import" href="chrome://resources/html/polymer.html">
<link rel="import" href="chrome://resources/cr_components/chromeos/cellular_setup/esim_manager_utils.html">
<link rel="import" href="chrome://resources/cr_components/chromeos/cellular_setup/mojo_interface_provider.html">
<link rel="import" href="chrome://resources/cr_components/chromeos/network/mojo_interface_provider.html">
<link rel="import" href="chrome://resources/cr_elements/cr_dialog/cr_dialog.html">
......
......@@ -61,8 +61,11 @@ Polymer({
/** @private */
async init_() {
const response = await this.eSimManagerRemote_.getAvailableEuiccs();
const euicc = response.euiccs[0];
const euicc = await cellular_setup.getEuicc();
if (!euicc) {
console.error('No Euiccs found');
return;
}
const esimProfilesRemotes = await euicc.getProfileList();
......
......@@ -139,42 +139,41 @@ cr.define('cellular_setup', function() {
},
/** @private */
fetchProfiles_() {
let euicc;
this.eSimManagerRemote_.getAvailableEuiccs()
.then(response => {
// TODO(crbug.com/1093185) User should have at least 1 EUICC or
// we shouldn't have gotten to this flow. Add check for this in
// cellular_setup.
euicc = response.euiccs[0];
this.euicc_ = euicc;
return euicc.requestPendingProfiles();
})
.then(response => {
if (response.result ===
chromeos.cellularSetup.mojom.ESimOperationResult.kFailure) {
console.error('Error requesting pending profiles: ' + response);
}
return cellular_setup.getPendingESimProfiles(euicc);
})
.then(profiles => {
this.pendingProfiles_ = profiles;
switch (profiles.length) {
case 0:
this.state_ = ESimUiState.ACTIVATION_CODE_ENTRY;
break;
case 1:
this.selectedProfile_ = profiles[0];
// Assume installing the profile doesn't require a confirmation
// code, send an empty string.
this.selectedProfile_.installProfile('').then(
this.handleProfileInstallResponse_.bind(this));
break;
default:
this.state_ = ESimUiState.PROFILE_SELECTION;
break;
}
});
async fetchProfiles_() {
const euicc = await cellular_setup.getEuicc();
if (!euicc) {
// TODO(crbug.com/1093185) User should have at least 1 EUICC or
// we shouldn't have gotten to this flow. Add check for this in
// cellular_setup.
console.error('No Euiccs found');
return;
}
this.euicc_ = euicc;
const requestPendingProfilesResponse =
await euicc.requestPendingProfiles();
if (requestPendingProfilesResponse.result ===
chromeos.cellularSetup.mojom.ESimOperationResult.kFailure) {
console.error(
'Error requesting pending profiles: ',
requestPendingProfilesResponse);
}
this.pendingProfiles_ =
await cellular_setup.getPendingESimProfiles(euicc);
switch (this.pendingProfiles_.length) {
case 0:
this.state_ = ESimUiState.ACTIVATION_CODE_ENTRY;
break;
case 1:
this.selectedProfile_ = this.pendingProfiles_[0];
// Assume installing the profile doesn't require a confirmation
// code, send an empty string.
this.selectedProfile_.installProfile('').then(
this.handleProfileInstallResponse_.bind(this));
break;
default:
this.state_ = ESimUiState.PROFILE_SELECTION;
break;
}
},
/**
......
......@@ -4,13 +4,14 @@
// clang-format off
// #import {getESimManagerRemote} from 'chrome://resources/cr_components/chromeos/cellular_setup/mojo_interface_provider.m.js';
// #import {loadTimeData} from 'chrome://resources/js/load_time_data.m.js';
// clang-format on
cr.define('cellular_setup', function() {
/**
* Fetches the EUICC's eSIM profiles with status 'Pending'.
* @param {!chromeos.cellularSetup.mojom.EuiccRemote} euicc
* @return {!Promise<Array<!chromeos.cellularSetup.mojom.ESimProfileRemote>>}
* @return {!Promise<!Array<!chromeos.cellularSetup.mojom.ESimProfileRemote>>}
*/
/* #export */ function getPendingESimProfiles(euicc) {
return euicc.getProfileList().then(response => {
......@@ -40,8 +41,29 @@ cr.define('cellular_setup', function() {
});
}
/**
* Returns the Euicc that should be used for eSim operations or null
* if there is none available.
* @return {!Promise<?chromeos.cellularSetup.mojom.EuiccRemote>}
*/
/* #export */ async function getEuicc() {
const eSimManagerRemote = cellular_setup.getESimManagerRemote();
const response = await eSimManagerRemote.getAvailableEuiccs();
if (!response || !response.euiccs) {
return null;
}
// Onboard Euicc always appears at index 0. If useExternalEuicc flag
// is set, use the next available Euicc.
const euiccIndex = loadTimeData.getBoolean('useExternalEuicc') ? 1 : 0;
if (euiccIndex >= response.euiccs.length) {
return null;
}
return response.euiccs[euiccIndex];
}
// #cr_define_end
return {
getEuicc,
getPendingESimProfiles,
};
});
......@@ -21,6 +21,7 @@ cr_components_chromeos_namespace_rewrites = [
"cellular_setup.setESimManagerRemoteForTesting|setESimManagerRemoteForTesting",
"cellular_setup.observeESimManager|observeESimManager",
"cellular_setup.getPendingESimProfiles|getPendingESimProfiles",
"cellular_setup.getEuicc|getEuicc",
"cellular_setup.CellularSetupDelegate|CellularSetupDelegate",
"network_config.MojoInterfaceProvider|MojoInterfaceProvider",
"network_config.MojoInterfaceProviderImpl|MojoInterfaceProviderImpl",
......@@ -35,7 +36,7 @@ cr_components_chromeos_auto_imports = [
"ui/webui/resources/cr_components/chromeos/cellular_setup/cellular_setup_delegate.html|CellularSetupDelegate",
"ui/webui/resources/cr_components/chromeos/cellular_setup/subflow_behavior.html|SubflowBehavior",
"ui/webui/resources/cr_components/chromeos/cellular_setup/mojo_interface_provider.html|setCellularSetupRemoteForTesting,getCellularSetupRemote,setESimManagerRemoteForTesting,getESimManagerRemote,observeESimManager",
"ui/webui/resources/cr_components/chromeos/cellular_setup/esim_manager_utils.html|getPendingESimProfiles",
"ui/webui/resources/cr_components/chromeos/cellular_setup/esim_manager_utils.html|getPendingESimProfiles,getEuicc",
"ui/webui/resources/cr_components/chromeos/cellular_setup/esim_manager_listener_behavior.html|ESimManagerListenerBehavior",
"ui/webui/resources/cr_components/chromeos/network/cr_policy_network_behavior_mojo.html|CrPolicyNetworkBehaviorMojo",
"ui/webui/resources/cr_components/chromeos/network/onc_mojo.html|OncMojo",
......
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