--- /dev/null
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * 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_APPFW_WATCH_APP_INTERNAL_H__
+#define __TIZEN_APPFW_WATCH_APP_INTERNAL_H__
+
+#include <bundle.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @brief Enumeration for event.
+ * @remark This function only for internal applications
+ */
+typedef enum {
+ WATCH_APP_AMBIENT_EVENT_PREPARE,
+ WATCH_APP_AMBIENT_EVENT_READY,
+ WATCH_APP_AMBIENT_EVENT_CHANGED
+} watch_app_ambient_event_e;
+
+/**
+ * @brief Sends event with bundle data to the @a receiver.
+ * @remark This function only for internal applications
+ * @param[in] receiver application id of receiver
+ * @param[in] event ambient event type
+ * @param[in] data extra bundle data
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ */
+int watch_app_ambient_send_event(const char *receiver, watch_app_ambient_event_e event, bundle *data);
+
+/**
+ * @brief Gets extra bundle data from ambient-viewer.
+ * @remark This function only for internal applications
+ * @param[out] data extra bundle data
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ */
+int watch_app_ambient_get_extra(bundle **extra);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __TIZEN_APPFW_WATCH_APP_INTERNAL_H__ */
\ No newline at end of file
#include <time.h>
#include <app_control.h>
#include <app_common.h>
+#include <bundle.h>
#ifdef __cplusplus
extern "C" {
WATCH_BASE_AMBIENT_TICK_EVERY_DAY
} watch_base_ambient_tick_type_e;
+typedef enum {
+ WATCH_BASE_AMBIENT_EVENT_PREPARE,
+ WATCH_BASE_AMBIENT_EVENT_READY,
+ WATCH_BASE_AMBIENT_EVENT_CHANGED
+} watch_base_ambient_event_e;
+
int watch_base_set_ambient_tick_type(watch_base_ambient_tick_type_e type);
int watch_base_get_ambient_tick_type(watch_base_ambient_tick_type_e *type);
int watch_base_time_get_current_time(watch_base_time_h *watch_base_time);
int watch_base_time_get_utc_timestamp(watch_base_time_h watch_base_time, time_t *utc_timestamp);
int watch_base_time_get_time_zone(watch_base_time_h watch_base_time, char **time_zone_id);
int watch_base_time_get_dst_status(watch_base_time_h watch_base_time, bool *status);
+int watch_base_ambient_send_event(const char *receiver, watch_base_ambient_event_e event, bundle *extra);
+int watch_base_ambient_get_extra(bundle **extra);
#ifdef __cplusplus
}
bool ambient_mode_skip_resume;
bool bg_launch;
guint pause_timer;
+ aul_app_com_connection_h conn;
+ bundle *extra;
void *data;
};
}
/* LCOV_EXCL_STOP */
+int __on_change_signal(const char *endpoint, aul_app_com_result_e e,
+ bundle *envelope, void *user_data)
+{
+ char *extra;
+ char *mode;
+ watch_base_ambient_changed_cb ambient_changed_cb;
+
+ _W("__on_change_signal");
+
+ bundle_get_str(envelope, "__AMBIENT_MODE__", &mode);
+ bundle_get_str(envelope, "__AMBIENT_EXTRA__", &extra);
+ __context.extra = bundle_decode((bundle_raw *)extra, strlen(extra));
+
+ ambient_changed_cb = __context.callback.ambient_changed;
+
+ if (ambient_changed_cb != NULL)
+ ambient_changed_cb((bool)atoi(mode), __context.data);
+
+ return 0;
+}
+
+static void __set_ambient_changed_cb()
+{
+ if (__context.conn) {
+ _D("Already set ambient changed cb");
+ return;
+ }
+
+ _D("Set ambient changed cb");
+
+ if (aul_app_com_create("watch.ambientchange", NULL, __on_change_signal,
+ NULL, &__context.conn) != AUL_R_OK) {
+ _E("Failed to listen 'watch.ambientchange' signal");
+ }
+}
+
+static void __unset_ambient_changed_cb()
+{
+ if (__context.conn) {
+ if (aul_app_com_leave(__context.conn) < 0)
+ _E("failed to leave app com disable");
+
+ __context.conn = NULL;
+ }
+
+ if (__context.extra)
+ bundle_free(__context.extra);
+}
+
static int __on_ui_base_create(void *data)
{
watch_base_create_cb create_cb;
__FUNCTION__, "failed to get the appid");
}
+ if (!__context.conn) {
+ __set_ambient_changed_cb();
+ }
+
/* override methods */
ops.base.create = __on_ui_base_create;
ops.base.control = __on_ui_base_control;
__context.ambient_mode_skip_resume = false;
__context.data = user_data;
__context.state = WATCH_BASE_STATE_CREATING;
+ __context.extra = NULL;
return appcore_ui_base_init(ops, argc, argv, NULL, 0);
}
EXPORT_API void watch_base_fini(void)
{
+ __unset_ambient_changed_cb();
free(__context.appid);
__context.appid = NULL;
appcore_ui_base_fini();
return APP_ERROR_INVALID_PARAMETER;
return __get_time_tick_frequency(ticks, type);
}
+
+EXPORT_API int watch_base_ambient_send_event(const char *receiver,
+ watch_base_ambient_event_e event, bundle *extra)
+{
+ char buf[32];
+ char endpoint[APPID_BUFFER_MAX];
+ char appid_buf[APPID_BUFFER_MAX] = {0, };
+ int ret;
+ bundle *envelope;
+
+ if (!receiver) {
+ _E("receiver should not be null");
+ return APP_ERROR_INVALID_PARAMETER;
+ }
+
+ if (extra == NULL) {
+ _E("extra data is null");
+ envelope = bundle_create();
+ } else {
+ envelope = bundle_dup(extra);
+ }
+
+ if (envelope == NULL) {
+ _E("out of memory");
+ return APP_ERROR_OUT_OF_MEMORY;
+ }
+
+ snprintf(buf, sizeof(buf), "%d", event);
+ ret = bundle_add_str(envelope, "__APP_AMBIENT_EVENT__", buf);
+ if (ret != BUNDLE_ERROR_NONE) {
+ _E("bundle_add_str returns false");
+ bundle_free(envelope);
+ return -1;
+ }
+
+ if (aul_app_get_appid_bypid(
+ getpid(), appid_buf, sizeof(appid_buf)) != AUL_R_OK) {
+ _E("Failed to get appid (%d)", getpid());
+ bundle_free(envelope);
+ return -1;
+ }
+
+ ret = bundle_add_str(envelope, "__APP_AMBIENT_SENDER__", appid_buf);
+ if (ret != BUNDLE_ERROR_NONE) {
+ _E("bundle_add_str returns false");
+ bundle_free(envelope);
+ return -1;
+ }
+
+ snprintf(endpoint, sizeof(endpoint), "send_extra_data:%s", receiver);
+
+ ret = aul_app_com_send(endpoint, envelope);
+ if (ret != AUL_R_OK) {
+ _E("Failed aul_app_com_send");
+ bundle_free(envelope);
+ return -1;
+ }
+
+ bundle_free(envelope);
+ return APP_ERROR_NONE;
+}
+
+EXPORT_API int watch_base_ambient_get_extra(bundle **extra)
+{
+ if (__context.extra == NULL) {
+ _E("Watch app not receive a bundle yet.");
+ return APP_ERROR_INVALID_CONTEXT;
+ }
+
+ *extra = bundle_dup(__context.extra);
+ return APP_ERROR_NONE;
+}
\ No newline at end of file