2 * Copyright (c) 2021 - 2022 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include "app-core-ui-cpp/app_core_ui_base.hh"
19 #include <Ecore_Wl2.h>
20 #include <aul_app_lifecycle.h>
21 #include <aul_rpc_port.h>
23 #include <bundle_internal.h>
26 #include <sys/syscall.h>
27 #include <sys/types.h>
37 #include "app-core-cpp/app_core_base.hh"
38 #include "app-core-ui-cpp/api/app_core_ui_base.h"
39 #include "app-core-ui-cpp/app_core_task_base.hh"
40 #include "app-core-ui-cpp/app_core_ui_delegator_private.hh"
41 #include "app-core-ui-cpp/app_core_ui_plugin_private.hh"
42 #include "app-core-ui-cpp/app_core_ui_thread_base.hh"
43 #include "app-core-ui-cpp/wayland_handler_private.hh"
44 #include "app-core-ui-cpp/window_position_private.hh"
45 #include "common/ecore_handler.hh"
46 #include "common/glib_private.hh"
47 #include "common/log_private.hh"
48 #include "common/log_tracer.hh"
52 constexpr const char K_SERVICE_THREAD[] = "__K_SERVICE_THREAD";
53 constexpr const char K_HINT_RECENT_SCREEN_POSITION[] =
54 "__K_HINT_RECENT_SCREEN_POSITION";
55 const int APPID_MAX = 256;
57 class AppCoreUiBase::Impl {
59 Impl(AppCoreUiBase* parent, unsigned int hint)
62 handler_(std::make_shared<EcoreHandler>(parent)),
63 wl_handler_(new WaylandHandler()),
64 wp_manager_(new WindowPositionManager()) {
68 friend class AppCoreUiBase;
69 AppCoreUiBase* parent_;
95 WinNode(unsigned int win, unsigned int surf)
96 : win_(win), surf_(surf), vis_(VT_NONE) {
100 void ExitFromSuspend();
101 void PrepareToSuspend();
102 void DoStart(tizen_base::Bundle b);
106 int IsLegacyLifecycle();
107 std::shared_ptr<struct WinNode> FindWin(unsigned int win);
108 bool AddWin(unsigned int win, unsigned int surf);
109 bool DeleteWin(unsigned int win);
110 bool UpdateWin(unsigned int win, unsigned int surf, int vis);
113 void ApplyBgState(bool bg_state);
117 void PluginInit(int argc, char** argv);
119 void SetWindowPosition(const tizen_base::Bundle& b);
120 void SetWindowPosition();
121 void SetWindow(unsigned int wid);
122 Ecore_Wl2_Window* GetWindow() const;
123 void Run(int argc, char** argv);
126 std::list<std::shared_ptr<WinNode>> winnode_list_;
128 std::string below_app_;
129 bool first_launch_ = true;
130 bool bg_state_ = false;
131 bool resource_reclaiming_ = true;
133 AppState state_ = AS_NONE;
134 WinStatus w_status_ = WS_NONE;
135 std::shared_ptr<EcoreHandler> handler_;
136 std::unique_ptr<WaylandHandler> wl_handler_;
137 IAppCoreUi* core_ui_delegator_ = nullptr;
138 std::unique_ptr<AppCoreUiDelegator> plugin_delegator_;
139 std::unique_ptr<AppCoreUiPlugin> plugin_;
140 std::unique_ptr<AppCoreTaskBase> service_;
141 std::unique_ptr<WindowPosition> position_;
142 Ecore_Wl2_Window* window_ = nullptr;
143 std::unique_ptr<WindowPositionManager> wp_manager_;
144 std::unique_ptr<AppCoreUiThreadBase> thread_;
147 AppCoreUiBase::AppCoreUiBase(unsigned int hint)
148 : impl_(new Impl(this, hint)) {
151 AppCoreUiBase::~AppCoreUiBase() = default;
153 std::shared_ptr<AppCoreUiBase::Impl::WinNode> AppCoreUiBase::Impl::FindWin(
155 for (auto& i : winnode_list_) {
163 bool AppCoreUiBase::Impl::AddWin(unsigned int win, unsigned int surf) {
164 _D("[EVENT_TEST][EVENT] __add_win WIN: %u", win);
165 std::shared_ptr<AppCoreUiBase::Impl::WinNode> node = FindWin(win);
166 if (node != nullptr) {
167 _D("[EVENT_TEST][EVENT] ERROR There is already window: %u", win);
172 winnode_list_.emplace_back(new WinNode(win, surf));
176 bool AppCoreUiBase::Impl::DeleteWin(unsigned int win) {
177 std::shared_ptr<struct AppCoreUiBase::Impl::WinNode> node = FindWin(win);
178 if (node == nullptr) {
179 _D("[EVENT_TEST][EVENT] ERROR There is no window: %u", win);
184 winnode_list_.remove_if(
185 [win](std::shared_ptr<struct AppCoreUiBase::Impl::WinNode> node) {
186 return node->win_ == win;
191 bool AppCoreUiBase::Impl::UpdateWin(unsigned int win, unsigned int surf,
193 std::shared_ptr<AppCoreUiBase::Impl::WinNode> node = FindWin(win);
194 if (node == nullptr) {
195 _D("[EVENT_TEST][EVENT] ERROR There is no window: %u", win);
205 if (GetWindow() == nullptr)
212 void AppCoreUiBase::Impl::RaiseWin() {
213 if (!(hint_ & HINT_WINDOW_STACK_CONTROL))
216 unsigned int win_id = parent_->GetMainWindow();
217 _I("Raise window: %u", win_id);
218 handler_->RaiseWin(win_id);
221 void AppCoreUiBase::Impl::PauseWin() {
222 if (!(hint_ & HINT_WINDOW_STACK_CONTROL))
226 for (auto& i : winnode_list_) {
227 _D("Pause window: %u", i->win_);
228 handler_->PauseWin(i->win_);
232 unsigned int AppCoreUiBase::GetMainWindow() {
233 if (impl_->winnode_list_.empty())
236 return impl_->winnode_list_.begin()->get()->win_;
239 unsigned int AppCoreUiBase::GetMainSurface() {
240 if (impl_->winnode_list_.empty())
243 return impl_->winnode_list_.begin()->get()->surf_;
246 void AppCoreUiBase::SetCoreUiDelegator(IAppCoreUi* delegator) {
247 impl_->core_ui_delegator_ = delegator;
250 void AppCoreUiBase::SetWindowDelegator(IWindow* delegator) {
251 impl_->handler_->SetWindow(delegator);
254 int AppCoreUiBase::Impl::InitWl() {
255 return wl_handler_->Init();
258 int AppCoreUiBase::Impl::FiniWl() {
263 void AppCoreUiBase::Impl::ApplyBgState(bool bg_state) {
264 if (wl_handler_->Init() < 0)
268 wl_handler_->SetBgState();
270 wl_handler_->UnsetBgState();
272 parent_->SetBgState(bg_state);
275 void AppCoreUiBase::Impl::SetAppId() {
276 if (wl_handler_->Init() < 0)
279 wl_handler_->SetAppId(appid_);
282 void AppCoreUiBase::Impl::PluginInit(int argc, char** argv) {
283 LogTracer tracer("AppCoreUiBase::Impl::PluginInit()");
284 plugin_.reset(AppCoreUiPlugin::Load());
285 if (plugin_ == nullptr)
288 app_core_ui_base_ops ops;
289 ops.base.create = [](void* data) -> int {
290 auto* base = reinterpret_cast<AppCoreUiBase*>(data);
291 return base->OnCreate();
294 ops.base.control = [](bundle* b, void* data) -> int {
295 auto* base = reinterpret_cast<AppCoreUiBase*>(data);
296 return base->OnControl(tizen_base::Bundle(b));
299 ops.base.terminate = [](void* data) -> int {
300 auto* base = reinterpret_cast<AppCoreUiBase*>(data);
301 return base->OnTerminate();
304 ops.base.receive = [](aul_type type, bundle* b, void* data) -> int {
305 auto* base = reinterpret_cast<AppCoreUiBase*>(data);
306 return base->OnReceive(type, tizen_base::Bundle(b));
309 ops.base.set_i18n = [](void* data) -> int {
310 auto* base = reinterpret_cast<AppCoreUiBase*>(data);
311 return base->OnSetI18n();
314 ops.base.init = [](int argc, char** argv, void* data) {
315 auto* base = reinterpret_cast<AppCoreUiBase*>(data);
316 base->OnLoopInit(argc, argv);
319 ops.base.finish = [](void* data) {
320 auto* base = reinterpret_cast<AppCoreUiBase*>(data);
321 base->OnLoopFinish();
324 ops.base.run = [](void* data) {
325 auto* base = reinterpret_cast<AppCoreUiBase*>(data);
329 ops.base.exit = [](void* data) {
330 auto* base = reinterpret_cast<AppCoreUiBase*>(data);
334 ops.base.set_event = [](app_core_ui_base_event_e event, void* data) {
335 auto* base = reinterpret_cast<AppCoreUiBase*>(data);
336 base->OnSetEvent(static_cast<IAppCore::IEvent::Type>(event));
339 ops.base.unset_event = [](app_core_ui_base_event_e event, void* data) {
340 auto* base = reinterpret_cast<AppCoreUiBase*>(data);
341 base->OnUnsetEvent(static_cast<IAppCore::IEvent::Type>(event));
344 ops.base.trim_memory = [](void* data) {
345 auto* base = reinterpret_cast<AppCoreUiBase*>(data);
346 base->OnTrimMemory();
349 ops.pause = [](void* data) -> int {
350 auto* base = reinterpret_cast<AppCoreUiBase*>(data);
351 return base->OnPause();
354 ops.resume = [](void* data) -> int {
355 auto* base = reinterpret_cast<AppCoreUiBase*>(data);
356 return base->OnResume();
359 ops.window.show = [](int type, void* event, void* data) {
360 auto* base = reinterpret_cast<AppCoreUiBase*>(data);
361 base->OnShow(type, event);
364 ops.window.hide = [](int type, void* event, void* data) {
365 auto* base = reinterpret_cast<AppCoreUiBase*>(data);
366 base->OnHide(type, event);
369 ops.window.lower = [](int type, void* event, void* data) {
370 auto* base = reinterpret_cast<AppCoreUiBase*>(data);
371 base->OnLower(type, event);
374 ops.window.visibility = [](int type, void* event, void* data) {
375 auto* base = reinterpret_cast<AppCoreUiBase*>(data);
376 base->OnVisibility(type, event);
379 ops.window.pre_visibility = [](int type, void* event, void* data) {
380 auto* base = reinterpret_cast<AppCoreUiBase*>(data);
381 base->OnPreVisibility(type, event);
384 ops.window.aux_message = [](int type, void* event, void* data) {
385 auto* base = reinterpret_cast<AppCoreUiBase*>(data);
386 base->OnAuxMessage(type, event);
389 plugin_->Init(parent_, &ops, argc, argv, &hint_);
390 plugin_delegator_.reset(new AppCoreUiDelegator(ops, parent_));
391 parent_->SetCoreDelegator(plugin_delegator_.get());
392 parent_->SetLoopDelegator(plugin_delegator_.get());
393 parent_->SetCoreUiDelegator(plugin_delegator_.get());
394 parent_->SetWindowDelegator(plugin_delegator_.get());
397 void AppCoreUiBase::Impl::PluginFini() {
398 if (plugin_ == nullptr)
401 plugin_->Fini(parent_);
404 void AppCoreUiBase::Impl::SetWindowPosition(const tizen_base::Bundle& b) {
405 position_ = wp_manager_->ReadFromBundle(b);
407 _D("x: %d, y: %d, w: %d, h: %d",
408 position_->GetPositionX(), position_->GetPositionY(),
409 position_->GetScreenWidth(), position_->GetScreenHeight());
412 auto recent_screen_position = b.GetString(K_HINT_RECENT_SCREEN_POSITION);
413 if (!recent_screen_position.empty()) {
414 auto position = wp_manager_->ReadFromFile();
416 _D("x: %d, y: %d, w: %d, h: %d",
417 position->GetPositionX(), position->GetPositionY(),
418 position->GetScreenWidth(), position->GetScreenHeight());
419 position_ = std::move(position);
421 _D("There is no window position");
426 wp_manager_->WriteToFile(position_);
429 void AppCoreUiBase::Impl::SetWindowPosition() {
433 if (GetWindow() == nullptr) {
434 _E("window is nullptr");
442 ecore_wl2_window_geometry_get(GetWindow(), &x, &y, &w, &h);
444 _W("x: %d, y: %d, w: %d, h: %d", w, y, w, h);
445 if (position_->GetPositionX() != x ||
446 position_->GetPositionY() != y ||
447 position_->GetScreenWidth() != w ||
448 position_->GetScreenHeight() != h) {
449 position_.reset(new WindowPosition(x, y, w, h));
450 wp_manager_->WriteToFile(position_);
454 void AppCoreUiBase::Impl::SetWindow(unsigned int wid) {
460 window_ = ecore_wl2_window_find(wid);
461 if (window_ == nullptr) {
462 _E("ecore_wl2_window_find() is failed. wid(%u)", wid);
466 _D("wid(%u), window(%p)", wid, window_);
469 Ecore_Wl2_Window* AppCoreUiBase::Impl::GetWindow() const {
473 void AppCoreUiBase::DoRun(int argc, char** argv) {
474 SetCoreDelegator(nullptr);
475 SetLoopDelegator(nullptr);
476 SetCoreUiDelegator(nullptr);
477 SetWindowDelegator(this);
478 impl_->plugin_delegator_.reset();
480 impl_->handler_->Init();
481 impl_->PluginInit(argc, argv);
483 char appid[APPID_MAX] = {0, };
484 int ret = aul_app_get_appid_bypid(getpid(), appid, sizeof(appid));
486 _E("Fail to get appid. pid(%d)", getpid());
488 impl_->state_ = Impl::AS_NONE;
489 impl_->w_status_ = Impl::WS_NONE;
490 impl_->appid_ = std::string(appid);
491 LOG(LOG_DEBUG, "LAUNCH", "[%s:Application:main:done]", appid);
493 tizen_base::Bundle b(bundle_import_from_argv(argc, argv), false, true);
495 if (impl_->hint_ & HINT_BG_LAUNCH_CONTROL) {
496 std::string bg_launch = b.GetString(AUL_SVC_K_BG_LAUNCH);
497 if (bg_launch.compare("enable") == 0)
498 impl_->ApplyBgState(true);
501 impl_->SetWindowPosition(b);
504 if (impl_->hint_ & HINT_WINDOW_ID_CONTROL)
507 AppCoreBase::Run(argc, argv);
510 void AppCoreUiBase::DoExit() {
514 void AppCoreUiBase::Impl::Run(int argc, char** argv) {
515 if (hint_ & HINT_DUAL_THREAD) {
516 service_ = parent_->CreateTask();
517 auto* thread_context = AppCoreUiThreadBase::GetContext();
518 if (thread_context == nullptr) {
519 thread_.reset(new AppCoreUiThreadBase());
520 thread_->Run(argc, argv);
521 thread_context = AppCoreUiThreadBase::GetContext();
524 thread_context->Post([&]() { parent_->DoRun(argc, argv); });
525 service_->Run(argc, argv);
529 parent_->DoRun(argc, argv);
532 void AppCoreUiBase::Impl::Exit() {
533 if (hint_ & HINT_DUAL_THREAD) {
534 auto* thread_context = AppCoreUiThreadBase::GetContext();
535 if (thread_context != nullptr) {
536 thread_context->Post([&]() { parent_->DoExit(); });
537 thread_context->Exit();
547 void AppCoreUiBase::Run(int argc, char** argv) {
548 impl_->Run(argc, argv);
551 void AppCoreUiBase::Exit() {
555 void AppCoreUiBase::Dispose() {
556 impl_->handler_->UnsetEvents();
559 impl_->appid_.clear();
561 AppCoreBase::Dispose();
563 impl_->handler_->Fini();
566 std::unique_ptr<AppCoreTaskBase> AppCoreUiBase::CreateTask() {
567 return std::make_unique<AppCoreTaskBase>();
570 void AppCoreUiBase::Impl::PrepareToSuspend() {
571 if (parent_->IsBgAllowed() && !parent_->IsSuspended()) {
572 SuspendedState suspend = SUSPENDED_STATE_WILL_ENTER_SUSPEND;
573 parent_->RaiseEvent(suspend, IEvent::Type::SUSPENDED_STATE_CHANGE);
574 parent_->ToggleSuspendedState();
578 void AppCoreUiBase::Impl::ExitFromSuspend() {
579 if (parent_->IsSuspended()) {
580 SuspendedState suspend = SUSPENDED_STATE_DID_EXIT_FROM_SUSPEND;
581 parent_->RaiseEvent(suspend, IEvent::Type::SUSPENDED_STATE_CHANGE);
582 parent_->ToggleSuspendedState();
586 void AppCoreUiBase::Impl::DoPause() {
587 if (state_ == AS_RUNNING) {
588 aul_app_lifecycle_update_state(AUL_APP_LIFECYCLE_STATE_PAUSED);
590 traceBegin(TTRACE_TAG_APPLICATION_MANAGER, "APPCORE:PAUSE");
591 _D("Call pause callback");
592 if (parent_->GetHint() & HINT_DUAL_THREAD)
593 service_->Post(AppCoreTaskBase::UiState::PAUSED);
596 if (core_ui_delegator_)
597 ret = core_ui_delegator_->OnPause();
599 ret = parent_->OnPause();
601 traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
602 if (ret >= 0 && resource_reclaiming_)
603 parent_->AddSuspendTimer();
608 aul_status_update(STATUS_BG);
611 void AppCoreUiBase::Impl::DoResume() {
612 if (state_ == AS_PAUSED || state_ == AS_CREATED) {
613 aul_app_lifecycle_update_state(AUL_APP_LIFECYCLE_STATE_RESUMED);
616 LOG(LOG_DEBUG, "LAUNCH", "[%s:Application:resume:start]", appid_.c_str());
617 traceBegin(TTRACE_TAG_APPLICATION_MANAGER, "APPCORE:RESUME");
618 _D("Call resume callback");
619 if (parent_->GetHint() & HINT_DUAL_THREAD)
620 service_->Post(AppCoreTaskBase::UiState::RESUMED);
622 parent_->RemoveSuspendTimer();
623 if (core_ui_delegator_)
624 core_ui_delegator_->OnResume();
628 traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
629 LOG(LOG_DEBUG, "LAUNCH", "[%s:Application:resume:done]", appid_.c_str());
632 aul_status_update(STATUS_VISIBLE);
635 void AppCoreUiBase::Impl::DoStart(tizen_base::Bundle b) {
636 if (parent_->GetHint() & HINT_WINDOW_STACK_CONTROL)
637 below_app_ = b.GetString(AUL_SVC_K_RELOCATE_BELOW);
640 first_launch_ = false;
644 std::string rpc_port = b.GetString(AUL_K_RPC_PORT);
645 if (parent_->GetHint() & HINT_BG_LAUNCH_CONTROL) {
646 std::string bg_launch = b.GetString(AUL_SVC_K_BG_LAUNCH);
647 if (!bg_launch.empty() && bg_launch.compare("enable") == 0) {
648 if (!bg_state_ && state_ != AS_RUNNING)
651 if (bg_state_ && rpc_port.empty())
656 if (parent_->GetHint() & HINT_WINDOW_AUTO_CONTROL) {
657 if (!bg_state_ && rpc_port.empty())
662 int AppCoreUiBase::Impl::IsLegacyLifecycle() {
663 static int is_legacy = -1;
664 if (__builtin_expect(is_legacy != -1, 1))
667 const char* api_version = getenv("TIZEN_API_VERSION");
669 if (strverscmp("2.4", api_version) > 0 &&
670 strverscmp("2.2.1", api_version) < 0)
681 int AppCoreUiBase::OnPause() {
685 int AppCoreUiBase::OnResume() {
689 int AppCoreUiBase::OnReceive(aul_type type, tizen_base::Bundle b) {
690 if (impl_->state_ == Impl::AS_DYING) {
691 _E("Skip the event in dying state");
695 if ((type == AUL_TERMINATE_BGAPP || type == AUL_TERMINATE_BG_INST) &&
696 impl_->state_ != Impl::AS_PAUSED)
699 if (type == AUL_START) {
700 impl_->ExitFromSuspend();
702 if (!b.GetString(K_SERVICE_THREAD).empty()) {
703 impl_->service_->OnReceive(type, std::move(b));
708 AppCoreBase::OnReceive(type, b);
713 if (GetHint() & HINT_LEGACY_CONTROL) {
714 if (impl_->bg_state_ && impl_->IsLegacyLifecycle()) {
715 _D("Legacy lifecycle");
721 if (impl_->bg_state_)
722 impl_->ApplyBgState(false);
727 if (impl_->state_ == Impl::AS_RUNNING) {
728 _D("Call pause callback");
729 if (impl_->core_ui_delegator_)
730 impl_->core_ui_delegator_->OnPause();
734 impl_->state_ = Impl::AS_DYING;
736 case AUL_TERMINATE_BGAPP:
737 case AUL_TERMINATE_BG_INST:
738 case AUL_TERMINATE_INST:
739 _D("[APP %d] TERMINATE", getpid());
740 if (impl_->state_ == Impl::AS_RUNNING) {
741 _D("Call pause callback");
742 if (impl_->core_ui_delegator_)
743 impl_->core_ui_delegator_->OnPause();
747 impl_->state_ = Impl::AS_DYING;
748 aul_status_update(STATUS_DYING);
761 int AppCoreUiBase::OnControl(tizen_base::Bundle b) {
762 LOG(LOG_DEBUG, "LAUNCH", "[%s:Application:reset:start]",
763 impl_->appid_.c_str());
764 AppCoreBase::OnControl(std::move(b));
765 LOG(LOG_DEBUG, "LAUNCH", "[%s:Application:reset:done]",
766 impl_->appid_.c_str());
770 int AppCoreUiBase::OnCreate() {
771 impl_->handler_->SetEvents();
772 AppCoreBase::OnCreate();
773 impl_->state_ = Impl::AS_CREATED;
774 LOG(LOG_DEBUG, "LAUNCH", "[%s:Application:create:done]",
775 impl_->appid_.c_str());
779 int AppCoreUiBase::OnTerminate() {
780 if (impl_->state_ == Impl::AS_RUNNING) {
781 _D("Call pause callback");
785 impl_->state_ = Impl::AS_DYING;
786 AppCoreBase::OnTerminate();
790 int AppCoreUiBase::OnTrimMemory() {
791 return AppCoreBase::OnTrimMemory();
794 int AppCoreUiBase::GroupAdd() {
796 static bool attached = false;
800 int wid = GetMainSurface();
802 _E("window wasn't ready");
806 int ret = aul_app_group_set_window(wid);
808 _E("Failed to set app group window. error(%d)", ret);
816 void AppCoreUiBase::GroupRemove() {
819 aul_app_group_lower(&exit);
826 void AppCoreUiBase::OnShow(int type, void* event) {
827 auto* ev = reinterpret_cast<Ecore_Wl2_Event_Window_Show*>(event);
828 if (ev->parent_win != 0)
831 unsigned int win = static_cast<unsigned int>(ev->win);
832 unsigned int surf = static_cast<unsigned int>(ev->data[0]);
833 _D("[EVENT_TEST][EVENT] GET SHOW EVENT!!!. WIN: %u, %u", win, surf);
835 if (!impl_->FindWin(win))
836 impl_->AddWin(win, surf);
838 impl_->UpdateWin(win, surf, Impl::VT_NONE);
845 bool AppCoreUiBase::Impl::CheckVisible() {
846 _D("[EVENT_TEST][EVENT] __check_visible");
847 for (auto& i : winnode_list_) {
848 _D("win : %u visibility : %d", i->win_, i->vis_);
849 if (i->vis_ == VT_UNOBSCURED)
856 void AppCoreUiBase::OnHide(int type, void* event) {
857 auto* ev = reinterpret_cast<Ecore_Wl2_Event_Window_Hide*>(event);
858 _D("[EVENT_TEST][EVENT] GET HIDE EVENT!!!. WIN :%d", ev->win);
859 if (impl_->FindWin((unsigned int)ev->win)) {
860 impl_->DeleteWin((unsigned int)ev->win);
861 bool bvisibility = impl_->CheckVisible();
862 if (!bvisibility && impl_->w_status_ != Impl::WS_PAUSE) {
863 _D("Go to Pasue state");
864 impl_->w_status_ = Impl::WS_PAUSE;
870 void AppCoreUiBase::OnLower(int type, void* event) {
871 auto* ev = reinterpret_cast<Ecore_Wl2_Event_Window_Lower*>(event);
875 _D("ECORE_WL2_EVENT_WINDOW_LOWER window id: %u", ev->win);
876 if (!(impl_->hint_ & HINT_WINDOW_GROUP_CONTROL))
882 void AppCoreUiBase::OnVisibility(int type, void* event) {
883 auto* ev = reinterpret_cast<Ecore_Wl2_Event_Window_Visibility_Change*>(event);
884 impl_->UpdateWin((unsigned int)ev->win, 0,
885 ev->fully_obscured ? Impl::VT_FULLY_OBSCURED : Impl::VT_UNOBSCURED);
886 bool bvisibility = impl_->CheckVisible();
887 _D("bvisibility %d, w_status_ %d", bvisibility, impl_->w_status_);
889 if (bvisibility && (impl_->hint_ & HINT_WINDOW_STACK_CONTROL) &&
890 !impl_->below_app_.empty()) {
891 aul_app_group_activate_below(impl_->below_app_.c_str());
892 impl_->below_app_.clear();
895 if (bvisibility && impl_->w_status_ != Impl::WS_RESUME) {
896 _D("Go to Resume state");
897 impl_->w_status_ = Impl::WS_RESUME;
899 } else if (!bvisibility && impl_->w_status_ != Impl::WS_PAUSE) {
900 _D("Go to Pasue state");
901 impl_->w_status_ = Impl::WS_PAUSE;
904 _D("No change state");
908 void AppCoreUiBase::OnPreVisibility(int type, void* event) {
909 auto* ev = reinterpret_cast<Ecore_Wl2_Event_Window_Pre_Visibility_Change*>(
911 if (ev && ev->type == ECORE_WL2_WINDOW_VISIBILITY_TYPE_PRE_UNOBSCURED) {
912 impl_->UpdateWin((unsigned int)ev->win, 0, Impl::VT_UNOBSCURED);
913 bool bvisibility = impl_->CheckVisible();
915 _D("bvisibility %d, w_status_ %d", bvisibility, impl_->w_status_);
916 if (bvisibility && impl_->w_status_ != Impl::WS_RESUME) {
917 _D(" Go to Resume state");
918 impl_->w_status_ = Impl::WS_RESUME;
924 void AppCoreUiBase::OnAuxMessage(int type, void* event) {
925 auto* ev = reinterpret_cast<Ecore_Wl2_Event_Aux_Message*>(event);
926 if (ev->key && !strcmp(ev->key, "dpms_wm")) {
927 if (ev->val && !strcmp(ev->val, "on")) {
928 _D("Display state: on");
929 SetDisplayState(DISPLAY_STATE_ON);
930 } else if (ev->val && !strcmp(ev->val, "off")) {
931 _D("Display state: off");
932 SetDisplayState(DISPLAY_STATE_OFF);
934 _E("Unknown state: %s", ev->val);
939 void AppCoreUiBase::Pause() {
943 void AppCoreUiBase::Resume() {
947 bool AppCoreUiBase::IsResumed() {
948 return impl_->state_ == Impl::AS_RUNNING;
951 int AppCoreUiBase::GetHint() {
955 bool AppCoreUiBase::GetBgState() {
956 return impl_->bg_state_;
959 void AppCoreUiBase::SetBgState(bool bg_state) {
960 impl_->bg_state_ = bg_state;
963 void AppCoreUiBase::SetSystemResourceReclaiming(bool enable) {
964 impl_->resource_reclaiming_ = enable;
967 int AppCoreUiBase::GetWindowPosition(int* x, int* y, int* w, int* h) {
968 if (!impl_->position_ ||
975 *x = impl_->position_->GetPositionX();
976 *y = impl_->position_->GetPositionY();
977 *w = impl_->position_->GetScreenWidth();
978 *h = impl_->position_->GetScreenHeight();
983 } // namespace tizen_cpp