• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2020 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include "common/libs/device_config/device_config.h"
18 #include "host/commands/modem_simulator/device_config.h"
19 #include "host/libs/config/cuttlefish_config.h"
20 
21 // this file provide cuttlefish hooks
22 namespace cuttlefish {
23 namespace modem {
24 
host_port()25 int DeviceConfig::host_port() {
26   if (!cuttlefish::CuttlefishConfig::Get()) {
27       return 6500;
28   }
29   auto config = cuttlefish::CuttlefishConfig::Get();
30   auto instance = config->ForDefaultInstance();
31   auto host_port = instance.host_port();
32   return host_port;
33 }
34 
PerInstancePath(const char * file_name)35 std::string DeviceConfig::PerInstancePath(const char* file_name) {
36   if (!cuttlefish::CuttlefishConfig::Get()) {
37       return "";
38   }
39   auto config = cuttlefish::CuttlefishConfig::Get();
40   auto instance = config->ForDefaultInstance();
41   return instance.PerInstancePath(file_name);
42 }
43 
DefaultHostArtifactsPath(const std::string & file)44 std::string DeviceConfig::DefaultHostArtifactsPath(const std::string& file) {
45   return cuttlefish::DefaultHostArtifactsPath(file);
46 }
47 
ril_address_and_prefix()48 std::string DeviceConfig::ril_address_and_prefix() {
49   auto device_config_helper = cuttlefish::DeviceConfigHelper::Get();
50   if (!device_config_helper) {
51       return "10.0.2.15/24";
52   }
53   const auto& ril_config = device_config_helper->GetDeviceConfig().ril_config();
54   return ril_config.ipaddr() + "/" + std::to_string(ril_config.prefixlen());
55 };
56 
ril_gateway()57 std::string DeviceConfig::ril_gateway() {
58   auto device_config_helper = cuttlefish::DeviceConfigHelper::Get();
59   if (!device_config_helper) {
60       return "10.0.2.2";
61   }
62   const auto& ril_config = device_config_helper->GetDeviceConfig().ril_config();
63   return ril_config.gateway();
64 }
65 
ril_dns()66 std::string DeviceConfig::ril_dns() {
67   auto device_config_helper = cuttlefish::DeviceConfigHelper::Get();
68   if (!device_config_helper) {
69       return "8.8.8.8";
70   }
71   const auto& ril_config = device_config_helper->GetDeviceConfig().ril_config();
72   return ril_config.dns();
73 }
74 
75 }  // namespace modem
76 }  // namespace cuttlefish
77