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 HfpClientConference(PhoneAccountHandle handle, BluetoothDevice device, BluetoothHeadsetClient client)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 onDisconnect()50 public void onDisconnect() { 51 Log.d(TAG, "onDisconnect"); 52 mHeadsetProfile.terminateCall(mDevice, null); 53 } 54 55 @Override onMerge(Connection connection)56 public void onMerge(Connection connection) { 57 Log.d(TAG, "onMerge " + connection); 58 addConnection(connection); 59 } 60 61 @Override onSeparate(Connection connection)62 public void onSeparate(Connection connection) { 63 Log.d(TAG, "onSeparate " + connection); 64 ((HfpClientConnection) connection).enterPrivateMode(); 65 removeConnection(connection); 66 } 67 68 @Override onHold()69 public void onHold() { 70 Log.d(TAG, "onHold"); 71 mHeadsetProfile.holdCall(mDevice); 72 } 73 74 @Override onUnhold()75 public void onUnhold() { 76 if (getPrimaryConnection().getConnectionService() 77 .getAllConnections().size() > 1) { 78 Log.w(TAG, "Ignoring unhold; call hold on the foreground call"); 79 return; 80 } 81 Log.d(TAG, "onUnhold"); 82 mHeadsetProfile.acceptCall(mDevice, BluetoothHeadsetClient.CALL_ACCEPT_HOLD); 83 } 84 85 @Override onPlayDtmfTone(char c)86 public void onPlayDtmfTone(char c) { 87 Log.d(TAG, "onPlayDtmfTone " + c); 88 if (mHeadsetProfile != null) { 89 mHeadsetProfile.sendDTMF(mDevice, (byte) c); 90 } 91 } 92 93 @Override onConnectionAdded(Connection connection)94 public void onConnectionAdded(Connection connection) { 95 Log.d(TAG, "onConnectionAdded " + connection); 96 if (connection.getState() == Connection.STATE_HOLDING && 97 getState() == Connection.STATE_ACTIVE) { 98 connection.onAnswer(); 99 } else if (connection.getState() == Connection.STATE_ACTIVE && 100 getState() == Connection.STATE_HOLDING) { 101 mHeadsetProfile.acceptCall(mDevice, BluetoothHeadsetClient.CALL_ACCEPT_NONE); 102 } 103 } 104 } 105