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/modem_service.h"
19 #include "host/commands/modem_simulator/pdu_parser.h"
20 #include "host/commands/modem_simulator/sim_service.h"
21 
22 namespace cuttlefish {
23 
24 class SmsService : public ModemService , public std::enable_shared_from_this<SmsService> {
25  public:
26   SmsService(int32_t service_id, ChannelMonitor* channel_monitor,
27              ThreadLooper* thread_looper);
28   ~SmsService() = default;
29 
30   SmsService(const SmsService &) = delete;
31   SmsService &operator=(const SmsService &) = delete;
32 
33   void SetupDependency(SimService* sim);
34 
35   void HandleSendSMS(const Client& client, std::string& command);
36   void HandleSendSMSPDU(const Client& client, std::string& command);
37   void HandleSMSAcknowledge(const Client& client, std::string& command);
38   void HandleWriteSMSToSim(const Client& client, std::string& command);
39   void HandleDeleteSmsOnSim(const Client& client, std::string& command);
40   void HandleBroadcastConfig(const Client& client, std::string& command);
41   void HandleGetSmscAddress(const Client& client);
42   void HandleSetSmscAddress(const Client& client, std::string& command);
43   void HandleWriteSMSPduToSim(const Client& client, std::string& command);
44   void HandleReceiveRemoteSMS(const Client& client, std::string& command);
45 
IsWaitingSmsPdu()46   bool IsWaitingSmsPdu() { return is_waiting_sms_pdu_; }
IsWaitingSmsToSim()47   bool IsWaitingSmsToSim() { return is_waiting_sms_to_sim_; }
48 
49  private:
50   void InitializeServiceState();
51   std::vector<CommandHandler> InitializeCommandHandlers();
52 
53   void HandleReceiveSMS(PDUParser sms_pdu);
54   void HandleSMSStatuReport(PDUParser sms_pdu, int message_reference);
55   void SendSmsToRemote(std::string remote_port, PDUParser& sms_pdu);
56 
57   SimService* sim_service_;
58 
59   struct SmsMessage {
60     enum SmsStatus { kUnread = 0, kRead = 1, kUnsent = 2, kSent = 3 };
61 
62     std::string message;
63     SmsStatus status;
64   };
65 
66   struct BroadcastConfig {
67     int mode;
68     std::string mids;
69     std::string dcss;
70   };
71 
72   struct SmsServiceCenterAddress {
73     std::string sca;
74     int tosca;
75   };
76 
77   bool is_waiting_sms_pdu_;
78   bool is_waiting_sms_to_sim_;
79   int message_id_;
80   int message_reference_;
81   SmsMessage::SmsStatus sms_status_on_sim_;
82 
83   BroadcastConfig broadcast_config_;
84   SmsServiceCenterAddress sms_service_center_address_;
85 
86   std::map<int, SmsMessage> messages_on_sim_card_;
87 };
88 
89 }  // namespace cuttlefish
90