summaryrefslogtreecommitdiffstats
path: root/src/com/android/incallui/AnswerPresenter.java
blob: 020d075d10a6c1d8ff34743ff276781f5536f691 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
/*
 * Copyright (C) 2013 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License
 */

package com.android.incallui;

import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.IBinder;
import android.os.RemoteException;
import android.provider.Settings;

import com.android.contacts.common.util.BlockContactHelper;
import com.android.dialer.util.TelecomUtil;
import com.android.incallui.InCallPresenter.InCallState;
import com.android.internal.telephony.util.BlacklistUtils;

import com.cyanogen.lookup.phonenumber.provider.LookupProviderImpl;
import org.codeaurora.ims.qtiims.IQtiImsInterface;
import org.codeaurora.ims.qtiims.IQtiImsInterfaceListener;
import org.codeaurora.ims.qtiims.QtiImsInterfaceListenerBaseImpl;
import org.codeaurora.ims.qtiims.QtiImsInterfaceUtils;
import org.codeaurora.ims.qtiims.QtiViceInfo;
import org.codeaurora.QtiVideoCallConstants;

import java.util.List;

/**
 * Presenter for the Incoming call widget. The {@link AnswerPresenter} handles the logic during
 * incoming calls. It is also in charge of responding to incoming calls, so there needs to be
 * an instance alive so that it can receive onIncomingCall callbacks.
 *
 * An instance of {@link AnswerPresenter} is created by InCallPresenter at startup, registers
 * for callbacks via InCallPresenter, and shows/hides the {@link AnswerFragment} via IncallActivity.
 *
 */
