diff options
author | Sewook Park <sewook7.park@samsung.com> | 2012-08-21 19:56:22 +0900 |
---|---|---|
committer | Sewook Park <sewook7.park@samsung.com> | 2012-08-21 19:56:22 +0900 |
commit | 49ad159aae9fa6bce07ab325356ffb7cbf85a476 (patch) | |
tree | 031d8d6471792b39dbbc00ea10fd49edc3604de0 /src | |
parent | b7d00f250a7c4012b018ccbfdeebd976f1bd907f (diff) | |
download | application-49ad159aae9fa6bce07ab325356ffb7cbf85a476.tar.gz application-49ad159aae9fa6bce07ab325356ffb7cbf85a476.tar.bz2 application-49ad159aae9fa6bce07ab325356ffb7cbf85a476.zip |
Upload Tizen2.0 source
Diffstat (limited to 'src')
-rwxr-xr-x | src/app_main.c | 3 | ||||
-rwxr-xr-x | src/app_package.c | 21 | ||||
-rwxr-xr-x | src/app_resource.c | 24 | ||||
-rwxr-xr-x | src/preference.c | 232 | ||||
-rwxr-xr-x | src/service.c | 243 | ||||
-rwxr-xr-x | src/ui_notification.c | 206 |
6 files changed, 572 insertions, 157 deletions
diff --git a/src/app_main.c b/src/app_main.c index e9a9cb8..058607f 100755 --- a/src/app_main.c +++ b/src/app_main.c @@ -147,6 +147,9 @@ int app_appcore_create(void *data) app_set_appcore_event_cb(app_context); snprintf(locale_dir, TIZEN_PATH_MAX, PATH_FMT_LOCALE_DIR, app_context->package); + if (access(locale_dir, R_OK) != 0) { + snprintf(locale_dir, TIZEN_PATH_MAX, PATH_FMT_RO_LOCALE_DIR, app_context->package); + } appcore_set_i18n(app_context->app_name, locale_dir); create_cb = app_context->callback->create; diff --git a/src/app_package.c b/src/app_package.c index b1b0646..a151744 100755 --- a/src/app_package.c +++ b/src/app_package.c @@ -69,26 +69,31 @@ int app_get_package_app_name(const char *package, char **name) int app_get_package(char **package) { - static char package_buf[TIZEN_PATH_MAX] = {0, }; + return app_get_id(package); +} - if (package == NULL) +int app_get_id(char **id) +{ + static char id_buf[TIZEN_PATH_MAX] = {0, }; + + if (id == NULL) { return app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); } - if (package_buf[0] == '\0') + if (id_buf[0] == '\0') { - aul_app_get_pkgname_bypid(getpid(), package_buf, sizeof(package_buf)); + aul_app_get_pkgname_bypid(getpid(), id_buf, sizeof(id_buf)); } - if (package_buf[0] == '\0') + if (id_buf[0] == '\0') { - return app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, "failed to get the package"); + return app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, "failed to get the application ID"); } - *package = strdup(package_buf); + *id = strdup(id_buf); - if (*package == NULL) + if (*id == NULL) { return app_error(APP_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL); } diff --git a/src/app_resource.c b/src/app_resource.c index 6999ccd..219eb6c 100755 --- a/src/app_resource.c +++ b/src/app_resource.c @@ -25,6 +25,7 @@ #include <bundle.h> #include <appcore-common.h> +#include <appcore-efl.h> #include <aul.h> #include <dlog.h> @@ -38,6 +39,7 @@ #define LOG_TAG "TIZEN_N_APPLICATION" static const char *INSTALLED_PATH = "/opt/apps"; +static const char *RO_INSTALLED_PATH = "/usr/apps"; static const char *RES_DIRECTORY_NAME = "res"; static const char *DATA_DIRECTORY_NAME = "data"; @@ -45,6 +47,7 @@ static char * app_get_root_directory(char *buffer, int size) { char *package = NULL; char root_directory[TIZEN_PATH_MAX] = {0, }; + char bin_directory[TIZEN_PATH_MAX] = {0, }; if (app_get_package(&package) != APP_ERROR_NONE) { @@ -53,6 +56,11 @@ static char * app_get_root_directory(char *buffer, int size) } snprintf(root_directory, sizeof(root_directory), "%s/%s", INSTALLED_PATH, package); + snprintf(bin_directory, sizeof(bin_directory), "%s/bin", root_directory); + + if (access(bin_directory, R_OK) != 0) { + snprintf(root_directory, sizeof(root_directory), "%s/%s", RO_INSTALLED_PATH, package); + } free(package); @@ -99,6 +107,7 @@ char* app_get_data_directory(char *buffer, int size) if (data_directory[0] == '\0') { char *root_directory = NULL; + char *package = NULL; root_directory = calloc(1, TIZEN_PATH_MAX); @@ -108,13 +117,16 @@ char* app_get_data_directory(char *buffer, int size) return NULL; } - if (app_get_root_directory(root_directory, TIZEN_PATH_MAX) == NULL) + if (app_get_package(&package) != APP_ERROR_NONE) { - free(root_directory); - app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, "failed to get the path to the root directory"); + app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, "failed to get the package"); return NULL; } + snprintf(root_directory, TIZEN_PATH_MAX, "%s/%s", INSTALLED_PATH, package); + + free(package); + snprintf(data_directory, sizeof(data_directory), "%s/%s", root_directory, DATA_DIRECTORY_NAME); data_directory_length = strlen(data_directory); @@ -176,3 +188,9 @@ char* app_get_resource(const char *resource, char *buffer, int size) return buffer; } + +void app_set_reclaiming_system_cache_on_pause(bool enable) +{ + appcore_set_system_resource_reclaiming(enable); +} + diff --git a/src/preference.c b/src/preference.c index 63b779b..ee1606b 100755 --- a/src/preference.c +++ b/src/preference.c @@ -11,7 +11,7 @@ * 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. + * limitations under the License. */ @@ -63,7 +63,7 @@ static int _initialize(void) snprintf(db_path, sizeof(db_path), "%s/%s", data_path, PREF_DB_NAME); ret = sqlite3_open(db_path, &pref_db); - if (ret != SQLITE_OK) + if (ret != SQLITE_OK) { LOGE("[%s] IO_ERROR(0x%08x) : fail to open db(%s)", __FUNCTION__, PREFERENCE_ERROR_IO_ERROR, sqlite3_errmsg(pref_db)); pref_db = NULL; @@ -72,7 +72,7 @@ static int _initialize(void) ret = sqlite3_exec(pref_db, "CREATE TABLE IF NOT EXISTS pref ( pref_key TEXT PRIMARY KEY, pref_type TEXT, pref_data TEXT)", NULL, NULL, &errmsg); - if (ret != SQLITE_OK) + if (ret != SQLITE_OK) { LOGE("[%s] IO_ERROR(0x%08x) : fail to create db table(%s)", __FUNCTION__, PREFERENCE_ERROR_IO_ERROR, errmsg); sqlite3_free(errmsg); @@ -82,11 +82,11 @@ static int _initialize(void) } app_finalizer_add(_finish, NULL); - + return PREFERENCE_ERROR_NONE; } -//static int _write_data(const char *key, preference_type_e type, const char *data) +//static int _write_data(const char *key, preference_type_e type, const char *data) static int _write_data(const char *key, const char *type, const char *data) { int ret; @@ -108,15 +108,15 @@ static int _write_data(const char *key, const char *type, const char *data) } // to use sqlite3_update_hook, we have to use INSERT/UPDATE operation instead of REPLACE operation - if (exist) + if (exist) { - buf = sqlite3_mprintf("UPDATE %s SET %s='%s', %s='%s' WHERE %s='%s';", + buf = sqlite3_mprintf("UPDATE %s SET %s='%s', %s='%s' WHERE %s='%s';", PREF_TBL_NAME, PREF_F_TYPE_NAME, type, PREF_F_DATA_NAME, data, PREF_F_KEY_NAME, key); } - else + else { - buf = sqlite3_mprintf("INSERT INTO %s (%s, %s, %s) values ('%q', '%q', '%q');", - PREF_TBL_NAME, PREF_F_KEY_NAME, PREF_F_TYPE_NAME, PREF_F_DATA_NAME, key, type, data); + buf = sqlite3_mprintf("INSERT INTO %s (%s, %s, %s) values ('%q', '%q', '%q');", + PREF_TBL_NAME, PREF_F_KEY_NAME, PREF_F_TYPE_NAME, PREF_F_DATA_NAME, key, type, data); } if (buf == NULL) @@ -124,16 +124,16 @@ static int _write_data(const char *key, const char *type, const char *data) LOGE("[%s] IO_ERROR(0x%08x) : fail to create query string", __FUNCTION__, PREFERENCE_ERROR_IO_ERROR); return PREFERENCE_ERROR_IO_ERROR; } - + ret = sqlite3_exec(pref_db, buf, NULL, NULL, &errmsg); sqlite3_free(buf); - if (ret != SQLITE_OK) + if (ret != SQLITE_OK) { LOGE("[%s] IO_ERROR(0x%08x): fail to write data(%s)", __FUNCTION__, PREFERENCE_ERROR_IO_ERROR, errmsg); sqlite3_free(errmsg); return PREFERENCE_ERROR_IO_ERROR; } - + return PREFERENCE_ERROR_NONE; } @@ -147,13 +147,13 @@ static int _read_data(const char *key, char *type, char *data) int columns; char *errmsg; - if (key == NULL || key[0] == '\0' || data == NULL) - { + if (key == NULL || key[0] == '\0' || data == NULL) + { LOGE("[%s] INVALID_PARAMETER(0x%08x)", __FUNCTION__, PREFERENCE_ERROR_INVALID_PARAMETER); return PREFERENCE_ERROR_INVALID_PARAMETER; - } + } - if (pref_db == NULL) + if (pref_db == NULL) { if (_initialize() != PREFERENCE_ERROR_NONE) { @@ -162,7 +162,7 @@ static int _read_data(const char *key, char *type, char *data) } } - buf = sqlite3_mprintf("SELECT %s, %s, %s FROM %s WHERE %s='%q';", + buf = sqlite3_mprintf("SELECT %s, %s, %s FROM %s WHERE %s='%q';", PREF_F_KEY_NAME, PREF_F_TYPE_NAME, PREF_F_DATA_NAME, PREF_TBL_NAME, PREF_F_KEY_NAME, key); if (buf == NULL) @@ -173,25 +173,25 @@ static int _read_data(const char *key, char *type, char *data) ret = sqlite3_get_table(pref_db, buf, &result, &rows, &columns, &errmsg); sqlite3_free(buf); - if (ret != SQLITE_OK) + if (ret != SQLITE_OK) { LOGE("[%s] IO_ERROR(0x%08x) : fail to read data (%s)", __FUNCTION__, PREFERENCE_ERROR_IO_ERROR, errmsg); sqlite3_free(errmsg); - return PREFERENCE_ERROR_IO_ERROR; + return PREFERENCE_ERROR_IO_ERROR; } - - if (rows == 0) + + if (rows == 0) { LOGE("[%s] NO_KEY(0x%08x) : fail to find given key(%s)", __FUNCTION__, PREFERENCE_ERROR_NO_KEY, key); sqlite3_free_table(result); - return PREFERENCE_ERROR_NO_KEY; + return PREFERENCE_ERROR_NO_KEY; } - snprintf(type, strlen(result[4]) + 1, "%s", result[4]); // get type value - snprintf(data, strlen(result[5]) + 1, "%s", result[5]); // get data value - + snprintf(type, 2, "%s", result[4]); // get type value + snprintf(data, BUF_LEN, "%s", result[5]); // get data value + sqlite3_free_table(result); - + return PREFERENCE_ERROR_NONE; } @@ -210,21 +210,21 @@ int preference_get_int(const char *key, int *value) char type[2]; char data[BUF_LEN]; int ret; - + ret = _read_data(key, type, data); - if (ret == PREFERENCE_ERROR_NONE) + if (ret == PREFERENCE_ERROR_NONE) { if (atoi(type) == PREFERENCE_TYPE_INT) { *value = atoi(data); - } - else + } + else { LOGE("[%s] INVALID_PARAMETER(0x%08x) : param type(%d)", __FUNCTION__, PREFERENCE_ERROR_INVALID_PARAMETER, atoi(type)); return PREFERENCE_ERROR_INVALID_PARAMETER; } } - + return ret; } @@ -243,27 +243,33 @@ int preference_get_double(const char *key, double *value) char data[BUF_LEN]; int ret; - + ret = _read_data(key, type, data); - if (ret == PREFERENCE_ERROR_NONE) + if (ret == PREFERENCE_ERROR_NONE) { if (atoi(type) == PREFERENCE_TYPE_DOUBLE) { *value = atof(data); - } - else + } + else { LOGE("[%s] INVALID_PARAMETER(0x%08x) : param type(%d)", __FUNCTION__, PREFERENCE_ERROR_INVALID_PARAMETER, atoi(type)); return PREFERENCE_ERROR_INVALID_PARAMETER; } } - - return ret; + + return ret; } int preference_set_string(const char *key, const char *value) { char type[2]; + + if (strlen(value) > (BUF_LEN-1)) + { + LOGE("[%s] INVALID_PARAMETER(0x%08x) : param type(%d)", __FUNCTION__, PREFERENCE_ERROR_INVALID_PARAMETER, atoi(type)); + return PREFERENCE_ERROR_INVALID_PARAMETER; + } snprintf(type, 2, "%d", PREFERENCE_TYPE_STRING); return _write_data(key, type, value); } @@ -280,9 +286,9 @@ int preference_get_string(const char *key, char **value) LOGE("[%s] INVALID_PARAMETER(0x%08x)", __FUNCTION__, PREFERENCE_ERROR_INVALID_PARAMETER); return PREFERENCE_ERROR_INVALID_PARAMETER; } - + ret = _read_data(key, type, data); - if (ret == PREFERENCE_ERROR_NONE) + if (ret == PREFERENCE_ERROR_NONE) { if (atoi(type) == PREFERENCE_TYPE_STRING) { @@ -292,15 +298,15 @@ int preference_get_string(const char *key, char **value) LOGE("[%s] OUT_OF_MEMORY(0x%08x)", __FUNCTION__, PREFERENCE_ERROR_OUT_OF_MEMORY); return PREFERENCE_ERROR_OUT_OF_MEMORY; } - } - else + } + else { LOGE("[%s] INVALID_PARAMETER(0x%08x) : param type(%d)", __FUNCTION__, PREFERENCE_ERROR_INVALID_PARAMETER, atoi(type)); return PREFERENCE_ERROR_INVALID_PARAMETER; } } - - return ret; + + return ret; } int preference_set_boolean(const char *key, bool value) @@ -318,22 +324,22 @@ int preference_get_boolean(const char *key, bool *value) char data[BUF_LEN]; int ret; - + ret = _read_data(key, type, data); - if (ret == PREFERENCE_ERROR_NONE) + if (ret == PREFERENCE_ERROR_NONE) { if (atoi(type) == PREFERENCE_TYPE_BOOLEAN) { *value = (bool)atoi(data); - } - else + } + else { LOGE("[%s] INVALID_PARAMETER(0x%08x) : param type(%d)", __FUNCTION__, PREFERENCE_ERROR_INVALID_PARAMETER, atoi(type)); return PREFERENCE_ERROR_INVALID_PARAMETER; } } - - return ret; + + return ret; } @@ -347,13 +353,13 @@ int preference_is_existing(const char *key, bool *exist) int columns; char *errmsg; - if (key == NULL || key[0] == '\0' || exist == NULL) + if (key == NULL || key[0] == '\0' || exist == NULL) { LOGE("[%s] INVALID_PARAMETER(0x%08x)", __FUNCTION__, PREFERENCE_ERROR_INVALID_PARAMETER); return PREFERENCE_ERROR_INVALID_PARAMETER; } - if (pref_db == NULL) + if (pref_db == NULL) { if (_initialize() != PREFERENCE_ERROR_NONE) { @@ -361,7 +367,7 @@ int preference_is_existing(const char *key, bool *exist) return PREFERENCE_ERROR_IO_ERROR; } } - + /* check data is exist */ buf = sqlite3_mprintf("SELECT %s FROM %s WHERE %s='%q';", PREF_F_KEY_NAME, PREF_TBL_NAME, PREF_F_KEY_NAME, key); @@ -370,16 +376,16 @@ int preference_is_existing(const char *key, bool *exist) LOGE("[%s] IO_ERROR(0x%08x) : fail to create query string", __FUNCTION__, PREFERENCE_ERROR_IO_ERROR); return PREFERENCE_ERROR_IO_ERROR; } - + ret = sqlite3_get_table(pref_db, buf, &result, &rows, &columns, &errmsg); sqlite3_free(buf); - if (ret != SQLITE_OK) + if (ret != SQLITE_OK) { LOGE("[%s] IO_ERROR(0x%08x) : fail to read data(%s)", __FUNCTION__, PREFERENCE_ERROR_IO_ERROR, errmsg); sqlite3_free(errmsg); return PREFERENCE_ERROR_IO_ERROR; } - + if (rows > 0) { *exist = true; @@ -404,9 +410,9 @@ static pref_changed_cb_node_t* _find_node(const char *key) tmp_node = head; - while (tmp_node) + while (tmp_node) { - if (strcmp(tmp_node->key, key) == 0) + if (strcmp(tmp_node->key, key) == 0) { break; } @@ -420,7 +426,7 @@ static pref_changed_cb_node_t* _find_node(const char *key) static int _add_node(const char *key, preference_changed_cb cb, void *user_data) { pref_changed_cb_node_t *tmp_node; - + if (key == NULL || key[0] == '\0' || cb == NULL) { LOGE("[%s] INVALID_PARAMETER(0x%08x)", __FUNCTION__, PREFERENCE_ERROR_INVALID_PARAMETER); @@ -463,30 +469,30 @@ static int _add_node(const char *key, preference_changed_cb cb, void *user_data) static int _remove_node(const char *key) { pref_changed_cb_node_t *tmp_node; - + if (key == NULL || key[0] == '\0' ) { LOGE("[%s] INVALID_PARAMETER(0x%08x)", __FUNCTION__, PREFERENCE_ERROR_INVALID_PARAMETER); return PREFERENCE_ERROR_INVALID_PARAMETER; } - + tmp_node = _find_node(key); - if (tmp_node == NULL) + if (tmp_node == NULL) { return PREFERENCE_ERROR_NONE; } - if (tmp_node->prev != NULL) + if (tmp_node->prev != NULL) { tmp_node->prev->next = tmp_node->next; - } - else + } + else { head = tmp_node->next; } - if (tmp_node->next != NULL) + if (tmp_node->next != NULL) { tmp_node->next->prev = tmp_node->prev; } @@ -495,7 +501,7 @@ static int _remove_node(const char *key) { free(tmp_node->key); } - + free(tmp_node); return PREFERENCE_ERROR_NONE; @@ -515,15 +521,15 @@ static void _remove_all_node(void) { free(tmp_node->key); } - + free(tmp_node); - } + } } static void _update_cb(void *data, int action, char const *db_name, char const *table_name, sqlite_int64 rowid) { - int ret; + int ret; char *buf; char **result; int rows; @@ -531,13 +537,13 @@ static void _update_cb(void *data, int action, char const *db_name, char const * char *errmsg; pref_changed_cb_node_t *tmp_node; - // skip INSERT/DELETE event - if (action != SQLITE_UPDATE) + // skip INSERT/DELETE event + if (action != SQLITE_UPDATE) { return; } - if (strcmp(table_name, PREF_TBL_NAME) != 0) + if (strcmp(table_name, PREF_TBL_NAME) != 0) { LOGI("[%s] given table name (%s) is not same", __FUNCTION__, table_name); return; @@ -550,22 +556,22 @@ static void _update_cb(void *data, int action, char const *db_name, char const * } ret = sqlite3_get_table(pref_db, buf, &result, &rows, &columns, &errmsg); sqlite3_free(buf); - if (ret != SQLITE_OK) + if (ret != SQLITE_OK) { LOGI("[%s] fail to read data(%s)", __FUNCTION__, errmsg); sqlite3_free(errmsg); return; } - - if (rows == 0) + + if (rows == 0) { - sqlite3_free_table(result); - return; + sqlite3_free_table(result); + return; } tmp_node = _find_node(result[1]); - if (tmp_node != NULL && tmp_node->cb != NULL) + if (tmp_node != NULL && tmp_node->cb != NULL) { tmp_node->cb(result[1], tmp_node->user_data); } @@ -579,19 +585,19 @@ int preference_remove(const char *key) int ret; char *buf; char *errmsg; - bool exist; - - ret = preference_is_existing(key, &exist); - if (ret != PREFERENCE_ERROR_NONE) - { - return ret; - } - - if (!exist) - { - return PREFERENCE_ERROR_NONE; - } - + bool exist; + + ret = preference_is_existing(key, &exist); + if (ret != PREFERENCE_ERROR_NONE) + { + return ret; + } + + if (!exist) + { + return PREFERENCE_ERROR_NONE; + } + /* insert data or update data if data already exist */ buf = sqlite3_mprintf("DELETE FROM %s WHERE %s = '%s';", PREF_TBL_NAME, PREF_F_KEY_NAME, key); @@ -601,10 +607,10 @@ int preference_remove(const char *key) LOGE("[%s] IO_ERROR(0x%08x) : fail to create query string", __FUNCTION__, PREFERENCE_ERROR_IO_ERROR); return PREFERENCE_ERROR_IO_ERROR; } - + ret = sqlite3_exec(pref_db, buf, NULL, NULL, &errmsg); sqlite3_free(buf); - if (ret != SQLITE_OK) + if (ret != SQLITE_OK) { LOGE("[%s] IO_ERROR(0x%08x) : fail to delete data (%s)", __FUNCTION__, PREFERENCE_ERROR_IO_ERROR, errmsg); sqlite3_free(errmsg); @@ -613,8 +619,8 @@ int preference_remove(const char *key) // if exist, remove changed cb _remove_node(key); - - return PREFERENCE_ERROR_NONE; + + return PREFERENCE_ERROR_NONE; } @@ -624,7 +630,7 @@ int preference_remove_all(void) char *buf; char *errmsg; - if (pref_db == NULL) + if (pref_db == NULL) { if (_initialize() != PREFERENCE_ERROR_NONE) { @@ -640,10 +646,10 @@ int preference_remove_all(void) LOGE("[%s] IO_ERROR(0x%08x) : fail to create query string", __FUNCTION__, PREFERENCE_ERROR_IO_ERROR); return PREFERENCE_ERROR_IO_ERROR; } - + ret = sqlite3_exec(pref_db, buf, NULL, NULL, &errmsg); sqlite3_free(buf); - if (ret != SQLITE_OK) + if (ret != SQLITE_OK) { LOGE("[%s] IO_ERROR(0x%08x) : fail to delete data (%s)", __FUNCTION__, PREFERENCE_ERROR_IO_ERROR, errmsg); sqlite3_free(errmsg); @@ -663,7 +669,7 @@ int preference_set_changed_cb(const char *key, preference_changed_cb callback, v bool exist; ret = preference_is_existing(key, &exist); - if (ret != PREFERENCE_ERROR_NONE) + if (ret != PREFERENCE_ERROR_NONE) { return ret; } @@ -672,27 +678,27 @@ int preference_set_changed_cb(const char *key, preference_changed_cb callback, v { LOGE("[%s] NO_KEY(0x%08x) : fail to find given key(%s)", __FUNCTION__, PREFERENCE_ERROR_NO_KEY, key); return PREFERENCE_ERROR_NO_KEY; - } - - if (!is_update_hook_registered) + } + + if (!is_update_hook_registered) { sqlite3_update_hook(pref_db, _update_cb, NULL); is_update_hook_registered = true; } - + return _add_node(key, callback, user_data); } int preference_unset_changed_cb(const char *key) { - if (pref_db == NULL) + if (pref_db == NULL) { if (_initialize() != PREFERENCE_ERROR_NONE) { return PREFERENCE_ERROR_IO_ERROR; } } - + return _remove_node(key); } @@ -706,7 +712,7 @@ int preference_foreach_item(preference_item_cb callback, void *user_data) char *errmsg; int i; - if (pref_db == NULL) + if (pref_db == NULL) { if (_initialize() != PREFERENCE_ERROR_NONE) { @@ -715,7 +721,7 @@ int preference_foreach_item(preference_item_cb callback, void *user_data) } } - if (callback == NULL) + if (callback == NULL) { LOGE("[%s] INVALID_PARAMETER(0x%08x)", __FUNCTION__, PREFERENCE_ERROR_INVALID_PARAMETER); return PREFERENCE_ERROR_INVALID_PARAMETER; @@ -727,19 +733,19 @@ int preference_foreach_item(preference_item_cb callback, void *user_data) LOGE("[%s] IO_ERROR(0x%08x) : fail to create query string", __FUNCTION__, PREFERENCE_ERROR_IO_ERROR); return PREFERENCE_ERROR_IO_ERROR; } - + ret = sqlite3_get_table(pref_db, buf, &result, &rows, &columns, &errmsg); sqlite3_free(buf); - if (ret != SQLITE_OK) + if (ret != SQLITE_OK) { LOGE("[%s] IO_ERROR(0x%08x) : fail to read data (%s)", __FUNCTION__, PREFERENCE_ERROR_IO_ERROR, errmsg); sqlite3_free(errmsg); return PREFERENCE_ERROR_IO_ERROR; } - - for (i = 1; i <= rows; i++) + + for (i = 1; i <= rows; i++) { - if (callback(result[i], user_data) != true) + if (callback(result[i], user_data) != true) { break; } diff --git a/src/service.c b/src/service.c index e53312c..c44e171 100755 --- a/src/service.c +++ b/src/service.c @@ -35,6 +35,10 @@ #define LOG_TAG "TIZEN_N_SERVICE" +#ifndef TIZEN_PATH_MAX +#define TIZEN_PATH_MAX 1024 +#endif + #define BUNDLE_KEY_PREFIX_AUL "__AUL_" #define BUNDLE_KEY_PREFIX_SERVICE "__APP_SVC_" @@ -43,6 +47,8 @@ #define BUNDLE_KEY_MIME "__APP_SVC_MIME_TYPE__" #define BUNDLE_KEY_DATA "__APP_SVC_DATA__" #define BUNDLE_KEY_PACKAGE "__APP_SVC_PKG_NAME__" +#define BUNDLE_KEY_WINDOW "__APP_SVC_K_WIN_ID__" + typedef enum { SERVICE_TYPE_REQUEST, @@ -62,6 +68,8 @@ typedef struct service_request_context_s { void *user_data; } *service_request_context_h; +extern int appsvc_allow_transient_app(bundle *b, unsigned int id); + static int service_create_reply(bundle *data, struct service_s **service); static const char* service_error_to_string(service_error_e error) @@ -193,7 +201,6 @@ static void service_request_result_broker(bundle *appsvc_bundle, int appsvc_requ } user_data = request_context->user_data; - reply_cb = request_context->reply_cb; if (reply_cb != NULL) @@ -205,6 +212,14 @@ static void service_request_result_broker(bundle *appsvc_bundle, int appsvc_requ service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, "invalid callback "); } + service_destroy(reply); + + if (request_context->service != NULL) + { + service_destroy(request_context->service); + } + + free(request_context); } @@ -287,11 +302,6 @@ int service_create_event(bundle *data, struct service_s **service) return SERVICE_ERROR_NONE; } -int service_impl_create_event(bundle *data, struct service_s **service) -{ - return service_create_event(data, service); -} - static int service_create_reply(bundle *data, struct service_s **service) { struct service_s *service_reply; @@ -485,16 +495,29 @@ int service_get_mime(service_h service, char **mime) int service_set_package(service_h service, const char *package) { + // TODO: this function must be deprecated + return service_set_app_id(service, package); +} + +int service_get_package(service_h service, char **package) +{ + // TODO: this function must be deprecated + return service_get_app_id(service, package); +} + + +int service_set_app_id(service_h service, const char *app_id) +{ if (service_valiate_service(service)) { return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); } - if (package != NULL) + if (app_id != NULL) { - if (appsvc_set_pkgname(service->data, package) != 0) + if (appsvc_set_pkgname(service->data, app_id) != 0) { - return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, "invalid package"); + return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, "invalid application ID"); } } else @@ -505,24 +528,70 @@ int service_set_package(service_h service, const char *package) return SERVICE_ERROR_NONE; } -int service_get_package(service_h service, char **package) + +int service_get_app_id(service_h service, char **app_id) { - const char *package_value; + const char *app_id_value; - if (service_valiate_service(service) || package == NULL) + if (service_valiate_service(service) || app_id == NULL) + { + return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); + } + + app_id_value = appsvc_get_pkgname(service->data); + + if (app_id_value != NULL) + { + *app_id = strdup(app_id_value); + } + else + { + *app_id = NULL; + } + + return SERVICE_ERROR_NONE; +} + +int service_set_window(service_h service, unsigned int id) +{ + if (service_valiate_service(service)) + { + return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); + } + + if (id > 0) + { + if (appsvc_allow_transient_app(service->data, id) != 0) + { + return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, "invalid id"); + } + } + else + { + bundle_del(service->data, BUNDLE_KEY_WINDOW); + } + + return SERVICE_ERROR_NONE; +} + +int service_get_window(service_h service, unsigned int *id) +{ + const char *window_id; + + if (service_valiate_service(service) || id == NULL) { return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); } - package_value = appsvc_get_pkgname(service->data); + window_id = bundle_get_val(service->data, BUNDLE_KEY_WINDOW); - if (package_value != NULL) + if (window_id != NULL) { - *package = strdup(package_value); + *id = atoi(window_id); } else { - *package = NULL; + *id = 0; } return SERVICE_ERROR_NONE; @@ -594,8 +663,9 @@ int service_send_launch_request(service_h service, service_reply_cb callback, vo if (callback != NULL) { + service_h request_clone = NULL; + request_context = calloc(1, sizeof(struct service_request_context_s)); - // request_context will be deallocated from service_request_result_broker() if (request_context == NULL) { @@ -603,7 +673,14 @@ int service_send_launch_request(service_h service, service_reply_cb callback, vo } request_context->reply_cb = callback; - request_context->service = service; + + if (service_clone(&request_clone, service) != SERVICE_ERROR_NONE) + { + free(request_context); + return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, "failed to clone the service request handle"); + } + + request_context->service = request_clone; request_context->user_data = user_data; } @@ -1023,3 +1100,133 @@ int service_foreach_app_matched(service_h service, service_app_matched_cb callba return SERVICE_ERROR_NONE; } + +int service_get_caller(service_h service, char **package) +{ + const char *bundle_value; + pid_t caller_pid; + char package_buf[TIZEN_PATH_MAX] = {0, }; + char *package_dup; + + if (service_valiate_service(service) || package == NULL) + { + return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); + } + + if (service->type != SERVICE_TYPE_EVENT) + { + return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, "invalid service handle type"); + } + + bundle_value = bundle_get_val(service->data, AUL_K_ORG_CALLER_PID); + + if (bundle_value == NULL) + { + bundle_value = bundle_get_val(service->data, AUL_K_CALLER_PID); + } + + if (bundle_value == NULL) + { + return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, "failed to retrieve the pid of the caller"); + } + + caller_pid = atoi(bundle_value); + + if (caller_pid <= 0) + { + return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, "invalid pid of the caller"); + } + + if (aul_app_get_pkgname_bypid(caller_pid, package_buf, sizeof(package_buf)) != AUL_R_OK) + { + return service_error(SERVICE_ERROR_APP_NOT_FOUND, __FUNCTION__, "failed to get the package name of the caller"); + } + + package_dup = strdup(package_buf); + + if (package_dup == NULL) + { + return service_error(SERVICE_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL); + } + + *package = package_dup; + + return SERVICE_ERROR_NONE; +} + + +int service_is_reply_requested(service_h service, bool *requested) +{ + const char *bundle_value; + + if (service_valiate_service(service) || requested == NULL) + { + return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); + } + + if (service->type != SERVICE_TYPE_EVENT) + { + return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, "invalid service handle type"); + } + + bundle_value = bundle_get_val(service->data, AUL_K_WAIT_RESULT); + + if (bundle_value != NULL) + { + *requested = true; + } + else + { + *requested = false; + } + + return SERVICE_ERROR_NONE; +} + +int service_import_from_bundle(service_h service, bundle *data) +{ + bundle *data_dup = NULL; + + if (service_valiate_service(service) || data == NULL) + { + return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); + } + + data_dup = bundle_dup(data); + + if (data_dup == NULL) + { + return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, "failed to duplicate the bundle"); + } + + if (service->data != NULL) + { + bundle_free(service->data); + } + + service->data = data_dup; + + return SERVICE_ERROR_NONE; +} + +int service_export_as_bundle(service_h service, bundle **data) +{ + bundle *data_dup = NULL; + + if (service_valiate_service(service) || data == NULL) + { + return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); + } + + data_dup = bundle_dup(service->data); + + if (data_dup == NULL) + { + return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, "failed to duplicate the bundle"); + } + + *data = data_dup; + + return SERVICE_ERROR_NONE; +} + diff --git a/src/ui_notification.c b/src/ui_notification.c index 2b54902..0df0991 100755 --- a/src/ui_notification.c +++ b/src/ui_notification.c @@ -11,7 +11,7 @@ * 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. + * limitations under the License. */ @@ -43,6 +43,8 @@ struct ui_notification_s { char *title; char *content; service_h service; + char *sound; + bool vibration; }; static int ui_notification_error_handler(int error, const char *func, const char *on_error) @@ -69,7 +71,7 @@ static int ui_notification_error_handler(int error, const char *func, const char case NOTIFICATION_ERROR_FROM_DB: retcode = UI_NOTIFICATION_ERROR_DB_FAILED; error_msg = "DB_FAILED"; - break; + break; case NOTIFICATION_ERROR_ALREADY_EXIST_ID: case NOTIFICATION_ERROR_NOT_EXIST_ID: @@ -108,7 +110,7 @@ int ui_notification_create(bool ongoing, ui_notification_h *notification) LOGE("[%s] OUT_OF_MEMORY(0x%08x)", __FUNCTION__, UI_NOTIFICATION_ERROR_OUT_OF_MEMORY); return UI_NOTIFICATION_ERROR_OUT_OF_MEMORY; } - + notification_out->raw_handle = NULL; notification_out->ongoing = ongoing; notification_out->posted = false; @@ -118,7 +120,9 @@ int ui_notification_create(bool ongoing, ui_notification_h *notification) notification_out->title = NULL; notification_out->content = NULL; notification_out->service = NULL; - + notification_out->sound = NULL; + notification_out->vibration = false; + *notification = notification_out; return UI_NOTIFICATION_ERROR_NONE; @@ -133,6 +137,9 @@ static int ui_notification_construct(bool ongoing, notification_h raw_handle, ui char *title; char *content; bundle *service_data; + const char *sound; + notification_sound_type_e sound_type; + notification_vibration_type_e vib_type; if (notification == NULL) { @@ -155,22 +162,22 @@ static int ui_notification_construct(bool ongoing, notification_h raw_handle, ui { return retcode; } - + notification_out->ongoing = ongoing; notification_out->posted = true; notification_out->removed = false; - if (!notification_get_image(raw_handle, NOTIFICATION_IMAGE_TYPE_ICON, &icon)) + if (!notification_get_image(raw_handle, NOTIFICATION_IMAGE_TYPE_ICON, &icon) && icon) { - notification_out->icon = icon; + notification_out->icon = strdup(icon); } if (!notification_get_time(raw_handle, &time)) { notification_out->time = malloc(sizeof(struct tm)); - + if (notification_out->time == NULL) { ui_notification_destroy(notification_out); @@ -181,14 +188,27 @@ static int ui_notification_construct(bool ongoing, notification_h raw_handle, ui localtime_r(&time, notification_out->time); } - if (!notification_get_text(raw_handle, NOTIFICATION_TEXT_TYPE_TITLE, &title)) + if (!notification_get_text(raw_handle, NOTIFICATION_TEXT_TYPE_TITLE, &title) && title) { - notification_out->title = title; + notification_out->title = strdup(title); } - if (! notification_get_text(raw_handle, NOTIFICATION_TEXT_TYPE_CONTENT, &content)) + if (!notification_get_text(raw_handle, NOTIFICATION_TEXT_TYPE_CONTENT, &content) && content) { - notification_out->content = content; + notification_out->content = strdup(content); + } + + if (!notification_get_sound(raw_handle, &sound_type, &sound) && sound) + { + notification_out->sound = strdup(sound); + } + + if (!notification_get_vibration(raw_handle, &vib_type, NULL)) + { + if (vib_type == NOTIFICATION_VIBRATION_TYPE_DEFAULT) + { + notification_out->vibration = true; + } } if (!notification_get_execute_option(raw_handle, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, NULL, &service_data)) @@ -229,6 +249,9 @@ int ui_notification_destroy(ui_notification_h notification) if (notification->content) free(notification->content); + if (notification->sound) + free(notification->sound); + if (notification->service) service_destroy(notification->service); @@ -290,6 +313,13 @@ int ui_notification_clone(ui_notification_h *clone, ui_notification_h notificati notification_out->content = strdup(notification->content); } + if (notification->sound) + { + notification_out->sound = strdup(notification->sound); + } + + notification_out->vibration = notification->vibration; + if (notification->service) { service_clone(&(notification_out->service), notification->service); @@ -422,7 +452,7 @@ int ui_notification_get_time(ui_notification_h notification, struct tm **time) LOGE("[%s] OUT_OF_MEMORY(0x%08x)", __FUNCTION__, UI_NOTIFICATION_ERROR_OUT_OF_MEMORY); return UI_NOTIFICATION_ERROR_OUT_OF_MEMORY; } - + memcpy(time_dup, notification->time, sizeof(struct tm)); } @@ -622,6 +652,91 @@ int ui_notification_get_service(ui_notification_h notification, service_h *servi return UI_NOTIFICATION_ERROR_NONE; } +int ui_notification_set_sound(ui_notification_h notification, const char *path) +{ + char *path_dup = NULL; + + if (notification == NULL) + { + LOGE("[%s] INVALID_PARAMETER(0x%08x)", __FUNCTION__, UI_NOTIFICATION_ERROR_INVALID_PARAMETER); + return UI_NOTIFICATION_ERROR_INVALID_PARAMETER; + } + + if (path != NULL) + { + path_dup = strdup(path); + + if (path_dup == NULL) + { + LOGE("[%s] OUT_OF_MEMORY(0x%08x)", __FUNCTION__, UI_NOTIFICATION_ERROR_OUT_OF_MEMORY); + return UI_NOTIFICATION_ERROR_OUT_OF_MEMORY; + } + } + + if (notification->sound != NULL) + { + free(notification->sound); + } + + notification->sound = path_dup; + + return UI_NOTIFICATION_ERROR_NONE; +} + +int ui_notification_get_sound(ui_notification_h notification, char **path) +{ + char *path_dup = NULL; + + if (notification == NULL || path == NULL) + { + LOGE("[%s] INVALID_PARAMETER(0x%08x)", __FUNCTION__, UI_NOTIFICATION_ERROR_INVALID_PARAMETER); + return UI_NOTIFICATION_ERROR_INVALID_PARAMETER; + } + + if (notification->sound != NULL) + { + path_dup = strdup(notification->sound); + + if (path_dup == NULL) + { + LOGE("[%s] OUT_OF_MEMORY(0x%08x)", __FUNCTION__, UI_NOTIFICATION_ERROR_OUT_OF_MEMORY); + *path = NULL; + + return UI_NOTIFICATION_ERROR_OUT_OF_MEMORY; + } + } + + *path = path_dup; + + return UI_NOTIFICATION_ERROR_NONE; +} + +int ui_notification_set_vibration(ui_notification_h notification, bool value) +{ + if (notification == NULL) + { + LOGE("[%s] INVALID_PARAMETER(0x%08x)", __FUNCTION__, UI_NOTIFICATION_ERROR_INVALID_PARAMETER); + return UI_NOTIFICATION_ERROR_INVALID_PARAMETER; + } + + notification->vibration = value; + + return UI_NOTIFICATION_ERROR_NONE; +} + +int ui_notification_get_vibration(ui_notification_h notification, bool *value) +{ + if (notification == NULL || value == NULL) + { + LOGE("[%s] INVALID_PARAMETER(0x%08x)", __FUNCTION__, UI_NOTIFICATION_ERROR_INVALID_PARAMETER); + return UI_NOTIFICATION_ERROR_INVALID_PARAMETER; + } + + *value = notification->vibration; + + return UI_NOTIFICATION_ERROR_NONE; +} + static int ui_notification_build_attributes(ui_notification_h notification) { bundle *service_data; @@ -635,7 +750,7 @@ static int ui_notification_build_attributes(ui_notification_h notification) if (notification->icon != NULL) { struct stat st; - + if (stat(notification->icon, &st) < 0) { LOGE("[%s] NO_SUCH_FILE(0x%08x) : invalid icon", __FUNCTION__, UI_NOTIFICATION_ERROR_NO_SUCH_FILE); @@ -670,6 +785,23 @@ static int ui_notification_build_attributes(ui_notification_h notification) notification_set_property(notification->raw_handle, NOTIFICATION_PROP_DISABLE_APP_LAUNCH); } + if (notification->sound != NULL) + { + struct stat st; + + if (stat(notification->sound, &st) < 0) + { + LOGE("[%s] NO_SUCH_FILE(0x%08x) : invalid sound file", __FUNCTION__, UI_NOTIFICATION_ERROR_NO_SUCH_FILE); + return UI_NOTIFICATION_ERROR_NO_SUCH_FILE; + } + notification_set_sound(notification->raw_handle, NOTIFICATION_SOUND_TYPE_USER_DATA, notification->sound); + } + + if (notification->vibration) + { + notification_set_vibration(notification->raw_handle, NOTIFICATION_VIBRATION_TYPE_DEFAULT, NULL); + } + return UI_NOTIFICATION_ERROR_NONE; } @@ -801,7 +933,7 @@ int ui_notification_update_progress(ui_notification_h notification, ui_notifica notification_update_size(notification->raw_handle, NOTIFICATION_PRIV_ID_NONE, value), __FUNCTION__, "failed to update the progress"); break; - + case UI_NOTIFICATION_PROGRESS_TYPE_PERCENTAGE: retcode = ui_notification_error_handler( notification_update_progress(notification->raw_handle, NOTIFICATION_PRIV_ID_NONE, value), @@ -864,6 +996,50 @@ void ui_notification_cancel_all(void) notification_delete_all_by_type(NULL, NOTIFICATION_TYPE_NONE); } +void ui_notification_cancel_all_by_type(bool ongoing) +{ + notification_type_e type = NOTIFICATION_TYPE_NONE; + + if (ongoing) + type = NOTIFICATION_TYPE_ONGOING; + else + type = NOTIFICATION_TYPE_NOTI; + + notification_delete_all_by_type(NULL, type); +} + +void ui_notification_cancel_all_by_package(const char *package, bool ongoing) +{ + notification_type_e type = NOTIFICATION_TYPE_NONE; + + if (ongoing) + type = NOTIFICATION_TYPE_ONGOING; + else + type = NOTIFICATION_TYPE_NOTI; + + notification_delete_all_by_type(package, type); +} + +int ui_notification_cancel_all_by_app_id(const char *app_id, bool ongoing) +{ + notification_type_e type = NOTIFICATION_TYPE_NONE; + + if (app_id == NULL) + { + LOGE("[%s] INVALID_PARAMETER(0x%08x)", __FUNCTION__, UI_NOTIFICATION_ERROR_INVALID_PARAMETER); + return UI_NOTIFICATION_ERROR_INVALID_PARAMETER; + } + + if (ongoing) + type = NOTIFICATION_TYPE_ONGOING; + else + type = NOTIFICATION_TYPE_NOTI; + + notification_delete_all_by_type(app_id, type); + + return UI_NOTIFICATION_ERROR_NONE; +} + static bool ui_notification_package_equal(notification_h handle) { char *package = NULL; |