portal: Add a getter for dconf access

Add method to find whether the sandbox provides
access to dconf. This will be used to tweak
the priorities for the keyfile settings backend.
This commit is contained in:
Matthias Clasen 2019-07-12 11:30:30 -04:00 committed by Philip Withnall
parent 618d3e4a0a
commit 9c5d3a6081
2 changed files with 19 additions and 0 deletions

View File

@ -23,6 +23,7 @@
static gboolean flatpak_info_read; static gboolean flatpak_info_read;
static gboolean use_portal; static gboolean use_portal;
static gboolean network_available; static gboolean network_available;
static gboolean dconf_access;
static void static void
read_flatpak_info (void) read_flatpak_info (void)
@ -40,11 +41,13 @@ read_flatpak_info (void)
use_portal = TRUE; use_portal = TRUE;
network_available = FALSE; network_available = FALSE;
dconf_access = FALSE;
keyfile = g_key_file_new (); keyfile = g_key_file_new ();
if (g_key_file_load_from_file (keyfile, path, G_KEY_FILE_NONE, NULL)) if (g_key_file_load_from_file (keyfile, path, G_KEY_FILE_NONE, NULL))
{ {
char **shared = NULL; char **shared = NULL;
char *dconf_policy = NULL;
shared = g_key_file_get_string_list (keyfile, "Context", "shared", NULL, NULL); shared = g_key_file_get_string_list (keyfile, "Context", "shared", NULL, NULL);
if (shared) if (shared)
@ -52,6 +55,14 @@ read_flatpak_info (void)
network_available = g_strv_contains ((const char * const *)shared, "network"); network_available = g_strv_contains ((const char * const *)shared, "network");
g_strfreev (shared); g_strfreev (shared);
} }
dconf_policy = g_key_file_get_string (keyfile, "Session Bus Policy", "ca.desrt.dconf", NULL);
if (dconf_policy)
{
if (strcmp (dconf_policy, "talk") == 0)
dconf_access = TRUE;
g_free (dconf_policy);
}
} }
g_key_file_unref (keyfile); g_key_file_unref (keyfile);
@ -64,6 +75,7 @@ read_flatpak_info (void)
if (var && var[0] == '1') if (var && var[0] == '1')
use_portal = TRUE; use_portal = TRUE;
network_available = TRUE; network_available = TRUE;
dconf_access = TRUE;
} }
} }
@ -81,3 +93,9 @@ glib_network_available_in_sandbox (void)
return network_available; return network_available;
} }
gboolean
glib_has_dconf_access_in_sandbox (void)
{
read_flatpak_info ();
return dconf_access;
}

View File

@ -24,6 +24,7 @@ G_BEGIN_DECLS
gboolean glib_should_use_portal (void); gboolean glib_should_use_portal (void);
gboolean glib_network_available_in_sandbox (void); gboolean glib_network_available_in_sandbox (void);
gboolean glib_has_dconf_access_in_sandbox (void);
G_END_DECLS G_END_DECLS