FileDocCategorySizeDatePackage
BluetoothHeadsetClient.javaAPI DocAndroid 5.1 API46519Thu Mar 12 22:22:10 GMT 2015android.bluetooth

BluetoothHeadsetClient

public final class BluetoothHeadsetClient extends Object implements BluetoothProfile
Public API to control Hands Free Profile (HFP role only).

This class defines methods that shall be used by application to manage profile connection, calls states and calls actions.

hide

Fields Summary
private static final String
TAG
private static final boolean
DBG
private static final boolean
VDBG
public static final String
ACTION_CONNECTION_STATE_CHANGED
Intent sent whenever connection to remote changes.

It includes two extras: BluetoothProfile.EXTRA_PREVIOUS_STATE and BluetoothProfile.EXTRA_STATE, which are mandatory.

There are also non mandatory feature extras: {@link #EXTRA_AG_FEATURE_3WAY_CALLING}, {@link #EXTRA_AG_FEATURE_VOICE_RECOGNITION}, {@link #EXTRA_AG_FEATURE_ATTACH_NUMBER_TO_VT}, {@link #EXTRA_AG_FEATURE_REJECT_CALL}, {@link #EXTRA_AG_FEATURE_ECC}, {@link #EXTRA_AG_FEATURE_RESPONSE_AND_HOLD}, {@link #EXTRA_AG_FEATURE_ACCEPT_HELD_OR_WAITING_CALL}, {@link #EXTRA_AG_FEATURE_RELEASE_HELD_OR_WAITING_CALL}, {@link #EXTRA_AG_FEATURE_RELEASE_AND_ACCEPT}, {@link #EXTRA_AG_FEATURE_MERGE}, {@link #EXTRA_AG_FEATURE_MERGE_AND_DETACH}, sent as boolean values only when EXTRA_STATE is set to STATE_CONNECTED.

Note that features supported by AG are being sent as booleans with value true, and not supported ones are not being sent at all.

public static final String
ACTION_AUDIO_STATE_CHANGED
Intent sent whenever audio state changes.

It includes two mandatory extras: {@link BluetoothProfile.EXTRA_STATE}, {@link BluetoothProfile.EXTRA_PREVIOUS_STATE}, with possible values: {@link #STATE_AUDIO_CONNECTING}, {@link #STATE_AUDIO_CONNECTED}, {@link #STATE_AUDIO_DISCONNECTED}

When EXTRA_STATE is set to STATE_AUDIO_CONNECTED, it also includes {@link #EXTRA_AUDIO_WBS} indicating wide band speech support.

public static final String
ACTION_AG_EVENT
Intent sending updates of the Audio Gateway state. Each extra is being sent only when value it represents has been changed recently on AG.

It can contain one or more of the following extras: {@link #EXTRA_NETWORK_STATUS}, {@link #EXTRA_NETWORK_SIGNAL_STRENGTH}, {@link #EXTRA_NETWORK_ROAMING}, {@link #EXTRA_BATTERY_LEVEL}, {@link #EXTRA_OPERATOR_NAME}, {@link #EXTRA_VOICE_RECOGNITION}, {@link #EXTRA_IN_BAND_RING}

public static final String
ACTION_CALL_CHANGED
Intent sent whenever state of a call changes.

It includes: {@link #EXTRA_CALL}, with value of {@link BluetoothHeadsetClientCall} instance, representing actual call state.

public static final String
ACTION_RESULT
Intent that notifies about the result of the last issued action. Please note that not every action results in explicit action result code being sent. Instead other notifications about new Audio Gateway state might be sent, like ACTION_AG_EVENT with EXTRA_VOICE_RECOGNITION value when for example user started voice recognition from HF unit.
public static final String
ACTION_LAST_VTAG
Intent that notifies about the number attached to the last voice tag recorded on AG.

It contains: {@link #EXTRA_NUMBER}, with a String value representing phone number.

public static final int
STATE_AUDIO_DISCONNECTED
public static final int
STATE_AUDIO_CONNECTING
public static final int
STATE_AUDIO_CONNECTED
public static final String
EXTRA_AUDIO_WBS
Extra with information if connected audio is WBS.

Possible values: true, false.

public static final String
EXTRA_NETWORK_STATUS
Extra for AG_EVENT indicates network status.

Value: 0 - network unavailable, 1 - network available

public static final String
EXTRA_NETWORK_SIGNAL_STRENGTH
Extra for AG_EVENT intent indicates network signal strength.

Value: Integer representing signal strength.

public static final String
EXTRA_NETWORK_ROAMING
Extra for AG_EVENT intent indicates roaming state.

Value: 0 - no roaming 1 - active roaming

public static final String
EXTRA_BATTERY_LEVEL
Extra for AG_EVENT intent indicates the battery level.

Value: Integer representing signal strength.

public static final String
EXTRA_OPERATOR_NAME
Extra for AG_EVENT intent indicates operator name.

Value: String representing operator name.

public static final String
EXTRA_VOICE_RECOGNITION
Extra for AG_EVENT intent indicates voice recognition state.

Value: 0 - voice recognition stopped, 1 - voice recognition started.

public static final String
EXTRA_IN_BAND_RING
Extra for AG_EVENT intent indicates in band ring state.

Value: 0 - in band ring tone not supported, or 1 - in band ring tone supported.

public static final String
EXTRA_SUBSCRIBER_INFO
Extra for AG_EVENT intent indicates subscriber info.

Value: String containing subscriber information.

public static final String
EXTRA_CALL
Extra for AG_CALL_CHANGED intent indicates the {@link BluetoothHeadsetClientCall} object that has changed.
public static final String
EXTRA_NUMBER
Extra for ACTION_LAST_VTAG intent.

Value: String representing phone number corresponding to last voice tag recorded on AG

public static final String
EXTRA_RESULT_CODE
Extra for ACTION_RESULT intent that shows the result code of last issued action.

Possible results: {@link #ACTION_RESULT_OK}, {@link #ACTION_RESULT_ERROR}, {@link #ACTION_RESULT_ERROR_NO_CARRIER}, {@link #ACTION_RESULT_ERROR_BUSY}, {@link #ACTION_RESULT_ERROR_NO_ANSWER}, {@link #ACTION_RESULT_ERROR_DELAYED}, {@link #ACTION_RESULT_ERROR_BLACKLISTED}, {@link #ACTION_RESULT_ERROR_CME}

public static final String
EXTRA_CME_CODE
Extra for ACTION_RESULT intent that shows the extended result code of last issued action.

Value: Integer - error code.

public static final String
EXTRA_AG_FEATURE_3WAY_CALLING
AG feature: three way calling.
public static final String
EXTRA_AG_FEATURE_VOICE_RECOGNITION
AG feature: voice recognition.
public static final String
EXTRA_AG_FEATURE_ATTACH_NUMBER_TO_VT
AG feature: fetching phone number for voice tagging procedure.
public static final String
EXTRA_AG_FEATURE_REJECT_CALL
AG feature: ability to reject incoming call.
public static final String
EXTRA_AG_FEATURE_ECC
AG feature: enhanced call handling (terminate specific call, private consultation).
public static final String
EXTRA_AG_FEATURE_RESPONSE_AND_HOLD
AG feature: response and hold.
public static final String
EXTRA_AG_FEATURE_ACCEPT_HELD_OR_WAITING_CALL
AG call handling feature: accept held or waiting call in three way calling scenarios.
public static final String
EXTRA_AG_FEATURE_RELEASE_HELD_OR_WAITING_CALL
AG call handling feature: release held or waiting call in three way calling scenarios.
public static final String
EXTRA_AG_FEATURE_RELEASE_AND_ACCEPT
AG call handling feature: release active call and accept held or waiting call in three way calling scenarios.
public static final String
EXTRA_AG_FEATURE_MERGE
AG call handling feature: merge two calls, held and active - multi party conference mode.
public static final String
EXTRA_AG_FEATURE_MERGE_AND_DETACH
AG call handling feature: merge calls and disconnect from multi party conversation leaving peers connected to each other. Note that this feature needs to be supported by mobile network operator as it requires connection and billing transfer.
public static final int
ACTION_RESULT_OK
public static final int
ACTION_RESULT_ERROR
public static final int
ACTION_RESULT_ERROR_NO_CARRIER
public static final int
ACTION_RESULT_ERROR_BUSY
public static final int
ACTION_RESULT_ERROR_NO_ANSWER
public static final int
ACTION_RESULT_ERROR_DELAYED
public static final int
ACTION_RESULT_ERROR_BLACKLISTED
public static final int
ACTION_RESULT_ERROR_CME
public static final int
CME_PHONE_FAILURE
public static final int
CME_NO_CONNECTION_TO_PHONE
public static final int
CME_OPERATION_NOT_ALLOWED
public static final int
CME_OPERATION_NOT_SUPPORTED
public static final int
CME_PHSIM_PIN_REQUIRED
public static final int
CME_PHFSIM_PIN_REQUIRED
public static final int
CME_PHFSIM_PUK_REQUIRED
public static final int
CME_SIM_NOT_INSERTED
public static final int
CME_SIM_PIN_REQUIRED
public static final int
CME_SIM_PUK_REQUIRED
public static final int
CME_SIM_FAILURE
public static final int
CME_SIM_BUSY
public static final int
CME_SIM_WRONG
public static final int
CME_INCORRECT_PASSWORD
public static final int
CME_SIM_PIN2_REQUIRED
public static final int
CME_SIM_PUK2_REQUIRED
public static final int
CME_MEMORY_FULL
public static final int
CME_INVALID_INDEX
public static final int
CME_NOT_FOUND
public static final int
CME_MEMORY_FAILURE
public static final int
CME_TEXT_STRING_TOO_LONG
public static final int
CME_INVALID_CHARACTER_IN_TEXT_STRING
public static final int
CME_DIAL_STRING_TOO_LONG
public static final int
CME_INVALID_CHARACTER_IN_DIAL_STRING
public static final int
CME_NO_NETWORK_SERVICE
public static final int
CME_NETWORK_TIMEOUT
public static final int
CME_EMERGENCY_SERVICE_ONLY
public static final int
CME_NO_SIMULTANOUS_VOIP_CS_CALLS
public static final int
CME_NOT_SUPPORTED_FOR_VOIP
public static final int
CME_SIP_RESPONSE_CODE
public static final int
CME_NETWORK_PERSONALIZATION_PIN_REQUIRED
public static final int
CME_NETWORK_PERSONALIZATION_PUK_REQUIRED
public static final int
CME_NETWORK_SUBSET_PERSONALIZATION_PIN_REQUIRED
public static final int
CME_NETWORK_SUBSET_PERSONALIZATION_PUK_REQUIRED
public static final int
CME_SERVICE_PROVIDER_PERSONALIZATION_PIN_REQUIRED
public static final int
CME_SERVICE_PROVIDER_PERSONALIZATION_PUK_REQUIRED
public static final int
CME_CORPORATE_PERSONALIZATION_PIN_REQUIRED
public static final int
CME_CORPORATE_PERSONALIZATION_PUK_REQUIRED
public static final int
CME_HIDDEN_KEY_REQUIRED
public static final int
CME_EAP_NOT_SUPPORTED
public static final int
CME_INCORRECT_PARAMETERS
public static final int
CALL_ACCEPT_NONE
public static final int
CALL_ACCEPT_HOLD
public static final int
CALL_ACCEPT_TERMINATE
private android.content.Context
mContext
private ServiceListener
mServiceListener
private IBluetoothHeadsetClient
mService
private BluetoothAdapter
mAdapter
private final IBluetoothStateChangeCallback
mBluetoothStateChangeCallback
private android.content.ServiceConnection
mConnection
Constructors Summary
BluetoothHeadsetClient(android.content.Context context, ServiceListener l)
Create a BluetoothHeadsetClient proxy object.


              
    /*package*/     
        mContext = context;
        mServiceListener = l;
        mAdapter = BluetoothAdapter.getDefaultAdapter();

        IBluetoothManager mgr = mAdapter.getBluetoothManager();
        if (mgr != null) {
            try {
                mgr.registerStateChangeCallback(mBluetoothStateChangeCallback);
            } catch (RemoteException e) {
                Log.e(TAG,"",e);
            }
        }

        doBind();
    
Methods Summary
public booleanacceptCall(BluetoothDevice device, int flag)
Accepts a call

param
device remote device
param
flag action policy while accepting a call. Possible values {@link #CALL_ACCEPT_NONE}, {@link #CALL_ACCEPT_HOLD}, {@link #CALL_ACCEPT_TERMINATE}
return
true if command has been issued successfully; false otherwise; upon completion HFP sends {@link #ACTION_CALL_CHANGED} intent.

        if (DBG) log("acceptCall()");
        if (mService != null && isEnabled() &&
                isValidDevice(device)) {
            try {
                return mService.acceptCall(device, flag);
            } catch (RemoteException e) {
                Log.e(TAG,  Log.getStackTraceString(new Throwable()));
            }
        }
        if (mService == null) Log.w(TAG, "Proxy not attached to service");
        return false;
    
public booleanacceptIncomingConnect(BluetoothDevice device)
Accept the incoming connection.

        if (DBG) log("acceptIncomingConnect");
        if (mService != null && isEnabled()) {
            try {
                return mService.acceptIncomingConnect(device);
            } catch (RemoteException e) {Log.e(TAG, e.toString());}
        } else {
            Log.w(TAG, "Proxy not attached to service");
            if (DBG) Log.d(TAG, Log.getStackTraceString(new Throwable()));
        }
        return false;
    
voidclose()
Close the connection to the backing service. Other public functions of BluetoothHeadsetClient will return default error results once close() has been called. Multiple invocations of close() are ok.

        if (VDBG) log("close()");

        IBluetoothManager mgr = mAdapter.getBluetoothManager();
        if (mgr != null) {
            try {
                mgr.unregisterStateChangeCallback(mBluetoothStateChangeCallback);
            } catch (Exception e) {
                Log.e(TAG,"",e);
            }
        }

        synchronized (mConnection) {
            if (mService != null) {
                try {
                    mService = null;
                    mContext.unbindService(mConnection);
                } catch (Exception re) {
                    Log.e(TAG,"",re);
                }
            }
        }
        mServiceListener = null;
    
public booleanconnect(BluetoothDevice device)
Connects to remote device. Currently, the system supports only 1 connection. So, in case of the second connection, this implementation will disconnect already connected device automatically and will process the new one.

param
device a remote device we want connect to
return
true if command has been issued successfully; false otherwise; upon completion HFP sends {@link #ACTION_CONNECTION_STATE_CHANGED} intent.

        if (DBG) log("connect(" + device + ")");
        if (mService != null && isEnabled() &&
                isValidDevice(device)) {
            try {
                return mService.connect(device);
            } catch (RemoteException e) {
                Log.e(TAG, Log.getStackTraceString(new Throwable()));
                return false;
            }
        }
        if (mService == null) Log.w(TAG, "Proxy not attached to service");
        return false;
    
public booleanconnectAudio()
Initiates a connection of audio channel. It setup SCO channel with remote connected Handsfree AG device.

return
true if command has been issued successfully; false otherwise; upon completion HFP sends {@link #ACTION_AUDIO_STATE_CHANGED} intent;

        if (mService != null && isEnabled()) {
            try {
                return mService.connectAudio();
            } catch (RemoteException e) {
                Log.e(TAG, e.toString());
            }
        } else {
            Log.w(TAG, "Proxy not attached to service");
            if (DBG) Log.d(TAG, Log.getStackTraceString(new Throwable()));
        }
        return false;
    
public booleandial(BluetoothDevice device, java.lang.String number)
Places a call with specified number.

param
device remote device
param
number valid phone number
return
true if command has been issued successfully; false otherwise; upon completion HFP sends {@link #ACTION_CALL_CHANGED} intent in case of success; {@link #ACTION_RESULT} is sent otherwise;

        if (DBG) log("dial()");
        if (mService != null && isEnabled() &&
                isValidDevice(device)) {
            try {
                return mService.dial(device, number);
            } catch (RemoteException e) {
                Log.e(TAG,  Log.getStackTraceString(new Throwable()));
            }
        }
        if (mService == null) Log.w(TAG, "Proxy not attached to service");
        return false;
    
public booleandialMemory(BluetoothDevice device, int location)
Places a call to the number under specified memory location.

param
device remote device
param
location valid memory location
return
true if command has been issued successfully; false otherwise; upon completion HFP sends {@link #ACTION_CALL_CHANGED} intent in case of success; {@link #ACTION_RESULT} is sent otherwise;

        if (DBG) log("dialMemory()");
        if (mService != null && isEnabled() &&
                isValidDevice(device)) {
            try {
                return mService.dialMemory(device, location);
            } catch (RemoteException e) {
                Log.e(TAG,  Log.getStackTraceString(new Throwable()));
            }
        }
        if (mService == null) Log.w(TAG, "Proxy not attached to service");
        return false;
    
public booleandisconnect(BluetoothDevice device)
Disconnects remote device

param
device a remote device we want disconnect
return
true if command has been issued successfully; false otherwise; upon completion HFP sends {@link #ACTION_CONNECTION_STATE_CHANGED} intent.

        if (DBG) log("disconnect(" + device + ")");
        if (mService != null && isEnabled() &&
                isValidDevice(device)) {
            try {
                return mService.disconnect(device);
            } catch (RemoteException e) {
              Log.e(TAG, Log.getStackTraceString(new Throwable()));
              return false;
            }
        }
        if (mService == null) Log.w(TAG, "Proxy not attached to service");
        return false;
    
public booleandisconnectAudio()
Disconnects audio channel. It tears down the SCO channel from remote AG device.

return
true if command has been issued successfully; false otherwise; upon completion HFP sends {@link #ACTION_AUDIO_STATE_CHANGED} intent;

        if (mService != null && isEnabled()) {
            try {
                return mService.disconnectAudio();
            } catch (RemoteException e) {
                Log.e(TAG, e.toString());
            }
        } else {
            Log.w(TAG, "Proxy not attached to service");
            if (DBG) Log.d(TAG, Log.getStackTraceString(new Throwable()));
        }
        return false;
    
booleandoBind()

        Intent intent = new Intent(IBluetoothHeadsetClient.class.getName());
        ComponentName comp = intent.resolveSystemService(mContext.getPackageManager(), 0);
        intent.setComponent(comp);
        if (comp == null || !mContext.bindServiceAsUser(intent, mConnection, 0,
                 android.os.Process.myUserHandle())) {
            Log.e(TAG, "Could not bind to Bluetooth Headset Client Service with " + intent);
            return false;
        }
        return true;
    
public booleanenterPrivateMode(BluetoothDevice device, int index)
Enters private mode with a specified call. Works only when Extended Call Control is supported by Audio Gateway.

param
device remote device
param
index index of the call to connect in private mode
return
true if command has been issued successfully; false otherwise; upon completion HFP sends {@link #ACTION_CALL_CHANGED} intent.

Feature required for successful execution is being reported by: {@link #EXTRA_AG_FEATURE_ECC}. This method invocation will fail silently when feature is not supported.

        if (DBG) log("enterPrivateMode()");
        if (mService != null && isEnabled() &&
                isValidDevice(device)) {
            try {
                return mService.enterPrivateMode(device, index);
            } catch (RemoteException e) {
                Log.e(TAG,  Log.getStackTraceString(new Throwable()));
            }
        }
        if (mService == null) Log.w(TAG, "Proxy not attached to service");
        return false;
    
public booleanexplicitCallTransfer(BluetoothDevice device)
Performs explicit call transfer. That means connect other calls and disconnect.

param
device remote device
return
true if command has been issued successfully; false otherwise; upon completion HFP sends {@link #ACTION_CALL_CHANGED} intent.

Feature required for successful execution is being reported by: {@link #EXTRA_AG_FEATURE_MERGE_AND_DETACH}. This method invocation will fail silently when feature is not supported.

        if (DBG) log("explicitCallTransfer()");
        if (mService != null && isEnabled() &&
                isValidDevice(device)) {
            try {
                return mService.explicitCallTransfer(device);
            } catch (RemoteException e) {
                Log.e(TAG,  Log.getStackTraceString(new Throwable()));
            }
        }
        if (mService == null) Log.w(TAG, "Proxy not attached to service");
        return false;
    
public intgetAudioState(BluetoothDevice device)
Returns current audio state of Audio Gateway. Note: This is an internal function and shouldn't be exposed

        if (VDBG) log("getAudioState");
        if (mService != null && isEnabled()) {
            try {
                return mService.getAudioState(device);
            } catch (RemoteException e) {Log.e(TAG, e.toString());}
        } else {
            Log.w(TAG, "Proxy not attached to service");
            if (DBG) Log.d(TAG, Log.getStackTraceString(new Throwable()));
        }
        return BluetoothHeadsetClient.STATE_AUDIO_DISCONNECTED;
    
public java.util.ListgetConnectedDevices()
Return the list of connected remote devices

return
list of connected devices; empty list if nothing is connected.

        if (VDBG) log("getConnectedDevices()");
        if (mService != null && isEnabled()) {
            try {
                return mService.getConnectedDevices();
            } catch (RemoteException e) {
                Log.e(TAG, Log.getStackTraceString(new Throwable()));
                return new ArrayList<BluetoothDevice>();
            }
        }
        if (mService == null) Log.w(TAG, "Proxy not attached to service");
        return new ArrayList<BluetoothDevice>();
    
public intgetConnectionState(BluetoothDevice device)
Returns state of the device

param
device a remote device
return
the state of connection of the device

        if (VDBG) log("getConnectionState(" + device + ")");
        if (mService != null && isEnabled() &&
                isValidDevice(device)) {
            try {
                return mService.getConnectionState(device);
            } catch (RemoteException e) {
                Log.e(TAG, Log.getStackTraceString(new Throwable()));
                return BluetoothProfile.STATE_DISCONNECTED;
            }
        }
        if (mService == null) Log.w(TAG, "Proxy not attached to service");
        return BluetoothProfile.STATE_DISCONNECTED;
    
public android.os.BundlegetCurrentAgEvents(BluetoothDevice device)
Returns list of current values of AG indicators.

param
device remote device
return
bundle of AG indicators; null if device is not in CONNECTED state

        if (DBG) log("getCurrentCalls()");
        if (mService != null && isEnabled() &&
                isValidDevice(device)) {
            try {
                return mService.getCurrentAgEvents(device);
            } catch (RemoteException e) {
                Log.e(TAG,  Log.getStackTraceString(new Throwable()));
            }
        }
        if (mService == null) Log.w(TAG, "Proxy not attached to service");
        return null;
    
public android.os.BundlegetCurrentAgFeatures(BluetoothDevice device)
Get Audio Gateway features

param
device remote device
return
bundle of AG features; null if no service or AG not connected

        if (mService != null && isEnabled()) {
            try {
                return mService.getCurrentAgFeatures(device);
            } catch (RemoteException e) {
                Log.e(TAG, e.toString());
            }
        } else {
            Log.w(TAG, "Proxy not attached to service");
            if (DBG) Log.d(TAG, Log.getStackTraceString(new Throwable()));
        }
        return null;
    
public java.util.ListgetCurrentCalls(BluetoothDevice device)
Returns list of all calls in any state.

param
device remote device
return
list of calls; empty list if none call exists

        if (DBG) log("getCurrentCalls()");
        if (mService != null && isEnabled() &&
                isValidDevice(device)) {
            try {
                return mService.getCurrentCalls(device);
            } catch (RemoteException e) {
                Log.e(TAG,  Log.getStackTraceString(new Throwable()));
            }
        }
        if (mService == null) Log.w(TAG, "Proxy not attached to service");
        return null;
    
public java.util.ListgetDevicesMatchingConnectionStates(int[] states)
Returns list of remote devices in a particular state

param
states collection of states
return
list of devices that state matches the states listed in states; empty list if nothing matches the states

        if (VDBG) log("getDevicesMatchingStates()");
        if (mService != null && isEnabled()) {
            try {
                return mService.getDevicesMatchingConnectionStates(states);
            } catch (RemoteException e) {
                Log.e(TAG, Log.getStackTraceString(new Throwable()));
                return new ArrayList<BluetoothDevice>();
            }
        }
        if (mService == null) Log.w(TAG, "Proxy not attached to service");
        return new ArrayList<BluetoothDevice>();
    
public booleangetLastVoiceTagNumber(BluetoothDevice device)
Get a number corresponding to last voice tag recorded on AG.

param
device remote device
return
true if command has been issued successfully; false otherwise; upon completion HFP sends {@link #ACTION_LAST_VTAG} or {@link #ACTION_RESULT} intent;

Feature required for successful execution is being reported by: {@link #EXTRA_AG_FEATURE_ATTACH_NUMBER_TO_VT}. This method invocation will fail silently when feature is not supported.

        if (DBG) log("getLastVoiceTagNumber()");
        if (mService != null && isEnabled() &&
                isValidDevice(device)) {
            try {
                return mService.getLastVoiceTagNumber(device);
            } catch (RemoteException e) {
                Log.e(TAG,  Log.getStackTraceString(new Throwable()));
            }
        }
        if (mService == null) Log.w(TAG, "Proxy not attached to service");
        return false;
    
public intgetPriority(BluetoothDevice device)
Get the priority of the profile.

        if (VDBG) log("getPriority(" + device + ")");
        if (mService != null && isEnabled() &&
                isValidDevice(device)) {
            try {
                return mService.getPriority(device);
            } catch (RemoteException e) {
                Log.e(TAG, Log.getStackTraceString(new Throwable()));
                return PRIORITY_OFF;
            }
        }
        if (mService == null) Log.w(TAG, "Proxy not attached to service");
        return PRIORITY_OFF;
    
public booleanholdCall(BluetoothDevice device)
Holds a call.

param
device remote device
return
true if command has been issued successfully; false otherwise; upon completion HFP sends {@link #ACTION_CALL_CHANGED} intent.

        if (DBG) log("holdCall()");
        if (mService != null && isEnabled() &&
                isValidDevice(device)) {
            try {
                return mService.holdCall(device);
            } catch (RemoteException e) {
                Log.e(TAG,  Log.getStackTraceString(new Throwable()));
            }
        }
        if (mService == null) Log.w(TAG, "Proxy not attached to service");
        return false;
    
private booleanisEnabled()


       
       if (mAdapter.getState() == BluetoothAdapter.STATE_ON) return true;
       return false;
    
private booleanisValidDevice(BluetoothDevice device)

       if (device == null) return false;

       if (BluetoothAdapter.checkBluetoothAddress(device.getAddress())) return true;
       return false;
    
private static voidlog(java.lang.String msg)

        Log.d(TAG, msg);
    
public booleanredial(BluetoothDevice device)
Redials last number from Audio Gateway.

param
device remote device
return
true if command has been issued successfully; false otherwise; upon completion HFP sends {@link #ACTION_CALL_CHANGED} intent in case of success; {@link #ACTION_RESULT} is sent otherwise;

        if (DBG) log("redial()");
        if (mService != null && isEnabled() &&
                isValidDevice(device)) {
            try {
                return mService.redial(device);
            } catch (RemoteException e) {
                Log.e(TAG,  Log.getStackTraceString(new Throwable()));
            }
        }
        if (mService == null) Log.w(TAG, "Proxy not attached to service");
        return false;
    
public booleanrejectCall(BluetoothDevice device)
Rejects a call.

param
device remote device
return
true if command has been issued successfully; false otherwise; upon completion HFP sends {@link #ACTION_CALL_CHANGED} intent.

Feature required for successful execution is being reported by: {@link #EXTRA_AG_FEATURE_REJECT_CALL}. This method invocation will fail silently when feature is not supported.

        if (DBG) log("rejectCall()");
        if (mService != null && isEnabled() &&
                isValidDevice(device)) {
            try {
                return mService.rejectCall(device);
            } catch (RemoteException e) {
                Log.e(TAG,  Log.getStackTraceString(new Throwable()));
            }
        }
        if (mService == null) Log.w(TAG, "Proxy not attached to service");
        return false;
    
public booleanrejectIncomingConnect(BluetoothDevice device)
Reject the incoming connection.

        if (DBG) log("rejectIncomingConnect");
        if (mService != null) {
            try {
                return mService.rejectIncomingConnect(device);
            } catch (RemoteException e) {Log.e(TAG, e.toString());}
        } else {
            Log.w(TAG, "Proxy not attached to service");
            if (DBG) Log.d(TAG, Log.getStackTraceString(new Throwable()));
        }
        return false;
    
public booleansendDTMF(BluetoothDevice device, byte code)
Sends DTMF code. Possible code values : 0,1,2,3,4,5,6,7,8,9,A,B,C,D,*,#

param
device remote device
param
code ASCII code
return
true if command has been issued successfully; false otherwise; upon completion HFP sends {@link #ACTION_RESULT} intent;

        if (DBG) log("sendDTMF()");
        if (mService != null && isEnabled() &&
                isValidDevice(device)) {
            try {
                return mService.sendDTMF(device, code);
            } catch (RemoteException e) {
                Log.e(TAG,  Log.getStackTraceString(new Throwable()));
            }
        }
        if (mService == null) Log.w(TAG, "Proxy not attached to service");
        return false;
    
public booleansetPriority(BluetoothDevice device, int priority)
Set priority of the profile The device should already be paired.

        if (DBG) log("setPriority(" + device + ", " + priority + ")");
        if (mService != null && isEnabled() &&
                isValidDevice(device)) {
            if (priority != BluetoothProfile.PRIORITY_OFF &&
                    priority != BluetoothProfile.PRIORITY_ON) {
              return false;
            }
            try {
                return mService.setPriority(device, priority);
            } catch (RemoteException e) {
                Log.e(TAG, Log.getStackTraceString(new Throwable()));
                return false;
            }
        }
        if (mService == null) Log.w(TAG, "Proxy not attached to service");
        return false;
    
public booleanstartVoiceRecognition(BluetoothDevice device)
Starts voice recognition.

param
device remote device
return
true if command has been issued successfully; false otherwise; upon completion HFP sends {@link #ACTION_AG_EVENT} intent.

Feature required for successful execution is being reported by: {@link #EXTRA_AG_FEATURE_VOICE_RECOGNITION}. This method invocation will fail silently when feature is not supported.

        if (DBG) log("startVoiceRecognition()");
        if (mService != null && isEnabled() &&
                isValidDevice(device)) {
            try {
                return mService.startVoiceRecognition(device);
            } catch (RemoteException e) {
                Log.e(TAG,  Log.getStackTraceString(new Throwable()));
            }
        }
        if (mService == null) Log.w(TAG, "Proxy not attached to service");
        return false;
    
public booleanstopVoiceRecognition(BluetoothDevice device)
Stops voice recognition.

param
device remote device
return
true if command has been issued successfully; false otherwise; upon completion HFP sends {@link #ACTION_AG_EVENT} intent.

Feature required for successful execution is being reported by: {@link #EXTRA_AG_FEATURE_VOICE_RECOGNITION}. This method invocation will fail silently when feature is not supported.

        if (DBG) log("stopVoiceRecognition()");
        if (mService != null && isEnabled() &&
                isValidDevice(device)) {
            try {
                return mService.stopVoiceRecognition(device);
            } catch (RemoteException e) {
                Log.e(TAG,  Log.getStackTraceString(new Throwable()));
            }
        }
        if (mService == null) Log.w(TAG, "Proxy not attached to service");
        return false;
    
public booleanterminateCall(BluetoothDevice device, int index)
Terminates a specified call. Works only when Extended Call Control is supported by Audio Gateway.

param
device remote device
param
index index of the call to be terminated
return
true if command has been issued successfully; false otherwise; upon completion HFP sends {@link #ACTION_CALL_CHANGED} intent.

Feature required for successful execution is being reported by: {@link #EXTRA_AG_FEATURE_ECC}. This method invocation will fail silently when feature is not supported.

        if (DBG) log("terminateCall()");
        if (mService != null && isEnabled() &&
                isValidDevice(device)) {
            try {
                return mService.terminateCall(device, index);
            } catch (RemoteException e) {
                Log.e(TAG,  Log.getStackTraceString(new Throwable()));
            }
        }
        if (mService == null) Log.w(TAG, "Proxy not attached to service");
        return false;