summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZeeshan Ali (Khattak) <zeeshanak@gnome.org>2016-02-10 18:23:35 +0000
committerZeeshan Ali (Khattak) <zeeshanak@gnome.org>2016-02-11 14:37:37 +0000
commit56620f03d7b7988878065675fd4b9179cf9e7e55 (patch)
treef12c3a1f1dae686de0643c0ba769a36ded01675a
parentb6166f72a3d516396e366cab10aa6e8207ce9fec (diff)
-rw-r--r--demo/gclue-service-agent.c36
-rw-r--r--libgeoclue/gclue-helpers.c63
-rw-r--r--src/agent/org.freedesktop.GeoClue2.Agent.xml24
-rw-r--r--src/gclue-config.c1
-rw-r--r--src/gclue-service-client.c56
-rw-r--r--src/org.freedesktop.GeoClue2.Client.xml15
6 files changed, 166 insertions, 29 deletions
diff --git a/demo/gclue-service-agent.c b/demo/gclue-service-agent.c
index 5b51c23..6fea1b9 100644
--- a/demo/gclue-service-agent.c
+++ b/demo/gclue-service-agent.c
@@ -315,23 +315,26 @@ on_notify_closed (NotifyNotification *notification,
gpointer user_data)
{
NotificationData *data = (NotificationData *) user_data;
+ GVariant *variant = g_variant_new ("(ddd)", 0, 0, 0);
if (data->authorized)
g_debug ("Authorized '%s'", g_app_info_get_display_name (data->app_info));
else
g_debug ("'%s' not authorized", g_app_info_get_display_name (data->app_info));
- gclue_agent_complete_authorize_app (data->agent,
- data->invocation,
- data->authorized,
- data->accuracy_level);
+ gclue_agent_complete_authorize_app2 (data->agent,
+ data->invocation,
+ data->authorized,
+ data->accuracy_level,
+ variant);
notification_data_free (data);
}
static gboolean
-gclue_service_agent_handle_authorize_app (GClueAgent *agent,
- GDBusMethodInvocation *invocation,
- const char *desktop_id,
- GClueAccuracyLevel accuracy_level)
+gclue_service_agent_handle_authorize_app2 (GClueAgent *agent,
+ GDBusMethodInvocation *invocation,
+ const char *desktop_id,
+ GClueAccuracyLevel accuracy_level,
+ const char *reason)
{
NotifyNotification *notification;
NotificationData *data;
@@ -344,10 +347,11 @@ gclue_service_agent_handle_authorize_app (GClueAgent *agent,
app_info = G_APP_INFO (g_desktop_app_info_new (desktop_file));
if (app_info == NULL) {
g_debug ("Failed to find %s", desktop_file);
- gclue_agent_complete_authorize_app (agent,
- invocation,
- FALSE,
- accuracy_level);
+ gclue_agent_complete_authorize_app2 (agent,
+ invocation,
+ FALSE,
+ accuracy_level,
+ NULL);
return TRUE;
}
@@ -355,6 +359,11 @@ gclue_service_agent_handle_authorize_app (GClueAgent *agent,
msg = g_strdup_printf (_("Allow '%s' to access your location information?"),
g_app_info_get_display_name (app_info));
+ if (reason != NULL && reason[0] != '/') {
+ char *tmp = msg;
+ msg = g_strdup_printf ("%s\n%s", msg, reason);
+ g_free (tmp);
+ }
notification = notify_notification_new (_("Geolocation"), msg, "dialog-question");
g_free (msg);
@@ -382,6 +391,7 @@ gclue_service_agent_handle_authorize_app (GClueAgent *agent,
data);
if (!notify_notification_show (notification, &error)) {
+ g_critical ("Failed to show notification: %s\n", error->message);
g_dbus_method_invocation_take_error (invocation, error);
notification_data_free (data);
@@ -394,7 +404,7 @@ gclue_service_agent_handle_authorize_app (GClueAgent *agent,
static void
gclue_service_agent_agent_iface_init (GClueAgentIface *iface)
{
- iface->handle_authorize_app = gclue_service_agent_handle_authorize_app;
+ iface->handle_authorize_app2 = gclue_service_agent_handle_authorize_app2;
}
static void
diff --git a/libgeoclue/gclue-helpers.c b/libgeoclue/gclue-helpers.c
index 5639eb6..1e2b9d7 100644
--- a/libgeoclue/gclue-helpers.c
+++ b/libgeoclue/gclue-helpers.c
@@ -142,6 +142,69 @@ on_manager_proxy_ready (GObject *source_object,
}
/**
+ * gclue_client_proxy_create_full:
+ * @desktop_id: The desktop file id (the basename of the desktop file).
+ * @accuracy_level: The requested accuracy level as #GClueAccuracyLevel.
+ * @reason: The reason to access the location data, as translated (by
+ * application) free-form string.
+ * @cancellable: (allow-none): A #GCancellable or %NULL.
+ * @callback: A #GAsyncReadyCallback to call when the results are ready.
+ * @user_data: User data to pass to @callback.
+ *
+ * A utility function to create a #GClueClientProxy without having to deal with
+ * a #GClueManager.
+ *
+ * See #gclue_client_proxy_create_sync() for the synchronous, blocking version
+ * of this function.
+ */
+void
+gclue_client_proxy_create_full (const char *desktop_id,
+ GClueAccuracyLevel accuracy_level,
+ const char *reason,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ GTask *task;
+ ClientCreateData *data;
+
+ task = g_task_new (NULL, cancellable, callback, user_data);
+
+ data = client_create_data_new (desktop_id, accuracy_level, reason);
+ g_task_set_task_data (task,
+ data,
+ (GDestroyNotify) client_create_data_free);
+
+ gclue_manager_proxy_new_for_bus (G_BUS_TYPE_SYSTEM,
+ G_DBUS_PROXY_FLAGS_NONE,
+ BUS_NAME,
+ MANAGER_PATH,
+ cancellable,
+ on_manager_proxy_ready,
+ task);
+}
+
+/**
+ * gclue_client_proxy_create_full_finish:
+ * @result: The #GAsyncResult obtained from the #GAsyncReadyCallback passed to
+ * gclue_client_proxy_create_full().
+ * @error: Return location for error or %NULL.
+ *
+ * Finishes an operation started with gclue_client_proxy_create().
+ *
+ * Returns: (transfer full) (type GClueClientProxy): The constructed proxy
+ * object or %NULL if @error is set.
+ */
+GClueClient *
+gclue_client_proxy_create_full_finish (GAsyncResult *result,
+ GError **error)
+{
+ g_return_val_if_fail (g_task_is_valid (result, NULL), NULL);
+
+ return g_task_propagate_pointer (G_TASK (result), error);
+}
+
+/**
* gclue_client_proxy_create:
* @desktop_id: The desktop file id (the basename of the desktop file).
* @accuracy_level: The requested accuracy level as #GClueAccuracyLevel.
diff --git a/src/agent/org.freedesktop.GeoClue2.Agent.xml b/src/agent/org.freedesktop.GeoClue2.Agent.xml
index e8217df..178a377 100644
--- a/src/agent/org.freedesktop.GeoClue2.Agent.xml
+++ b/src/agent/org.freedesktop.GeoClue2.Agent.xml
@@ -27,7 +27,8 @@
@allowed_accuracy_level: The level of location accuracy allowed for client, as <link linkend="GClueAccuracyLevel">GClueAccuracyLevel</link>.
This is the method that will be called by geoclue to get applications
- authorized to be given location information.
+ authorized to be given location information. Deprecated in favor of
+ org.freedesktop.GeoClue2.Agent.AuthorizeApp2.
-->
<method name="AuthorizeApp">
<arg name="desktop_id" type="s" direction="in"/>
@@ -37,6 +38,27 @@
</method>
<!--
+ AuthorizeApp2:
+ @desktop_id: The desktop file id (the basename of the desktop file) of the application requesting location information.
+ @req_accuracy_level: The level of location accuracy requested by client, as <link linkend="GClueAccuracyLevel">GClueAccuracyLevel</link>.
+ @reason: The application-provided reason for access to location data, as freeform text.
+ @authorized: Return value indicating if application should be given location information or not.
+ @allowed_accuracy_level: The level of location accuracy allowed for client, as <link linkend="GClueAccuracyLevel">GClueAccuracyLevel</link>.
+ @location: User/agent can use this to dictate location to be given to user, although currently it's completely ignored and is only added here for future safety. Format is latitiude, longitude, accuracy (in meters).
+
+ This is the method that will be called by geoclue to get applications
+ authorized to be given location information.
+ -->
+ <method name="AuthorizeApp2">
+ <arg name="desktop_id" type="s" direction="in"/>
+ <arg name="req_accuracy_level" type="u" direction="in"/>
+ <arg name="reason" type="s" direction="in"/>
+ <arg name="authorized" type="b" direction="out"/>
+ <arg name="allowed_accuracy_level" type="u" direction="out"/>
+ <arg name="location" type="(ddd)" direction="out"/>
+ </method>
+
+ <!--
MaxAccuracyLevel:
The global maximum level of accuracy allowed for all clients. Since
diff --git a/src/gclue-config.c b/src/gclue-config.c
index 2298a37..1408066 100644
--- a/src/gclue-config.c
+++ b/src/gclue-config.c
@@ -299,6 +299,7 @@ gclue_config_is_agent_allowed (GClueConfig *config,
gsize i;
for (i = 0; i < config->priv->num_agents; i++) {
+ g_print ("\nChecking %s\n", config->priv->agents[i]);
if (g_strcmp0 (desktop_id, config->priv->agents[i]) == 0)
return TRUE;
}
diff --git a/src/gclue-service-client.c b/src/gclue-service-client.c
index 68564c7..a4327ff 100644
--- a/src/gclue-service-client.c
+++ b/src/gclue-service-client.c
@@ -286,6 +286,8 @@ typedef struct
GDBusMethodInvocation *invocation;
char *desktop_id;
GClueAccuracyLevel accuracy_level;
+
+ gboolean auth2_failed;
} StartData;
static void
@@ -320,12 +322,34 @@ on_authorize_app_ready (GObject *source_object,
GError *error = NULL;
gboolean authorized = FALSE;
- if (!gclue_agent_call_authorize_app_finish (GCLUE_AGENT (source_object),
- &authorized,
- &data->accuracy_level,
- res,
- &error))
- goto error_out;
+ if (data->auth2_failed) {
+ if (!gclue_agent_call_authorize_app_finish
+ (priv->agent_proxy,
+ &authorized,
+ &data->accuracy_level,
+ res,
+ &error))
+ goto error_out;
+ } else {
+ if (!gclue_agent_call_authorize_app2_finish
+ (priv->agent_proxy,
+ &authorized,
+ &data->accuracy_level,
+ NULL,
+ res,
+ &error)) {
+ // Try V1 then
+ g_print ("Now trying v1\n");
+ data->auth2_failed = TRUE;
+ gclue_agent_call_authorize_app (priv->agent_proxy,
+ data->desktop_id,
+ data->accuracy_level,
+ NULL,
+ on_authorize_app_ready,
+ data);
+ return;
+ }
+ }
if (!authorized) {
guint32 uid;
@@ -360,7 +384,7 @@ gclue_service_client_handle_start (GClueDBusClient *client,
GClueServiceClientPrivate *priv = GCLUE_SERVICE_CLIENT (client)->priv;
GClueConfig *config;
StartData *data;
- const char *desktop_id;
+ const char *desktop_id, *reason;
GClueAccuracyLevel max_accuracy;
GClueAppPerm app_perm;
guint32 uid;
@@ -439,13 +463,17 @@ gclue_service_client_handle_start (GClueDBusClient *client,
"Max accuracy level allowed by agent: %u",
data->accuracy_level, max_accuracy);
data->accuracy_level = CLAMP (data->accuracy_level, 0, max_accuracy);
-
- gclue_agent_call_authorize_app (priv->agent_proxy,
- desktop_id,
- data->accuracy_level,
- NULL,
- on_authorize_app_ready,
- data);
+ reason = gclue_dbus_client_get_reason (client);
+ if (reason == NULL)
+ reason = "/";
+
+ gclue_agent_call_authorize_app2 (priv->agent_proxy,
+ desktop_id,
+ data->accuracy_level,
+ reason,
+ NULL,
+ on_authorize_app_ready,
+ data);
return TRUE;
}
diff --git a/src/org.freedesktop.GeoClue2.Client.xml b/src/org.freedesktop.GeoClue2.Client.xml
index cff6830..95bdf69 100644
--- a/src/org.freedesktop.GeoClue2.Client.xml
+++ b/src/org.freedesktop.GeoClue2.Client.xml
@@ -44,7 +44,8 @@
DesktopId:
The desktop file id (the basename of the desktop file). This property
- must be set by applications for authorization to work.
+ must be set by applications for authorization to work, unless your app
+ is an xdg-app bundle.
-->
<property name="DesktopId" type="s" access="readwrite"/>
@@ -61,6 +62,18 @@
<property name="RequestedAccuracyLevel" type="u" access="readwrite"/>
<!--
+ Reason:
+
+ The reason for accessing location data. This is free-form localized (by
+ application) string that is presented to users when they are asked if
+ they'd like to give access to location data to your application.
+
+ While it is not mandatory to set this property, it is highly recommended
+ to do so.
+ -->
+ <property name="Reason" type="s" access="readwrite"/>
+
+ <!--
Active:
If client is active, i-e started successfully using