Release Tizen2.0 beta
[framework/location/libslp-location.git] / location / manager / location-common-util.c
index 290a6e0..4e178d0 100644 (file)
  * limitations under the License.
  */
 
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdio.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <location-appman.h>
+
 #include "location.h"
 #include "location-common-util.h"
 #include "location-setting.h"
 #include "location-log.h"
 
+
+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);
+               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);
+                       return FALSE;
+               }
+       } else {
+               LOCATION_LOGD("[%s] is already registered. Update recently used time", appman->package);
+               time(&timestamp);
+               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");
+               return FALSE;
+       }
+       return enabled;
+}
+
 static gint compare_position (gconstpointer a, gconstpointer b)
 {
        g_return_val_if_fail(a, 1);
@@ -169,3 +223,11 @@ int set_prop_removal_boundary(GList **prev_boundary_list, LocationBoundary* boun
 
        return LOCATION_ERROR_NONE;
 }
+
+void free_boundary_list (gpointer data)
+{
+       LocationBoundary *boundary = (LocationBoundary *)data;
+
+       location_boundary_free(boundary);
+}
+