1# Copyright (C) 2024 The Android Open Source Project
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#      http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15import os
16import socket
17
18
19class Modem:
20
21    def __init__(self, port):
22        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
23        s.connect(("127.0.0.1", port))
24        self.active_calls = []
25        self.socket = s
26
27    def close(self):
28        for phone_number in self.active_calls:
29            self.socket.sendall(b'REM0\r\nAT+REMOTECALL=6,0,0,"' + str(phone_number).encode("utf-8") + b'",0\r\n')
30        self.socket.close()
31
32    def call(self, phone_number):
33        self.active_calls.append(phone_number)
34        self.socket.sendall(b'REM0\r\nAT+REMOTECALL=4,0,0,"' + str(phone_number).encode("utf-8") + b'",129\r\n')
35
36    def answer_outgoing_call(self, phone_number):
37        self.active_calls.append(phone_number)
38        self.socket.sendall(b'REM0\r\nAT+REMOTECALL=0,0,0,"' + str(phone_number).encode("utf-8") + b'",129\r\n')
39