diff options
author | Treehugger Robot <android-test-infra-autosubmit@system.gserviceaccount.com> | 2024-05-08 00:25:03 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2024-05-08 00:25:03 +0000 |
commit | a077ddd87162d6cd05c0aa1ad906f237db3a08f6 (patch) | |
tree | 50f87e0aecf914d2e2bc416e68045c3d1e39734b | |
parent | 7e301ae4ab6106d08b6f3781cd62e587cc2cd0a8 (diff) | |
parent | 6347320a71abe744ab733b93a0648efb3fd841e8 (diff) | |
download | cuttlefish-a077ddd87162d6cd05c0aa1ad906f237db3a08f6.tar.gz |
Merge "Minor refactors in modem_simulator" into main
-rw-r--r-- | host/commands/modem_simulator/main.cpp | 2 | ||||
-rw-r--r-- | host/commands/modem_simulator/network_service.cpp | 17 | ||||
-rw-r--r-- | host/commands/modem_simulator/nvram_config.cpp | 8 | ||||
-rw-r--r-- | host/commands/modem_simulator/nvram_config.h | 2 |
4 files changed, 12 insertions, 17 deletions
diff --git a/host/commands/modem_simulator/main.cpp b/host/commands/modem_simulator/main.cpp index a979c3662..c22d11d77 100644 --- a/host/commands/modem_simulator/main.cpp +++ b/host/commands/modem_simulator/main.cpp @@ -92,7 +92,7 @@ int ModemSimulatorMain(int argc, char** argv) { } auto nvram_config = NvramConfig::Get(); - auto nvram_config_file = nvram_config->ConfigFileLocation(); + const auto nvram_config_file = nvram_config->ConfigFileLocation(); // Start channel monitor, wait for RIL to connect int32_t modem_id = 0; diff --git a/host/commands/modem_simulator/network_service.cpp b/host/commands/modem_simulator/network_service.cpp index 25a2f97d4..03d0a59a9 100644 --- a/host/commands/modem_simulator/network_service.cpp +++ b/host/commands/modem_simulator/network_service.cpp @@ -160,18 +160,15 @@ void NetworkService::InitializeNetworkOperator() { current_operator_numeric_ = operator_list_.begin()->numeric; operator_list_.begin()->operator_state = NetworkOperator::OPER_STATE_CURRENT; } else if (oper_selection_mode_ == OperatorSelectionMode::OPER_SELECTION_MANUAL_AUTOMATIC) { - auto iter = operator_list_.begin(); - for (; iter != operator_list_.end(); ++iter) { - if (iter->numeric == current_operator_numeric_) { - break; + for (auto& iter : operator_list_) { + if (iter.numeric == current_operator_numeric_) { + iter.operator_state = NetworkOperator::OPER_STATE_CURRENT; + return; } } - if (iter == operator_list_.end()) { - current_operator_numeric_ = operator_list_.begin()->numeric; - operator_list_.begin()->operator_state = NetworkOperator::OPER_STATE_CURRENT; - } else { - iter->operator_state = NetworkOperator::OPER_STATE_CURRENT; - } + current_operator_numeric_ = operator_list_.begin()->numeric; + operator_list_.begin()->operator_state = + NetworkOperator::OPER_STATE_CURRENT; } } diff --git a/host/commands/modem_simulator/nvram_config.cpp b/host/commands/modem_simulator/nvram_config.cpp index 22b337329..021ba7391 100644 --- a/host/commands/modem_simulator/nvram_config.cpp +++ b/host/commands/modem_simulator/nvram_config.cpp @@ -45,11 +45,9 @@ static constexpr bool kDefaultEmergencyMode = false; * Returns nullptr if there was an error loading from file */ NvramConfig* NvramConfig::BuildConfigImpl(size_t num_instances, int sim_type) { - auto nvram_config_path = - cuttlefish::modem::DeviceConfig::PerInstancePath("modem_nvram.json"); - auto ret = new NvramConfig(num_instances, sim_type); if (ret) { + const auto nvram_config_path = ConfigFileLocation(); if (!cuttlefish::FileExists(nvram_config_path) || !cuttlefish::FileHasContent(nvram_config_path.c_str())) { ret->InitDefaultNvramConfig(); @@ -82,7 +80,7 @@ void NvramConfig::InitNvramConfigService(size_t num_instances, int sim_type) { void NvramConfig::SaveToFile() { auto nvram_config = Get(); - auto nvram_config_file = nvram_config->ConfigFileLocation(); + const auto nvram_config_file = ConfigFileLocation(); nvram_config->SaveToFile(nvram_config_file); } @@ -101,7 +99,7 @@ NvramConfig::InstanceSpecific NvramConfig::ForInstance(int num) const { return InstanceSpecific(this, std::to_string(num)); } -std::string NvramConfig::ConfigFileLocation() const { +/* static */ std::string NvramConfig::ConfigFileLocation() { return cuttlefish::AbsolutePath( cuttlefish::modem::DeviceConfig::PerInstancePath("modem_nvram.json")); } diff --git a/host/commands/modem_simulator/nvram_config.h b/host/commands/modem_simulator/nvram_config.h index fc51c80fb..bf4370a0a 100644 --- a/host/commands/modem_simulator/nvram_config.h +++ b/host/commands/modem_simulator/nvram_config.h @@ -32,7 +32,7 @@ class NvramConfig { ~NvramConfig(); NvramConfig& operator=(NvramConfig&&); - std::string ConfigFileLocation() const; + static std::string ConfigFileLocation(); // Saves the configuration object in a file bool SaveToFile(const std::string& file) const; |