blob: 5fd9244a806bb2e80e70334b7a299bfeee7b0b38 [file] [log] [blame]
/*
* 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.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.os.Trace;
import android.support.v4.app.Fragment;
import android.support.v4.os.UserManagerCompat;
import android.telecom.CallAudioState;
import android.telecom.PhoneAccountHandle;
import android.telecom.TelecomManager;
import android.widget.Toast;
import com.android.contacts.common.compat.CallCompat;
import com.android.dialer.common.Assert;
import com.android.dialer.common.LogUtil;
import com.android.dialer.common.concurrent.DialerExecutorComponent;
import com.android.dialer.logging.DialerImpression;
import com.android.dialer.logging.DialerImpression.Type;
import com.android.dialer.logging.Logger;
import com.android.dialer.telecom.TelecomUtil;
import com.android.incallui.InCallCameraManager.Listener;
import com.android.incallui.InCallPresenter.CanAddCallListener;
import com.android.incallui.InCallPresenter.InCallDetailsListener;
import com.android.incallui.InCallPresenter.InCallEventListener;
import com.android.incallui.InCallPresenter.InCallState;
import com.android.incallui.InCallPresenter.InCallStateListener;
import com.android.incallui.InCallPresenter.IncomingCallListener;
import com.android.incallui.audiomode.AudioModeProvider;
import com.android.incallui.audiomode.AudioModeProvider.AudioModeListener;
import com.android.incallui.call.CallList;
import com.android.incallui.call.DialerCall;
import com.android.incallui.call.DialerCall.CameraDirection;
import com.android.incallui.call.DialerCallListener;
import com.android.incallui.call.TelecomAdapter;
import com.android.incallui.call.state.DialerCallState;
import com.android.incallui.incall.protocol.InCallButtonIds;
import com.android.incallui.incall.protocol.InCallButtonUi;
import com.android.incallui.incall.protocol.InCallButtonUiDelegate;
import com.android.incallui.multisim.SwapSimWorker;
import com.android.incallui.videotech.utils.SessionModificationState;
import com.android.incallui.videotech.utils.VideoUtils;
import org.codeaurora.ims.utils.QtiImsExtUtils;
/** Logic for call buttons. */
public class CallButtonPresenter
implements InCallStateListener,
AudioModeListener,
IncomingCallListener,
InCallDetailsListener,
InCallEventListener,
CanAddCallListener,
Listener,
InCallButtonUiDelegate,
DialerCallListener {
private final Context context;
private InCallButtonUi inCallButtonUi;
private DialerCall call;
private boolean isInCallButtonUiReady;
private PhoneAccountHandle otherAccount;
private static final int MAX_PARTICIPANTS_LIMIT = 6;
private final PhoneAccountChangedReceiver phoneAccountChangedReceiver;
public CallButtonPresenter(Context context) {
this.context = context.getApplicationContext();
phoneAccountChangedReceiver = new PhoneAccountChangedReceiver(this);
}
@Override
public void onInCallButtonUiReady(InCallButtonUi ui) {
Assert.checkState(!isInCallButtonUiReady);
inCallButtonUi = ui;
AudioModeProvider.getInstance().addListener(this);
// register for call state changes last
final InCallPresenter inCallPresenter = InCallPresenter.getInstance();
inCallPresenter.addListener(this);
inCallPresenter.addIncomingCallListener(this);
inCallPresenter.addDetailsListener(this);
inCallPresenter.addInCallEventListener(this);
inCallPresenter.addCanAddCallListener(this);
inCallPresenter.getInCallCameraManager().addCameraSelectionListener(this);
// Update the buttons state immediately for the current call
onStateChange(InCallState.NO_CALLS, inCallPresenter.getInCallState(), CallList.getInstance());
phoneAccountChangedReceiver.register();
isInCallButtonUiReady = true;
}
@Override
public void onInCallButtonUiUnready() {
Assert.checkState(isInCallButtonUiReady);
inCallButtonUi = null;
InCallPresenter.getInstance().removeListener(this);
AudioModeProvider.getInstance().removeListener(this);
InCallPresenter.getInstance().removeIncomingCallListener(this);
InCallPresenter.getInstance().removeDetailsListener(this);
InCallPresenter.getInstance().removeInCallEventListener(this);
InCallPresenter.getInstance().getInCallCameraManager().removeCameraSelectionListener(this);
InCallPresenter.getInstance().removeCanAddCallListener(this);
phoneAccountChangedReceiver.unregister();
isInCallButtonUiReady = false;
if (call != null) {
call.removeListener(this);
}
}
@Override
public void onStateChange(InCallState oldState, InCallState newState, CallList callList) {
Trace.beginSection("CallButtonPresenter.onStateChange");
if (call != null) {
call.removeListener(this);
}
if (newState == InCallState.OUTGOING) {
call = callList.getOutgoingCall();
} else if (newState == InCallState.INCALL) {
call = callList.getActiveOrBackgroundCall();
// When connected to voice mail, automatically shows the dialpad.
// (On previous releases we showed it when in-call shows up, before waiting for
// OUTGOING. We may want to do that once we start showing "Voice mail" label on
// the dialpad too.)
if (oldState == InCallState.OUTGOING && call != null) {
if (call.isVoiceMailNumber() && getActivity() != null) {
getActivity().showDialpadFragment(true /* show */, true /* animate */);
}
}
} else if (newState == InCallState.INCOMING) {
if (getActivity() != null) {
getActivity().showDialpadFragment(false /* show */, true /* animate */);
}
call = callList.getIncomingCall();
} else {
call = null;
}
if (call != null) {
call.addListener(this);
}
updateUi(newState, call);
Trace.endSection();
}
/**
* Updates the user interface in response to a change in the details of a call. Currently handles
* changes to the call buttons in response to a change in the details for a call. This is
* important to ensure changes to the active call are reflected in the available buttons.
*
* @param call The active call.
* @param details The call details.
*/
@Override
public void onDetailsChanged(DialerCall call, android.telecom.Call.Details details) {
// Only update if the changes are for the currently active call
if (inCallButtonUi != null && call != null && call.equals(this.call)) {
updateButtonsState(call);
}
}
@Override
public void onIncomingCall(InCallState oldState, InCallState newState, DialerCall call) {
onStateChange(oldState, newState, CallList.getInstance());
}
@Override
public void onCanAddCallChanged(boolean canAddCall) {
if (inCallButtonUi != null && call != null) {
updateButtonsState(call);
}
}
@Override
public void onAudioStateChanged(CallAudioState audioState) {
if (inCallButtonUi != null) {
inCallButtonUi.setAudioState(audioState);
}
}
@Override
public CallAudioState getCurrentAudioState() {
return AudioModeProvider.getInstance().getAudioState();
}
@Override
public void setAudioRoute(int route) {
LogUtil.i(
"CallButtonPresenter.setAudioRoute",
"sending new audio route: " + CallAudioState.audioRouteToString(route));
TelecomAdapter.getInstance().setAudioRoute(route);
}
/** Function assumes that bluetooth is not supported. */
@Override
public void toggleSpeakerphone() {
// This function should not be called if bluetooth is available.
CallAudioState audioState = getCurrentAudioState();
if (0 != (CallAudioState.ROUTE_BLUETOOTH & audioState.getSupportedRouteMask())) {
// It's clear the UI is wrong, so update the supported mode once again.
LogUtil.e(
"CallButtonPresenter", "toggling speakerphone not allowed when bluetooth supported.");
inCallButtonUi.setAudioState(audioState);
return;
}
int newRoute;
if (audioState.getRoute() == CallAudioState.ROUTE_SPEAKER) {
newRoute = CallAudioState.ROUTE_WIRED_OR_EARPIECE;
Logger.get(context)
.logCallImpression(
DialerImpression.Type.IN_CALL_SCREEN_TURN_ON_WIRED_OR_EARPIECE,
call.getUniqueCallId(),
call.getTimeAddedMs());
} else {
newRoute = CallAudioState.ROUTE_SPEAKER;
Logger.get(context)
.logCallImpression(
DialerImpression.Type.IN_CALL_SCREEN_TURN_ON_SPEAKERPHONE,
call.getUniqueCallId(),
call.getTimeAddedMs());
}
setAudioRoute(newRoute);
}
@Override
public void muteClicked(boolean checked, boolean clickedByUser) {
LogUtil.i(
"CallButtonPresenter", "turning on mute: %s, clicked by user: %s", checked, clickedByUser);
if (clickedByUser && call != null) {
Logger.get(context)
.logCallImpression(
checked
? DialerImpression.Type.IN_CALL_SCREEN_TURN_ON_MUTE
: DialerImpression.Type.IN_CALL_SCREEN_TURN_OFF_MUTE,
call.getUniqueCallId(),
call.getTimeAddedMs());
}
TelecomAdapter.getInstance().mute(checked);
}
@Override
public void holdClicked(boolean checked) {
if (call == null) {
return;
}
if (checked) {
LogUtil.i("CallButtonPresenter", "putting the call on hold: " + call);
call.hold();
} else {
LogUtil.i("CallButtonPresenter", "removing the call from hold: " + call);
call.unhold();
}
}
@Override
public void swapClicked() {
if (call == null) {
return;
}
LogUtil.i("CallButtonPresenter", "swapping the call: " + call);
TelecomAdapter.getInstance().swap(call.getId());
}
@Override
public void mergeClicked() {
if (call == null) {
return;
}
Logger.get(context)
.logCallImpression(
DialerImpression.Type.IN_CALL_MERGE_BUTTON_PRESSED,
call.getUniqueCallId(),
call.getTimeAddedMs());
if (QtiImsExtUtils.isCarrierConfigEnabled(BottomSheetHelper.getInstance().getPhoneId(),
context,"config_conference_call_show_participant_status")) {
int participantsCount = 0;
if (call.isConferenceCall()) {
participantsCount = call.getChildCallIds().size();
} else {
DialerCall backgroundCall = CallList.getInstance().getBackgroundCall();
if (backgroundCall != null && backgroundCall.isConferenceCall()) {
participantsCount = backgroundCall.getChildCallIds().size();
}
}
Log.i(this, "Number of participantsCount is " + participantsCount);
if (participantsCount >= MAX_PARTICIPANTS_LIMIT) {
Toast.makeText(context,
R.string.too_many_recipients, Toast.LENGTH_SHORT).show();
return;
}
}
TelecomAdapter.getInstance().merge(call.getId());
}
@Override
public void addCallClicked() {
if (call != null) {
Logger.get(context)
.logCallImpression(
DialerImpression.Type.IN_CALL_ADD_CALL_BUTTON_PRESSED,
call.getUniqueCallId(),
call.getTimeAddedMs());
}
InCallPresenter.getInstance().addCallClicked();
}
@Override
public void showDialpadClicked(boolean checked) {
if (call != null) {
Logger.get(context)
.logCallImpression(
DialerImpression.Type.IN_CALL_SHOW_DIALPAD_BUTTON_PRESSED,
call.getUniqueCallId(),
call.getTimeAddedMs());
}
LogUtil.v("CallButtonPresenter", "show dialpad " + String.valueOf(checked));
getActivity().showDialpadFragment(checked /* show */, true /* animate */);
}
@Override
public void changeToVideoClicked() {
LogUtil.enterBlock("CallButtonPresenter.changeToVideoClicked");
Logger.get(context)
.logCallImpression(
DialerImpression.Type.VIDEO_CALL_UPGRADE_REQUESTED,
call.getUniqueCallId(),
call.getTimeAddedMs());
call.getVideoTech().upgradeToVideo(context);
}
@Override
public void changeToRttClicked() {
LogUtil.enterBlock("CallButtonPresenter.changeToRttClicked");
call.sendRttUpgradeRequest();
}
@Override
public void onEndCallClicked() {
LogUtil.i("CallButtonPresenter.onEndCallClicked", "call: " + call);
if (call != null) {
call.disconnect();
}
}
@Override
public void showAudioRouteSelector() {
inCallButtonUi.showAudioRouteSelector();
}
@Override
public void swapSimClicked() {
LogUtil.enterBlock("CallButtonPresenter.swapSimClicked");
Logger.get(getContext()).logImpression(Type.DUAL_SIM_CHANGE_SIM_PRESSED);
SwapSimWorker worker =
new SwapSimWorker(
getContext(),
call,
InCallPresenter.getInstance().getCallList(),
otherAccount,
InCallPresenter.getInstance().acquireInCallUiLock("swapSim"));
DialerExecutorComponent.get(getContext())
.dialerExecutorFactory()
.createNonUiTaskBuilder(worker)
.build()
.executeParallel(null);
}
/**
* Switches the camera between the front-facing and back-facing camera.
*
* @param useFrontFacingCamera True if we should switch to using the front-facing camera, or false
* if we should switch to using the back-facing camera.
*/
@Override
public void switchCameraClicked(boolean useFrontFacingCamera) {
updateCamera(useFrontFacingCamera);
}
@Override
public void toggleCameraClicked() {
LogUtil.i("CallButtonPresenter.toggleCameraClicked", "");
if (call == null) {
return;
}
Logger.get(context)
.logCallImpression(
DialerImpression.Type.IN_CALL_SCREEN_SWAP_CAMERA,
call.getUniqueCallId(),
call.getTimeAddedMs());
switchCameraClicked(
!InCallPresenter.getInstance().getInCallCameraManager().isUsingFrontFacingCamera());
}
/**
* Stop or start client's video transmission.
*
* @param pause True if pausing the local user's video, or false if starting the local user's
* video.
*/
@Override
public void pauseVideoClicked(boolean pause) {
LogUtil.i("CallButtonPresenter.pauseVideoClicked", "%s", pause ? "pause" : "unpause");
Logger.get(context)
.logCallImpression(
pause
? DialerImpression.Type.IN_CALL_SCREEN_TURN_OFF_VIDEO
: DialerImpression.Type.IN_CALL_SCREEN_TURN_ON_VIDEO,
call.getUniqueCallId(),
call.getTimeAddedMs());
if (pause) {
call.getVideoTech().stopTransmission();
} else {
updateCamera(
InCallPresenter.getInstance().getInCallCameraManager().isUsingFrontFacingCamera());
call.getVideoTech().resumeTransmission(context);
}
inCallButtonUi.setVideoPaused(pause);
inCallButtonUi.enableButton(InCallButtonIds.BUTTON_PAUSE_VIDEO, false);
}
@Override
public void sendSipDtmfClicked(int buttonId) {
InCallPresenter.getInstance().sendSipDtmfClicked(buttonId);
}
private void updateCamera(boolean useFrontFacingCamera) {
InCallCameraManager cameraManager = InCallPresenter.getInstance().getInCallCameraManager();
cameraManager.setUseFrontFacingCamera(useFrontFacingCamera);
String cameraId = cameraManager.getActiveCameraId();
if (cameraId != null) {
final int cameraDir =
cameraManager.isUsingFrontFacingCamera()
? CameraDirection.CAMERA_DIRECTION_FRONT_FACING
: CameraDirection.CAMERA_DIRECTION_BACK_FACING;
call.setCameraDir(cameraDir);
call.getVideoTech().setCamera(cameraId);
InCallZoomController.getInstance().onCameraEnabled(cameraId);
}
}
private void updateUi(InCallState state, DialerCall call) {
LogUtil.v("CallButtonPresenter", "updating call UI for call: %s", call);
if (inCallButtonUi == null) {
return;
}
if (call != null) {
inCallButtonUi.updateInCallButtonUiColors(
InCallPresenter.getInstance().getThemeColorManager().getSecondaryColor());
}
final boolean isEnabled =
state.isConnectingOrConnected() && !state.isIncoming() && call != null;
inCallButtonUi.setEnabled(isEnabled);
if (call == null) {
return;
}
updateButtonsState(call);
}
/**
* Updates the buttons applicable for the UI.
*
* @param call The active call.
*/
@SuppressWarnings(value = {"MissingPermission"})
private void updateButtonsState(DialerCall call) {
LogUtil.v("CallButtonPresenter.updateButtonsState", "");
final boolean isVideo = call.isVideoCall();
// Common functionality (audio, hold, etc).
// Show either HOLD or SWAP, but not both. If neither HOLD or SWAP is available:
// (1) If the device normally can hold, show HOLD in a disabled state.
// (2) If the device doesn't have the concept of hold/swap, remove the button.
final boolean showSwap = call.can(android.telecom.Call.Details.CAPABILITY_SWAP_CONFERENCE);
final boolean showHold =
!showSwap
&& !call.hasSentVideoUpgradeRequest()
&& call.can(android.telecom.Call.Details.CAPABILITY_SUPPORT_HOLD)
&& call.can(android.telecom.Call.Details.CAPABILITY_HOLD);
final boolean isCallOnHold = call.getState() == DialerCallState.ONHOLD;
final boolean showAddCall =
TelecomAdapter.getInstance().canAddCall() && UserManagerCompat.isUserUnlocked(context)
&& !call.hasSentVideoUpgradeRequest();
// There can only be two calls so don't show the ability to merge when one of them
// is a speak easy call.
final boolean showMerge =
InCallPresenter.getInstance()
.getCallList()
.getAllCalls()
.stream()
.noneMatch(c -> c != null && c.isSpeakEasyCall())
&& call.can(android.telecom.Call.Details.CAPABILITY_MERGE_CONFERENCE)
&& !call.hasSentVideoUpgradeRequest();
final boolean useExt = QtiCallUtils.useExt(context);
final boolean showUpgradeToVideo = !isVideo && (hasVideoCallCapabilities(call)) && !useExt;
final boolean showDowngradeToAudio = isVideo && isDowngradeToAudioSupported(call) && !useExt;
final boolean showMute = call.can(android.telecom.Call.Details.CAPABILITY_MUTE);
final boolean hasCameraPermission =
isVideo && VideoUtils.hasCameraPermissionAndShownPrivacyToast(context);
// Disabling local video doesn't seem to work when dialing. See a bug.
final boolean showPauseVideo =
isVideo
&& call.getState() != DialerCallState.DIALING
&& call.getState() != DialerCallState.CONNECTING;
otherAccount = TelecomUtil.getOtherAccount(getContext(), call.getAccountHandle());
boolean showSwapSim =
!call.isEmergencyCall()
&& otherAccount != null
&& !call.isVoiceMailNumber()
&& DialerCallState.isDialing(call.getState())
// Most devices cannot make calls on 2 SIMs at the same time.
&& InCallPresenter.getInstance().getCallList().getAllCalls().size() == 1
&& !call.isConferenceCall();
boolean showUpgradeToRtt = call.canUpgradeToRttCall();
boolean enableUpgradeToRtt = showUpgradeToRtt && call.getState() == DialerCallState.ACTIVE;
inCallButtonUi.showButton(InCallButtonIds.BUTTON_AUDIO, true);
inCallButtonUi.showButton(InCallButtonIds.BUTTON_SWAP, showSwap);
inCallButtonUi.showButton(InCallButtonIds.BUTTON_HOLD, showHold);
inCallButtonUi.setHold(isCallOnHold);
inCallButtonUi.showButton(InCallButtonIds.BUTTON_MUTE, showMute);
inCallButtonUi.showButton(InCallButtonIds.BUTTON_SWAP_SIM, showSwapSim);
inCallButtonUi.showButton(InCallButtonIds.BUTTON_ADD_CALL, showAddCall);
inCallButtonUi.enableButton(InCallButtonIds.BUTTON_ADD_CALL, showAddCall);
inCallButtonUi.showButton(InCallButtonIds.BUTTON_UPGRADE_TO_VIDEO, showUpgradeToVideo);
inCallButtonUi.showButton(InCallButtonIds.BUTTON_UPGRADE_TO_RTT, showUpgradeToRtt);
inCallButtonUi.enableButton(InCallButtonIds.BUTTON_UPGRADE_TO_RTT, enableUpgradeToRtt);
inCallButtonUi.showButton(InCallButtonIds.BUTTON_DOWNGRADE_TO_AUDIO, showDowngradeToAudio);
inCallButtonUi.showButton(
InCallButtonIds.BUTTON_SWITCH_CAMERA,
isVideo && hasCameraPermission && call.getVideoTech().isTransmitting()
&& !BottomSheetHelper.getInstance().isInHideMeMode(call)
&& !ScreenShareHelper.screenShareRequested());
inCallButtonUi.showButton(InCallButtonIds.BUTTON_PAUSE_VIDEO, showPauseVideo);
if (isVideo) {
inCallButtonUi.setVideoPaused(!call.getVideoTech().isTransmitting() || !hasCameraPermission);
}
inCallButtonUi.showButton(InCallButtonIds.BUTTON_DIALPAD, true);
inCallButtonUi.showButton(InCallButtonIds.BUTTON_MERGE, showMerge);
updateSipDtmfButtons(InCallPresenter.getInstance().getSipDtmfBitMask());
inCallButtonUi.updateButtonStates();
if (BottomSheetHelper.getInstance().shallShowMoreButton(getActivity())) {
BottomSheetHelper.getInstance().updateMap();
}
}
private boolean hasVideoCallCapabilities(DialerCall call) {
return call.getVideoTech().isAvailable(context, call.getAccountHandle());
}
/**
* Determines if downgrading from a video call to an audio-only call is supported. In order to
* support downgrade to audio, the SDK version must be >= N and the call should NOT have the
* {@link android.telecom.Call.Details#CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO}.
*
* @param call The call.
* @return {@code true} if downgrading to an audio-only call from a video call is supported.
*/
private boolean isDowngradeToAudioSupported(DialerCall call) {
// TODO(a bug): If there is an RCS video share session, return true here
return !call.can(CallCompat.Details.CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO);
}
/**
* Handles a change to the video call hide me selection
*/
@Override
public void onHideMeUiModeChanged() {
if (call == null) {
return;
}
updateButtonsState(call);
}
@Override
public void onFullscreenModeChanged(boolean isFullscreenMode) {
}
@Override
public void onOutgoingVideoSourceChanged(int videoSource) {
if (inCallButtonUi != null && call != null) {
updateButtonsState(call);
}
}
@Override
public void onSessionModificationStateChange(DialerCall call) {
if (inCallButtonUi != null && call != null && call.equals(this.call)) {
int sessionModifyState = call.getVideoTech().getSessionModificationState();
if (sessionModifyState == SessionModificationState.WAITING_FOR_UPGRADE_TO_VIDEO_RESPONSE ||
sessionModifyState == SessionModificationState.NO_REQUEST) {
updateButtonsState(call);
}
}
}
@Override
public void onSipDtmfChanged(int sipDtmfbitMap) {
if (inCallButtonUi != null && call != null) {
updateSipDtmfButtons(sipDtmfbitMap);
}
}
private void updateSipDtmfButtons(int sipDtmfbitMap) {
boolean enable = (sipDtmfbitMap & SipDtmfUtil.SIP_DTMF_TYPE_LIKE)
== SipDtmfUtil.SIP_DTMF_TYPE_LIKE;
inCallButtonUi.showButton(InCallButtonIds.BUTTON_LIKE, enable);
enable = (sipDtmfbitMap & SipDtmfUtil.SIP_DTMF_TYPE_SHARE)
== SipDtmfUtil.SIP_DTMF_TYPE_SHARE;
inCallButtonUi.showButton(InCallButtonIds.BUTTON_SHARE, enable);
enable = (sipDtmfbitMap & SipDtmfUtil.SIP_DTMF_TYPE_FAVORITE)
== SipDtmfUtil.SIP_DTMF_TYPE_FAVORITE;
inCallButtonUi.showButton(InCallButtonIds.BUTTON_FAVORITE, enable);
enable = (sipDtmfbitMap & SipDtmfUtil.SIP_DTMF_TYPE_COPY)
== SipDtmfUtil.SIP_DTMF_TYPE_COPY;
inCallButtonUi.showButton(InCallButtonIds.BUTTON_COPY, enable);
enable = (sipDtmfbitMap & SipDtmfUtil.SIP_DTMF_TYPE_COMMENT)
== SipDtmfUtil.SIP_DTMF_TYPE_COMMENT;
inCallButtonUi.showButton(InCallButtonIds.BUTTON_COMMENT, enable);
enable = (sipDtmfbitMap & SipDtmfUtil.SIP_DTMF_TYPE_DETAIL)
== SipDtmfUtil.SIP_DTMF_TYPE_DETAIL;
inCallButtonUi.showButton(InCallButtonIds.BUTTON_DETAIL, enable);
enable = (sipDtmfbitMap & SipDtmfUtil.SIP_DTMF_TYPE_RED_ENVELOPE)
== SipDtmfUtil.SIP_DTMF_TYPE_RED_ENVELOPE;
inCallButtonUi.showButton(InCallButtonIds.BUTTON_RED_ENVELOPE, enable);
}
@Override
public void onSaveInstanceState(Bundle outState) {}
@Override
public void onRestoreInstanceState(Bundle savedInstanceState) {}
@Override
public void onCameraPermissionGranted() {
if (call != null) {
updateButtonsState(call);
}
}
@Override
public void onActiveCameraSelectionChanged(boolean isUsingFrontFacingCamera) {
if (inCallButtonUi == null) {
return;
}
inCallButtonUi.setCameraSwitched(!isUsingFrontFacingCamera);
}
@Override
public void onDialerCallSessionModificationStateChange() {
if (inCallButtonUi != null && call != null) {
inCallButtonUi.enableButton(InCallButtonIds.BUTTON_PAUSE_VIDEO, true);
updateButtonsState(call);
}
}
@Override
public void onDialerCallDisconnect() {}
@Override
public void onDialerCallUpdate() {}
@Override
public void onDialerCallChildNumberChange() {}
@Override
public void onDialerCallLastForwardedNumberChange() {}
@Override
public void onDialerCallUpgradeToVideo() {}
@Override
public void onWiFiToLteHandover() {}
@Override
public void onHandoverToWifiFailure() {}
@Override
public void onInternationalCallOnWifi() {}
@Override
public void onEnrichedCallSessionUpdate() {}
@Override
public void onSuplServiceMessage(String suplNotificationMessage) {}
@Override
public Context getContext() {
return context;
}
private InCallActivity getActivity() {
if (inCallButtonUi != null) {
Fragment fragment = inCallButtonUi.getInCallButtonUiFragment();
if (fragment != null) {
return (InCallActivity) fragment.getActivity();
}
}
return null;
}
/**package*/ void phoneAccountChanged(PhoneAccountHandle accountHandle) {
if (call != null
&& (accountHandle == null || !accountHandle.equals(call.getAccountHandle()))) {
updateButtonsState(call);
}
}
private final static class PhoneAccountChangedReceiver extends BroadcastReceiver {
private final CallButtonPresenter callButtonPresenter;
private boolean isRegistered = false;
public PhoneAccountChangedReceiver(CallButtonPresenter callButtonPresenter) {
this.callButtonPresenter = callButtonPresenter;
}
@Override
public void onReceive(Context context, Intent intent) {
LogUtil.i(
"CallButtonPresenter.PhoneAccountChangedReceiver",
"onReceive: " + intent.getAction());
if (TelecomManager.ACTION_PHONE_ACCOUNT_REGISTERED.equals(intent.getAction())
|| TelecomManager.ACTION_PHONE_ACCOUNT_UNREGISTERED.equals(intent.getAction())) {
callButtonPresenter.phoneAccountChanged(intent
.getParcelableExtra(TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE));
}
}
public void register() {
if (!isRegistered) {
IntentFilter filter = new IntentFilter(TelecomManager.ACTION_PHONE_ACCOUNT_REGISTERED);
filter.addAction(TelecomManager.ACTION_PHONE_ACCOUNT_UNREGISTERED);
callButtonPresenter.getContext().registerReceiver(this, filter);
isRegistered = true;
}
}
public void unregister() {
if (isRegistered) {
callButtonPresenter.getContext().unregisterReceiver(this);
isRegistered = false;
}
}
}
}