CallButtonPresenter.java revision ddb824ecb3f052551b3ea97d5f5cb3037ec4c683
1241d50d5f523eb0b644d8a9c1cf7fd2eb418ab88Chiao Cheng/*
2241d50d5f523eb0b644d8a9c1cf7fd2eb418ab88Chiao Cheng * Copyright (C) 2013 The Android Open Source Project
3241d50d5f523eb0b644d8a9c1cf7fd2eb418ab88Chiao Cheng *
4241d50d5f523eb0b644d8a9c1cf7fd2eb418ab88Chiao Cheng * Licensed under the Apache License, Version 2.0 (the "License");
5241d50d5f523eb0b644d8a9c1cf7fd2eb418ab88Chiao Cheng * you may not use this file except in compliance with the License.
6241d50d5f523eb0b644d8a9c1cf7fd2eb418ab88Chiao Cheng * You may obtain a copy of the License at
7241d50d5f523eb0b644d8a9c1cf7fd2eb418ab88Chiao Cheng *
8241d50d5f523eb0b644d8a9c1cf7fd2eb418ab88Chiao Cheng *      http://www.apache.org/licenses/LICENSE-2.0
9241d50d5f523eb0b644d8a9c1cf7fd2eb418ab88Chiao Cheng *
10241d50d5f523eb0b644d8a9c1cf7fd2eb418ab88Chiao Cheng * Unless required by applicable law or agreed to in writing, software
11241d50d5f523eb0b644d8a9c1cf7fd2eb418ab88Chiao Cheng * distributed under the License is distributed on an "AS IS" BASIS,
12241d50d5f523eb0b644d8a9c1cf7fd2eb418ab88Chiao Cheng * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13241d50d5f523eb0b644d8a9c1cf7fd2eb418ab88Chiao Cheng * See the License for the specific language governing permissions and
14241d50d5f523eb0b644d8a9c1cf7fd2eb418ab88Chiao Cheng * limitations under the License
15241d50d5f523eb0b644d8a9c1cf7fd2eb418ab88Chiao Cheng */
16241d50d5f523eb0b644d8a9c1cf7fd2eb418ab88Chiao Cheng
17241d50d5f523eb0b644d8a9c1cf7fd2eb418ab88Chiao Chengpackage com.android.incallui;
18241d50d5f523eb0b644d8a9c1cf7fd2eb418ab88Chiao Cheng
19746ee736f255772f7da308765fab22ba7512a10eAndrew Leeimport android.content.Context;
20746ee736f255772f7da308765fab22ba7512a10eAndrew Leeimport android.hardware.camera2.CameraAccessException;
21746ee736f255772f7da308765fab22ba7512a10eAndrew Leeimport android.hardware.camera2.CameraCharacteristics;
22746ee736f255772f7da308765fab22ba7512a10eAndrew Leeimport android.hardware.camera2.CameraManager;
23b48e2280930b5ed0b04dd34d59dc5980b379a475Sailesh Nepalimport android.telecomm.CallCapabilities;
24746ee736f255772f7da308765fab22ba7512a10eAndrew Leeimport android.telecomm.RemoteCallVideoProvider;
25746ee736f255772f7da308765fab22ba7512a10eAndrew Leeimport android.telecomm.VideoCallProfile;
265bcdca79b692712ff8a5a7e3e1c282f4d73cdf1cSailesh Nepal
2755e998472730cae27a82eed49cf7b020699b9286Christine Chenimport com.android.contacts.common.util.PhoneNumberHelper;
2855e998472730cae27a82eed49cf7b020699b9286Christine Chenimport com.android.contacts.common.util.TelephonyManagerUtils;
29dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordonimport com.android.incallui.AudioModeProvider.AudioModeListener;
30671b221ccadea34fb9327ef5342b26419eb5ca99Santos Cordonimport com.android.incallui.InCallPresenter.InCallState;
31671b221ccadea34fb9327ef5342b26419eb5ca99Santos Cordonimport com.android.incallui.InCallPresenter.InCallStateListener;
32c155f799fc0d4a2c9577f1e0688a3f1f5b436aefChristine Chenimport com.android.incallui.InCallPresenter.IncomingCallListener;
33dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordonimport com.android.services.telephony.common.AudioMode;
34671b221ccadea34fb9327ef5342b26419eb5ca99Santos Cordon
3504fb50696f53d728d9c9175c786544427c20e381Andrew Leeimport android.telephony.PhoneNumberUtils;
362ce872d6f7dd8a7eb0275b4195336f779972f698Makoto Onuki
37241d50d5f523eb0b644d8a9c1cf7fd2eb418ab88Chiao Cheng/**
38241d50d5f523eb0b644d8a9c1cf7fd2eb418ab88Chiao Cheng * Logic for call buttons.
39241d50d5f523eb0b644d8a9c1cf7fd2eb418ab88Chiao Cheng */
40150a5c58c67f230c8fd7293b180bbf50aa761480Santos Cordonpublic class CallButtonPresenter extends Presenter<CallButtonPresenter.CallButtonUi>
417debd4141ad074559c570e5d6737c0712fccae5fAndrew Lee        implements InCallStateListener, AudioModeListener, IncomingCallListener {
42241d50d5f523eb0b644d8a9c1cf7fd2eb418ab88Chiao Cheng
43671b221ccadea34fb9327ef5342b26419eb5ca99Santos Cordon    private Call mCall;
44e08284ea58e98666e6f1b45734d9901de91c2bb4Yorke Lee    private boolean mAutomaticallyMuted = false;
45e08284ea58e98666e6f1b45734d9901de91c2bb4Yorke Lee    private boolean mPreviousMuteState = false;
4646c57f18a63d5923b0b93f1988a56bb4beb9cc5dChristine Chen    private boolean mShowGenericMerge = false;
4746c57f18a63d5923b0b93f1988a56bb4beb9cc5dChristine Chen    private boolean mShowManageConference = false;
48746ee736f255772f7da308765fab22ba7512a10eAndrew Lee    private boolean mUseFrontFacingCamera = true;
4946c57f18a63d5923b0b93f1988a56bb4beb9cc5dChristine Chen
502ce872d6f7dd8a7eb0275b4195336f779972f698Makoto Onuki    private InCallState mPreviousState = null;
51746ee736f255772f7da308765fab22ba7512a10eAndrew Lee    private CameraManager mCameraManager;
522ce872d6f7dd8a7eb0275b4195336f779972f698Makoto Onuki
539de3d7c5188c02cabf03799f87d494ee7dc702cbSantos Cordon    public CallButtonPresenter() {
54241d50d5f523eb0b644d8a9c1cf7fd2eb418ab88Chiao Cheng    }
55241d50d5f523eb0b644d8a9c1cf7fd2eb418ab88Chiao Cheng
56746ee736f255772f7da308765fab22ba7512a10eAndrew Lee    public void initializeCameraManager(Context context) {
57746ee736f255772f7da308765fab22ba7512a10eAndrew Lee        mCameraManager = (CameraManager) context.getSystemService(Context.CAMERA_SERVICE);
58746ee736f255772f7da308765fab22ba7512a10eAndrew Lee    }
59746ee736f255772f7da308765fab22ba7512a10eAndrew Lee
60241d50d5f523eb0b644d8a9c1cf7fd2eb418ab88Chiao Cheng    @Override
61241d50d5f523eb0b644d8a9c1cf7fd2eb418ab88Chiao Cheng    public void onUiReady(CallButtonUi ui) {
62241d50d5f523eb0b644d8a9c1cf7fd2eb418ab88Chiao Cheng        super.onUiReady(ui);
638b6c8d0dbfba6eabe3d835f8cdcec8a13e253d0cChiao Cheng
64b0d08a16da088e01f416f52a7b74ee9630c1493aSantos Cordon        AudioModeProvider.getInstance().addListener(this);
65b0d08a16da088e01f416f52a7b74ee9630c1493aSantos Cordon
66b0d08a16da088e01f416f52a7b74ee9630c1493aSantos Cordon        // register for call state changes last
67b0d08a16da088e01f416f52a7b74ee9630c1493aSantos Cordon        InCallPresenter.getInstance().addListener(this);
68c155f799fc0d4a2c9577f1e0688a3f1f5b436aefChristine Chen        InCallPresenter.getInstance().addIncomingCallListener(this);
69dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon    }
70dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon
71dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon    @Override
72dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon    public void onUiUnready(CallButtonUi ui) {
7322c678c74fa38e921ea22b09962062fce6148047Christine Chen        super.onUiUnready(ui);
7422c678c74fa38e921ea22b09962062fce6148047Christine Chen
75b0d08a16da088e01f416f52a7b74ee9630c1493aSantos Cordon        InCallPresenter.getInstance().removeListener(this);
76b0d08a16da088e01f416f52a7b74ee9630c1493aSantos Cordon        AudioModeProvider.getInstance().removeListener(this);
77c155f799fc0d4a2c9577f1e0688a3f1f5b436aefChristine Chen        InCallPresenter.getInstance().removeIncomingCallListener(this);
78241d50d5f523eb0b644d8a9c1cf7fd2eb418ab88Chiao Cheng    }
79241d50d5f523eb0b644d8a9c1cf7fd2eb418ab88Chiao Cheng
80150a5c58c67f230c8fd7293b180bbf50aa761480Santos Cordon    @Override
81671b221ccadea34fb9327ef5342b26419eb5ca99Santos Cordon    public void onStateChange(InCallState state, CallList callList) {
8255e998472730cae27a82eed49cf7b020699b9286Christine Chen        CallButtonUi ui = getUi();
839be240faad1857e122614a70fd6e632b143ddc41Christine Chen
84e7be13fb0556e62b07bc271b130412d82d7f7521Santos Cordon        if (state == InCallState.OUTGOING) {
85e7be13fb0556e62b07bc271b130412d82d7f7521Santos Cordon            mCall = callList.getOutgoingCall();
86e7be13fb0556e62b07bc271b130412d82d7f7521Santos Cordon        } else if (state == InCallState.INCALL) {
87efd4282ec4221ec5eefd4155a4ad915adcedca70Santos Cordon            mCall = callList.getActiveOrBackgroundCall();
882ce872d6f7dd8a7eb0275b4195336f779972f698Makoto Onuki
892ce872d6f7dd8a7eb0275b4195336f779972f698Makoto Onuki            // When connected to voice mail, automatically shows the dialpad.
902ce872d6f7dd8a7eb0275b4195336f779972f698Makoto Onuki            // (On previous releases we showed it when in-call shows up, before waiting for
912ce872d6f7dd8a7eb0275b4195336f779972f698Makoto Onuki            // OUTGOING.  We may want to do that once we start showing "Voice mail" label on
922ce872d6f7dd8a7eb0275b4195336f779972f698Makoto Onuki            // the dialpad too.)
9355e998472730cae27a82eed49cf7b020699b9286Christine Chen            if (ui != null) {
9455e998472730cae27a82eed49cf7b020699b9286Christine Chen                if (mPreviousState == InCallState.OUTGOING && mCall != null
9504fb50696f53d728d9c9175c786544427c20e381Andrew Lee                        && PhoneNumberUtils.isVoiceMailNumber(mCall.getNumber())) {
9681bcf2a2e1c197655cf4a3aaf7d9af8088cf102eSai Cheemalapati                    ui.displayDialpad(true /* show */, true /* animate */);
9755e998472730cae27a82eed49cf7b020699b9286Christine Chen                }
982ce872d6f7dd8a7eb0275b4195336f779972f698Makoto Onuki            }
99c155f799fc0d4a2c9577f1e0688a3f1f5b436aefChristine Chen        } else if (state == InCallState.INCOMING) {
10055e998472730cae27a82eed49cf7b020699b9286Christine Chen            if (ui != null) {
10181bcf2a2e1c197655cf4a3aaf7d9af8088cf102eSai Cheemalapati                ui.displayDialpad(false /* show */, true /* animate */);
10255e998472730cae27a82eed49cf7b020699b9286Christine Chen            }
103c155f799fc0d4a2c9577f1e0688a3f1f5b436aefChristine Chen            mCall = null;
104671b221ccadea34fb9327ef5342b26419eb5ca99Santos Cordon        } else {
105671b221ccadea34fb9327ef5342b26419eb5ca99Santos Cordon            mCall = null;
106671b221ccadea34fb9327ef5342b26419eb5ca99Santos Cordon        }
107bc168c4fb0638846c5076a5a35a2e75ee4947908Santos Cordon        updateUi(state, mCall);
1082ce872d6f7dd8a7eb0275b4195336f779972f698Makoto Onuki
1092ce872d6f7dd8a7eb0275b4195336f779972f698Makoto Onuki        mPreviousState = state;
110241d50d5f523eb0b644d8a9c1cf7fd2eb418ab88Chiao Cheng    }
111241d50d5f523eb0b644d8a9c1cf7fd2eb418ab88Chiao Cheng
112dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon    @Override
113c155f799fc0d4a2c9577f1e0688a3f1f5b436aefChristine Chen    public void onIncomingCall(InCallState state, Call call) {
114c155f799fc0d4a2c9577f1e0688a3f1f5b436aefChristine Chen        onStateChange(state, CallList.getInstance());
115c155f799fc0d4a2c9577f1e0688a3f1f5b436aefChristine Chen    }
116c155f799fc0d4a2c9577f1e0688a3f1f5b436aefChristine Chen
117c155f799fc0d4a2c9577f1e0688a3f1f5b436aefChristine Chen    @Override
118dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon    public void onAudioMode(int mode) {
1198b6c8d0dbfba6eabe3d835f8cdcec8a13e253d0cChiao Cheng        if (getUi() != null) {
1208b6c8d0dbfba6eabe3d835f8cdcec8a13e253d0cChiao Cheng            getUi().setAudio(mode);
1218b6c8d0dbfba6eabe3d835f8cdcec8a13e253d0cChiao Cheng        }
122dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon    }
123dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon
124dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon    @Override
125dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon    public void onSupportedAudioMode(int mask) {
1268b6c8d0dbfba6eabe3d835f8cdcec8a13e253d0cChiao Cheng        if (getUi() != null) {
1278b6c8d0dbfba6eabe3d835f8cdcec8a13e253d0cChiao Cheng            getUi().setSupportedAudio(mask);
1288b6c8d0dbfba6eabe3d835f8cdcec8a13e253d0cChiao Cheng        }
129dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon    }
130dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon
1313e69e4fe0e6dbce738cc6b3f9a71fc177e9fe1b6Santos Cordon    @Override
1323e69e4fe0e6dbce738cc6b3f9a71fc177e9fe1b6Santos Cordon    public void onMute(boolean muted) {
1337154c3df1cd121a61b8fdd51f6e936be735c4e2bAndrew Lee        if (getUi() != null && !mAutomaticallyMuted) {
1343e69e4fe0e6dbce738cc6b3f9a71fc177e9fe1b6Santos Cordon            getUi().setMute(muted);
1353e69e4fe0e6dbce738cc6b3f9a71fc177e9fe1b6Santos Cordon        }
1363e69e4fe0e6dbce738cc6b3f9a71fc177e9fe1b6Santos Cordon    }
1373e69e4fe0e6dbce738cc6b3f9a71fc177e9fe1b6Santos Cordon
138dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon    public int getAudioMode() {
139b0d08a16da088e01f416f52a7b74ee9630c1493aSantos Cordon        return AudioModeProvider.getInstance().getAudioMode();
140dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon    }
141dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon
142dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon    public int getSupportedAudio() {
143b0d08a16da088e01f416f52a7b74ee9630c1493aSantos Cordon        return AudioModeProvider.getInstance().getSupportedModes();
144dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon    }
145dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon
146dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon    public void setAudioMode(int mode) {
147dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon
148dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon        // TODO: Set a intermediate state in this presenter until we get
149dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon        // an update for onAudioMode().  This will make UI response immediate
150dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon        // if it turns out to be slow
151dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon
1521a7f2bcab2d2023f2ee4cfb0bc57bc265b5aab87Chiao Cheng        Log.d(this, "Sending new Audio Mode: " + AudioMode.toString(mode));
153fc22ba88566ef70e202128335231c367de6c52afSailesh Nepal        TelecommAdapter.getInstance().setAudioRoute(mode);
154dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon    }
155dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon
156dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon    /**
157dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon     * Function assumes that bluetooth is not supported.
158dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon     */
159dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon    public void toggleSpeakerphone() {
160dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon        // this function should not be called if bluetooth is available
1619de3d7c5188c02cabf03799f87d494ee7dc702cbSantos Cordon        if (0 != (AudioMode.BLUETOOTH & getSupportedAudio())) {
162dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon
1639de3d7c5188c02cabf03799f87d494ee7dc702cbSantos Cordon            // It's clear the UI is wrong, so update the supported mode once again.
1641a7f2bcab2d2023f2ee4cfb0bc57bc265b5aab87Chiao Cheng            Log.e(this, "toggling speakerphone not allowed when bluetooth supported.");
1659de3d7c5188c02cabf03799f87d494ee7dc702cbSantos Cordon            getUi().setSupportedAudio(getSupportedAudio());
166dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon            return;
167dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon        }
168dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon
169dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon        int newMode = AudioMode.SPEAKER;
170dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon
171dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon        // if speakerphone is already on, change to wired/earpiece
1729de3d7c5188c02cabf03799f87d494ee7dc702cbSantos Cordon        if (getAudioMode() == AudioMode.SPEAKER) {
173dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon            newMode = AudioMode.WIRED_OR_EARPIECE;
174dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon        }
175dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon
176dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon        setAudioMode(newMode);
177dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon    }
178dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon
1790f09a02be361d5bb36fac6981649204f5d6987faChristine Chen    public void manageConferenceButtonClicked() {
1800f09a02be361d5bb36fac6981649204f5d6987faChristine Chen        getUi().displayManageConferencePanel(true);
1810f09a02be361d5bb36fac6981649204f5d6987faChristine Chen    }
1820f09a02be361d5bb36fac6981649204f5d6987faChristine Chen
183241d50d5f523eb0b644d8a9c1cf7fd2eb418ab88Chiao Cheng    public void muteClicked(boolean checked) {
1841a7f2bcab2d2023f2ee4cfb0bc57bc265b5aab87Chiao Cheng        Log.d(this, "turning on mute: " + checked);
185fc22ba88566ef70e202128335231c367de6c52afSailesh Nepal        TelecommAdapter.getInstance().mute(checked);
186241d50d5f523eb0b644d8a9c1cf7fd2eb418ab88Chiao Cheng    }
187241d50d5f523eb0b644d8a9c1cf7fd2eb418ab88Chiao Cheng
1888193bc3df6b0726d36a5b7b889ec91c4d59f40c1Santos Cordon    public void holdClicked(boolean checked) {
189e286f91abd12dee037de19c3836d8002e450a9c9Santos Cordon        if (mCall == null) {
190e286f91abd12dee037de19c3836d8002e450a9c9Santos Cordon            return;
191e286f91abd12dee037de19c3836d8002e450a9c9Santos Cordon        }
192fc22ba88566ef70e202128335231c367de6c52afSailesh Nepal        if (checked) {
193fc22ba88566ef70e202128335231c367de6c52afSailesh Nepal            Log.i(this, "Putting the call on hold: " + mCall);
194df06e232852a93d8238f3cacaab4d704de7e1216Ihab Awad            TelecommAdapter.getInstance().holdCall(mCall.getId());
195fc22ba88566ef70e202128335231c367de6c52afSailesh Nepal        } else {
196fc22ba88566ef70e202128335231c367de6c52afSailesh Nepal            Log.i(this, "Removing the call from hold: " + mCall);
197df06e232852a93d8238f3cacaab4d704de7e1216Ihab Awad            TelecommAdapter.getInstance().unholdCall(mCall.getId());
1980e7d8b3f2a18171087b3fe4aa9cc3bf4449ad5b3Yorke Lee        }
1998193bc3df6b0726d36a5b7b889ec91c4d59f40c1Santos Cordon    }
2008193bc3df6b0726d36a5b7b889ec91c4d59f40c1Santos Cordon
20161b7737bc556865097f9ca846bddb562371013fdSantos Cordon    public void mergeClicked() {
202df06e232852a93d8238f3cacaab4d704de7e1216Ihab Awad        TelecommAdapter.getInstance().merge(mCall.getId());
20361b7737bc556865097f9ca846bddb562371013fdSantos Cordon    }
20461b7737bc556865097f9ca846bddb562371013fdSantos Cordon
20561b7737bc556865097f9ca846bddb562371013fdSantos Cordon    public void addCallClicked() {
206e08284ea58e98666e6f1b45734d9901de91c2bb4Yorke Lee        // Automatically mute the current call
207e08284ea58e98666e6f1b45734d9901de91c2bb4Yorke Lee        mAutomaticallyMuted = true;
208b0d08a16da088e01f416f52a7b74ee9630c1493aSantos Cordon        mPreviousMuteState = AudioModeProvider.getInstance().getMute();
209a485665ec253f0a04cf7e411cb7acc2738196c63Yorke Lee        // Simulate a click on the mute button
210a485665ec253f0a04cf7e411cb7acc2738196c63Yorke Lee        muteClicked(true);
211e08284ea58e98666e6f1b45734d9901de91c2bb4Yorke Lee
212fc22ba88566ef70e202128335231c367de6c52afSailesh Nepal        TelecommAdapter.getInstance().addCall();
21361b7737bc556865097f9ca846bddb562371013fdSantos Cordon    }
21461b7737bc556865097f9ca846bddb562371013fdSantos Cordon
215746ee736f255772f7da308765fab22ba7512a10eAndrew Lee    public void changeToVoiceClicked() {
216746ee736f255772f7da308765fab22ba7512a10eAndrew Lee        RemoteCallVideoProvider callVideoProvider = mCall.getCallVideoProvider();
217746ee736f255772f7da308765fab22ba7512a10eAndrew Lee        if (callVideoProvider == null) {
218746ee736f255772f7da308765fab22ba7512a10eAndrew Lee            return;
219746ee736f255772f7da308765fab22ba7512a10eAndrew Lee        }
220746ee736f255772f7da308765fab22ba7512a10eAndrew Lee
221746ee736f255772f7da308765fab22ba7512a10eAndrew Lee        VideoCallProfile videoCallProfile = new VideoCallProfile(
222746ee736f255772f7da308765fab22ba7512a10eAndrew Lee                VideoCallProfile.VIDEO_STATE_AUDIO_ONLY, VideoCallProfile.QUALITY_DEFAULT);
223746ee736f255772f7da308765fab22ba7512a10eAndrew Lee        callVideoProvider.sendSessionModifyRequest(videoCallProfile);
224746ee736f255772f7da308765fab22ba7512a10eAndrew Lee    }
225746ee736f255772f7da308765fab22ba7512a10eAndrew Lee
22661b7737bc556865097f9ca846bddb562371013fdSantos Cordon    public void swapClicked() {
227df06e232852a93d8238f3cacaab4d704de7e1216Ihab Awad        TelecommAdapter.getInstance().swap(mCall.getId());
22861b7737bc556865097f9ca846bddb562371013fdSantos Cordon    }
22961b7737bc556865097f9ca846bddb562371013fdSantos Cordon
2305b9034b5b1b48a4339dd2f893a851cc64d6279dfChristine Chen    public void showDialpadClicked(boolean checked) {
2311a7f2bcab2d2023f2ee4cfb0bc57bc265b5aab87Chiao Cheng        Log.v(this, "Show dialpad " + String.valueOf(checked));
23281bcf2a2e1c197655cf4a3aaf7d9af8088cf102eSai Cheemalapati        getUi().displayDialpad(checked /* show */, true /* animate */);
23346c57f18a63d5923b0b93f1988a56bb4beb9cc5dChristine Chen        updateExtraButtonRow();
2345b9034b5b1b48a4339dd2f893a851cc64d6279dfChristine Chen    }
2355b9034b5b1b48a4339dd2f893a851cc64d6279dfChristine Chen
236746ee736f255772f7da308765fab22ba7512a10eAndrew Lee    public void changeToVideoClicked() {
237746ee736f255772f7da308765fab22ba7512a10eAndrew Lee        RemoteCallVideoProvider callVideoProvider = mCall.getCallVideoProvider();
238746ee736f255772f7da308765fab22ba7512a10eAndrew Lee        if (callVideoProvider == null) {
239746ee736f255772f7da308765fab22ba7512a10eAndrew Lee            return;
240746ee736f255772f7da308765fab22ba7512a10eAndrew Lee        }
241746ee736f255772f7da308765fab22ba7512a10eAndrew Lee
242746ee736f255772f7da308765fab22ba7512a10eAndrew Lee        VideoCallProfile videoCallProfile =
243746ee736f255772f7da308765fab22ba7512a10eAndrew Lee                new VideoCallProfile(VideoCallProfile.VIDEO_STATE_BIDIRECTIONAL);
244746ee736f255772f7da308765fab22ba7512a10eAndrew Lee        callVideoProvider.sendSessionModifyRequest(videoCallProfile);
245746ee736f255772f7da308765fab22ba7512a10eAndrew Lee    }
246746ee736f255772f7da308765fab22ba7512a10eAndrew Lee
247746ee736f255772f7da308765fab22ba7512a10eAndrew Lee    /**
248746ee736f255772f7da308765fab22ba7512a10eAndrew Lee     * Switches the camera between the front-facing and back-facing camera.
249746ee736f255772f7da308765fab22ba7512a10eAndrew Lee     * @param useFrontFacingCamera True if we should switch to using the front-facing camera, or
250746ee736f255772f7da308765fab22ba7512a10eAndrew Lee     *     false if we should switch to using the back-facing camera.
251746ee736f255772f7da308765fab22ba7512a10eAndrew Lee     */
252746ee736f255772f7da308765fab22ba7512a10eAndrew Lee    public void switchCameraClicked(boolean useFrontFacingCamera) {
253746ee736f255772f7da308765fab22ba7512a10eAndrew Lee        mUseFrontFacingCamera = useFrontFacingCamera;
254746ee736f255772f7da308765fab22ba7512a10eAndrew Lee
255746ee736f255772f7da308765fab22ba7512a10eAndrew Lee        RemoteCallVideoProvider callVideoProvider = mCall.getCallVideoProvider();
256746ee736f255772f7da308765fab22ba7512a10eAndrew Lee        if (callVideoProvider == null) {
257746ee736f255772f7da308765fab22ba7512a10eAndrew Lee            return;
258746ee736f255772f7da308765fab22ba7512a10eAndrew Lee        }
259746ee736f255772f7da308765fab22ba7512a10eAndrew Lee
260746ee736f255772f7da308765fab22ba7512a10eAndrew Lee        String cameraId = getCameraId();
261746ee736f255772f7da308765fab22ba7512a10eAndrew Lee        if (cameraId != null) {
262746ee736f255772f7da308765fab22ba7512a10eAndrew Lee            callVideoProvider.setCamera(cameraId);
263746ee736f255772f7da308765fab22ba7512a10eAndrew Lee        }
264746ee736f255772f7da308765fab22ba7512a10eAndrew Lee        getUi().setSwitchCameraButton(!useFrontFacingCamera);
265746ee736f255772f7da308765fab22ba7512a10eAndrew Lee    }
266746ee736f255772f7da308765fab22ba7512a10eAndrew Lee
267746ee736f255772f7da308765fab22ba7512a10eAndrew Lee    /**
268746ee736f255772f7da308765fab22ba7512a10eAndrew Lee     * Stop or start client's video transmission.
269746ee736f255772f7da308765fab22ba7512a10eAndrew Lee     * @param pause True if pausing the local user's video, or false if starting the local user's
270746ee736f255772f7da308765fab22ba7512a10eAndrew Lee     *    video.
271746ee736f255772f7da308765fab22ba7512a10eAndrew Lee     */
272746ee736f255772f7da308765fab22ba7512a10eAndrew Lee    public void pauseVideoClicked(boolean pause) {
273746ee736f255772f7da308765fab22ba7512a10eAndrew Lee        RemoteCallVideoProvider callVideoProvider = mCall.getCallVideoProvider();
274746ee736f255772f7da308765fab22ba7512a10eAndrew Lee        if (callVideoProvider == null) {
275746ee736f255772f7da308765fab22ba7512a10eAndrew Lee            return;
276746ee736f255772f7da308765fab22ba7512a10eAndrew Lee        }
277746ee736f255772f7da308765fab22ba7512a10eAndrew Lee
278746ee736f255772f7da308765fab22ba7512a10eAndrew Lee        if (pause) {
279746ee736f255772f7da308765fab22ba7512a10eAndrew Lee            callVideoProvider.setCamera(null);
280746ee736f255772f7da308765fab22ba7512a10eAndrew Lee            VideoCallProfile videoCallProfile = new VideoCallProfile(
281746ee736f255772f7da308765fab22ba7512a10eAndrew Lee                    mCall.getVideoState() | VideoCallProfile.VIDEO_STATE_PAUSED);
282746ee736f255772f7da308765fab22ba7512a10eAndrew Lee            callVideoProvider.sendSessionModifyRequest(videoCallProfile);
283746ee736f255772f7da308765fab22ba7512a10eAndrew Lee        } else {
284746ee736f255772f7da308765fab22ba7512a10eAndrew Lee            callVideoProvider.setCamera(getCameraId());
285746ee736f255772f7da308765fab22ba7512a10eAndrew Lee            VideoCallProfile videoCallProfile = new VideoCallProfile(
286746ee736f255772f7da308765fab22ba7512a10eAndrew Lee                    mCall.getVideoState() & ~VideoCallProfile.VIDEO_STATE_PAUSED);
287746ee736f255772f7da308765fab22ba7512a10eAndrew Lee            callVideoProvider.sendSessionModifyRequest(videoCallProfile);
288746ee736f255772f7da308765fab22ba7512a10eAndrew Lee        }
289746ee736f255772f7da308765fab22ba7512a10eAndrew Lee        getUi().setPauseVideoButton(pause);
290746ee736f255772f7da308765fab22ba7512a10eAndrew Lee    }
291746ee736f255772f7da308765fab22ba7512a10eAndrew Lee
292bc168c4fb0638846c5076a5a35a2e75ee4947908Santos Cordon    private void updateUi(InCallState state, Call call) {
29389fbf5c95d0f0ed345c5e5b251ead1c519144c88Andrew Lee        Log.d(this, "Updating call UI for call: ", call);
29489fbf5c95d0f0ed345c5e5b251ead1c519144c88Andrew Lee
295bc168c4fb0638846c5076a5a35a2e75ee4947908Santos Cordon        final CallButtonUi ui = getUi();
296bc168c4fb0638846c5076a5a35a2e75ee4947908Santos Cordon        if (ui == null) {
297bc168c4fb0638846c5076a5a35a2e75ee4947908Santos Cordon            return;
298bc168c4fb0638846c5076a5a35a2e75ee4947908Santos Cordon        }
299bc168c4fb0638846c5076a5a35a2e75ee4947908Santos Cordon
30089fbf5c95d0f0ed345c5e5b251ead1c519144c88Andrew Lee        final boolean isEnabled =
30189fbf5c95d0f0ed345c5e5b251ead1c519144c88Andrew Lee                state.isConnectingOrConnected() &&!state.isIncoming() && call != null;
30218db3795cd475434ee28841de75b3d85eab5fa57Ben Gilad        ui.setEnabled(isEnabled);
30361b7737bc556865097f9ca846bddb562371013fdSantos Cordon
30489fbf5c95d0f0ed345c5e5b251ead1c519144c88Andrew Lee        if (!isEnabled) {
30589fbf5c95d0f0ed345c5e5b251ead1c519144c88Andrew Lee            return;
30646c57f18a63d5923b0b93f1988a56bb4beb9cc5dChristine Chen        }
30789fbf5c95d0f0ed345c5e5b251ead1c519144c88Andrew Lee
3082b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee        if (call.isVideoCall()) {
3092b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee            updateVideoCallButtons(call);
3102b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee        } else {
3112b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee            updateVoiceCallButtons(call);
3122b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee        }
3132b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee
3142b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee        ui.enableMute(call.can(CallCapabilities.MUTE));
3152b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee
3162b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee        // Finally, update the "extra button row": It's displayed above the "End" button, but only
3172b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee        // if necessary. It's never displayed while the dialpad is visible since it would overlap.
3182b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee        //
3192b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee        // The row contains two buttons:
3202b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee        //     - "Manage conference" (used only on GSM devices)
3212b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee        //     - "Merge" button (used only on CDMA devices)
3222b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee        final boolean canMerge = call.can(CallCapabilities.MERGE_CALLS);
3232b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee        final boolean isGenericConference = call.can(CallCapabilities.GENERIC_CONFERENCE);
3242b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee        mShowGenericMerge = isGenericConference && canMerge;
3252b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee        mShowManageConference = (call.isConferenceCall() && !isGenericConference);
3262b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee        updateExtraButtonRow();
3272b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee    }
3282b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee
3292b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee    private void updateVideoCallButtons(Call call) {
3302b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee        Log.v(this, "Showing buttons for video call.");
3312b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee        final CallButtonUi ui = getUi();
3322b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee
3332b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee        // Hide all voice-call-related buttons.
3342b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee        ui.showAudioButton(false);
3352b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee        ui.showDialpadButton(false);
3362b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee        ui.showHoldButton(false);
3372b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee        ui.showSwapButton(false);
3382b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee        ui.showChangeToVideoButton(false);
3392b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee        ui.showAddCallButton(false);
3402b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee        ui.showMergeButton(false);
3412b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee        ui.showOverflowButton(false);
3422b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee
3432b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee        // Show all video-call-related buttons.
3442b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee        ui.showChangeToVoiceButton(true);
3452b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee        ui.showSwitchCameraButton(true);
3462b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee        ui.showPauseVideoButton(true);
3472b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee    }
3482b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee
3492b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee    private void updateVoiceCallButtons(Call call) {
3502b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee        Log.v(this, "Showing buttons for voice call.");
3512b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee        final CallButtonUi ui = getUi();
3522b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee
3532b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee        // Hide all video-call-related buttons.
3542b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee        ui.showChangeToVoiceButton(false);
3552b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee        ui.showSwitchCameraButton(false);
3562b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee        ui.showPauseVideoButton(false);
3572b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee
3582b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee        // Show all voice-call-related buttons.
3592b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee        ui.showAudioButton(true);
3602b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee        ui.showDialpadButton(true);
3612b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee
36289fbf5c95d0f0ed345c5e5b251ead1c519144c88Andrew Lee        Log.v(this, "Show hold ", call.can(CallCapabilities.SUPPORT_HOLD));
36389fbf5c95d0f0ed345c5e5b251ead1c519144c88Andrew Lee        Log.v(this, "Enable hold", call.can(CallCapabilities.HOLD));
36489fbf5c95d0f0ed345c5e5b251ead1c519144c88Andrew Lee        Log.v(this, "Show merge ", call.can(CallCapabilities.MERGE_CALLS));
36589fbf5c95d0f0ed345c5e5b251ead1c519144c88Andrew Lee        Log.v(this, "Show swap ", call.can(CallCapabilities.SWAP_CALLS));
36689fbf5c95d0f0ed345c5e5b251ead1c519144c88Andrew Lee        Log.v(this, "Show add call ", call.can(CallCapabilities.ADD_CALL));
36789fbf5c95d0f0ed345c5e5b251ead1c519144c88Andrew Lee        Log.v(this, "Show mute ", call.can(CallCapabilities.MUTE));
36889fbf5c95d0f0ed345c5e5b251ead1c519144c88Andrew Lee
36989fbf5c95d0f0ed345c5e5b251ead1c519144c88Andrew Lee        final boolean canMerge = call.can(CallCapabilities.MERGE_CALLS);
37089fbf5c95d0f0ed345c5e5b251ead1c519144c88Andrew Lee        final boolean canAdd = call.can(CallCapabilities.ADD_CALL);
37189fbf5c95d0f0ed345c5e5b251ead1c519144c88Andrew Lee        final boolean isGenericConference = call.can(CallCapabilities.GENERIC_CONFERENCE);
37289fbf5c95d0f0ed345c5e5b251ead1c519144c88Andrew Lee        final boolean canHold = call.can(CallCapabilities.HOLD);
37389fbf5c95d0f0ed345c5e5b251ead1c519144c88Andrew Lee        final boolean canSwap = call.can(CallCapabilities.SWAP_CALLS);
37489fbf5c95d0f0ed345c5e5b251ead1c519144c88Andrew Lee        final boolean supportHold = call.can(CallCapabilities.SUPPORT_HOLD);
3752b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee        boolean canVideoCall = call.can(CallCapabilities.SUPPORTS_VT_LOCAL)
3762b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee                && call.can(CallCapabilities.SUPPORTS_VT_REMOTE);
37789fbf5c95d0f0ed345c5e5b251ead1c519144c88Andrew Lee
37889fbf5c95d0f0ed345c5e5b251ead1c519144c88Andrew Lee        final boolean showMerge = !isGenericConference && canMerge;
37989fbf5c95d0f0ed345c5e5b251ead1c519144c88Andrew Lee
3802b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee        ui.showChangeToVideoButton(canVideoCall);
38189fbf5c95d0f0ed345c5e5b251ead1c519144c88Andrew Lee
382ddb824ecb3f052551b3ea97d5f5cb3037ec4c683Andrew Lee        // Show either MERGE or ADD, but not both.
383ddb824ecb3f052551b3ea97d5f5cb3037ec4c683Andrew Lee        final boolean showMergeOption = showMerge;
384ddb824ecb3f052551b3ea97d5f5cb3037ec4c683Andrew Lee        final boolean showAddCallOption = !showMerge;
385ddb824ecb3f052551b3ea97d5f5cb3037ec4c683Andrew Lee        final boolean enableAddCallOption = showAddCallOption && canAdd;
386ddb824ecb3f052551b3ea97d5f5cb3037ec4c683Andrew Lee        // Show either HOLD or SWAP, but not both.
387ddb824ecb3f052551b3ea97d5f5cb3037ec4c683Andrew Lee        // If neither HOLD or SWAP is available:
388ddb824ecb3f052551b3ea97d5f5cb3037ec4c683Andrew Lee        //     (1) If the device normally can hold/swap, show HOLD in a disabled state.
389ddb824ecb3f052551b3ea97d5f5cb3037ec4c683Andrew Lee        //     (2) If the device doesn't have the concept of hold/swap, remove the button.
390ddb824ecb3f052551b3ea97d5f5cb3037ec4c683Andrew Lee        final boolean showHoldOption = canHold || (!canSwap && supportHold);
391ddb824ecb3f052551b3ea97d5f5cb3037ec4c683Andrew Lee        final boolean enableHoldOption = canHold;
392ddb824ecb3f052551b3ea97d5f5cb3037ec4c683Andrew Lee        final boolean showSwapOption = !canHold && canSwap;
393ddb824ecb3f052551b3ea97d5f5cb3037ec4c683Andrew Lee
394ddb824ecb3f052551b3ea97d5f5cb3037ec4c683Andrew Lee        ui.setHold(call.getState() == Call.State.ONHOLD);
395ddb824ecb3f052551b3ea97d5f5cb3037ec4c683Andrew Lee        if (canVideoCall && (showAddCallOption || showMergeOption)
396ddb824ecb3f052551b3ea97d5f5cb3037ec4c683Andrew Lee                && (showHoldOption || showSwapOption)) {
3972b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee            ui.showHoldButton(false);
3982b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee            ui.showSwapButton(false);
3992b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee            ui.showAddCallButton(false);
4002b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee            ui.showMergeButton(false);
40189fbf5c95d0f0ed345c5e5b251ead1c519144c88Andrew Lee
4022b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee            ui.showOverflowButton(true);
403ddb824ecb3f052551b3ea97d5f5cb3037ec4c683Andrew Lee            ui.configureOverflowMenu(
404ddb824ecb3f052551b3ea97d5f5cb3037ec4c683Andrew Lee                    showMergeOption,
405ddb824ecb3f052551b3ea97d5f5cb3037ec4c683Andrew Lee                    showAddCallOption && enableAddCallOption /* showAddMenuOption */,
406ddb824ecb3f052551b3ea97d5f5cb3037ec4c683Andrew Lee                    showHoldOption && enableHoldOption /* showHoldMenuOption */,
407ddb824ecb3f052551b3ea97d5f5cb3037ec4c683Andrew Lee                    showSwapOption);
4082b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee        } else {
409ddb824ecb3f052551b3ea97d5f5cb3037ec4c683Andrew Lee            ui.showMergeButton(showMergeOption);
410ddb824ecb3f052551b3ea97d5f5cb3037ec4c683Andrew Lee            ui.showAddCallButton(showAddCallOption);
411ddb824ecb3f052551b3ea97d5f5cb3037ec4c683Andrew Lee            ui.enableAddCall(enableAddCallOption);
412ddb824ecb3f052551b3ea97d5f5cb3037ec4c683Andrew Lee
413ddb824ecb3f052551b3ea97d5f5cb3037ec4c683Andrew Lee            ui.showHoldButton(showHoldOption);
414ddb824ecb3f052551b3ea97d5f5cb3037ec4c683Andrew Lee            ui.enableHold(enableHoldOption);
415ddb824ecb3f052551b3ea97d5f5cb3037ec4c683Andrew Lee            ui.showSwapButton(showSwapOption);
4162b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee        }
41746c57f18a63d5923b0b93f1988a56bb4beb9cc5dChristine Chen    }
41846c57f18a63d5923b0b93f1988a56bb4beb9cc5dChristine Chen
41946c57f18a63d5923b0b93f1988a56bb4beb9cc5dChristine Chen    private void updateExtraButtonRow() {
42046c57f18a63d5923b0b93f1988a56bb4beb9cc5dChristine Chen        final boolean showExtraButtonRow = (mShowGenericMerge || mShowManageConference) &&
42146c57f18a63d5923b0b93f1988a56bb4beb9cc5dChristine Chen                !getUi().isDialpadVisible();
42246c57f18a63d5923b0b93f1988a56bb4beb9cc5dChristine Chen
42346c57f18a63d5923b0b93f1988a56bb4beb9cc5dChristine Chen        Log.d(this, "isGeneric: " + mShowGenericMerge);
42446c57f18a63d5923b0b93f1988a56bb4beb9cc5dChristine Chen        Log.d(this, "mShowManageConference : " + mShowManageConference);
42546c57f18a63d5923b0b93f1988a56bb4beb9cc5dChristine Chen        Log.d(this, "mShowGenericMerge: " + mShowGenericMerge);
42646c57f18a63d5923b0b93f1988a56bb4beb9cc5dChristine Chen        if (showExtraButtonRow) {
42746c57f18a63d5923b0b93f1988a56bb4beb9cc5dChristine Chen            if (mShowGenericMerge) {
42846c57f18a63d5923b0b93f1988a56bb4beb9cc5dChristine Chen                getUi().showGenericMergeButton();
42946c57f18a63d5923b0b93f1988a56bb4beb9cc5dChristine Chen            } else if (mShowManageConference) {
43046c57f18a63d5923b0b93f1988a56bb4beb9cc5dChristine Chen                getUi().showManageConferenceCallButton();
4310f09a02be361d5bb36fac6981649204f5d6987faChristine Chen            }
43246c57f18a63d5923b0b93f1988a56bb4beb9cc5dChristine Chen        } else {
43346c57f18a63d5923b0b93f1988a56bb4beb9cc5dChristine Chen            getUi().hideExtraRow();
434bc168c4fb0638846c5076a5a35a2e75ee4947908Santos Cordon        }
435bc168c4fb0638846c5076a5a35a2e75ee4947908Santos Cordon    }
436bc168c4fb0638846c5076a5a35a2e75ee4947908Santos Cordon
437746ee736f255772f7da308765fab22ba7512a10eAndrew Lee    private String getCameraId() {
438746ee736f255772f7da308765fab22ba7512a10eAndrew Lee        String[] cameraIds = {};
439746ee736f255772f7da308765fab22ba7512a10eAndrew Lee        String cameraId = null;
440746ee736f255772f7da308765fab22ba7512a10eAndrew Lee        int targetCharacteristic = mUseFrontFacingCamera
441746ee736f255772f7da308765fab22ba7512a10eAndrew Lee                ? CameraCharacteristics.LENS_FACING_FRONT : CameraCharacteristics.LENS_FACING_BACK;
442746ee736f255772f7da308765fab22ba7512a10eAndrew Lee
443746ee736f255772f7da308765fab22ba7512a10eAndrew Lee        try {
444746ee736f255772f7da308765fab22ba7512a10eAndrew Lee            cameraIds = mCameraManager.getCameraIdList();
445746ee736f255772f7da308765fab22ba7512a10eAndrew Lee        } catch (CameraAccessException e) {
446746ee736f255772f7da308765fab22ba7512a10eAndrew Lee            // Camera disabled by device policy.
447746ee736f255772f7da308765fab22ba7512a10eAndrew Lee        }
448746ee736f255772f7da308765fab22ba7512a10eAndrew Lee
449746ee736f255772f7da308765fab22ba7512a10eAndrew Lee        for (int i = 0; i < cameraIds.length; i++) {
450746ee736f255772f7da308765fab22ba7512a10eAndrew Lee            CameraCharacteristics c = null;
451746ee736f255772f7da308765fab22ba7512a10eAndrew Lee            try {
452746ee736f255772f7da308765fab22ba7512a10eAndrew Lee                c = mCameraManager.getCameraCharacteristics(cameraIds[i]);
453746ee736f255772f7da308765fab22ba7512a10eAndrew Lee            } catch (IllegalArgumentException e) {
454746ee736f255772f7da308765fab22ba7512a10eAndrew Lee                // Device Id is unknown.
455746ee736f255772f7da308765fab22ba7512a10eAndrew Lee            } catch (CameraAccessException e) {
456746ee736f255772f7da308765fab22ba7512a10eAndrew Lee                // Camera disabled by device policy.
457746ee736f255772f7da308765fab22ba7512a10eAndrew Lee            }
458746ee736f255772f7da308765fab22ba7512a10eAndrew Lee            if (c != null) {
459746ee736f255772f7da308765fab22ba7512a10eAndrew Lee                int facingCharacteristic = c.get(CameraCharacteristics.LENS_FACING);
460746ee736f255772f7da308765fab22ba7512a10eAndrew Lee                if (facingCharacteristic == targetCharacteristic) {
461746ee736f255772f7da308765fab22ba7512a10eAndrew Lee                    cameraId = cameraIds[i];
462746ee736f255772f7da308765fab22ba7512a10eAndrew Lee                    break;
463746ee736f255772f7da308765fab22ba7512a10eAndrew Lee                }
464746ee736f255772f7da308765fab22ba7512a10eAndrew Lee            }
465746ee736f255772f7da308765fab22ba7512a10eAndrew Lee        }
466746ee736f255772f7da308765fab22ba7512a10eAndrew Lee
467746ee736f255772f7da308765fab22ba7512a10eAndrew Lee        return cameraId;
468746ee736f255772f7da308765fab22ba7512a10eAndrew Lee    }
469746ee736f255772f7da308765fab22ba7512a10eAndrew Lee
470eb7244f3001ca3b001b17bda99ab5c790eb1b2d3Christine Chen    public void refreshMuteState() {
471eb7244f3001ca3b001b17bda99ab5c790eb1b2d3Christine Chen        // Restore the previous mute state
472eb7244f3001ca3b001b17bda99ab5c790eb1b2d3Christine Chen        if (mAutomaticallyMuted &&
473eb7244f3001ca3b001b17bda99ab5c790eb1b2d3Christine Chen                AudioModeProvider.getInstance().getMute() != mPreviousMuteState) {
474eb7244f3001ca3b001b17bda99ab5c790eb1b2d3Christine Chen            if (getUi() == null) {
475eb7244f3001ca3b001b17bda99ab5c790eb1b2d3Christine Chen                return;
476eb7244f3001ca3b001b17bda99ab5c790eb1b2d3Christine Chen            }
477eb7244f3001ca3b001b17bda99ab5c790eb1b2d3Christine Chen            muteClicked(mPreviousMuteState);
478eb7244f3001ca3b001b17bda99ab5c790eb1b2d3Christine Chen        }
479eb7244f3001ca3b001b17bda99ab5c790eb1b2d3Christine Chen        mAutomaticallyMuted = false;
480eb7244f3001ca3b001b17bda99ab5c790eb1b2d3Christine Chen    }
481eb7244f3001ca3b001b17bda99ab5c790eb1b2d3Christine Chen
482241d50d5f523eb0b644d8a9c1cf7fd2eb418ab88Chiao Cheng    public interface CallButtonUi extends Ui {
48318db3795cd475434ee28841de75b3d85eab5fa57Ben Gilad        void setEnabled(boolean on);
484241d50d5f523eb0b644d8a9c1cf7fd2eb418ab88Chiao Cheng        void setMute(boolean on);
485fe09b09a955c574d1131932211a05f862ee9e50fChristine Chen        void enableMute(boolean enabled);
4862b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee        void showAudioButton(boolean show);
4872b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee        void showChangeToVoiceButton(boolean show);
4882b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee        void showDialpadButton(boolean show);
4898193bc3df6b0726d36a5b7b889ec91c4d59f40c1Santos Cordon        void setHold(boolean on);
4902b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee        void showHoldButton(boolean show);
491fe09b09a955c574d1131932211a05f862ee9e50fChristine Chen        void enableHold(boolean enabled);
4922b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee        void showSwapButton(boolean show);
4932b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee        void showChangeToVideoButton(boolean show);
4942b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee        void showSwitchCameraButton(boolean show);
495746ee736f255772f7da308765fab22ba7512a10eAndrew Lee        void setSwitchCameraButton(boolean isBackFacingCamera);
4962b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee        void showAddCallButton(boolean show);
497fe09b09a955c574d1131932211a05f862ee9e50fChristine Chen        void enableAddCall(boolean enabled);
4982b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee        void showMergeButton(boolean show);
4992b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee        void showPauseVideoButton(boolean show);
500746ee736f255772f7da308765fab22ba7512a10eAndrew Lee        void setPauseVideoButton(boolean isPaused);
5012b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee        void showOverflowButton(boolean show);
50281bcf2a2e1c197655cf4a3aaf7d9af8088cf102eSai Cheemalapati        void displayDialpad(boolean on, boolean animate);
5030f09a02be361d5bb36fac6981649204f5d6987faChristine Chen        boolean isDialpadVisible();
504dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon        void setAudio(int mode);
505dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon        void setSupportedAudio(int mask);
506ddb824ecb3f052551b3ea97d5f5cb3037ec4c683Andrew Lee        void configureOverflowMenu(boolean showMergeMenuOption, boolean showAddMenuOption,
507ddb824ecb3f052551b3ea97d5f5cb3037ec4c683Andrew Lee                boolean showHoldMenuOption, boolean showSwapMenuOption);
5080f09a02be361d5bb36fac6981649204f5d6987faChristine Chen        void showManageConferenceCallButton();
509625ac576cb403744ef0baeba8e8993da963461eeSantos Cordon        void showGenericMergeButton();
5100f09a02be361d5bb36fac6981649204f5d6987faChristine Chen        void hideExtraRow();
5110f09a02be361d5bb36fac6981649204f5d6987faChristine Chen        void displayManageConferencePanel(boolean on);
512241d50d5f523eb0b644d8a9c1cf7fd2eb418ab88Chiao Cheng    }
513241d50d5f523eb0b644d8a9c1cf7fd2eb418ab88Chiao Cheng}
514