From 1869dcf386a96f060a16ac74f1722d816b69aa7d Mon Sep 17 00:00:00 2001 From: Tyler Gunn Date: Tue, 22 Jul 2014 12:16:47 -0700 Subject: InCall UI VT changes 1. Adding CallVideoClientNotifier - used by InCallVideoClient to notify interested listeners of events related to call video clients. 2. Change InCallVideoClient to use CallVideoClientNotifier to notify listeners of incoming events. 3. Modify call details listener signature in InCallPresenter to include the call for which the details changed. 4. Changing VideoCallPresenter to subscribe to call details changes, so it will keep informed of changes to the video state of the call. Bug: 16012946 Change-Id: I47aa2a8e8c852bb7e4ea2e83fa4a30b2697266e6 --- InCallUI/src/com/android/incallui/Call.java | 2 +- .../com/android/incallui/CallCardPresenter.java | 2 +- .../android/incallui/CallVideoClientNotifier.java | 207 +++++++++++++++++++++ .../src/com/android/incallui/InCallPresenter.java | 5 +- .../com/android/incallui/InCallVideoClient.java | 91 ++++++++- .../com/android/incallui/VideoCallFragment.java | 13 -- .../com/android/incallui/VideoCallPresenter.java | 103 +++++++++- 7 files changed, 399 insertions(+), 24 deletions(-) create mode 100644 InCallUI/src/com/android/incallui/CallVideoClientNotifier.java diff --git a/InCallUI/src/com/android/incallui/Call.java b/InCallUI/src/com/android/incallui/Call.java index f3986a4fa..3887eca5b 100644 --- a/InCallUI/src/com/android/incallui/Call.java +++ b/InCallUI/src/com/android/incallui/Call.java @@ -202,7 +202,7 @@ public final class Call { if (mTelecommCall.getCallVideoProvider() != null) { if (mCallVideoClient == null) { - mCallVideoClient = new InCallVideoClient(); + mCallVideoClient = new InCallVideoClient(this); } mTelecommCall.getCallVideoProvider().setCallVideoClient(mCallVideoClient); } diff --git a/InCallUI/src/com/android/incallui/CallCardPresenter.java b/InCallUI/src/com/android/incallui/CallCardPresenter.java index 5a1605090..645879984 100644 --- a/InCallUI/src/com/android/incallui/CallCardPresenter.java +++ b/InCallUI/src/com/android/incallui/CallCardPresenter.java @@ -220,7 +220,7 @@ public class CallCardPresenter extends Presenter } @Override - public void onDetailsChanged(android.telecomm.Call.Details details) { + public void onDetailsChanged(Call call, android.telecomm.Call.Details details) { getUi().setCallDetails(details); if (mPrimary != null) { diff --git a/InCallUI/src/com/android/incallui/CallVideoClientNotifier.java b/InCallUI/src/com/android/incallui/CallVideoClientNotifier.java new file mode 100644 index 000000000..2c048997f --- /dev/null +++ b/InCallUI/src/com/android/incallui/CallVideoClientNotifier.java @@ -0,0 +1,207 @@ +/* + * 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.android.collect.Sets; +import com.google.common.base.Preconditions; + +import java.util.Set; + +/** + * Class used by {@link InCallVideoClient}s to notify interested parties of incoming events. + */ +public class CallVideoClientNotifier { + /** + * Singleton instance of this class. + */ + private static CallVideoClientNotifier sInstance = new CallVideoClientNotifier(); + + private final Set mSessionModificationListeners = + Sets.newHashSet(); + private final Set mVideoEventListeners = Sets.newHashSet(); + private final Set mSurfaceChangeListeners = Sets.newHashSet(); + + /** + * Static singleton accessor method. + */ + public static CallVideoClientNotifier getInstance() { + return sInstance; + } + + /** + * Private constructor. Instance should only be acquired through getInstance(). + */ + private CallVideoClientNotifier() { + } + + /** + * 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) { + Preconditions.checkNotNull(listener); + 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) { + Preconditions.checkNotNull(listener); + 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) { + Preconditions.checkNotNull(listener); + mSurfaceChangeListeners.remove(listener); + } + + /** + * Inform listeners of an upgrade to video request for a call. + * + * @param call The call. + */ + public void upgradeToVideoRequest(Call call) { + for (SessionModificationListener listener : mSessionModificationListeners) { + listener.onUpgradeToVideoRequest(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 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 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); + } + } + + /** + * 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. + */ + public void onUpgradeToVideoRequest(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. + */ + 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); + } + + /** + * 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); + } +} diff --git a/InCallUI/src/com/android/incallui/InCallPresenter.java b/InCallUI/src/com/android/incallui/InCallPresenter.java index cc7f1b9a0..3a8dc43b6 100644 --- a/InCallUI/src/com/android/incallui/InCallPresenter.java +++ b/InCallUI/src/com/android/incallui/InCallPresenter.java @@ -88,7 +88,8 @@ public class InCallPresenter implements CallList.Listener, InCallPhoneListener { public void onDetailsChanged(android.telecomm.Call call, android.telecomm.Call.Details details) { for (InCallDetailsListener listener : mDetailsListeners) { - listener.onDetailsChanged(details); + listener.onDetailsChanged(CallList.getInstance().getCallByTelecommCall(call), + details); } } @@ -876,6 +877,6 @@ public class InCallPresenter implements CallList.Listener, InCallPhoneListener { } public interface InCallDetailsListener { - public void onDetailsChanged(android.telecomm.Call.Details details); + public void onDetailsChanged(Call call, android.telecomm.Call.Details details); } } diff --git a/InCallUI/src/com/android/incallui/InCallVideoClient.java b/InCallUI/src/com/android/incallui/InCallVideoClient.java index 097054dbf..792348b6a 100644 --- a/InCallUI/src/com/android/incallui/InCallVideoClient.java +++ b/InCallUI/src/com/android/incallui/InCallVideoClient.java @@ -24,34 +24,117 @@ import android.telecomm.CallVideoClient; * Implements the InCall-UI Call Video client. */ public class InCallVideoClient extends CallVideoClient { + + /** + * 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 InCallVideoClient(Call call) { + mCall = call; + } + + /** + * Handles an incoming session modification request. + * + * @param videoCallProfile The requested video call profile. + */ @Override public void onReceiveSessionModifyRequest(VideoCallProfile videoCallProfile) { + int previousVideoState = mCall.getVideoState(); + int newVideoState = videoCallProfile.getVideoState(); + + boolean wasVideoState = isVideoStateSet(previousVideoState, + VideoCallProfile.VIDEO_STATE_BIDIRECTIONAL); + boolean isVideoState = isVideoStateSet(newVideoState, + VideoCallProfile.VIDEO_STATE_BIDIRECTIONAL); + + boolean wasPaused = isVideoStateSet(previousVideoState, VideoCallProfile.VIDEO_STATE_PAUSED); + boolean isPaused = isVideoStateSet(newVideoState, VideoCallProfile.VIDEO_STATE_PAUSED); + // Check for upgrades to video and downgrades to audio. + if (!wasVideoState && isVideoState) { + CallVideoClientNotifier.getInstance().upgradeToVideoRequest(mCall); + } else if (wasVideoState && !isVideoState) { + CallVideoClientNotifier.getInstance().downgradeToAudio(mCall); + } + + // Check for pause/un-pause + if (!wasPaused && isPaused) { + CallVideoClientNotifier.getInstance().peerPausedStateChanged(mCall, true /* pause */); + } else { + CallVideoClientNotifier.getInstance().peerPausedStateChanged(mCall, false /* resume */); + } } + /** + * Handles a session modification response. + * + * @param status Status of the session modify request. Valid values are + * {@link CallVideoClient#SESSION_MODIFY_REQUEST_SUCCESS}, + * {@link CallVideoClient#SESSION_MODIFY_REQUEST_FAIL}, + * {@link CallVideoClient#SESSION_MODIFY_REQUEST_INVALID} + * @param requestedProfile + * @param responseProfile The actual profile changes made by the peer device. + */ @Override public void onReceiveSessionModifyResponse(int status, VideoCallProfile requestedProfile, VideoCallProfile responseProfile) { - } + /** + * Handles a call session event. + * + * @param event The event. + */ @Override public void onHandleCallSessionEvent(int 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 onUpdatePeerDimensions(int width, int height) { - + CallVideoClientNotifier.getInstance().peerDimensionsChanged(mCall, width, height); } + /** + * 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 onUpdateCallDataUsage(int dataUsage) { - } + /** + * Handles changes to the camera capabilities. No implementation as the in-call UI does not + * make use of camera capabilities. + * + * @param callCameraCapabilities The changed camera capabilities. + */ @Override public void onHandleCameraCapabilitiesChange(CallCameraCapabilities callCameraCapabilities) { + } + /** + * Determines if a specified state is set in a videoState bit-mask. + * + * @param videoState The video state bit-mask. + * @param state The state to check. + * @return {@code True} if the state is set. + */ + private boolean isVideoStateSet(int videoState, int state) { + return (videoState & state) == state; } } diff --git a/InCallUI/src/com/android/incallui/VideoCallFragment.java b/InCallUI/src/com/android/incallui/VideoCallFragment.java index eee9643f2..969ec01d2 100644 --- a/InCallUI/src/com/android/incallui/VideoCallFragment.java +++ b/InCallUI/src/com/android/incallui/VideoCallFragment.java @@ -16,7 +16,6 @@ package com.android.incallui; -import android.content.res.Configuration; import android.os.Bundle; import android.view.LayoutInflater; import android.view.Surface; @@ -27,7 +26,6 @@ import android.view.ViewGroup; import android.view.ViewStub; import java.util.Set; -import java.util.concurrent.CopyOnWriteArraySet; /** * Fragment containing video calling surfaces. @@ -48,11 +46,6 @@ public class VideoCallFragment extends BaseFragment mListeners = new CopyOnWriteArraySet<>(); - /** * {@link ViewStub} holding the video call surfaces. This is the parent for the * {@link VideoCallFragment}. Used to ensure that the video surfaces are only inflated when @@ -195,7 +188,6 @@ public class VideoCallFragment extends BaseFragment implements - InCallPresenter.IncomingCallListener, InCallPresenter.InCallStateListener { + IncomingCallListener, InCallStateListener, + InCallDetailsListener, SurfaceChangeListener, VideoEventListener { /** * The current context. @@ -74,9 +80,28 @@ public class VideoCallPresenter extends Presenter