路径:
frameworks/base/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java
frameworks/base/services/core/java/com/android/server/policy/PhoneWindowManager.java

【思路】

  • 1、在事件处理处,发送广播给KeyguardViewMediator
  • 2、KeyguardViewMediator来实现锁屏

frameworks/base/services/core/java/com/android/server/policy/PhoneWindowManager.java

public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) {
//新增锁屏键
case KeyEvent.KEYCODE_BREAK:
Intent intent = new Intent("com.android.internal.policy.impl.PhoneWindowManager.DELAYED_KEYGUARD");
intent.putExtra("BREAK","break"); //发送标识,因为我们要针对它做专门处理
mContext.sendBroadcast(intent);
break;
}

frameworks/base/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java

private final BroadcastReceiver mDelayedLockBroadcastReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
//根据PauseBreak键发起的广播请求由我们自己来处理
if (intent.getStringExtra("BREAK").equals("break")){
doKeyguardLocked(null); //锁屏
return;
...
}
};