1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
|
/*
* 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.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) {
int previousVideoState = mCall.getVideoState();
int newVideoState = videoProfile.getVideoState();
boolean wasVideoCall = VideoProfile.VideoState.isBidirectional(previousVideoState);
boolean isVideoCall = VideoProfile.VideoState.isBidirectional(newVideoState);
boolean wasPaused = VideoProfile.VideoState.isPaused(previousVideoState);
boolean isPaused = VideoProfile.VideoState.isPaused(newVideoState);
// Check for upgrades to video and downgrades to audio.
if (!wasVideoCall && isVideoCall) {
InCallVideoCallListenerNotifier.getInstance().upgradeToVideoRequest(mCall);
} else if (wasVideoCall && !isVideoCall) {
InCallVideoCallListenerNotifier.getInstance().downgradeToAudio(mCall);
}
boolean pause = !wasPaused && isPaused;
InCallVideoCallListenerNotifier.getInstance().peerPausedStateChanged(mCall, pause);
}
/**
* 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) {
boolean modifySucceeded =
requestedProfile.getVideoState() == responseProfile.getVideoState();
boolean isVideoCall =
VideoProfile.VideoState.isBidirectional(responseProfile.getVideoState());
if (modifySucceeded && isVideoCall) {
InCallVideoCallListenerNotifier.getInstance().upgradeToVideoSuccess(mCall);
} else if (!modifySucceeded || status != Connection.VideoProvider.SESSION_MODIFY_REQUEST_SUCCESS) {
InCallVideoCallListenerNotifier.getInstance().upgradeToVideoFail(mCall);
}
}
/**
* Handles a call session event.
*
* @param event The event.
*/
@Override
public void onCallSessionEvent(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 onPeerDimensionsChanged(int width, int height) {
InCallVideoCallListenerNotifier.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 onCallDataUsageChanged(int 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());
}
}
}
|