Bug in idle time patch

17 views
Skip to first unread message

Paul Kim

unread,
Feb 5, 2008, 8:25:51 PM2/5/08
to spark...@googlegroups.com
Hi all,

It appears there is a bug in the Tiger version of
CGEventSourceSecondsSinceLastEventType() which is used by my previous
patch which would delay showing an update alert until the user was
idle. It appears on at least some, if not all, Tiger systems, this
call hangs indefinitely. In SUUpdater, you can patch the conditional
around line 512 with the following:

long version;

if ([delayAlerts boolValue] && !verbose &&
(Gestalt(gestaltSystemVersion, &version) == noErr) && (version >=
0x1050))

I'll submit a formal patch to Tom when I hear back from him but the
patch above just checks for Leopard. I apologize for not having tested
this properly on a Tiger machine.

If you have any questions about this, let me know.

Paul Kim

Evan Schoenberg

unread,
Feb 5, 2008, 8:48:06 PM2/5/08
to spark...@googlegroups.com
The following code works on Mac OS X 10.1 through 10.5 for determining the idle time:

extern CFTimeInterval CGSSecondsSinceLastInputEvent(unsigned long evType);

/*!
 * @brief Returns the current machine idle time
 *
 * Returns the current number of seconds the machine has been idle.  The machine is idle when there are no input
 * events from the user (such as mouse movement or keyboard input) or when the screen saver is active.
 * In addition to this method, the status controller sends out notifications when the machine becomes idle,
 * stays idle, and returns to an active state.
 */
- (CFTimeInterval)currentMachineIdle
{
CFTimeInterval idleTime;

/* CGSSecondsSinceLastInputEvent is a private function available in 10.2 and later. Note that CGEventSourceSecondsSinceLastEventType()
* should work as of 10.4 but doesn't return a sensical value.
*/
idleTime = CGSSecondsSinceLastInputEvent(-1);


/* On MDD Powermacs, the above function will return a large value when the machine is active (perhaps a -1?).
* Here we check for that value and correctly return a 0 idle time.
*/
if (idleTime >= 18446744000.0) idleTime = 0.0; //18446744073.0 is the lowest I've seen on my MDD -ai


    return idleTime;

Paul Kim

unread,
Feb 5, 2008, 9:07:27 PM2/5/08
to spark...@googlegroups.com
Hey Evan,

Well, I can integrate that into the patch if Tom feels that using private API is ok.

According to the code comment, it says that function returns a bad value. I'm seeing that it never returns at all (at least for 10.4.10 and 10.4.11). Do you know for certain that this function actually returned on certain versions of 10.4?

Paul

Evan Schoenberg

unread,
Feb 5, 2008, 9:48:20 PM2/5/08
to spark...@googlegroups.com
In 10.4 (don't recall which minor version) it definitely returned the nanoseconds since the user logged in, a totally useless value. I filed a radar on it which was closed with no explanation by apple. 

Cheers,
Evan
Reply all
Reply to author
Forward
0 new messages