Lock on unplug
Here's a hack for Gnome (vaguely relevant to Android too) that I've been using for a little while. When I get up from a computer, I generally want to lock the screensaver. I also pick up my phone from a USB dock (not the Nexus One Desktop Dock; that doesn't connect to a computer). So why not have the screensaver lock automatically when the phone disappears from USB? This is helpful when you're hurriedly picking up the phone to answer a call, and might otherwise forget to lock the screen. Of course, if you get a lot of calls that you want to answer while looking at your computer, this is not for you. :-)
This is pretty easy to achieve using udev. First we ask udev to run a script when this device disappears. The following goes in /etc/udev/rules.d/51-android.rules (or a similar name; the number is used for ordering). While I'm at it, I'll set sensible permissions and group ownership, using the first line.
1 # Set mode and group for (some) devices made by HTC 2 SUBSYSTEM=="usb", ATTRS{idVendor}=="18d1", MODE="0660", GROUP="mygroup" 3 # Nexus One without debugging enabled 4 SUBSYSTEM=="usb", ATTRS{idVendor}=="18d1", ATTRS{idProduct}=="4e11", \ 5 ATTRS{serial}=="HT123P456789", ENV{IS_MY_PHONE}="yes" 6 # Nexus One with debugging enabled 7 SUBSYSTEM=="usb", ATTRS{idVendor}=="18d1", ATTRS{idProduct}=="4e12", \ 8 ATTRS{serial}=="HT123P456789", ENV{IS_MY_PHONE}="yes" 9 # You could unlock on connect if you want: 10 #ENV{IS_MY_PHONE}=="yes", ACTION=="add", RUN+="/somewhere/unlock" 11 # Lock when my phone goes away 12 ENV{IS_MY_PHONE}=="yes", ACTION=="remove", RUN+="/somewhere/lock"
- The device doesn't have to be a Nexus One or a phone at all, run
lsusbto find youridVendor/idProductvalues (for Android, this may differ when you turn on/off USB debugging). - To find your device's serial number, run
sudo lsusb -vand look foriSerial(or runadb devicesif you already set that up). - Pick somewhere to put the lock script referenced in the last line.
- The contents of that script should be:
1 #!/bin/sh 2 exec su user -c ". /home/user/.dbus/session-bus/*-0; \ 3 export DBUS_SESSION_BUS_ADDRESS; \ 4 gnome-screensaver-command --lock"
The unlock script would be the same with --deactivate. Replace user with your username, and if your display isn't :0 then you might need to do something smarter to get the right session bus. Oh, and I'm on Ubuntu Karmic (9.10); adjustments may be required for other environments. When you've done all that, run sudo reload udev to pick up the changes, unplug the phone, and watch the screen fade to black.
Question: how easy is it to fake a serial number of a USB device? Equivalently, how silly is it to have the unlock line uncommented? I'm guessing fairly easy.
Have you seen Matt's bluemon (http://www.matthew.ath.cx/projects/bluemon/)? Basically the same but without the USB cable. :-) Probably more secure too (unusually!); it's almost certainly trivial to fake a USB serial number given a USB device chip.
PS: my browser (Firefox 3.6.3 / Windows) doesn't trust your SSL certificate.
Oops, looks like I was supplying the wrong intermediate certificate, fixed now. I had seen bluemon, but at work I've had so much trouble with bluetooth (too many other devices at a guess) that I doubt it would be reliable, and at home I'd wonder about the possibility of accidentally sitting in a position with strong signal strength in the room directly below the machine in question. Probably worth giving it another try though.