X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=location%2Fmanager%2Flocation-common-util.c;h=e7aa284fb916ed4cff47d53edc58e40519753ec6;hb=refs%2Ftags%2Faccepted%2Ftizen%2F4.0%2Funified%2F20170829.020414;hp=8bf7e678db0bdab409ee173e367fbdfd20efffc1;hpb=8844d894be764f9924fea5a9415f9203b97c02a3;p=platform%2Fcore%2Flocation%2Flbs-location.git diff --git a/location/manager/location-common-util.c b/location/manager/location-common-util.c index 8bf7e67..e7aa284 100644 --- a/location/manager/location-common-util.c +++ b/location/manager/location-common-util.c @@ -3,9 +3,6 @@ * * Copyright (c) 2010-2013 Samsung Electronics Co., Ltd. All rights reserved. * - * Contact: Youngae Kang , Minjune Kim - * Genie Kim - * * 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 @@ -24,172 +21,40 @@ #endif #include +#include #include #include -#include #include "location.h" #include "location-common-util.h" #include "location-setting.h" #include "location-log.h" +#include -int location_application_get_authority (void) +int location_application_get_authority(void) { - pid_t pid = getpid(); - location_appman_s *appman; - int enabled; - int found; - - if (location_appman_get_package_by_pid(pid, &appman) != LOCATION_APPMAN_ERROR_NONE) { - LOCATION_LOGE("Fail to location_appman_get_package_by_pid"); - return LOCATION_APP_NOT_FOUND; - } - - if (location_appman_find_package(appman->package, &found) != LOCATION_APPMAN_ERROR_NONE || found == LOCATION_APPMAN_PACKAGE_NOTFOUND) { - LOCATION_LOGE("Cannot find package [%s]", appman->package); - return LOCATION_APP_NOT_FOUND; - } - - if (location_appman_is_enabled(appman->package, &enabled) != LOCATION_APPMAN_ERROR_NONE) { - LOCATION_LOGE("Fail to location_appman_is_enabled"); - return LOCATION_APP_NOT_FOUND; - } - - if (enabled) { - return LOCATION_APP_ON; - } - else { - return LOCATION_APP_OFF; - - } - - return LOCATION_APP_NOT_FOUND; + return LOCATION_APP_ON; } -int location_application_set_authority (int auth) +int location_application_set_authority(int auth) { - pid_t pid = getpid(); - location_appman_s *appman; - int enabled; - int found; - - if (location_appman_get_package_by_pid(pid, &appman) != LOCATION_APPMAN_ERROR_NONE) { - LOCATION_LOGE("Fail to location_appman_get_package_by_pid"); - return LOCATION_ERROR_UNKNOWN; - } - - if (location_appman_find_package(appman->package, &found) != LOCATION_APPMAN_ERROR_NONE || found == LOCATION_APPMAN_PACKAGE_NOTFOUND) { - LOCATION_LOGE("Cannot find package [%s]", appman->package); - return LOCATION_ERROR_UNKNOWN; - } - - if (location_appman_set_on(appman->package, auth) != LOCATION_APPMAN_ERROR_NONE) { - LOCATION_LOGE("Fail to location_appman_is_enabled"); - return LOCATION_ERROR_UNKNOWN; - } - return LOCATION_ERROR_NONE; } -int location_application_add_app_to_applist (void) -{ - pid_t pid = getpid(); - location_appman_s *appman; - int found; - time_t timestamp; - - if (location_appman_get_package_by_pid(pid, &appman) != LOCATION_APPMAN_ERROR_NONE) { - LOCATION_LOGE("Fail to location_appman_get_package_by_pid"); - return FALSE; - } - - if (location_appman_find_package(appman->package, &found) != LOCATION_APPMAN_ERROR_NONE) { - LOCATION_LOGE("Cannot find package [%s]", appman->package); - if (appman) g_free(appman); - return FALSE; - } - - if (found == LOCATION_APPMAN_PACKAGE_NOTFOUND) { - LOCATION_LOGD("First time to use location [%s]", appman->package); - if (location_appman_register_package(appman) != LOCATION_APPMAN_ERROR_NONE) { - LOCATION_LOGE("Fail to register [%s]", appman->package); - if (appman) g_free(appman); - return FALSE; - } - } else { - LOCATION_LOGD("[%s] is already registered. Update recently used time", appman->package); - if (appman) g_free(appman); - return FALSE; - } - - if (appman) g_free(appman); - return TRUE; -} - -int location_application_enabled (void) -{ - pid_t pid = getpid(); - location_appman_s *appman; - int enabled; - int found; - time_t timestamp; - - if (TRUE == location_appman_check_developer_mode()) { - LOCATION_LOGE("Location is Enabled"); - return TRUE; - } - - if (location_appman_get_package_by_pid(pid, &appman) != LOCATION_APPMAN_ERROR_NONE) { - LOCATION_LOGE("Fail to location_appman_get_package_by_pid"); - return FALSE; - } - - if (location_appman_find_package(appman->package, &found) != LOCATION_APPMAN_ERROR_NONE) { - LOCATION_LOGE("Cannot find package [%s]", appman->package); - if (appman) g_free(appman); - return FALSE; - } - - if (found == LOCATION_APPMAN_PACKAGE_NOTFOUND) { - LOCATION_LOGD("First time to use location [%s]", appman->package); - if (location_appman_register_package(appman) != LOCATION_APPMAN_ERROR_NONE) { - LOCATION_LOGE("Fail to register [%s]", appman->package); - if (appman) g_free(appman); - return FALSE; - } - } else { - LOCATION_LOGD("[%s] is already registered. Update recently used time", appman->package); - time(×tamp); - if (location_appman_set_recently_used(appman->package, timestamp) != LOCATION_APPMAN_ERROR_NONE) { - LOCATION_LOGD("Cannot update recently used time"); - } - } - - if (location_appman_is_enabled(appman->package, &enabled) != LOCATION_APPMAN_ERROR_NONE) { - LOCATION_LOGE("Fail to location_appman_is_enabled"); - if (appman) g_free(appman); - return FALSE; - } - - if (appman) g_free(appman); - return enabled; -} - -static gint compare_position (gconstpointer a, gconstpointer b) +static gint compare_position(gconstpointer a, gconstpointer b) { g_return_val_if_fail(a, 1); g_return_val_if_fail(b, -1); - if(location_position_equal((LocationPosition*) a, (LocationPosition *)b) == TRUE) { + if (location_position_equal((LocationPosition *) a, (LocationPosition *)b) == TRUE) return 0; - } return -1; } static int -boundary_compare (gconstpointer comp1, gconstpointer comp2) +boundary_compare(gconstpointer comp1, gconstpointer comp2) { g_return_val_if_fail(comp1, 1); g_return_val_if_fail(comp2, -1); @@ -202,69 +67,73 @@ boundary_compare (gconstpointer comp1, gconstpointer comp2) if (priv1->boundary->type == priv2->boundary->type) { switch (priv1->boundary->type) { case LOCATION_BOUNDARY_CIRCLE: { - if (location_position_equal(priv1->boundary->circle.center, priv2->boundary->circle.center) - && priv1->boundary->circle.radius == priv2->boundary->circle.radius) { - ret = 0; + if (location_position_equal(priv1->boundary->circle.center, priv2->boundary->circle.center) + && priv1->boundary->circle.radius == priv2->boundary->circle.radius) { + ret = 0; + } + break; } - break; - } case LOCATION_BOUNDARY_RECT: { - if (location_position_equal(priv1->boundary->rect.left_top, priv2->boundary->rect.left_top) - && location_position_equal(priv1->boundary->rect.right_bottom, priv2->boundary->rect.right_bottom)) { - ret = 0; + if (location_position_equal(priv1->boundary->rect.left_top, priv2->boundary->rect.left_top) + && location_position_equal(priv1->boundary->rect.right_bottom, priv2->boundary->rect.right_bottom)) { + ret = 0; + } + break; } - break; - } case LOCATION_BOUNDARY_POLYGON: { - GList *boundary1_next = NULL; - GList *boundary2_start = NULL, *boundary2_prev = NULL, *boundary2_next = NULL; - if (g_list_length(priv1->boundary->polygon.position_list) != g_list_length(priv2->boundary->polygon.position_list)) { - return -1; - } + GList *boundary1_next = NULL; + GList *boundary2_start = NULL, *boundary2_prev = NULL, *boundary2_next = NULL; + if (g_list_length(priv1->boundary->polygon.position_list) != g_list_length(priv2->boundary->polygon.position_list)) + return -1; - // Find a matching index of Boundary2 with Boundary1's 1st postion. - boundary2_start = g_list_find_custom(priv2->boundary->polygon.position_list, g_list_nth_data(priv1->boundary->polygon.position_list, 0), (GCompareFunc) compare_position); - if (boundary2_start == NULL) return -1; - - boundary2_prev = g_list_previous(boundary2_start); - boundary2_next = g_list_next(boundary2_start); - if (boundary2_prev == NULL) boundary2_prev = g_list_last(priv2->boundary->polygon.position_list); - if (boundary2_next == NULL) boundary2_next = g_list_first(priv2->boundary->polygon.position_list); - - boundary1_next = g_list_next(priv1->boundary->polygon.position_list); - if (location_position_equal((LocationPosition*)boundary1_next->data, (LocationPosition*)boundary2_prev->data) == TRUE){ - boundary1_next = g_list_next(boundary1_next); - while (boundary1_next) { - boundary2_prev = g_list_previous(boundary2_prev); - if (boundary2_prev == NULL) boundary2_prev = g_list_last(priv2->boundary->polygon.position_list); - if (location_position_equal((LocationPosition*)boundary1_next->data, (LocationPosition*) boundary2_prev->data) == FALSE){ - return -1; - } + /* Find a matching index of Boundary2 with Boundary1's 1st postion. */ + boundary2_start = g_list_find_custom(priv2->boundary->polygon.position_list, g_list_nth_data(priv1->boundary->polygon.position_list, 0), (GCompareFunc) compare_position); + if (boundary2_start == NULL) return -1; + + boundary2_prev = g_list_previous(boundary2_start); + boundary2_next = g_list_next(boundary2_start); + if (boundary2_prev == NULL) + boundary2_prev = g_list_last(priv2->boundary->polygon.position_list); + + if (boundary2_next == NULL) + boundary2_next = g_list_first(priv2->boundary->polygon.position_list); + + boundary1_next = g_list_next(priv1->boundary->polygon.position_list); + if (boundary1_next && location_position_equal((LocationPosition *)boundary1_next->data, (LocationPosition *)boundary2_prev->data) == TRUE) { boundary1_next = g_list_next(boundary1_next); - } - ret = 0; - } - else if (location_position_equal((LocationPosition*)boundary1_next->data, (LocationPosition*)boundary2_next->data) == TRUE) { - boundary1_next = g_list_next(boundary1_next); - while(boundary1_next) { - boundary2_next = g_list_next(boundary2_next); - if (boundary2_next == NULL) boundary2_next = g_list_first(priv2->boundary->polygon.position_list); - if (location_position_equal((LocationPosition*)boundary1_next->data, (LocationPosition*) boundary2_next->data) == FALSE){ - return -1; + while (boundary1_next) { + boundary2_prev = g_list_previous(boundary2_prev); + if (boundary2_prev == NULL) + boundary2_prev = g_list_last(priv2->boundary->polygon.position_list); + + if (location_position_equal((LocationPosition *)boundary1_next->data, (LocationPosition *) boundary2_prev->data) == FALSE) + return -1; + + boundary1_next = g_list_next(boundary1_next); } + ret = 0; + } else if (boundary1_next && location_position_equal((LocationPosition *)boundary1_next->data, (LocationPosition *)boundary2_next->data) == TRUE) { boundary1_next = g_list_next(boundary1_next); + while (boundary1_next) { + boundary2_next = g_list_next(boundary2_next); + if (boundary2_next == NULL) + boundary2_next = g_list_first(priv2->boundary->polygon.position_list); + + if (location_position_equal((LocationPosition *)boundary1_next->data, (LocationPosition *) boundary2_next->data) == FALSE) + return -1; + + boundary1_next = g_list_next(boundary1_next); + } + ret = 0; + } else { + return -1; } - ret = 0; + break; } - else { - return -1; + default: { + ret = -1; + break; } - break; - } - default:{ - ret = -1; - break; - } } } @@ -274,61 +143,133 @@ boundary_compare (gconstpointer comp1, gconstpointer comp2) int set_prop_boundary(GList **prev_boundary_priv_list, GList *new_boundary_priv_list) { + LOC_FUNC_LOG g_return_val_if_fail(new_boundary_priv_list, LOCATION_ERROR_PARAMETER); int index = 0; GList *check_list = NULL; LocationBoundaryPrivate *new_priv = NULL; - LocationBoundaryPrivate *copy_priv = g_slice_new0(LocationBoundaryPrivate); - while((new_priv = (LocationBoundaryPrivate *) g_list_nth_data(new_boundary_priv_list, index)) != NULL) { + while ((new_priv = (LocationBoundaryPrivate *) g_list_nth_data(new_boundary_priv_list, index)) != NULL) { + *prev_boundary_priv_list = g_list_first(*prev_boundary_priv_list); check_list = g_list_find_custom(*prev_boundary_priv_list, new_priv, (GCompareFunc)boundary_compare); if (check_list == NULL) { - LOCATION_LOGD("Set Prop >> boundary type: [%d]", new_priv->boundary->type); + LocationBoundaryPrivate *copy_priv = g_slice_new0(LocationBoundaryPrivate); + if (!copy_priv) break; copy_priv->boundary = location_boundary_copy(new_priv->boundary); + if (!copy_priv->boundary) break; copy_priv->zone_status = new_priv->zone_status; *prev_boundary_priv_list = g_list_append(*prev_boundary_priv_list, copy_priv); + + LOCATION_LOGD("copy_priv: %p, copy_priv->boundary: %p, copy_priv->boundary->type: %d", copy_priv, copy_priv->boundary, copy_priv->boundary->type); } + location_boundary_free(new_priv->boundary); index++; } - *prev_boundary_priv_list = g_list_first(*prev_boundary_priv_list); return LOCATION_ERROR_NONE; } - -int set_prop_removal_boundary(GList **prev_boundary_list, LocationBoundary* boundary) +int set_prop_removal_boundary(GList **prev_boundary_list, LocationBoundary *boundary) { + LOC_FUNC_LOG g_return_val_if_fail(*prev_boundary_list, LOCATION_ERROR_PARAMETER); GList *check_list = NULL; LocationBoundaryPrivate *remove_priv = g_slice_new0(LocationBoundaryPrivate); + g_return_val_if_fail(remove_priv, LOCATION_ERROR_PARAMETER); remove_priv->boundary = location_boundary_copy(boundary); + g_return_val_if_fail(remove_priv->boundary, LOCATION_ERROR_PARAMETER); - check_list = g_list_find_custom (*prev_boundary_list, remove_priv, (GCompareFunc) boundary_compare); + check_list = g_list_find_custom(*prev_boundary_list, remove_priv, (GCompareFunc) boundary_compare); if (check_list) { LOCATION_LOGD("Found"); *prev_boundary_list = g_list_delete_link(*prev_boundary_list, check_list); - g_slice_free(LocationBoundaryPrivate, remove_priv); } - if (g_list_length(*prev_boundary_list) == 0 ) { + if (g_list_length(*prev_boundary_list) == 0) { LOCATION_LOGD("Boundary List is empty"); g_list_free(*prev_boundary_list); *prev_boundary_list = NULL; } + location_boundary_free(remove_priv->boundary); g_slice_free(LocationBoundaryPrivate, remove_priv); + + LOCATION_LOGD("EXIT <<<"); return LOCATION_ERROR_NONE; } -void free_boundary_list (gpointer data) +void free_boundary_list(gpointer data) { - LocationBoundaryPrivate *priv= (LocationBoundaryPrivate *)data; + LocationBoundaryPrivate *priv = (LocationBoundaryPrivate *)data; location_boundary_free(priv->boundary); g_slice_free(LocationBoundaryPrivate, priv); } +int location_get_app_type(char *target_app_id) +{ + int ret = 0; + pid_t pid = 0; + char *app_id = NULL; + app_info_h app_info; + char *type = NULL; + + if (target_app_id == NULL) { + pid = getpid(); + ret = app_manager_get_app_id(pid, &app_id); + LOC_COND_RET(ret != APP_MANAGER_ERROR_NONE, LOCATION_ERROR_NONE, _E, "Fail to get app_id. Err[%d]", ret); + } else { + app_id = g_strdup(target_app_id); + } + + ret = app_info_create(app_id, &app_info); + if (ret != APP_MANAGER_ERROR_NONE) { + LOCATION_LOGE("Fail to get app_info. Err[%d]", ret); + g_free(app_id); + return LOCATION_ERROR_NONE; + } + + ret = app_info_get_type(app_info, &type); + if (ret != APP_MANAGER_ERROR_NONE) { + LOCATION_LOGE("Fail to get type. Err[%d]", ret); + g_free(app_id); + app_info_destroy(app_info); + return LOCATION_ERROR_NONE; + } + + if (strcmp(type, "c++app") == 0) + ret = CPPAPP; + else if (strcmp(type, "webapp") == 0) + ret = WEBAPP; + else + ret = CAPP; + + g_free(type); + g_free(app_id); + app_info_destroy(app_info); + + return ret; +} + +const char* err_msg(int err) +{ + switch (err) { + case LOCATION_ERROR_NONE: return "LOCATION_ERROR_NONE"; + case LOCATION_ERROR_NOT_ALLOWED: return "LOCATION_ERROR_NOT_ALLOWED"; + case LOCATION_ERROR_NOT_AVAILABLE: return "LOCATION_ERROR_NOT_AVAILABLE"; + case LOCATION_ERROR_NETWORK_FAILED: return "LOCATION_ERROR_NETWORK_FAILED"; + case LOCATION_ERROR_NETWORK_NOT_CONNECTED: return "LOCATION_ERROR_NETWORK_NOT_CONNECTED"; + case LOCATION_ERROR_CONFIGURATION: return "LOCATION_ERROR_CONFIGURATION"; + case LOCATION_ERROR_PARAMETER: return "LOCATION_ERROR_PARAMETER"; + case LOCATION_ERROR_NOT_FOUND: return "LOCATION_ERROR_NOT_FOUND"; + case LOCATION_ERROR_NOT_SUPPORTED: return "LOCATION_ERROR_NOT_SUPPORTED"; + case LOCATION_ERROR_UNKNOWN: return "LOCATION_ERROR_UNKNOWN"; + case LOCATION_ERROR_SETTING_OFF: return "LOCATION_ERROR_SETTING_OFF"; + case LOCATION_ERROR_SECURITY_DENIED: return "LOCATION_ERROR_SECURITY_DENIED"; + default: return "LOCATION_ERROR_UNKNOWN"; + } +}