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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
|
/*
* 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 = CallUtils.isVideoCall(previousVideoState);
boolean isVideoCall = CallUtils.isVideoCall(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) {
// Report the reason the upgrade failed as the new session modification state.
if (status == VideoProvider.SESSION_MODIFY_REQUEST_TIMED_OUT) {
mCall.setSessionModificationState(
Call.SessionModificationState.UPGRADE_TO_VIDEO_REQUEST_TIMED_OUT);
} else {
if (status == VideoProvider.SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE) {
mCall.setSessionModificationState(
Call.SessionModificationState.REQUEST_REJECTED);
} else {
mCall.setSessionModificationState(
Call.SessionModificationState.REQUEST_FAILED);
}
}
InCallVideoCallCallbackNotifier.getInstance().upgradeToVideoFail(status, mCall);
} else if (requestedProfile != null && responseProfile != null) {
boolean modifySucceeded = requestedProfile.getVideoState() ==
responseProfile.getVideoState();
boolean isVideoCall = CallUtils.isVideoCall(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");
}
// Finally clear the outstanding request.
mCall.setSessionModificationState(Call.SessionModificationState.NO_REQUEST);
}
/**
* 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());
}
}
}
|