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 #pragma once
17 
18 #include "host/commands/modem_simulator/channel_monitor.h"
19 #include "host/commands/modem_simulator/modem_service.h"
20 #include "host/commands/modem_simulator/nvram_config.h"
21 #include "host/commands/modem_simulator/thread_looper.h"
22 
23 namespace cuttlefish {
24 
25 class SimService;
26 class MiscService;
27 class NetworkService;
28 class SmsService;
29 class ModemSimulator {
30  public:
31   ModemSimulator(int32_t modem_id);
32   ~ModemSimulator();
33 
34   ModemSimulator(const ModemSimulator&) = delete;
35   ModemSimulator& operator=(const ModemSimulator&) = delete;
36 
37   void Initialize(std::unique_ptr<ChannelMonitor>&& channel_monitor);
38 
39   void DispatchCommand(const Client& client, std::string& command);
40 
41   void OnFirstClientConnected();
42   void SaveModemState();
43   bool IsWaitingSmsPdu();
44   bool IsRadioOn() const;
SetRemoteClient(cuttlefish::SharedFD client,bool is_accepted)45   void SetRemoteClient(cuttlefish::SharedFD client, bool is_accepted) {
46     channel_monitor_->SetRemoteClient(client, is_accepted);
47   }
48 
49   void SetTimeZone(std::string timezone);
50   bool SetPhoneNumber(std::string_view number);
51  private:
52   int32_t modem_id_;
53   std::unique_ptr<ChannelMonitor> channel_monitor_;
54   std::unique_ptr<ThreadLooper> thread_looper_;
55 
56   SmsService* sms_service_{nullptr};
57   SimService* sim_service_{nullptr};
58   MiscService* misc_service_{nullptr};
59   NetworkService* network_service_{nullptr};
60 
61   std::map<ModemServiceType, std::unique_ptr<ModemService>> modem_services_;
62 
63   static void LoadNvramConfig();
64 
65   void RegisterModemService();
66 };
67 
68 }  // namespace cuttlefish
69