android Telephony學習 --- 第八篇 android7.0 來電UI啟動流程

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();
            } 
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市永脓,隨后出現(xiàn)的幾起案子袍辞,更是在濱河造成了極大的恐慌,老刑警劉巖常摧,帶你破解...
    沈念sama閱讀 218,546評論 6 507
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件搅吁,死亡現(xiàn)場離奇詭異威创,居然都是意外死亡,警方通過查閱死者的電腦和手機谎懦,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,224評論 3 395
  • 文/潘曉璐 我一進店門肚豺,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人界拦,你說我怎么就攤上這事吸申。” “怎么了享甸?”我有些...
    開封第一講書人閱讀 164,911評論 0 354
  • 文/不壞的土叔 我叫張陵截碴,是天一觀的道長。 經常有香客問我蛉威,道長日丹,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,737評論 1 294
  • 正文 為了忘掉前任蚯嫌,我火速辦了婚禮哲虾,結果婚禮上,老公的妹妹穿的比我還像新娘齐帚。我一直安慰自己妒牙,他們只是感情好彼哼,可當我...
    茶點故事閱讀 67,753評論 6 392
  • 文/花漫 我一把揭開白布对妄。 她就那樣靜靜地躺著,像睡著了一般敢朱。 火紅的嫁衣襯著肌膚如雪剪菱。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,598評論 1 305
  • 那天拴签,我揣著相機與錄音孝常,去河邊找鬼。 笑死蚓哩,一個胖子當著我的面吹牛构灸,可吹牛的內容都是我干的。 我是一名探鬼主播岸梨,決...
    沈念sama閱讀 40,338評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼喜颁,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了曹阔?” 一聲冷哼從身側響起半开,我...
    開封第一講書人閱讀 39,249評論 0 276
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎赃份,沒想到半個月后寂拆,有當地人在樹林里發(fā)現(xiàn)了一具尸體奢米,經...
    沈念sama閱讀 45,696評論 1 314
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內容為張勛視角 年9月15日...
    茶點故事閱讀 37,888評論 3 336
  • 正文 我和宋清朗相戀三年纠永,在試婚紗的時候發(fā)現(xiàn)自己被綠了鬓长。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 40,013評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡渺蒿,死狀恐怖痢士,靈堂內的尸體忽然破棺而出,到底是詐尸還是另有隱情茂装,我是刑警寧澤怠蹂,帶...
    沈念sama閱讀 35,731評論 5 346
  • 正文 年R本政府宣布,位于F島的核電站少态,受9級特大地震影響城侧,放射性物質發(fā)生泄漏。R本人自食惡果不足惜彼妻,卻給世界環(huán)境...
    茶點故事閱讀 41,348評論 3 330
  • 文/蒙蒙 一嫌佑、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧侨歉,春花似錦屋摇、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,929評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至牵舵,卻和暖如春柒啤,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背畸颅。 一陣腳步聲響...
    開封第一講書人閱讀 33,048評論 1 270
  • 我被黑心中介騙來泰國打工担巩, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人没炒。 一個月前我還...
    沈念sama閱讀 48,203評論 3 370
  • 正文 我出身青樓涛癌,卻偏偏與公主長得像,于是被迫代替她去往敵國和親送火。 傳聞我的和親對象是個殘疾皇子拳话,可洞房花燭夜當晚...
    茶點故事閱讀 44,960評論 2 355

推薦閱讀更多精彩內容