Incall發(fā)起notification后寸宏,由systemui根據當前手機狀態(tài)顷霹,來決定是顯示來電界面還是headsup小窗口。
android7.0 來電UI啟動流程.png
-
package/app/Dialer -- InCallPresenter
接著上篇文章击吱,從onIncomingCall開始查看:
@Override
public void onIncomingCall(Call call) {
InCallState newState = startOrFinishUi(InCallState.INCOMING);
for (IncomingCallListener listener : mIncomingCallListeners) {
listener.onIncomingCall(oldState, mInCallState, call);
}
}
關注startOrFinishUi方法淋淀,若是滿足直接顯示UI的條件調用showInCall,直接啟動UI覆醇;否則調用startUi:
private InCallState startOrFinishUi(InCallState newState) {
if (showCallUi || showAccountPicker || isAutoAnswer) {
showInCall(false /* showDialpad */, !showAccountPicker /* newOutgoingCall */);
} else if (startIncomingCallSequence) {
if (!startUi(newState)) {
return mInCallState;
}
}
}
調用StatusBarNotifier.updateNotification:
private boolean startUi(InCallState inCallState) {
if (isCallWaiting || anyOtherSubActive) {
if (mProximitySensor.isScreenReallyOff() && isActivityStarted()) {
mInCallActivity.finish();
return false;
} else {
showInCall(false, false);
}
} else {
mStatusBarNotifier.updateNotification(inCallState, mCallList);
}
return true;
}
-
package/app/Dialer -- StatusBarNotifier
incall發(fā)起通知朵纷,后續(xù)由notification決定是顯示小窗口還是來電界面:
private void buildAndSendNotification(Call originalCall, ContactCacheEntry contactInfo) {
Notification.Builder publicBuilder = new Notification.Builder(mContext);
final PendingIntent inCallPendingIntent = createLaunchPendingIntent();
if (notificationType == NOTIFICATION_INCOMING_CALL
&& (!InCallPresenter.getInstance().isShowingInCallUi() ||
(pendingAccountSelectionCall != null))) {
configureFullScreenIntent(builder, inCallPendingIntent, call);
}
Notification notification = builder.build();
mNotificationManager.notify(notificationType, notification);
}
configureFullScreenIntent方法:
private void configureFullScreenIntent(Notification.Builder builder, PendingIntent intent,
Call call) {
// Ok, we actually want to launch the incoming call
// UI at this point (in addition to simply posting a notification
// to the status bar). Setting fullScreenIntent will cause
// the InCallScreen to be launched immediately *unless* the
// current foreground activity is marked as "immersive".
builder.setFullScreenIntent(intent, true);
}
攜帶intent來啟動InCallActivity:
private PendingIntent createLaunchPendingIntent() {
final Intent intent = InCallPresenter.getInstance().getInCallIntent(
false /* showDialpad */, false /* newOutgoingCall */);
// PendingIntent that can be used to launch the InCallActivity. The
// system fires off this intent if the user pulls down the windowshade
// and clicks the notification's expanded view. It's also used to
// launch the InCallActivity immediately when when there's an incoming
// call (see the "fullScreenIntent" field below).
PendingIntent inCallPendingIntent = PendingIntent.getActivity(mContext, 0, intent, 0);
return inCallPendingIntent;
}
- frameworks/base/core -- NotificationManager
public void notifyAsUser(String tag, int id, Notification notification, UserHandle user)
{
INotificationManager service = getService();
try {
service.enqueueNotificationWithTag(pkg, mContext.getOpPackageName(), tag, id,
copy, idOut, user.getIdentifier());
}
}
-
frameworks/base/core -- NotificationManagerService
找到INotificationManager aidl實現(xiàn)enqueueNotificationWithTag方法的地方:
private final IBinder mService = new INotificationManager.Stub() {
@Override
public void enqueueNotificationWithTag(String pkg, String opPkg, String tag, int id,
Notification notification, int[] idOut, int userId) throws RemoteException {
enqueueNotificationInternal(pkg, opPkg, Binder.getCallingUid(),
Binder.getCallingPid(), tag, id, notification, idOut, userId);
}
- frameworks/base/packages/SystemUI -- BaseStatusBar
private final NotificationListenerService mNotificationListener =
new NotificationListenerService() {
@Override
public void onNotificationPosted(final StatusBarNotification sbn,
final RankingMap rankingMap) {
if (sbn != null) {
mHandler.post(new Runnable() {
@Override
public void run() {
if (isUpdate) {
updateNotification(sbn, rankingMap);
} else {
addNotification(sbn, rankingMap, null /* oldEntry */);
}
}
});
-
frameworks/base/packages/SystemUI -- PhoneStatusBar
isHeadsUped決定是顯示headsup還是來電界面:
@Override
public void addNotification(StatusBarNotification notification, RankingMap ranking,
Entry oldEntry) {
boolean isHeadsUped = shouldPeek(shadeEntry);
if (isHeadsUped) {
mHeadsUpManager.showNotification(shadeEntry);
setNotificationShown(notification);
}
if (!isHeadsUped && notification.getNotification().fullScreenIntent != null) {
try {
notification.getNotification().fullScreenIntent.send();
shadeEntry.notifyFullScreenIntentLaunched();
}