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 */ 16 package com.android.bluetooth.hfpclient.connserv; 17 18 import android.bluetooth.BluetoothDevice; 19 import android.bluetooth.BluetoothHeadsetClient; 20 import android.bluetooth.BluetoothHeadsetClientCall; 21 import android.os.Bundle; 22 import android.telecom.Conference; 23 import android.telecom.Connection; 24 import android.telecom.DisconnectCause; 25 import android.telecom.PhoneAccountHandle; 26 import android.util.Log; 27 28 import java.util.List; 29 import java.util.ArrayList; 30 31 public 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, null); 53 } 54 55 @Override 56 public void onMerge(Connection connection) { 57 Log.d(TAG, "onMerge " + connection); 58 addConnection(connection); 59 } 60 61 @Override 62 public void onSeparate(Connection connection) { 63 Log.d(TAG, "onSeparate " + connection); 64 ((HfpClientConnection) connection).enterPrivateMode(); 65 removeConnection(connection); 66 } 67 68 @Override 69 public void onHold() { 70 Log.d(TAG, "onHold"); 71 mHeadsetProfile.holdCall(mDevice); 72 } 73 74 @Override 75 public void onUnhold() { 76 Log.d(TAG, "onUnhold"); 77 mHeadsetProfile.acceptCall(mDevice, BluetoothHeadsetClient.CALL_ACCEPT_HOLD); 78 } 79 80 @Override 81 public void onPlayDtmfTone(char c) { 82 Log.d(TAG, "onPlayDtmfTone " + c); 83 if (mHeadsetProfile != null) { 84 mHeadsetProfile.sendDTMF(mDevice, (byte) c); 85 } 86 } 87 88 @Override 89 public void onConnectionAdded(Connection connection) { 90 Log.d(TAG, "onConnectionAdded " + connection); 91 if (connection.getState() == Connection.STATE_HOLDING && 92 getState() == Connection.STATE_ACTIVE) { 93 connection.onAnswer(); 94 } else if (connection.getState() == Connection.STATE_ACTIVE && 95 getState() == Connection.STATE_HOLDING) { 96 mHeadsetProfile.acceptCall(mDevice, BluetoothHeadsetClient.CALL_ACCEPT_NONE); 97 } 98 } 99 } 100