From ab02490917d8b7fdf743b1024e674da4b15adb3c Mon Sep 17 00:00:00 2001 From: Lefucjusz Date: Thu, 30 Jun 2022 12:13:30 +0200 Subject: [PATCH] [MOS-559] Fix phone unlock after mode change Correction of the previous fix addressing this issue. Previous idea didn't work when popup tried to display in application other than ApplicationDesktop --- module-apps/apps-common/ApplicationCommon.cpp | 24 ------------------- module-apps/apps-common/ApplicationCommon.hpp | 4 ++-- .../policies/CallNotificationPolicy.cpp | 2 ++ .../policies/NotificationsListPolicy.cpp | 4 +++- .../policies/SMSNotificationPolicy.cpp | 4 +++- .../rt1051/bsp/magnetometer/magnetometer.cpp | 2 +- module-gui/gui/widgets/StatusBar.hpp | 2 +- .../gui/widgets/status-bar/PhoneMode.cpp | 2 ++ .../call/include/call/CellularCall.hpp | 2 +- .../include/PhoneModes/Observer.hpp | 2 +- .../include/PhoneModes/PhoneMode.hpp | 3 ++- .../PhoneModes/include/PhoneModes/Subject.hpp | 2 +- .../services/appmgr/ApplicationManager.cpp | 5 ++++ 13 files changed, 24 insertions(+), 34 deletions(-) diff --git a/module-apps/apps-common/ApplicationCommon.cpp b/module-apps/apps-common/ApplicationCommon.cpp index a09135ff6268dfce3d6a8a1af11278eef58d4bd1..4eaea929aea112e9a74ec57007f93f4673fef193 100644 --- a/module-apps/apps-common/ApplicationCommon.cpp +++ b/module-apps/apps-common/ApplicationCommon.cpp @@ -28,8 +28,6 @@ #include #include -#include - #if DEBUG_INPUT_EVENTS == 1 #define debug_input_events(...) LOG_DEBUG(__VA_ARGS__) #else @@ -94,7 +92,6 @@ namespace app bus.channels.push_back(sys::BusChannel::ServiceCellularNotifications); bus.channels.push_back(sys::BusChannel::USBNotifications); - bus.channels.push_back(sys::BusChannel::PhoneLockChanges); longPressTimer = sys::TimerFactory::createPeriodicTimer(this, "LongPress", @@ -115,16 +112,6 @@ namespace app connect(typeid(sdesktop::usb::USBDisconnected), [&](sys::Message *msg) -> sys::MessagePointer { return handleUSBStatusChange(); }); - connect(typeid(locks::UnlockedPhone), [&](sys::Message *msg) { - phoneIsLocked = false; - return sys::MessageNone{}; - }); - - connect(typeid(locks::LockedPhone), [&](sys::Message *msg) { - phoneIsLocked = true; - return sys::MessageNone{}; - }); - addActionReceiver(app::manager::actions::PhoneModeChanged, [this](auto &¶ms) { if (params != nullptr) { auto modeParams = static_cast(params.get()); @@ -564,17 +551,6 @@ namespace app return sys::msgHandled(); } - // Workaround for corner case when phone started with mode slider in position different than "Connected". - // This triggers race condition between PhoneLockPopup and PhoneModesPopup. Usually PhoneLockPopup got placed - // on PhoneModesPopup in windows stack, which resulted in PhoneLockPopup being dropped when phone mode was - // changed again (see how pushWindow method works), what bypassed the phone lock. - if (phoneIsLocked && (not windowsStack().isWindowOnStack(gui::popup::window::phone_lock_window)) && - (windowName == gui::popup::window::phone_modes_window)) { - LOG_ERROR( - "Tried to show PhoneModesPopup on locked phone, but PhoneLockPopup was not at the window stack yet!"); - return sys::msgHandled(); - } - auto switchData = std::move(msg->getData()); if (switchData && switchData->ignoreCurrentWindowOnStack) { windowsStack().pop(); diff --git a/module-apps/apps-common/ApplicationCommon.hpp b/module-apps/apps-common/ApplicationCommon.hpp index 56f5038105de10e2db94ce2955539afd12b11567..1aa1cb65a5dd633af2eacff2b6aa01fbf6562c90 100644 --- a/module-apps/apps-common/ApplicationCommon.hpp +++ b/module-apps/apps-common/ApplicationCommon.hpp @@ -122,7 +122,7 @@ namespace app class StatusIndicators { public: - sys::phone_modes::PhoneMode phoneMode = sys::phone_modes::PhoneMode::Connected; + sys::phone_modes::PhoneMode phoneMode = sys::phone_modes::PhoneMode::Uninitialized; sys::bluetooth::BluetoothMode bluetoothMode = sys::bluetooth::BluetoothMode::Disabled; bool alarmClockStatus = false; }; @@ -187,7 +187,7 @@ namespace app std::unique_ptr windowsStackImpl; std::string default_window; State state = State::DEACTIVATED; - bool phoneIsLocked = true; + bool phoneIsLocked = false; sys::MessagePointer handleSignalStrengthUpdate(sys::Message *msgl); sys::MessagePointer handleNetworkAccessTechnologyUpdate(sys::Message *msgl); diff --git a/module-apps/apps-common/notifications/policies/CallNotificationPolicy.cpp b/module-apps/apps-common/notifications/policies/CallNotificationPolicy.cpp index 6e9fc3910add109f7b9d02a44c6368f9d3128ea8..7bf228113082691a1fa3d200dd984f65ee948e83 100644 --- a/module-apps/apps-common/notifications/policies/CallNotificationPolicy.cpp +++ b/module-apps/apps-common/notifications/policies/CallNotificationPolicy.cpp @@ -12,6 +12,8 @@ void CallNotificationPolicy::updateCurrentCall(sys::phone_modes::PhoneMode phone numberCheckNeeded = false; switch (phoneMode) { + case sys::phone_modes::PhoneMode::Uninitialized: + [[fallthrough]]; case sys::phone_modes::PhoneMode::Connected: popupOn = true; ringtoneOn = true; diff --git a/module-apps/apps-common/notifications/policies/NotificationsListPolicy.cpp b/module-apps/apps-common/notifications/policies/NotificationsListPolicy.cpp index d815304e5d6a84c66ec4737456a4f49c028acab7..f6e250dbb3b7022c53c0ab01402dc192beea7f06 100644 --- a/module-apps/apps-common/notifications/policies/NotificationsListPolicy.cpp +++ b/module-apps/apps-common/notifications/policies/NotificationsListPolicy.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. +// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #include "NotificationsListPolicy.hpp" @@ -17,6 +17,8 @@ void NotificationsListPolicy::updateCurrentList(sys::phone_modes::PhoneMode phon showWhenLocked = lockedScreenNotificationSetting; updateAllowed = (isLocked && lockedScreenNotificationSetting) || (!isLocked); break; + case sys::phone_modes::PhoneMode::Uninitialized: + [[fallthrough]]; case sys::phone_modes::PhoneMode::Connected: [[fallthrough]]; case sys::phone_modes::PhoneMode::Offline: diff --git a/module-apps/apps-common/notifications/policies/SMSNotificationPolicy.cpp b/module-apps/apps-common/notifications/policies/SMSNotificationPolicy.cpp index 5bbcc96e32fe59d898ba871db89a40e753cc57ff..712ad3f9007778a7723352efd47a7de1026a5e3f 100644 --- a/module-apps/apps-common/notifications/policies/SMSNotificationPolicy.cpp +++ b/module-apps/apps-common/notifications/policies/SMSNotificationPolicy.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. +// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #include "SMSNotificationPolicy.hpp" @@ -12,6 +12,8 @@ void SMSNotificationPolicy::updateCurrentSMS(sys::phone_modes::PhoneMode phoneMo case sys::phone_modes::PhoneMode::DoNotDisturb: ringtoneOn = false; break; + case sys::phone_modes::PhoneMode::Uninitialized: + [[fallthrough]]; case sys::phone_modes::PhoneMode::Connected: [[fallthrough]]; case sys::phone_modes::PhoneMode::Offline: diff --git a/module-bsp/board/rt1051/bsp/magnetometer/magnetometer.cpp b/module-bsp/board/rt1051/bsp/magnetometer/magnetometer.cpp index d0be9414dc1d6ffdae127487bebe5dc0c3ffa309..676810ec6b8714e0b06d1e1173e9bd2c3154fbd3 100644 --- a/module-bsp/board/rt1051/bsp/magnetometer/magnetometer.cpp +++ b/module-bsp/board/rt1051/bsp/magnetometer/magnetometer.cpp @@ -195,7 +195,7 @@ namespace bsp timerHandle = xTimerCreate( "SliderTimer", pdMS_TO_TICKS(MAGNETOMETER_POLL_INTERVAL_MS), true, nullptr, TimerHandler); if (timerHandle == nullptr) { - LOG_FATAL("Could not create the timer for Headset insertion/removal detection"); + LOG_ERROR("Could not create the timer for magnetometer state change detection!"); return kStatus_Fail; } } diff --git a/module-gui/gui/widgets/StatusBar.hpp b/module-gui/gui/widgets/StatusBar.hpp index ac6725be60e2a55a6187f7e9f30e6461f04c8298..93f17d40c90510b524ead28cc6e2b6c0cf1bc62a 100644 --- a/module-gui/gui/widgets/StatusBar.hpp +++ b/module-gui/gui/widgets/StatusBar.hpp @@ -132,7 +132,7 @@ namespace gui::status_bar }; /// Phone mode - sys::phone_modes::PhoneMode mPhoneMode = sys::phone_modes::PhoneMode::Connected; + sys::phone_modes::PhoneMode mPhoneMode = sys::phone_modes::PhoneMode::Uninitialized; /// Bluetooth mode sys::bluetooth::BluetoothMode mBluetoothMode = sys::bluetooth::BluetoothMode::Disabled; diff --git a/module-gui/gui/widgets/status-bar/PhoneMode.cpp b/module-gui/gui/widgets/status-bar/PhoneMode.cpp index 89f074eebbe8fd6f3e3362be69f7efd4c9dd4d9c..84fac2e3138f0c0dd0be2601de31a0202ae9e5fc 100644 --- a/module-gui/gui/widgets/status-bar/PhoneMode.cpp +++ b/module-gui/gui/widgets/status-bar/PhoneMode.cpp @@ -31,6 +31,8 @@ namespace gui::status_bar setText(utils::translate("home_modes_offline")); break; + case sys::phone_modes::PhoneMode::Uninitialized: + [[fallthrough]]; case sys::phone_modes::PhoneMode::Connected: setText(""); break; diff --git a/module-services/service-cellular/call/include/call/CellularCall.hpp b/module-services/service-cellular/call/include/call/CellularCall.hpp index 6b1fc9917364de57002853425950e0473d11d87a..5e0754da0a4ece3d9f4d96a4f62edfc6a0c4f0de 100644 --- a/module-services/service-cellular/call/include/call/CellularCall.hpp +++ b/module-services/service-cellular/call/include/call/CellularCall.hpp @@ -35,7 +35,7 @@ namespace call struct CallData { CalllogRecord record = {}; - sys::phone_modes::PhoneMode mode = sys::phone_modes::PhoneMode::Connected; + sys::phone_modes::PhoneMode mode = sys::phone_modes::PhoneMode::Uninitialized; sys::phone_modes::Tethering tethering = sys::phone_modes::Tethering::Off; }; diff --git a/module-sys/PhoneModes/include/PhoneModes/Observer.hpp b/module-sys/PhoneModes/include/PhoneModes/Observer.hpp index 0509cb1ee2948ba9a122cb635f3ea93b11bb33de..6f348f479159bf3a29be734e288f6e8e2d22487b 100644 --- a/module-sys/PhoneModes/include/PhoneModes/Observer.hpp +++ b/module-sys/PhoneModes/include/PhoneModes/Observer.hpp @@ -35,7 +35,7 @@ namespace sys::phone_modes OnPhoneModeChangedCallback onPhoneModeChangedCallback; OnTetheringChangedCallback onTetheringChangedCallback; - PhoneMode phoneMode = PhoneMode::Connected; + PhoneMode phoneMode = PhoneMode::Uninitialized; Tethering tetheringMode = Tethering::Off; }; } // namespace sys::phone_modes diff --git a/module-sys/PhoneModes/include/PhoneModes/PhoneMode.hpp b/module-sys/PhoneModes/include/PhoneModes/PhoneMode.hpp index 39dc7ee0eaf713b64c450e7cb13ebb7fe3271a19..dc6d83dd888305cdf176fd02c59aeaf559b34f7f 100644 --- a/module-sys/PhoneModes/include/PhoneModes/PhoneMode.hpp +++ b/module-sys/PhoneModes/include/PhoneModes/PhoneMode.hpp @@ -9,6 +9,7 @@ namespace sys::phone_modes { Connected, DoNotDisturb, - Offline + Offline, + Uninitialized }; } diff --git a/module-sys/PhoneModes/include/PhoneModes/Subject.hpp b/module-sys/PhoneModes/include/PhoneModes/Subject.hpp index 2b360fbba9cb252f7a9efef6eb8b59a9c332fdda..1e2efdb9153ac94d070bc4acb3bfe950d7d59f93 100644 --- a/module-sys/PhoneModes/include/PhoneModes/Subject.hpp +++ b/module-sys/PhoneModes/include/PhoneModes/Subject.hpp @@ -51,7 +51,7 @@ namespace sys::phone_modes void notifyTetheringChange(); Service *owner; - PhoneMode phoneMode = PhoneMode::Connected; + PhoneMode phoneMode = PhoneMode::Uninitialized; Tethering tetheringMode = Tethering::Off; const std::function activeSimSelected; const std::function isCallOngoing; diff --git a/products/PurePhone/services/appmgr/ApplicationManager.cpp b/products/PurePhone/services/appmgr/ApplicationManager.cpp index ce77644f5735d6f9eb501bfff78ff842a1927cb1..8406326d71a95b2c65ad4570cc96e87bebbe20f9 100644 --- a/products/PurePhone/services/appmgr/ApplicationManager.cpp +++ b/products/PurePhone/services/appmgr/ApplicationManager.cpp @@ -138,7 +138,12 @@ namespace app::manager phoneModeObserver->connect(this); phoneModeObserver->subscribe([this](sys::phone_modes::PhoneMode phoneMode) { + static bool isFirstUpdateAfterStartup = true; handlePhoneModeChanged(phoneMode); + if (isFirstUpdateAfterStartup) { + isFirstUpdateAfterStartup = false; + return; + } actionsRegistry.enqueue( ActionEntry{actions::ShowPopup, std::make_unique(phoneMode)}); });