public class AnswerPresenter extends Presenter<AnswerPresenter.AnswerUi>
        implements CallList.CallUpdateListener, InCallPresenter.InCallUiListener,
                InCallPresenter.IncomingCallListener,
                CallList.Listener, CallList.ActiveSubChangeListener {

    private static final String TAG = AnswerPresenter.class.getSimpleName();

    private String mCallId[] = new String[InCallServiceImpl.sPhoneCount];
    private Call mCall[] = new Call[InCallServiceImpl.sPhoneCount];
    private final CallList mCalls = CallList.getInstance();
    private boolean mHasTextMessages = false;
    private BlockContactHelper mBlockContactHelper;

    /**
     * Details required to support call deflection feature.
     */
    private static final String IMS_SERVICE_PKG_NAME = "org.codeaurora.ims";
    private IQtiImsInterface mQtiImsInterface = null;
    private boolean mImsServiceBound = false;

    /* Variables to cache the request details during asynchronous bind request */
    private boolean mPendingDeflectRequest = false;
    private String mDeflectToNumber = null;
    private int mDeflectPhoneId = 0;

    /* Service connection bound to IQtiImsInterface */
    private ServiceConnection mConnection = new ServiceConnection() {

        /* Below API gets invoked when connection to ImsService is established */
        public void onServiceConnected(ComponentName className, IBinder service) {
            /* Retrieve the IQtiImsInterface */
            mQtiImsInterface = IQtiImsInterface.Stub.asInterface(service);

            /**
             * If interface is available and deflect request is pending,
             * then, process the deflect request.
             */
            if (mQtiImsInterface != null && mPendingDeflectRequest) {
                sendCallDeflectRequest(mDeflectPhoneId, mDeflectToNumber);
            } else {
                /* Request or interface is unavailable, unbind the service */
                unbindImsService();
            }
        }

        /* Below API gets invoked when connection to ImsService is disconnected */
        public void onServiceDisconnected(ComponentName className) {
        }
    };

    /* QtiImsInterfaceListenerBaseImpl instance to handle call deflection response */
    private QtiImsInterfaceListenerBaseImpl imsInterfaceListener =
            new QtiImsInterfaceListenerBaseImpl() {

        /* Handles call deflect response */
        @Override
        public void receiveCallDeflectResponse(int result) {
            Log.w(this, "receiveCallDeflectResponse: " + result);
        }

        public void notifyRefreshViceInfo(QtiViceInfo qtiViceInfo) {
        }
    };

    /**
     * Informs if call deflection interafce is available or not.
     * Returns true if allowed, false otherwise.
     */
    public boolean isQtiImsInterfaceAvailable() {
        return (mImsServiceBound && (mQtiImsInterface != null));
    }

    /**
     * Checks if ims service is bound or not
     * Returns true when bound, false otherwise.
     */
    public boolean isImsServiceAvailable() {
        return mImsServiceBound;
    }

    /**
     * Bind to the ims service
     * Returns true if bound sucessfully, false otherwise.
     */
    public boolean bindImsService() {
        Intent intent = new Intent(IQtiImsInterface.class.getName());
        intent.setPackage(IMS_SERVICE_PKG_NAME);
        mImsServiceBound = getUi().getContext().bindService(intent,
                                   mConnection,
                                   Context.BIND_AUTO_CREATE);
        Log.d(this, "Getting IQtiImsInterface : " + (mImsServiceBound?"yes":"failed"));
        return mImsServiceBound;
    }

    /* Unbind the ims service if was already bound */
    public void unbindImsService() {
        if (mImsServiceBound) {
            Log.d(this, "UnBinding IQtiImsInterface: callId " + mCallId);

            /* When disconnecting, reset the globals variables */
            mImsServiceBound = false;
            mPendingDeflectRequest = false;
            getUi().getContext().unbindService(mConnection);
        }
    }

    /* Send call deflect request to lower layers */
    public void sendCallDeflectRequest(int phoneId, String deflectNumber) {
        /* Call deflection interface is available, send the request now */
        try {
            Log.d(this, "Sending deflect request with Phone id " + phoneId +
                    " to " + deflectNumber);
            mQtiImsInterface.sendCallDeflectRequest(phoneId, deflectNumber,
                    imsInterfaceListener);
        } catch (RemoteException e) {
            Log.e(this, "sendCallDeflectRequest exception " + e);
            mPendingDeflectRequest = false;
            QtiCallUtils.displayToast(getUi().getContext(),
                    R.string.qti_description_deflect_service_error);
        }
    }

    private boolean checkSubId(int phoneId) {
        int subId[] = mCalls.getSubId(phoneId);
        return (subId != null && subId.length > 0);
    }

    @Override
    public void onUiShowing(boolean showing) {
        if (showing) {
            mCalls.addListener(this);
            mCalls.addActiveSubChangeListener(this);
            Call call;
            // Consider incoming/waiting calls on both subscriptions
            // for DSDA.
            for (int i = 0; i < InCallServiceImpl.sPhoneCount; i++) {
                int[] subId = mCalls.getSubId(i);
                if (checkSubId(i)) {
                    call = mCalls.getCallWithState(Call.State.INCOMING, 0, subId[0]);
                    if (call == null) {
                        call = mCalls.getCallWithState(Call.State.CALL_WAITING, 0, subId[0]);
                    }
                    if (call != null) {
                        processIncomingCall(call);
                    }
                } else {
                    Log.d(TAG, "No valid sub");
                }
            }
            call = mCalls.getVideoUpgradeRequestCall();
            Log.d(this, "getVideoUpgradeRequestCall call =" + call);
            if (call != null) {
                showAnswerUi(true);
                processVideoUpgradeRequestCall(call);
            }
        } else {
            mCalls.removeListener(this);
            // This is necessary because the activity can be destroyed while an incoming call exists.
            // This happens when back button is pressed while incoming call is still being shown.
            for (int i = 0; i < InCallServiceImpl.sPhoneCount; i++) {
                int[] subId = mCalls.getSubId(i);
                if (checkSubId(i)) {
                    Call call = mCalls.getCallWithState(Call.State.INCOMING, 0, subId[0]);
                    if (call == null) {
                        call = mCalls.getCallWithState(Call.State.CALL_WAITING, 0, subId[0]);
                    }
                    if (call == null) {
                        call = mCalls.getCallWithState(Call.State.ACTIVE, 0, subId[0]);
                    }
                    if (mCallId[i] != null && call == null) {
                        mCalls.removeCallUpdateListener(mCallId[i], this);
                        mCalls.removeActiveSubChangeListener(this);
                    }
                } else {
                    Log.d(TAG, "No valid sub");
                }
            }
        }
    }

    @Override
    public void onIncomingCall(InCallState oldState, InCallState newState, Call call) {
        int subId = call.getSubId();
        int phoneId = mCalls.getPhoneId(subId);
        Log.d(this, "onIncomingCall: " + this);
        Call modifyCall = mCalls.getVideoUpgradeRequestCall();
        if (modifyCall != null) {
            showAnswerUi(false);
            Log.d(this, "declining upgrade request id: ");
            mCalls.removeCallUpdateListener(mCallId[phoneId], this);
            InCallPresenter.getInstance().declineUpgradeRequest(getUi().getContext());
        }
        if (!call.getId().equals(mCallId[phoneId])) {
            // A new call is coming in.
            processIncomingCall(call);
        }
    }

    @Override
    public void onIncomingCall(Call call) {
    }

    @Override
    public void onCallListChange(CallList list) {
    }

    @Override
    public void onDisconnect(Call call) {
        int subId = call.getSubId();
        int phoneId = mCalls.getPhoneId(subId);
        if (call.equals(mCall[phoneId])) {
            mCall[phoneId] = null;
        }
    }

    public void onSessionModificationStateChange(int sessionModificationState) {
        boolean isUpgradePending = sessionModificationState ==
                Call.SessionModificationState.RECEIVED_UPGRADE_TO_VIDEO_REQUEST;

        if (!isUpgradePending) {
            // Stop listening for updates.
            for (int i = 0; i < InCallServiceImpl.sPhoneCount; i++) {
                if (mCallId[i] != null) {
                    mCalls.removeCallUpdateListener(mCallId[i], this);
                }
            }
            showAnswerUi(false);
        }
    }

    @Override
    public void onLastForwardedNumberChange() {
        // no-op
    }

    @Override
    public void onChildNumberChange() {
        // no-op
    }

    private boolean isVideoUpgradePending(Call call) {
        return call.getSessionModificationState()
                == Call.SessionModificationState.RECEIVED_UPGRADE_TO_VIDEO_REQUEST;
    }

    @Override
    public void onUpgradeToVideo(Call call) {
        Log.d(this, "onUpgradeToVideo: " + this + " call=" + call);
        showAnswerUi(true);
        boolean isUpgradePending = isVideoUpgradePending(call);
        InCallPresenter inCallPresenter = InCallPresenter.getInstance();
        if (isUpgradePending
                && inCallPresenter.getInCallState() == InCallPresenter.InCallState.INCOMING) {
            Log.d(this, "declining upgrade request");
            //If there is incoming call reject upgrade request
            inCallPresenter.declineUpgradeRequest(getUi().getContext());
        } else if (isUpgradePending) {
            Log.d(this, "process upgrade request as no MT call");
            processVideoUpgradeRequestCall(call);
        }
    }

    private void processIncomingCall(Call call) {
        int subId = call.getSubId();
        int phoneId = mCalls.getPhoneId(subId);
        mCallId[phoneId] = call.getId();
        mCall[phoneId] = call;
        mCalls.addListener(this);
        // Listen for call updates for the current call.
        mCalls.addCallUpdateListener(mCallId[phoneId], this);

        Log.d(TAG, "Showing incoming for call id: " + mCallId[phoneId] + " " + this);
        if (showAnswerUi(true)) {
            final List<String> textMsgs = mCalls.getTextResponses(call.getId());
            configureAnswerTargetsForSms(call, textMsgs);
        }
    }

    private boolean showAnswerUi(boolean show) {
        final InCallActivity activity = InCallPresenter.getInstance().getActivity();
        if (activity != null) {
            activity.showAnswerFragment(show);
            if (getUi() != null) {
                getUi().onShowAnswerUi(show);
            }
            return true;
        } else {
            return false;
        }
    }

    private void processVideoUpgradeRequestCall(Call call) {
        Log.d(this, " processVideoUpgradeRequestCall call=" + call);
        int subId = call.getSubId();
        int phoneId = mCalls.getPhoneId(subId);
        mCallId[phoneId] = call.getId();
        mCall[phoneId] = call;

        // Listen for call updates for the current call.
        CallList.getInstance().addCallUpdateListener(mCallId[phoneId], this);

        final int currentVideoState = call.getVideoState();
        final int modifyToVideoState = call.getModifyToVideoState();

        if (currentVideoState == modifyToVideoState) {
            Log.w(this, "processVideoUpgradeRequestCall: Video states are same. Return.");
            return;
        }

        AnswerUi ui = getUi();

        if (ui == null) {
            Log.e(this, "Ui is null. Can't process upgrade request");
            return;
        }
        showAnswerUi(true);
        ui.showTargets(QtiCallUtils.getSessionModificationOptions(getUi().getContext(),
                currentVideoState, modifyToVideoState));

    }

    private boolean isEnabled(int videoState, int mask) {
        return (videoState & mask) == mask;
    }

    @Override
    public void onCallChanged(Call call) {
        Log.d(this, "onCallStateChange() " + call + " " + this);
        if (call.getState() != Call.State.INCOMING) {
            boolean isUpgradePending = isVideoUpgradePending(call);
            int subId = call.getSubId();
            int phoneId = mCalls.getPhoneId(subId);
            if (!isUpgradePending) {
                // Stop listening for updates.
                mCalls.removeCallUpdateListener(mCallId[phoneId], this);
            }

            final Call incall = mCalls.getIncomingCall();
            if (incall != null || isUpgradePending) {
                showAnswerUi(true);
            } else {
                showAnswerUi(false);
            }

            mHasTextMessages = false;

            /* if available, release the call deflect interface */
            unbindImsService();

        } else if (!mHasTextMessages) {
            final List<String> textMsgs = mCalls.getTextResponses(call.getId());
            if (textMsgs != null) {
                configureAnswerTargetsForSms(call, textMsgs);
            }
        }
    }

    // get active phoneId, for which call is visible to user
    private int getActivePhoneId() {
        int phoneId = -1;
        if (InCallServiceImpl.isDsdaEnabled()) {
            int subId = mCalls.getActiveSubId();
            phoneId = mCalls.getPhoneId(subId);
        } else {
            for (int i = 0; i < mCall.length; i++) {
                if (mCall[i] != null) {
                    phoneId = i;
                }
            }
        }
        return phoneId;
    }

    public void onAnswer(int videoState, Context context, int callWaitingResponseType) {
        int phoneId = getActivePhoneId();
        Log.i(this, "onAnswer  mCallId:" + mCallId + "phoneId:" + phoneId);
        if (mCallId == null || phoneId == -1) {
            return;
        }

        if (mCall[phoneId].getSessionModificationState()
                == Call.SessionModificationState.RECEIVED_UPGRADE_TO_VIDEO_REQUEST) {
            Log.d(this, "onAnswer (upgradeCall) mCallId=" + mCallId + " videoState=" + videoState);
            InCallPresenter.getInstance().acceptUpgradeRequest(videoState, context);
        } else {
            Log.d(this, "onAnswer (answerCall) mCallId=" + mCallId + " videoState=" + videoState);
            TelecomAdapter.getInstance().answerCall(mCall[phoneId].getId(), videoState,
                    callWaitingResponseType);
        }
    }

    /**
     * TODO: We are using reject and decline interchangeably. We should settle on
     * reject since it seems to be more prevalent.
     */
    public void onDecline(Context context) {
        int phoneId = getActivePhoneId();
        Log.d(this, "onDecline mCallId:" + mCallId + "phoneId:" + phoneId);
        if (mCall[phoneId].getSessionModificationState()
                == Call.SessionModificationState.RECEIVED_UPGRADE_TO_VIDEO_REQUEST) {
            InCallPresenter.getInstance().declineUpgradeRequest(context);
        } else {
            TelecomAdapter.getInstance().rejectCall(mCall[phoneId].getId(), false, null);
        }
    }

    public void onText() {
        if (getUi() != null) {
            TelecomUtil.silenceRinger(getUi().getContext());
            getUi().showMessageDialog();
        }
    }

    public void onBlock(boolean notifyLookupProvider) {
        if (mBlockContactHelper != null) {
            mBlockContactHelper.blockContactAsync(notifyLookupProvider);
            // end the call
            onDecline(getUi().getContext());
        }
    }

    public boolean isBlockingEnabled() {
        return BlacklistUtils.isBlacklistEnabled(getUi().getContext());
    }

    public void onBlockDialogInitialize() {
        int phoneId = getActivePhoneId();
        Log.d(this, "onBlock mCallId:" + mCallId + "phoneId:" + phoneId);
        Call call = mCall[phoneId];
        final String number = call.getNumber();
        final Context context = getUi().getContext();
        mBlockContactHelper = new BlockContactHelper(context);
        mBlockContactHelper.setContactInfo(number);
    }

    public String getLookupProviderName() {
        return mBlockContactHelper.getLookupProviderName();
    }

    /**
     * Deflect the incoming call.
     */
    public void onDeflect(Context context) {
        String deflectCallNumber = QtiImsInterfaceUtils.getCallDeflectNumber(
                                           context.getContentResolver());
        /* If not set properly, inform user via toast */
        if (deflectCallNumber == null) {
            Log.w(this, "getCallDeflectNumber is null or Empty.");
            QtiCallUtils.displayToast(context, R.string.qti_description_deflect_error);
        } else {
            /* Cache the variables and bind to service */
            mPendingDeflectRequest = true;
            mDeflectToNumber = deflectCallNumber;

            /* Try to get required interface */
            if (bindImsService()) {
                /* wait for the service connection callback */
            } else {
                /* Ims service is available, but no QtiImsInterface available */
                Log.d(this, "Ims Service is not available for call deflection interface");
                mPendingDeflectRequest = false;
                QtiCallUtils.displayToast(context,
                        R.string.qti_description_deflect_service_error);
           }
        }
    }

    public void rejectCallWithMessage(String message) {
        int phoneId = getActivePhoneId();
        Log.i(this, "sendTextToDefaultActivity()...phoneId:" + phoneId);
        TelecomAdapter.getInstance().rejectCall(mCall[phoneId].getId(), true, message);

        onDismissDialog();
    }

    public void onDismissDialog() {
        InCallPresenter.getInstance().onDismissDialog();
    }

    private void configureAnswerTargetsForSms(Call call, List<String> textMsgs) {
        if (getUi() == null) {
            return;
        }
        mHasTextMessages = textMsgs != null;
        boolean withSms =
                call.can(android.telecom.Call.Details.CAPABILITY_RESPOND_VIA_TEXT)
                && mHasTextMessages;
        boolean withBlock = isBlockingEnabled();

        Call activeCall = CallList.getInstance().getActiveCall();
        boolean isCallWaiting = activeCall != null && activeCall != call;

        // Only present the user with the option to answer as a video call if the incoming call is
        // a bi-directional video call.
        if (call.isVideoCall(getUi().getContext())) {
            getUi().showTargets(QtiCallUtils.getIncomingCallAnswerOptions(
                    getUi().getContext(), withSms, withBlock));
            if (withSms) {
                getUi().configureMessageDialog(textMsgs);
            }
        } else if (isCallDeflectSupported()) {
            /**
             * Only present the user with the option to deflect call,
             * if the incoming call is only an audio call.
             */
            if (withSms) {
                getUi().showTargets(AnswerFragment.TARGET_SET_FOR_QTI_AUDIO_WITH_SMS);
                getUi().configureMessageDialog(textMsgs);
            } else {
                getUi().showTargets(AnswerFragment.TARGET_SET_FOR_QTI_AUDIO_WITHOUT_SMS);
            }
        } else {
            if (withSms) {
                if (isCallWaiting) {
                    getUi().showTargets(AnswerFragment
                            .TARGET_SET_FOR_AUDIO_WITH_SMS_AND_CALL_WAITING);
                    getUi().configureMessageDialog(textMsgs);
                } else {
                    getUi().showTargets(withBlock
                            ? AnswerFragment.TARGET_SET_FOR_AUDIO_WITH_SMS_AND_BLOCK
                            : AnswerFragment.TARGET_SET_FOR_AUDIO_WITH_SMS_WITHOUT_BLOCK);
                    getUi().configureMessageDialog(textMsgs);
                }
            } else {
                if (isCallWaiting) {
                    getUi().showTargets(AnswerFragment
                            .TARGET_SET_FOR_AUDIO_WITHOUT_SMS_WITH_CALL_WAITING);
                } else {
                    getUi().showTargets(withBlock
                            ? AnswerFragment.TARGET_SET_FOR_AUDIO_WITHOUT_SMS_WITH_BLOCK
                            : AnswerFragment.TARGET_SET_FOR_AUDIO_WITHOUT_SMS_AND_BLOCK);
                }
            }
        }
    }

    @Override
    public void onUiUnready(AnswerUi ui) {
        super.onUiUnready(ui);
        if (mBlockContactHelper != null) {
            mBlockContactHelper.destroy();
        }
    }

    /**
     * Checks the Settings to conclude on the call deflect support.
     * Returns true if call deflect is possible, false otherwise.
     */
    public boolean isCallDeflectSupported() {
        int value = 0;
        try{
            value = android.provider.Settings.Global.getInt(
                              getUi().getContext().getContentResolver(),
                              QtiImsInterfaceUtils.QTI_IMS_DEFLECT_ENABLED);
        } catch(Settings.SettingNotFoundException e) {
            //do Nothing
        }
        return (value == 1);
    }

    interface AnswerUi extends Ui {
        public void onShowAnswerUi(boolean shown);
        public void showTargets(int targetSet);
        public void showTargets(int targetSet, int videoState);
        public void showMessageDialog();
        public void configureMessageDialog(List<String> textResponses);
        public Context getContext();
    }

    @Override
    public void onActiveSubChanged(int subId) {
        final Call call = mCalls.getIncomingCall();
        int phoneId = CallList.getInstance().getPhoneId(subId);
        if ((call != null) && (call.getId() == mCallId[phoneId])) {
            Log.d(this, "Show incoming for call id: " + mCallId[phoneId] + " " + this);
            if (showAnswerUi(true)) {
                final List<String> textMsgs = mCalls.getTextResponses(
                        call.getId());
                configureAnswerTargetsForSms(call, textMsgs);
            }
        } else if ((call == null) && (mCalls.hasAnyLiveCall(subId))) {
            Log.d(this, "Hide incoming for call id: " + mCallId[phoneId] + " " + this);
            showAnswerUi(false);
        } else {
            Log.d(this, "No incoming call present for sub = " + subId + " " + this);
        }
    }
}