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>
36 #include "app-core-cpp/app_core_base.hh"
37 #include "app-core-ui-cpp/api/app_core_ui_base.h"
38 #include "app-core-ui-cpp/app_core_task_base.hh"
39 #include "app-core-ui-cpp/app_core_ui_delegator_private.hh"
40 #include "app-core-ui-cpp/app_core_ui_plugin_private.hh"
41 #include "app-core-ui-cpp/wayland_handler_private.hh"
42 #include "common/ecore_handler.hh"
43 #include "common/glib_private.hh"
44 #include "common/log_private.hh"
48 constexpr const char K_SERVICE_THREAD[] = "__K_SERVICE_THREAD";
50 void SetComm(const std::string& name) {
51 pid_t tid = syscall(__NR_gettid);
52 std::string path = "/proc/" + std::to_string(tid) + "/comm";
53 int fd = open(path.c_str(), O_WRONLY);
55 _E("open(%s) is failed. errno(%d)", path.c_str(), errno);
59 ssize_t bytes_written = write(fd, name.c_str(), name.length() + 1);
60 if (bytes_written < 0)
61 _E("write(%d) is failed. errno(%d)", fd, errno);
66 class AppCoreUiBase::Impl {
68 Impl(AppCoreUiBase* parent, unsigned int hint)
71 handler_(std::make_shared<EcoreHandler>(parent)),
72 wl_handler_(new WaylandHandler()) {
76 friend class AppCoreUiBase;
77 AppCoreUiBase* parent_;
103 WinNode(unsigned int win, unsigned int surf)
104 : win_(win), surf_(surf), vis_(VT_NONE) {
108 class WindowPosition {
110 WindowPosition(int x, int y, int w, int h)
111 : x_(x), y_(y), w_(w), h_(h){
114 int GetPositionX() const { return x_; }
115 int GetPositionY() const { return y_; }
116 int GetScreenWidth() const { return w_; }
117 int GetScreenHeight() const { return h_; }
126 void ExitFromSuspend();
127 void PrepareToSuspend();
128 void DoStart(tizen_base::Bundle b);
132 int IsLegacyLifecycle();
133 std::shared_ptr<struct WinNode> FindWin(unsigned int win);
134 bool AddWin(unsigned int win, unsigned int surf);
135 bool DeleteWin(unsigned int win);
136 bool UpdateWin(unsigned int win, unsigned int surf, int vis);
139 void ApplyBgState(bool bg_state);
143 void PluginInit(int argc, char** argv);
145 void SetWindowPosition(const tizen_base::Bundle& b);
146 void Run(int argc, char** argv);
149 std::list<std::shared_ptr<WinNode>> winnode_list_;
151 std::string below_app_;
152 bool first_launch_ = true;
153 bool bg_state_ = false;
154 bool resource_reclaiming_ = true;
156 AppState state_ = AS_NONE;
157 WinStatus w_status_ = WS_NONE;
158 std::shared_ptr<EcoreHandler> handler_;
159 std::unique_ptr<WaylandHandler> wl_handler_;
160 IAppCoreUi* core_ui_delegator_ = nullptr;
161 std::unique_ptr<AppCoreUiDelegator> plugin_delegator_;
162 std::unique_ptr<AppCoreUiPlugin> plugin_;
163 std::unique_ptr<AppCoreTaskBase> service_;
164 GMainContext* context_ = nullptr;
166 std::unique_ptr<WindowPosition> position_;
169 AppCoreUiBase::AppCoreUiBase(unsigned int hint)
170 : impl_(new Impl(this, hint)) {
173 AppCoreUiBase::~AppCoreUiBase() = default;
175 std::shared_ptr<AppCoreUiBase::Impl::WinNode> AppCoreUiBase::Impl::FindWin(
177 for (auto& i : winnode_list_) {
185 bool AppCoreUiBase::Impl::AddWin(unsigned int win, unsigned int surf) {
186 _D("[EVENT_TEST][EVENT] __add_win WIN: %u", win);
187 std::shared_ptr<AppCoreUiBase::Impl::WinNode> node = FindWin(win);
188 if (node != nullptr) {
189 _D("[EVENT_TEST][EVENT] ERROR There is already window: %u", win);
193 winnode_list_.emplace_back(new WinNode(win, surf));
197 bool AppCoreUiBase::Impl::DeleteWin(unsigned int win) {
198 std::shared_ptr<struct AppCoreUiBase::Impl::WinNode> node = FindWin(win);
199 if (node == nullptr) {
200 _D("[EVENT_TEST][EVENT] ERROR There is no window: %u", win);
204 winnode_list_.remove_if(
205 [win](std::shared_ptr<struct AppCoreUiBase::Impl::WinNode> node) {
206 return node->win_ == win;
211 bool AppCoreUiBase::Impl::UpdateWin(unsigned int win, unsigned int surf,
213 std::shared_ptr<AppCoreUiBase::Impl::WinNode> node = FindWin(win);
214 if (node == nullptr) {
215 _D("[EVENT_TEST][EVENT] ERROR There is no window: %u", win);
228 void AppCoreUiBase::Impl::RaiseWin() {
229 if (!(hint_ & HINT_WINDOW_STACK_CONTROL))
232 unsigned int win_id = parent_->GetMainWindow();
233 _I("Raise window: %u", win_id);
234 handler_->RaiseWin(win_id);
237 void AppCoreUiBase::Impl::PauseWin() {
238 if (!(hint_ & HINT_WINDOW_STACK_CONTROL))
242 for (auto& i : winnode_list_) {
243 _D("Pause window: %u", i->win_);
244 handler_->PauseWin(i->win_);
248 unsigned int AppCoreUiBase::GetMainWindow() {
249 if (impl_->winnode_list_.empty())
252 return impl_->winnode_list_.begin()->get()->win_;
255 unsigned int AppCoreUiBase::GetMainSurface() {
256 if (impl_->winnode_list_.empty())
259 return impl_->winnode_list_.begin()->get()->surf_;
262 void AppCoreUiBase::SetCoreUiDelegator(IAppCoreUi* delegator) {
263 impl_->core_ui_delegator_ = delegator;
266 void AppCoreUiBase::SetWindowDelegator(IWindow* delegator) {
267 impl_->handler_->SetWindow(delegator);
270 int AppCoreUiBase::Impl::InitWl() {
271 return wl_handler_->Init();
274 int AppCoreUiBase::Impl::FiniWl() {
279 void AppCoreUiBase::Impl::ApplyBgState(bool bg_state) {
280 if (wl_handler_->Init() < 0)
284 wl_handler_->SetBgState();
286 wl_handler_->UnsetBgState();
288 parent_->SetBgState(bg_state);
291 void AppCoreUiBase::Impl::SetAppId() {
292 if (wl_handler_->Init() < 0)
295 wl_handler_->SetAppId(appid_);
298 void AppCoreUiBase::Impl::PluginInit(int argc, char** argv) {
299 plugin_.reset(AppCoreUiPlugin::Load());
300 if (plugin_ == nullptr)
303 app_core_ui_base_ops ops;
304 ops.base.create = [](void* data) -> int {
305 auto* base = reinterpret_cast<AppCoreUiBase*>(data);
306 return base->OnCreate();
309 ops.base.control = [](bundle* b, void* data) -> int {
310 auto* base = reinterpret_cast<AppCoreUiBase*>(data);
311 return base->OnControl(tizen_base::Bundle(b));
314 ops.base.terminate = [](void* data) -> int {
315 auto* base = reinterpret_cast<AppCoreUiBase*>(data);
316 return base->OnTerminate();
319 ops.base.receive = [](aul_type type, bundle* b, void* data) -> int {
320 auto* base = reinterpret_cast<AppCoreUiBase*>(data);
321 return base->OnReceive(type, tizen_base::Bundle(b));
324 ops.base.set_i18n = [](void* data) -> int {
325 auto* base = reinterpret_cast<AppCoreUiBase*>(data);
326 return base->OnSetI18n();
329 ops.base.init = [](int argc, char** argv, void* data) {
330 auto* base = reinterpret_cast<AppCoreUiBase*>(data);
331 base->OnLoopInit(argc, argv);
334 ops.base.finish = [](void* data) {
335 auto* base = reinterpret_cast<AppCoreUiBase*>(data);
336 base->OnLoopFinish();
339 ops.base.run = [](void* data) {
340 auto* base = reinterpret_cast<AppCoreUiBase*>(data);
344 ops.base.exit = [](void* data) {
345 auto* base = reinterpret_cast<AppCoreUiBase*>(data);
349 ops.base.set_event = [](app_core_ui_base_event_e event, void* data) {
350 auto* base = reinterpret_cast<AppCoreUiBase*>(data);
351 base->OnSetEvent(static_cast<IAppCore::IEvent::Type>(event));
354 ops.base.unset_event = [](app_core_ui_base_event_e event, void* data) {
355 auto* base = reinterpret_cast<AppCoreUiBase*>(data);
356 base->OnUnsetEvent(static_cast<IAppCore::IEvent::Type>(event));
359 ops.base.trim_memory = [](void* data) {
360 auto* base = reinterpret_cast<AppCoreUiBase*>(data);
361 base->OnTrimMemory();
364 ops.pause = [](void* data) -> int {
365 auto* base = reinterpret_cast<AppCoreUiBase*>(data);
366 return base->OnPause();
369 ops.resume = [](void* data) -> int {
370 auto* base = reinterpret_cast<AppCoreUiBase*>(data);
371 return base->OnResume();
374 ops.window.show = [](int type, void* event, void* data) {
375 auto* base = reinterpret_cast<AppCoreUiBase*>(data);
376 base->OnShow(type, event);
379 ops.window.hide = [](int type, void* event, void* data) {
380 auto* base = reinterpret_cast<AppCoreUiBase*>(data);
381 base->OnHide(type, event);
384 ops.window.lower = [](int type, void* event, void* data) {
385 auto* base = reinterpret_cast<AppCoreUiBase*>(data);
386 base->OnLower(type, event);
389 ops.window.visibility = [](int type, void* event, void* data) {
390 auto* base = reinterpret_cast<AppCoreUiBase*>(data);
391 base->OnVisibility(type, event);
394 ops.window.pre_visibility = [](int type, void* event, void* data) {
395 auto* base = reinterpret_cast<AppCoreUiBase*>(data);
396 base->OnPreVisibility(type, event);
399 ops.window.aux_message = [](int type, void* event, void* data) {
400 auto* base = reinterpret_cast<AppCoreUiBase*>(data);
401 base->OnAuxMessage(type, event);
404 plugin_->Init(parent_, &ops, argc, argv, &hint_);
405 plugin_delegator_.reset(new AppCoreUiDelegator(ops, parent_));
406 parent_->SetCoreDelegator(plugin_delegator_.get());
407 parent_->SetLoopDelegator(plugin_delegator_.get());
408 parent_->SetCoreUiDelegator(plugin_delegator_.get());
409 parent_->SetWindowDelegator(plugin_delegator_.get());
412 void AppCoreUiBase::Impl::PluginFini() {
413 if (plugin_ == nullptr)
416 plugin_->Fini(parent_);
419 void AppCoreUiBase::Impl::SetWindowPosition(const tizen_base::Bundle& b) {
420 std::string x_str = b.GetString(AUL_K_HINT_SCREEN_POS_X);
424 std::string y_str = b.GetString(AUL_K_HINT_SCREEN_POS_Y);
428 std::string w_str = b.GetString(AUL_K_HINT_SCREEN_WIDTH);
432 std::string h_str = b.GetString(AUL_K_HINT_SCREEN_HEIGHT);
436 position_ = std::make_unique<AppCoreUiBase::Impl::WindowPosition>(
437 std::stoi(x_str), std::stoi(y_str), std::stoi(w_str), std::stoi(h_str));
440 void AppCoreUiBase::DoRun(int argc, char** argv) {
441 SetCoreDelegator(nullptr);
442 SetLoopDelegator(nullptr);
443 SetCoreUiDelegator(nullptr);
444 SetWindowDelegator(this);
445 impl_->plugin_delegator_.reset();
447 impl_->handler_->Init();
448 impl_->PluginInit(argc, argv);
450 char appid[PATH_MAX] = {0, };
451 int ret = aul_app_get_appid_bypid(getpid(), appid, sizeof(appid));
453 _E("Fail to get appid. pid(%d)", getpid());
455 impl_->state_ = Impl::AS_NONE;
456 impl_->w_status_ = Impl::WS_NONE;
457 impl_->appid_ = std::string(appid);
458 LOG(LOG_DEBUG, "LAUNCH", "[%s:Application:main:done]", appid);
460 tizen_base::Bundle b(bundle_import_from_argv(argc, argv), false, true);
462 if (impl_->hint_ & HINT_BG_LAUNCH_CONTROL) {
463 std::string bg_launch = b.GetString(AUL_SVC_K_BG_LAUNCH);
464 if (bg_launch.compare("enable") == 0)
465 impl_->ApplyBgState(true);
468 impl_->SetWindowPosition(b);
471 if (impl_->hint_ & HINT_WINDOW_ID_CONTROL)
474 AppCoreBase::Run(argc, argv);
477 void AppCoreUiBase::DoExit() {
481 void AppCoreUiBase::Impl::Run(int argc, char** argv) {
482 if (hint_ & HINT_DUAL_THREAD) {
483 // For the loader case
484 while (ecore_shutdown() != 0);
486 service_ = parent_->CreateTask();
487 context_ = g_main_context_new();
488 std::string env = std::to_string(
489 reinterpret_cast<unsigned long int>(context_));
490 setenv("TIZEN_GLIB_CONTEXT", env.c_str(), 1);
492 thread_ = std::thread([&] {
493 SetComm("UIThread+");
494 parent_->DoRun(argc, argv);
497 service_->Run(argc, argv);
499 if (thread_.joinable())
502 setenv("TIZEN_GLIB_CONTEXT", "0", 1);
503 g_main_context_unref(context_);
508 parent_->DoRun(argc, argv);
511 void AppCoreUiBase::Impl::Exit() {
512 if (hint_ & HINT_DUAL_THREAD) {
513 GLib::IdleAdd(context_, [](gpointer user_data) {
514 auto* impl = static_cast<AppCoreUiBase::Impl*>(user_data);
515 impl->parent_->DoExit();
516 return G_SOURCE_REMOVE;
526 void AppCoreUiBase::Run(int argc, char** argv) {
527 impl_->Run(argc, argv);
530 void AppCoreUiBase::Exit() {
534 void AppCoreUiBase::Dispose() {
535 impl_->handler_->UnsetEvents();
538 impl_->appid_.clear();
540 AppCoreBase::Dispose();
542 impl_->handler_->Fini();
545 std::unique_ptr<AppCoreTaskBase> AppCoreUiBase::CreateTask() {
546 return std::make_unique<AppCoreTaskBase>();
549 void AppCoreUiBase::Impl::PrepareToSuspend() {
550 if (parent_->IsBgAllowed() && !parent_->IsSuspended()) {
551 SuspendedState suspend = SUSPENDED_STATE_WILL_ENTER_SUSPEND;
552 parent_->RaiseEvent(suspend, IEvent::Type::SUSPENDED_STATE_CHANGE);
553 parent_->ToggleSuspendedState();
557 void AppCoreUiBase::Impl::ExitFromSuspend() {
558 if (parent_->IsSuspended()) {
559 SuspendedState suspend = SUSPENDED_STATE_DID_EXIT_FROM_SUSPEND;
560 parent_->RaiseEvent(suspend, IEvent::Type::SUSPENDED_STATE_CHANGE);
561 parent_->ToggleSuspendedState();
565 void AppCoreUiBase::Impl::DoPause() {
566 if (state_ == AS_RUNNING) {
567 aul_app_lifecycle_update_state(AUL_APP_LIFECYCLE_STATE_PAUSED);
569 traceBegin(TTRACE_TAG_APPLICATION_MANAGER, "APPCORE:PAUSE");
570 _D("Call pause callback");
571 if (parent_->GetHint() & HINT_DUAL_THREAD)
572 service_->Post(AppCoreTaskBase::UiState::PAUSED);
575 if (core_ui_delegator_)
576 ret = core_ui_delegator_->OnPause();
578 ret = parent_->OnPause();
580 traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
581 if (ret >= 0 && resource_reclaiming_)
582 parent_->AddSuspendTimer();
587 aul_status_update(STATUS_BG);
590 void AppCoreUiBase::Impl::DoResume() {
591 if (state_ == AS_PAUSED || state_ == AS_CREATED) {
592 aul_app_lifecycle_update_state(AUL_APP_LIFECYCLE_STATE_RESUMED);
595 LOG(LOG_DEBUG, "LAUNCH", "[%s:Application:resume:start]", appid_.c_str());
596 traceBegin(TTRACE_TAG_APPLICATION_MANAGER, "APPCORE:RESUME");
597 _D("Call resume callback");
598 if (parent_->GetHint() & HINT_DUAL_THREAD)
599 service_->Post(AppCoreTaskBase::UiState::RESUMED);
601 parent_->RemoveSuspendTimer();
602 if (core_ui_delegator_)
603 core_ui_delegator_->OnResume();
607 traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
608 LOG(LOG_DEBUG, "LAUNCH", "[%s:Application:resume:done]", appid_.c_str());
611 aul_status_update(STATUS_VISIBLE);
614 void AppCoreUiBase::Impl::DoStart(tizen_base::Bundle b) {
615 if (parent_->GetHint() & HINT_WINDOW_STACK_CONTROL)
616 below_app_ = b.GetString(AUL_SVC_K_RELOCATE_BELOW);
619 first_launch_ = false;
623 std::string rpc_port = b.GetString(AUL_K_RPC_PORT);
624 if (parent_->GetHint() & HINT_BG_LAUNCH_CONTROL) {
625 std::string bg_launch = b.GetString(AUL_SVC_K_BG_LAUNCH);
626 if (!bg_launch.empty() && bg_launch.compare("enable") == 0) {
627 if (!bg_state_ && state_ != AS_RUNNING)
630 if (bg_state_ && rpc_port.empty())
635 if (parent_->GetHint() & HINT_WINDOW_AUTO_CONTROL) {
636 if (!bg_state_ && rpc_port.empty())
641 int AppCoreUiBase::Impl::IsLegacyLifecycle() {
642 static int is_legacy = -1;
643 if (__builtin_expect(is_legacy != -1, 1))
646 const char* api_version = getenv("TIZEN_API_VERSION");
648 if (strverscmp("2.4", api_version) > 0 &&
649 strverscmp("2.2.1", api_version) < 0)
660 int AppCoreUiBase::OnPause() {
664 int AppCoreUiBase::OnResume() {
668 int AppCoreUiBase::OnReceive(aul_type type, tizen_base::Bundle b) {
669 if (impl_->state_ == Impl::AS_DYING) {
670 _E("Skip the event in dying state");
674 if ((type == AUL_TERMINATE_BGAPP || type == AUL_TERMINATE_BG_INST) &&
675 impl_->state_ != Impl::AS_PAUSED)
678 if (type == AUL_START) {
679 impl_->ExitFromSuspend();
681 if (!b.GetString(K_SERVICE_THREAD).empty()) {
682 impl_->service_->OnReceive(type, std::move(b));
687 AppCoreBase::OnReceive(type, b);
692 if (GetHint() & HINT_LEGACY_CONTROL) {
693 if (impl_->bg_state_ && impl_->IsLegacyLifecycle()) {
694 _D("Legacy lifecycle");
700 if (impl_->bg_state_)
701 impl_->ApplyBgState(false);
706 if (impl_->state_ == Impl::AS_RUNNING) {
707 _D("Call pause callback");
708 if (impl_->core_ui_delegator_)
709 impl_->core_ui_delegator_->OnPause();
713 impl_->state_ = Impl::AS_DYING;
715 case AUL_TERMINATE_BGAPP:
716 case AUL_TERMINATE_BG_INST:
717 case AUL_TERMINATE_INST:
718 _D("[APP %d] TERMINATE", getpid());
719 if (impl_->state_ == Impl::AS_RUNNING) {
720 _D("Call pause callback");
721 if (impl_->core_ui_delegator_)
722 impl_->core_ui_delegator_->OnPause();
726 impl_->state_ = Impl::AS_DYING;
727 aul_status_update(STATUS_DYING);
740 int AppCoreUiBase::OnControl(tizen_base::Bundle b) {
741 LOG(LOG_DEBUG, "LAUNCH", "[%s:Application:reset:start]",
742 impl_->appid_.c_str());
743 AppCoreBase::OnControl(std::move(b));
744 LOG(LOG_DEBUG, "LAUNCH", "[%s:Application:reset:done]",
745 impl_->appid_.c_str());
749 int AppCoreUiBase::OnCreate() {
750 impl_->handler_->SetEvents();
751 AppCoreBase::OnCreate();
752 impl_->state_ = Impl::AS_CREATED;
753 LOG(LOG_DEBUG, "LAUNCH", "[%s:Application:create:done]",
754 impl_->appid_.c_str());
758 int AppCoreUiBase::OnTerminate() {
759 if (impl_->state_ == Impl::AS_RUNNING) {
760 _D("Call pause callback");
764 impl_->state_ = Impl::AS_DYING;
765 AppCoreBase::OnTerminate();
769 int AppCoreUiBase::OnTrimMemory() {
770 return AppCoreBase::OnTrimMemory();
773 int AppCoreUiBase::GroupAdd() {
775 static bool attached = false;
779 int wid = GetMainSurface();
781 _E("window wasn't ready");
785 int ret = aul_app_group_set_window(wid);
787 _E("Failed to set app group window. error(%d)", ret);
795 void AppCoreUiBase::GroupRemove() {
798 aul_app_group_lower(&exit);
805 void AppCoreUiBase::OnShow(int type, void* event) {
806 auto* ev = reinterpret_cast<Ecore_Wl2_Event_Window_Show*>(event);
807 if (ev->parent_win != 0)
810 unsigned int win = static_cast<unsigned int>(ev->win);
811 unsigned int surf = static_cast<unsigned int>(ev->data[0]);
812 _D("[EVENT_TEST][EVENT] GET SHOW EVENT!!!. WIN: %u, %u", win, surf);
814 if (!impl_->FindWin(win))
815 impl_->AddWin(win, surf);
817 impl_->UpdateWin(win, surf, Impl::VT_NONE);
823 bool AppCoreUiBase::Impl::CheckVisible() {
824 _D("[EVENT_TEST][EVENT] __check_visible");
825 for (auto& i : winnode_list_) {
826 _D("win : %u visibility : %d", i->win_, i->vis_);
827 if (i->vis_ == VT_UNOBSCURED)
834 void AppCoreUiBase::OnHide(int type, void* event) {
835 auto* ev = reinterpret_cast<Ecore_Wl2_Event_Window_Hide*>(event);
836 _D("[EVENT_TEST][EVENT] GET HIDE EVENT!!!. WIN :%d", ev->win);
837 if (impl_->FindWin((unsigned int)ev->win)) {
838 impl_->DeleteWin((unsigned int)ev->win);
839 bool bvisibility = impl_->CheckVisible();
840 if (!bvisibility && impl_->w_status_ != Impl::WS_PAUSE) {
841 _D("Go to Pasue state");
842 impl_->w_status_ = Impl::WS_PAUSE;
848 void AppCoreUiBase::OnLower(int type, void* event) {
849 auto* ev = reinterpret_cast<Ecore_Wl2_Event_Window_Lower*>(event);
853 _D("ECORE_WL2_EVENT_WINDOW_LOWER window id: %u", ev->win);
854 if (!(impl_->hint_ & HINT_WINDOW_GROUP_CONTROL))
860 void AppCoreUiBase::OnVisibility(int type, void* event) {
861 auto* ev = reinterpret_cast<Ecore_Wl2_Event_Window_Visibility_Change*>(event);
862 impl_->UpdateWin((unsigned int)ev->win, 0,
863 ev->fully_obscured ? Impl::VT_FULLY_OBSCURED : Impl::VT_UNOBSCURED);
864 bool bvisibility = impl_->CheckVisible();
865 _D("bvisibility %d, w_status_ %d", bvisibility, impl_->w_status_);
867 if (bvisibility && (impl_->hint_ & HINT_WINDOW_STACK_CONTROL) &&
868 !impl_->below_app_.empty()) {
869 aul_app_group_activate_below(impl_->below_app_.c_str());
870 impl_->below_app_.clear();
873 if (bvisibility && impl_->w_status_ != Impl::WS_RESUME) {
874 _D("Go to Resume state");
875 impl_->w_status_ = Impl::WS_RESUME;
877 } else if (!bvisibility && impl_->w_status_ != Impl::WS_PAUSE) {
878 _D("Go to Pasue state");
879 impl_->w_status_ = Impl::WS_PAUSE;
882 _D("No change state");
886 void AppCoreUiBase::OnPreVisibility(int type, void* event) {
887 auto* ev = reinterpret_cast<Ecore_Wl2_Event_Window_Pre_Visibility_Change*>(
889 if (ev && ev->type == ECORE_WL2_WINDOW_VISIBILITY_TYPE_PRE_UNOBSCURED) {
890 impl_->UpdateWin((unsigned int)ev->win, 0, Impl::VT_UNOBSCURED);
891 bool bvisibility = impl_->CheckVisible();
893 _D("bvisibility %d, w_status_ %d", bvisibility, impl_->w_status_);
894 if (bvisibility && impl_->w_status_ != Impl::WS_RESUME) {
895 _D(" Go to Resume state");
896 impl_->w_status_ = Impl::WS_RESUME;
902 void AppCoreUiBase::OnAuxMessage(int type, void* event) {
903 auto* ev = reinterpret_cast<Ecore_Wl2_Event_Aux_Message*>(event);
904 if (ev->key && !strcmp(ev->key, "dpms_wm")) {
905 if (ev->val && !strcmp(ev->val, "on")) {
906 _D("Display state: on");
907 SetDisplayState(DISPLAY_STATE_ON);
908 } else if (ev->val && !strcmp(ev->val, "off")) {
909 _D("Display state: off");
910 SetDisplayState(DISPLAY_STATE_OFF);
912 _E("Unknown state: %s", ev->val);
917 void AppCoreUiBase::Pause() {
921 void AppCoreUiBase::Resume() {
925 bool AppCoreUiBase::IsResumed() {
926 return impl_->state_ == Impl::AS_RUNNING;
929 int AppCoreUiBase::GetHint() {
933 bool AppCoreUiBase::GetBgState() {
934 return impl_->bg_state_;
937 void AppCoreUiBase::SetBgState(bool bg_state) {
938 impl_->bg_state_ = bg_state;
941 void AppCoreUiBase::SetSystemResourceReclaiming(bool enable) {
942 impl_->resource_reclaiming_ = enable;
945 int AppCoreUiBase::GetWindowPosition(int* x, int* y, int* w, int* h) {
946 if (!impl_->position_ ||
953 *x = impl_->position_->GetPositionX();
954 *y = impl_->position_->GetPositionY();
955 *w = impl_->position_->GetScreenWidth();
956 *h = impl_->position_->GetScreenHeight();
961 } // namespace tizen_cpp