#include <widget_app.h>
#include <screen_connector_provider.h>
#include <pkgmgr-info.h>
+#include <aul_app_com.h>
#include "appcore-watch.h"
#include "appcore-watch-log.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"
static Ecore_Timer *watch_tick = NULL;
static alarm_id_t alarm_id = 0;
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;
/**
* Appcore internal system event
WE_MAX
};
+enum watch_visible_state {
+ WVS_UNKNOWN,
+ WVS_PAUSE,
+ WVS_RESUME
+};
+
+enum viewer_visible_state{
+ WATCH_CONTROL_UNKNOWN,
+ WATCH_CONTROL_PAUSE,
+ WATCH_CONTROL_RESUME
+};
+
static enum watch_core_event to_ae[SE_MAX] = {
WATCH_CORE_EVENT_UNKNOWN, /* SE_UNKNOWN */
WATCH_CORE_EVENT_LOW_MEMORY, /* SE_LOWMEM */
const char *name;
pid_t pid;
enum watch_state state;
+ enum watch_visible_state watch_visibility;
+ enum viewer_visible_state viewer_visibility;
int ambient_mode;
int ambient_mode_skip_resume;
-
struct watchcore_ops *ops;
};
watch->appid = strdup(appid);
watch->name = __get_domain_name(appid);
watch->pid = getpid();
+ watch->viewer_visibility = WATCH_CONTROL_UNKNOWN;
+ watch->watch_visibility = WVS_UNKNOWN;
return 0;
}
ucal_close(cal);
}
+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);
+ priv.viewer_visibility = *state;
+ _D("set viewer state to %d", *state);
+
+ if (*state == WATCH_CONTROL_RESUME && priv.watch_visibility == WVS_RESUME)
+ __do_app(WE_RESUME, &priv, NULL);
+ else if (*state == WATCH_CONTROL_PAUSE)
+ __do_app(WE_PAUSE, &priv, NULL);
+
+ return 0;
+}
+
int watch_core_init(const char *name, const struct watch_ops *ops,
int argc, char **argv)
{
goto err;
}
+ r = aul_app_com_create(priv.appid, NULL, __viewer_state_handler, NULL, &__conn_viewer_state);
+ if (r < 0) {
+ _E("failed to create app com viewer state endpoint : %s", priv.appid);
+ goto err;
+ }
+
core.ops = ops;
core.init = 1;
sec = __get_next_tick_sec();
watch_tick = ecore_timer_add(sec, __watch_core_time_tick, NULL);
- _D("next time tick: %f, type %d, ticks %d", sec, app_tick_type, app_tick_resolution);
+ _D("next time tick: %f, type %d, ticks %d", sec, app_tick_resolution, app_tick_type);
priv.ops->time_tick(&timeinfo, priv.ops->data);
}
{
_D("widget_pause");
+ priv.watch_visibility = WVS_PAUSE;
__do_app(WE_PAUSE, &priv, NULL);
return WIDGET_ERROR_NONE;
static int __widget_resume(const char *id, void *data)
{
_D("widget_resume");
+ priv.watch_visibility = WVS_RESUME;
- __do_app(WE_RESUME, &priv, NULL);
+ if (priv.viewer_visibility == WATCH_CONTROL_RESUME)
+ __do_app(WE_RESUME, &priv, NULL);
+ else
+ _D("viewer is paused, do not resume watch");
return WIDGET_ERROR_NONE;
}
_D("visibility %d %d", (unsigned int)ev->win, (unsigned int)ev->fully_obscured);
- if (ev->fully_obscured)
+ if (ev->fully_obscured) {
+ priv.watch_visibility = WVS_PAUSE;
__do_app(WE_PAUSE, &priv, NULL);
- else
- __do_app(WE_RESUME, &priv, NULL);
+ } else {
+ priv.watch_visibility = WVS_RESUME;
+ if (priv.viewer_visibility == WATCH_CONTROL_RESUME)
+ __do_app(WE_RESUME, &priv, NULL);
+ else
+ _D("viewer is paused, do not resume watch");
+ }
return ECORE_CALLBACK_RENEW;
}
if (watch->ops && watch->ops->terminate)
watch->ops->terminate(watch->ops->data);
+ if (__conn_viewer_state) {
+ if (aul_app_com_leave(__conn_viewer_state) < 0)
+ _E("failed to leave app com endpoint __conn_viewer_state");
+ __conn_viewer_state = NULL;
+ }
+
screen_connector_provider_fini();
elm_shutdown();