diff options
author | stevenjb@chromium.org <stevenjb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-07-25 19:14:29 +0000 |
---|---|---|
committer | stevenjb@chromium.org <stevenjb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-07-25 19:14:29 +0000 |
commit | a2026bae02183185d44ea2f3d0cf426a10757a2b (patch) | |
tree | 86956389a2d6422dd8d035ff5285e28c7b783f1d | |
parent | 4046634cb38fe63eb88b8b0952cc7c41d1e530c2 (diff) | |
download | chromium_src-a2026bae02183185d44ea2f3d0cf426a10757a2b.zip chromium_src-a2026bae02183185d44ea2f3d0cf426a10757a2b.tar.gz chromium_src-a2026bae02183185d44ea2f3d0cf426a10757a2b.tar.bz2 |
Correctly translate Cellular Device properties to ONC
This fixes how we translate the Device properties to ONC instead of
just copying the Shill properties.
BUG=279351
Review URL: https://codereview.chromium.org/402953004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@285642 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chromeos/network/onc/onc_signature.cc | 42 | ||||
-rw-r--r-- | chromeos/network/onc/onc_signature.h | 2 | ||||
-rw-r--r-- | chromeos/network/onc/onc_translation_tables.cc | 28 | ||||
-rw-r--r-- | chromeos/network/onc/onc_translator_shill_to_onc.cc | 65 | ||||
-rw-r--r-- | chromeos/test/data/network/shill_cellular_with_state.json | 49 | ||||
-rw-r--r-- | chromeos/test/data/network/translation_of_shill_cellular_with_state.onc | 6 | ||||
-rw-r--r-- | components/onc/onc_constants.cc | 18 | ||||
-rw-r--r-- | components/onc/onc_constants.h | 17 |
8 files changed, 163 insertions, 64 deletions
diff --git a/chromeos/network/onc/onc_signature.cc b/chromeos/network/onc/onc_signature.cc index 54632ac..1b1daa7 100644 --- a/chromeos/network/onc/onc_signature.cc +++ b/chromeos/network/onc/onc_signature.cc @@ -22,6 +22,9 @@ const OncValueSignature kStringSignature = { const OncValueSignature kIntegerSignature = { base::Value::TYPE_INTEGER, NULL }; +const OncValueSignature kDoubleSignature = { + base::Value::TYPE_DOUBLE, NULL +}; const OncValueSignature kStringListSignature = { base::Value::TYPE_LIST, NULL, &kStringSignature }; @@ -34,6 +37,9 @@ const OncValueSignature kIPConfigListSignature = { const OncValueSignature kCellularApnListSignature = { base::Value::TYPE_LIST, NULL, &kCellularApnSignature }; +const OncValueSignature kCellularFoundNetworkListSignature = { + base::Value::TYPE_LIST, NULL, &kCellularFoundNetworkSignature +}; const OncFieldSignature issuer_subject_pattern_fields[] = { { ::onc::client_cert::kCommonName, &kStringSignature}, @@ -220,6 +226,22 @@ const OncFieldSignature cellular_apn_fields[] = { { ::onc::cellular_apn::kName, &kStringSignature}, { ::onc::cellular_apn::kUsername, &kStringSignature}, { ::onc::cellular_apn::kPassword, &kStringSignature}, + { ::onc::cellular_apn::kLocalizedName, &kStringSignature}, + { ::onc::cellular_apn::kLanguage, &kStringSignature}, + {NULL}}; + +const OncFieldSignature cellular_found_network_fields[] = { + { ::onc::cellular_found_network::kStatus, &kStringSignature}, + { ::onc::cellular_found_network::kNetworkId, &kStringSignature}, + { ::onc::cellular_found_network::kShortName, &kStringSignature}, + { ::onc::cellular_found_network::kLongName, &kStringSignature}, + { ::onc::cellular_found_network::kTechnology, &kStringSignature}, + {NULL}}; + +const OncFieldSignature sim_lock_status_fields[] = { + { ::onc::sim_lock_status::kLockEnabled, &kBoolSignature}, + { ::onc::sim_lock_status::kLockType, &kStringSignature}, + { ::onc::sim_lock_status::kRetriesLeft, &kDoubleSignature}, {NULL}}; const OncFieldSignature cellular_fields[] = { @@ -236,7 +258,7 @@ const OncFieldSignature cellular_with_state_fields[] = { { ::onc::cellular::kESN, &kStringSignature}, { ::onc::cellular::kFamily, &kStringSignature}, { ::onc::cellular::kFirmwareRevision, &kStringSignature}, - { ::onc::cellular::kFoundNetworks, &kStringSignature}, + { ::onc::cellular::kFoundNetworks, &kCellularFoundNetworkListSignature}, { ::onc::cellular::kHardwareRevision, &kStringSignature}, { ::onc::cellular::kHomeProvider, &kCellularProviderSignature}, { ::onc::cellular::kICCID, &kStringSignature}, @@ -248,17 +270,15 @@ const OncFieldSignature cellular_with_state_fields[] = { { ::onc::cellular::kMIN, &kStringSignature}, { ::onc::cellular::kModelID, &kStringSignature}, { ::onc::cellular::kNetworkTechnology, &kStringSignature}, - { ::onc::cellular::kPRLVersion, &kStringSignature}, + { ::onc::cellular::kPRLVersion, &kIntegerSignature}, { ::onc::cellular::kProviderRequiresRoaming, &kBoolSignature}, { ::onc::cellular::kRoamingState, &kStringSignature}, { ::onc::cellular::kSelectedNetwork, &kStringSignature}, { ::onc::cellular::kServingOperator, &kCellularProviderSignature}, - { ::onc::cellular::kSIMLockEnabled, &kBoolSignature}, - { ::onc::cellular::kSIMLockStatus, &kStringSignature}, - { ::onc::cellular::kSIMLockType, &kStringSignature}, - { ::onc::cellular::kSIMPresent, &kStringSignature}, - { ::onc::cellular::kSupportedCarriers, &kStringSignature}, - { ::onc::cellular::kSupportNetworkScan, &kStringSignature}, + { ::onc::cellular::kSIMLockStatus, &kSIMLockStatusSignature}, + { ::onc::cellular::kSIMPresent, &kBoolSignature}, + { ::onc::cellular::kSupportNetworkScan, &kBoolSignature}, + { ::onc::cellular::kSupportedCarriers, &kStringListSignature}, {NULL}}; const OncFieldSignature network_configuration_fields[] = { @@ -409,6 +429,12 @@ const OncValueSignature kCellularProviderSignature = { const OncValueSignature kCellularApnSignature = { base::Value::TYPE_DICTIONARY, cellular_apn_fields, NULL }; +const OncValueSignature kCellularFoundNetworkSignature = { + base::Value::TYPE_DICTIONARY, cellular_found_network_fields, NULL +}; +const OncValueSignature kSIMLockStatusSignature = { + base::Value::TYPE_DICTIONARY, sim_lock_status_fields, NULL +}; const OncFieldSignature* GetFieldSignature(const OncValueSignature& signature, const std::string& onc_field_name) { diff --git a/chromeos/network/onc/onc_signature.h b/chromeos/network/onc/onc_signature.h index d4904b0..31a4f2a 100644 --- a/chromeos/network/onc/onc_signature.h +++ b/chromeos/network/onc/onc_signature.h @@ -67,6 +67,8 @@ CHROMEOS_EXPORT extern const OncValueSignature kCellularSignature; CHROMEOS_EXPORT extern const OncValueSignature kCellularWithStateSignature; CHROMEOS_EXPORT extern const OncValueSignature kCellularProviderSignature; CHROMEOS_EXPORT extern const OncValueSignature kCellularApnSignature; +CHROMEOS_EXPORT extern const OncValueSignature kCellularFoundNetworkSignature; +CHROMEOS_EXPORT extern const OncValueSignature kSIMLockStatusSignature; } // namespace onc } // namespace chromeos diff --git a/chromeos/network/onc/onc_translation_tables.cc b/chromeos/network/onc/onc_translation_tables.cc index 8181216..6aba3c1 100644 --- a/chromeos/network/onc/onc_translation_tables.cc +++ b/chromeos/network/onc/onc_translation_tables.cc @@ -122,6 +122,16 @@ const FieldTranslationEntry cellular_apn_fields[] = { { ::onc::cellular_apn::kName, shill::kApnProperty}, { ::onc::cellular_apn::kUsername, shill::kApnUsernameProperty}, { ::onc::cellular_apn::kPassword, shill::kApnPasswordProperty}, + { ::onc::cellular_apn::kLocalizedName, shill::kApnLocalizedNameProperty}, + { ::onc::cellular_apn::kLanguage, shill::kApnLanguageProperty}, + {NULL}}; + +const FieldTranslationEntry cellular_found_network_fields[] = { + { ::onc::cellular_found_network::kNetworkId, shill::kNetworkIdProperty}, + { ::onc::cellular_found_network::kStatus, shill::kStatusProperty}, + { ::onc::cellular_found_network::kTechnology, shill::kTechnologyProperty}, + { ::onc::cellular_found_network::kShortName, shill::kShortNameProperty}, + { ::onc::cellular_found_network::kLongName, shill::kLongNameProperty}, {NULL}}; const FieldTranslationEntry cellular_provider_fields[] = { @@ -130,6 +140,12 @@ const FieldTranslationEntry cellular_provider_fields[] = { { ::onc::cellular_provider::kName, shill::kOperatorNameKey}, {NULL}}; +const FieldTranslationEntry sim_lock_status_fields[] = { + { ::onc::sim_lock_status::kLockEnabled, shill::kSIMLockEnabledProperty}, + { ::onc::sim_lock_status::kLockType, shill::kSIMLockTypeProperty}, + { ::onc::sim_lock_status::kRetriesLeft, shill::kSIMLockRetriesLeftProperty}, + {NULL}}; + // This must only contain Service properties and not Device properties. // For Device properties see kCellularDeviceTable. const FieldTranslationEntry cellular_fields[] = { @@ -185,7 +201,9 @@ const OncValueTranslationEntry onc_value_translation_table[] = { { &kWiFiSignature, wifi_fields }, { &kWiFiWithStateSignature, wifi_fields }, { &kCellularApnSignature, cellular_apn_fields }, + { &kCellularFoundNetworkSignature, cellular_found_network_fields }, { &kCellularProviderSignature, cellular_provider_fields }, + { &kSIMLockStatusSignature, sim_lock_status_fields }, { &kCellularSignature, cellular_fields }, { &kCellularWithStateSignature, cellular_fields }, { &kNetworkWithStateSignature, network_fields }, @@ -258,12 +276,15 @@ const StringTranslationEntry kEAP_TTLS_InnerTable[] = { // This must contain only Shill Device properties and no Service properties. // For Service properties see cellular_fields. const FieldTranslationEntry kCellularDeviceTable[] = { + // This field is converted during translation, see onc_translator_*. + // { ::onc::cellular::kAPNList, shill::kCellularApnListProperty}, { ::onc::cellular::kAllowRoaming, shill::kCellularAllowRoamingProperty}, { ::onc::cellular::kCarrier, shill::kCarrierProperty}, { ::onc::cellular::kESN, shill::kEsnProperty}, { ::onc::cellular::kFamily, shill::kTechnologyFamilyProperty}, { ::onc::cellular::kFirmwareRevision, shill::kFirmwareRevisionProperty}, - { ::onc::cellular::kFoundNetworks, shill::kFoundNetworksProperty}, + // This field is converted during translation, see onc_translator_*. + // { ::onc::cellular::kFoundNetworks, shill::kFoundNetworksProperty}, { ::onc::cellular::kHardwareRevision, shill::kHardwareRevisionProperty}, { ::onc::cellular::kHomeProvider, shill::kHomeProviderProperty}, { ::onc::cellular::kICCID, shill::kIccidProperty}, @@ -278,9 +299,8 @@ const FieldTranslationEntry kCellularDeviceTable[] = { { ::onc::cellular::kProviderRequiresRoaming, shill::kProviderRequiresRoamingProperty}, { ::onc::cellular::kSelectedNetwork, shill::kSelectedNetworkProperty}, - { ::onc::cellular::kSIMLockEnabled, shill::kSIMLockEnabledProperty}, - { ::onc::cellular::kSIMLockStatus, shill::kSIMLockStatusProperty}, - { ::onc::cellular::kSIMLockType, shill::kSIMLockTypeProperty}, + // This field is converted during translation, see onc_translator_*. + // { ::onc::cellular::kSIMLockStatus, shill::kSIMLockStatusProperty}, { ::onc::cellular::kSIMPresent, shill::kSIMPresentProperty}, { ::onc::cellular::kSupportedCarriers, shill::kSupportedCarriersProperty}, { ::onc::cellular::kSupportNetworkScan, shill::kSupportNetworkScanProperty}, diff --git a/chromeos/network/onc/onc_translator_shill_to_onc.cc b/chromeos/network/onc/onc_translator_shill_to_onc.cc index a3651f6..dc01b2a 100644 --- a/chromeos/network/onc/onc_translator_shill_to_onc.cc +++ b/chromeos/network/onc/onc_translator_shill_to_onc.cc @@ -55,6 +55,14 @@ class ShillToONCTranslator { field_translation_table_ = GetFieldTranslationTable(onc_signature); } + ShillToONCTranslator(const base::DictionaryValue& shill_dictionary, + const OncValueSignature& onc_signature, + const FieldTranslationEntry* field_translation_table) + : shill_dictionary_(&shill_dictionary), + onc_signature_(&onc_signature), + field_translation_table_(field_translation_table) { + } + // Translates the associated Shill dictionary and creates an ONC object of the // given signature. scoped_ptr<base::DictionaryValue> CreateTranslatedONCObject(); @@ -66,6 +74,7 @@ class ShillToONCTranslator { void TranslateVPN(); void TranslateWiFiWithState(); void TranslateCellularWithState(); + void TranslateCellularDevice(); void TranslateNetworkWithState(); void TranslateIPConfig(); @@ -132,7 +141,10 @@ ShillToONCTranslator::CreateTranslatedONCObject() { } else if (onc_signature_ == &kWiFiWithStateSignature) { TranslateWiFiWithState(); } else if (onc_signature_ == &kCellularWithStateSignature) { - TranslateCellularWithState(); + if (field_translation_table_ == kCellularDeviceTable) + TranslateCellularDevice(); + else + TranslateCellularWithState(); } else if (onc_signature_ == &kIPConfigSignature) { TranslateIPConfig(); } else { @@ -258,36 +270,39 @@ void ShillToONCTranslator::TranslateCellularWithState() { shill::kCellularApnProperty, &dictionary)) { TranslateAndAddNestedObject(::onc::cellular::kAPN, *dictionary); } - const base::ListValue* shill_apns = NULL; - if (shill_dictionary_->GetListWithoutPathExpansion( - shill::kCellularApnListProperty, &shill_apns)) { - TranslateAndAddListOfObjects(::onc::cellular::kAPNList, *shill_apns); - } - + // Merge the Device dictionary with this one (Cellular) using the + // CellularDevice signature. const base::DictionaryValue* device_dictionary = NULL; if (!shill_dictionary_->GetDictionaryWithoutPathExpansion( shill::kDeviceProperty, &device_dictionary)) { return; } + ShillToONCTranslator nested_translator(*device_dictionary, + kCellularWithStateSignature, + kCellularDeviceTable); + scoped_ptr<base::DictionaryValue> nested_object = + nested_translator.CreateTranslatedONCObject(); + onc_object_->MergeDictionary(nested_object.get()); +} - // Iterate through all fields of the CellularWithState signature and copy - // values from the device properties according to the separate - // CellularDeviceTable. - for (const OncFieldSignature* field_signature = onc_signature_->fields; - field_signature->onc_field_name != NULL; ++field_signature) { - const std::string& onc_field_name = field_signature->onc_field_name; - - std::string shill_property_name; - const base::Value* shill_value = NULL; - if (!GetShillPropertyName(field_signature->onc_field_name, - kCellularDeviceTable, - &shill_property_name) || - !device_dictionary->GetWithoutPathExpansion(shill_property_name, - &shill_value)) { - continue; - } - onc_object_->SetWithoutPathExpansion(onc_field_name, - shill_value->DeepCopy()); +void ShillToONCTranslator::TranslateCellularDevice() { + CopyPropertiesAccordingToSignature(); + const base::DictionaryValue* shill_sim_lock_status = NULL; + if (shill_dictionary_->GetDictionaryWithoutPathExpansion( + shill::kSIMLockStatusProperty, &shill_sim_lock_status)) { + TranslateAndAddNestedObject(::onc::cellular::kSIMLockStatus, + *shill_sim_lock_status); + } + const base::ListValue* shill_apns = NULL; + if (shill_dictionary_->GetListWithoutPathExpansion( + shill::kCellularApnListProperty, &shill_apns)) { + TranslateAndAddListOfObjects(::onc::cellular::kAPNList, *shill_apns); + } + const base::ListValue* shill_found_networks = NULL; + if (shill_dictionary_->GetListWithoutPathExpansion( + shill::kFoundNetworksProperty, &shill_found_networks)) { + TranslateAndAddListOfObjects(::onc::cellular::kFoundNetworks, + *shill_found_networks); } } diff --git a/chromeos/test/data/network/shill_cellular_with_state.json b/chromeos/test/data/network/shill_cellular_with_state.json index 96d0f70..b26aaae 100644 --- a/chromeos/test/data/network/shill_cellular_with_state.json +++ b/chromeos/test/data/network/shill_cellular_with_state.json @@ -10,38 +10,43 @@ }, "Cellular.APN": { "apn": "test-apn", + "name": "test-apn-name", "username": "test-username", "password": "test-password" }, - "Cellular.APNList": [ - { - "apn": "test-apn0", - "username": "test-username0", - "password": "test-password0" - }, - { - "apn": "test-apn1", - "username": "test-username1", - "password": "test-password1" - }, - { - "apn": "test-apn2", - "username": "test-username2", - "password": "test-password2" - }, - { - "apn": "test-apn3", - "username": "test-username3", - "password": "test-password3" - } - ], "Device": { // This dictionary contains Device properties and not Service properties as // above. "Cellular.AllowRoaming": true, + "Cellular.APNList": [ + { + "apn": "test-apn0", + "username": "test-username0", + "password": "test-password0" + }, + { + "apn": "test-apn1", + "username": "test-username1", + "password": "test-password1" + }, + { + "apn": "test-apn2", + "username": "test-username2", + "password": "test-password2" + }, + { + "apn": "test-apn3", + "username": "test-username3", + "password": "test-password3" + } + ], "Cellular.HomeProvider": { "country": "us", "name": "cellular_provider" + }, + "Cellular.SIMLockStatus": { + "LockType": "sim-pin", + "LockEnabled": true } } } diff --git a/chromeos/test/data/network/translation_of_shill_cellular_with_state.onc b/chromeos/test/data/network/translation_of_shill_cellular_with_state.onc index 0ce9ce7..ee290f5 100644 --- a/chromeos/test/data/network/translation_of_shill_cellular_with_state.onc +++ b/chromeos/test/data/network/translation_of_shill_cellular_with_state.onc @@ -36,6 +36,10 @@ "Password": "test-password3", "Username": "test-username3" } - ] + ], + "SIMLockStatus": { + "LockType": "sim-pin", + "LockEnabled": true + } } } diff --git a/components/onc/onc_constants.cc b/components/onc/onc_constants.cc index 57df38e..f7e932b 100644 --- a/components/onc/onc_constants.cc +++ b/components/onc/onc_constants.cc @@ -101,9 +101,7 @@ const char kProviderRequiresRoaming[] = "ProviderRequiresRoaming"; const char kRoamingState[] = "RoamingState"; const char kSelectedNetwork[] = "SelectedNetwork"; const char kServingOperator[] = "ServingOperator"; -const char kSIMLockEnabled[] = "SIMLockEnabled"; const char kSIMLockStatus[] = "SIMLockStatus"; -const char kSIMLockType[] = "SIMLockType"; const char kSIMPresent[] = "SIMPresent"; const char kSupportedCarriers[] = "SupportedCarriers"; const char kSupportNetworkScan[] = "SupportNetworkScan"; @@ -119,8 +117,24 @@ namespace cellular_apn { const char kName[] = "Name"; const char kUsername[] = "Username"; const char kPassword[] = "Password"; +const char kLocalizedName[] = "LocalizedName"; +const char kLanguage[] = "LocalizedName"; } // namespace cellular_apn +namespace cellular_found_network { +const char kStatus[] = "Status"; +const char kNetworkId[] = "NetworkId"; +const char kShortName[] = "ShortName"; +const char kLongName[] = "LongName"; +const char kTechnology[] = "Technology"; +} // namespace cellular_apn + +namespace sim_lock_status { +const char kLockEnabled[] = "LockEnabled"; +const char kLockType[] = "LockType"; +const char kRetriesLeft[] = "RetriesLeft"; +} + namespace connection_state { const char kConnected[] = "Connected"; const char kConnecting[] = "Connecting"; diff --git a/components/onc/onc_constants.h b/components/onc/onc_constants.h index e3db4d7..ca85a76 100644 --- a/components/onc/onc_constants.h +++ b/components/onc/onc_constants.h @@ -118,9 +118,7 @@ ONC_EXPORT extern const char kProviderRequiresRoaming[]; ONC_EXPORT extern const char kRoamingState[]; ONC_EXPORT extern const char kSelectedNetwork[]; ONC_EXPORT extern const char kServingOperator[]; -ONC_EXPORT extern const char kSIMLockEnabled[]; ONC_EXPORT extern const char kSIMLockStatus[]; -ONC_EXPORT extern const char kSIMLockType[]; ONC_EXPORT extern const char kSIMPresent[]; ONC_EXPORT extern const char kSupportedCarriers[]; ONC_EXPORT extern const char kSupportNetworkScan[]; @@ -136,8 +134,23 @@ namespace cellular_apn { ONC_EXPORT extern const char kName[]; ONC_EXPORT extern const char kUsername[]; ONC_EXPORT extern const char kPassword[]; +ONC_EXPORT extern const char kLocalizedName[]; +ONC_EXPORT extern const char kLanguage[]; } // namespace cellular_apn +namespace cellular_found_network { +ONC_EXPORT extern const char kStatus[]; +ONC_EXPORT extern const char kNetworkId[]; +ONC_EXPORT extern const char kShortName[]; +ONC_EXPORT extern const char kLongName[]; +ONC_EXPORT extern const char kTechnology[]; +} // namespace cellular_found_network + +namespace sim_lock_status { +ONC_EXPORT extern const char kLockEnabled[]; +ONC_EXPORT extern const char kLockType[]; +ONC_EXPORT extern const char kRetriesLeft[]; +} // namespace sim_lock_status namespace connection_state { ONC_EXPORT extern const char kConnected[]; |