17aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta/*
27aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta * Copyright (C) 2014 The Android Open Source Project
37aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta *
47aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta * Licensed under the Apache License, Version 2.0 (the "License");
57aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta * you may not use this file except in compliance with the License.
67aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta * You may obtain a copy of the License at
77aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta *
87aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta *      http://www.apache.org/licenses/LICENSE-2.0
97aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta *
107aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta * Unless required by applicable law or agreed to in writing, software
117aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta * distributed under the License is distributed on an "AS IS" BASIS,
127aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
137aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta * See the License for the specific language governing permissions and
147aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta * limitations under the License.
157aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta */
167aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta
177aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Guptapackage android.bluetooth;
187aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta
197aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Guptaimport android.content.ComponentName;
207aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Guptaimport android.content.Context;
217aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Guptaimport android.content.Intent;
227aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Guptaimport android.content.ServiceConnection;
230a17db1cc5942ea000ca87bb72853de57a15ec64Jeff Sharkeyimport android.os.Binder;
247aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Guptaimport android.os.Bundle;
257aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Guptaimport android.os.IBinder;
267aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Guptaimport android.os.RemoteException;
277aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Guptaimport android.util.Log;
287aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta
297aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Guptaimport java.util.ArrayList;
307aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Guptaimport java.util.List;
3140bb6f3f8fc02600fe24301c11e804196ced3531Sanket Agarwalimport java.util.UUID;
327aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta
337aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta/**
347aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta * Public API to control Hands Free Profile (HFP role only).
357aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta * <p>
367aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta * This class defines methods that shall be used by application to manage profile
377aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta * connection, calls states and calls actions.
387aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta * <p>
397aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta *
407aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta * @hide
417aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta * */
42cf916d34671f0ab6aad8de24c18e4dc96fb21941Mike Lockwoodpublic final class BluetoothHeadsetClient implements BluetoothProfile {
43cf916d34671f0ab6aad8de24c18e4dc96fb21941Mike Lockwood    private static final String TAG = "BluetoothHeadsetClient";
447aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    private static final boolean DBG = true;
457aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    private static final boolean VDBG = false;
467aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta
477aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    /**
487aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * Intent sent whenever connection to remote changes.
497aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     *
507aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * <p>It includes two extras:
517aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * <code>BluetoothProfile.EXTRA_PREVIOUS_STATE</code>
527aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * and <code>BluetoothProfile.EXTRA_STATE</code>, which
537aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * are mandatory.
547aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * <p>There are also non mandatory feature extras:
557aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * {@link #EXTRA_AG_FEATURE_3WAY_CALLING},
567aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * {@link #EXTRA_AG_FEATURE_VOICE_RECOGNITION},
577aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * {@link #EXTRA_AG_FEATURE_ATTACH_NUMBER_TO_VT},
587aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * {@link #EXTRA_AG_FEATURE_REJECT_CALL},
597aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * {@link #EXTRA_AG_FEATURE_ECC},
607aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * {@link #EXTRA_AG_FEATURE_RESPONSE_AND_HOLD},
617aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * {@link #EXTRA_AG_FEATURE_ACCEPT_HELD_OR_WAITING_CALL},
627aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * {@link #EXTRA_AG_FEATURE_RELEASE_HELD_OR_WAITING_CALL},
637aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * {@link #EXTRA_AG_FEATURE_RELEASE_AND_ACCEPT},
647aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * {@link #EXTRA_AG_FEATURE_MERGE},
657aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * {@link #EXTRA_AG_FEATURE_MERGE_AND_DETACH},
667aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * sent as boolean values only when <code>EXTRA_STATE</code>
677aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * is set to <code>STATE_CONNECTED</code>.</p>
687aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     *
697aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * <p>Note that features supported by AG are being sent as
707aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * booleans with value <code>true</code>,
717aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * and not supported ones are <strong>not</strong> being sent at all.</p>
727aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     */
737aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    public static final String ACTION_CONNECTION_STATE_CHANGED =
74cf916d34671f0ab6aad8de24c18e4dc96fb21941Mike Lockwood        "android.bluetooth.headsetclient.profile.action.CONNECTION_STATE_CHANGED";
757aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta
767aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    /**
777aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * Intent sent whenever audio state changes.
787aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     *
797aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * <p>It includes two mandatory extras:
807aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * {@link BluetoothProfile.EXTRA_STATE},
817aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * {@link BluetoothProfile.EXTRA_PREVIOUS_STATE},
827aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * with possible values:
837aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * {@link #STATE_AUDIO_CONNECTING},
847aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * {@link #STATE_AUDIO_CONNECTED},
857aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * {@link #STATE_AUDIO_DISCONNECTED}</p>
867aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * <p>When <code>EXTRA_STATE</code> is set
877aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * to </code>STATE_AUDIO_CONNECTED</code>,
887aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * it also includes {@link #EXTRA_AUDIO_WBS}
897aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * indicating wide band speech support.</p>
907aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     */
917aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    public static final String ACTION_AUDIO_STATE_CHANGED =
92cf916d34671f0ab6aad8de24c18e4dc96fb21941Mike Lockwood        "android.bluetooth.headsetclient.profile.action.AUDIO_STATE_CHANGED";
937aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta
947aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    /**
957aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * Intent sending updates of the Audio Gateway state.
967aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * Each extra is being sent only when value it
977aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * represents has been changed recently on AG.
987aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * <p>It can contain one or more of the following extras:
997aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * {@link #EXTRA_NETWORK_STATUS},
1007aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * {@link #EXTRA_NETWORK_SIGNAL_STRENGTH},
1017aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * {@link #EXTRA_NETWORK_ROAMING},
1027aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * {@link #EXTRA_BATTERY_LEVEL},
1037aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * {@link #EXTRA_OPERATOR_NAME},
1047aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * {@link #EXTRA_VOICE_RECOGNITION},
1057aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * {@link #EXTRA_IN_BAND_RING}</p>
1067aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     */
1077aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    public static final String ACTION_AG_EVENT =
108cf916d34671f0ab6aad8de24c18e4dc96fb21941Mike Lockwood            "android.bluetooth.headsetclient.profile.action.AG_EVENT";
1097aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta
1107aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    /**
1117aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * Intent sent whenever state of a call changes.
1127aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     *
1137aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * <p>It includes:
1147aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * {@link #EXTRA_CALL},
115cf916d34671f0ab6aad8de24c18e4dc96fb21941Mike Lockwood     * with value of {@link BluetoothHeadsetClientCall} instance,
1167aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * representing actual call state.</p>
1177aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     */
1187aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    public static final String ACTION_CALL_CHANGED =
119cf916d34671f0ab6aad8de24c18e4dc96fb21941Mike Lockwood            "android.bluetooth.headsetclient.profile.action.AG_CALL_CHANGED";
1207aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta
1217aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    /**
1227aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * Intent that notifies about the result of the last issued action.
1237aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * Please note that not every action results in explicit action result code being sent.
1247aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * Instead other notifications about new Audio Gateway state might be sent,
1257aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * like <code>ACTION_AG_EVENT</code> with <code>EXTRA_VOICE_RECOGNITION</code> value
1267aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * when for example user started voice recognition from HF unit.
1277aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     */
1287aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    public static final String ACTION_RESULT =
129cf916d34671f0ab6aad8de24c18e4dc96fb21941Mike Lockwood            "android.bluetooth.headsetclient.profile.action.RESULT";
1307aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta
1317aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    /**
1327aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * Intent that notifies about the number attached to the last voice tag
1337aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * recorded on AG.
1347aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     *
1357aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * <p>It contains:
1367aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * {@link #EXTRA_NUMBER},
1377aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * with a <code>String</code> value representing phone number.</p>
1387aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     */
1397aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    public static final String ACTION_LAST_VTAG =
140cf916d34671f0ab6aad8de24c18e4dc96fb21941Mike Lockwood            "android.bluetooth.headsetclient.profile.action.LAST_VTAG";
1417aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta
1427aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    public static final int STATE_AUDIO_DISCONNECTED = 0;
1437aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    public static final int STATE_AUDIO_CONNECTING = 1;
1447aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    public static final int STATE_AUDIO_CONNECTED = 2;
1457aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta
1467aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    /**
1477aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * Extra with information if connected audio is WBS.
1487aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * <p>Possible values: <code>true</code>,
1497aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     *                     <code>false</code>.</p>
1507aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     */
1517aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    public static final String EXTRA_AUDIO_WBS =
152cf916d34671f0ab6aad8de24c18e4dc96fb21941Mike Lockwood            "android.bluetooth.headsetclient.extra.AUDIO_WBS";
1537aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta
1547aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    /**
1557aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * Extra for AG_EVENT indicates network status.
1567aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * <p>Value: 0 - network unavailable,
1577aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     *           1 - network available </p>
1587aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     */
1597aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    public static final String EXTRA_NETWORK_STATUS =
160cf916d34671f0ab6aad8de24c18e4dc96fb21941Mike Lockwood            "android.bluetooth.headsetclient.extra.NETWORK_STATUS";
1617aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    /**
1627aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * Extra for AG_EVENT intent indicates network signal strength.
1637aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * <p>Value: <code>Integer</code> representing signal strength.</p>
1647aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     */
1657aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    public static final String EXTRA_NETWORK_SIGNAL_STRENGTH =
166cf916d34671f0ab6aad8de24c18e4dc96fb21941Mike Lockwood            "android.bluetooth.headsetclient.extra.NETWORK_SIGNAL_STRENGTH";
1677aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    /**
1687aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * Extra for AG_EVENT intent indicates roaming state.
1697aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * <p>Value: 0 - no roaming
1707aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     *           1 - active roaming</p>
1717aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     */
1727aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    public static final String EXTRA_NETWORK_ROAMING =
173cf916d34671f0ab6aad8de24c18e4dc96fb21941Mike Lockwood            "android.bluetooth.headsetclient.extra.NETWORK_ROAMING";
1747aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    /**
1757aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * Extra for AG_EVENT intent indicates the battery level.
1767aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * <p>Value: <code>Integer</code> representing signal strength.</p>
1777aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     */
1787aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    public static final String EXTRA_BATTERY_LEVEL =
179cf916d34671f0ab6aad8de24c18e4dc96fb21941Mike Lockwood            "android.bluetooth.headsetclient.extra.BATTERY_LEVEL";
1807aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    /**
1817aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * Extra for AG_EVENT intent indicates operator name.
1827aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * <p>Value: <code>String</code> representing operator name.</p>
1837aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     */
1847aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    public static final String EXTRA_OPERATOR_NAME =
185cf916d34671f0ab6aad8de24c18e4dc96fb21941Mike Lockwood            "android.bluetooth.headsetclient.extra.OPERATOR_NAME";
1867aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    /**
1877aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * Extra for AG_EVENT intent indicates voice recognition state.
1887aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * <p>Value:
1897aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     *          0 - voice recognition stopped,
1907aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     *          1 - voice recognition started.</p>
1917aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     */
1927aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    public static final String EXTRA_VOICE_RECOGNITION =
193cf916d34671f0ab6aad8de24c18e4dc96fb21941Mike Lockwood            "android.bluetooth.headsetclient.extra.VOICE_RECOGNITION";
1947aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    /**
1957aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * Extra for AG_EVENT intent indicates in band ring state.
1967aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * <p>Value:
1977aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     *          0 - in band ring tone not supported, or
1987aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     *          1 - in band ring tone supported.</p>
1997aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     */
2007aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    public static final String EXTRA_IN_BAND_RING =
201cf916d34671f0ab6aad8de24c18e4dc96fb21941Mike Lockwood            "android.bluetooth.headsetclient.extra.IN_BAND_RING";
2027aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta
2037aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    /**
2047aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * Extra for AG_EVENT intent indicates subscriber info.
2057aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * <p>Value: <code>String</code> containing subscriber information.</p>
2067aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     */
2077aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    public static final String EXTRA_SUBSCRIBER_INFO =
208cf916d34671f0ab6aad8de24c18e4dc96fb21941Mike Lockwood            "android.bluetooth.headsetclient.extra.SUBSCRIBER_INFO";
2097aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta
2107aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    /**
2117aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     *  Extra for AG_CALL_CHANGED intent indicates the
212cf916d34671f0ab6aad8de24c18e4dc96fb21941Mike Lockwood     *  {@link BluetoothHeadsetClientCall} object that has changed.
2137aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     */
2147aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    public static final String EXTRA_CALL =
215cf916d34671f0ab6aad8de24c18e4dc96fb21941Mike Lockwood            "android.bluetooth.headsetclient.extra.CALL";
2167aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta
2177aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    /**
2187aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * Extra for ACTION_LAST_VTAG intent.
2197aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * <p>Value: <code>String</code> representing phone number
2207aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * corresponding to last voice tag recorded on AG</p>
2217aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     */
2227aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    public static final String EXTRA_NUMBER =
223cf916d34671f0ab6aad8de24c18e4dc96fb21941Mike Lockwood            "android.bluetooth.headsetclient.extra.NUMBER";
2247aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta
2257aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    /**
2267aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * Extra for ACTION_RESULT intent that shows the result code of
2277aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * last issued action.
2287aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * <p>Possible results:
2297aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * {@link #ACTION_RESULT_OK},
2307aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * {@link #ACTION_RESULT_ERROR},
2317aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * {@link #ACTION_RESULT_ERROR_NO_CARRIER},
2327aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * {@link #ACTION_RESULT_ERROR_BUSY},
2337aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * {@link #ACTION_RESULT_ERROR_NO_ANSWER},
2347aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * {@link #ACTION_RESULT_ERROR_DELAYED},
2357aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * {@link #ACTION_RESULT_ERROR_BLACKLISTED},
2367aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * {@link #ACTION_RESULT_ERROR_CME}</p>
2377aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     */
2387aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    public static final String EXTRA_RESULT_CODE =
239cf916d34671f0ab6aad8de24c18e4dc96fb21941Mike Lockwood            "android.bluetooth.headsetclient.extra.RESULT_CODE";
2407aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta
2417aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    /**
2427aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * Extra for ACTION_RESULT intent that shows the extended result code of
2437aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * last issued action.
2447aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * <p>Value: <code>Integer</code> - error code.</p>
2457aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     */
2467aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    public static final String EXTRA_CME_CODE =
247cf916d34671f0ab6aad8de24c18e4dc96fb21941Mike Lockwood            "android.bluetooth.headsetclient.extra.CME_CODE";
2487aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta
2497aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    /* Extras for AG_FEATURES, extras type is boolean */
2507aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    // TODO verify if all of those are actually useful
2517aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    /**
2527aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * AG feature: three way calling.
2537aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     */
2547aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    public final static String EXTRA_AG_FEATURE_3WAY_CALLING =
255cf916d34671f0ab6aad8de24c18e4dc96fb21941Mike Lockwood            "android.bluetooth.headsetclient.extra.EXTRA_AG_FEATURE_3WAY_CALLING";
2567aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    /**
2577aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * AG feature: voice recognition.
2587aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     */
2597aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    public final static String EXTRA_AG_FEATURE_VOICE_RECOGNITION =
260cf916d34671f0ab6aad8de24c18e4dc96fb21941Mike Lockwood            "android.bluetooth.headsetclient.extra.EXTRA_AG_FEATURE_VOICE_RECOGNITION";
2617aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    /**
2627aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * AG feature: fetching phone number for voice tagging procedure.
2637aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     */
2647aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    public final static String EXTRA_AG_FEATURE_ATTACH_NUMBER_TO_VT =
265cf916d34671f0ab6aad8de24c18e4dc96fb21941Mike Lockwood            "android.bluetooth.headsetclient.extra.EXTRA_AG_FEATURE_ATTACH_NUMBER_TO_VT";
2667aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    /**
2677aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * AG feature: ability to reject incoming call.
2687aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     */
2697aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    public final static String EXTRA_AG_FEATURE_REJECT_CALL =
270cf916d34671f0ab6aad8de24c18e4dc96fb21941Mike Lockwood            "android.bluetooth.headsetclient.extra.EXTRA_AG_FEATURE_REJECT_CALL";
2717aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    /**
2727aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * AG feature: enhanced call handling (terminate specific call, private consultation).
2737aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     */
2747aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    public final static String EXTRA_AG_FEATURE_ECC =
275cf916d34671f0ab6aad8de24c18e4dc96fb21941Mike Lockwood            "android.bluetooth.headsetclient.extra.EXTRA_AG_FEATURE_ECC";
2767aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    /**
2777aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * AG feature: response and hold.
2787aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     */
2797aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    public final static String EXTRA_AG_FEATURE_RESPONSE_AND_HOLD =
280cf916d34671f0ab6aad8de24c18e4dc96fb21941Mike Lockwood            "android.bluetooth.headsetclient.extra.EXTRA_AG_FEATURE_RESPONSE_AND_HOLD";
2817aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    /**
2827aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * AG call handling feature: accept held or waiting call in three way calling scenarios.
2837aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     */
2847aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    public final static String EXTRA_AG_FEATURE_ACCEPT_HELD_OR_WAITING_CALL =
285cf916d34671f0ab6aad8de24c18e4dc96fb21941Mike Lockwood            "android.bluetooth.headsetclient.extra.EXTRA_AG_FEATURE_ACCEPT_HELD_OR_WAITING_CALL";
2867aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    /**
2877aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * AG call handling feature: release held or waiting call in three way calling scenarios.
2887aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     */
2897aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    public final static String EXTRA_AG_FEATURE_RELEASE_HELD_OR_WAITING_CALL =
290cf916d34671f0ab6aad8de24c18e4dc96fb21941Mike Lockwood            "android.bluetooth.headsetclient.extra.EXTRA_AG_FEATURE_RELEASE_HELD_OR_WAITING_CALL";
2917aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    /**
2927aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * AG call handling feature: release active call and accept held or waiting call in three way
2937aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * calling scenarios.
2947aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     */
2957aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    public final static String EXTRA_AG_FEATURE_RELEASE_AND_ACCEPT =
296cf916d34671f0ab6aad8de24c18e4dc96fb21941Mike Lockwood            "android.bluetooth.headsetclient.extra.EXTRA_AG_FEATURE_RELEASE_AND_ACCEPT";
2977aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    /**
2987aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * AG call handling feature: merge two calls, held and active - multi party conference mode.
2997aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     */
3007aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    public final static String EXTRA_AG_FEATURE_MERGE =
301cf916d34671f0ab6aad8de24c18e4dc96fb21941Mike Lockwood            "android.bluetooth.headsetclient.extra.EXTRA_AG_FEATURE_MERGE";
3027aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    /**
3037aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * AG call handling feature: merge calls and disconnect from multi party
3047aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * conversation leaving peers connected to each other.
3057aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * Note that this feature needs to be supported by mobile network operator
3067aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * as it requires connection and billing transfer.
3077aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     */
3087aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    public final static String EXTRA_AG_FEATURE_MERGE_AND_DETACH =
309cf916d34671f0ab6aad8de24c18e4dc96fb21941Mike Lockwood            "android.bluetooth.headsetclient.extra.EXTRA_AG_FEATURE_MERGE_AND_DETACH";
3107aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta
3117aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    /* Action result codes */
3127aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    public final static int ACTION_RESULT_OK = 0;
3137aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    public final static int ACTION_RESULT_ERROR = 1;
3147aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    public final static int ACTION_RESULT_ERROR_NO_CARRIER = 2;
3157aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    public final static int ACTION_RESULT_ERROR_BUSY = 3;
3167aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    public final static int ACTION_RESULT_ERROR_NO_ANSWER = 4;
3177aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    public final static int ACTION_RESULT_ERROR_DELAYED = 5;
3187aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    public final static int ACTION_RESULT_ERROR_BLACKLISTED = 6;
3197aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    public final static int ACTION_RESULT_ERROR_CME = 7;
3207aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta
3217aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    /* Detailed CME error codes */
3227aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    public final static int CME_PHONE_FAILURE                           = 0;
3237aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    public final static int CME_NO_CONNECTION_TO_PHONE                  = 1;
3247aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    public final static int CME_OPERATION_NOT_ALLOWED                   = 3;
3257aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    public final static int CME_OPERATION_NOT_SUPPORTED                 = 4;
3267aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    public final static int CME_PHSIM_PIN_REQUIRED                      = 5;
3277aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    public final static int CME_PHFSIM_PIN_REQUIRED                     = 6;
3287aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    public final static int CME_PHFSIM_PUK_REQUIRED                     = 7;
3297aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    public final static int CME_SIM_NOT_INSERTED                        = 10;
3307aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    public final static int CME_SIM_PIN_REQUIRED                        = 11;
3317aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    public final static int CME_SIM_PUK_REQUIRED                        = 12;
3327aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    public final static int CME_SIM_FAILURE                             = 13;
3337aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    public final static int CME_SIM_BUSY                                = 14;
3347aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    public final static int CME_SIM_WRONG                               = 15;
3357aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    public final static int CME_INCORRECT_PASSWORD                      = 16;
3367aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    public final static int CME_SIM_PIN2_REQUIRED                       = 17;
3377aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    public final static int CME_SIM_PUK2_REQUIRED                       = 18;
3387aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    public final static int CME_MEMORY_FULL                             = 20;
3397aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    public final static int CME_INVALID_INDEX                           = 21;
3407aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    public final static int CME_NOT_FOUND                               = 22;
3417aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    public final static int CME_MEMORY_FAILURE                          = 23;
3427aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    public final static int CME_TEXT_STRING_TOO_LONG                    = 24;
3437aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    public final static int CME_INVALID_CHARACTER_IN_TEXT_STRING        = 25;
3447aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    public final static int CME_DIAL_STRING_TOO_LONG                    = 26;
3457aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    public final static int CME_INVALID_CHARACTER_IN_DIAL_STRING        = 27;
3467aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    public final static int CME_NO_NETWORK_SERVICE                      = 30;
3477aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    public final static int CME_NETWORK_TIMEOUT                         = 31;
3487aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    public final static int CME_EMERGENCY_SERVICE_ONLY                  = 32;
3497aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    public final static int CME_NO_SIMULTANOUS_VOIP_CS_CALLS            = 33;
3507aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    public final static int CME_NOT_SUPPORTED_FOR_VOIP                  = 34;
3517aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    public final static int CME_SIP_RESPONSE_CODE                       = 35;
3527aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    public final static int CME_NETWORK_PERSONALIZATION_PIN_REQUIRED    = 40;
3537aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    public final static int CME_NETWORK_PERSONALIZATION_PUK_REQUIRED    = 41;
3547aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    public final static int CME_NETWORK_SUBSET_PERSONALIZATION_PIN_REQUIRED   = 42;
3557aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    public final static int CME_NETWORK_SUBSET_PERSONALIZATION_PUK_REQUIRED   = 43;
3567aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    public final static int CME_SERVICE_PROVIDER_PERSONALIZATION_PIN_REQUIRED = 44;
3577aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    public final static int CME_SERVICE_PROVIDER_PERSONALIZATION_PUK_REQUIRED = 45;
3587aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    public final static int CME_CORPORATE_PERSONALIZATION_PIN_REQUIRED  = 46;
3597aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    public final static int CME_CORPORATE_PERSONALIZATION_PUK_REQUIRED  = 47;
3607aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    public final static int CME_HIDDEN_KEY_REQUIRED                     = 48;
3617aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    public final static int CME_EAP_NOT_SUPPORTED                       = 49;
3627aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    public final static int CME_INCORRECT_PARAMETERS                    = 50;
3637aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta
3647aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    /* Action policy for other calls when accepting call */
3657aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    public static final int CALL_ACCEPT_NONE = 0;
3667aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    public static final int CALL_ACCEPT_HOLD = 1;
3677aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    public static final int CALL_ACCEPT_TERMINATE = 2;
3687aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta
3697aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    private Context mContext;
3707aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    private ServiceListener mServiceListener;
371cf916d34671f0ab6aad8de24c18e4dc96fb21941Mike Lockwood    private IBluetoothHeadsetClient mService;
3727aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    private BluetoothAdapter mAdapter;
3737aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta
3747aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    final private IBluetoothStateChangeCallback mBluetoothStateChangeCallback =
3757aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta            new IBluetoothStateChangeCallback.Stub() {
3767aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta                @Override
3777aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta                public void onBluetoothStateChange(boolean up) {
3787aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta                    if (DBG) Log.d(TAG, "onBluetoothStateChange: up=" + up);
3797aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta                    if (!up) {
3807aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta                        if (VDBG) Log.d(TAG,"Unbinding service...");
3817aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta                        synchronized (mConnection) {
3827aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta                            try {
3837aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta                                mService = null;
3847aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta                                mContext.unbindService(mConnection);
3857aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta                            } catch (Exception re) {
3867aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta                                Log.e(TAG,"",re);
3877aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta                            }
3887aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta                        }
3897aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta                    } else {
3907aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta                        synchronized (mConnection) {
3917aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta                            try {
3927aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta                                if (mService == null) {
3937aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta                                    if (VDBG) Log.d(TAG,"Binding service...");
394cf916d34671f0ab6aad8de24c18e4dc96fb21941Mike Lockwood                                    Intent intent = new Intent(IBluetoothHeadsetClient.class.getName());
395cf916d34671f0ab6aad8de24c18e4dc96fb21941Mike Lockwood                                    doBind();
3967aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta                                }
3977aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta                            } catch (Exception re) {
3987aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta                                Log.e(TAG,"",re);
3997aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta                            }
4007aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta                        }
4017aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta                    }
4027aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta                }
4037aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        };
4047aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta
4057aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    /**
406cf916d34671f0ab6aad8de24c18e4dc96fb21941Mike Lockwood     * Create a BluetoothHeadsetClient proxy object.
4077aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     */
408cf916d34671f0ab6aad8de24c18e4dc96fb21941Mike Lockwood    /*package*/ BluetoothHeadsetClient(Context context, ServiceListener l) {
4097aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        mContext = context;
4107aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        mServiceListener = l;
4117aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        mAdapter = BluetoothAdapter.getDefaultAdapter();
4127aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta
4137aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        IBluetoothManager mgr = mAdapter.getBluetoothManager();
4147aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        if (mgr != null) {
4157aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta            try {
4167aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta                mgr.registerStateChangeCallback(mBluetoothStateChangeCallback);
4177aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta            } catch (RemoteException e) {
4187aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta                Log.e(TAG,"",e);
4197aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta            }
4207aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        }
4217aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta
422cf916d34671f0ab6aad8de24c18e4dc96fb21941Mike Lockwood        doBind();
423cf916d34671f0ab6aad8de24c18e4dc96fb21941Mike Lockwood    }
424cf916d34671f0ab6aad8de24c18e4dc96fb21941Mike Lockwood
425cf916d34671f0ab6aad8de24c18e4dc96fb21941Mike Lockwood    boolean doBind() {
426cf916d34671f0ab6aad8de24c18e4dc96fb21941Mike Lockwood        Intent intent = new Intent(IBluetoothHeadsetClient.class.getName());
427cf916d34671f0ab6aad8de24c18e4dc96fb21941Mike Lockwood        ComponentName comp = intent.resolveSystemService(mContext.getPackageManager(), 0);
428cf916d34671f0ab6aad8de24c18e4dc96fb21941Mike Lockwood        intent.setComponent(comp);
429cf916d34671f0ab6aad8de24c18e4dc96fb21941Mike Lockwood        if (comp == null || !mContext.bindServiceAsUser(intent, mConnection, 0,
430cf916d34671f0ab6aad8de24c18e4dc96fb21941Mike Lockwood                 android.os.Process.myUserHandle())) {
431cf916d34671f0ab6aad8de24c18e4dc96fb21941Mike Lockwood            Log.e(TAG, "Could not bind to Bluetooth Headset Client Service with " + intent);
432cf916d34671f0ab6aad8de24c18e4dc96fb21941Mike Lockwood            return false;
4337aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        }
434cf916d34671f0ab6aad8de24c18e4dc96fb21941Mike Lockwood        return true;
4357aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    }
4367aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta
4377aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    /**
4387aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * Close the connection to the backing service.
439cf916d34671f0ab6aad8de24c18e4dc96fb21941Mike Lockwood     * Other public functions of BluetoothHeadsetClient will return default error
4407aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * results once close() has been called. Multiple invocations of close()
4417aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * are ok.
4427aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     */
4437aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    /*package*/ void close() {
4447aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        if (VDBG) log("close()");
4457aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta
4467aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        IBluetoothManager mgr = mAdapter.getBluetoothManager();
4477aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        if (mgr != null) {
4487aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta            try {
4497aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta                mgr.unregisterStateChangeCallback(mBluetoothStateChangeCallback);
4507aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta            } catch (Exception e) {
4517aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta                Log.e(TAG,"",e);
4527aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta            }
4537aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        }
4547aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta
4557aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        synchronized (mConnection) {
4567aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta            if (mService != null) {
4577aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta                try {
4587aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta                    mService = null;
4597aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta                    mContext.unbindService(mConnection);
4607aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta                } catch (Exception re) {
4617aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta                    Log.e(TAG,"",re);
4627aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta                }
4637aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta            }
4647aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        }
4657aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        mServiceListener = null;
4667aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    }
4677aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta
4687aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    /**
4697aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * Connects to remote device.
4707aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     *
4717aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * Currently, the system supports only 1 connection. So, in case of the
4727aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * second connection, this implementation will disconnect already connected
4737aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * device automatically and will process the new one.
4747aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     *
4757aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * @param device    a remote device we want connect to
4767aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * @return <code>true</code> if command has been issued successfully;
4777aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     *          <code>false</code> otherwise;
4787aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     *          upon completion HFP sends {@link #ACTION_CONNECTION_STATE_CHANGED}
4797aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     *          intent.
4807aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     */
4817aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    public boolean connect(BluetoothDevice device) {
4827aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        if (DBG) log("connect(" + device + ")");
4837aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        if (mService != null && isEnabled() &&
4847aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta                isValidDevice(device)) {
4857aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta            try {
4867aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta                return mService.connect(device);
4877aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta            } catch (RemoteException e) {
4887aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta                Log.e(TAG, Log.getStackTraceString(new Throwable()));
4897aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta                return false;
4907aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta            }
4917aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        }
4927aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        if (mService == null) Log.w(TAG, "Proxy not attached to service");
4937aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        return false;
4947aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    }
4957aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta
4967aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    /**
4977aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * Disconnects remote device
4987aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     *
4997aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * @param device    a remote device we want disconnect
5007aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * @return          <code>true</code> if command has been issued successfully;
5017aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     *                  <code>false</code> otherwise;
5027aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     *                  upon completion HFP sends {@link #ACTION_CONNECTION_STATE_CHANGED}
5037aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     *                  intent.
5047aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     */
5057aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    public boolean disconnect(BluetoothDevice device) {
5067aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        if (DBG) log("disconnect(" + device + ")");
5077aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        if (mService != null && isEnabled() &&
5087aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta                isValidDevice(device)) {
5097aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta            try {
5107aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta                return mService.disconnect(device);
5117aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta            } catch (RemoteException e) {
5127aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta              Log.e(TAG, Log.getStackTraceString(new Throwable()));
5137aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta              return false;
5147aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta            }
5157aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        }
5167aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        if (mService == null) Log.w(TAG, "Proxy not attached to service");
5177aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        return false;
5187aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    }
5197aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta
5207aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    /**
5217aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * Return the list of connected remote devices
5227aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     *
5237aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * @return list of connected devices; empty list if nothing is connected.
5247aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     */
5257aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    @Override
5267aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    public List<BluetoothDevice> getConnectedDevices() {
5277aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        if (VDBG) log("getConnectedDevices()");
5287aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        if (mService != null && isEnabled()) {
5297aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta            try {
5307aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta                return mService.getConnectedDevices();
5317aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta            } catch (RemoteException e) {
5327aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta                Log.e(TAG, Log.getStackTraceString(new Throwable()));
5337aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta                return new ArrayList<BluetoothDevice>();
5347aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta            }
5357aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        }
5367aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        if (mService == null) Log.w(TAG, "Proxy not attached to service");
5377aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        return new ArrayList<BluetoothDevice>();
5387aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    }
5397aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta
5407aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    /**
5417aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * Returns list of remote devices in a particular state
5427aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     *
5437aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * @param states    collection of states
5447aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * @return          list of devices that state matches the states listed in
5457aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     *                  <code>states</code>; empty list if nothing matches the
5467aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     *                  <code>states</code>
5477aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     */
5487aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    @Override
5497aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    public List<BluetoothDevice> getDevicesMatchingConnectionStates(int[] states) {
5507aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        if (VDBG) log("getDevicesMatchingStates()");
5517aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        if (mService != null && isEnabled()) {
5527aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta            try {
5537aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta                return mService.getDevicesMatchingConnectionStates(states);
5547aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta            } catch (RemoteException e) {
5557aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta                Log.e(TAG, Log.getStackTraceString(new Throwable()));
5567aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta                return new ArrayList<BluetoothDevice>();
5577aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta            }
5587aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        }
5597aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        if (mService == null) Log.w(TAG, "Proxy not attached to service");
5607aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        return new ArrayList<BluetoothDevice>();
5617aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    }
5627aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta
5637aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    /**
5647aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * Returns state of the <code>device</code>
5657aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     *
5667aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * @param device    a remote device
5677aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * @return          the state of connection of the device
5687aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     */
5697aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    @Override
5707aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    public int getConnectionState(BluetoothDevice device) {
5717aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        if (VDBG) log("getConnectionState(" + device + ")");
5727aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        if (mService != null && isEnabled() &&
5737aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta                isValidDevice(device)) {
5747aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta            try {
5757aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta                return mService.getConnectionState(device);
5767aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta            } catch (RemoteException e) {
5777aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta                Log.e(TAG, Log.getStackTraceString(new Throwable()));
5787aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta                return BluetoothProfile.STATE_DISCONNECTED;
5797aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta            }
5807aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        }
5817aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        if (mService == null) Log.w(TAG, "Proxy not attached to service");
5827aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        return BluetoothProfile.STATE_DISCONNECTED;
5837aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    }
5847aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta
5857aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    /**
5867aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * Set priority of the profile
5877aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     *
5887aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * The device should already be paired.
5897aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     */
5907aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    public boolean setPriority(BluetoothDevice device, int priority) {
5917aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        if (DBG) log("setPriority(" + device + ", " + priority + ")");
5927aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        if (mService != null && isEnabled() &&
5937aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta                isValidDevice(device)) {
5947aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta            if (priority != BluetoothProfile.PRIORITY_OFF &&
5957aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta                    priority != BluetoothProfile.PRIORITY_ON) {
5967aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta              return false;
5977aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta            }
5987aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta            try {
5997aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta                return mService.setPriority(device, priority);
6007aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta            } catch (RemoteException e) {
6017aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta                Log.e(TAG, Log.getStackTraceString(new Throwable()));
6027aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta                return false;
6037aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta            }
6047aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        }
6057aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        if (mService == null) Log.w(TAG, "Proxy not attached to service");
6067aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        return false;
6077aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    }
6087aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta
6097aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    /**
6107aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * Get the priority of the profile.
6117aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     */
6127aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    public int getPriority(BluetoothDevice device) {
6137aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        if (VDBG) log("getPriority(" + device + ")");
6147aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        if (mService != null && isEnabled() &&
6157aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta                isValidDevice(device)) {
6167aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta            try {
6177aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta                return mService.getPriority(device);
6187aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta            } catch (RemoteException e) {
6197aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta                Log.e(TAG, Log.getStackTraceString(new Throwable()));
6207aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta                return PRIORITY_OFF;
6217aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta            }
6227aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        }
6237aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        if (mService == null) Log.w(TAG, "Proxy not attached to service");
6247aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        return PRIORITY_OFF;
6257aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    }
6267aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta
6277aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    /**
6287aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * Starts voice recognition.
6297aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     *
6307aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * @param device    remote device
6317aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * @return          <code>true</code> if command has been issued successfully;
6327aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     *                   <code>false</code> otherwise;
6337aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     *                   upon completion HFP sends {@link #ACTION_AG_EVENT}
6347aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     *                   intent.
6357aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     *
6367aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * <p>Feature required for successful execution is being reported by:
6377aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * {@link #EXTRA_AG_FEATURE_VOICE_RECOGNITION}.
6387aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * This method invocation will fail silently when feature is not supported.</p>
6397aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     */
6407aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    public boolean startVoiceRecognition(BluetoothDevice device) {
6417aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        if (DBG) log("startVoiceRecognition()");
6427aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        if (mService != null && isEnabled() &&
6437aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta                isValidDevice(device)) {
6447aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta            try {
6457aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta                return mService.startVoiceRecognition(device);
6467aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta            } catch (RemoteException e) {
6477aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta                Log.e(TAG,  Log.getStackTraceString(new Throwable()));
6487aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta            }
6497aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        }
6507aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        if (mService == null) Log.w(TAG, "Proxy not attached to service");
6517aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        return false;
6527aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    }
6537aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta
6547aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    /**
6557aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * Stops voice recognition.
6567aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     *
6577aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * @param device    remote device
6587aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * @return          <code>true</code> if command has been issued successfully;
6597aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     *                   <code>false</code> otherwise;
6607aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     *                   upon completion HFP sends {@link #ACTION_AG_EVENT}
6617aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     *                   intent.
6627aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     *
6637aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * <p>Feature required for successful execution is being reported by:
6647aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * {@link #EXTRA_AG_FEATURE_VOICE_RECOGNITION}.
6657aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * This method invocation will fail silently when feature is not supported.</p>
6667aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     */
6677aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    public boolean stopVoiceRecognition(BluetoothDevice device) {
6687aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        if (DBG) log("stopVoiceRecognition()");
6697aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        if (mService != null && isEnabled() &&
6707aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta                isValidDevice(device)) {
6717aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta            try {
6727aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta                return mService.stopVoiceRecognition(device);
6737aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta            } catch (RemoteException e) {
6747aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta                Log.e(TAG,  Log.getStackTraceString(new Throwable()));
6757aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta            }
6767aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        }
6777aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        if (mService == null) Log.w(TAG, "Proxy not attached to service");
6787aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        return false;
6797aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    }
6807aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta
6817aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    /**
6827aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * Returns list of all calls in any state.
6837aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     *
6847aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * @param device    remote device
6857aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * @return          list of calls; empty list if none call exists
6867aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     */
687cf916d34671f0ab6aad8de24c18e4dc96fb21941Mike Lockwood    public List<BluetoothHeadsetClientCall> getCurrentCalls(BluetoothDevice device) {
6887aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        if (DBG) log("getCurrentCalls()");
6897aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        if (mService != null && isEnabled() &&
6907aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta                isValidDevice(device)) {
6917aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta            try {
6927aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta                return mService.getCurrentCalls(device);
6937aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta            } catch (RemoteException e) {
6947aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta                Log.e(TAG,  Log.getStackTraceString(new Throwable()));
6957aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta            }
6967aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        }
6977aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        if (mService == null) Log.w(TAG, "Proxy not attached to service");
6987aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        return null;
6997aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    }
7007aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta
7017aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    /**
7027aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * Returns list of current values of AG indicators.
7037aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     *
7047aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * @param device    remote device
7057aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * @return          bundle of AG  indicators; null if device is not in
7067aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     *                  CONNECTED state
7077aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     */
7087aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    public Bundle getCurrentAgEvents(BluetoothDevice device) {
7097aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        if (DBG) log("getCurrentCalls()");
7107aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        if (mService != null && isEnabled() &&
7117aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta                isValidDevice(device)) {
7127aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta            try {
7137aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta                return mService.getCurrentAgEvents(device);
7147aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta            } catch (RemoteException e) {
7157aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta                Log.e(TAG,  Log.getStackTraceString(new Throwable()));
7167aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta            }
7177aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        }
7187aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        if (mService == null) Log.w(TAG, "Proxy not attached to service");
7197aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        return null;
7207aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    }
7217aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta
7227aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    /**
7237aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * Accepts a call
7247aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     *
7257aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * @param device    remote device
7267aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * @param flag      action policy while accepting a call. Possible values
7277aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     *                   {@link #CALL_ACCEPT_NONE}, {@link #CALL_ACCEPT_HOLD},
7287aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     *                   {@link #CALL_ACCEPT_TERMINATE}
7297aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * @return          <code>true</code> if command has been issued successfully;
7307aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     *                   <code>false</code> otherwise;
7317aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     *                   upon completion HFP sends {@link #ACTION_CALL_CHANGED}
7327aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     *                   intent.
7337aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     */
7347aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    public boolean acceptCall(BluetoothDevice device, int flag) {
7357aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        if (DBG) log("acceptCall()");
7367aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        if (mService != null && isEnabled() &&
7377aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta                isValidDevice(device)) {
7387aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta            try {
7397aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta                return mService.acceptCall(device, flag);
7407aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta            } catch (RemoteException e) {
7417aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta                Log.e(TAG,  Log.getStackTraceString(new Throwable()));
7427aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta            }
7437aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        }
7447aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        if (mService == null) Log.w(TAG, "Proxy not attached to service");
7457aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        return false;
7467aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    }
7477aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta
7487aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    /**
7497aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * Holds a call.
7507aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     *
7517aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * @param device    remote device
7527aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * @return          <code>true</code> if command has been issued successfully;
7537aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     *                   <code>false</code> otherwise;
7547aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     *                   upon completion HFP sends {@link #ACTION_CALL_CHANGED}
7557aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     *                   intent.
7567aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     */
7577aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    public boolean holdCall(BluetoothDevice device) {
7587aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        if (DBG) log("holdCall()");
7597aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        if (mService != null && isEnabled() &&
7607aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta                isValidDevice(device)) {
7617aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta            try {
7627aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta                return mService.holdCall(device);
7637aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta            } catch (RemoteException e) {
7647aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta                Log.e(TAG,  Log.getStackTraceString(new Throwable()));
7657aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta            }
7667aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        }
7677aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        if (mService == null) Log.w(TAG, "Proxy not attached to service");
7687aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        return false;
7697aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    }
7707aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta
7717aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    /**
7727aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * Rejects a call.
7737aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     *
7747aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * @param device    remote device
7757aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * @return          <code>true</code> if command has been issued successfully;
7767aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     *                   <code>false</code> otherwise;
7777aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     *                   upon completion HFP sends {@link #ACTION_CALL_CHANGED}
7787aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     *                   intent.
7797aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     *
7807aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * <p>Feature required for successful execution is being reported by:
7817aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * {@link #EXTRA_AG_FEATURE_REJECT_CALL}.
7827aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * This method invocation will fail silently when feature is not supported.</p>
7837aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     */
7847aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    public boolean rejectCall(BluetoothDevice device) {
7857aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        if (DBG) log("rejectCall()");
7867aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        if (mService != null && isEnabled() &&
7877aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta                isValidDevice(device)) {
7887aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta            try {
7897aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta                return mService.rejectCall(device);
7907aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta            } catch (RemoteException e) {
7917aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta                Log.e(TAG,  Log.getStackTraceString(new Throwable()));
7927aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta            }
7937aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        }
7947aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        if (mService == null) Log.w(TAG, "Proxy not attached to service");
7957aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        return false;
7967aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    }
7977aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta
7987aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    /**
7997aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * Terminates a specified call.
8007aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     *
8017aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * Works only when Extended Call Control is supported by Audio Gateway.
8027aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     *
8037aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * @param device    remote device
80440bb6f3f8fc02600fe24301c11e804196ced3531Sanket Agarwal     * @param call      Handle of call obtained in {@link dial()} or obtained via
80540bb6f3f8fc02600fe24301c11e804196ced3531Sanket Agarwal     *                  {@link ACTION_CALL_CHANGED}. {@code call} may be null in which
80640bb6f3f8fc02600fe24301c11e804196ced3531Sanket Agarwal     *                  case we will hangup all active calls.
8077aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * @return          <code>true</code> if command has been issued successfully;
8087aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     *                   <code>false</code> otherwise;
8097aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     *                   upon completion HFP sends {@link #ACTION_CALL_CHANGED}
8107aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     *                   intent.
8117aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     *
8127aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * <p>Feature required for successful execution is being reported by:
8137aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * {@link #EXTRA_AG_FEATURE_ECC}.
8147aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * This method invocation will fail silently when feature is not supported.</p>
8157aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     */
81640bb6f3f8fc02600fe24301c11e804196ced3531Sanket Agarwal    public boolean terminateCall(BluetoothDevice device, BluetoothHeadsetClientCall call) {
8177aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        if (DBG) log("terminateCall()");
8187aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        if (mService != null && isEnabled() &&
8197aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta                isValidDevice(device)) {
8207aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta            try {
82140bb6f3f8fc02600fe24301c11e804196ced3531Sanket Agarwal                return mService.terminateCall(device, call);
8227aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta            } catch (RemoteException e) {
8237aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta                Log.e(TAG,  Log.getStackTraceString(new Throwable()));
8247aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta            }
8257aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        }
8267aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        if (mService == null) Log.w(TAG, "Proxy not attached to service");
8277aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        return false;
8287aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    }
8297aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta
8307aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    /**
8317aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * Enters private mode with a specified call.
8327aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     *
8337aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * Works only when Extended Call Control is supported by Audio Gateway.
8347aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     *
8357aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * @param device    remote device
8367aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * @param index     index of the call to connect in private mode
8377aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * @return          <code>true</code> if command has been issued successfully;
8387aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     *                   <code>false</code> otherwise;
8397aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     *                   upon completion HFP sends {@link #ACTION_CALL_CHANGED}
8407aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     *                   intent.
8417aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     *
8427aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * <p>Feature required for successful execution is being reported by:
8437aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * {@link #EXTRA_AG_FEATURE_ECC}.
8447aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * This method invocation will fail silently when feature is not supported.</p>
8457aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     */
8467aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    public boolean enterPrivateMode(BluetoothDevice device, int index) {
8477aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        if (DBG) log("enterPrivateMode()");
8487aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        if (mService != null && isEnabled() &&
8497aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta                isValidDevice(device)) {
8507aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta            try {
8517aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta                return mService.enterPrivateMode(device, index);
8527aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta            } catch (RemoteException e) {
8537aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta                Log.e(TAG,  Log.getStackTraceString(new Throwable()));
8547aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta            }
8557aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        }
8567aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        if (mService == null) Log.w(TAG, "Proxy not attached to service");
8577aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        return false;
8587aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    }
8597aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta
8607aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    /**
8617aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * Performs explicit call transfer.
8627aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     *
8637aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * That means connect other calls and disconnect.
8647aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     *
8657aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * @param device    remote device
8667aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * @return          <code>true</code> if command has been issued successfully;
8677aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     *                   <code>false</code> otherwise;
8687aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     *                   upon completion HFP sends {@link #ACTION_CALL_CHANGED}
8697aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     *                   intent.
8707aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     *
8717aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * <p>Feature required for successful execution is being reported by:
8727aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * {@link #EXTRA_AG_FEATURE_MERGE_AND_DETACH}.
8737aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * This method invocation will fail silently when feature is not supported.</p>
8747aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     */
8757aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    public boolean explicitCallTransfer(BluetoothDevice device) {
8767aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        if (DBG) log("explicitCallTransfer()");
8777aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        if (mService != null && isEnabled() &&
8787aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta                isValidDevice(device)) {
8797aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta            try {
8807aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta                return mService.explicitCallTransfer(device);
8817aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta            } catch (RemoteException e) {
8827aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta                Log.e(TAG,  Log.getStackTraceString(new Throwable()));
8837aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta            }
8847aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        }
8857aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        if (mService == null) Log.w(TAG, "Proxy not attached to service");
8867aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        return false;
8877aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    }
8887aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta
8897aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    /**
8907aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * Places a call with specified number.
8917aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     *
8927aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * @param device    remote device
8937aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * @param number    valid phone number
89440bb6f3f8fc02600fe24301c11e804196ced3531Sanket Agarwal     * @return          <code>{@link BluetoothHeadsetClientCall} call</code> if command has been
89540bb6f3f8fc02600fe24301c11e804196ced3531Sanket Agarwal     *                  issued successfully;
89640bb6f3f8fc02600fe24301c11e804196ced3531Sanket Agarwal     *                  <code>{@link null}</code> otherwise;
89740bb6f3f8fc02600fe24301c11e804196ced3531Sanket Agarwal     *                  upon completion HFP sends {@link #ACTION_CALL_CHANGED}
89840bb6f3f8fc02600fe24301c11e804196ced3531Sanket Agarwal     *                  intent in case of success; {@link #ACTION_RESULT} is sent
89940bb6f3f8fc02600fe24301c11e804196ced3531Sanket Agarwal     *                  otherwise;
90040bb6f3f8fc02600fe24301c11e804196ced3531Sanket Agarwal     */
90140bb6f3f8fc02600fe24301c11e804196ced3531Sanket Agarwal    public BluetoothHeadsetClientCall dial(BluetoothDevice device, String number) {
9027aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        if (DBG) log("dial()");
9037aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        if (mService != null && isEnabled() &&
9047aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta                isValidDevice(device)) {
9057aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta            try {
9067aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta                return mService.dial(device, number);
9077aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta            } catch (RemoteException e) {
9087aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta                Log.e(TAG,  Log.getStackTraceString(new Throwable()));
9097aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta            }
9107aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        }
9117aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        if (mService == null) Log.w(TAG, "Proxy not attached to service");
91240bb6f3f8fc02600fe24301c11e804196ced3531Sanket Agarwal        return null;
9137aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    }
9147aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta
9157aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    /**
9167aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * Sends DTMF code.
9177aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     *
9187aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * Possible code values : 0,1,2,3,4,5,6,7,8,9,A,B,C,D,*,#
9197aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     *
9207aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * @param device    remote device
9217aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * @param code  ASCII code
9227aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * @return          <code>true</code> if command has been issued successfully;
9237aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     *                   <code>false</code> otherwise;
9247aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     *                   upon completion HFP sends {@link #ACTION_RESULT} intent;
9257aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     */
9267aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    public boolean sendDTMF(BluetoothDevice device, byte code) {
9277aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        if (DBG) log("sendDTMF()");
9287aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        if (mService != null && isEnabled() &&
9297aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta                isValidDevice(device)) {
9307aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta            try {
9317aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta                return mService.sendDTMF(device, code);
9327aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta            } catch (RemoteException e) {
9337aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta                Log.e(TAG,  Log.getStackTraceString(new Throwable()));
9347aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta            }
9357aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        }
9367aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        if (mService == null) Log.w(TAG, "Proxy not attached to service");
9377aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        return false;
9387aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    }
9397aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta
9407aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    /**
9417aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * Get a number corresponding to last voice tag recorded on AG.
9427aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     *
9437aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * @param device    remote device
9447aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * @return          <code>true</code> if command has been issued successfully;
9457aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     *                   <code>false</code> otherwise;
9467aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     *                   upon completion HFP sends {@link #ACTION_LAST_VTAG}
9477aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     *                   or {@link #ACTION_RESULT} intent;
9487aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     *
9497aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * <p>Feature required for successful execution is being reported by:
9507aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * {@link #EXTRA_AG_FEATURE_ATTACH_NUMBER_TO_VT}.
9517aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * This method invocation will fail silently when feature is not supported.</p>
9527aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     */
9537aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    public boolean getLastVoiceTagNumber(BluetoothDevice device) {
9547aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        if (DBG) log("getLastVoiceTagNumber()");
9557aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        if (mService != null && isEnabled() &&
9567aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta                isValidDevice(device)) {
9577aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta            try {
9587aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta                return mService.getLastVoiceTagNumber(device);
9597aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta            } catch (RemoteException e) {
9607aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta                Log.e(TAG,  Log.getStackTraceString(new Throwable()));
9617aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta            }
9627aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        }
9637aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        if (mService == null) Log.w(TAG, "Proxy not attached to service");
9647aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        return false;
9657aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    }
9667aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta
9677aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    /**
9687aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * Returns current audio state of Audio Gateway.
9697aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     *
9707aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * Note: This is an internal function and shouldn't be exposed
9717aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     */
9727aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    public int getAudioState(BluetoothDevice device) {
9737aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        if (VDBG) log("getAudioState");
9747aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        if (mService != null && isEnabled()) {
9757aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta            try {
9767aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta                return mService.getAudioState(device);
9777aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta            } catch (RemoteException e) {Log.e(TAG, e.toString());}
9787aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        } else {
9797aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta            Log.w(TAG, "Proxy not attached to service");
9807aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta            if (DBG) Log.d(TAG, Log.getStackTraceString(new Throwable()));
9817aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        }
982cf916d34671f0ab6aad8de24c18e4dc96fb21941Mike Lockwood        return BluetoothHeadsetClient.STATE_AUDIO_DISCONNECTED;
9837aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    }
9847aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta
9857aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    /**
986dc133826225ea61c71f4a2131956e48ed2b0611aBryce Lee     * Sets whether audio routing is allowed.
987dc133826225ea61c71f4a2131956e48ed2b0611aBryce Lee     *
988039eeb81b5ceb5a7141ae852346e054348ac2a06Sanket Agarwal     * @param device    remote device
989039eeb81b5ceb5a7141ae852346e054348ac2a06Sanket Agarwal     * @param allowed   if routing is allowed to the device
990dc133826225ea61c71f4a2131956e48ed2b0611aBryce Lee     * Note: This is an internal function and shouldn't be exposed
991dc133826225ea61c71f4a2131956e48ed2b0611aBryce Lee     */
992039eeb81b5ceb5a7141ae852346e054348ac2a06Sanket Agarwal    public void setAudioRouteAllowed(BluetoothDevice device, boolean allowed) {
993dc133826225ea61c71f4a2131956e48ed2b0611aBryce Lee        if (VDBG) log("setAudioRouteAllowed");
994dc133826225ea61c71f4a2131956e48ed2b0611aBryce Lee        if (mService != null && isEnabled()) {
995dc133826225ea61c71f4a2131956e48ed2b0611aBryce Lee            try {
996039eeb81b5ceb5a7141ae852346e054348ac2a06Sanket Agarwal                mService.setAudioRouteAllowed(device, allowed);
997dc133826225ea61c71f4a2131956e48ed2b0611aBryce Lee            } catch (RemoteException e) {Log.e(TAG, e.toString());}
998dc133826225ea61c71f4a2131956e48ed2b0611aBryce Lee        } else {
999dc133826225ea61c71f4a2131956e48ed2b0611aBryce Lee            Log.w(TAG, "Proxy not attached to service");
1000dc133826225ea61c71f4a2131956e48ed2b0611aBryce Lee            if (DBG) Log.d(TAG, Log.getStackTraceString(new Throwable()));
1001dc133826225ea61c71f4a2131956e48ed2b0611aBryce Lee        }
1002dc133826225ea61c71f4a2131956e48ed2b0611aBryce Lee    }
1003dc133826225ea61c71f4a2131956e48ed2b0611aBryce Lee
1004dc133826225ea61c71f4a2131956e48ed2b0611aBryce Lee    /**
1005dc133826225ea61c71f4a2131956e48ed2b0611aBryce Lee     * Returns whether audio routing is allowed.
1006039eeb81b5ceb5a7141ae852346e054348ac2a06Sanket Agarwal     * @param device    remote device
1007039eeb81b5ceb5a7141ae852346e054348ac2a06Sanket Agarwal     * @return whether the command succeeded
1008dc133826225ea61c71f4a2131956e48ed2b0611aBryce Lee     * Note: This is an internal function and shouldn't be exposed
1009dc133826225ea61c71f4a2131956e48ed2b0611aBryce Lee     */
1010039eeb81b5ceb5a7141ae852346e054348ac2a06Sanket Agarwal    public boolean getAudioRouteAllowed(BluetoothDevice device) {
1011dc133826225ea61c71f4a2131956e48ed2b0611aBryce Lee        if (VDBG) log("getAudioRouteAllowed");
1012dc133826225ea61c71f4a2131956e48ed2b0611aBryce Lee        if (mService != null && isEnabled()) {
1013dc133826225ea61c71f4a2131956e48ed2b0611aBryce Lee            try {
1014039eeb81b5ceb5a7141ae852346e054348ac2a06Sanket Agarwal                return mService.getAudioRouteAllowed(device);
1015dc133826225ea61c71f4a2131956e48ed2b0611aBryce Lee            } catch (RemoteException e) {Log.e(TAG, e.toString());}
1016dc133826225ea61c71f4a2131956e48ed2b0611aBryce Lee        } else {
1017dc133826225ea61c71f4a2131956e48ed2b0611aBryce Lee            Log.w(TAG, "Proxy not attached to service");
1018dc133826225ea61c71f4a2131956e48ed2b0611aBryce Lee            if (DBG) Log.d(TAG, Log.getStackTraceString(new Throwable()));
1019dc133826225ea61c71f4a2131956e48ed2b0611aBryce Lee        }
1020dc133826225ea61c71f4a2131956e48ed2b0611aBryce Lee        return false;
1021dc133826225ea61c71f4a2131956e48ed2b0611aBryce Lee    }
1022dc133826225ea61c71f4a2131956e48ed2b0611aBryce Lee
1023dc133826225ea61c71f4a2131956e48ed2b0611aBryce Lee    /**
10247aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * Initiates a connection of audio channel.
10257aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     *
10267aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * It setup SCO channel with remote connected Handsfree AG device.
10277aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     *
1028039eeb81b5ceb5a7141ae852346e054348ac2a06Sanket Agarwal     * @param device    remote device
10297aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * @return          <code>true</code> if command has been issued successfully;
10307aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     *                   <code>false</code> otherwise;
10317aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     *                   upon completion HFP sends {@link #ACTION_AUDIO_STATE_CHANGED}
10327aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     *                   intent;
10337aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     */
1034039eeb81b5ceb5a7141ae852346e054348ac2a06Sanket Agarwal    public boolean connectAudio(BluetoothDevice device) {
10357aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        if (mService != null && isEnabled()) {
10367aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta            try {
1037039eeb81b5ceb5a7141ae852346e054348ac2a06Sanket Agarwal                return mService.connectAudio(device);
10387aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta            } catch (RemoteException e) {
10397aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta                Log.e(TAG, e.toString());
10407aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta            }
10417aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        } else {
10427aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta            Log.w(TAG, "Proxy not attached to service");
10437aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta            if (DBG) Log.d(TAG, Log.getStackTraceString(new Throwable()));
10447aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        }
10457aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        return false;
10467aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    }
10477aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta
10487aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    /**
10497aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * Disconnects audio channel.
10507aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     *
10517aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * It tears down the SCO channel from remote AG device.
10527aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     *
1053039eeb81b5ceb5a7141ae852346e054348ac2a06Sanket Agarwal     * @param   device  remote device
10547aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * @return          <code>true</code> if command has been issued successfully;
10557aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     *                   <code>false</code> otherwise;
10567aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     *                   upon completion HFP sends {@link #ACTION_AUDIO_STATE_CHANGED}
10577aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     *                   intent;
10587aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     */
1059039eeb81b5ceb5a7141ae852346e054348ac2a06Sanket Agarwal    public boolean disconnectAudio(BluetoothDevice device) {
10607aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        if (mService != null && isEnabled()) {
10617aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta            try {
1062039eeb81b5ceb5a7141ae852346e054348ac2a06Sanket Agarwal                return mService.disconnectAudio(device);
10637aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta            } catch (RemoteException e) {
10647aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta                Log.e(TAG, e.toString());
10657aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta            }
10667aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        } else {
10677aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta            Log.w(TAG, "Proxy not attached to service");
10687aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta            if (DBG) Log.d(TAG, Log.getStackTraceString(new Throwable()));
10697aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        }
10707aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        return false;
10717aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    }
10727aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta
10737aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    /**
10747aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * Get Audio Gateway features
10757aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     *
10767aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * @param device    remote device
10777aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     * @return          bundle of AG features; null if no service or
10787aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     *                  AG not connected
10797aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta     */
10807aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    public Bundle getCurrentAgFeatures(BluetoothDevice device) {
10817aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        if (mService != null && isEnabled()) {
10827aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta            try {
10837aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta                return mService.getCurrentAgFeatures(device);
10847aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta            } catch (RemoteException e) {
10857aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta                Log.e(TAG, e.toString());
10867aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta            }
10877aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        } else {
10887aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta            Log.w(TAG, "Proxy not attached to service");
10897aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta            if (DBG) Log.d(TAG, Log.getStackTraceString(new Throwable()));
10907aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        }
10917aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        return null;
10927aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    }
10937aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta
10947aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta
10957aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    private ServiceConnection mConnection = new ServiceConnection() {
10967aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        @Override
10977aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        public void onServiceConnected(ComponentName className, IBinder service) {
10987aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta            if (DBG) Log.d(TAG, "Proxy object connected");
10990a17db1cc5942ea000ca87bb72853de57a15ec64Jeff Sharkey            mService = IBluetoothHeadsetClient.Stub.asInterface(Binder.allowBlocking(service));
11007aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta
11017aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta            if (mServiceListener != null) {
1102cf916d34671f0ab6aad8de24c18e4dc96fb21941Mike Lockwood                mServiceListener.onServiceConnected(BluetoothProfile.HEADSET_CLIENT,
1103cf916d34671f0ab6aad8de24c18e4dc96fb21941Mike Lockwood                        BluetoothHeadsetClient.this);
11047aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta            }
11057aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        }
11067aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        @Override
11077aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        public void onServiceDisconnected(ComponentName className) {
11087aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta            if (DBG) Log.d(TAG, "Proxy object disconnected");
11097aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta            mService = null;
11107aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta            if (mServiceListener != null) {
1111cf916d34671f0ab6aad8de24c18e4dc96fb21941Mike Lockwood                mServiceListener.onServiceDisconnected(BluetoothProfile.HEADSET_CLIENT);
11127aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta            }
11137aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        }
11147aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    };
11157aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta
11167aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    private boolean isEnabled() {
11177aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta       if (mAdapter.getState() == BluetoothAdapter.STATE_ON) return true;
11187aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta       return false;
11197aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    }
11207aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta
11217aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    private boolean isValidDevice(BluetoothDevice device) {
11227aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta       if (device == null) return false;
11237aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta
11247aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta       if (BluetoothAdapter.checkBluetoothAddress(device.getAddress())) return true;
11257aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta       return false;
11267aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    }
11277aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta
11287aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    private static void log(String msg) {
11297aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta        Log.d(TAG, msg);
11307aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta    }
11317aca90fcc0175ab44613bb3e4f3f13fc4a688fa5Hemant Gupta}
1132