Beispiel #1
0
/**
 * gpm_control_suspend:
 **/
gboolean
gpm_control_suspend (GpmControl *control, GError **error)
{
	gboolean allowed;
	gboolean ret = FALSE;
	gboolean do_lock;
	gboolean nm_sleep;
	GpmScreensaver *screensaver;
	guint32 throttle_cookie = 0;
#ifdef WITH_KEYRING
	gboolean lock_mate_keyring;
	MateKeyringResult keyres;
#endif /* WITH_KEYRING */

	screensaver = gpm_screensaver_new ();

	g_object_get (control->priv->client,
		      "can-suspend", &allowed,
		      NULL);
	if (!allowed) {
		egg_debug ("cannot suspend as not allowed from policy");
		g_set_error_literal (error, GPM_CONTROL_ERROR, GPM_CONTROL_ERROR_GENERAL, "Cannot suspend");
		goto out;
	}

#ifdef WITH_KEYRING
	/* we should perhaps lock keyrings when sleeping #375681 */
	lock_mate_keyring = g_settings_get_boolean (control->priv->settings, GPM_SETTINGS_LOCK_KEYRING_SUSPEND);
	if (lock_mate_keyring) {
		keyres = mate_keyring_lock_all_sync ();
		if (keyres != MATE_KEYRING_RESULT_OK)
			egg_warning ("could not lock keyring");
	}
#endif /* WITH_KEYRING */

	do_lock = gpm_control_get_lock_policy (control, GPM_SETTINGS_LOCK_ON_SUSPEND);
	if (do_lock) {
		throttle_cookie = gpm_screensaver_add_throttle (screensaver, "suspend");
		gpm_screensaver_lock (screensaver);
	}

	nm_sleep = g_settings_get_boolean (control->priv->settings, GPM_SETTINGS_NETWORKMANAGER_SLEEP);
	if (nm_sleep)
		gpm_networkmanager_sleep ();

	/* Do the suspend */
	egg_debug ("emitting sleep");
	g_signal_emit (control, signals [SLEEP], 0, GPM_CONTROL_ACTION_SUSPEND);

	ret = up_client_suspend_sync (control->priv->client, NULL, error);

	egg_debug ("emitting resume");
	g_signal_emit (control, signals [RESUME], 0, GPM_CONTROL_ACTION_SUSPEND);

	if (do_lock) {
		gpm_screensaver_poke (screensaver);
		if (throttle_cookie)
			gpm_screensaver_remove_throttle (screensaver, throttle_cookie);
	}

	nm_sleep = g_settings_get_boolean (control->priv->settings, GPM_SETTINGS_NETWORKMANAGER_SLEEP);
	if (nm_sleep)
		gpm_networkmanager_wake ();

out:
	g_object_unref (screensaver);
	return ret;
}
Beispiel #2
0
/**
 * gpm_control_suspend:
 **/
gboolean
gpm_control_suspend (GpmControl *control, GError **error)
{
	gboolean allowed;
	gboolean ret = FALSE;
	gboolean do_lock;
	gboolean nm_sleep;
	GpmScreensaver *screensaver;
	guint32 throttle_cookie = 0;
#ifdef WITH_KEYRING
	gboolean lock_mate_keyring;
	MateKeyringResult keyres;
#endif /* WITH_KEYRING */
#ifdef WITH_SYSTEMD_SLEEP
	GError *dbus_error = NULL;
	DBusGProxy *proxy;
	GVariant *res;
#endif

	screensaver = gpm_screensaver_new ();
#ifndef WITH_SYSTEMD_SLEEP
	g_object_get (control->priv->client,
		      "can-suspend", &allowed,
		      NULL);
	if (!allowed) {
		egg_debug ("cannot suspend as not allowed from policy");
		g_set_error_literal (error, GPM_CONTROL_ERROR, GPM_CONTROL_ERROR_GENERAL, "Cannot suspend");
		goto out;
	}
#endif

#ifdef WITH_KEYRING
	/* we should perhaps lock keyrings when sleeping #375681 */
	lock_mate_keyring = g_settings_get_boolean (control->priv->settings, GPM_SETTINGS_LOCK_KEYRING_SUSPEND);
	if (lock_mate_keyring) {
		keyres = mate_keyring_lock_all_sync ();
		if (keyres != MATE_KEYRING_RESULT_OK)
			egg_warning ("could not lock keyring");
	}
#endif /* WITH_KEYRING */

	do_lock = gpm_control_get_lock_policy (control, GPM_SETTINGS_LOCK_ON_SUSPEND);
	if (do_lock) {
		throttle_cookie = gpm_screensaver_add_throttle (screensaver, "suspend");
		gpm_screensaver_lock (screensaver);
	}

	nm_sleep = g_settings_get_boolean (control->priv->settings, GPM_SETTINGS_NETWORKMANAGER_SLEEP);
	if (nm_sleep)
		gpm_networkmanager_sleep ();

	/* Do the suspend */
	egg_debug ("emitting sleep");
	g_signal_emit (control, signals [SLEEP], 0, GPM_CONTROL_ACTION_SUSPEND);

#ifdef WITH_SYSTEMD_SLEEP
	/* sleep via logind */
	proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
			G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES,
			NULL,
			"org.freedesktop.login1",
			"/org/freedesktop/login1",
			"org.freedesktop.login1.Manager",
			NULL,
			&dbus_error );
    if (proxy == NULL) {
        egg_error("Error connecting to dbus - %s", dbus_error->message);
        g_error_free (dbus_error);
        return -1;
    }
    g_dbus_proxy_call_sync (proxy, "Suspend", 
                            g_variant_new( "(b)",FALSE),
                            G_DBUS_CALL_FLAGS_NONE,
                            -1,
                            NULL,
                            &dbus_error
                            );
    if (dbus_error != NULL ) {
	    egg_debug ("Error in dbus - %s", dbus_error->message);
	    g_error_free (dbus_error);
	    ret = TRUE;
    }
    else {
	    ret = TRUE;
    }
    g_object_unref(proxy);
#else
	ret = up_client_suspend_sync (control->priv->client, NULL, error);
#endif

	egg_debug ("emitting resume");
	g_signal_emit (control, signals [RESUME], 0, GPM_CONTROL_ACTION_SUSPEND);

	if (do_lock) {
		gpm_screensaver_poke (screensaver);
		if (throttle_cookie)
			gpm_screensaver_remove_throttle (screensaver, throttle_cookie);
	}

	nm_sleep = g_settings_get_boolean (control->priv->settings, GPM_SETTINGS_NETWORKMANAGER_SLEEP);
	if (nm_sleep)
		gpm_networkmanager_wake ();

out:
	g_object_unref (screensaver);
	return ret;
}