Android 11 sim卡来电不弹出悬浮通知,默认来电默认全屏
默认情况下,来电android是以通知窗口的形式显示,只在屏幕的顶部弹出一个悬浮通知,现在改为全屏显示,直接跳转来电界面InCallActivity
\packages\apps\Dialer\java\com\android\incallui\StatusBarNotifier.java
/**
* Helper method for updateInCallNotification() and updateNotification(): Update the phone app's
* status bar notification based on the current telephony state, or cancels the notification if
* the phone is totally idle.
*/
private boolean firstShow = true;//add
@RequiresPermission(Manifest.permission.READ_PHONE_STATE)
private void updateInCallNotification() {
LogUtil.d("StatusBarNotifier.updateInCallNotification", "");
final DialerCall call = getCallToShow(CallList.getInstance());
// don't show Notification, if call has already been rejected
if (call != null && !call.isRejected()) {
// add 当去电或者来电是会一直重复调用这个方法,要做一个判断,防止重复进入InCallActivity
showNotification(call);
if (firstShow) {
context.startActivity(InCallActivity.getIntent(context, false/*showDialpad*/, false/*newOutgoingCall*/, true /* forFullScreen */));
firstShow = false;
}
//add end
} else {
firstShow = true;//add
cancelNotification();
}
}
Android 11 通知是否弹出,有两个因素决定,
一个是通知的优先级(setPriority(NotificationCompat.PRIORITY_MIN)),
另一个是通知渠道(通道)的优先级(NotificationManager.IMPORTANCE_HIGH)
public NotificationChannel(String id, CharSequence name, @Importance int importance) {
this.mId = getTrimmedString(id);
this.mName = name != null ? getTrimmedString(name.toString()) : null;
this.mImportance = importance;
}
\packages\apps\Dialer\java\com\android\dialer\notification\NotificationChannelManager.java
这是通话app 为通知渠道的管理和创建
private static void createIncomingCallChannel(@NonNull Context context) {
NotificationChannel channel =
new NotificationChannel(
NotificationChannelId.INCOMING_CALL,
context.getText(R.string.notification_channel_incoming_call),
NotificationManager.IMPORTANCE_MAX);
......
}
实际修改 :来电通知弹出悬浮
/** Sets up the main Ui for the notification */
@RequiresPermission(Manifest.permission.READ_PHONE_STATE)
private void buildAndSendNotification(CallList callList, DialerCall originalCall, ContactCacheEntry contactInfo) {
...........
switch (notificationType) {
case NOTIFICATION_INCOMING_CALL:
if (BuildCompat.isAtLeastO()) {
builder.setChannelId(NotificationChannelId.ONGOING_CALL);// add old -> NotificationChannelId.INCOMING_CALL
}
......
}
break;
case NOTIFICATION_INCOMING_CALL_QUIET:
if (BuildCompat.isAtLeastO()) {
builder.setChannelId(NotificationChannelId.ONGOING_CALL);
}
break;
............
}
按钮接听方式
修改位置
packages\apps\Dialer\java\com\android\incallui\answer\impl\answermethod\AnswerMethodFactory.java
@NonNull
public static AnswerMethod createAnswerMethod(@NonNull Activity activity) {
if (needTwoButton(activity)) {
return new TwoButtonMethod();
} else {
//return new FlingUpDownMethod();
return new TwoButtonMethod();//add
}
}
其实通知和SystemUI 相关,也可以在它哪里拦截!!!
SystemIU关于悬浮通知
modified: packages/SystemUI/src/com/android/systemui/statusbar/notification/interruption/HeadsUpViewBinder.java
modified: packages/SystemUI/src/com/android/systemui/statusbar/notification/interruption/NotificationInterruptStateProviderImpl.java
modified: packages/SystemUI/src/com/android/systemui/statusbar/policy/HeadsUpManager.java
//HeadsUpManager.java
@Override
protected void onAlertEntryAdded(AlertEntry alertEntry) {
NotificationEntry entry = alertEntry.mEntry;
if(entry.getSbn().getPackageName().equals("com.xx.xxx")){
return;
}
entry.setHeadsUp(true);
setEntryPinned((HeadsUpEntry) alertEntry, shouldHeadsUpBecomePinned(entry));
for (OnHeadsUpChangedListener listener : mListeners) {
listener.onHeadsUpStateChanged(entry, true);
}
}
在Frameworks层拦截Home键
https://blog.csdn.net/abc6368765/article/details/132164705
/frameworks/base/services/core/java/com/android/server/policy/PhoneWindowManager.java/frameworks/base/services/core/java/com/android/server/policy/PhoneWindowManager.java
/** {@inheritDoc} */
@Override
public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int policyFlags) {
......
// First we always handle the home key here, so applications
// can never break it, although if keyguard is on, we do let
// it handle it, because that gives us the correct 5 second
// timeout.
if (keyCode == KeyEvent.KEYCODE_HOME) {
// If we have released the home key, and didn't do anything else
// while it was pressed, then it is time to go home!
if (!down) {
//添加的判断当前前台运行APP代码
if (!isBackgroundActivity(mContext, PKG_NAME_xxxxx)) {
Log.d(TAG, "xxxx app is foreground");
if (!getTopActivity(mContext).equals(ACTIVITY_NAME_xxxx)) {
Log.d(TAG, "xxxxx app is foreground activity");
return -1;
}
return -1;
}
cancelPreloadRecentApps();
mHomePressed = false;
if (mHomeConsumed) {
mHomeConsumed = false;
return -1;
}
......