Android 11.0 自定义按键实现锁屏
原创
©著作权归作者所有:来自51CTO博客作者51CTO王睿丶的原创作品,请联系作者获取转载授权,否则将追究法律责任
路径:
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) {
if (intent.getStringExtra("BREAK").equals("break")){
doKeyguardLocked(null);
return;
...
}
};