From ce82949067a12b62875dfb1055abbd2af1a64484 Mon Sep 17 00:00:00 2001 From: "Pawel.Paprocki" Date: Tue, 3 Aug 2021 18:50:06 +0200 Subject: [PATCH] [EGD-7167] Pass IMEI number to Settings Get IMEI from cellular and display it in Settings --- .../ApplicationSettings.cpp | 5 +- .../application-settings/CMakeLists.txt | 1 + .../system/TechnicalInformationModel.cpp | 19 ++++++-- .../system/TechnicalInformationModel.hpp | 11 +++-- .../system/TechnicalInformationRepository.cpp | 33 +++++++++++++ .../system/TechnicalInformationRepository.hpp | 28 +++++++++++ .../system/TechnicalWindowPresenter.cpp | 19 ++++++-- .../system/TechnicalWindowPresenter.hpp | 12 ++++- .../system/TechnicalInformationWindow.cpp | 25 +++++++--- .../system/TechnicalInformationWindow.hpp | 3 ++ .../service-cellular/CMakeLists.txt | 1 + .../service-cellular/ServiceCellular.cpp | 3 ++ .../service-cellular/CellularMessage.hpp | 24 ++++++++++ .../service-cellular/ServiceCellular.hpp | 2 + .../service-cellular/src/ImeiGetHandler.cpp | 40 ++++++++++++++++ .../service-cellular/src/ImeiGetHandler.hpp | 46 +++++++++++++++++++ .../src/ServiceCellularPriv.cpp | 14 +++++- .../src/ServiceCellularPriv.hpp | 3 ++ 18 files changed, 268 insertions(+), 21 deletions(-) create mode 100644 module-apps/application-settings/models/system/TechnicalInformationRepository.cpp create mode 100644 module-apps/application-settings/models/system/TechnicalInformationRepository.hpp create mode 100644 module-services/service-cellular/src/ImeiGetHandler.cpp create mode 100644 module-services/service-cellular/src/ImeiGetHandler.hpp diff --git a/module-apps/application-settings/ApplicationSettings.cpp b/module-apps/application-settings/ApplicationSettings.cpp index 316f7d3f234ecb43c8ffd35a39dc6113d35e9a7c..b51b643132b677f4eb0efa80ceb155c9ff586a61 100644 --- a/module-apps/application-settings/ApplicationSettings.cpp +++ b/module-apps/application-settings/ApplicationSettings.cpp @@ -502,8 +502,9 @@ namespace app }); windowsFactory.attach(gui::window::name::technical_information, [&](Application *app, const std::string &name) { auto factoryData = std::make_unique(*settings); - auto model = std::make_unique(std::move(factoryData)); - auto presenter = std::make_unique(std::move(model)); + auto repository = std::make_unique(this); + auto model = std::make_unique(std::move(factoryData), std::move(repository)); + auto presenter = std::make_unique(this, std::move(model)); return std::make_unique(app, std::move(presenter)); }); windowsFactory.attach(gui::window::name::certification, [](Application *app, const std::string &name) { diff --git a/module-apps/application-settings/CMakeLists.txt b/module-apps/application-settings/CMakeLists.txt index 790f7a3ab42b8dd789bd8e6ac1225dc9ea9b616e..3100b7dfd3e4cc6b4354c1a7cac5921c2aeb7abb 100644 --- a/module-apps/application-settings/CMakeLists.txt +++ b/module-apps/application-settings/CMakeLists.txt @@ -27,6 +27,7 @@ target_sources( ${PROJECT_NAME} models/apps/SoundsModel.cpp models/system/DateAndTimeModel.cpp models/system/SARInfoRepository.cpp + models/system/TechnicalInformationRepository.cpp models/system/FactoryData.cpp models/system/TechnicalInformationModel.cpp presenter/network/SimContactsImportWindowPresenter.cpp diff --git a/module-apps/application-settings/models/system/TechnicalInformationModel.cpp b/module-apps/application-settings/models/system/TechnicalInformationModel.cpp index fa181dcfe68ca9d0e8182aa87d4a3f1fe836ea0a..3a1ff34cf251889712299d0bf31bd2284afee6d9 100644 --- a/module-apps/application-settings/models/system/TechnicalInformationModel.cpp +++ b/module-apps/application-settings/models/system/TechnicalInformationModel.cpp @@ -9,8 +9,9 @@ #include #include -TechnicalInformationModel::TechnicalInformationModel(std::unique_ptr &&factoryData) - : factoryData{std::move(factoryData)} +TechnicalInformationModel::TechnicalInformationModel(std::unique_ptr &&factoryData, + std::unique_ptr repository) + : factoryData{std::move(factoryData)}, technicalInformationRepository(std::move(repository)) { createData(); } @@ -47,7 +48,8 @@ void TechnicalInformationModel::createData() internalData.push_back( new gui::TechnicalInformationItem(utils::translate("app_settings_tech_info_os_version"), std::string(VERSION))); - internalData.push_back(new gui::TechnicalInformationItem(utils::translate("app_settings_tech_info_imei"), imei)); + internalData.push_back(new gui::TechnicalInformationItem(utils::translate("app_settings_tech_info_imei"), + technicalInformationRepository->getImei())); #if DEVELOPER_SETTINGS_OPTIONS == 1 internalData.push_back(new gui::TechnicalInformationItem(utils::translate("app_settings_tech_info_battery"), @@ -70,3 +72,14 @@ void TechnicalInformationModel::createData() item->deleteByList = false; } } + +void TechnicalInformationModel::clearData() +{ + list->reset(); + eraseInternalData(); +} + +void TechnicalInformationModel::requestImei(std::function onImeiReadCallback) +{ + technicalInformationRepository->readImei(std::move(onImeiReadCallback)); +} diff --git a/module-apps/application-settings/models/system/TechnicalInformationModel.hpp b/module-apps/application-settings/models/system/TechnicalInformationModel.hpp index af77952d3de4f7eac2e0c6a95aaafe05ac9d73c2..644bd58eefc256c6125cb6ccfccda30dfe541274 100644 --- a/module-apps/application-settings/models/system/TechnicalInformationModel.hpp +++ b/module-apps/application-settings/models/system/TechnicalInformationModel.hpp @@ -4,24 +4,29 @@ #pragma once #include "FactoryData.hpp" +#include "TechnicalInformationRepository.hpp" #include #include +#include class TechnicalInformationModel : public app::InternalModel, public gui::ListItemProvider { private: - static constexpr auto imei = "AA-BBBBBB-CCCCC-D"; - + app::Application *application = nullptr; std::unique_ptr factoryData; + std::shared_ptr technicalInformationRepository = nullptr; public: - explicit TechnicalInformationModel(std::unique_ptr &&factoryData); + explicit TechnicalInformationModel(std::unique_ptr &&factoryData, + std::unique_ptr repository); void createData(); + void clearData(); [[nodiscard]] auto requestRecordsCount() -> unsigned int override; [[nodiscard]] auto getMinimalItemSpaceRequired() const -> unsigned int override; auto getItem(gui::Order order) -> gui::ListItem * override; void requestRecords(const uint32_t offset, const uint32_t limit) override; + void requestImei(std::function onImeiReadCallback); }; diff --git a/module-apps/application-settings/models/system/TechnicalInformationRepository.cpp b/module-apps/application-settings/models/system/TechnicalInformationRepository.cpp new file mode 100644 index 0000000000000000000000000000000000000000..140d0d29db96d08f54f031d9bda687c34a18e2c7 --- /dev/null +++ b/module-apps/application-settings/models/system/TechnicalInformationRepository.cpp @@ -0,0 +1,33 @@ +// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. +// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md + +#include "TechnicalInformationRepository.hpp" +#include +#include + +TechnicalInformationRepository::TechnicalInformationRepository(app::Application *application) + : app::AsyncCallbackReceiver{application}, application{application} +{} + +void TechnicalInformationRepository::readImei(AbstractTechnicalInformationRepository::OnReadCallback readDoneCallback) +{ + + std::function callback = [&](const std::string &imei) { imeiStr = imei; }; + + auto msg = std::make_unique(); + auto task = app::AsyncRequest::createFromMessage(std::move(msg), cellular::service::name); + auto cb = [callback, readDoneCallback](auto response) { + auto result = dynamic_cast(response); + if (result != nullptr && result->retCode == sys::ReturnCodes::Success) { + callback(*result->getImei()); + } + readDoneCallback(); + return true; + }; + task->execute(this->application, this, cb); +} + +std::string TechnicalInformationRepository::getImei() +{ + return imeiStr; +} diff --git a/module-apps/application-settings/models/system/TechnicalInformationRepository.hpp b/module-apps/application-settings/models/system/TechnicalInformationRepository.hpp new file mode 100644 index 0000000000000000000000000000000000000000..159b35451f9178a8878f99401b23b7248d3bbb27 --- /dev/null +++ b/module-apps/application-settings/models/system/TechnicalInformationRepository.hpp @@ -0,0 +1,28 @@ +// 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 +#include + +class AbstractTechnicalInformationRepository +{ + public: + using OnReadCallback = std::function; + virtual ~AbstractTechnicalInformationRepository() noexcept = default; + virtual void readImei(OnReadCallback callback) = 0; + virtual std::string getImei() = 0; +}; + +class TechnicalInformationRepository : public AbstractTechnicalInformationRepository, public app::AsyncCallbackReceiver +{ + public: + explicit TechnicalInformationRepository(app::Application *application); + void readImei(OnReadCallback callback) override; + std::string getImei() override; + + private: + app::Application *application{}; + std::string imeiStr; +}; diff --git a/module-apps/application-settings/presenter/system/TechnicalWindowPresenter.cpp b/module-apps/application-settings/presenter/system/TechnicalWindowPresenter.cpp index 2d0575af44a1882c75bcf6ffee727b6e0f291444..cd44b91241f28e08ed8da40f8e36a0c45897c52f 100644 --- a/module-apps/application-settings/presenter/system/TechnicalWindowPresenter.cpp +++ b/module-apps/application-settings/presenter/system/TechnicalWindowPresenter.cpp @@ -3,11 +3,24 @@ #include "TechnicalWindowPresenter.hpp" -TechnicalWindowPresenter::TechnicalWindowPresenter(std::shared_ptr technicalInformationProvider) - : technicalInformationProvider{std::move(technicalInformationProvider)} -{} +TechnicalWindowPresenter::TechnicalWindowPresenter( + app::Application *application, std::shared_ptr technicalInformationProvider) + : application(application), technicalInformationProvider{std::move(technicalInformationProvider)} +{ + onImeiReady = [&]() { + this->technicalInformationProvider->clearData(); + this->technicalInformationProvider->createData(); + getView()->imeiReady(); + this->application->refreshWindow(gui::RefreshModes::GUI_REFRESH_FAST); + }; +} std::shared_ptr TechnicalWindowPresenter::getTechnicalInformationProvider() const { return technicalInformationProvider; } + +void TechnicalWindowPresenter::requestImei() +{ + technicalInformationProvider->requestImei(onImeiReady); +} diff --git a/module-apps/application-settings/presenter/system/TechnicalWindowPresenter.hpp b/module-apps/application-settings/presenter/system/TechnicalWindowPresenter.hpp index ae39a459e02ffc432439156b5e7f475fa66143bf..4dd50d12af2568d358a55e655d8bb81737c8689d 100644 --- a/module-apps/application-settings/presenter/system/TechnicalWindowPresenter.hpp +++ b/module-apps/application-settings/presenter/system/TechnicalWindowPresenter.hpp @@ -3,6 +3,8 @@ #pragma once +#include + #include #include @@ -13,6 +15,7 @@ class TechnicalWindowContract { public: virtual ~View() noexcept = default; + virtual void imeiReady() noexcept = 0; }; class Presenter : public app::BasePresenter { @@ -20,16 +23,21 @@ class TechnicalWindowContract virtual ~Presenter() noexcept = default; virtual std::shared_ptr getTechnicalInformationProvider() const = 0; + virtual void requestImei() = 0; }; }; class TechnicalWindowPresenter : public TechnicalWindowContract::Presenter { public: - explicit TechnicalWindowPresenter(std::shared_ptr technicalInformationProvider); + explicit TechnicalWindowPresenter(app::Application *application, + std::shared_ptr technicalInformationProvider); std::shared_ptr getTechnicalInformationProvider() const override; + void requestImei() override; private: - std::shared_ptr technicalInformationProvider; + app::Application *application{}; + std::shared_ptr technicalInformationProvider; + std::function onImeiReady = nullptr; }; diff --git a/module-apps/application-settings/windows/system/TechnicalInformationWindow.cpp b/module-apps/application-settings/windows/system/TechnicalInformationWindow.cpp index dfd6f78cb48a93d1346073cdc3a24a8b48c4e5a9..60e775b0cc62b544612f773ac2e35aee878643b9 100644 --- a/module-apps/application-settings/windows/system/TechnicalInformationWindow.cpp +++ b/module-apps/application-settings/windows/system/TechnicalInformationWindow.cpp @@ -15,6 +15,11 @@ namespace gui buildInterface(); } + void TechnicalInformationWindow::onBeforeShow(ShowMode mode, SwitchData *data) + { + presenter->requestImei(); + } + void TechnicalInformationWindow::buildInterface() { AppWindow::buildInterface(); @@ -23,15 +28,21 @@ namespace gui bottomBar->setActive(gui::BottomBar::Side::RIGHT, true); bottomBar->setText(gui::BottomBar::Side::RIGHT, utils::translate(::style::strings::common::back)); - auto list = new ListView(this, - style::window::default_left_margin, - style::window::default_vertical_pos, - style::listview::body_width_with_scroll, - style::window::default_body_height, - presenter->getTechnicalInformationProvider(), - listview::ScrollBarType::Fixed); + list = new ListView(this, + style::window::default_left_margin, + style::window::default_vertical_pos, + style::listview::body_width_with_scroll, + style::window::default_body_height, + presenter->getTechnicalInformationProvider(), + listview::ScrollBarType::Fixed); setFocusItem(list); list->rebuildList(); } + + void TechnicalInformationWindow::imeiReady() noexcept + { + list->rebuildList(); + } + } // namespace gui diff --git a/module-apps/application-settings/windows/system/TechnicalInformationWindow.hpp b/module-apps/application-settings/windows/system/TechnicalInformationWindow.hpp index 7f20f7b9158de0095f411c3912ab7715bbfddf48..4e191f2e5505346ef401186c49e4299f8dfad214 100644 --- a/module-apps/application-settings/windows/system/TechnicalInformationWindow.hpp +++ b/module-apps/application-settings/windows/system/TechnicalInformationWindow.hpp @@ -18,7 +18,10 @@ namespace gui private: void buildInterface() override; + void onBeforeShow(ShowMode mode, SwitchData *data) override; + void imeiReady() noexcept override; + ListView *list = nullptr; std::shared_ptr presenter; }; diff --git a/module-services/service-cellular/CMakeLists.txt b/module-services/service-cellular/CMakeLists.txt index 6ad2aa1ca1204d39d87e3617e40d004979711f9f..438f9b445e44589520ecc0b7566d124feafc5bf3 100644 --- a/module-services/service-cellular/CMakeLists.txt +++ b/module-services/service-cellular/CMakeLists.txt @@ -9,6 +9,7 @@ set(SOURCES src/NetworkTime.cpp src/SimContacts.cpp src/SMSSendHandler.cpp + src/ImeiGetHandler.cpp CellularCall.cpp CellularServiceAPI.cpp diff --git a/module-services/service-cellular/ServiceCellular.cpp b/module-services/service-cellular/ServiceCellular.cpp index 78d68cd014e5a43f5d4b025b7db9a8c0cc857286..17e5c762a1aa76c561575c05b8682c592b95deff 100644 --- a/module-services/service-cellular/ServiceCellular.cpp +++ b/module-services/service-cellular/ServiceCellular.cpp @@ -299,6 +299,7 @@ void ServiceCellular::registerMessageHandlers() priv->connectSimCard(); priv->connectNetworkTime(); priv->connectSimContacts(); + priv->connectImeiGetHandler(); connect(typeid(CellularStartOperatorsScanMessage), [&](sys::Message *request) -> sys::MessagePointer { auto msg = static_cast(request); @@ -385,6 +386,7 @@ void ServiceCellular::registerMessageHandlers() priv->simCard->setChannel(nullptr); priv->networkTime->setChannel(nullptr); priv->simContacts->setChannel(nullptr); + priv->imeiGetHandler->setChannel(nullptr); cmux->closeChannels(); ///> change state - simulate hot start @@ -853,6 +855,7 @@ bool ServiceCellular::handle_audio_conf_procedure() priv->simCard->setChannel(cmux->get(CellularMux::Channel::Commands)); priv->networkTime->setChannel(cmux->get(CellularMux::Channel::Commands)); priv->simContacts->setChannel(cmux->get(CellularMux::Channel::Commands)); + priv->imeiGetHandler->setChannel(cmux->get(CellularMux::Channel::Commands)); // open channel - notifications DLCChannel *notificationsChannel = cmux->get(CellularMux::Channel::Notifications); if (notificationsChannel != nullptr) { diff --git a/module-services/service-cellular/service-cellular/CellularMessage.hpp b/module-services/service-cellular/service-cellular/CellularMessage.hpp index e975a24d7cc293d075dfe266f13b68ce61dd1e2b..513981f894f37076361c6c5363bd964875b185c8 100644 --- a/module-services/service-cellular/service-cellular/CellularMessage.hpp +++ b/module-services/service-cellular/service-cellular/CellularMessage.hpp @@ -936,4 +936,28 @@ namespace cellular private: std::shared_ptr> contacts; }; + + class GetImeiRequest : public sys::DataMessage + { + public: + GetImeiRequest() : sys::DataMessage(MessageType::MessageTypeUninitialized){}; + }; + + class GetImeiResponse : public sys::ResponseMessage + { + public: + explicit GetImeiResponse(std::shared_ptr imei) + : sys::ResponseMessage(sys::ReturnCodes::Success), imei(imei) + {} + GetImeiResponse() : sys::ResponseMessage(sys::ReturnCodes::Failure) + {} + auto getImei() -> std::shared_ptr + { + return imei; + } + + private: + std::shared_ptr imei; + }; + } // namespace cellular diff --git a/module-services/service-cellular/service-cellular/ServiceCellular.hpp b/module-services/service-cellular/service-cellular/ServiceCellular.hpp index 51b2790e92fc83690aaf38989233c6c0e6325a1c..acf463de3656917daba0d6dcf4b98e00e4f9ae8b 100644 --- a/module-services/service-cellular/service-cellular/ServiceCellular.hpp +++ b/module-services/service-cellular/service-cellular/ServiceCellular.hpp @@ -227,6 +227,8 @@ class ServiceCellular : public sys::Service uint32_t ussdTimeout = 0; void setUSSDTimer(); bool handleUSSDRequest(CellularUSSDMessage::RequestType requestType, const std::string &request = ""); + bool handleIMEIRequest(); + bool handleUSSDURC(); void handleUSSDTimer(); diff --git a/module-services/service-cellular/src/ImeiGetHandler.cpp b/module-services/service-cellular/src/ImeiGetHandler.cpp new file mode 100644 index 0000000000000000000000000000000000000000..fafa01dcb087f981da29af9a53f1ec6dcf367d50 --- /dev/null +++ b/module-services/service-cellular/src/ImeiGetHandler.cpp @@ -0,0 +1,40 @@ +// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. +// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md + +#include "ImeiGetHandler.hpp" +#include +#include + +#include + +namespace +{ + constexpr auto IMEIResonseSize = 2; +} + +namespace cellular::service +{ + void ImeiGetHandler::setChannel(at::BaseChannel *channel) + { + this->channel = channel; + } + + auto ImeiGetHandler::getImei(std::string &destination) -> bool + { + + if (channel == nullptr) { + LOG_ERROR("No channel provided. Request ignored"); + return false; + } + auto result = channel->cmd(at::factory(at::AT::GET_IMEI)); + + if (result.code == at::Result::Code::OK && result.response.size() == IMEIResonseSize) { + destination = result.response[0]; + return true; + } + else { + return false; + } + } + +} // namespace cellular::service diff --git a/module-services/service-cellular/src/ImeiGetHandler.hpp b/module-services/service-cellular/src/ImeiGetHandler.hpp new file mode 100644 index 0000000000000000000000000000000000000000..a0f5b43292f90ddb2d4f5430e32293ccac3c6a70 --- /dev/null +++ b/module-services/service-cellular/src/ImeiGetHandler.hpp @@ -0,0 +1,46 @@ +// 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 + +#include +//#include + +namespace at +{ + class Cmd; + class BaseChannel; +} // namespace at + +namespace sys +{ + class Message; +} // namespace sys + +namespace cellular::service +{ + class ImeiGetHandler + { + public: + /** Set cmd channel + * \param channel channel (or nullptr to block communication) + */ + void setChannel(at::BaseChannel *channel); + /** + * Reads IMEI as a string + * @param destination reference to data destination + * @return boor result true on success, false on fail + */ + auto getImei(std::string &destination) -> bool; + + private: + /** + * Reads number of contacts stored on sim card + * @param count number of contacts stored on sim card + * @return boor result true on success, false on fail + */ + at::BaseChannel *channel = nullptr; + }; +} // namespace cellular::service diff --git a/module-services/service-cellular/src/ServiceCellularPriv.cpp b/module-services/service-cellular/src/ServiceCellularPriv.cpp index a4e54b1d43c29d77c2ca2241a69c1b13bd5826d1..0524c39116b63348f7b8634f9ab0dcf45eba053e 100644 --- a/module-services/service-cellular/src/ServiceCellularPriv.cpp +++ b/module-services/service-cellular/src/ServiceCellularPriv.cpp @@ -26,7 +26,8 @@ namespace cellular::internal { ServiceCellularPriv::ServiceCellularPriv(ServiceCellular *owner) : owner{owner}, simCard{std::make_unique()}, state{std::make_unique(owner)}, - networkTime{std::make_unique()}, simContacts{std::make_unique()} + networkTime{std::make_unique()}, simContacts{std::make_unique()}, + imeiGetHandler{std::make_unique()} { initSimCard(); initSMSSendHandler(); @@ -261,4 +262,15 @@ namespace cellular::internal }); } + void ServiceCellularPriv::connectImeiGetHandler() + { + owner->connect(typeid(cellular::GetImeiRequest), [&](sys::Message *request) -> sys::MessagePointer { + std::string imei; + if (imeiGetHandler->getImei(imei)) { + return std::make_shared(std::make_shared(imei)); + } + return std::make_shared(); + }); + } + } // namespace cellular::internal diff --git a/module-services/service-cellular/src/ServiceCellularPriv.hpp b/module-services/service-cellular/src/ServiceCellularPriv.hpp index e12d7c08ad19eece9eb39507df6a801e30465fd8..2db0e4a06922ad7ae294ee385a8e5243261337b5 100644 --- a/module-services/service-cellular/src/ServiceCellularPriv.hpp +++ b/module-services/service-cellular/src/ServiceCellularPriv.hpp @@ -10,6 +10,7 @@ #include "SimCard.hpp" #include "NetworkTime.hpp" #include "SimContacts.hpp" +#include "ImeiGetHandler.hpp" namespace cellular::internal { @@ -27,6 +28,7 @@ namespace cellular::internal std::unique_ptr state; std::unique_ptr networkTime; std::unique_ptr simContacts; + std::unique_ptr imeiGetHandler; State::PowerState nextPowerState = State::PowerState::Off; public: @@ -35,6 +37,7 @@ namespace cellular::internal void connectSimCard(); void connectNetworkTime(); void connectSimContacts(); + void connectImeiGetHandler(); void requestNetworkTimeSettings();