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
|
/*
* Copyright 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.server.telecom;
import android.media.ToneGenerator;
import android.telecom.Connection;
import android.telecom.VideoProfile;
import java.util.Collection;
/**
* Monitors events from CallsManager and plays in-call tones for events which require them, such as
* different type of call disconnections (busy tone, congestion tone, etc).
*/
public final class InCallToneMonitor extends CallsManagerListenerBase {
private final InCallTonePlayer.Factory mPlayerFactory;
private final CallsManager mCallsManager;
InCallToneMonitor(InCallTonePlayer.Factory playerFactory, CallsManager callsManager) {
mPlayerFactory = playerFactory;
mCallsManager = callsManager;
}
@Override
public void onCallStateChanged(Call call, int oldState, int newState) {
if (mCallsManager.getForegroundCall() != call) {
// We only play tones for foreground calls.
return;
}
if (newState == CallState.DISCONNECTED && call.getDisconnectCause() != null) {
int toneToPlay = InCallTonePlayer.TONE_INVALID;
Log.v(this, "Disconnect cause: %s.", call.getDisconnectCause());
switch(call.getDisconnectCause().getTone()) {
case ToneGenerator.TONE_SUP_BUSY:
toneToPlay = InCallTonePlayer.TONE_BUSY;
break;
case ToneGenerator.TONE_SUP_CONGESTION:
toneToPlay = InCallTonePlayer.TONE_CONGESTION;
break;
case ToneGenerator.TONE_CDMA_REORDER:
toneToPlay = InCallTonePlayer.TONE_REORDER;
break;
case ToneGenerator.TONE_CDMA_ABBR_INTERCEPT:
toneToPlay = InCallTonePlayer.TONE_INTERCEPT;
break;
case ToneGenerator.TONE_CDMA_CALLDROP_LITE:
toneToPlay = InCallTonePlayer.TONE_CDMA_DROP;
break;
case ToneGenerator.TONE_SUP_ERROR:
toneToPlay = InCallTonePlayer.TONE_UNOBTAINABLE_NUMBER;
break;
case ToneGenerator.TONE_PROP_PROMPT:
toneToPlay = InCallTonePlayer.TONE_CALL_ENDED;
break;
}
Log.d(this, "Found a disconnected call with tone to play %d.", toneToPlay);
if (toneToPlay != InCallTonePlayer.TONE_INVALID) {
mPlayerFactory.createPlayer(toneToPlay).startTone();
}
}
}
/**
* Handles requests received via the {@link VideoProviderProxy} requesting a change in the video
* state of the call by the peer. If the request involves the peer turning their camera on,
* the call waiting tone is played to inform the user of the incoming request.
*
* @param call The call.
* @param videoProfile The requested video profile.
*/
@Override
public void onSessionModifyRequestReceived(Call call, VideoProfile videoProfile) {
if (videoProfile == null) {
return;
}
if (mCallsManager.getForegroundCall() != call) {
// We only play tones for foreground calls.
return;
}
int previousVideoState = call.getVideoState();
int newVideoState = videoProfile.getVideoState();
Log.v(this, "onSessionModifyRequestReceived : videoProfile = " + VideoProfile
.videoStateToString(newVideoState));
boolean isUpgradeRequest = !VideoProfile.isReceptionEnabled(previousVideoState) &&
VideoProfile.isReceptionEnabled(newVideoState);
if (isUpgradeRequest) {
mPlayerFactory.createPlayer(InCallTonePlayer.TONE_VIDEO_UPGRADE).startTone();
}
}
}
|