• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.telecom.Conference;
21 import android.telecom.Connection;
22 import android.telecom.PhoneAccountHandle;
23 import android.util.Log;
24 
25 public class HfpClientConference extends Conference {
26     private static final String TAG = "HfpClientConference";
27 
28     private BluetoothDevice mDevice;
29     private BluetoothHeadsetClient mHeadsetProfile;
30 
HfpClientConference(PhoneAccountHandle handle, BluetoothDevice device, BluetoothHeadsetClient client)31     public HfpClientConference(PhoneAccountHandle handle, BluetoothDevice device,
32             BluetoothHeadsetClient client) {
33         super(handle);
34         mDevice = device;
35         mHeadsetProfile = client;
36         boolean manage = HfpClientConnectionService.hasHfpClientEcc(client, device);
37         setConnectionCapabilities(
38                 Connection.CAPABILITY_SUPPORT_HOLD | Connection.CAPABILITY_HOLD | (manage
39                         ? Connection.CAPABILITY_MANAGE_CONFERENCE : 0));
40         setActive();
41     }
42 
43     @Override
onDisconnect()44     public void onDisconnect() {
45         Log.d(TAG, "onDisconnect");
46         mHeadsetProfile.terminateCall(mDevice, null);
47     }
48 
49     @Override
onMerge(Connection connection)50     public void onMerge(Connection connection) {
51         Log.d(TAG, "onMerge " + connection);
52         addConnection(connection);
53     }
54 
55     @Override
onSeparate(Connection connection)56     public void onSeparate(Connection connection) {
57         Log.d(TAG, "onSeparate " + connection);
58         ((HfpClientConnection) connection).enterPrivateMode();
59         removeConnection(connection);
60     }
61 
62     @Override
onHold()63     public void onHold() {
64         Log.d(TAG, "onHold");
65         mHeadsetProfile.holdCall(mDevice);
66     }
67 
68     @Override
onUnhold()69     public void onUnhold() {
70         Log.d(TAG, "onUnhold");
71         mHeadsetProfile.acceptCall(mDevice, BluetoothHeadsetClient.CALL_ACCEPT_HOLD);
72     }
73 
74     @Override
onPlayDtmfTone(char c)75     public void onPlayDtmfTone(char c) {
76         Log.d(TAG, "onPlayDtmfTone " + c);
77         if (mHeadsetProfile != null) {
78             mHeadsetProfile.sendDTMF(mDevice, (byte) c);
79         }
80     }
81 
82     @Override
onConnectionAdded(Connection connection)83     public void onConnectionAdded(Connection connection) {
84         Log.d(TAG, "onConnectionAdded " + connection);
85         if (connection.getState() == Connection.STATE_HOLDING
86                 && getState() == Connection.STATE_ACTIVE) {
87             connection.onAnswer();
88         } else if (connection.getState() == Connection.STATE_ACTIVE
89                 && getState() == Connection.STATE_HOLDING) {
90             mHeadsetProfile.acceptCall(mDevice, BluetoothHeadsetClient.CALL_ACCEPT_NONE);
91         }
92     }
93 }
94