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") { ...@@ -223,6 +223,7 @@ js_library("cellular_networks_list") {
js_library("esim_rename_dialog") { js_library("esim_rename_dialog") {
deps = [ 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/cellular_setup:mojo_interface_provider",
"//ui/webui/resources/cr_components/chromeos/network:mojo_interface_provider", "//ui/webui/resources/cr_components/chromeos/network:mojo_interface_provider",
"//ui/webui/resources/cr_elements/cr_dialog:cr_dialog", "//ui/webui/resources/cr_elements/cr_dialog:cr_dialog",
...@@ -233,6 +234,7 @@ js_library("esim_rename_dialog") { ...@@ -233,6 +234,7 @@ js_library("esim_rename_dialog") {
js_library("esim_remove_profile_dialog") { js_library("esim_remove_profile_dialog") {
deps = [ 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/cellular_setup:mojo_interface_provider",
"//ui/webui/resources/cr_components/chromeos/network:mojo_interface_provider", "//ui/webui/resources/cr_components/chromeos/network:mojo_interface_provider",
"//ui/webui/resources/cr_elements/cr_dialog:cr_dialog", "//ui/webui/resources/cr_elements/cr_dialog:cr_dialog",
...@@ -542,6 +544,7 @@ js_library("cellular_networks_list.m") { ...@@ -542,6 +544,7 @@ js_library("cellular_networks_list.m") {
js_library("esim_rename_dialog.m") { js_library("esim_rename_dialog.m") {
sources = [ "$root_gen_dir/chrome/browser/resources/settings/chromeos/internet_page/esim_rename_dialog.m.js" ] sources = [ "$root_gen_dir/chrome/browser/resources/settings/chromeos/internet_page/esim_rename_dialog.m.js" ]
deps = [ 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/cellular_setup:mojo_interface_provider.m",
"//ui/webui/resources/cr_components/chromeos/network: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", "//ui/webui/resources/cr_elements/cr_dialog:cr_dialog.m",
...@@ -554,6 +557,7 @@ js_library("esim_rename_dialog.m") { ...@@ -554,6 +557,7 @@ js_library("esim_rename_dialog.m") {
js_library("esim_remove_profile_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" ] sources = [ "$root_gen_dir/chrome/browser/resources/settings/chromeos/internet_page/esim_remove_profile_dialog.m.js" ]
deps = [ 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/cellular_setup:mojo_interface_provider.m",
"//ui/webui/resources/cr_components/chromeos/network: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", "//ui/webui/resources/cr_elements/cr_dialog:cr_dialog.m",
......
...@@ -161,16 +161,12 @@ Polymer({ ...@@ -161,16 +161,12 @@ Polymer({
/** @private */ /** @private */
fetchESimPendingProfileList_() { fetchESimPendingProfileList_() {
cellular_setup.getESimManagerRemote() cellular_setup.getEuicc().then(euicc => {
.getAvailableEuiccs() if (!euicc) {
.then(response => { return;
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; this.euicc_ = euicc;
this.fetchESimPendingProfileListForEuicc_(euicc);
}); });
}, },
......
<link rel="import" href="chrome://resources/html/polymer.html"> <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/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_components/chromeos/network/mojo_interface_provider.html">
<link rel="import" href="chrome://resources/cr_elements/cr_dialog/cr_dialog.html"> <link rel="import" href="chrome://resources/cr_elements/cr_dialog/cr_dialog.html">
......
...@@ -61,8 +61,11 @@ Polymer({ ...@@ -61,8 +61,11 @@ Polymer({
/** @private */ /** @private */
async init_() { async init_() {
const response = await this.eSimManagerRemote_.getAvailableEuiccs(); const euicc = await cellular_setup.getEuicc();
const euicc = response.euiccs[0]; if (!euicc) {
console.error('No Euiccs found');
return;
}
const esimProfilesRemotes = await euicc.getProfileList(); const esimProfilesRemotes = await euicc.getProfileList();
......
<link rel="import" href="chrome://resources/html/polymer.html"> <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/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_components/chromeos/network/mojo_interface_provider.html">
<link rel="import" href="chrome://resources/cr_elements/cr_dialog/cr_dialog.html"> <link rel="import" href="chrome://resources/cr_elements/cr_dialog/cr_dialog.html">
......
...@@ -61,8 +61,11 @@ Polymer({ ...@@ -61,8 +61,11 @@ Polymer({
/** @private */ /** @private */
async init_() { async init_() {
const response = await this.eSimManagerRemote_.getAvailableEuiccs(); const euicc = await cellular_setup.getEuicc();
const euicc = response.euiccs[0]; if (!euicc) {
console.error('No Euiccs found');
return;
}
const esimProfilesRemotes = await euicc.getProfileList(); const esimProfilesRemotes = await euicc.getProfileList();
......
...@@ -139,32 +139,32 @@ cr.define('cellular_setup', function() { ...@@ -139,32 +139,32 @@ cr.define('cellular_setup', function() {
}, },
/** @private */ /** @private */
fetchProfiles_() { async fetchProfiles_() {
let euicc; const euicc = await cellular_setup.getEuicc();
this.eSimManagerRemote_.getAvailableEuiccs() if (!euicc) {
.then(response => {
// TODO(crbug.com/1093185) User should have at least 1 EUICC or // 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 // we shouldn't have gotten to this flow. Add check for this in
// cellular_setup. // cellular_setup.
euicc = response.euiccs[0]; console.error('No Euiccs found');
return;
}
this.euicc_ = euicc; this.euicc_ = euicc;
return euicc.requestPendingProfiles(); const requestPendingProfilesResponse =
}) await euicc.requestPendingProfiles();
.then(response => { if (requestPendingProfilesResponse.result ===
if (response.result ===
chromeos.cellularSetup.mojom.ESimOperationResult.kFailure) { chromeos.cellularSetup.mojom.ESimOperationResult.kFailure) {
console.error('Error requesting pending profiles: ' + response); console.error(
'Error requesting pending profiles: ',
requestPendingProfilesResponse);
} }
return cellular_setup.getPendingESimProfiles(euicc); this.pendingProfiles_ =
}) await cellular_setup.getPendingESimProfiles(euicc);
.then(profiles => { switch (this.pendingProfiles_.length) {
this.pendingProfiles_ = profiles;
switch (profiles.length) {
case 0: case 0:
this.state_ = ESimUiState.ACTIVATION_CODE_ENTRY; this.state_ = ESimUiState.ACTIVATION_CODE_ENTRY;
break; break;
case 1: case 1:
this.selectedProfile_ = profiles[0]; this.selectedProfile_ = this.pendingProfiles_[0];
// Assume installing the profile doesn't require a confirmation // Assume installing the profile doesn't require a confirmation
// code, send an empty string. // code, send an empty string.
this.selectedProfile_.installProfile('').then( this.selectedProfile_.installProfile('').then(
...@@ -174,7 +174,6 @@ cr.define('cellular_setup', function() { ...@@ -174,7 +174,6 @@ cr.define('cellular_setup', function() {
this.state_ = ESimUiState.PROFILE_SELECTION; this.state_ = ESimUiState.PROFILE_SELECTION;
break; break;
} }
});
}, },
/** /**
......
...@@ -4,13 +4,14 @@ ...@@ -4,13 +4,14 @@
// clang-format off // clang-format off
// #import {getESimManagerRemote} from 'chrome://resources/cr_components/chromeos/cellular_setup/mojo_interface_provider.m.js'; // #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 // clang-format on
cr.define('cellular_setup', function() { cr.define('cellular_setup', function() {
/** /**
* Fetches the EUICC's eSIM profiles with status 'Pending'. * Fetches the EUICC's eSIM profiles with status 'Pending'.
* @param {!chromeos.cellularSetup.mojom.EuiccRemote} euicc * @param {!chromeos.cellularSetup.mojom.EuiccRemote} euicc
* @return {!Promise<Array<!chromeos.cellularSetup.mojom.ESimProfileRemote>>} * @return {!Promise<!Array<!chromeos.cellularSetup.mojom.ESimProfileRemote>>}
*/ */
/* #export */ function getPendingESimProfiles(euicc) { /* #export */ function getPendingESimProfiles(euicc) {
return euicc.getProfileList().then(response => { return euicc.getProfileList().then(response => {
...@@ -40,8 +41,29 @@ cr.define('cellular_setup', function() { ...@@ -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 // #cr_define_end
return { return {
getEuicc,
getPendingESimProfiles, getPendingESimProfiles,
}; };
}); });
...@@ -21,6 +21,7 @@ cr_components_chromeos_namespace_rewrites = [ ...@@ -21,6 +21,7 @@ cr_components_chromeos_namespace_rewrites = [
"cellular_setup.setESimManagerRemoteForTesting|setESimManagerRemoteForTesting", "cellular_setup.setESimManagerRemoteForTesting|setESimManagerRemoteForTesting",
"cellular_setup.observeESimManager|observeESimManager", "cellular_setup.observeESimManager|observeESimManager",
"cellular_setup.getPendingESimProfiles|getPendingESimProfiles", "cellular_setup.getPendingESimProfiles|getPendingESimProfiles",
"cellular_setup.getEuicc|getEuicc",
"cellular_setup.CellularSetupDelegate|CellularSetupDelegate", "cellular_setup.CellularSetupDelegate|CellularSetupDelegate",
"network_config.MojoInterfaceProvider|MojoInterfaceProvider", "network_config.MojoInterfaceProvider|MojoInterfaceProvider",
"network_config.MojoInterfaceProviderImpl|MojoInterfaceProviderImpl", "network_config.MojoInterfaceProviderImpl|MojoInterfaceProviderImpl",
...@@ -35,7 +36,7 @@ cr_components_chromeos_auto_imports = [ ...@@ -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/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/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/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/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/cr_policy_network_behavior_mojo.html|CrPolicyNetworkBehaviorMojo",
"ui/webui/resources/cr_components/chromeos/network/onc_mojo.html|OncMojo", "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