Support ambient block tick state 89/234389/4
authorhyunho <hhstark.kang@samsung.com>
Tue, 26 May 2020 04:35:14 +0000 (13:35 +0900)
committerhyunho <hhstark.kang@samsung.com>
Wed, 27 May 2020 02:07:35 +0000 (11:07 +0900)
Change-Id: I9d63b8034ae7fcc6ed979faf4d8e64bf2e9f20a0
Signed-off-by: hyunho <hhstark.kang@samsung.com>
ambient-viewer/include/ambient_viewer.h
ambient-viewer/src/ambient-viewer.cc
ambient-viewer/src/ambient-viewer.hh
ambient-viewer/src/stub.cc
unittest/src/test_ambient_viewer.cc
unittest/src/test_ambient_viewer_stub.cc
watch-holder/src/ambient_listener.cc
watch-holder/src/ambient_listener.hh

index b2f3bf1..1ca031c 100644 (file)
@@ -53,6 +53,12 @@ typedef enum {
        AMBIENT_VIEWER_DIRECTION_ALL, /**<All */
 } ambient_viewer_direction_e;
 
+typedef enum {
+       AMBIENT_VIEWER_AMBIENT_STATE_LEAVE, /**<AMBIENT LEAVE */
+       AMBIENT_VIEWER_AMBIENT_STATE_ENTER, /**<AMBIENT ENTER */
+       AMBIENT_VIEWER_AMBIENT_STATE_BLOCK_TICK, /**<AMBIENT BLOCK TICK */
+} ambient_viewer_state_e;
+
 /**
  * @brief The callback function for lifecycle added.
  * @remarks This function only for internal applications.
@@ -136,7 +142,7 @@ int ambient_viewer_block_update(ambient_viewer_h handle, bool enable);
  * @brief Notifies the ambient event.
  * @remarks This function only for internal applications.
  * @param[in] handle The ambient viewer handle
- * @param[in] enter Whether to enter ambient mode
+ * @param[in] state Ambient state
  * @param[in] dir Direction to notify
  * @param[in] extra The bundle handle
  * @return #AMBIENT_VIEWER_ERROR_NONE On success, other value on failure
@@ -144,7 +150,7 @@ int ambient_viewer_block_update(ambient_viewer_h handle, bool enable);
  * @retval #AMBIENT_VIEWER_ERROR_INVALID_PARAMETER Invalid parameter
  * @see #ambient_viewer_direction_e
  */
