Strange behavior in user idle detection in Adobe Air on Mac
Asked Answered
S

1

6

I've got an Adobe AIR application written in pure AS3 that has some functionality that happens when the user is idle and then returns to the normal state when the user returns. I'm detecting this activity with the following code:

NativeApplication.nativeApplication.idleThreshold = 180;
NativeApplication.nativeApplication.addEventListener(Event.USER_IDLE, onUserIdle);
NativeApplication.nativeApplication.addEventListener(Event.USER_PRESENT, onUserPresent);

The onUserIdle method is called after 3 minutes as it should be, but then the onUserPresent event is fired almost immediately afterwards. I'm talking milliseconds later. This happens without any user input whatsoever. The bizarre thing is that this does not occur on Windows - only on OSX. And it happens on all flavors of OSX going back to 10.6.3.

Adobe's documentation is incredibly vague on how those events are determined, so I'm not sure if there is something I can do at the system level to fix the problem. Does anyone have any experience with this issue, and if not, any other suggestions on how I can detect user idleness even when the app does not have focus?

Just to preempt the suggestion, I cannot use mouse/keyboard listeners to simulate the same behavior because they do not work if the application loses focus, whereas the NativeApplication events still fire. I've also used NativeProcess to get the output of ioreg to get the hardware idle time as reported by the system, but it does not appear to be affected by the mouse.

I really appreciate any assistance.

Edit: I just discovered that this does not occur when the application is run in an Administrator account on OSX. It only happens in a User account, which only serves to confuse me more.

Statant answered 16/10, 2012 at 1:37 Comment(3)
I wonder if the threshold value is being reset somehow or just ignored. What happens if you invert the order of 2nd and 3rd lines?Divulgence
@SauloSilva Interesting that you ask that because I have in fact done that and there was no difference in the observed behavior. The threshold value is constant and correct when I trace it out in the event handlers. One thing that I just discovered (and I'll update the question) is that this is not happening in an Administrator account - this is only happening in a normal User account - which throws a giant monkey wrench into the situation!Statant
Wow. This seems to be a bug. Here is a similar one: forums.adobe.com/thread/570669Divulgence
S
1

I figured out what the issue is. When the USER_IDLE event is fired in a user account, we did several things - one of which was forcibly kill the Dock in order to make sure it was hidden from the screen. For whatever reason, this resets the internally available idleThreshold count. This was not only happening in AIR - it was also happening when monitored through Terminal and it appears there is absolutely nothing that can be done to stop it. The solution was to stop killing the dock. Everything magically worked after that.

Statant answered 16/10, 2012 at 18:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.