Look in com.android.internal.policy.impl.WindowManagerPolicy.java. This handles dispatching of key events to the appropriate place and also provides custom handling of the power button.
In particular, you might be interested in interceptKeyBeforeQueueing(), or just search for KEYCODE_POWER.