Revert "Separate rotation implementation from app-core-cpp" 38/306138/1
authorHwankyu Jhun <h.jhun@samsung.com>
Fri, 16 Feb 2024 08:25:10 +0000 (17:25 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Fri, 16 Feb 2024 08:25:13 +0000 (17:25 +0900)
This reverts commit 1821adaa196168935f3afe9f3853f88866d1ff6c.

Change-Id: Ide0876922ee21bc59ab8ac9a970331f8b9e5b93b

18 files changed:
CMakeLists.txt
packaging/app-core.spec
tizen-cpp/CMakeLists.txt
tizen-cpp/app-core-cpp/CMakeLists.txt
tizen-cpp/app-core-cpp/app_core_base.cc
tizen-cpp/app-core-cpp/app_core_base.hh
tizen-cpp/app-core-multi-window-cpp/CMakeLists.txt
tizen-cpp/app-core-multi-window-cpp/app_core_multi_window_base.cc
tizen-cpp/app-core-multi-window-cpp/app_core_multi_window_base.hh
tizen-cpp/app-core-rotation-cpp/CMakeLists.txt [deleted file]
tizen-cpp/app-core-rotation-cpp/app-core-rotation-cpp.pc.in [deleted file]
tizen-cpp/app-core-rotation-cpp/app_core_rotation.cc [deleted file]
tizen-cpp/app-core-rotation-cpp/app_core_rotation.hh [deleted file]
tizen-cpp/app-core-ui-cpp/CMakeLists.txt
tizen-cpp/app-core-ui-cpp/app_core_ui_base.cc
tizen-cpp/app-core-ui-cpp/app_core_ui_base.hh
unittests/CMakeLists.txt
unittests/app_core_base_test.cc

index c52b31b22bb1e5bd91f201d4288d0e65e15a3c2f..36b2ac03a7eba15bb4da4ddbfba4a3643cbbfccd 100644 (file)
@@ -17,7 +17,6 @@ SET(TARGET_APP_CORE_CPP "app-core-cpp")
 SET(TARGET_APP_CORE_UI_CPP "app-core-ui-cpp")
 SET(TARGET_APP_CORE_EFL_CPP "app-core-efl-cpp")
 SET(TARGET_APP_CORE_MULTI_WINDOW_CPP "app-core-multi-window-cpp")
-SET(TARGET_APP_CORE_ROTATION_CPP "app-core-rotation-cpp")
 
 SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -Wl,-zdefs -pie" )
 SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden")
index 5bdc2e9c0b53e33e68eada808ad23c6918df2c62..13e90d609e5cc4f1b284d2ff4e2c55b7d841a851 100644 (file)
@@ -261,7 +261,6 @@ install -m 0644 %{name}.zip %{buildroot}%{_datadir}/gcov/
 %{_libdir}/libappcore-common.so.*
 
 %{_libdir}/libapp-core-cpp.so.*
-%{_libdir}/libapp-core-rotation-cpp.so.*
 %license LICENSE
 
 %files common-devel
@@ -282,10 +281,6 @@ install -m 0644 %{name}.zip %{buildroot}%{_datadir}/gcov/
 %{_libdir}/libapp-core-cpp.so
 %{_libdir}/pkgconfig/app-core-cpp.pc
 
-%{_includedir}/appcore_cpp/app_core_rotation.hh
-%{_libdir}/libapp-core-rotation-cpp.so
-%{_libdir}/pkgconfig/app-core-rotation-cpp.pc
-
 %files ui
 %manifest %{name}.manifest
 %{_libdir}/libappcore-ui.so.*
index 569335c0b5baace32799b4d9898cb64ca31f32b7..0814703f71cefd0d3b9c4ee27c11d663cc0cafcb 100644 (file)
@@ -2,4 +2,3 @@ ADD_SUBDIRECTORY(app-core-efl-cpp)
 ADD_SUBDIRECTORY(app-core-multi-window-cpp)
 ADD_SUBDIRECTORY(app-core-cpp)
 ADD_SUBDIRECTORY(app-core-ui-cpp)
-ADD_SUBDIRECTORY(app-core-rotation-cpp)
index 0534880a6467f23c00f373059080c2ac89385658..6f427fb097a64ce86f8984e68161769d4dffb8d1 100644 (file)
@@ -18,6 +18,7 @@ APPLY_PKG_CONFIG(${TARGET_APP_CORE_CPP} PUBLIC
   BUNDLE_DEPS
   DLOG_DEPS
   GIO_2_DEPS
+  SENSOR_DEPS
   TTRACE_DEPS
   VCONF_DEPS
 )
index 021435e27ba4e73648122f47f02886ceab833a01..2e14d8ae5db246156bf45e986267cb1b663cbc0b 100644 (file)
@@ -29,6 +29,7 @@
 #include <linux/limits.h>
 #include <locale.h>
 #include <malloc.h>
+#include <sensor_internal.h>
 #include <signal.h>
 #include <stdbool.h>
 #include <sys/stat.h>
@@ -70,7 +71,16 @@ internal::SigtermHandler sigterm_handler;
 constexpr const char PATH_LOCALE[] = "locale";
 constexpr int SQLITE_FLUSH_MAX = 1024 * 1024;
 
-AppCoreBase::RotationState __rotation_state = AppCoreBase::ROTATION_UNKNOWN;
+struct Rotation {
+  int conn;
+  int lock;
+  int ref;
+  tizen_cpp::AppCoreBase::RotationState rm;
+  int charger_status;
+  bool initialized;
+};
+
+Rotation __rotation;
 AppCoreBase::DisplayState __display_state = AppCoreBase::DISPLAY_STATE_UNKNOWN;
 
 }  // namespace
