• 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.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, 0);
53         setDisconnected(new DisconnectCause(DisconnectCause.LOCAL));
54     }
55 
56     @Override
onMerge(Connection connection)57     public void onMerge(Connection connection) {
58         Log.d(TAG, "onMerge " + connection);
59         addConnection(connection);
60     }
61 
62     @Override
onSeparate(Connection connection)63     public void onSeparate(Connection connection) {
64         Log.d(TAG, "onSeparate " + connection);
65         ((HfpClientConnection) connection).enterPrivateMode();
66         removeConnection(connection);
67     }
68 
69     @Override
onHold()70     public void onHold() {
71         Log.d(TAG, "onHold");
72         mHeadsetProfile.holdCall(mDevice);
73     }
74 
75     @Override
onUnhold()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
onPlayDtmfTone(char c)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
onConnectionAdded(Connection connection)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