you got it right. The sensor sends out a signal, a light, that you can see if you push any of the buttons with the phone locked in low light. My guess as to how it works is it sends out a low-frequency signal, perhaps infared/borderline red light, and if it is reflected back, it recognizes it as being 'covered'. Because it is low-frequency/low-power, it only will recieve the signal back from very short distances. True, most fabric won't block it. If you're wearing tight jeans/pants, then it does work if you put hte screen-side against your leg. But what i did was file down the volume keys anyways. They sit about half as high as they were originally, and now it is very hard for them to be accidentally changed, but they still can be pushed for the camera zoom, or volume change, when i want.
Thanks for the reply; I figured it was an infrared beam and was looking for the reflected wavelengths, but I found it odd that it works fine right up to the point that it actually touches my jeans. Facing it towards my leg in my pocket like you suggest works most of the time, but not always... might have to mod my keys like you did, because I'm tired of pulling it out of my pocket with it about to turn off or the volume on max.
I have also thought about filing down the volume keys, they are just to easily pressed..I am left handed so when on a phone call I am always turning the volume up and down! The only thing that worries me is that I am pretty sure if you file or alter the volume keys that it will void out the warranty on the phone.. which would stink I guess if any problems arise later.. but that really is a good idea!
If you are having an issue with the volume buttons being pushed, try putting a case on the phone. Even if you put only the back half on you will eliminate that problem as the case will stick out farther then the buttons.
There is a thread in here dedicated to cases check it out.