From e786d511b015bc2d495233df6ab7f52938798de1 Mon Sep 17 00:00:00 2001 From: Anish Mangal Date: Mon, 06 Feb 2012 15:25:44 +0000 Subject: v2, olpc#10363: Inhitbit suspend when sharing, joining and inviting (private share) In dextrose, and as the bug history of olpc#10363 and au#1049 suggests, power management kicking in doesnt work well with activities that are collaborating. This patch inhibits the ability to suspend when sharing, joining and inviting to a private share. Changelog * v2 Check for path exists before removing * v1 Initial version --- diff --git a/src/sugar/activity/activity.py b/src/sugar/activity/activity.py index 4938caf..0070210 100644 --- a/src/sugar/activity/activity.py +++ b/src/sugar/activity/activity.py @@ -97,6 +97,8 @@ J_DBUS_SERVICE = 'org.laptop.Journal' J_DBUS_PATH = '/org/laptop/Journal' J_DBUS_INTERFACE = 'org.laptop.Journal' +POWERD_INHIBIT_DIR = '/var/run/powerd-inhibit-suspend' + CONN_INTERFACE_ACTIVITY_PROPERTIES = 'org.laptop.Telepathy.ActivityProperties' @@ -713,6 +715,18 @@ class Activity(Window, gtk.Container): else: self._jobject.metadata['share-scope'] = SCOPE_NEIGHBORHOOD + def _inhibit_suspend(self): + if not os.path.exists(POWERD_INHIBIT_DIR): + return + + path = os.path.join(POWERD_INHIBIT_DIR, str(os.getpid())) + try: + fd = open(path, 'w') + except IOError: + logging.error("Inhibit Suspend: Could not create file %s", path) + else: + fd.close() + def __joined_cb(self, activity, success, err): """Callback when join has finished""" logging.debug('Activity.__joined_cb %r', success) @@ -722,6 +736,8 @@ class Activity(Window, gtk.Container): logging.debug('Failed to join activity: %s', err) return + self._inhibit_suspend() + self.reveal() self.emit('joined') self.__privacy_changed_cb(self.shared_activity, None) @@ -750,6 +766,8 @@ class Activity(Window, gtk.Container): activity.props.name = self._jobject.metadata['title'] + self._inhibit_suspend() + self.shared_activity = activity self.shared_activity.connect('notify::private', self.__privacy_changed_cb) @@ -864,6 +882,11 @@ class Activity(Window, gtk.Container): # Make the exported object inaccessible dbus.service.Object.remove_from_connection(self._bus) + if os.path.exists(POWERD_INHIBIT_DIR): + path = os.path.join(POWERD_INHIBIT_DIR, str(os.getpid())) + if os.path.exists(path): + os.unlink(path) + self._session.unregister(self) def close(self, skip_save=False): -- cgit v0.9.1