1/* 2 * Copyright (C) 2016 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 */ 16package com.android.bluetooth.hfpclient.connserv; 17 18import android.bluetooth.BluetoothDevice; 19import android.bluetooth.BluetoothHeadsetClient; 20import android.bluetooth.BluetoothHeadsetClientCall; 21import android.os.Bundle; 22import android.telecom.Conference; 23import android.telecom.Connection; 24import android.telecom.DisconnectCause; 25import android.telecom.PhoneAccountHandle; 26import android.util.Log; 27 28import java.util.List; 29import java.util.ArrayList; 30 31public class HfpClientConference extends Conference { 32 private static final String TAG = "HfpClientConference"; 33 34 private BluetoothDevice mDevice; 35 private BluetoothHeadsetClient mHeadsetProfile; 36 37 public HfpClientConference(PhoneAccountHandle handle, 38 BluetoothDevice device, BluetoothHeadsetClient client) { 39 super(handle); 40 mDevice = device; 41 mHeadsetProfile = client; 42 boolean manage = HfpClientConnectionService.hasHfpClientEcc(client, device); 43 setConnectionCapabilities(Connection.CAPABILITY_SUPPORT_HOLD | 44 Connection.CAPABILITY_HOLD | 45 (manage ? Connection.CAPABILITY_MANAGE_CONFERENCE : 0)); 46 setActive(); 47 } 48 49 @Override 50 public void onDisconnect() { 51 Log.d(TAG, "onDisconnect"); 52 mHeadsetProfile.terminateCall(mDevice, 0); 53 setDisconnected(new DisconnectCause(DisconnectCause.LOCAL)); 54 } 55 56 @Override 57 public void onMerge(Connection connection) { 58 Log.d(TAG, "onMerge " + connection); 59 addConnection(connection); 60 } 61 62 @Override 63 public void onSeparate(Connection connection) { 64 Log.d(TAG, "onSeparate " + connection); 65 ((HfpClientConnection) connection).enterPrivateMode(); 66 removeConnection(connection); 67 } 68 69 @Override 70 public void onHold() { 71 Log.d(TAG, "onHold"); 72 mHeadsetProfile.holdCall(mDevice); 73 } 74 75 @Override 76 public void onUnhold() { 77 if (getPrimaryConnection().getConnectionService() 78 .getAllConnections().size() > 1) { 79 Log.w(TAG, "Ignoring unhold; call hold on the foreground call"); 80 return; 81 } 82 Log.d(TAG, "onUnhold"); 83 mHeadsetProfile.acceptCall(mDevice, BluetoothHeadsetClient.CALL_ACCEPT_HOLD); 84 } 85 86 @Override 87 public void onPlayDtmfTone(char c) { 88 Log.d(TAG, "onPlayDtmfTone " + c); 89 if (mHeadsetProfile != null) { 90 mHeadsetProfile.sendDTMF(mDevice, (byte) c); 91 } 92 } 93 94 @Override 95 public void onConnectionAdded(Connection connection) { 96 Log.d(TAG, "onConnectionAdded " + connection); 97 if (connection.getState() == Connection.STATE_HOLDING && 98 getState() == Connection.STATE_ACTIVE) { 99 connection.onAnswer(); 100 } else if (connection.getState() == Connection.STATE_ACTIVE && 101 getState() == Connection.STATE_HOLDING) { 102 mHeadsetProfile.acceptCall(mDevice, BluetoothHeadsetClient.CALL_ACCEPT_NONE); 103 } 104 } 105} 106