#include <app_control_internal.h>
#include <bundle_internal.h>
#include <pkgmgr-info.h>
+#include <aul_app_com.h>
#include "appcore-watch-log.h"
#include "watch_app_private.h"
#define ONE_DAY_IN_SEC 86400
#define METADATA_TICK_PER_SECOND "http://developer.samsung.com/tizen/metadata/tickpersecond"
#define METADATA_MINUTE_TICK "http://developer.samsung.com/tizen/metadata/minutetick"
+#define WATCH_CONTROL_STATE "watch,state"
typedef enum {
WATCH_APP_STATE_NOT_RUNNING = 0, /* The application has been launched or was running but was terminated */
char *timezone;
};
+enum watch_visible_state {
+ WVS_UNKNOWN,
+ WVS_PAUSE,
+ WVS_RESUME
+};
+
+enum viewer_visible_state {
+ WATCH_CONTROL_UNKNOWN,
+ WATCH_CONTROL_PAUSE,
+ WATCH_CONTROL_RESUME
+};
+
#define WATCH_APP_EVENT_MAX 5
static Ecore_Timer *watch_tick = NULL;
static alarm_id_t alarm_id = 0;
-static watch_app_ambient_tick_type_e ambient_tick_type
- = WATCH_APP_AMBIENT_TICK_EVERY_MINUTE;
-
+static watch_app_ambient_tick_type_e ambient_tick_type = WATCH_APP_AMBIENT_TICK_EVERY_MINUTE;
static watch_app_time_tick_resolution_e app_tick_type = WATCH_APP_TIME_TICKS_PER_SECOND;
static int app_tick_resolution = 1;
+static aul_app_com_connection_h __conn_viewer_state;
struct app_event_handler {
app_event_type_e type;
watch_app_lifecycle_callback_s callback;
int width;
int height;
+ enum watch_visible_state watch_visibility;
+ enum viewer_visible_state viewer_visibility;
bool ambient_mode;
bool ambient_mode_skip_resume;
void *data;
{
_W("_watch_core_pause");
+ __context.watch_visibility = WVS_PAUSE;
/* Handling the ambient mode */
if (__context.ambient_mode)
__context.ambient_mode_skip_resume = 1;
{
_W("_watch_core_resume");
+ __context.watch_visibility = WVS_RESUME;
+ if (__context.viewer_visibility != WATCH_CONTROL_RESUME) {
+ _D("Viewer is paused, do not resume watch");
+ return APP_ERROR_NONE;
+ }
+
appcore_efl_base_on_resume();
if (__context.ambient_mode) {
appcore_efl_base_resume();
}
+static void __on_window_visibility(int type, void *event, void *data)
+{
+ Ecore_Wl_Event_Window_Visibility_Change *ev = event;
+
+ _D("visibility %u %u",
+ (unsigned int)ev->win,
+ (unsigned int)ev->fully_obscured);
+
+ if (ev->fully_obscured) {
+ __context.watch_visibility = WVS_PAUSE;
+ __on_pause(NULL);
+ } else {
+ __context.watch_visibility = WVS_RESUME;
+ if (__context.viewer_visibility == WATCH_CONTROL_RESUME)
+ __on_resume(NULL);
+ else
+ _D("Viewer is paused, do not resume watch");
+ }
+}
+
static int __set_ambient_tick_type(watch_app_ambient_tick_type_e type)
{
_D("set ambient tick type : %d", type);
return 0;
}
+static int __viewer_state_handler(const char *widget_id, aul_app_com_result_e e,
+ bundle *envelope, void *user_data)
+{
+ int *state = NULL;
+ size_t state_sz = 0;
+
+ bundle_get_byte(envelope, WATCH_CONTROL_STATE, (void **)&state,
+ &state_sz);
+ __context.viewer_visibility = *state;
+ _D("set viewer state to %d", *state);
+
+ if (*state == WATCH_CONTROL_RESUME &&
+ __context.watch_visibility == WVS_RESUME)
+ __on_resume(NULL);
+ else if (*state == WATCH_CONTROL_PAUSE)
+ __on_pause(NULL);
+
+ return 0;
+}
+
EXPORT_API int watch_app_main(int argc, char **argv,
watch_app_lifecycle_callback_s *callback, void *user_data)
{
ops.ui_base.pause = __on_pause;
ops.ui_base.resume = __on_resume;
ops.ui_base.window.show = __on_window_show;
+ ops.ui_base.window.visibility = __on_window_visibility;
kb = bundle_import_from_argv(argc, argv);
if (kb) {
return watch_app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__,
"failed to get the appid");
+ ret = aul_app_com_create(__context.appid, NULL, __viewer_state_handler,
+ NULL, &__conn_viewer_state);
+ if (ret < 0) {
+ free(__context.appid);
+ __context.appid = NULL;
+ return watch_app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__,
+ "Failed to create app com");
+ }
+
__context.callback = *callback;
__context.width = width;
__context.height = height;
+ __context.viewer_visibility = WATCH_CONTROL_UNKNOWN;
+ __context.watch_visibility = WVS_UNKNOWN;
__context.ambient_mode = false;
__context.ambient_mode_skip_resume = false;
__context.data = user_data;
ret = appcore_efl_base_init(ops, argc, argv, NULL, 0);
free(__context.appid);
__context.appid = NULL;
+ aul_app_com_leave(__conn_viewer_state);
+ __conn_viewer_state = NULL;
if (ret < 0) {
__context.state = WATCH_APP_STATE_NOT_RUNNING;