In a Java Swing desktop application running on Linux (e.g., Ubuntu), how can the application be notified that the PC has just resumed from the sleep/suspended/hibernated state?
Screen blanking is not a concern. All other suspended or hibernated states (suspend to RAM or suspend to disk) are of interest (and for my purposes they will all be treated the same).
My goal is to invoke a class method automatically when the PC or device is resumed. (That method needs to restart rxtxSerial, fwiw.)
EDIT: A comment from Thorbjørn Ravn Andersen made me realize my question is not clear. My goal is to listen to an operating system event (or utilize a system log file) that would indication the system has just resumed from a suspended state.
Here’s what the Canonical support engineer suggested.
20/11/2011 22:53 | Jason
My suggestion is to create a script under the /etc/pm/sleep.d/. The script will be execute when resume from suspend. Please reference to the /usr/share/doc/pm-utils/HOWTO.hooks.gz for the details.
Here’s the intro from that file:
How to write a pm-utils hook:
PARAMETERS
A pm-utils hook is simply an executable file that accepts at least one
parameter.
For hooks in sleep.d, the potential values of the first parameter are:
suspend — The hook MUST perform whatever action is appropriate when the
system is preparing for memory sleep (or its equivalent).
resume — The hook MUST perform whatever action is appropriate when the
system is coming out of suspend.
hibernate — The hook MUST perform whatever action is appropriate when
the system is preparing for suspend-to-disk.
thaw — The hook MUST perform whatever action is appropriate when the system
is coming out of suspend-to-disk.
help — If your hook parses the PM_CMDLINE environment variable for switches,
this function SHOULD output text describing the parameters it parses
in a format easily understandable by an end-user.
The actual sleep method being used will be passed as the second parameter —
if your hook needs to handle suspend-hybrid (or any other platform-specific
sleep method), it should examine the second parameter.
For hooks in power.d, the potential values of that parameter are:
true — the hook MUST perform whatever action is appropriate when the system
transitions TO battery power.
false — The hook MUST perform whatever action is appropriate when the system
transitions FROM battery power.
And here’s an example: