• 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_id()25 int DeviceConfig::host_id() {
26   if (!cuttlefish::CuttlefishConfig::Get()) {
27     return 1000;
28   }
29   auto config = cuttlefish::CuttlefishConfig::Get();
30   auto instance = config->ForDefaultInstance();
31   return instance.modem_simulator_host_id();
32 }
33 
PerInstancePath(const char * file_name)34 std::string DeviceConfig::PerInstancePath(const char* file_name) {
35   if (!cuttlefish::CuttlefishConfig::Get()) {
36       return "";
37   }
38   auto config = cuttlefish::CuttlefishConfig::Get();
39   auto instance = config->ForDefaultInstance();
40   return instance.PerInstancePath(file_name);
41 }
42 
DefaultHostArtifactsPath(const std::string & file)43 std::string DeviceConfig::DefaultHostArtifactsPath(const std::string& file) {
44   return cuttlefish::DefaultHostArtifactsPath(file);
45 }
46 
ril_address_and_prefix()47 std::string DeviceConfig::ril_address_and_prefix() {
48   auto device_config_helper = cuttlefish::DeviceConfigHelper::Get();
49   if (!device_config_helper) {
50       return "10.0.2.15/24";
51   }
52   const auto& ril_config = device_config_helper->GetDeviceConfig().ril_config();
53   return ril_config.ipaddr() + "/" + std::to_string(ril_config.prefixlen());
54 };
55 
ril_gateway()56 std::string DeviceConfig::ril_gateway() {
57   auto device_config_helper = cuttlefish::DeviceConfigHelper::Get();
58   if (!device_config_helper) {
59       return "10.0.2.2";
60   }
61   const auto& ril_config = device_config_helper->GetDeviceConfig().ril_config();
62   return ril_config.gateway();
63 }
64 
ril_dns()65 std::string DeviceConfig::ril_dns() {
66   auto device_config_helper = cuttlefish::DeviceConfigHelper::Get();
67   if (!device_config_helper) {
68       return "8.8.8.8";
69   }
70   const auto& ril_config = device_config_helper->GetDeviceConfig().ril_config();
71   return ril_config.dns();
72 }
73 
open_ifstream_crossplat(const char * filename)74 std::ifstream DeviceConfig::open_ifstream_crossplat(const char* filename) {
75     return std::ifstream(filename);
76 }
77 
open_ofstream_crossplat(const char * filename,std::ios_base::openmode mode)78 std::ofstream DeviceConfig::open_ofstream_crossplat(const char* filename, std::ios_base::openmode mode) {
79     return std::ofstream(filename, mode);
80 }
81 
82 }  // namespace modem
83 }  // namespace cuttlefish
84