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/sim_service.h"
20 
21 namespace cuttlefish {
22 
23 class StkService : public ModemService, public std::enable_shared_from_this<StkService> {
24  public:
25   StkService(int32_t service_id, ChannelMonitor* channel_monitor,
26              ThreadLooper* thread_looper);
27   ~StkService() = default;
28 
29   StkService(const StkService &) = delete;
30   StkService &operator=(const StkService &) = delete;
31 
32   void SetupDependency(SimService* sim);
33 
34   void HandleReportStkServiceIsRunning(const Client& client);
35   void HandleSendEnvelope(const Client& client, std::string& command);
36   void HandleSendTerminalResponseToSim(const Client& client, std::string& command);
37 
38  private:
39   std::vector<CommandHandler> InitializeCommandHandlers();
40 
41   SimService* sim_service_;
42 
43   // For now, only support DISPLAY_TEXT, SELECT_ITEM and SETUP_MENU
44   enum CommandType {
45     DISPLAY_TEXT        = 0x21,
46     GET_INKEY           = 0x22,
47     GET_INPUT           = 0x23,
48     LAUNCH_BROWSER      = 0x15,
49     PLAY_TONE           = 0x20,
50     REFRESH             = 0x01,
51     SELECT_ITEM         = 0x24,
52     SEND_SS             = 0x11,
53     SEND_USSD           = 0x12,
54     SEND_SMS            = 0x13,
55     RUN_AT              = 0x34,
56     SEND_DTMF           = 0x14,
57     SET_UP_EVENT_LIST   = 0x05,
58     SET_UP_IDLE_MODE_TEXT = 0x28,
59     SET_UP_MENU         = 0x25,
60     SET_UP_CALL         = 0x10,
61     PROVIDE_LOCAL_INFORMATION = 0x26,
62     LANGUAGE_NOTIFICATION = 0x35,
63     OPEN_CHANNEL        = 0x40,
64     CLOSE_CHANNEL       = 0x41,
65     RECEIVE_DATA        = 0x42,
66     SEND_DATA           = 0x43,
67     GET_CHANNEL_STATUS  = 0x44
68   };
69 
70   std::vector<std::string> current_select_item_menu_ids_;
71 
72   XMLElement* GetCurrentSelectItem();
73   void OnUnsolicitedCommandForTR(std::string& command);
74 };
75 
76 }  // namespace cuttlefish
77