-int ambient_viewer_notify_ambient_event(ambient_viewer_h handle, bool enter,
+int ambient_viewer_notify_ambient_event(ambient_viewer_h handle, ambient_viewer_state_e state,
                        ambient_viewer_direction_e dir, bundle *extra);
 
 /**
index 60dd2ea..92918eb 100644 (file)
@@ -166,7 +166,7 @@ void AmbientViewer::OnReceived(AmbientViewer::EventType ev, std::string sender,
     Bundle extra) {
 }
 
-int AmbientViewer::NotifyAmbientEvent(bool enter, AmbientViewer::Direction dir,
+int AmbientViewer::NotifyAmbientEvent(AmbientState state, AmbientViewer::Direction dir,
     Bundle extra) {
   bundle* b;
   bundle* extra_data;
@@ -182,7 +182,7 @@ int AmbientViewer::NotifyAmbientEvent(bool enter, AmbientViewer::Direction dir,
 
   extra_data = extra.GetHandle();
 
-  snprintf(ambient_mode, sizeof(ambient_mode), "%d", (int)enter);
+  snprintf(ambient_mode, sizeof(ambient_mode), "%d", (int)state);
   bundle_add_str(b, "__AMBIENT_MODE__", ambient_mode);
 
   bundle_encode(extra_data, &raw, &len);
index a9f2d58..da12006 100644 (file)
@@ -45,6 +45,12 @@ class EXPORT_API AmbientViewer : public IAmbientViewer {
     EVENT_WATCH_CHANGED,
   };
 
+  enum AmbientState {
+    AMBIENT_LEAVE,
+    AMBIENT_ENTER,
+    AMBIENT_BLOCK_TICK,
+  };
+
   enum Direction {
     DIRECTION_VIEWER_AND_WATCH,
     DIRECTION_VIEWER_AND_TOP_APP,
@@ -57,7 +63,7 @@ class EXPORT_API AmbientViewer : public IAmbientViewer {
   void Monitor(bool full = false);
   void Unmonitor();
   virtual void OnReceived(EventType ev, std::string sender, tizen_base::Bundle extra) = 0;
-  int NotifyAmbientEvent(bool enter, Direction dir, tizen_base::Bundle extra);
+  int NotifyAmbientEvent(AmbientState state, Direction dir, tizen_base::Bundle extra);
   const ISurface& GetWatchSurface() const;
   const ISurface& GetTopAppSurface() const;
   void BlockUpdate(bool enable);
index d8eb136..8ef3226 100644 (file)
@@ -179,7 +179,7 @@ extern "C" EXPORT_API int ambient_viewer_destroy(ambient_viewer_h handle) {
 }
 
 extern "C" EXPORT_API int ambient_viewer_notify_ambient_event(
-    ambient_viewer_h handle, bool enter,
+    ambient_viewer_h handle, ambient_viewer_state_e state,
     ambient_viewer_direction_e dir, bundle *extra) {
   if (handle == nullptr) {
     LOGE("Invalid parameter");
@@ -187,8 +187,8 @@ extern "C" EXPORT_API int ambient_viewer_notify_ambient_event(
   }
 
   AmbientViewerStub* stub = static_cast<AmbientViewerStub*>(handle);
-  stub->NotifyAmbientEvent(enter, static_cast<AmbientViewer::Direction>(dir),
-    Bundle(extra, false, false));
+  stub->NotifyAmbientEvent((AmbientViewer::AmbientState)state,
+    static_cast<AmbientViewer::Direction>(dir), Bundle(extra, false, false));
 
   return AMBIENT_VIEWER_ERROR_NONE;
 }
index f184477..c5de1cc 100644 (file)
@@ -253,19 +253,19 @@ TEST_F(AmbientViewerTest, create) {
 
 TEST_F(AmbientViewerTest, NotifyAmbientEvent) {
   Bundle b;
-  EXPECT_EQ(AmbientViewerTest::stub->NotifyAmbientEvent(true,
+  EXPECT_EQ(AmbientViewerTest::stub->NotifyAmbientEvent(AmbientViewer::AMBIENT_ENTER,
     AmbientViewer::DIRECTION_ALL, b), 0);
 }
 
 TEST_F(AmbientViewerTest, NotifyAmbientEvent2) {
   Bundle b;
-  EXPECT_EQ(AmbientViewerTest::stub->NotifyAmbientEvent(true,
+  EXPECT_EQ(AmbientViewerTest::stub->NotifyAmbientEvent(AmbientViewer::AMBIENT_ENTER,
     AmbientViewer::DIRECTION_VIEWER_AND_WATCH, b), 0);
 }
 
 TEST_F(AmbientViewerTest, NotifyAmbientEvent3) {
   Bundle b;
-  EXPECT_EQ(AmbientViewerTest::stub->NotifyAmbientEvent(true,
+  EXPECT_EQ(AmbientViewerTest::stub->NotifyAmbientEvent(AmbientViewer::AMBIENT_ENTER,
     AmbientViewer::DIRECTION_VIEWER_AND_TOP_APP, b), 0);
 }
 
index f93e6fa..8e1bff7 100644 (file)
@@ -69,7 +69,7 @@ TEST_F(AmbientViewerStubTest, ambient_viewer_destroy) {
 }
 
 TEST_F(AmbientViewerStubTest, ambient_viewer_notify_ambient_event_n) {
-  EXPECT_EQ(ambient_viewer_notify_ambient_event(nullptr, true,
+  EXPECT_EQ(ambient_viewer_notify_ambient_event(nullptr, AMBIENT_VIEWER_AMBIENT_STATE_ENTER,
       AMBIENT_VIEWER_DIRECTION_ALL, nullptr),
       AMBIENT_VIEWER_ERROR_INVALID_PARAMETER);
 }
index 120d530..a36fa53 100644 (file)
@@ -84,7 +84,12 @@ int AmbientListener::OnAmbientChangedSignal(const char *endpoint,
   bool enter;
   try {
     extra_data = tizen_base::Bundle(extra);
-    enter = (bool)stoi(mode);
+    AmbientState state = (AmbientState)stoi(mode);
+    if (state != AMBIENT_ENTER && state != AMBIENT_LEAVE) {
+      LOGW("Invalid state (%d)", (int)state);
+      return 0;
+    }
+    enter = (state == AMBIENT_ENTER);
   } catch (const std::exception& e) {
     LOGE("Exception (%s)", e.what());
     return 0;
index 75128d0..332ce5a 100644 (file)
@@ -31,6 +31,12 @@ class AmbientListener {
     EVENT_AOD_READY,
     EVENT_AOD_NOTIFIED
   };
+
+  enum AmbientState {
+    AMBIENT_LEAVE,
+    AMBIENT_ENTER,
+    AMBIENT_BLOCK_TICK,
+  };
   AmbientListener();
   virtual ~AmbientListener();
   static int OnAmbientChangedSignal(const char *endpoint,