From b73b8ba04f32faeeb8c11e28ab4fc19b81daf653 Mon Sep 17 00:00:00 2001 From: Andrew Lee Date: Wed, 15 Apr 2015 14:13:32 -0700 Subject: Rename CallListener to CallCallback. To match API changes. Bug: 20160491 Change-Id: I664cb0c3db7e0affc42179d467828246887069e8 --- InCallUI/src/com/android/incallui/Call.java | 32 +- .../src/com/android/incallui/InCallPresenter.java | 29 +- .../android/incallui/InCallVideoCallCallback.java | 156 ++++++++++ .../incallui/InCallVideoCallCallbackNotifier.java | 342 +++++++++++++++++++++ .../android/incallui/InCallVideoCallListener.java | 156 ---------- .../incallui/InCallVideoCallListenerNotifier.java | 341 -------------------- .../com/android/incallui/VideoCallPresenter.java | 18 +- .../com/android/incallui/VideoPauseController.java | 6 +- 8 files changed, 553 insertions(+), 527 deletions(-) create mode 100644 InCallUI/src/com/android/incallui/InCallVideoCallCallback.java create mode 100644 InCallUI/src/com/android/incallui/InCallVideoCallCallbackNotifier.java delete mode 100644 InCallUI/src/com/android/incallui/InCallVideoCallListener.java delete mode 100644 InCallUI/src/com/android/incallui/InCallVideoCallListenerNotifier.java diff --git a/InCallUI/src/com/android/incallui/Call.java b/InCallUI/src/com/android/incallui/Call.java index 4ed7a49cf..d637c8a60 100644 --- a/InCallUI/src/com/android/incallui/Call.java +++ b/InCallUI/src/com/android/incallui/Call.java @@ -172,11 +172,11 @@ public class Call { private static final String ID_PREFIX = Call.class.getSimpleName() + "_"; private static int sIdCounter = 0; - private android.telecom.Call.Listener mTelecommCallListener = - new android.telecom.Call.Listener() { + private android.telecom.Call.Callback mTelecomCallCallback = + new android.telecom.Call.Callback() { @Override public void onStateChanged(android.telecom.Call call, int newState) { - Log.d(this, "TelecommCallListener onStateChanged call=" + call + " newState=" + Log.d(this, "TelecommCallCallback onStateChanged call=" + call + " newState=" + newState); update(); } @@ -184,7 +184,7 @@ public class Call { @Override public void onParentChanged(android.telecom.Call call, android.telecom.Call newParent) { - Log.d(this, "TelecommCallListener onParentChanged call=" + call + " newParent=" + Log.d(this, "TelecommCallCallback onParentChanged call=" + call + " newParent=" + newParent); update(); } @@ -198,7 +198,7 @@ public class Call { @Override public void onDetailsChanged(android.telecom.Call call, android.telecom.Call.Details details) { - Log.d(this, "TelecommCallListener onStateChanged call=" + call + " details=" + Log.d(this, "TelecommCallCallback onStateChanged call=" + call + " details=" + details); update(); } @@ -206,7 +206,7 @@ public class Call { @Override public void onCannedTextResponsesLoaded(android.telecom.Call call, List cannedTextResponses) { - Log.d(this, "TelecommCallListener onStateChanged call=" + call + Log.d(this, "TelecommCallCallback onStateChanged call=" + call + " cannedTextResponses=" + cannedTextResponses); update(); } @@ -214,7 +214,7 @@ public class Call { @Override public void onPostDialWait(android.telecom.Call call, String remainingPostDialSequence) { - Log.d(this, "TelecommCallListener onStateChanged call=" + call + Log.d(this, "TelecommCallCallback onStateChanged call=" + call + " remainingPostDialSequence=" + remainingPostDialSequence); update(); } @@ -222,15 +222,15 @@ public class Call { @Override public void onVideoCallChanged(android.telecom.Call call, VideoCall videoCall) { - Log.d(this, "TelecommCallListener onStateChanged call=" + call + " videoCall=" + Log.d(this, "TelecommCallCallback onStateChanged call=" + call + " videoCall=" + videoCall); update(); } @Override public void onCallDestroyed(android.telecom.Call call) { - Log.d(this, "TelecommCallListener onStateChanged call=" + call); - call.removeListener(mTelecommCallListener); + Log.d(this, "TelecommCallCallback onStateChanged call=" + call); + call.unregisterCallback(mTelecomCallCallback); } @Override @@ -252,7 +252,7 @@ public class Call { */ private int mModifyToVideoState = VideoProfile.VideoState.AUDIO_ONLY; - private InCallVideoCallListener mVideoCallListener; + private InCallVideoCallCallback mVideoCallCallback; /** * Used only to create mock calls for testing @@ -268,7 +268,7 @@ public class Call { mTelecommCall = telecommCall; mId = ID_PREFIX + Integer.toString(sIdCounter++); updateFromTelecommCall(); - mTelecommCall.addListener(mTelecommCallListener); + mTelecommCall.registerCallback(mTelecomCallCallback); } public android.telecom.Call getTelecommCall() { @@ -301,10 +301,10 @@ public class Call { setDisconnectCause(mTelecommCall.getDetails().getDisconnectCause()); if (mTelecommCall.getVideoCall() != null) { - if (mVideoCallListener == null) { - mVideoCallListener = new InCallVideoCallListener(this); + if (mVideoCallCallback == null) { + mVideoCallCallback = new InCallVideoCallCallback(this); } - mTelecommCall.getVideoCall().setVideoCallListener(mVideoCallListener); + mTelecommCall.getVideoCall().registerCallback(mVideoCallCallback); } mChildCallIds.clear(); @@ -562,7 +562,7 @@ public class Call { getParentId(), this.mTelecommCall.getConferenceableCalls(), mTelecommCall.getDetails().getVideoState(), - mTelecommCall.getDetails().getCallSubstate(), + mTelecommCall.getDetails().getCallSubstate(), mSessionModificationState, getVideoSettings()); } diff --git a/InCallUI/src/com/android/incallui/InCallPresenter.java b/InCallUI/src/com/android/incallui/InCallPresenter.java index 9c0fca305..0880607fc 100644 --- a/InCallUI/src/com/android/incallui/InCallPresenter.java +++ b/InCallUI/src/com/android/incallui/InCallPresenter.java @@ -110,8 +110,33 @@ public class InCallPresenter implements CallList.Listener, */ private PhoneAccountHandle mPendingPhoneAccountHandle; - private final android.telecom.Call.Listener mCallListener = - new android.telecom.Call.Listener() { + private final Phone.Listener mPhoneListener = new Phone.Listener() { + @Override + public void onBringToForeground(Phone phone, boolean showDialpad) { + Log.i(this, "Bringing UI to foreground."); + bringToForeground(showDialpad); + } + @Override + public void onCallAdded(Phone phone, android.telecom.Call call) { + // Since a call has been added we are no longer waiting for Telecom to send us a + // call. + setBoundAndWaitingForOutgoingCall(false, null); + call.registerCallback(mCallCallback); + } + @Override + public void onCallRemoved(Phone phone, android.telecom.Call call) { + call.unregisterCallback(mCallCallback); + } + @Override + public void onCanAddCallChanged(Phone phone, boolean canAddCall) { + for (CanAddCallListener listener : mCanAddCallListeners) { + listener.onCanAddCallChanged(canAddCall); + } + } + }; + + private final android.telecom.Call.Callback mCallCallback = + new android.telecom.Call.Callback() { @Override public void onPostDialWait(android.telecom.Call call, String remainingPostDialSequence) { onPostDialCharWait(mCallList.getCallByTelecommCall(call).getId(), diff --git a/InCallUI/src/com/android/incallui/InCallVideoCallCallback.java b/InCallUI/src/com/android/incallui/InCallVideoCallCallback.java new file mode 100644 index 000000000..f868b3baf --- /dev/null +++ b/InCallUI/src/com/android/incallui/InCallVideoCallCallback.java @@ -0,0 +1,156 @@ +/* + * Copyright (C) 2014 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.telecom.CameraCapabilities; +import android.telecom.Connection; +import android.telecom.Connection.VideoProvider; +import android.telecom.InCallService.VideoCall; +import android.telecom.VideoProfile; + +/** + * Implements the InCallUI VideoCall Callback. + */ +public class InCallVideoCallCallback extends VideoCall.Callback { + + /** + * The call associated with this {@link InCallVideoClient}. + */ + private Call mCall; + + /** + * Creates an instance of the call video client, specifying the call it is related to. + * + * @param call The call. + */ + public InCallVideoCallCallback(Call call) { + mCall = call; + } + + /** + * Handles an incoming session modification request. + * + * @param videoProfile The requested video call profile. + */ + @Override + public void onSessionModifyRequestReceived(VideoProfile videoProfile) { + Log.d(this, " onSessionModifyRequestReceived videoProfile=" + videoProfile); + int previousVideoState = CallUtils.getUnPausedVideoState(mCall.getVideoState()); + int newVideoState = CallUtils.getUnPausedVideoState(videoProfile.getVideoState()); + + boolean wasVideoCall = VideoProfile.VideoState.isVideo(previousVideoState); + boolean isVideoCall = VideoProfile.VideoState.isVideo(newVideoState); + + // Check for upgrades to video and downgrades to audio. + if (wasVideoCall && !isVideoCall) { + InCallVideoCallCallbackNotifier.getInstance().downgradeToAudio(mCall); + } else if (previousVideoState != newVideoState) { + InCallVideoCallCallbackNotifier.getInstance().upgradeToVideoRequest(mCall, + newVideoState); + } + } + + /** + * Handles a session modification response. + * + * @param status Status of the session modify request. Valid values are + * {@link Connection.VideoProvider#SESSION_MODIFY_REQUEST_SUCCESS}, + * {@link Connection.VideoProvider#SESSION_MODIFY_REQUEST_FAIL}, + * {@link Connection.VideoProvider#SESSION_MODIFY_REQUEST_INVALID} + * @param requestedProfile + * @param responseProfile The actual profile changes made by the peer device. + */ + @Override + public void onSessionModifyResponseReceived(int status, VideoProfile requestedProfile, + VideoProfile responseProfile) { + Log.d(this, "onSessionModifyResponseReceived status=" + status + " requestedProfile=" + + requestedProfile + " responseProfile=" + responseProfile); + if (status != VideoProvider.SESSION_MODIFY_REQUEST_SUCCESS) { + InCallVideoCallCallbackNotifier.getInstance().upgradeToVideoFail(status, mCall); + } else if (requestedProfile != null && responseProfile != null) { + boolean modifySucceeded = requestedProfile.getVideoState() == + responseProfile.getVideoState(); + boolean isVideoCall = VideoProfile.VideoState.isVideo(responseProfile.getVideoState()); + if (modifySucceeded && isVideoCall) { + InCallVideoCallCallbackNotifier.getInstance().upgradeToVideoSuccess(mCall); + } else if (!modifySucceeded && isVideoCall) { + InCallVideoCallCallbackNotifier.getInstance().upgradeToVideoFail(status, mCall); + } else if (modifySucceeded && !isVideoCall) { + InCallVideoCallCallbackNotifier.getInstance().downgradeToAudio(mCall); + } + } else { + Log.d(this, "onSessionModifyResponseReceived request and response Profiles are null"); + } + } + + /** + * Handles a call session event. + * + * @param event The event. + */ + @Override + public void onCallSessionEvent(int event) { + InCallVideoCallCallbackNotifier.getInstance().callSessionEvent(event); + } + + /** + * Handles a change to the peer video dimensions. + * + * @param width The updated peer video width. + * @param height The updated peer video height. + */ + @Override + public void onPeerDimensionsChanged(int width, int height) { + InCallVideoCallCallbackNotifier.getInstance().peerDimensionsChanged(mCall, width, height); + } + + /** + * Handles a change to the video quality of the call. + * + * @param videoQuality The updated video call quality. + */ + @Override + public void onVideoQualityChanged(int videoQuality) { + InCallVideoCallCallbackNotifier.getInstance().videoQualityChanged(mCall, videoQuality); + } + + /** + * Handles a change to the call data usage. No implementation as the in-call UI does not + * display data usage. + * + * @param dataUsage The updated data usage. + */ + @Override + public void onCallDataUsageChanged(long dataUsage) { + Log.d(this, "onCallDataUsageChanged: dataUsage = " + dataUsage); + InCallVideoCallCallbackNotifier.getInstance().callDataUsageChanged(dataUsage); + } + + /** + * Handles changes to the camera capabilities. No implementation as the in-call UI does not + * make use of camera capabilities. + * + * @param cameraCapabilities The changed camera capabilities. + */ + @Override + public void onCameraCapabilitiesChanged(CameraCapabilities cameraCapabilities) { + if (cameraCapabilities != null) { + InCallVideoCallCallbackNotifier.getInstance().cameraDimensionsChanged( + mCall, cameraCapabilities.getWidth(), cameraCapabilities.getHeight()); + } + } +} diff --git a/InCallUI/src/com/android/incallui/InCallVideoCallCallbackNotifier.java b/InCallUI/src/com/android/incallui/InCallVideoCallCallbackNotifier.java new file mode 100644 index 000000000..dfb645bfc --- /dev/null +++ b/InCallUI/src/com/android/incallui/InCallVideoCallCallbackNotifier.java @@ -0,0 +1,342 @@ +/* + * Copyright (C) 2014 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 com.google.common.base.Preconditions; + +import java.util.Collections; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; + +/** + * Class used by {@link InCallService.VideoCallCallback} to notify interested parties of incoming + * events. + */ +public class InCallVideoCallCallbackNotifier { + /** + * Singleton instance of this class. + */ + private static InCallVideoCallCallbackNotifier sInstance = + new InCallVideoCallCallbackNotifier(); + + /** + * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is + * load factor before resizing, 1 means we only expect a single thread to + * access the map so make only a single shard + */ + private final Set mSessionModificationListeners = + Collections.newSetFromMap(new ConcurrentHashMap + (8, 0.9f, 1)); + private final Set mVideoEventListeners = Collections.newSetFromMap( + new ConcurrentHashMap(8, 0.9f, 1)); + private final Set mSurfaceChangeListeners = Collections.newSetFromMap( + new ConcurrentHashMap(8, 0.9f, 1)); + + /** + * Static singleton accessor method. + */ + public static InCallVideoCallCallbackNotifier getInstance() { + return sInstance; + } + + /** + * Private constructor. Instance should only be acquired through getInstance(). + */ + private InCallVideoCallCallbackNotifier() { + } + + /** + * Adds a new {@link SessionModificationListener}. + * + * @param listener The listener. + */ + public void addSessionModificationListener(SessionModificationListener listener) { + Preconditions.checkNotNull(listener); + mSessionModificationListeners.add(listener); + } + + /** + * Remove a {@link SessionModificationListener}. + * + * @param listener The listener. + */ + public void removeSessionModificationListener(SessionModificationListener listener) { + if (listener != null) { + mSessionModificationListeners.remove(listener); + } + } + + /** + * Adds a new {@link VideoEventListener}. + * + * @param listener The listener. + */ + public void addVideoEventListener(VideoEventListener listener) { + Preconditions.checkNotNull(listener); + mVideoEventListeners.add(listener); + } + + /** + * Remove a {@link VideoEventListener}. + * + * @param listener The listener. + */ + public void removeVideoEventListener(VideoEventListener listener) { + if (listener != null) { + mVideoEventListeners.remove(listener); + } + } + + /** + * Adds a new {@link SurfaceChangeListener}. + * + * @param listener The listener. + */ + public void addSurfaceChangeListener(SurfaceChangeListener listener) { + Preconditions.checkNotNull(listener); + mSurfaceChangeListeners.add(listener); + } + + /** + * Remove a {@link SurfaceChangeListener}. + * + * @param listener The listener. + */ + public void removeSurfaceChangeListener(SurfaceChangeListener listener) { + if (listener != null) { + mSurfaceChangeListeners.remove(listener); + } + } + + /** + * Inform listeners of an upgrade to video request for a call. + * @param call The call. + * @param videoState The video state we want to upgrade to. + */ + public void upgradeToVideoRequest(Call call, int videoState) { + Log.d(this, "upgradeToVideoRequest call = " + call + " new video state = " + videoState); + for (SessionModificationListener listener : mSessionModificationListeners) { + listener.onUpgradeToVideoRequest(call, videoState); + } + } + + /** + * Inform listeners of a successful response to a video request for a call. + * + * @param call The call. + */ + public void upgradeToVideoSuccess(Call call) { + for (SessionModificationListener listener : mSessionModificationListeners) { + listener.onUpgradeToVideoSuccess(call); + } + } + + /** + * Inform listeners of an unsuccessful response to a video request for a call. + * + * @param call The call. + */ + public void upgradeToVideoFail(int status, Call call) { + for (SessionModificationListener listener : mSessionModificationListeners) { + listener.onUpgradeToVideoFail(status, call); + } + } + + /** + * Inform listeners of a downgrade to audio. + * + * @param call The call. + */ + public void downgradeToAudio(Call call) { + for (SessionModificationListener listener : mSessionModificationListeners) { + listener.onDowngradeToAudio(call); + } + } + + /** + * Inform listeners of a call session event. + * + * @param event The call session event. + */ + public void callSessionEvent(int event) { + for (VideoEventListener listener : mVideoEventListeners) { + listener.onCallSessionEvent(event); + } + } + + /** + * Inform listeners of a downgrade to audio. + * + * @param call The call. + * @param paused The paused state. + */ + public void peerPausedStateChanged(Call call, boolean paused) { + for (VideoEventListener listener : mVideoEventListeners) { + listener.onPeerPauseStateChanged(call, paused); + } + } + + /** + * Inform listeners of any change in the video quality of the call + * + * @param call The call. + * @param videoQuality The updated video quality of the call. + */ + public void videoQualityChanged(Call call, int videoQuality) { + for (VideoEventListener listener : mVideoEventListeners) { + listener.onVideoQualityChanged(call, videoQuality); + } + } + + /** + * Inform listeners of a change to peer dimensions. + * + * @param call The call. + * @param width New peer width. + * @param height New peer height. + */ + public void peerDimensionsChanged(Call call, int width, int height) { + for (SurfaceChangeListener listener : mSurfaceChangeListeners) { + listener.onUpdatePeerDimensions(call, width, height); + } + } + + /** + * Inform listeners of a change to camera dimensions. + * + * @param call The call. + * @param width The new camera video width. + * @param height The new camera video height. + */ + public void cameraDimensionsChanged(Call call, int width, int height) { + for (SurfaceChangeListener listener : mSurfaceChangeListeners) { + listener.onCameraDimensionsChange(call, width, height); + } + } + + /** + * Inform listeners of a change to call data usage. + * + * @param dataUsage data usage value + */ + public void callDataUsageChanged(long dataUsage) { + for (VideoEventListener listener : mVideoEventListeners) { + listener.onCallDataUsageChange(dataUsage); + } + } + + /** + * Listener interface for any class that wants to be notified of upgrade to video and downgrade + * to audio session modification requests. + */ + public interface SessionModificationListener { + /** + * Called when a peer request is received to upgrade an audio-only call to a video call. + * + * @param call The call the request was received for. + * @param videoState The video state that the request wants to upgrade to. + */ + public void onUpgradeToVideoRequest(Call call, int videoState); + + /** + * Called when a request to a peer to upgrade an audio-only call to a video call is + * successful. + * + * @param call The call the request was successful for. + */ + public void onUpgradeToVideoSuccess(Call call); + + /** + * Called when a request to a peer to upgrade an audio-only call to a video call is + * NOT successful. This can be if the peer chooses rejects the the video call, or if the + * peer does not support video calling, or if there is some error in sending the request. + * + * @param call The call the request was successful for. + */ + public void onUpgradeToVideoFail(int status, Call call); + + /** + * Called when a call has been downgraded to audio-only. + * + * @param call The call which was downgraded to audio-only. + */ + public void onDowngradeToAudio(Call call); + } + + /** + * Listener interface for any class that wants to be notified of video events, including pause + * and un-pause of peer video, video quality changes. + */ + public interface VideoEventListener { + /** + * Called when the peer pauses or un-pauses video transmission. + * + * @param call The call which paused or un-paused video transmission. + * @param paused {@code True} when the video transmission is paused, {@code false} + * otherwise. + */ + public void onPeerPauseStateChanged(Call call, boolean paused); + + /** + * Called when the video quality changes. + * + * @param call The call whose video quality changes. + * @param videoCallQuality - values are QUALITY_HIGH, MEDIUM, LOW and UNKNOWN. + */ + public void onVideoQualityChanged(Call call, int videoCallQuality); + + /* + * Called when call data usage value is requested or when call data usage value is updated + * because of a call state change + * + * @param dataUsage call data usage value + */ + public void onCallDataUsageChange(long dataUsage); + + /** + * Called when call session event is raised. + * + * @param event The call session event. + */ + public void onCallSessionEvent(int event); + } + + /** + * Listener interface for any class that wants to be notified of changes to the video surfaces. + */ + public interface SurfaceChangeListener { + /** + * Called when the peer video feed changes dimensions. This can occur when the peer rotates + * their device, changing the aspect ratio of the video signal. + * + * @param call The call which experienced a peer video + * @param width + * @param height + */ + public void onUpdatePeerDimensions(Call call, int width, int height); + + /** + * Called when the local camera changes dimensions. This occurs when a change in camera + * occurs. + * + * @param call The call which experienced the camera dimension change. + * @param width The new camera video width. + * @param height The new camera video height. + */ + public void onCameraDimensionsChange(Call call, int width, int height); + } +} diff --git a/InCallUI/src/com/android/incallui/InCallVideoCallListener.java b/InCallUI/src/com/android/incallui/InCallVideoCallListener.java deleted file mode 100644 index 741b8d614..000000000 --- a/InCallUI/src/com/android/incallui/InCallVideoCallListener.java +++ /dev/null @@ -1,156 +0,0 @@ -/* - * Copyright (C) 2014 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.telecom.CameraCapabilities; -import android.telecom.Connection; -import android.telecom.Connection.VideoProvider; -import android.telecom.InCallService.VideoCall; -import android.telecom.VideoProfile; - -/** - * Implements the InCallUI Video Call Listener. - */ -public class InCallVideoCallListener extends VideoCall.Listener { - - /** - * The call associated with this {@link InCallVideoClient}. - */ - private Call mCall; - - /** - * Creates an instance of the call video client, specifying the call it is related to. - * - * @param call The call. - */ - public InCallVideoCallListener(Call call) { - mCall = call; - } - - /** - * Handles an incoming session modification request. - * - * @param videoProfile The requested video call profile. - */ - @Override - public void onSessionModifyRequestReceived(VideoProfile videoProfile) { - Log.d(this, " onSessionModifyRequestReceived videoProfile=" + videoProfile); - int previousVideoState = CallUtils.getUnPausedVideoState(mCall.getVideoState()); - int newVideoState = CallUtils.getUnPausedVideoState(videoProfile.getVideoState()); - - boolean wasVideoCall = VideoProfile.VideoState.isVideo(previousVideoState); - boolean isVideoCall = VideoProfile.VideoState.isVideo(newVideoState); - - // Check for upgrades to video and downgrades to audio. - if (wasVideoCall && !isVideoCall) { - InCallVideoCallListenerNotifier.getInstance().downgradeToAudio(mCall); - } else if (previousVideoState != newVideoState) { - InCallVideoCallListenerNotifier.getInstance().upgradeToVideoRequest(mCall, - newVideoState); - } - } - - /** - * Handles a session modification response. - * - * @param status Status of the session modify request. Valid values are - * {@link Connection.VideoProvider#SESSION_MODIFY_REQUEST_SUCCESS}, - * {@link Connection.VideoProvider#SESSION_MODIFY_REQUEST_FAIL}, - * {@link Connection.VideoProvider#SESSION_MODIFY_REQUEST_INVALID} - * @param requestedProfile - * @param responseProfile The actual profile changes made by the peer device. - */ - @Override - public void onSessionModifyResponseReceived(int status, VideoProfile requestedProfile, - VideoProfile responseProfile) { - Log.d(this, "onSessionModifyResponseReceived status=" + status + " requestedProfile=" - + requestedProfile + " responseProfile=" + responseProfile); - if (status != VideoProvider.SESSION_MODIFY_REQUEST_SUCCESS) { - InCallVideoCallListenerNotifier.getInstance().upgradeToVideoFail(status, mCall); - } else if (requestedProfile != null && responseProfile != null) { - boolean modifySucceeded = requestedProfile.getVideoState() == - responseProfile.getVideoState(); - boolean isVideoCall = VideoProfile.VideoState.isVideo(responseProfile.getVideoState()); - if (modifySucceeded && isVideoCall) { - InCallVideoCallListenerNotifier.getInstance().upgradeToVideoSuccess(mCall); - } else if (!modifySucceeded && isVideoCall) { - InCallVideoCallListenerNotifier.getInstance().upgradeToVideoFail(status, mCall); - } else if (modifySucceeded && !isVideoCall) { - InCallVideoCallListenerNotifier.getInstance().downgradeToAudio(mCall); - } - } else { - Log.d(this, "onSessionModifyResponseReceived request and response Profiles are null"); - } - } - - /** - * Handles a call session event. - * - * @param event The event. - */ - @Override - public void onCallSessionEvent(int event) { - InCallVideoCallListenerNotifier.getInstance().callSessionEvent(event); - } - - /** - * Handles a change to the peer video dimensions. - * - * @param width The updated peer video width. - * @param height The updated peer video height. - */ - @Override - public void onPeerDimensionsChanged(int width, int height) { - InCallVideoCallListenerNotifier.getInstance().peerDimensionsChanged(mCall, width, height); - } - - /** - * Handles a change to the video quality of the call. - * - * @param videoQuality The updated video call quality. - */ - @Override - public void onVideoQualityChanged(int videoQuality) { - InCallVideoCallListenerNotifier.getInstance().videoQualityChanged(mCall, videoQuality); - } - - /** - * Handles a change to the call data usage. No implementation as the in-call UI does not - * display data usage. - * - * @param dataUsage The updated data usage. - */ - @Override - public void onCallDataUsageChanged(long dataUsage) { - Log.d(this, "onCallDataUsageChanged: dataUsage = " + dataUsage); - InCallVideoCallListenerNotifier.getInstance().callDataUsageChanged(dataUsage); - } - - /** - * Handles changes to the camera capabilities. No implementation as the in-call UI does not - * make use of camera capabilities. - * - * @param cameraCapabilities The changed camera capabilities. - */ - @Override - public void onCameraCapabilitiesChanged(CameraCapabilities cameraCapabilities) { - if (cameraCapabilities != null) { - InCallVideoCallListenerNotifier.getInstance().cameraDimensionsChanged( - mCall, cameraCapabilities.getWidth(), cameraCapabilities.getHeight()); - } - } -} diff --git a/InCallUI/src/com/android/incallui/InCallVideoCallListenerNotifier.java b/InCallUI/src/com/android/incallui/InCallVideoCallListenerNotifier.java deleted file mode 100644 index 818ed032a..000000000 --- a/InCallUI/src/com/android/incallui/InCallVideoCallListenerNotifier.java +++ /dev/null @@ -1,341 +0,0 @@ -/* - * Copyright (C) 2014 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 com.google.common.base.Preconditions; - -import java.util.Collections; -import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; - -/** - * Class used by {@link InCallService.VideoCallListener} to notify interested parties of incoming - * events. - */ -public class InCallVideoCallListenerNotifier { - /** - * Singleton instance of this class. - */ - private static InCallVideoCallListenerNotifier sInstance = new InCallVideoCallListenerNotifier(); - - /** - * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is - * load factor before resizing, 1 means we only expect a single thread to - * access the map so make only a single shard - */ - private final Set mSessionModificationListeners = - Collections.newSetFromMap(new ConcurrentHashMap - (8, 0.9f, 1)); - private final Set mVideoEventListeners = Collections.newSetFromMap( - new ConcurrentHashMap(8, 0.9f, 1)); - private final Set mSurfaceChangeListeners = Collections.newSetFromMap( - new ConcurrentHashMap(8, 0.9f, 1)); - - /** - * Static singleton accessor method. - */ - public static InCallVideoCallListenerNotifier getInstance() { - return sInstance; - } - - /** - * Private constructor. Instance should only be acquired through getInstance(). - */ - private InCallVideoCallListenerNotifier() { - } - - /** - * Adds a new {@link SessionModificationListener}. - * - * @param listener The listener. - */ - public void addSessionModificationListener(SessionModificationListener listener) { - Preconditions.checkNotNull(listener); - mSessionModificationListeners.add(listener); - } - - /** - * Remove a {@link SessionModificationListener}. - * - * @param listener The listener. - */ - public void removeSessionModificationListener(SessionModificationListener listener) { - if (listener != null) { - mSessionModificationListeners.remove(listener); - } - } - - /** - * Adds a new {@link VideoEventListener}. - * - * @param listener The listener. - */ - public void addVideoEventListener(VideoEventListener listener) { - Preconditions.checkNotNull(listener); - mVideoEventListeners.add(listener); - } - - /** - * Remove a {@link VideoEventListener}. - * - * @param listener The listener. - */ - public void removeVideoEventListener(VideoEventListener listener) { - if (listener != null) { - mVideoEventListeners.remove(listener); - } - } - - /** - * Adds a new {@link SurfaceChangeListener}. - * - * @param listener The listener. - */ - public void addSurfaceChangeListener(SurfaceChangeListener listener) { - Preconditions.checkNotNull(listener); - mSurfaceChangeListeners.add(listener); - } - - /** - * Remove a {@link SurfaceChangeListener}. - * - * @param listener The listener. - */ - public void removeSurfaceChangeListener(SurfaceChangeListener listener) { - if (listener != null) { - mSurfaceChangeListeners.remove(listener); - } - } - - /** - * Inform listeners of an upgrade to video request for a call. - * @param call The call. - * @param videoState The video state we want to upgrade to. - */ - public void upgradeToVideoRequest(Call call, int videoState) { - Log.d(this, "upgradeToVideoRequest call = " + call + " new video state = " + videoState); - for (SessionModificationListener listener : mSessionModificationListeners) { - listener.onUpgradeToVideoRequest(call, videoState); - } - } - - /** - * Inform listeners of a successful response to a video request for a call. - * - * @param call The call. - */ - public void upgradeToVideoSuccess(Call call) { - for (SessionModificationListener listener : mSessionModificationListeners) { - listener.onUpgradeToVideoSuccess(call); - } - } - - /** - * Inform listeners of an unsuccessful response to a video request for a call. - * - * @param call The call. - */ - public void upgradeToVideoFail(int status, Call call) { - for (SessionModificationListener listener : mSessionModificationListeners) { - listener.onUpgradeToVideoFail(status, call); - } - } - - /** - * Inform listeners of a downgrade to audio. - * - * @param call The call. - */ - public void downgradeToAudio(Call call) { - for (SessionModificationListener listener : mSessionModificationListeners) { - listener.onDowngradeToAudio(call); - } - } - - /** - * Inform listeners of a call session event. - * - * @param event The call session event. - */ - public void callSessionEvent(int event) { - for (VideoEventListener listener : mVideoEventListeners) { - listener.onCallSessionEvent(event); - } - } - - /** - * Inform listeners of a downgrade to audio. - * - * @param call The call. - * @param paused The paused state. - */ - public void peerPausedStateChanged(Call call, boolean paused) { - for (VideoEventListener listener : mVideoEventListeners) { - listener.onPeerPauseStateChanged(call, paused); - } - } - - /** - * Inform listeners of any change in the video quality of the call - * - * @param call The call. - * @param videoQuality The updated video quality of the call. - */ - public void videoQualityChanged(Call call, int videoQuality) { - for (VideoEventListener listener : mVideoEventListeners) { - listener.onVideoQualityChanged(call, videoQuality); - } - } - - /** - * Inform listeners of a change to peer dimensions. - * - * @param call The call. - * @param width New peer width. - * @param height New peer height. - */ - public void peerDimensionsChanged(Call call, int width, int height) { - for (SurfaceChangeListener listener : mSurfaceChangeListeners) { - listener.onUpdatePeerDimensions(call, width, height); - } - } - - /** - * Inform listeners of a change to camera dimensions. - * - * @param call The call. - * @param width The new camera video width. - * @param height The new camera video height. - */ - public void cameraDimensionsChanged(Call call, int width, int height) { - for (SurfaceChangeListener listener : mSurfaceChangeListeners) { - listener.onCameraDimensionsChange(call, width, height); - } - } - - /** - * Inform listeners of a change to call data usage. - * - * @param dataUsage data usage value - */ - public void callDataUsageChanged(long dataUsage) { - for (VideoEventListener listener : mVideoEventListeners) { - listener.onCallDataUsageChange(dataUsage); - } - } - - /** - * Listener interface for any class that wants to be notified of upgrade to video and downgrade - * to audio session modification requests. - */ - public interface SessionModificationListener { - /** - * Called when a peer request is received to upgrade an audio-only call to a video call. - * - * @param call The call the request was received for. - * @param videoState The video state that the request wants to upgrade to. - */ - public void onUpgradeToVideoRequest(Call call, int videoState); - - /** - * Called when a request to a peer to upgrade an audio-only call to a video call is - * successful. - * - * @param call The call the request was successful for. - */ - public void onUpgradeToVideoSuccess(Call call); - - /** - * Called when a request to a peer to upgrade an audio-only call to a video call is - * NOT successful. This can be if the peer chooses rejects the the video call, or if the - * peer does not support video calling, or if there is some error in sending the request. - * - * @param call The call the request was successful for. - */ - public void onUpgradeToVideoFail(int status, Call call); - - /** - * Called when a call has been downgraded to audio-only. - * - * @param call The call which was downgraded to audio-only. - */ - public void onDowngradeToAudio(Call call); - } - - /** - * Listener interface for any class that wants to be notified of video events, including pause - * and un-pause of peer video, video quality changes. - */ - public interface VideoEventListener { - /** - * Called when the peer pauses or un-pauses video transmission. - * - * @param call The call which paused or un-paused video transmission. - * @param paused {@code True} when the video transmission is paused, {@code false} - * otherwise. - */ - public void onPeerPauseStateChanged(Call call, boolean paused); - - /** - * Called when the video quality changes. - * - * @param call The call whose video quality changes. - * @param videoCallQuality - values are QUALITY_HIGH, MEDIUM, LOW and UNKNOWN. - */ - public void onVideoQualityChanged(Call call, int videoCallQuality); - - /* - * Called when call data usage value is requested or when call data usage value is updated - * because of a call state change - * - * @param dataUsage call data usage value - */ - public void onCallDataUsageChange(long dataUsage); - - /** - * Called when call session event is raised. - * - * @param event The call session event. - */ - public void onCallSessionEvent(int event); - } - - /** - * Listener interface for any class that wants to be notified of changes to the video surfaces. - */ - public interface SurfaceChangeListener { - /** - * Called when the peer video feed changes dimensions. This can occur when the peer rotates - * their device, changing the aspect ratio of the video signal. - * - * @param call The call which experienced a peer video - * @param width - * @param height - */ - public void onUpdatePeerDimensions(Call call, int width, int height); - - /** - * Called when the local camera changes dimensions. This occurs when a change in camera - * occurs. - * - * @param call The call which experienced the camera dimension change. - * @param width The new camera video width. - * @param height The new camera video height. - */ - public void onCameraDimensionsChange(Call call, int width, int height); - } -} diff --git a/InCallUI/src/com/android/incallui/VideoCallPresenter.java b/InCallUI/src/com/android/incallui/VideoCallPresenter.java index 9bc0822bf..b9aeacfd7 100644 --- a/InCallUI/src/com/android/incallui/VideoCallPresenter.java +++ b/InCallUI/src/com/android/incallui/VideoCallPresenter.java @@ -33,8 +33,8 @@ import com.android.incallui.InCallPresenter.InCallDetailsListener; import com.android.incallui.InCallPresenter.InCallOrientationListener; import com.android.incallui.InCallPresenter.InCallStateListener; import com.android.incallui.InCallPresenter.IncomingCallListener; -import com.android.incallui.InCallVideoCallListenerNotifier.SurfaceChangeListener; -import com.android.incallui.InCallVideoCallListenerNotifier.VideoEventListener; +import com.android.incallui.InCallVideoCallCallbackNotifier.SurfaceChangeListener; +import com.android.incallui.InCallVideoCallCallbackNotifier.VideoEventListener; import com.google.common.base.Preconditions; import java.util.Objects; @@ -64,7 +64,7 @@ import java.util.Objects; public class VideoCallPresenter extends Presenter implements IncomingCallListener, InCallOrientationListener, InCallStateListener, InCallDetailsListener, SurfaceChangeListener, VideoEventListener, - InCallVideoCallListenerNotifier.SessionModificationListener { + InCallVideoCallCallbackNotifier.SessionModificationListener { public static final String TAG = "VideoCallPresenter"; public static final boolean DEBUG = false; @@ -198,9 +198,9 @@ public class VideoCallPresenter extends Presenter