Author: Andriy Grytsenko <andrej@rep.kiev.ua>
Description: Remove all dpkg related code from lxsession, it's forbidden by the Debian policy.

--- a/lxsession/app.vala
+++ b/lxsession/app.vala
@@ -1163,534 +1163,6 @@
     }
 }
 
-public class UpdatesManagerApp: SimpleAppObject
-{
-    string updatesmanager_command;
-
-    IconObject updates_icon;
-    MenuObject icon_menu;
-
-    IconObject language_icon;
-
-    IconObject reboot_icon;
-
-    string apt_update_path = "/var/lib/apt/periodic/update-success-stamp";
-    GLib.File apt_update_file ;
-    GLib.FileMonitor apt_update_monitor ;
-
-    string dpkg_update_path = "/var/lib/dpkg/status";
-    GLib.File dpkg_update_file ;
-    GLib.FileMonitor dpkg_update_monitor ;
-
-    string dpkg_run_path = "/var/lib/update-notifier/dpkg-run-stamp";
-    GLib.File dpkg_run_file ;
-    GLib.FileMonitor dpkg_run_monitor ;
-
-    string apt_lists_update_path = "/var/lib/apt/lists";
-    GLib.File apt_lists_update_file ;
-    GLib.FileMonitor apt_lists_update_monitor ;
-
-    string reboot_path = "/var/run/reboot-required";
-    GLib.File reboot_file ;
-    GLib.FileMonitor reboot_monitor ;
-
-    string dpkg_lock_file = "/var/lib/dpkg/lock";
-
-    int lock_check = 0;
-
-    public UpdatesManagerApp ()
-    {
-        init();
-    }
-
-    public override void read_settings()
-    {
-        updatesmanager_command = global_settings.get_item_string("Session", "updates_manager", "command");
-
-        switch (updatesmanager_command)
-        {
-            case null:
-                break;
-            case "":
-                break;
-            case " ":
-                break;
-            case "update-notifier-clone":
-                setup_apt_config();
-                setup_reboot_config();
-                run_check();
-                break;
-            default:
-                string[] create_command = updatesmanager_command.split_set(" ",0);
-                this.name = create_command[0];
-                this.command = create_command;
-                break;
-        }
-    }
-
-    public void test_inactivate()
-    {
-        updates_icon.inactivate();
-    }
-
-    public void test_activate()
-    {
-        updates_icon.activate();
-    }
-
-    public void run_check()
-    {
-        if (this.lock_check == 0)
-        {
-            if (check_lock_file(dpkg_lock_file) == true)
-            {
-                this.lock_check = 1;
-                int timeout = 60;
-                if (global_settings.get_item_string("Session", "updates_manager", "timeout") != null)
-                {
-                    timeout = int.parse(global_settings.get_item_string("Session", "updates_manager", "timeout"));
-                }
-                GLib.Timeout.add_seconds(timeout, on_apt_update_file_change);
-            }
-        }
-    }
-
-    public void reboot_launch()
-    {
-        var session = new SessionObject();
-        session.lxsession_restart();
-    }
-
-    public void run_check_reboot()
-    {
-        string notification_text ="";
-
-        if (this.reboot_file.query_exists ())
-        {
-            if (this.reboot_icon == null)
-            {
-                var reboot_icon_menu = new MenuObject() ;
-                string line = _("Reboot required");
-
-                try
-                {
-                    var dis = new DataInputStream (this.reboot_file.read ());
-                    line = dis.read_line ();
-                }
-                catch (GLib.Error e)
-                {
-                    message ("Error: %s\n", e.message);
-                }
-
-                if (line != null)
-                {
-                    notification_text = line;
-                }
-
-                var menu_item = new MenuItemObject();
-                menu_item.set_label(notification_text);
-                menu_item.activate.connect(() => {
-                    reboot_launch();
-                });
-                menu_item.show();
-                reboot_icon_menu.add(menu_item);
-
-                this.reboot_icon = new IconObject("RebootIcon", "system-reboot", notification_text, reboot_icon_menu);
-                this.reboot_icon.init();
-                this.reboot_icon.clear_actions ();
-                this.reboot_icon.add_action ("launch_reboot", _("Reboot"), () =>
-                {
-                    reboot_launch();
-                });
-                this.reboot_icon.activate();
-            }
-        }
-        else
-        {
-            if (this.reboot_icon != null)
-            {
-                this.reboot_icon.inactivate();
-            }
-        }
-    }
-
-    public void language_launch()
-    {
-        if (this.language_icon != null)
-        {
-            try
-            {
-                Process.spawn_command_line_async("gnome-language-selector");
-                this.language_icon.inactivate();
-            }
-            catch (SpawnError err)
-            {
-                warning (err.message);
-            }
-        }
-    }
-
-    public void check_language_support()
-    {
-        string command = "check-language-support";
-
-        string standard_output;
-        string standard_error;
-        int exit_status;
-
-        string launch_string = _("Launch language support");
-
-        try
-        {
-            Process.spawn_command_line_sync (command, out standard_output, out standard_error, out exit_status);
-
-            message ("Launching %s", command);
-            message ("Language state: %s", standard_error);
-            message ("Language exit status: %i", exit_status);
-            message ("Language output: %s", standard_output);
-
-        }
-        catch (SpawnError err)
-        {
-            warning (err.message);
-        }
-
-        if (standard_output != null)
-        {
-            if (standard_output.length >= 3)
-            {
-                if (this.language_icon == null)
-                {
-                    var language_icon_menu = new MenuObject() ;
-
-                    var menu_item = new MenuItemObject();
-                    menu_item.set_label(launch_string);
-                    menu_item.activate.connect(() => {
-                        language_launch();
-                    });
-                    menu_item.show();
-                    language_icon_menu.add(menu_item);
-
-                    this.language_icon = new IconObject("LanguageIcon", "preferences-desktop-locale", _("Language support missing"), language_icon_menu);
-                    this.language_icon.init();
-                    this.language_icon.clear_actions ();
-                    this.language_icon.add_action ("launch_language_support", launch_string, () =>
-                    {
-                        language_launch();
-                    });
-                    this.language_icon.activate();
-                }
-            }
-            else if (this.language_icon != null)
-                {
-                    this.language_icon.inactivate();
-                }
-        }
-        else if (this.language_icon != null)
-            {
-                this.language_icon.inactivate();
-            }
-    }
-
-    public void upgrade_launch (string upgrade_manager_command)
-    {
-        try
-        {
-            Process.spawn_command_line_async(upgrade_manager_command);
-        }
-        catch (SpawnError err)
-        {
-            warning (err.message);
-        }
-    }
-
-    public bool on_apt_update_file_change()
-    {
-        /* Launch something that check if updates are available */
-        /* For now, use lxsession-apt-check, which is apt-check from update-notifier */
-
-        string standard_output;
-        string standard_error;
-        int exit_status;
-
-        string notification_text = _("Updates available");
-
-        string launch_string = _("Launch Update Manager");
-        string upgrade_manager_command = "";
-
-        string[] updates_num;
-        int updates_urgent = 0;
-        int updates_normal = 0;
-        int updates_state = 0;
-        int number_updates = 0;
-
-        /* Lock the check process, to avoid launching the check many times when one is already running */
-        this.lock_check = 1;
-
-        if (this.icon_menu == null)
-        {
-            this.icon_menu = new MenuObject();
-
-            if (global_settings.get_item_string("Session", "upgrade_manager", "command") != null)
-            {
-                upgrade_manager_command = global_settings.get_item_string("Session", "upgrade_manager", "command");
-
-                var menu_item = new MenuItemObject();
-                menu_item.set_label(launch_string);
-                menu_item.activate.connect(() => {
-                    upgrade_launch (upgrade_manager_command);
-                });
-                menu_item.show();
-                icon_menu.add(menu_item);
-            }
-        }
-
-        string command = "/usr/bin/nice" + " " + "/usr/bin/ionice" + " " + "-c3" + " " + "/usr/lib/update-notifier/apt-check";
-
-        string error_string = "";
-
-        try
-        {
-            Process.spawn_command_line_sync (command, out standard_output, out standard_error, out exit_status);
-
-            message ("Launching %s", command);
-            message ("Update state: %s", standard_error);
-            message ("Update exit status: %i", exit_status);
-
-        }
-        catch (SpawnError err)
-        {
-            warning (err.message);
-        }
-
-        if (this.updates_icon == null)
-        {
-            this.updates_icon = new IconObject("UpdatesIcon", "software-update-available", notification_text, this.icon_menu);
-            this.updates_icon.init();
-            if (global_settings.get_item_string("Session", "upgrade_manager", "command") != null)
-            {
-                upgrade_manager_command = global_settings.get_item_string("Session", "upgrade_manager", "command");
-                this.updates_icon.clear_actions ();
-                this.updates_icon.add_action ("launch_upgrade_manager", launch_string, () =>
-                {
-                    upgrade_launch (upgrade_manager_command);
-                });
-            }
-            this.updates_icon.inactivate();
-        }
-        else
-        {
-            this.updates_icon.inactivate();
-        }
-
-        if (standard_error != "")
-        {
-            if (standard_error[0:1] == "E")
-            {
-                updates_urgent = 0;
-                updates_normal = 0;
-                updates_state = 1;
-                error_string =   _("An error occurred, please run Package Manager from the left-click menu or apt-get in a terminal to see what is wrong.");
-                if (standard_error.length > 3)
-                {
-                    notification_text = error_string + "\n" + _("The error message was: ") + standard_error;
-                }
-                else
-                {
-                    notification_text = error_string;
-                }
-            }
-            else
-                {
-                    updates_num = standard_error.split_set(";",2);
-                    message ("Number of upgrades: %s", updates_num[0]);
-                    message ("Number of security upgrades: %s", updates_num[1]);
-                    updates_num[2] = "0";
-
-                    updates_urgent = int.parse(updates_num[1]);
-                    updates_normal = int.parse(updates_num[0]);
-                    number_updates = updates_normal + updates_urgent;
-
-                    if (number_updates == 1)
-                    {
-                        notification_text = number_updates.to_string() + _(" Update available");
-                    }
-                    else if (number_updates > 1)
-                        {
-                            notification_text = number_updates.to_string() + (" ") + _("Updates available");
-                        }
-                }
-
-        }
-        else
-        {
-            updates_state = 1;
-        }
-
-
-        if (number_updates > 0)
-        {
-            message("Activate icon because of updates available");
-            this.updates_icon.set_notification_body(notification_text);
-            this.updates_icon.activate();
-        }
-
-        if (updates_urgent > 0)
-        {
-            message("Set urgent icon");
-            this.updates_icon.set_icon("software-update-urgent");
-            this.updates_icon.set_notification_body(notification_text);
-        }
-
-
-        if (updates_state > 0)
-        {
-            message("Problem in package state");
-            this.updates_icon.set_icon("software-update-urgent");
-            this.updates_icon.set_notification_body(notification_text);
-            this.updates_icon.clear_actions ();
-            this.updates_icon.add_action ("launch_upgrade_manager", launch_string, () =>
-            {
-                upgrade_launch ("synaptic-pkexec");
-            });
-            var new_menu = new MenuObject();
-            var new_menu_item = new MenuItemObject();
-            new_menu_item.set_label(launch_string);
-            new_menu_item.activate.connect(() => {
-                upgrade_launch ("synaptic-pkexec");
-            });
-            new_menu_item.show();
-            new_menu.add(new_menu_item);
-            this.updates_icon.set_menu(new_menu);
-            this.updates_icon.activate();
-        }
-
-        /* Check if language support is complete */
-        check_language_support();
-
-        /* Check if a reboot is requiered */
-        run_check_reboot();
-
-        /* Unlock the check */
-        this.lock_check = 0;
-
-        return false;
-    }
-
-    public void setup_apt_config ()
-    {
-        /* Note directories monitored by update-notifier :
-                "/var/lib/apt/lists/" ==> files of meta data of the repositories
-                "/var/lib/apt/lists/partial/"
-                "/var/cache/apt/archives/" ==> .deb in cache
-                "/var/cache/apt/archives/partial/"
-
-            Files monitored by update-notifier :
-              "/var/lib/dpkg/status" => big file of dpkg status
-              "/var/lib/update-notifier/dpkg-run-stamp" update-notifier stamp for dpkg ?
-              "/var/lib/apt/periodic/update-success-stamp" 
-        */
-
-        try
-        {
-            this.apt_update_file = File.new_for_path(this.apt_update_path);
-            this.apt_update_monitor = apt_update_file.monitor_file(GLib.FileMonitorFlags.NONE);
-            this.apt_update_monitor.changed.connect(run_check);
-            message ("Monitoring apt changes");
-        }
-        catch (GLib.Error err)
-        {
-            message (err.message);
-        }
-
-        try
-        {
-            this.dpkg_update_file = File.new_for_path(this.dpkg_update_path);
-            this.dpkg_update_monitor = dpkg_update_file.monitor_file(GLib.FileMonitorFlags.NONE);
-            this.dpkg_update_monitor.changed.connect(run_check);
-            message ("Monitoring dpkg changes");
-        }
-        catch (GLib.Error err)
-        {
-            message (err.message);
-        }
-
-        try
-        {
-            this.dpkg_run_file = File.new_for_path(this.dpkg_run_path);
-            this.dpkg_run_monitor = dpkg_run_file.monitor_file(GLib.FileMonitorFlags.NONE);
-            this.dpkg_run_monitor.changed.connect(run_check);
-            message ("Monitoring dpkg run changes");
-        }
-        catch (GLib.Error err)
-        {
-            message (err.message);
-        }
-
-        try
-        {
-            this.apt_lists_update_file = File.new_for_path(this.apt_lists_update_path);
-            this.apt_lists_update_monitor = apt_lists_update_file.monitor_directory(GLib.FileMonitorFlags.NONE);
-            this.apt_lists_update_monitor.changed.connect(run_check);
-            message ("Monitoring apt_lists changes");
-        }
-        catch (GLib.Error err)
-        {
-            message (err.message);
-        }
-    }
-
-    public void setup_reboot_config ()
-    {
-        try
-        {
-            this.reboot_file = File.new_for_path(this.reboot_path);
-            this.reboot_monitor = reboot_file.monitor_file(GLib.FileMonitorFlags.NONE);
-            this.reboot_monitor.changed.connect(run_check_reboot);
-            message ("Monitoring reboot changes");
-        }
-        catch (GLib.Error err)
-        {
-            message (err.message);
-        }
-    }
-
-    /* From https://mail.gnome.org/archives/vala-list/2010-October/msg00036.html */
-    public bool check_lock_file(string check_file)
-    {
-            
-            string lock_file_name = check_file;
-            int fd = Posix.open (lock_file_name, Posix.O_RDWR); 
-            if (fd == -1)
-            {
-              print ("There was an error opening the file '"  
-                + lock_file_name + " (Error number "  
-                + Posix.errno.to_string() + ")\n");
-              return true;
-            }
-                    
-            // Try to get a lock
-            Posix.Flock fl = Posix.Flock();
-            fl.l_type = Posix.F_WRLCK;
-            fl.l_whence = Posix.SEEK_SET;
-            fl.l_start = 100;
-            fl.l_len = 0;
-                    
-            int fcntl_return = Posix.fcntl (fd, Posix.F_SETLK, fl);
-            if (fcntl_return == -1) 
-                    return true;
-                    
-            // Release the lock again
-            fl.l_type = Posix.F_UNLCK;
-            fl.l_whence = Posix.SEEK_SET;
-            fl.l_start = 100;
-            fl.l_len = 0;
-            fcntl_return = Posix.fcntl (fd, Posix.F_SETLK, fl);
-
-            return false;
-    }
-
-}
 public class CrashManagerApp: SimpleAppObject
 {
     string crash_manager_command;
--- a/lxsession/dbus-lxde-session.vala
+++ b/lxsession/dbus-lxde-session.vala
@@ -425,21 +425,6 @@
                         KeyringActivate();
                         break;
 
-                    case "updates_manager":
-                        if (option == "check")
-                        {
-                            UpdatesCheck();
-                        }
-                        else if (option == "activate")
-                            {
-                                UpdatesAct();
-                            }
-                            else if (option == "inactivate")
-                                {
-                                    UpdatesInactivate();
-                                }
-                        break;
-
                     case "crash_manager":
                         if (option == "activate")
                         {
@@ -459,91 +444,6 @@
             }
         }
 