@@ -88,6 +98,8 @@ class AppCoreBase::Impl : public SuspendEvent::IEventListener {
   explicit Impl(AppCoreBase* parent) : parent_(parent) {}
 
  private:
+  void UnregisterRotationChangedEvent();
+  void RegisterRotationChangedEvent();
   std::string GetAppName(const char* appid);
   std::string GetLocaleResourceDir();
   void UpdateLang();
@@ -122,9 +134,15 @@ class AppCoreBase::Impl : public SuspendEvent::IEventListener {
   static gboolean InvokeLangChangeCb(gpointer data);
   static void OnLowBatteryCb(keynode_t* key, void* data);
   static void OnTimeZoneChangedCb(keynode_t* key, void* data);
+  static void LockCb(keynode_t* node, void* user_data);
+  static void AutoRotationChangedCb(sensor_t sensor, unsigned int event_type,
+      sensor_data_t* data, void* user_data);
   static void LanguageChangeCb(keynode_t* key, void* data);
   static void RegionChangeCb(keynode_t* key, void* data);
   static void LowMemoryCb(keynode_t* key, void* data);
+  void InitRotation();
+  void FiniRotation();
+  RotationState GetRm(sensor_data_t data);
   void VerifyLanguage();
   void SetDefaultEvents();
   void UnsetDefaultEvents();
@@ -228,6 +246,27 @@ void AppCoreBase::Impl::OnFreezerSignal() {
   }
 }
 
+AppCoreBase::RotationState AppCoreBase::Impl::GetRm(sensor_data_t data) {
+  if (data.value_count <= 0) {
+    _E("Failed to get sensor data");
+    return ROTATION_UNKNOWN;
+  }
+
+  int event = data.values[0];
+  switch (event) {
+  case AUTO_ROTATION_DEGREE_0:
+    return ROTATION_PORTRAIT_NORMAL;
+  case AUTO_ROTATION_DEGREE_90:
+    return ROTATION_LANDSCAPE_NORMAL;
+  case AUTO_ROTATION_DEGREE_180:
+    return ROTATION_PORTRAIT_REVERSE;
+  case AUTO_ROTATION_DEGREE_270:
+    return ROTATION_LANDSCAPE_REVERSE;
+  default:
+    return ROTATION_UNKNOWN;
+  }
+}
+
 void AppCoreBase::Impl::InitSuspend() {
   suspend_event_.reset(new SuspendEvent(this));
 }
@@ -285,6 +324,113 @@ void AppCoreBase::Impl::LowMemoryCb(keynode_t* key, void* user_data) {
     malloc_trim(0);
 }
 
+void AppCoreBase::Impl::LockCb(keynode_t* node, void* user_data) {
+  AppCoreBase::RotationState rm;
+  AppCoreBase* base = reinterpret_cast<AppCoreBase*>(user_data);
+
+  __rotation.lock = !vconf_keynode_get_bool(node);
+  if (__rotation.lock) {
+    _D("Rotation locked");
+    rm = ROTATION_PORTRAIT_NORMAL;
+  } else {
+    _D("Rotation unlocked");
+    sensor_data_t data;
+    bool r = sensord_get_data(__rotation.conn, AUTO_ROTATION_SENSOR, &data);
+    if (!r) {
+      _E("Failed to get sensor data");
+      return;
+    }
+
+    rm = base->impl_->GetRm(data);
+    if (rm == ROTATION_UNKNOWN) {
+      _E("Unknown mode");
+      return;
+    }
+  }
+
+  if (__rotation.rm == rm)
+    return;
+
+  _D("Rotation: %d -> %d", __rotation.rm, rm);
+  __rotation.rm = rm;
+  base->impl_->InvokeCallback(__rotation.rm,
+      IEvent::Type::DEVICE_ORIENTATION_CHANGED);
+}
+
+void AppCoreBase::Impl::AutoRotationChangedCb(sensor_t sensor,
+    unsigned int event_type, sensor_data_t* data, void* user_data) {
+  if (data == nullptr)
+    return;
+
+  if (__rotation.lock)
+    return;
+
+  if (event_type != AUTO_ROTATION_CHANGE_STATE_EVENT)
+    return;
+
+  AppCoreBase* base = reinterpret_cast<AppCoreBase*>(user_data);
+  AppCoreBase::RotationState rm = base->impl_->GetRm(*data);
+  if (rm == ROTATION_UNKNOWN) {
+    _E("Unknown mode");
+    return;
+  }
+
+  _D("Rotation: %d -> %d", __rotation.rm, rm);
+  __rotation.rm = rm;
+  base->impl_->InvokeCallback(__rotation.rm,
+      IEvent::Type::DEVICE_ORIENTATION_CHANGED);
+}
+
+void AppCoreBase::Impl::InitRotation() {
+  if (__rotation.initialized)
+    return;
+
+  sensor_t sensor = sensord_get_sensor(AUTO_ROTATION_SENSOR);
+  __rotation.conn = sensord_connect(sensor);
+  if (__rotation.conn < 0) {
+    _E("Failed to connect sensord");
+    return;
+  }
+
+  bool r = sensord_register_event(__rotation.conn,
+      AUTO_ROTATION_CHANGE_STATE_EVENT, SENSOR_INTERVAL_NORMAL, 0,
+      AutoRotationChangedCb, parent_);
+  if (!r) {
+    _E("Failed to register auto rotation change event");
+    sensord_disconnect(__rotation.conn);
+    return;
+  }
+
+  r = sensord_start(__rotation.conn, 0);
+  if (!r) {
+    _E("Failed to start sensord");
+    sensord_unregister_event(__rotation.conn, AUTO_ROTATION_CHANGE_STATE_EVENT);
+    sensord_disconnect(__rotation.conn);
+    return;
+  }
+
+  int lock = 0;
+  vconf_get_bool(VCONFKEY_SETAPPL_AUTO_ROTATE_SCREEN_BOOL, &lock);
+  vconf_notify_key_changed(VCONFKEY_SETAPPL_AUTO_ROTATE_SCREEN_BOOL, LockCb,
+      parent_);
+
+  __rotation.lock = !lock;
+  __rotation.initialized = true;
+}
+
+void AppCoreBase::Impl::FiniRotation() {
+  if (!__rotation.initialized)
+    return;
+
+  vconf_ignore_key_changed(VCONFKEY_SETAPPL_AUTO_ROTATE_SCREEN_BOOL, LockCb);
+  sensord_unregister_event(__rotation.conn, AUTO_ROTATION_CHANGE_STATE_EVENT);
+  sensord_stop(__rotation.conn);
+  sensord_disconnect(__rotation.conn);
+
+  __rotation.lock = 0;
+  __rotation.initialized = false;
+}
+
 void AppCoreBase::Impl::VerifyLanguage() {
   const char* env_lang = getenv("LANG");
   if (env_lang == nullptr)
@@ -502,6 +648,20 @@ void AppCoreBase::Impl::OnTimeZoneChangedCb(keynode_t* key, void* data) {
   }
 }
 
+void AppCoreBase::Impl::UnregisterRotationChangedEvent() {
+  if (!__rotation.ref)
+    return;
+
+  __rotation.ref--;
+  if (__rotation.ref == 0) FiniRotation();
+}
+
+void AppCoreBase::Impl::RegisterRotationChangedEvent() {
+  if (__rotation.ref == 0) InitRotation();
+
+  __rotation.ref++;
+}
+
 int AppCoreBase::OnSetEvent(IEvent::Type event) {
   switch (event) {
   case IEvent::Type::LOW_BATTERY:
@@ -509,6 +669,7 @@ int AppCoreBase::OnSetEvent(IEvent::Type event) {
         impl_->OnLowBatteryCb, this);
     break;
   case IEvent::Type::DEVICE_ORIENTATION_CHANGED:
+    impl_->RegisterRotationChangedEvent();
     break;
   case IEvent::Type::SUSPENDED_STATE_CHANGE:
     break;
@@ -526,6 +687,7 @@ int AppCoreBase::OnUnsetEvent(IEvent::Type event) {
         impl_->OnLowBatteryCb);
     break;
   case IEvent::Type::DEVICE_ORIENTATION_CHANGED:
+    impl_->UnregisterRotationChangedEvent();
     break;
   case IEvent::Type::SUSPENDED_STATE_CHANGE:
     break;
@@ -597,11 +759,10 @@ void AppCoreBase::FlushMemory() {
 }
 
 AppCoreBase::RotationState AppCoreBase::GetRotationState() {
-  return __rotation_state;
-}
+  if (!__rotation.ref)
+    throw std::runtime_error("invalid rotation state");
 
-void AppCoreBase::SetRotationState(RotationState state) {
-  __rotation_state = state;
+  return __rotation.rm;
 }
 
 bool AppCoreBase::IsBgAllowed() {
index d8196a0f11589b7109cc21ab0e53917e4a279821..815c6ffb7cd0c6046a7eb93acc36e8b811390ccf 100644 (file)
@@ -105,7 +105,6 @@ class EXPORT_API AppCoreBase : public IAppCore, public IMainLoop {
   static int EnableWatchdog();
   static int DisableWatchdog();
   static int KickWatchdog();
-  static void SetRotationState(RotationState state);
 
  protected:
   void SetCoreDelegator(IAppCore* delegator);
index 65f02997ca4329afaf498529fcdb8fb08e2c14f3..3cf26f299668b46a47bf6f68a590ca1531993f7a 100644 (file)
@@ -13,7 +13,6 @@ TARGET_INCLUDE_DIRECTORIES(${TARGET_APP_CORE_MULTI_WINDOW_CPP} PUBLIC
 
 TARGET_LINK_LIBRARIES(${TARGET_APP_CORE_MULTI_WINDOW_CPP} PUBLIC
   ${TARGET_APP_CORE_CPP}
-  ${TARGET_APP_CORE_ROTATION_CPP}
   "-L${LIB_INSTALL_DIR}/hal")
 
 SET_TARGET_PROPERTIES(${TARGET_APP_CORE_MULTI_WINDOW_CPP}
index f69eca03f17d5fb134846526b24a7ebc80d03622..86261da76b38c15831f89a9e83e1a7d9f88fcca9 100644 (file)
  * limitations under the License.
  */
 
-#include "app-core-multi-window-cpp/app_core_multi_window_base.hh"
-
 #include <list>
 #include <map>
 #include <stdexcept>
 #include <string>
-#include <utility>
 
-#include "app-core-rotation-cpp/app_core_rotation.hh"
+#include "app-core-multi-window-cpp/app_core_multi_window_base.hh"
 #include "common/ecore_handler.hh"
 #include "common/log_private.hh"
 
@@ -42,24 +39,13 @@ class AppCoreMultiWindowBase::Context::Impl {
   AppCoreMultiWindowBase* app_;
 };
 
-class AppCoreMultiWindowBase::Impl : public AppCoreRotation::IEventListener {
- public:
-  explicit Impl(AppCoreMultiWindowBase* parent) : parent_(parent) {}
-
- private:
-  void RotationInit();
-  void RotationShutdown();
-  void OnRotationChanged(int degree) override;
-
+class AppCoreMultiWindowBase::Impl {
  private:
   friend class AppCoreMultiWindowBase;
-  AppCoreMultiWindowBase* parent_;
-
   std::shared_ptr<EcoreHandler> handler_;
   std::map<std::string, std::shared_ptr<Context::IFactory>> factory_map_;
   std::list<std::shared_ptr<Context>> contexts_;
   std::unique_ptr<EcoreHandler::ITrim> trim_;
-  std::unique_ptr<AppCoreRotation> rotation_;
 };
 
 AppCoreMultiWindowBase::Context::Context(std::string context_id,
@@ -129,7 +115,7 @@ AppCoreMultiWindowBase* AppCoreMultiWindowBase::Context::GetApp() {
 }
 
 AppCoreMultiWindowBase::AppCoreMultiWindowBase() :
-    impl_(std::make_unique<Impl>(this)) {}
+    impl_(std::make_unique<Impl>()) {}
 
 AppCoreMultiWindowBase::~AppCoreMultiWindowBase() = default;
 
@@ -320,36 +306,4 @@ AppCoreMultiWindowBase::GetContextFactory(const std::string& context_id) {
   return impl_->factory_map_[context_id];
 }
 
-void AppCoreMultiWindowBase::Impl::RotationInit() {
-  if (!rotation_) rotation_.reset(new AppCoreRotation(this));
-
-  rotation_->Init();
-}
-
-void AppCoreMultiWindowBase::Impl::RotationShutdown() {
-  if (rotation_) rotation_->Dispose();
-}
-
-void AppCoreMultiWindowBase::Impl::OnRotationChanged(int degree) {
-  AppCoreBase::SetRotationState(
-      static_cast<AppCoreBase::RotationState>(degree));
-  parent_->RaiseEvent(degree, IEvent::Type::DEVICE_ORIENTATION_CHANGED);
-}
-
-int AppCoreMultiWindowBase::OnSetEvent(IEvent::Type event) {
-  AppCoreBase::OnSetEvent(event);
-  if (event == IEvent::Type::DEVICE_ORIENTATION_CHANGED)
-    impl_->RotationInit();
-
-  return 0;
-}
-
-int AppCoreMultiWindowBase::OnUnsetEvent(IEvent::Type event) {
-  AppCoreBase::OnUnsetEvent(event);
-  if (event == IEvent::Type::DEVICE_ORIENTATION_CHANGED)
-    impl_->RotationShutdown();
-
-  return 0;
-}
-
 }  // namespace tizen_cpp
index 8a502df789346c938c3a2d8f883f878ce41b432e..d308f0b78978a35accf9ffdbe4d8c49459d34a93 100644 (file)
@@ -94,8 +94,6 @@ class EXPORT_API AppCoreMultiWindowBase : public AppCoreBase, public IWindow {
   std::shared_ptr<Context::IFactory> GetContextFactory(
       const std::string& context_id);
   void Dispose() override;
-  int OnSetEvent(IEvent::Type event) override;
-  int OnUnsetEvent(IEvent::Type event) override;
 
  private:
   class Impl;
@@ -104,4 +102,4 @@ class EXPORT_API AppCoreMultiWindowBase : public AppCoreBase, public IWindow {
 
 }  // namespace tizen_cpp
 
-#endif  // TIZEN_CPP_APP_CORE_MULTI_WINDOW_CPP_APP_CORE_MULTI_WINDOW_BASE_HH_
+#endif  // TIZEN_CPP_APP_CORE_MULTI_WINDOW_CPP__APP_CORE_MULTI_WINDOW_BASE_HH_
diff --git a/tizen-cpp/app-core-rotation-cpp/CMakeLists.txt b/tizen-cpp/app-core-rotation-cpp/CMakeLists.txt
deleted file mode 100644 (file)
index de705a7..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} APP_CORE_ROTATION_CPP_SRCS)
-
-ADD_LIBRARY(${TARGET_APP_CORE_ROTATION_CPP} SHARED
-  ${APP_CORE_ROTATION_CPP_SRCS})
-
-TARGET_INCLUDE_DIRECTORIES(${TARGET_APP_CORE_ROTATION_CPP} PUBLIC
-  ${CMAKE_CURRENT_SOURCE_DIR}
-  ${CMAKE_CURRENT_SOURCE_DIR}/../)
-
-TARGET_LINK_LIBRARIES(${TARGET_APP_CORE_ROTATION_CPP} PUBLIC
-  "-L${LIB_INSTALL_DIR}/hal")
-
-SET_TARGET_PROPERTIES(${TARGET_APP_CORE_ROTATION_CPP}
-  PROPERTIES SOVERSION ${MAJORVER})
-SET_TARGET_PROPERTIES(${TARGET_APP_CORE_ROTATION_CPP}
-  PROPERTIES VERSION ${FULLVER})
-
-APPLY_PKG_CONFIG(${TARGET_APP_CORE_ROTATION_CPP} PUBLIC
-  DLOG_DEPS
-  SENSOR_DEPS
-  VCONF_DEPS
-)
-
-CONFIGURE_FILE(${TARGET_APP_CORE_ROTATION_CPP}.pc.in
-  ${TARGET_APP_CORE_ROTATION_CPP}.pc @ONLY)
-INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/${TARGET_APP_CORE_ROTATION_CPP}.pc
-  DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
-
-INSTALL(TARGETS ${TARGET_APP_CORE_ROTATION_CPP} DESTINATION ${LIB_INSTALL_DIR})
-INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/ DESTINATION include/appcore_cpp
-  FILES_MATCHING
-  PATTERN "*_private.hh" EXCLUDE
-  PATTERN "*.hh")
diff --git a/tizen-cpp/app-core-rotation-cpp/app-core-rotation-cpp.pc.in b/tizen-cpp/app-core-rotation-cpp/app-core-rotation-cpp.pc.in
deleted file mode 100644 (file)
index 48c7bd5..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-# Package Information for pkg-config
-
-prefix=@PREFIX@
-exec_prefix=@EXEC_PREFIX@
-libdir=@LIB_INSTALL_DIR@
-includedir=@INCLUDEDIR@
-
-Name: app-core-rotation-cpp
-Description: Tizen application core library for rotation event
-Version: @VERSION@
-Requires.private: dlog sensor vconf
-Libs: -L${libdir} -lapp-core-rotation-cpp
-Cflags: -I${includedir} -I${includedir}/appcore_cpp
-cppflags: I${includedir} -I${includedir}/appcore_cpp
diff --git a/tizen-cpp/app-core-rotation-cpp/app_core_rotation.cc b/tizen-cpp/app-core-rotation-cpp/app_core_rotation.cc
deleted file mode 100644 (file)
index c6b08ba..0000000
+++ /dev/null
@@ -1,131 +0,0 @@
-/*
- * Copyright (c) 2024 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "app-core-rotation-cpp/app_core_rotation.hh"
-
-#include "common/log_private.hh"
-
-namespace tizen_cpp {
-
-AppCoreRotation::AppCoreRotation(IEventListener* listener)
-    : listener_(listener) {}
-
-AppCoreRotation::~AppCoreRotation() { Dispose(); }
-
-bool AppCoreRotation::Init() {
-  if (!disposed_) {
-    ref_++;
-    return true;
-  }
-
-  sensor_t sensor = sensord_get_sensor(AUTO_ROTATION_SENSOR);
-  conn_ = sensord_connect(sensor);
-  if (conn_ < 0) {
-    _E("sensord_connect() is failed");
-    return false;
-  }
-
-  if (!sensord_register_event(conn_, AUTO_ROTATION_CHANGE_STATE_EVENT,
-                              SENSOR_INTERVAL_NORMAL, 0, SensorEventCb, this)) {
-    _E("sensord_register_event() is failed");
-    sensord_disconnect(conn_);
-    conn_ = 0;
-    return false;
-  }
-
-  if (!sensord_start(conn_, 0)) {
-    _E("sensord_start() is failed");
-    sensord_unregister_event(conn_, AUTO_ROTATION_CHANGE_STATE_EVENT);
-    sensord_disconnect(conn_);
-    conn_ = 0;
-    return false;
-  }
-
-  int lock = 0;
-  vconf_get_bool(VCONFKEY_SETAPPL_AUTO_ROTATE_SCREEN_BOOL, &lock);
-  vconf_notify_key_changed(VCONFKEY_SETAPPL_AUTO_ROTATE_SCREEN_BOOL, VconfCb,
-                           this);
-
-  lock_ = !lock;
-  ref_++;
-  disposed_ = false;
-  return true;
-}
-
-void AppCoreRotation::Dispose() {
-  if (disposed_) return;
-
-  ref_--;
-  if (ref_ > 0) return;
-
-  vconf_ignore_key_changed(VCONFKEY_SETAPPL_AUTO_ROTATE_SCREEN_BOOL, VconfCb);
-  sensord_unregister_event(conn_, AUTO_ROTATION_CHANGE_STATE_EVENT);
-  sensord_stop(conn_);
-  sensord_disconnect(conn_);
-  conn_ = 0;
-  lock_ = 0;
-  disposed_ = true;
-}
-
-bool AppCoreRotation::IsLocked() const { return lock_; }
-
-int AppCoreRotation::GetDegree() const { return degree_; }
-
-void AppCoreRotation::SensorEventCb(sensor_t sensor, unsigned int event_type,
-                                    sensor_data_t* data, void* user_data) {
-  if (event_type != AUTO_ROTATION_CHANGE_STATE_EVENT) return;
-
-  auto self = static_cast<AppCoreRotation*>(user_data);
-  if (self->IsLocked()) return;
-
-  int degree = static_cast<int>(data->values[0]);
-  if (degree == static_cast<int>(AUTO_ROTATION_DEGREE_UNKNOWN)) return;
-
-  if (self->degree_ == degree) return;
-
-  _D("Rotation: %d -> %d", self->degree_, degree);
-  self->degree_ = degree;
-  self->listener_->OnRotationChanged(degree);
-}
-
-void AppCoreRotation::VconfCb(keynode_t* node, void* user_data) {
-  int degree;
-  auto self = static_cast<AppCoreRotation*>(user_data);
-  self->lock_ = !vconf_keynode_get_bool(node);
-  if (self->lock_) {
-    _D("Rotation locked");
-    degree = 0;
-  } else {
-    _D("Rotation unlocked");
-    sensor_data_t data;
-    if (!sensord_get_data(self->conn_, AUTO_ROTATION_CHANGE_STATE_EVENT,
-                          &data)) {
-      _E("sensord_get_data() is failed");
-      return;
-    }
-
-    degree = static_cast<int>(data.values[0]);
-    if (degree == static_cast<int>(AUTO_ROTATION_DEGREE_UNKNOWN)) return;
-  }
-
-  if (self->degree_ == degree) return;
-
-  _D("Rotation: %d -> %d", self->degree_, degree);
-  self->degree_ = degree;
-  self->listener_->OnRotationChanged(degree);
-}
-
-}  // namespace tizen_cpp
diff --git a/tizen-cpp/app-core-rotation-cpp/app_core_rotation.hh b/tizen-cpp/app-core-rotation-cpp/app_core_rotation.hh
deleted file mode 100644 (file)
index 4798436..0000000
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * Copyright (c) 2024 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef TIZEN_CPP_APP_CORE_ROTATION_CPP_APP_CORE_ROTATION_HH_
-#define TIZEN_CPP_APP_CORE_ROTATION_CPP_APP_CORE_ROTATION_HH_
-
-#include <sensor_internal.h>
-#include <vconf.h>
-
-#undef EXPORT_API
-#define EXPORT_API __attribute__((visibility("default")))
-
-namespace tizen_cpp {
-
-class EXPORT_API AppCoreRotation {
- public:
-  class IEventListener {
-   public:
-    virtual ~IEventListener() = default;
-    virtual void OnRotationChanged(int degree) = 0;
-  };
-
-  explicit AppCoreRotation(IEventListener* listener);
-  ~AppCoreRotation();
-
-  bool Init();
-  void Dispose();
-
-  bool IsLocked() const;
-  int GetDegree() const;
-
- private:
-  static void SensorEventCb(sensor_t sensor, unsigned int event_type,
-                            sensor_data_t* data, void* user_data);
-  static void VconfCb(keynode_t* node, void* user_data);
-
- private:
-  bool disposed_ = true;
-  IEventListener* listener_;
-  int conn_ = 0;
-  int lock_ = 0;
-  uint32_t ref_ = 0;
-  int degree_ = 0;
-};
-
-}  // namespace tizen_cpp
-
-#endif  // TIZEN_CPP_APP_CORE_ROTATION_CPP_APP_CORE_ROTATION_HH_
index 2e5fa178b7b4efe4f322fd57ba4b56ef9cd4de42..6c52af898b5deb41a854d75212e6548ba21762c9 100644 (file)
@@ -14,7 +14,6 @@ TARGET_INCLUDE_DIRECTORIES(${TARGET_APP_CORE_UI_CPP} PUBLIC
 
 TARGET_LINK_LIBRARIES(${TARGET_APP_CORE_UI_CPP} PUBLIC
   ${TARGET_APP_CORE_CPP}
-  ${TARGET_APP_CORE_ROTATION_CPP}
   "-L${LIB_INSTALL_DIR}/hal")
 
 SET_TARGET_PROPERTIES(${TARGET_APP_CORE_UI_CPP}
index beeef295c50b54b3ac62995abdac90f67aafc490..2eeb488de259e9b7c0ce34539210c40a3cd6d508 100644 (file)
@@ -35,7 +35,6 @@
 #include <utility>
 
 #include "app-core-cpp/app_core_base.hh"
-#include "app-core-rotation-cpp/app_core_rotation.hh"
 #include "app-core-ui-cpp/api/app_core_ui_base.h"
 #include "app-core-ui-cpp/app_core_task_base.hh"
 #include "app-core-ui-cpp/app_core_ui_delegator_private.hh"
@@ -55,7 +54,7 @@ constexpr const char K_HINT_RECENT_SCREEN_POSITION[] =
     "__K_HINT_RECENT_SCREEN_POSITION";
 const int APPID_MAX = 256;
 
-class AppCoreUiBase::Impl : public AppCoreRotation::IEventListener {
+class AppCoreUiBase::Impl {
  public:
   Impl(AppCoreUiBase* parent, unsigned int hint)
       : parent_(parent),
@@ -123,9 +122,6 @@ class AppCoreUiBase::Impl : public AppCoreRotation::IEventListener {
   Ecore_Wl2_Window* GetWindow() const;
   void Run(int argc, char** argv);
   void Exit();
-  void RotationInit();
-  void RotationShutdown();
-  void OnRotationChanged(int degree) override;
 
   std::list<std::shared_ptr<WinNode>> winnode_list_;
   unsigned int hint_;
@@ -146,7 +142,6 @@ class AppCoreUiBase::Impl : public AppCoreRotation::IEventListener {
   Ecore_Wl2_Window* window_ = nullptr;
   std::unique_ptr<WindowPositionManager> wp_manager_;
   std::unique_ptr<AppCoreUiThreadBase> thread_;
-  std::unique_ptr<AppCoreRotation> rotation_;
 };
 
 AppCoreUiBase::AppCoreUiBase(unsigned int hint)
@@ -549,22 +544,6 @@ void AppCoreUiBase::Impl::Exit() {
   parent_->DoExit();
 }
 
-void AppCoreUiBase::Impl::RotationInit() {
-  if (!rotation_) rotation_.reset(new AppCoreRotation(this));
-
-  rotation_->Init();
-}
-
-void AppCoreUiBase::Impl::RotationShutdown() {
-  if (rotation_) rotation_->Dispose();
-}
-
-void AppCoreUiBase::Impl::OnRotationChanged(int degree) {
-  AppCoreBase::SetRotationState(
-      static_cast<AppCoreBase::RotationState>(degree));
-  parent_->RaiseEvent(degree, IEvent::Type::DEVICE_ORIENTATION_CHANGED);
-}
-
 void AppCoreUiBase::Run(int argc, char** argv) {
   impl_->Run(argc, argv);
 }
@@ -1001,22 +980,4 @@ int AppCoreUiBase::GetWindowPosition(int* x, int* y, int* w, int* h) {
   return 0;
 }
 
-int AppCoreUiBase::OnSetEvent(IEvent::Type event) {
-  AppCoreBase::OnSetEvent(event);
-
-  if (event == IEvent::Type::DEVICE_ORIENTATION_CHANGED)
-    impl_->RotationInit();
-
-  return 0;
-}
-
-int AppCoreUiBase::OnUnsetEvent(IEvent::Type event) {
-  AppCoreBase::OnUnsetEvent(event);
-
-  if (event == IEvent::Type::DEVICE_ORIENTATION_CHANGED)
-    impl_->RotationShutdown();
-
-  return 0;
-}
-
 }  // namespace tizen_cpp
index a7f0ec3057937b61dc5717f7dfe31c9f2fa7974d..0c4acac6353f4ef3aab46704afefaed4858f1ec0 100644 (file)
@@ -74,8 +74,6 @@ class EXPORT_API AppCoreUiBase : public AppCoreBase,
   virtual std::unique_ptr<AppCoreTaskBase> CreateTask();
   void Exit() override;
   int GetWindowPosition(int* x, int* y, int* w, int* h);
-  int OnSetEvent(IEvent::Type event) override;
-  int OnUnsetEvent(IEvent::Type event) override;
 
  protected:
   void SetCoreUiDelegator(IAppCoreUi* delegator);
index fa272bf5892047ba2a4fbac24c15e9c379c50537..2e79bc9c4d2cd8222d8f87e3745bb7de3dd1bc9d 100644 (file)
@@ -2,8 +2,6 @@ SET(TARGET_UNIT_TEST "app-core_unittests")
 
 AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/../tizen-cpp/app-core-cpp
   LIB_APP_CORE_CPP_SRCS)
-AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/../tizen-cpp/app-core-rotation-cpp
-  LIB_APP_CORE_ROTATION_CPP_SRCS)
 AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/../tizen-cpp/app-core-ui-cpp
   LIB_APP_CORE_UI_CPP_SRCS)
 AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/../tizen-cpp/app-core-ui-cpp/api
@@ -21,7 +19,6 @@ ADD_EXECUTABLE(${TARGET_UNIT_TEST}
   ${MOCK_SRCS}
   ${TEST_SRCS}
   ${LIB_APP_CORE_CPP_SRCS}
-  ${LIB_APP_CORE_ROTATION_CPP_SRCS}
   ${LIB_APP_CORE_UI_CPP_SRCS}
   ${LIB_APP_CORE_UI_CPP_API_SRCS}
   ${LIB_APP_CORE_EFL_CPP_SRCS}
index 698daa3c8c23d8cb564c1c3b65e3386829195750..08c749d2816fc535b20f9ba0adfbc24a36126637 100644 (file)
  * limitations under the License.
  */
 
-#include <bundle_cpp.h>
-#include <bundle_internal.h>
-#include <glib.h>
 #include <gmock/gmock.h>
 #include <stdio.h>
+#include <glib.h>
+#include <bundle_cpp.h>
+#include <bundle_internal.h>
 
-#include <functional>
-
-#include "mock/app_core_base_mock.h"
+#include "mock/test_fixture.h"
 #include "mock/aul_mock.h"
-#include "mock/dbus_mock.h"
-#include "mock/dl_mock.h"
 #include "mock/sensor_mock.h"
-#include "mock/test_fixture.h"
 #include "mock/vconf_mock.h"
+#include "mock/dbus_mock.h"
+#include "mock/dl_mock.h"
+#include "mock/app_core_base_mock.h"
+
+#include <functional>
 
 using ::testing::_;
 using ::testing::DoAll;
@@ -104,7 +104,7 @@ class DummyArgs {
 
 class TestEvent : public AppCoreBase::EventBase {
  public:
-  explicit TestEvent(Type type) : EventBase(type) {}
+  TestEvent(Type type) : EventBase(type) {}
 
   void OnEvent(const std::string& val) override {
     SetVal(val);
@@ -268,12 +268,11 @@ TEST_F(AppCoreBaseTest, AppCoreBase_AllowBG) {
   EXPECT_CALL(core, OnTerminate())
       .Times(1);
   EXPECT_CALL(core, OnReceive(_, _))
-      .WillOnce(
-          Invoke([&core, &bg](aul_type type, tizen_base::Bundle b) -> int {
-            int ret = core.AppCoreBase::OnReceive(type, std::move(b));
-            bg = core.IsBgAllowed();
-            return ret;
-          }));
+      .WillOnce(Invoke([&core, &bg](aul_type type, tizen_base::Bundle b) -> int {
+        int ret = core.AppCoreBase::OnReceive(type, std::move(b));
+        bg = core.IsBgAllowed();
+        return ret;
+      }));
 
   DummyArgs da(AUL_K_ALLOWED_BG, "ALLOWED_BG");
   core.SetFeature(AppCoreBase::FEATURE_BACKGROUND_MANAGEMENT);
@@ -316,6 +315,112 @@ TEST_F(AppCoreBaseTest, AppCoreBase_FlushMemory) {
   core.Run(da.GetArgc(), da.GetArgv());
 }
 
+TEST_F(AppCoreBaseTest, AppCoreBase_GetRotationState_N) {
+  bool result = false;
+
+  try {
+    AppCoreBase::GetRotationState();
+  } catch (const std::runtime_error& e) {
+    EXPECT_STREQ(e.what(), "invalid rotation state");
+    result = true;
+  }
+
+  EXPECT_TRUE(result);
+}
+
+TEST_F(AppCoreBaseTest, AppCoreBase_GetRotationState) {
+  testing::NiceMock<AppCoreBaseMock> core;
+  AppCoreBase::RotationState rst = AppCoreBase::ROTATION_UNKNOWN;
+
+  EXPECT_CALL(core, OnCreate())
+      .WillOnce(Invoke([&core, &rst]() -> int {
+        core.AppCoreBase::OnCreate();
+        rst = AppCoreBase::GetRotationState();
+        g_idle_add_full(G_PRIORITY_LOW, [](gpointer data) -> gboolean {
+          auto* obj = static_cast<testing::NiceMock<AppCoreBaseMock>*>(data);
+          obj->Exit();
+          return G_SOURCE_REMOVE;
+        }, &core, nullptr);
+        return 0;
+      }));
+  EXPECT_CALL(core, OnTerminate())
+      .Times(1);
+  EXPECT_CALL(GetMock<SensorMock>(), sensord_register_event(_, _, _, _, _, _))
+      .WillOnce(Invoke([](int handle, unsigned int event_type,
+          unsigned int interval, unsigned int max_batch_latency,
+          sensor_cb_t cb, void *user_data) -> bool {
+          sensor_t sensor = { 0, };
+          sensor_data_t data = { 0, };
+          data.value_count = 1;
+          data.values[0] = AUTO_ROTATION_DEGREE_0;
+          cb(sensor, AUTO_ROTATION_CHANGE_STATE_EVENT, &data, user_data);
+        return true;
+      }));
+
+  DummyArgs da;
+  auto ev = std::shared_ptr<AppCoreBase::EventBase>(
+      new TestEvent(IAppCore::IEvent::Type::DEVICE_ORIENTATION_CHANGED));
+  core.AddEvent(ev);
+  core.Run(da.GetArgc(), da.GetArgv());
+  EXPECT_EQ(rst, AppCoreBase::ROTATION_PORTRAIT_NORMAL);
+  core.RemoveEvent(ev);
+}
+
+TEST_F(AppCoreBaseTest, AppCoreBase_LockCb) {
+  testing::NiceMock<AppCoreBaseMock> core;
+  AppCoreBase::RotationState rst = AppCoreBase::ROTATION_UNKNOWN;
+
+  EXPECT_CALL(core, OnCreate())
+      .WillOnce(Invoke([&core, &rst]() -> int {
+        core.AppCoreBase::OnCreate();
+        GetMock<VConfMock>().ChangeBool(VCONFKEY_SETAPPL_AUTO_ROTATE_SCREEN_BOOL, true);
+        rst = AppCoreBase::GetRotationState();
+        g_idle_add_full(G_PRIORITY_LOW, [](gpointer data) -> gboolean {
+          auto* obj = static_cast<testing::NiceMock<AppCoreBaseMock>*>(data);
+          obj->Exit();
+          return G_SOURCE_REMOVE;
+        }, &core, nullptr);
+        return 0;
+      }));
+  EXPECT_CALL(core, OnTerminate())
+      .Times(1);
+
+  DummyArgs da;
+  auto ev = std::shared_ptr<AppCoreBase::EventBase>(
+      new TestEvent(IAppCore::IEvent::Type::DEVICE_ORIENTATION_CHANGED));
+  core.AddEvent(ev);
+  core.Run(da.GetArgc(), da.GetArgv());
+  EXPECT_EQ(rst, AppCoreBase::ROTATION_PORTRAIT_NORMAL);
+  core.RemoveEvent(ev);
+}
+
+TEST_F(AppCoreBaseTest, AppCoreBase_ChargerStatusChangedCb) {
+  testing::NiceMock<AppCoreBaseMock> core;
+
+  EXPECT_CALL(core, OnCreate())
+      .WillOnce(Invoke([&]() -> int {
+        core.AppCoreBase::OnCreate();
+        GetMock<VConfMock>().ChangeInt(VCONFKEY_SYSMAN_CHARGER_STATUS, 0);
+        GetMock<VConfMock>().ChangeInt(VCONFKEY_SYSMAN_CHARGER_STATUS, 1);
+        g_idle_add_full(G_PRIORITY_LOW, [](gpointer data) -> gboolean {
+          auto* obj = static_cast<testing::NiceMock<AppCoreBaseMock>*>(data);
+          obj->Exit();
+          return G_SOURCE_REMOVE;
+        }, &core, nullptr);
+        return 0;
+      }));
+  EXPECT_CALL(core, OnTerminate())
+      .Times(1);
+
+  DummyArgs da;
+  auto ev = std::shared_ptr<AppCoreBase::EventBase>(
+      new TestEvent(IAppCore::IEvent::Type::DEVICE_ORIENTATION_CHANGED));
+  core.SetFeature(AppCoreBase::FEATURE_CHARGER_STATUS);
+  core.AddEvent(ev);
+  core.Run(da.GetArgc(), da.GetArgv());
+  core.RemoveEvent(ev);
+}
+
 TEST_F(AppCoreBaseTest, AppCoreBase_AddEvent_LanguageChanged) {
   testing::NiceMock<AppCoreBaseMock> core;
 
@@ -680,4 +785,4 @@ TEST_F(AppCoreBaseTest, AppCoreBase_RotationState) {
   EXPECT_EQ(AppCoreBase::GetDisplayState(), AppCoreBase::DISPLAY_STATE_UNKNOWN);
 }
 
-}  // namespace tizen_cpp
+} // namespace tizen_cpp