Implementation ideas:The Windowmanagerservice Loop reads the following key messages and distributes them to the window, filtering the messages in the Phonewindowmanager.interceptkeybeforequeueing method before the message is distributed. Therefore, the implementation of the message before the distribution of the Interceptkeybeforequeueing method to listen to the current key is the volume down key, if the current state is the lock screen state, and the key is the volume down key, and two times the key interval less than 800ms to send snapshot broadcast-" Com.bill.snapshot ".
The specific implementation is as follows:
/framework/base/policy/src/com/android/policy/impl/phonewindowmanager.java
Private long lasttime=0;private Keyguard mkeyguardmanager;private keyguard Getkeyguardmanager () {if (mKeyguardManager= =null) {mkeyguardmanager= (Keyguradmanager) Mcontext.getsystemservice (Context.keyguard_service); } return Mkeyguradmanager;}
public int interceptkeybeforequeueing (keyevent event,int Policyflags,boolean isscreenon) {if (Event.getkeycode () ==Key Event.keycode_volume_down && Event.isdwon ()) {if (Getkeyguardmanager (). Inkeyguardrestrictedinputmode ()) { if ((System.currenttimemillis ()-lasttime) <) {Intent intent=new Intent ("Com.bill.snapsh OT "); Mcontext.sendbroadcast (Intent); } lasttime=system.currenttimemillis (); } }......}
Android lock screen or off-screen state, quickly press two volume down key to achieve snapshot function (one, the framework layer implementation)