+ if (apps_to_remove == NULL)
+ {
+ /* there are no apps to be removed from this LUC type, just copy
+ * all currently registered apps over */
+ g_variant_builder_add (&builder, "{s@as}", luc_type, current_apps);
+ }
+ else
+ {
+ /* we need to remove some apps from the current LUC type, so let's
+ * build a new string array */
+ g_variant_builder_init (&apps_builder, G_VARIANT_TYPE ("as"));
+
+ /* add all apps currently registered for this LUC type to the string
+ * array unless they are to be removed */
+ for (n = 0, num_apps = 0;
+ current_apps != NULL && n < g_variant_n_children (current_apps);
+ n++)
+ {
+ g_variant_get_child (current_apps, n, "&s", &app);
+ if (!g_variant_string_array_has_string (apps_to_remove, app))
+ {
+ g_variant_builder_add (&apps_builder, "s", app);
+ num_apps++;
+ }
+ }
+
+ /* add the LUC type and its apps to the new context unless there are none */
+ if (num_apps > 0)
+ g_variant_builder_add (&builder, "{sas}", luc_type, &apps_builder);
+
+ /* free resources used for building the string array */
+ g_variant_builder_clear (&apps_builder);
+ }
+
+ /* release the apps to be removed for this LUC type */
+ if (apps_to_remove != NULL)
+ g_variant_unref (apps_to_remove);
+ }
+
+ /* apply the new last user context */
+ new_context = g_variant_builder_end (&builder);
+ luc_handler_set_last_user_context (service->interface, new_context);
+
+ /* notify the caller that we have handled the deregistration request */
+ g_dbus_method_invocation_return_value (invocation, NULL);