-        private void UpdatesActivate()
-        {
-            message("Reload updates_manager");
-            if (global_settings.get_item_string("Session", "updates_manager", "command") == null)
-            {
-                warning("Updates_manager not set");
-            }
-            else if (global_updates == null)
-            {
-                message("Updates_manager doesn't exist, creating it");
-                var updates = new UpdatesManagerApp();
-                global_updates = updates;
-                global_updates.launch();
-            }
-            else
-            {
-                message("Reload existing Updates_manager");
-                global_updates.reload();
-            }
-        }
-
-        private void UpdatesCheck()
-        {
-            message("Reload updates_manager");
-            if (global_settings.get_item_string("Session", "updates_manager", "command") == null)
-            {
-                warning("Updates_manager not set");
-            }
-            else if (global_updates == null)
-            {
-                message("Updates_manager doesn't exist, creating it");
-                var updates = new UpdatesManagerApp();
-                global_updates = updates;
-                global_updates.launch();
-                global_updates.run_check();
-            }
-            else
-            {
-                message("Check Updates");
-                global_updates.run_check();
-            }
-        }
-
-        private void UpdatesAct()
-        {
-            message("Reload updates_manager");
-            if (global_settings.get_item_string("Session", "updates_manager", "command") == null)
-            {
-                warning("Updates_manager not set");
-            }
-            else if (global_updates == null)
-            {
-                message("Updates_manager doesn't exist, creating it");
-                var updates = new UpdatesManagerApp();
-                global_updates = updates;
-                global_updates.test_activate();
-            }
-            else
-            {
-                message("Check Updates");
-                global_updates.test_activate();
-            }
-        }
-
-        private void UpdatesInactivate()
-        {
-            message("Reload updates_manager");
-            if (global_settings.get_item_string("Session", "updates_manager", "command") == null)
-            {
-                warning("Updates_manager not set");
-            }
-            else if (global_updates == null)
-            {
-                message("Updates_manager doesn't exist, creating it");
-                var updates = new UpdatesManagerApp();
-                global_updates = updates;
-                global_updates.test_inactivate();
-            }
-            else
-            {
-                message("Check Updates");
-                global_updates.test_inactivate();
-            }
-        }
-
         public void CrashManagerLaunch()
         {
             message("Launch crash manager");
@@ -1127,13 +1027,6 @@
             }
         }
 
