Commit fbe23b5a authored by stevenjb's avatar stevenjb Committed by Commit bot

Use ONC carrier info in JS

Also, cleanup internet_options_handler.cc 'showViewAccountButton' code.

BUG=279351

Review URL: https://codereview.chromium.org/561073002

Cr-Commit-Position: refs/heads/master@{#294951}
parent 1c8fb800
...@@ -15,8 +15,6 @@ ...@@ -15,8 +15,6 @@
* InternetDetailedInfo argument passed to showDetailedInfo. * InternetDetailedInfo argument passed to showDetailedInfo.
* @see chrome/browser/ui/webui/options/chromeos/internet_options_handler.cc * @see chrome/browser/ui/webui/options/chromeos/internet_options_handler.cc
* @typedef {{ * @typedef {{
* carriers: (Array.<string>|undefined),
* currentCarrierIndex: (number|undefined),
* deviceConnected: (boolean|undefined), * deviceConnected: (boolean|undefined),
* errorMessage: (string|undefined), * errorMessage: (string|undefined),
* servicePath: string, * servicePath: string,
...@@ -33,6 +31,7 @@ cr.define('options.internet', function() { ...@@ -33,6 +31,7 @@ cr.define('options.internet', function() {
/** @const */ var IPAddressField = options.internet.IPAddressField; /** @const */ var IPAddressField = options.internet.IPAddressField;
/** @const */ var GoogleNameServersString = '8.8.4.4,8.8.8.8'; /** @const */ var GoogleNameServersString = '8.8.4.4,8.8.8.8';
/** @const */ var CarrierGenericUMTS = 'Generic UMTS';
/** /**
* Helper function to set hidden attribute for elements matching a selector. * Helper function to set hidden attribute for elements matching a selector.
...@@ -1356,19 +1355,35 @@ cr.define('options.internet', function() { ...@@ -1356,19 +1355,35 @@ cr.define('options.internet', function() {
$('wimax-signal-strength').textContent = strengthString; $('wimax-signal-strength').textContent = strengthString;
} else if (type == 'Cellular') { } else if (type == 'Cellular') {
OptionsPage.showTab($('cellular-conn-nav-tab')); OptionsPage.showTab($('cellular-conn-nav-tab'));
if (data.showCarrierSelect && data.currentCarrierIndex != -1) {
var carrierSelector = $('select-carrier'); var isGsm = onc.getActiveValue('Cellular.Family') == 'GSM';
carrierSelector.onchange = DetailsInternetPage.handleCarrierChanged;
carrierSelector.options.length = 0; var currentCarrierIndex = -1;
for (var i = 0; i < data.carriers.length; ++i) { if (data.showCarrierSelect) {
var option = document.createElement('option'); var currentCarrier =
option.textContent = data.carriers[i]; isGsm ? CarrierGenericUMTS : onc.getActiveValue('Cellular.Carrier');
carrierSelector.add(option); var supportedCarriers =
onc.getActiveValue('Cellular.SupportedCarriers');
for (var c1 = 0; c1 < supportedCarriers.length; ++c1) {
if (supportedCarriers[c1] == currentCarrier) {
currentCarrierIndex = c1;
break;
}
}
if (currentCarrierIndex != -1) {
var carrierSelector = $('select-carrier');
carrierSelector.onchange = DetailsInternetPage.handleCarrierChanged;
carrierSelector.options.length = 0;
for (var c2 = 0; c2 < supportedCarriers.length; ++c2) {
var option = document.createElement('option');
option.textContent = supportedCarriers[c2];
carrierSelector.add(option);
}
carrierSelector.selectedIndex = currentCarrierIndex;
} }
carrierSelector.selectedIndex = data.currentCarrierIndex;
} else {
$('service-name').textContent = networkName;
} }
if (currentCarrierIndex == -1)
$('service-name').textContent = networkName;
$('network-technology').textContent = $('network-technology').textContent =
onc.getActiveValue('Cellular.NetworkTechnology'); onc.getActiveValue('Cellular.NetworkTechnology');
...@@ -1411,7 +1426,7 @@ cr.define('options.internet', function() { ...@@ -1411,7 +1426,7 @@ cr.define('options.internet', function() {
setOrHideParent('min', onc.getActiveValue('Cellular.MIN')); setOrHideParent('min', onc.getActiveValue('Cellular.MIN'));
setOrHideParent('prl-version', onc.getActiveValue('Cellular.PRLVersion')); setOrHideParent('prl-version', onc.getActiveValue('Cellular.PRLVersion'));
if (onc.getActiveValue('Cellular.Family') == 'GSM') { if (isGsm) {
$('iccid').textContent = onc.getActiveValue('Cellular.ICCID'); $('iccid').textContent = onc.getActiveValue('Cellular.ICCID');
$('imsi').textContent = onc.getActiveValue('Cellular.IMSI'); $('imsi').textContent = onc.getActiveValue('Cellular.IMSI');
detailsPage.initializeApnList_(); detailsPage.initializeApnList_();
......
...@@ -123,8 +123,6 @@ const char kTagErrorMessage[] = "errorMessage"; ...@@ -123,8 +123,6 @@ const char kTagErrorMessage[] = "errorMessage";
const char kTagForget[] = "forget"; const char kTagForget[] = "forget";
const char kTagOptions[] = "options"; const char kTagOptions[] = "options";
const char kTagRememberedList[] = "rememberedList"; const char kTagRememberedList[] = "rememberedList";
const char kTagCarriers[] = "carriers";
const char kTagCurrentCarrierIndex[] = "currentCarrierIndex";
const char kTagShowViewAccountButton[] = "showViewAccountButton"; const char kTagShowViewAccountButton[] = "showViewAccountButton";
const char kTagTrue[] = "true"; const char kTagTrue[] = "true";
const char kTagVpnList[] = "vpnList"; const char kTagVpnList[] = "vpnList";
...@@ -189,98 +187,46 @@ base::DictionaryValue* BuildNetworkDictionary( ...@@ -189,98 +187,46 @@ base::DictionaryValue* BuildNetworkDictionary(
return network_info.release(); return network_info.release();
} }
// Given a list of supported carrier's by the device, return the index of bool ShowViewAccountButton(const NetworkState* cellular) {
// the carrier the device is currently using. if (cellular->activation_state() != shill::kActivationStateActivating &&
int FindCurrentCarrierIndex(const base::ListValue* carriers, cellular->activation_state() != shill::kActivationStateActivated)
const DeviceState* device) { return false;
DCHECK(carriers);
DCHECK(device);
bool gsm = (device->technology_family() == shill::kTechnologyFamilyGsm);
int index = 0;
for (base::ListValue::const_iterator it = carriers->begin();
it != carriers->end(); ++it, ++index) {
std::string value;
if (!(*it)->GetAsString(&value))
continue;
// For GSM devices the device name will be empty, so simply select
// the Generic UMTS carrier option if present.
if (gsm && (value == shill::kCarrierGenericUMTS))
return index;
// For other carriers, the service name will match the carrier name.
if (value == device->carrier())
return index;
}
return -1;
}
void PopulateCellularDetails(const NetworkState* cellular,
base::DictionaryValue* dictionary) {
dictionary->SetBoolean(kTagCarrierSelectFlag,
CommandLine::ForCurrentProcess()->HasSwitch(
chromeos::switches::kEnableCarrierSwitching));
// These default to empty and are only set if device != NULL.
std::string carrier_id;
std::string mdn;
// Device settings.
const DeviceState* device = const DeviceState* device =
NetworkHandler::Get()->network_state_handler()->GetDeviceState( NetworkHandler::Get()->network_state_handler()->GetDeviceState(
cellular->device_path()); cellular->device_path());
if (device) {
const base::DictionaryValue& device_properties = device->properties(); // If no online payment URL was provided by shill, Check to see if the
// MobileConfig carrier indicates that "View Account" should be shown.
carrier_id = device->home_provider_id(); if (cellular->payment_url().empty()) {
device_properties.GetStringWithoutPathExpansion(shill::kMdnProperty, &mdn); if (!device || !MobileConfig::GetInstance()->IsReady())
return false;
const base::ListValue* supported_carriers; const MobileConfig::Carrier* carrier =
if (device_properties.GetListWithoutPathExpansion( MobileConfig::GetInstance()->GetCarrier(device->home_provider_id());
shill::kSupportedCarriersProperty, &supported_carriers)) { if (!carrier || !carrier->show_portal_button())
dictionary->Set(kTagCarriers, supported_carriers->DeepCopy()); return false;
dictionary->SetInteger(
kTagCurrentCarrierIndex,
FindCurrentCarrierIndex(supported_carriers, device));
} else {
// In case of any error, set the current carrier tag to -1 indicating
// to the JS code to fallback to a single carrier.
dictionary->SetInteger(kTagCurrentCarrierIndex, -1);
}
} }
if (cellular->activation_state() == shill::kActivationStateActivating || if (!cellular->IsConnectedState()) {
cellular->activation_state() == shill::kActivationStateActivated) { // Disconnected LTE networks should show the button if we are online and
// TODO(stevenjb): Determine if we actually need this check. The payment url // the device's MDN is set. This is to enable users to update their plan
// property is commented as 'Deprecated' in service_constants.h and appears // if they are out of credits.
// to be unset in Shill, but we still reference it in mobile_setup.cc. if (!NetworkHandler::Get()->network_state_handler()->DefaultNetwork())
bool may_show_portal_button = !cellular->payment_url().empty(); return false;
const std::string& technology = cellular->network_technology();
// If no online payment URL was provided by shill, fall back to if (technology != shill::kNetworkTechnologyLte &&
// MobileConfig to determine if the "View Account" should be shown. technology != shill::kNetworkTechnologyLteAdvanced)
if (!may_show_portal_button && MobileConfig::GetInstance()->IsReady()) { return false;
const MobileConfig::Carrier* carrier = std::string mdn;
MobileConfig::GetInstance()->GetCarrier(carrier_id); if (device) {
may_show_portal_button = carrier && carrier->show_portal_button(); device->properties().GetStringWithoutPathExpansion(shill::kMdnProperty,
} &mdn);
if (may_show_portal_button) {
// The button should be shown for a LTE network even when the LTE network
// is not connected, but CrOS is online. This is done to enable users to
// update their plan even if they are out of credits.
// The button should not be shown when the device's mdn is not set,
// because the network's proper portal url cannot be generated without it
const NetworkState* default_network =
NetworkHandler::Get()->network_state_handler()->DefaultNetwork();
const std::string& technology = cellular->network_technology();
bool force_show_view_account_button =
(technology == shill::kNetworkTechnologyLte ||
technology == shill::kNetworkTechnologyLteAdvanced) &&
default_network && !mdn.empty();
// The button will trigger ShowMorePlanInfoCallback() which will open
// carrier specific portal.
if (cellular->IsConnectedState() || force_show_view_account_button)
dictionary->SetBoolean(kTagShowViewAccountButton, true);
} }
if (mdn.empty())
return false;
} }
return true;
} }
scoped_ptr<base::DictionaryValue> PopulateConnectionDetails( scoped_ptr<base::DictionaryValue> PopulateConnectionDetails(
...@@ -300,9 +246,14 @@ scoped_ptr<base::DictionaryValue> PopulateConnectionDetails( ...@@ -300,9 +246,14 @@ scoped_ptr<base::DictionaryValue> PopulateConnectionDetails(
NetworkTypePattern::Primitive(type)); NetworkTypePattern::Primitive(type));
dictionary->SetBoolean(kTagDeviceConnected, connected_network != NULL); dictionary->SetBoolean(kTagDeviceConnected, connected_network != NULL);
if (type == shill::kTypeCellular) if (type == shill::kTypeCellular) {
PopulateCellularDetails(network, dictionary.get()); dictionary->SetBoolean(
kTagCarrierSelectFlag,
CommandLine::ForCurrentProcess()
->HasSwitch(chromeos::switches::kEnableCarrierSwitching));
dictionary->SetBoolean(kTagShowViewAccountButton,
ShowViewAccountButton(network));
}
return dictionary.Pass(); return dictionary.Pass();
} }
......
...@@ -756,6 +756,12 @@ void FakeShillManagerClient::SetupDefaultEnvironment() { ...@@ -756,6 +756,12 @@ void FakeShillManagerClient::SetupDefaultEnvironment() {
devices->SetDeviceProperty("/device/cellular1", devices->SetDeviceProperty("/device/cellular1",
shill::kCarrierProperty, shill::kCarrierProperty,
base::StringValue(shill::kCarrierSprint)); base::StringValue(shill::kCarrierSprint));
base::ListValue carrier_list;
carrier_list.AppendString(shill::kCarrierSprint);
carrier_list.AppendString(shill::kCarrierGenericUMTS);
devices->SetDeviceProperty("/device/cellular1",
shill::kSupportedCarriersProperty,
carrier_list);
services->AddService(kCellularServicePath, services->AddService(kCellularServicePath,
"cellular1_guid", "cellular1_guid",
......
...@@ -42,6 +42,7 @@ ...@@ -42,6 +42,7 @@
"password": "test-password3" "password": "test-password3"
} }
], ],
"Cellular.Carrier": "cellular_provider",
"Cellular.HomeProvider": { "Cellular.HomeProvider": {
"country": "us", "country": "us",
"name": "cellular_provider" "name": "cellular_provider"
...@@ -49,7 +50,11 @@ ...@@ -49,7 +50,11 @@
"Cellular.SIMLockStatus": { "Cellular.SIMLockStatus": {
"LockType": "sim-pin", "LockType": "sim-pin",
"LockEnabled": true "LockEnabled": true
} },
"Cellular.SupportedCarriers": [
"cellular_provider",
"generic_provider"
],
}, },
"Profile": "/profile/default", "Profile": "/profile/default",
} }
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
"ActivationType": "OTASP", "ActivationType": "OTASP",
"AllowRoaming": true, "AllowRoaming": true,
"AutoConnect": true, "AutoConnect": true,
"Carrier": "cellular_provider",
"HomeProvider": { "HomeProvider": {
"country": "us", "country": "us",
"name": "cellular_provider" "name": "cellular_provider"
...@@ -16,6 +17,10 @@ ...@@ -16,6 +17,10 @@
"Country": "test-country", "Country": "test-country",
"Name": "test-name" "Name": "test-name"
}, },
"SupportedCarriers": [
"cellular_provider",
"generic_provider"
],
"APN": { "APN": {
"AccessPointName": "test-apn", "AccessPointName": "test-apn",
"Name": "test-apn-name", "Name": "test-apn-name",
...@@ -39,7 +44,7 @@ ...@@ -39,7 +44,7 @@
"Password": "test-password3", "Password": "test-password3",
"Username": "test-username3" "Username": "test-username3"
} }
], ],
"SIMLockStatus": { "SIMLockStatus": {
"LockType": "sim-pin", "LockType": "sim-pin",
"LockEnabled": true "LockEnabled": true
......
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