M module-services/service-desktop/endpoints/developerMode/DeveloperModeEndpoint.cpp => module-services/service-desktop/endpoints/developerMode/DeveloperModeEndpoint.cpp +1 -0
@@ 11,6 11,7 @@ auto DeveloperModeEndpoint::handle(Context &context) -> void
{
switch (context.getMethod()) {
case http::Method::get:
+ helper->processGetRequest(context);
break;
case http::Method::post:
break;
M module-services/service-desktop/endpoints/developerMode/DeveloperModeHelper.cpp => module-services/service-desktop/endpoints/developerMode/DeveloperModeHelper.cpp +39 -1
@@ 1,4 1,4 @@
-// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved.
+// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
#include "DeveloperModeHelper.hpp"
@@ 11,6 11,7 @@
#include <service-cellular/CellularMessage.hpp>
#include <service-cellular/ServiceCellular.hpp>
#include <service-bluetooth/messages/Status.hpp>
+#include <service-cellular/CellularServiceAPI.hpp>
#include <gui/Common.hpp>
#include <service-appmgr/Actions.hpp>
@@ 69,12 70,40 @@ auto DeveloperModeHelper::processPutRequest(Context &context) -> sys::ReturnCode
MessageHandler::putToSendQueue(context.createSimpleResponse());
}
+ else if (body[json::developerMode::changeSim].is_number()) {
+ int simSelected = body[json::developerMode::changeSim].int_value();
+ requestSimChange(simSelected);
+ MessageHandler::putToSendQueue(context.createSimpleResponse());
+ }
else {
context.setResponseStatus(http::Code::BadRequest);
MessageHandler::putToSendQueue(context.createSimpleResponse());
}
return sys::ReturnCodes::Unresolved;
}
+
+auto DeveloperModeHelper::processGetRequest(Context &context) -> sys::ReturnCodes
+{
+ auto body = context.getBody();
+ if (body[json::developerMode::getInfo].is_string()) {
+ auto keyValue = body[json::developerMode::getInfo].string_value();
+ if (keyValue == json::developerMode::simStateInfo) {
+ context.setResponseBody(json11::Json::object(
+ {{json::selectedSim, std::to_string(static_cast<int>(Store::GSM::get()->selected))},
+ {json::sim, std::to_string(static_cast<int>(Store::GSM::get()->sim))},
+ {json::trayState, std::to_string(static_cast<int>(Store::GSM::get()->tray))}}));
+ }
+ else {
+ context.setResponseStatus(http::Code::BadRequest);
+ }
+ }
+ else {
+ context.setResponseStatus(http::Code::BadRequest);
+ }
+ MessageHandler::putToSendQueue(context.createSimpleResponse());
+ return sys::ReturnCodes::Unresolved;
+}
+
auto DeveloperModeHelper::getKeyCode(int val) noexcept -> bsp::KeyCodes
{
switch (val) {
@@ 144,3 173,12 @@ void DeveloperModeHelper::sendKeypress(bsp::KeyCodes keyCode, gui::InputEvent::S
sys::Bus::SendUnicast(std::move(message), service::name::evt_manager, ownerServicePtr);
}
+
+void DeveloperModeHelper::requestSimChange(const int simSelected)
+{
+ Store::GSM::SIM sim = Store::GSM::SIM::SIM1;
+ if (simSelected == static_cast<int>(Store::GSM::SIM::SIM2)) {
+ sim = Store::GSM::SIM::SIM2;
+ }
+ CellularServiceAPI::SetSimCard(ownerServicePtr, sim);
+}
M module-services/service-desktop/endpoints/developerMode/DeveloperModeHelper.hpp => module-services/service-desktop/endpoints/developerMode/DeveloperModeHelper.hpp +8 -0
@@ 25,9 25,12 @@ namespace parserFSM
static auto getKeyCode(int val) noexcept -> bsp::KeyCodes;
void sendKeypress(bsp::KeyCodes keyCode, gui::InputEvent::State state);
+ void requestSimChange(const int simSelected);
+
public:
DeveloperModeHelper(sys::Service *_ownerServicePtr) : ownerServicePtr(_ownerServicePtr){};
auto processPutRequest(Context &context) -> sys::ReturnCodes;
+ auto processGetRequest(Context &context) -> sys::ReturnCodes;
};
namespace json::developerMode
@@ 42,5 45,10 @@ namespace parserFSM
inline constexpr auto btState = "btState";
inline constexpr auto btOn = "on";
inline constexpr auto btCommand = "btCommand";
+ inline constexpr auto changeSim = "changeSim";
+ inline constexpr auto getInfo = "getInfo";
+
+ /// values for getInfo cmd
+ inline constexpr auto simStateInfo = "simState";
}
} // namespace parserFSM
M module-services/service-desktop/parser/ParserUtils.hpp => module-services/service-desktop/parser/ParserUtils.hpp +1 -0
@@ 104,6 104,7 @@ namespace parserFSM
inline constexpr auto batteryLevel = "batteryLevel";
inline constexpr auto batteryState = "batteryState";
inline constexpr auto selectedSim = "selectedSim";
+ inline constexpr auto sim = "sim";
inline constexpr auto trayState = "trayState";
inline constexpr auto signalStrength = "signalStrength";
inline constexpr auto fsTotal = "fsTotal";
M test/harness/utils.py => test/harness/utils.py +13 -1
@@ 120,7 120,19 @@ def send_char(char: str, connection):
connection.send_key_code(int(char), key_type)
connection.send_key_code(key_codes["right"])
last_char = char
-
+ elif char.islower():
+ tmp = char.upper()
+ # toggle to lowercase mode
+ connection.send_key_code(key_codes["*"], key_type)
+ if last_char is keymap[tmp][0]:
+ print("repeated key!")
+ connection.send_key_code(key_codes["right"], key_type)
+ for key in keymap[tmp]:
+ connection.send_key_code(int(key), key_type)
+ last_char = keymap[tmp][0]
+ # toggle to uppercase mode
+ connection.send_key_code(key_codes["*"], key_type)
+ connection.send_key_code(key_codes["*"], key_type)
else:
if last_char is keymap[char][0]:
print("repeated key!")
M test/pytest/conftest.py => test/pytest/conftest.py +2 -0
@@ 128,3 128,5 @@ def pytest_configure(config):
"rt1051: mark test if it's target only (eg. calls, messages)")
config.addinivalue_line("markers",
"usb_cdc_echo: mark test if it's intended for usb-cdc echo mode")
+ config.addinivalue_line("markers",
+ "two_sim_cards: mark test in case when two sim cards are required")
A test/pytest/test_change_sim.py => test/pytest/test_change_sim.py +53 -0
@@ 0,0 1,53 @@
+# Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
+# For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
+
+import pytest
+from harness.interface.defs import status
+from test_send_message import get_message_by_text, test_send_message as send_message
+import time
+
+
+@pytest.mark.rt1051
+@pytest.mark.two_sim_cards
+@pytest.mark.usefixtures("phone_unlocked")
+def test_change_sim(harness, phone_number, sms_text):
+ simCard = {
+ "SIM1": 0,
+ "SIM2": 1,
+ }
+
+ # change sim to SIM1
+ body = {"changeSim": simCard["SIM1"]}
+ ret = harness.endpoint_request("developerMode", "put", body)
+ assert ret["status"] == status["OK"]
+
+ # time to change sim card in pure phone, value is experimentally chosen, no idea how to do it right
+ time.sleep(2)
+
+ # retrieve sim info
+ body = {"getInfo": "simState"}
+ ret = harness.endpoint_request("developerMode", "get", body)
+ assert ret["status"] == status["OK"]
+ assert ret["body"]["selectedSim"] == str(simCard["SIM1"])
+ assert ret["body"]["sim"] == str(simCard["SIM1"])
+
+ # send text message using SIM1
+ send_message(harness, phone_number, sms_text)
+
+ # change sim to SIM2
+ body = {"changeSim": simCard["SIM2"]}
+ ret = harness.endpoint_request("developerMode", "put", body)
+ assert ret["status"] == status["OK"]
+
+ # time to change sim card in pure phone, value is experimentally chosen, no idea how to do it right
+ time.sleep(2)
+
+ # retrieve sim info
+ body = {"getInfo": "simState"}
+ ret = harness.endpoint_request("developerMode", "get", body)
+ assert ret["status"] == status["OK"]
+ assert ret["body"]["selectedSim"] == str(simCard["SIM2"])
+ assert ret["body"]["sim"] == str(simCard["SIM2"])
+
+ # send text message using SIM2
+ send_message(harness, phone_number, sms_text)
M test/pytest/test_send_message.py => test/pytest/test_send_message.py +2 -2
@@ 14,7 14,7 @@ def get_message_by_text(harness, message: str, phone_number: str):
@pytest.mark.rt1051
@pytest.mark.usefixtures("phone_unlocked")
def test_send_message(harness, phone_number, sms_text):
- old_messages = get_message_by_text(harness, sms_text.upper(), str(phone_number))
+ old_messages = get_message_by_text(harness, sms_text, str(phone_number))
# enter menu
harness.connection.send_key_code(key_codes["enter"])
@@ 38,7 38,7 @@ def test_send_message(harness, phone_number, sms_text):
time.sleep(1.2) # it take horrendous amount of time to go back to thread view
harness.connection.send_key_code(key_codes["fnRight"])
- new_messages = get_message_by_text(harness, sms_text.upper(), str(phone_number))
+ new_messages = get_message_by_text(harness, sms_text, str(phone_number))
diff_messages = []
for message in new_messages: