M module-services/service-desktop/endpoints/developerMode/DeveloperModeHelper.cpp => module-services/service-desktop/endpoints/developerMode/DeveloperModeHelper.cpp +21 -3
@@ 15,6 15,9 @@
#include <service-appmgr/Actions.hpp>
#include <messages/AppMessage.hpp>
+#include <module-sys/SystemManager/messages/TetheringStateRequest.hpp>
+#include <module-sys/SystemManager/Constants.hpp>
+
#include <service-db/DBServiceAPI.hpp>
#include <time/time_conversion.hpp>
#include <service-desktop/parser/MessageHandler.hpp>
@@ 26,10 29,19 @@ namespace parserFSM
using namespace parserFSM;
-constexpr http::Code toCode(bool r)
+namespace
{
- return r ? http::Code::OK : http::Code::InternalServerError;
-}
+ constexpr http::Code toCode(bool r)
+ {
+ return r ? http::Code::OK : http::Code::InternalServerError;
+ }
+
+ auto toTetheringState(const std::string &state) -> sys::phone_modes::Tethering
+ {
+ return state == json::developerMode::tetheringOn ? sys::phone_modes::Tethering::On
+ : sys::phone_modes::Tethering::Off;
+ }
+} // namespace
auto DeveloperModeHelper::processPut(Context &context) -> ProcessResult
{
@@ 85,6 97,12 @@ auto DeveloperModeHelper::processPut(Context &context) -> ProcessResult
}
}
}
+ else if (body[json::developerMode::tethering].is_string()) {
+ const auto &tetheringState = body[json::developerMode::tethering].string_value();
+ owner->bus.sendUnicast(std::make_shared<sys::TetheringStateRequest>(toTetheringState(tetheringState)),
+ service::name::system_manager);
+ return {sent::delayed, std::nullopt};
+ }
return {sent::no, endpoint::ResponseContext{.status = code}};
}
M module-services/service-desktop/endpoints/developerMode/DeveloperModeHelper.hpp => module-services/service-desktop/endpoints/developerMode/DeveloperModeHelper.hpp +5 -0
@@ 54,6 54,7 @@ namespace parserFSM
inline constexpr auto smsCommand = "smsCommand";
inline constexpr auto changeCellularStateCmd = "changeCellularStateCmd";
inline constexpr auto getInfo = "getInfo";
+ inline constexpr auto tethering = "tethering";
/// values for getInfo cmd
inline constexpr auto simStateInfo = "simState";
@@ 61,5 62,9 @@ namespace parserFSM
/// values for smsCommand
inline constexpr auto smsAdd = "smsAdd";
+
+ /// values for tethering
+ inline constexpr auto tetheringOn = "on";
+ inline constexpr auto tetheringOff = "off";
}
} // namespace parserFSM
M module-sys/SystemManager/SystemManager.cpp => module-sys/SystemManager/SystemManager.cpp +13 -0
@@ 26,6 26,7 @@
#include "messages/SentinelRegistrationMessage.hpp"
#include "messages/RequestCpuFrequencyMessage.hpp"
#include "messages/PhoneModeRequest.hpp"
+#include "messages/TetheringStateRequest.hpp"
#include <time/ScopedTime.hpp>
const inline size_t systemManagerStack = 4096 * 2;
@@ 384,6 385,11 @@ namespace sys
return handlePhoneModeRequest(request);
});
+ connect(typeid(TetheringStateRequest), [this](sys::Message *message) -> sys::MessagePointer {
+ auto request = static_cast<TetheringStateRequest *>(message);
+ return handleTetheringStateRequest(request);
+ });
+
deviceManager->RegisterNewDevice(powerManager->getExternalRamDevice());
return ReturnCodes::Success;
@@ 507,6 513,13 @@ namespace sys
return MessageNone{};
}
+ MessagePointer SystemManager::handleTetheringStateRequest(TetheringStateRequest *request)
+ {
+ LOG_INFO("Tethering state change requested");
+ phoneModeSubject->setTetheringMode(request->getTetheringState());
+ return MessageNone{};
+ }
+
std::vector<std::shared_ptr<Service>> SystemManager::servicesList;
cpp_freertos::MutexStandard SystemManager::destroyMutex;
std::unique_ptr<PowerManager> SystemManager::powerManager;
M module-sys/SystemManager/SystemManager.hpp => module-sys/SystemManager/SystemManager.hpp +2 -0
@@ 37,6 37,7 @@ namespace sys
} // namespace constants
class PhoneModeRequest; // Forward declaration
+ class TetheringStateRequest; // Forward declaration
enum class Code
{
@@ 153,6 154,7 @@ namespace sys
void CpuStatisticsTimerHandler();
MessagePointer handlePhoneModeRequest(PhoneModeRequest *request);
+ MessagePointer handleTetheringStateRequest(TetheringStateRequest *request);
bool cpuStatisticsTimerInit{false};
A module-sys/SystemManager/messages/TetheringStateRequest.hpp => module-sys/SystemManager/messages/TetheringStateRequest.hpp +25 -0
@@ 0,0 1,25 @@
+// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
+// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
+
+#pragma once
+
+#include <module-sys/PhoneModes/Common.hpp>
+
+namespace sys
+{
+ class TetheringStateRequest : public sys::DataMessage
+ {
+ public:
+ explicit TetheringStateRequest(phone_modes::Tethering state)
+ : sys::DataMessage(MessageType::MessageTypeUninitialized), tetheringState{state}
+ {}
+
+ [[nodiscard]] auto getTetheringState() const noexcept -> phone_modes::Tethering
+ {
+ return tetheringState;
+ }
+
+ private:
+ phone_modes::Tethering tetheringState;
+ };
+} // namespace sys
M test/harness/harness.py => test/harness/harness.py +6 -0
@@ 108,3 108,9 @@ class Harness:
self.connection.send_key_code(key_codes["fnRight"], Keytype.long_press)
self.connection.send_key_code(key_codes["right"])
self.connection.send_key_code(key_codes["enter"])
+
+ def set_tethering_state(self, enabled: bool):
+ state = 'on' if enabled else 'off'
+ body = {"tethering": state}
+ log.info(f"Set tethering state to: {state}")
+ return self.endpoint_request("developerMode", "put", body)
A test/set_tethering.py => test/set_tethering.py +43 -0
@@ 0,0 1,43 @@
+# Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
+# For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
+
+import sys
+
+from harness import log
+from harness.harness import Harness
+from harness.interface.error import TestError, Error
+
+
+def main():
+ if len(sys.argv) == 1 or "/dev" not in sys.argv[1]:
+ log.warning("Port name not passed, trying port name filename from simulator...")
+ try:
+ file = open("/tmp/purephone_pts_name", "r")
+ except FileNotFoundError:
+ raise TestError(Error.PORT_FILE_NOT_FOUND)
+
+ port_name = file.readline()
+ if port_name.isascii():
+ log.debug("found {} entry!".format(port_name))
+ else:
+ print(f'Please pass port name as the parameter: python {sys.argv[0]} /dev/ttyACM0 number duration')
+ raise TestError(Error.PORT_NOT_FOUND)
+ else:
+ port_name = sys.argv[1]
+
+ harness = Harness(port_name)
+ state = int(sys.argv[2])
+
+ harness.unlock_phone()
+ harness.set_tethering_state(True if state == 1 else False)
+ # No response is available immediately.
+ print(f'Please wait for the request to be sent...')
+ time.sleep(30)
+
+
+if __name__ == "__main__":
+ try:
+ main()
+ except TestError as err:
+ log.error(err)
+ exit(err.get_error_code())