-        /* Package manager running */
-        public async void PackageManagerRunning (out bool is_running)
-        {
-            message ("Check if package manager is running");
-            is_running = check_package_manager_running();
-        }
-
         /* Test interface */
         public void TestIconNotification()
         {
--- a/lxsession/main.vala
+++ b/lxsession/main.vala
@@ -54,7 +54,6 @@
     XrandrApp global_xrandr;
     KeyringApp global_keyring;
     A11yApp global_a11y;
-    UpdatesManagerApp global_updates;
     CrashManagerApp global_crash;
     GenericSimpleApp global_im1;
     GenericSimpleApp global_im2;
@@ -476,13 +475,6 @@
             global_proxy.launch();
         }
 
-        if (global_settings.get_item_string("Session", "updates_manager", "command") != null)
-        {
-            var updates = new UpdatesManagerApp();
-            global_updates = updates;
-            //global_updates.launch();
-        }
-
         if (global_settings.get_item_string("Session", "crash_manager", "command") != null)
         {
             var crash = new CrashManagerApp();
--- a/lxsession/utils.vala
+++ b/lxsession/utils.vala
@@ -139,37 +139,4 @@
     }
 }
 
-public bool check_package_manager_running ()
-{
-    GLib.File dpkg, apt_archives, apt_lists, unattended_upgrades;
-    bool return_value = false;
-
-    dpkg = File.new_for_path("/var/lib/dpkg/lock");
-    apt_archives = File.new_for_path("/var/cache/apt/archives/lock");
-    apt_lists = File.new_for_path("/var/lib/apt/lists/lock");
-    unattended_upgrades = File.new_for_path("/var/run/unattended-upgrades.lock");
-
-    if (dpkg.query_exists ())
-    {
-        return_value = true;
-    }
-
-    if (apt_archives.query_exists ())
-    {
-        return_value = true;
-    }
-
-    if (apt_lists.query_exists ())
-    {
-        return_value = true;
-    }
-
-    if (unattended_upgrades.query_exists ())
-    {
-        return_value = true;
-    }
-
-    return return_value;
-}
-
 }
