Check previous state when do resume/pause 04/172104/1
authorhyunho <hhstark.kang@samsung.com>
Mon, 12 Mar 2018 01:37:47 +0000 (10:37 +0900)
committerhyunho <hhstark.kang@samsung.com>
Mon, 12 Mar 2018 01:37:47 +0000 (10:37 +0900)
Change-Id: Ie9e6f80cb131e2390cafe3cb2330208696b29758
Signed-off-by: hyunho <hhstark.kang@samsung.com>
src/watch_app_main.c

index 1ede5b6..82921a3 100755 (executable)
@@ -79,6 +79,14 @@ typedef enum {
        WATCH_APP_STATE_RUNNING, /* The application is running in the foreground and background */
 } watch_app_state_e;
 
+enum watch_state {
+       WS_NONE,
+       WS_CREATED,
+       WS_RUNNING,
+       WS_PAUSED,
+       WS_DYING,
+};
+
 struct _watch_time_s {
        int year;
        int month;
@@ -162,6 +170,7 @@ static int __app_event_converter[APPCORE_BASE_EVENT_MAX] = {
 struct watch_app_context __context;
 static double __prev_target_tick = -1;
 static Evas_Object *__watch_win;
+enum watch_state __state;
 
 static void __on_ambient_tick(void *watchtime, void *data);
 static void __on_ambient_changed(int ambient, void *data);
@@ -554,6 +563,7 @@ static int __on_create(void *data)
        if (create_cb == NULL || create_cb(__context.width, __context.height, __context.data) == false)
                return watch_app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__,
                                "watch_app_create_cb() returns false");
+       __state = WS_CREATED;
 
        /* Alarm init */
        __alarm_init();
@@ -588,6 +598,11 @@ static int __on_pause(void *data)
 {
        _W("_watch_core_pause");
 
+       if (__state == WS_CREATED) {
+               _E("Invalid state");
+               return APP_ERROR_NONE;
+       }
+
        /* clear pre resume flag */
        __pre_resume_called = 0;
 
@@ -602,6 +617,8 @@ static int __on_pause(void *data)
        if (__context.callback.pause)
                __context.callback.pause(__context.data);
 
+       __state = WS_PAUSED;
+
        return APP_ERROR_NONE;
 }
 /* LCOV_EXCL_STOP */
@@ -638,6 +655,11 @@ static int __on_resume(void *data)
                return APP_ERROR_NONE;
        }
 
+       if (__state != WS_PAUSED && __state != WS_CREATED) {
+               _E("Invalid state");
+               return APP_ERROR_NONE;
+       }
+
        appcore_efl_base_on_resume();
 
        if (__context.ambient_mode) {
@@ -648,6 +670,8 @@ static int __on_resume(void *data)
        if (__context.callback.resume)
                __context.callback.resume(__context.data);
 
+       __state = WS_RUNNING;
+
        if (!watch_tick) {
                __time_tick_cb(data);
        } else {
@@ -662,6 +686,7 @@ static int __on_terminate(void *data)
 {
        _W("_watch_core_terminate");
 
+       __state = WS_DYING;
        if (appcore_efl_base_is_resumed())
                appcore_efl_base_pause();