Home | History | Annotate | Download | only in telecom
      1 /*
      2  * Copyright 2014, The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *     http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package com.android.server.telecom;
     18 
     19 import android.media.ToneGenerator;
     20 import android.telecom.Connection;
     21 import android.telecom.VideoProfile;
     22 
     23 import java.util.Collection;
     24 
     25 /**
     26  * Monitors events from CallsManager and plays in-call tones for events which require them, such as
     27  * different type of call disconnections (busy tone, congestion tone, etc).
     28  */
     29 public final class InCallToneMonitor extends CallsManagerListenerBase {
     30     private final InCallTonePlayer.Factory mPlayerFactory;
     31 
     32     private final CallsManager mCallsManager;
     33 
     34     InCallToneMonitor(InCallTonePlayer.Factory playerFactory, CallsManager callsManager) {
     35         mPlayerFactory = playerFactory;
     36         mCallsManager = callsManager;
     37     }
     38 
     39     @Override
     40     public void onCallStateChanged(Call call, int oldState, int newState) {
     41         if (mCallsManager.getForegroundCall() != call) {
     42             // We only play tones for foreground calls.
     43             return;
     44         }
     45 
     46         if (newState == CallState.DISCONNECTED && call.getDisconnectCause() != null) {
     47             int toneToPlay = InCallTonePlayer.TONE_INVALID;
     48 
     49             Log.v(this, "Disconnect cause: %s.", call.getDisconnectCause());
     50 
     51             switch(call.getDisconnectCause().getTone()) {
     52                 case ToneGenerator.TONE_SUP_BUSY:
     53                     toneToPlay = InCallTonePlayer.TONE_BUSY;
     54                     break;
     55                 case ToneGenerator.TONE_SUP_CONGESTION:
     56                     toneToPlay = InCallTonePlayer.TONE_CONGESTION;
     57                     break;
     58                 case ToneGenerator.TONE_CDMA_REORDER:
     59                     toneToPlay = InCallTonePlayer.TONE_REORDER;
     60                     break;
     61                 case ToneGenerator.TONE_CDMA_ABBR_INTERCEPT:
     62                     toneToPlay = InCallTonePlayer.TONE_INTERCEPT;
     63                     break;
     64                 case ToneGenerator.TONE_CDMA_CALLDROP_LITE:
     65                     toneToPlay = InCallTonePlayer.TONE_CDMA_DROP;
     66                     break;
     67                 case ToneGenerator.TONE_SUP_ERROR:
     68                     toneToPlay = InCallTonePlayer.TONE_UNOBTAINABLE_NUMBER;
     69                     break;
     70                 case ToneGenerator.TONE_PROP_PROMPT:
     71                     toneToPlay = InCallTonePlayer.TONE_CALL_ENDED;
     72                     break;
     73             }
     74 
     75             Log.d(this, "Found a disconnected call with tone to play %d.", toneToPlay);
     76 
     77             if (toneToPlay != InCallTonePlayer.TONE_INVALID) {
     78                 mPlayerFactory.createPlayer(toneToPlay).startTone();
     79             }
     80         }
     81     }
     82 
     83     /**
     84      * Handles requests received via the {@link VideoProviderProxy} requesting a change in the video
     85      * state of the call by the peer.  If the request involves the peer turning their camera on,
     86      * the call waiting tone is played to inform the user of the incoming request.
     87      *
     88      * @param call The call.
     89      * @param videoProfile The requested video profile.
     90      */
     91     @Override
     92     public void onSessionModifyRequestReceived(Call call, VideoProfile videoProfile) {
     93         if (videoProfile == null) {
     94             return;
     95         }
     96 
     97         if (mCallsManager.getForegroundCall() != call) {
     98             // We only play tones for foreground calls.
     99             return;
    100         }
    101 
    102         int previousVideoState = call.getVideoState();
    103         int newVideoState = videoProfile.getVideoState();
    104         Log.v(this, "onSessionModifyRequestReceived : videoProfile = " + VideoProfile
    105                 .videoStateToString(newVideoState));
    106 
    107         boolean isUpgradeRequest = !VideoProfile.isReceptionEnabled(previousVideoState) &&
    108                 VideoProfile.isReceptionEnabled(newVideoState);
    109 
    110         if (isUpgradeRequest) {
    111             mPlayerFactory.createPlayer(InCallTonePlayer.TONE_VIDEO_UPGRADE).startTone();
    112         }
    113     }
    114 }
    115