Commit 4ff8121c authored by stevenjb's avatar stevenjb Committed by Commit bot

Use ONC for Cellular APN and SimLock in Settings

BUG=279351
For chrome/browser/ui/webui/chromeos/network_config_message_handler.cc:
TBR=xiyuan@chromium.org

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

Cr-Commit-Position: refs/heads/master@{#292245}
parent 13d9b125
......@@ -11,6 +11,7 @@
#include "base/logging.h"
#include "base/values.h"
#include "chromeos/login/login_state.h"
#include "chromeos/network/device_state.h"
#include "chromeos/network/managed_network_configuration_handler.h"
#include "chromeos/network/network_configuration_handler.h"
#include "chromeos/network/network_state.h"
......@@ -173,12 +174,32 @@ void NetworkConfigMessageHandler::GetShillProperties(
}
NetworkHandler::Get()->network_configuration_handler()->GetProperties(
service_path,
base::Bind(&NetworkConfigMessageHandler::GetPropertiesSuccess,
base::Bind(&NetworkConfigMessageHandler::GetShillPropertiesSuccess,
weak_ptr_factory_.GetWeakPtr(), callback_id),
base::Bind(&NetworkConfigMessageHandler::ErrorCallback,
weak_ptr_factory_.GetWeakPtr(), callback_id));
}
void NetworkConfigMessageHandler::GetShillPropertiesSuccess(
int callback_id,
const std::string& service_path,
const base::DictionaryValue& dictionary) const {
scoped_ptr<base::DictionaryValue> dictionary_copy(dictionary.DeepCopy());
// Get the device properties for debugging.
std::string device;
dictionary_copy->GetStringWithoutPathExpansion(
shill::kDeviceProperty, &device);
const DeviceState* device_state =
NetworkHandler::Get()->network_state_handler()->GetDeviceState(device);
if (device_state) {
base::DictionaryValue* device_dictionary =
device_state->properties().DeepCopy();
dictionary_copy->Set(shill::kDeviceProperty, device_dictionary);
}
GetPropertiesSuccess(callback_id, service_path, *dictionary_copy);
}
void NetworkConfigMessageHandler::InvokeCallback(
const base::ListValue& arg_list) const {
web_ui()->CallJavascriptFunction(
......
......@@ -38,10 +38,16 @@ class NetworkConfigMessageHandler : public content::WebUIMessageHandler {
void GetNetworks(const base::ListValue* arg_list) const;
void GetProperties(const base::ListValue* arg_list);
void GetManagedProperties(const base::ListValue* arg_list);
void GetShillProperties(const base::ListValue* arg_list);
void GetPropertiesSuccess(int callback_id,
const std::string& service_path,
const base::DictionaryValue& dictionary) const;
// Get Shill Properties for debugging purposes only.
void GetShillProperties(const base::ListValue* arg_list);
void GetShillPropertiesSuccess(int callback_id,
const std::string& service_path,
const base::DictionaryValue& dictionary) const;
void InvokeCallback(const base::ListValue& arg_list) const;
void ErrorCallback(int callback_id,
const std::string& error_name,
......
......@@ -28,6 +28,7 @@
#include "chrome/browser/chromeos/ui/mobile_config_ui.h"
#include "chrome/browser/chromeos/ui_proxy_config_service.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/webui/chromeos/mobile_setup_dialog.h"
#include "chrome/browser/ui/webui/options/chromeos/internet_options_handler_strings.h"
#include "chromeos/chromeos_switches.h"
#include "chromeos/network/device_state.h"
......@@ -131,7 +132,6 @@ const char kShowMorePlanInfoMessage[] = "showMorePlanInfo";
const char kTagActivate[] = "activate";
const char kTagActivationState[] = "activationState";
const char kTagAddConnection[] = "add";
const char kTagApn[] = "apn";
const char kTagCarrierSelectFlag[] = "showCarrierSelect";
const char kTagCarrierUrl[] = "carrierUrl";
const char kTagCellularAvailable[] = "cellularAvailable";
......@@ -144,17 +144,10 @@ const char kTagDeviceConnected[] = "deviceConnected";
const char kTagDisconnect[] = "disconnect";
const char kTagErrorMessage[] = "errorMessage";
const char kTagForget[] = "forget";
const char kTagLanguage[] = "language";
const char kTagLastGoodApn[] = "lastGoodApn";
const char kTagLocalizedName[] = "localizedName";
const char kTagName[] = "name";
const char kTagNameServersGoogle[] = "nameServersGoogle";
const char kTagNameServerType[] = "nameServerType";
const char kTagNetworkId[] = "networkId";
const char kTagOptions[] = "options";
const char kTagPassword[] = "password";
const char kTagPolicy[] = "policy";
const char kTagProviderApnList[] = "providerApnList";
const char kTagRecommended[] = "recommended";
const char kTagRecommendedValue[] = "recommendedValue";
const char kTagRemembered[] = "remembered";
......@@ -166,10 +159,7 @@ const char kTagCurrentCarrierIndex[] = "currentCarrierIndex";
const char kTagShared[] = "shared";
const char kTagShowActivateButton[] = "showActivateButton";
const char kTagShowViewAccountButton[] = "showViewAccountButton";
const char kTagSimCardLockEnabled[] = "simCardLockEnabled";
const char kTagSupportUrl[] = "supportUrl";
const char kTagTrue[] = "true";
const char kTagUsername[] = "username";
const char kTagValue[] = "value";
const char kTagVpnList[] = "vpnList";
const char kTagWifiAvailable[] = "wifiAvailable";
......@@ -414,16 +404,6 @@ void SetTranslatedDictionary(const char* settings_dict_key,
dict->SetString(kTranslatedKey, translated_value);
}
std::string CopyStringFromDictionary(const base::DictionaryValue& source,
const std::string& src_key,
const std::string& dest_key,
base::DictionaryValue* dest) {
std::string string_value;
if (source.GetStringWithoutPathExpansion(src_key, &string_value))
dest->SetStringWithoutPathExpansion(dest_key, string_value);
return string_value;
}
// Fills |dictionary| with the configuration details of |vpn|. |onc| is required
// for augmenting the policy-managed information.
void PopulateVPNDetails(const NetworkState* vpn,
......@@ -506,24 +486,7 @@ int FindCurrentCarrierIndex(const base::ListValue* carriers,
return -1;
}
void CreateDictionaryFromCellularApn(const base::DictionaryValue* apn,
base::DictionaryValue* dictionary) {
CopyStringFromDictionary(*apn, shill::kApnProperty, kTagApn, dictionary);
CopyStringFromDictionary(
*apn, shill::kApnNetworkIdProperty, kTagNetworkId, dictionary);
CopyStringFromDictionary(
*apn, shill::kApnUsernameProperty, kTagUsername, dictionary);
CopyStringFromDictionary(
*apn, shill::kApnPasswordProperty, kTagPassword, dictionary);
CopyStringFromDictionary(*apn, shill::kApnNameProperty, kTagName, dictionary);
CopyStringFromDictionary(
*apn, shill::kApnLocalizedNameProperty, kTagLocalizedName, dictionary);
CopyStringFromDictionary(
*apn, shill::kApnLanguageProperty, kTagLanguage, dictionary);
}
void PopulateCellularDetails(const NetworkState* cellular,
const base::DictionaryValue& shill_properties,
base::DictionaryValue* dictionary) {
dictionary->SetBoolean(kTagCarrierSelectFlag,
CommandLine::ForCurrentProcess()->HasSwitch(
......@@ -539,29 +502,6 @@ void PopulateCellularDetails(const NetworkState* cellular,
internet_options_strings::RestrictedStateString(
cellular->connection_state()));
const base::DictionaryValue* olp = NULL;
if (shill_properties.GetDictionaryWithoutPathExpansion(
shill::kPaymentPortalProperty, &olp)) {
std::string url;
olp->GetStringWithoutPathExpansion(shill::kPaymentPortalURL, &url);
dictionary->SetString(kTagSupportUrl, url);
}
base::DictionaryValue* apn = new base::DictionaryValue;
const base::DictionaryValue* source_apn = NULL;
if (shill_properties.GetDictionaryWithoutPathExpansion(
shill::kCellularApnProperty, &source_apn)) {
CreateDictionaryFromCellularApn(source_apn, apn);
}
dictionary->Set(kTagApn, apn);
base::DictionaryValue* last_good_apn = new base::DictionaryValue;
if (shill_properties.GetDictionaryWithoutPathExpansion(
shill::kCellularLastGoodApnProperty, &source_apn)) {
CreateDictionaryFromCellularApn(source_apn, last_good_apn);
}
dictionary->Set(kTagLastGoodApn, last_good_apn);
// These default to empty and are only set if device != NULL.
std::string carrier_id;
std::string mdn;
......@@ -572,15 +512,6 @@ void PopulateCellularDetails(const NetworkState* cellular,
cellular->device_path());
if (device) {
const base::DictionaryValue& device_properties = device->properties();
::onc::ONCSource onc_source;
NetworkHandler::Get()->managed_network_configuration_handler()->
FindPolicyByGUID(LoginState::Get()->primary_user_hash(),
cellular->guid(), &onc_source);
const NetworkPropertyUIData cellular_property_ui_data(onc_source);
SetValueDictionary(kTagSimCardLockEnabled,
new base::FundamentalValue(device->sim_lock_enabled()),
cellular_property_ui_data,
dictionary);
carrier_id = device->home_provider_id();
device_properties.GetStringWithoutPathExpansion(shill::kMdnProperty, &mdn);
......@@ -592,25 +523,6 @@ void PopulateCellularDetails(const NetworkState* cellular,
dictionary->SetString(kTagCarrierUrl, carrier->top_up_url());
}
base::ListValue* apn_list_value = new base::ListValue();
const base::ListValue* apn_list;
if (device_properties.GetListWithoutPathExpansion(
shill::kCellularApnListProperty, &apn_list)) {
for (base::ListValue::const_iterator iter = apn_list->begin();
iter != apn_list->end();
++iter) {
const base::DictionaryValue* dict;
if ((*iter)->GetAsDictionary(&dict)) {
base::DictionaryValue* apn = new base::DictionaryValue;
CreateDictionaryFromCellularApn(dict, apn);
apn_list_value->Append(apn);
}
}
}
SetValueDictionary(kTagProviderApnList,
apn_list_value,
cellular_property_ui_data,
dictionary);
const base::ListValue* supported_carriers;
if (device_properties.GetListWithoutPathExpansion(
shill::kSupportedCarriersProperty, &supported_carriers)) {
......@@ -626,12 +538,9 @@ void PopulateCellularDetails(const NetworkState* cellular,
}
// Don't show any account management related buttons if the activation
// state is unknown or no payment portal URL is available.
std::string support_url;
if (cellular->activation_state() == shill::kActivationStateUnknown ||
!dictionary->GetString(kTagSupportUrl, &support_url) ||
support_url.empty()) {
VLOG(2) << "No support URL is available. Don't display buttons.";
// state is unknown.
if (cellular->activation_state() == shill::kActivationStateUnknown) {
VLOG(2) << "Activation state unknown. Don't display buttons.";
return;
}
......@@ -639,15 +548,11 @@ void PopulateCellularDetails(const NetworkState* cellular,
cellular->activation_state() != shill::kActivationStateActivated) {
dictionary->SetBoolean(kTagShowActivateButton, true);
} else {
bool may_show_portal_button = false;
// If an online payment URL was provided by shill, then this means that the
// "View Account" button should be shown for the current carrier.
if (olp) {
std::string url;
olp->GetStringWithoutPathExpansion(shill::kPaymentPortalURL, &url);
may_show_portal_button = !url.empty();
}
// TODO(stevenjb): Determine if we actually need this check. The payment url
// property is commented as 'Deprecated' in service_constants.h and appears
// to be unset in Shill, but we still reference it in mobile_setup.cc.
bool may_show_portal_button = !cellular->payment_url().empty();
// If no online payment URL was provided by shill, fall back to
// MobileConfig to determine if the "View Account" should be shown.
if (!may_show_portal_button && MobileConfig::GetInstance()->IsReady()) {
......@@ -721,7 +626,7 @@ scoped_ptr<base::DictionaryValue> PopulateConnectionDetails(
dictionary->SetBoolean(kTagDeviceConnected, connected_network != NULL);
if (type == shill::kTypeCellular)
PopulateCellularDetails(network, shill_properties, dictionary.get());
PopulateCellularDetails(network, dictionary.get());
else if (type == shill::kTypeVPN)
PopulateVPNDetails(network, shill_properties, dictionary.get());
......
......@@ -99,6 +99,12 @@ bool NetworkState::PropertyChanged(const std::string& key,
return GetStringValue(key, value, &activation_state_);
} else if (key == shill::kRoamingStateProperty) {
return GetStringValue(key, value, &roaming_);
} else if (key == shill::kPaymentPortalProperty) {
const base::DictionaryValue* olp;
if (!value.GetAsDictionary(&olp))
return false;
return olp->GetStringWithoutPathExpansion(shill::kPaymentPortalURL,
&payment_url_);
} else if (key == shill::kSecurityProperty) {
return GetStringValue(key, value, &security_);
} else if (key == shill::kEapMethodProperty) {
......
......@@ -87,6 +87,7 @@ class CHROMEOS_EXPORT NetworkState : public ManagedState {
const std::string& activation_type() const { return activation_type_; }
const std::string& activation_state() const { return activation_state_; }
const std::string& roaming() const { return roaming_; }
const std::string& payment_url() const { return payment_url_; }
bool cellular_out_of_credits() const { return cellular_out_of_credits_; }
// Whether this network has a CACertNSS nickname set.
......@@ -169,6 +170,7 @@ class CHROMEOS_EXPORT NetworkState : public ManagedState {
std::string activation_type_;
std::string activation_state_;
std::string roaming_;
std::string payment_url_;
bool cellular_out_of_credits_;
// Whether a deprecated CaCertNSS property of this network is set. Required
......
......@@ -223,6 +223,7 @@ const OncFieldSignature cellular_provider_fields[] = {
{NULL}};
const OncFieldSignature cellular_apn_fields[] = {
{ ::onc::cellular_apn::kAccessPointName, &kStringSignature},
{ ::onc::cellular_apn::kName, &kStringSignature},
{ ::onc::cellular_apn::kUsername, &kStringSignature},
{ ::onc::cellular_apn::kPassword, &kStringSignature},
......@@ -264,6 +265,7 @@ const OncFieldSignature cellular_with_state_fields[] = {
{ ::onc::cellular::kICCID, &kStringSignature},
{ ::onc::cellular::kIMEI, &kStringSignature},
{ ::onc::cellular::kIMSI, &kStringSignature},
{ ::onc::cellular::kLastGoodAPN, &kCellularApnSignature },
{ ::onc::cellular::kManufacturer, &kStringSignature},
{ ::onc::cellular::kMDN, &kStringSignature},
{ ::onc::cellular::kMEID, &kStringSignature},
......
......@@ -120,7 +120,8 @@ const FieldTranslationEntry wifi_fields[] = {
{NULL}};
const FieldTranslationEntry cellular_apn_fields[] = {
{ ::onc::cellular_apn::kName, shill::kApnProperty},
{ ::onc::cellular_apn::kAccessPointName, shill::kApnProperty},
{ ::onc::cellular_apn::kName, shill::kApnNameProperty},
{ ::onc::cellular_apn::kUsername, shill::kApnUsernameProperty},
{ ::onc::cellular_apn::kPassword, shill::kApnPasswordProperty},
{ ::onc::cellular_apn::kLocalizedName, shill::kApnLocalizedNameProperty},
......
......@@ -309,6 +309,10 @@ void ShillToONCTranslator::TranslateCellularWithState() {
shill::kCellularApnProperty, &dictionary)) {
TranslateAndAddNestedObject(::onc::cellular::kAPN, *dictionary);
}
if (shill_dictionary_->GetDictionaryWithoutPathExpansion(
shill::kCellularLastGoodApnProperty, &dictionary)) {
TranslateAndAddNestedObject(::onc::cellular::kLastGoodAPN, *dictionary);
}
// Merge the Device dictionary with this one (Cellular) using the
// CellularDevice signature.
const base::DictionaryValue* device_dictionary = NULL;
......
......@@ -3,7 +3,7 @@
"Name": "Test Network",
"Cellular": {
"APN": {
"Name": "test-apn",
"AccessPointName": "test-apn",
"Username": "test-username",
"Password": "test-password"
}
......
......@@ -15,24 +15,25 @@
"Name": "test-name"
},
"APN": {
"Name": "test-apn",
"AccessPointName": "test-apn",
"Name": "test-apn-name",
"Username": "test-username",
"Password": "test-password"
},
"APNList": [ {
"Name": "test-apn0",
"AccessPointName": "test-apn0",
"Password": "test-password0",
"Username": "test-username0"
}, {
"Name": "test-apn1",
"AccessPointName": "test-apn1",
"Password": "test-password1",
"Username": "test-username1"
}, {
"Name": "test-apn2",
"AccessPointName": "test-apn2",
"Password": "test-password2",
"Username": "test-username2"
}, {
"Name": "test-apn3",
"AccessPointName": "test-apn3",
"Password": "test-password3",
"Username": "test-username3"
}
......
......@@ -91,6 +91,7 @@ const char kHomeProvider[] = "HomeProvider";
const char kICCID[] = "ICCID";
const char kIMEI[] = "IMEI";
const char kIMSI[] = "IMSI";
const char kLastGoodAPN[] = "LastGoodAPN";
const char kManufacturer[] = "Manufacturer";
const char kMDN[] = "MDN";
const char kMEID[] = "MEID";
......@@ -115,6 +116,7 @@ const char kName[] = "Name";
} // namespace cellular_provider
namespace cellular_apn {
const char kAccessPointName[] = "AccessPointName";
const char kName[] = "Name";
const char kUsername[] = "Username";
const char kPassword[] = "Password";
......
......@@ -108,6 +108,7 @@ ONC_EXPORT extern const char kHomeProvider[];
ONC_EXPORT extern const char kICCID[];
ONC_EXPORT extern const char kIMEI[];
ONC_EXPORT extern const char kIMSI[];
ONC_EXPORT extern const char kLastGoodAPN[];
ONC_EXPORT extern const char kManufacturer[];
ONC_EXPORT extern const char kMDN[];
ONC_EXPORT extern const char kMEID[];
......@@ -132,6 +133,7 @@ ONC_EXPORT extern const char kName[];
} // namespace cellular_provider
namespace cellular_apn {
ONC_EXPORT extern const char kAccessPointName[];
ONC_EXPORT extern const char kName[];
ONC_EXPORT extern const char kUsername[];
ONC_EXPORT extern const char kPassword[];
......
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