final class HeadsetStateMachine extends StateMachine {
private static final String TAG = "HeadsetStateMachine";
private static final boolean DBG = false;
- //For Debugging only
- private static int sRefCount=0;
+ // For Debugging only
+ private static int sRefCount = 0;
private static final String HEADSET_NAME = "bt_headset_name";
private static final String HEADSET_NREC = "bt_headset_nrec";
private static final Map<String, Integer> VENDOR_SPECIFIC_AT_COMMAND_COMPANY_ID;
// Hash for storing the Audio Parameters like NREC for connected headsets
private HashMap<BluetoothDevice, HashMap> mHeadsetAudioParam =
- new HashMap<BluetoothDevice, HashMap>();
+ new HashMap<BluetoothDevice, HashMap>();
// Hash for storing the Remotedevice BRSF
private HashMap<BluetoothDevice, Integer> mHeadsetBrsf =
- new HashMap<BluetoothDevice, Integer>();
+ new HashMap<BluetoothDevice, Integer>();
private static final ParcelUuid[] HEADSET_UUIDS = {
- BluetoothUuid.HSP,
- BluetoothUuid.Handsfree,
+ BluetoothUuid.HSP, BluetoothUuid.Handsfree,
};
private Disconnected mDisconnected;
private boolean mVirtualCallStarted = false;
private boolean mVoiceRecognitionStarted = false;
private boolean mWaitingForVoiceRecognition = false;
- private WakeLock mStartVoiceRecognitionWakeLock; // held while waiting for voice recognition
+ private WakeLock mStartVoiceRecognitionWakeLock; // held while waiting for voice recognition
private boolean mDialingOut = false;
private AudioManager mAudioManager;
private BluetoothDevice mMultiDisconnectDevice = null;
// Multi HFP: Connected devices list holds all currently connected headsets
- private ArrayList<BluetoothDevice> mConnectedDevicesList =
- new ArrayList<BluetoothDevice>();
+ private ArrayList<BluetoothDevice> mConnectedDevicesList = new ArrayList<BluetoothDevice>();
static {
classInitNative();
mWaitingForVoiceRecognition = false;
mPowerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
- mStartVoiceRecognitionWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
- TAG + ":VoiceRecognition");
+ mStartVoiceRecognitionWakeLock = mPowerManager.newWakeLock(
+ PowerManager.PARTIAL_WAKE_LOCK, TAG + ":VoiceRecognition");
mStartVoiceRecognitionWakeLock.setReferenceCounted(false);
mDialingOut = false;
}
String max_hfp_clients = SystemProperties.get("bt.max.hfpclient.connections");
- if (!max_hfp_clients.isEmpty() && (Integer.parseInt(max_hfp_clients) == 2))
+ if (!max_hfp_clients.isEmpty() && (Integer.parseInt(max_hfp_clients) == 2)) {
max_hf_connections = Integer.parseInt(max_hfp_clients);
+ }
Log.d(TAG, "max_hf_connections = " + max_hf_connections);
initializeNative(max_hf_connections);
- mNativeAvailable=true;
+ mNativeAvailable = true;
mDisconnected = new Disconnected();
mPending = new Pending();
return hssm;
}
-
public void doQuit() {
quitNow();
}
public void cleanup() {
if (mPhoneProxy != null) {
- if (DBG) Log.d(TAG,"Unbinding service...");
+ if (DBG) Log.d(TAG, "Unbinding service...");
synchronized (mConnection) {
try {
mPhoneProxy = null;
mService.unbindService(mConnection);
} catch (Exception re) {
- Log.e(TAG,"Error unbinding from IBluetoothHeadsetPhone",re);
+ Log.e(TAG, "Error unbinding from IBluetoothHeadsetPhone", re);
}
}
}
private class Disconnected extends State {
@Override
public void enter() {
- log("Enter Disconnected: " + getCurrentMessage().what +
- ", size: " + mConnectedDevicesList.size());
+ log("Enter Disconnected: " + getCurrentMessage().what + ", size: "
+ + mConnectedDevicesList.size());
mPhonebook.resetAtState();
mPhoneState.listenForPhoneState(false);
mVoiceRecognitionStarted = false;
@Override
public boolean processMessage(Message message) {
- log("Disconnected process message: " + message.what +
- ", size: " + mConnectedDevicesList.size());
- if (mConnectedDevicesList.size() != 0 || mTargetDevice != null ||
- mIncomingDevice != null) {
- Log.e(TAG, "ERROR: mConnectedDevicesList is not empty," +
- "target, or mIncomingDevice not null in Disconnected");
+ log("Disconnected process message: " + message.what + ", size: "
+ + mConnectedDevicesList.size());
+ if (mConnectedDevicesList.size() != 0 || mTargetDevice != null
+ || mIncomingDevice != null) {
+ Log.e(TAG, "ERROR: mConnectedDevicesList is not empty,"
+ + "target, or mIncomingDevice not null in Disconnected");
return NOT_HANDLED;
}
boolean retValue = HANDLED;
- switch(message.what) {
+ switch (message.what) {
case CONNECT:
BluetoothDevice device = (BluetoothDevice) message.obj;
broadcastConnectionState(device, BluetoothProfile.STATE_CONNECTING,
- BluetoothProfile.STATE_DISCONNECTED);
+ BluetoothProfile.STATE_DISCONNECTED);
- if (!connectHfpNative(getByteAddress(device)) ) {
+ if (!connectHfpNative(getByteAddress(device))) {
broadcastConnectionState(device, BluetoothProfile.STATE_DISCONNECTED,
- BluetoothProfile.STATE_CONNECTING);
+ BluetoothProfile.STATE_CONNECTING);
break;
}
processIntentBatteryChanged((Intent) message.obj);
break;
case CALL_STATE_CHANGED:
- processCallState((HeadsetCallState) message.obj,
- ((message.arg1 == 1)?true:false));
+ processCallState((HeadsetCallState) message.obj, message.arg1 == 1);
break;
case STACK_EVENT:
StackEvent event = (StackEvent) message.obj;
// in Disconnected state
private void processConnectionEvent(int state, BluetoothDevice device) {
- Log.d(TAG, "processConnectionEvent state = " + state +
- ", device = " + device);
+ Log.d(TAG, "processConnectionEvent state = " + state + ", device = " + device);
switch (state) {
- case HeadsetHalConstants.CONNECTION_STATE_DISCONNECTED:
- Log.w(TAG, "Ignore HF DISCONNECTED event, device: " + device);
- break;
- case HeadsetHalConstants.CONNECTION_STATE_CONNECTING:
- if (okToConnect(device)) {
- Log.i(TAG,"Incoming Hf accepted");
- broadcastConnectionState(device, BluetoothProfile.STATE_CONNECTING,
- BluetoothProfile.STATE_DISCONNECTED);
- synchronized (HeadsetStateMachine.this) {
- mIncomingDevice = device;
- transitionTo(mPending);
+ case HeadsetHalConstants.CONNECTION_STATE_DISCONNECTED:
+ Log.w(TAG, "Ignore HF DISCONNECTED event, device: " + device);
+ break;
+ case HeadsetHalConstants.CONNECTION_STATE_CONNECTING:
+ if (okToConnect(device)) {
+ Log.i(TAG, "Incoming Hf accepted");
+ broadcastConnectionState(device, BluetoothProfile.STATE_CONNECTING,
+ BluetoothProfile.STATE_DISCONNECTED);
+ synchronized (HeadsetStateMachine.this) {
+ mIncomingDevice = device;
+ transitionTo(mPending);
+ }
+ } else {
+ Log.i(TAG, "Incoming Hf rejected. priority=" + mService.getPriority(device)
+ + " bondState=" + device.getBondState());
+ // reject the connection and stay in Disconnected state itself
+ disconnectHfpNative(getByteAddress(device));
+ // the other profile connection should be initiated
+ broadcastConnectionState(device, BluetoothProfile.STATE_DISCONNECTED,
+ BluetoothProfile.STATE_DISCONNECTED);
}
- } else {
- Log.i(TAG,"Incoming Hf rejected. priority=" + mService.getPriority(device)+
- " bondState=" + device.getBondState());
- //reject the connection and stay in Disconnected state itself
- disconnectHfpNative(getByteAddress(device));
- // the other profile connection should be initiated
- broadcastConnectionState(device, BluetoothProfile.STATE_DISCONNECTED,
- BluetoothProfile.STATE_DISCONNECTED);
- }
- break;
- case HeadsetHalConstants.CONNECTION_STATE_CONNECTED:
- Log.w(TAG, "HFP Connected from Disconnected state");
- if (okToConnect(device)) {
- Log.i(TAG,"Incoming Hf accepted");
- broadcastConnectionState(device, BluetoothProfile.STATE_CONNECTED,
- BluetoothProfile.STATE_DISCONNECTED);
- synchronized (HeadsetStateMachine.this) {
- if (!mConnectedDevicesList.contains(device)) {
- mConnectedDevicesList.add(device);
- Log.d(TAG, "device " + device.getAddress() +
- " is adding in Disconnected state");
+ break;
+ case HeadsetHalConstants.CONNECTION_STATE_CONNECTED:
+ Log.w(TAG, "HFP Connected from Disconnected state");
+ if (okToConnect(device)) {
+ Log.i(TAG, "Incoming Hf accepted");
+ broadcastConnectionState(device, BluetoothProfile.STATE_CONNECTED,
+ BluetoothProfile.STATE_DISCONNECTED);
+ synchronized (HeadsetStateMachine.this) {
+ if (!mConnectedDevicesList.contains(device)) {
+ mConnectedDevicesList.add(device);
+ Log.d(TAG, "device " + device.getAddress()
+ + " is adding in Disconnected state");
+ }
+ mCurrentDevice = device;
+ transitionTo(mConnected);
}
- mCurrentDevice = device;
- transitionTo(mConnected);
+ configAudioParameters(device);
+ } else {
+ // reject the connection and stay in Disconnected state itself
+ Log.i(TAG, "Incoming Hf rejected. priority=" + mService.getPriority(device)
+ + " bondState=" + device.getBondState());
+ disconnectHfpNative(getByteAddress(device));
+ // the other profile connection should be initiated
+ broadcastConnectionState(device, BluetoothProfile.STATE_DISCONNECTED,
+ BluetoothProfile.STATE_DISCONNECTED);
}
- configAudioParameters(device);
- } else {
- //reject the connection and stay in Disconnected state itself
- Log.i(TAG,"Incoming Hf rejected. priority=" + mService.getPriority(device) +
- " bondState=" + device.getBondState());
- disconnectHfpNative(getByteAddress(device));
- // the other profile connection should be initiated
- broadcastConnectionState(device, BluetoothProfile.STATE_DISCONNECTED,
- BluetoothProfile.STATE_DISCONNECTED);
- }
- break;
- case HeadsetHalConstants.CONNECTION_STATE_DISCONNECTING:
- Log.w(TAG, "Ignore HF DISCONNECTING event, device: " + device);
- break;
- default:
- Log.e(TAG, "Incorrect state: " + state);
- break;
+ break;
+ case HeadsetHalConstants.CONNECTION_STATE_DISCONNECTING:
+ Log.w(TAG, "Ignore HF DISCONNECTING event, device: " + device);
+ break;
+ default:
+ Log.e(TAG, "Incorrect state: " + state);
+ break;
}
}
}
@Override
public boolean processMessage(Message message) {
log("Pending process message: " + message.what + ", size: "
- + mConnectedDevicesList.size());
+ + mConnectedDevicesList.size());
boolean retValue = HANDLED;
- switch(message.what) {
+ switch (message.what) {
case CONNECT:
case CONNECT_AUDIO:
deferMessage(message);
break;
case CONNECT_TIMEOUT:
onConnectionStateChanged(HeadsetHalConstants.CONNECTION_STATE_DISCONNECTED,
- getByteAddress(mTargetDevice));
+ getByteAddress(mTargetDevice));
break;
case DISCONNECT:
BluetoothDevice device = (BluetoothDevice) message.obj;
- if (mCurrentDevice != null && mTargetDevice != null &&
- mTargetDevice.equals(device) ) {
+ if (mCurrentDevice != null && mTargetDevice != null
+ && mTargetDevice.equals(device)) {
// cancel connection to the mTargetDevice
broadcastConnectionState(device, BluetoothProfile.STATE_DISCONNECTED,
- BluetoothProfile.STATE_CONNECTING);
+ BluetoothProfile.STATE_CONNECTING);
synchronized (HeadsetStateMachine.this) {
mTargetDevice = null;
}
processIntentBatteryChanged((Intent) message.obj);
break;
case CALL_STATE_CHANGED:
- processCallState((HeadsetCallState) message.obj,
- ((message.arg1 == 1)?true:false));
+ processCallState((HeadsetCallState) message.obj, message.arg1 == 1);
break;
case STACK_EVENT:
StackEvent event = (StackEvent) message.obj;
// in Pending state
private void processConnectionEvent(int state, BluetoothDevice device) {
- Log.d(TAG, "processConnectionEvent state = " + state +
- ", device = " + device);
+ Log.d(TAG, "processConnectionEvent state = " + state + ", device = " + device);
switch (state) {
case HeadsetHalConstants.CONNECTION_STATE_DISCONNECTED:
if (mConnectedDevicesList.contains(device)) {
-
synchronized (HeadsetStateMachine.this) {
mConnectedDevicesList.remove(device);
mHeadsetAudioParam.remove(device);
mHeadsetBrsf.remove(device);
- Log.d(TAG, "device " + device.getAddress() +
- " is removed in Pending state");
+ Log.d(TAG, "device " + device.getAddress()
+ + " is removed in Pending state");
}
- broadcastConnectionState(device,
- BluetoothProfile.STATE_DISCONNECTED,
- BluetoothProfile.STATE_DISCONNECTING);
+ broadcastConnectionState(device, BluetoothProfile.STATE_DISCONNECTED,
+ BluetoothProfile.STATE_DISCONNECTING);
synchronized (HeadsetStateMachine.this) {
mCurrentDevice = null;
}
if (mTargetDevice != null) {
if (!connectHfpNative(getByteAddress(mTargetDevice))) {
broadcastConnectionState(mTargetDevice,
- BluetoothProfile.STATE_DISCONNECTED,
- BluetoothProfile.STATE_CONNECTING);
+ BluetoothProfile.STATE_DISCONNECTED,
+ BluetoothProfile.STATE_CONNECTING);
synchronized (HeadsetStateMachine.this) {
mTargetDevice = null;
transitionTo(mDisconnected);
mIncomingDevice = null;
if (mConnectedDevicesList.size() == 0) {
transitionTo(mDisconnected);
- }
- else {
+ } else {
processMultiHFConnected(device);
}
}
} else if (mTargetDevice != null && mTargetDevice.equals(device)) {
// outgoing connection failed
broadcastConnectionState(mTargetDevice, BluetoothProfile.STATE_DISCONNECTED,
- BluetoothProfile.STATE_CONNECTING);
+ BluetoothProfile.STATE_CONNECTING);
synchronized (HeadsetStateMachine.this) {
mTargetDevice = null;
if (mConnectedDevicesList.size() == 0) {
transitionTo(mDisconnected);
- }
- else {
+ } else {
transitionTo(mConnected);
}
-
}
} else if (mIncomingDevice != null && mIncomingDevice.equals(device)) {
broadcastConnectionState(mIncomingDevice,
- BluetoothProfile.STATE_DISCONNECTED,
- BluetoothProfile.STATE_CONNECTING);
+ BluetoothProfile.STATE_DISCONNECTED,
+ BluetoothProfile.STATE_CONNECTING);
synchronized (HeadsetStateMachine.this) {
mIncomingDevice = null;
if (mConnectedDevicesList.size() == 0) {
transitionTo(mDisconnected);
- }
- else {
+ } else {
transitionTo(mConnected);
}
}
break;
case HeadsetHalConstants.CONNECTION_STATE_CONNECTED:
if (mConnectedDevicesList.contains(device)) {
- // disconnection failed
- broadcastConnectionState(device, BluetoothProfile.STATE_CONNECTED,
- BluetoothProfile.STATE_DISCONNECTING);
+ // disconnection failed
+ broadcastConnectionState(device, BluetoothProfile.STATE_CONNECTED,
+ BluetoothProfile.STATE_DISCONNECTING);
if (mTargetDevice != null) {
broadcastConnectionState(mTargetDevice,
- BluetoothProfile.STATE_DISCONNECTED,
- BluetoothProfile.STATE_CONNECTING);
+ BluetoothProfile.STATE_DISCONNECTED,
+ BluetoothProfile.STATE_CONNECTING);
}
synchronized (HeadsetStateMachine.this) {
mTargetDevice = null;
transitionTo(mConnected);
}
} else if (mTargetDevice != null && mTargetDevice.equals(device)) {
-
synchronized (HeadsetStateMachine.this) {
mCurrentDevice = device;
mConnectedDevicesList.add(device);
- Log.d(TAG, "device " + device.getAddress() +
- " is added in Pending state");
+ Log.d(TAG,
+ "device " + device.getAddress() + " is added in Pending state");
mTargetDevice = null;
transitionTo(mConnected);
}
broadcastConnectionState(device, BluetoothProfile.STATE_CONNECTED,
- BluetoothProfile.STATE_CONNECTING);
+ BluetoothProfile.STATE_CONNECTING);
configAudioParameters(device);
} else if (mIncomingDevice != null && mIncomingDevice.equals(device)) {
-
synchronized (HeadsetStateMachine.this) {
mCurrentDevice = device;
mConnectedDevicesList.add(device);
- Log.d(TAG, "device " + device.getAddress() +
- " is added in Pending state");
+ Log.d(TAG,
+ "device " + device.getAddress() + " is added in Pending state");
mIncomingDevice = null;
transitionTo(mConnected);
}
broadcastConnectionState(device, BluetoothProfile.STATE_CONNECTED,
- BluetoothProfile.STATE_CONNECTING);
+ BluetoothProfile.STATE_CONNECTING);
configAudioParameters(device);
} else {
Log.w(TAG, "Some other incoming HF connected in Pending state");
if (okToConnect(device)) {
- Log.i(TAG,"Incoming Hf accepted");
+ Log.i(TAG, "Incoming Hf accepted");
broadcastConnectionState(device, BluetoothProfile.STATE_CONNECTED,
- BluetoothProfile.STATE_DISCONNECTED);
+ BluetoothProfile.STATE_DISCONNECTED);
synchronized (HeadsetStateMachine.this) {
mCurrentDevice = device;
mConnectedDevicesList.add(device);
- Log.d(TAG, "device " + device.getAddress() +
- " is added in Pending state");
+ Log.d(TAG, "device " + device.getAddress()
+ + " is added in Pending state");
}
configAudioParameters(device);
} else {
- //reject the connection and stay in Pending state itself
- Log.i(TAG,"Incoming Hf rejected. priority=" +
- mService.getPriority(device) + " bondState=" +
- device.getBondState());
+ // reject the connection and stay in Pending state itself
+ Log.i(TAG, "Incoming Hf rejected. priority="
+ + mService.getPriority(device) + " bondState="
+ + device.getBondState());
disconnectHfpNative(getByteAddress(device));
}
}
if (DBG) {
log("Stack and target device are connecting");
}
- }
- else if (mIncomingDevice != null && mIncomingDevice.equals(device)) {
+ } else if (mIncomingDevice != null && mIncomingDevice.equals(device)) {
Log.e(TAG, "Another connecting event on the incoming device");
} else {
// We get an incoming connecting request while Pending
if (mCurrentDevice != null && mCurrentDevice.equals(device)) {
transitionTo(mConnected);
int deviceSize = mConnectedDevicesList.size();
- mCurrentDevice = mConnectedDevicesList.get(deviceSize-1);
+ mCurrentDevice = mConnectedDevicesList.get(deviceSize - 1);
} else {
// The disconnected device is not current active device
if (mAudioState == BluetoothHeadset.STATE_AUDIO_CONNECTED)
transitionTo(mAudioOn);
- else transitionTo(mConnected);
+ else
+ transitionTo(mConnected);
}
- log("processMultiHFConnected , the latest mCurrentDevice is:"
- + mCurrentDevice);
- log("Pending state: processMultiHFConnected ," +
- "fake broadcasting for mCurrentDevice");
+ log("processMultiHFConnected , the latest mCurrentDevice is:" + mCurrentDevice);
+ log("Pending state: processMultiHFConnected ,"
+ + "fake broadcasting for mCurrentDevice");
broadcastConnectionState(mCurrentDevice, BluetoothProfile.STATE_CONNECTED,
- BluetoothProfile.STATE_DISCONNECTED);
+ BluetoothProfile.STATE_DISCONNECTED);
}
}
// TODO: This needs to check for multiple HFP connections, once supported...
removeDeferredMessages(CONNECT);
- log("Enter Connected: " + getCurrentMessage().what +
- ", size: " + mConnectedDevicesList.size());
+ log("Enter Connected: " + getCurrentMessage().what + ", size: "
+ + mConnectedDevicesList.size());
// start phone state listener here so that the CIND response as part of SLC can be
// responded to, correctly.
// we may enter Connected from Disconnected/Pending/AudioOn. listenForPhoneState
@Override
public boolean processMessage(Message message) {
- log("Connected process message: " + message.what +
- ", size: " + mConnectedDevicesList.size());
+ log("Connected process message: " + message.what + ", size: "
+ + mConnectedDevicesList.size());
if (DBG) {
if (mConnectedDevicesList.size() == 0) {
log("ERROR: mConnectedDevicesList is empty in Connected");
}
boolean retValue = HANDLED;
- switch(message.what) {
- case CONNECT:
- {
+ switch (message.what) {
+ case CONNECT: {
BluetoothDevice device = (BluetoothDevice) message.obj;
if (device == null) {
break;
break;
}
- if (mConnectedDevicesList.size() >= max_hf_connections) {
- BluetoothDevice DisconnectConnectedDevice = null;
- IState CurrentAudioState = getCurrentState();
- Log.d(TAG, "Reach to max size, disconnect one of them first");
- /* TODO: Disconnect based on CoD */
- DisconnectConnectedDevice = mConnectedDevicesList.get(0);
-
- broadcastConnectionState(device, BluetoothProfile.STATE_CONNECTING,
- BluetoothProfile.STATE_DISCONNECTED);
-
- if (!disconnectHfpNative(getByteAddress(DisconnectConnectedDevice))) {
- broadcastConnectionState(device, BluetoothProfile.STATE_DISCONNECTED,
- BluetoothProfile.STATE_CONNECTING);
- break;
- } else {
- broadcastConnectionState(DisconnectConnectedDevice,
- BluetoothProfile.STATE_DISCONNECTING,
- BluetoothProfile.STATE_CONNECTED);
- }
-
- synchronized (HeadsetStateMachine.this) {
- mTargetDevice = device;
- if (max_hf_connections == 1) {
- transitionTo(mPending);
- } else {
- mMultiDisconnectDevice = DisconnectConnectedDevice;
- transitionTo(mMultiHFPending);
- }
- DisconnectConnectedDevice = null;
- }
- }else if (mConnectedDevicesList.size() < max_hf_connections) {
- broadcastConnectionState(device, BluetoothProfile.STATE_CONNECTING,
- BluetoothProfile.STATE_DISCONNECTED);
- if (!connectHfpNative(getByteAddress(device))) {
- broadcastConnectionState(device, BluetoothProfile.STATE_DISCONNECTED,
- BluetoothProfile.STATE_CONNECTING);
- break;
- }
- synchronized (HeadsetStateMachine.this) {
- mTargetDevice = device;
- // Transtion to MultiHFPending state for Multi HF connection
- transitionTo(mMultiHFPending);
- }
+ if (mConnectedDevicesList.size() >= max_hf_connections) {
+ BluetoothDevice DisconnectConnectedDevice = null;
+ IState CurrentAudioState = getCurrentState();
+ Log.d(TAG, "Reach to max size, disconnect one of them first");
+ /* TODO: Disconnect based on CoD */
+ DisconnectConnectedDevice = mConnectedDevicesList.get(0);
+
+ broadcastConnectionState(device, BluetoothProfile.STATE_CONNECTING,
+ BluetoothProfile.STATE_DISCONNECTED);
+
+ if (!disconnectHfpNative(getByteAddress(DisconnectConnectedDevice))) {
+ broadcastConnectionState(device, BluetoothProfile.STATE_DISCONNECTED,
+ BluetoothProfile.STATE_CONNECTING);
+ break;
+ } else {
+ broadcastConnectionState(DisconnectConnectedDevice,
+ BluetoothProfile.STATE_DISCONNECTING,
+ BluetoothProfile.STATE_CONNECTED);
+ }
+
+ synchronized (HeadsetStateMachine.this) {
+ mTargetDevice = device;
+ if (max_hf_connections == 1) {
+ transitionTo(mPending);
+ } else {
+ mMultiDisconnectDevice = DisconnectConnectedDevice;
+ transitionTo(mMultiHFPending);
+ }
+ DisconnectConnectedDevice = null;
+ }
+ } else if (mConnectedDevicesList.size() < max_hf_connections) {
+ broadcastConnectionState(device, BluetoothProfile.STATE_CONNECTING,
+ BluetoothProfile.STATE_DISCONNECTED);
+ if (!connectHfpNative(getByteAddress(device))) {
+ broadcastConnectionState(device, BluetoothProfile.STATE_DISCONNECTED,
+ BluetoothProfile.STATE_CONNECTING);
+ break;
+ }
+ synchronized (HeadsetStateMachine.this) {
+ mTargetDevice = device;
+ // Transtion to MultiHFPending state for Multi HF connection
+ transitionTo(mMultiHFPending);
+ }
}
Message m = obtainMessage(CONNECT_TIMEOUT);
m.obj = device;
sendMessageDelayed(m, 30000);
- }
- break;
- case DISCONNECT:
- {
+ } break;
+ case DISCONNECT: {
BluetoothDevice device = (BluetoothDevice) message.obj;
if (!mConnectedDevicesList.contains(device)) {
break;
}
broadcastConnectionState(device, BluetoothProfile.STATE_DISCONNECTING,
- BluetoothProfile.STATE_CONNECTED);
+ BluetoothProfile.STATE_CONNECTED);
if (!disconnectHfpNative(getByteAddress(device))) {
broadcastConnectionState(device, BluetoothProfile.STATE_CONNECTED,
- BluetoothProfile.STATE_DISCONNECTED);
+ BluetoothProfile.STATE_DISCONNECTED);
break;
}
} else {
transitionTo(mPending);
}
- }
- break;
- case CONNECT_AUDIO:
- {
+ } break;
+ case CONNECT_AUDIO: {
BluetoothDevice device = mCurrentDevice;
if (!isScoAcceptable()) {
Log.w(TAG,"No Active/Held call, MO call setup, not allowing SCO");
}
log("connectAudioNative in Connected for device = " + device);
connectAudioNative(getByteAddress(device));
- }
- break;
+ } break;
case VOICE_RECOGNITION_START:
processLocalVrEvent(HeadsetHalConstants.VR_STATE_STARTED);
break;
processLocalVrEvent(HeadsetHalConstants.VR_STATE_STOPPED);
break;
case CALL_STATE_CHANGED:
- processCallState((HeadsetCallState) message.obj, ((message.arg1==1)?true:false));
+ processCallState((HeadsetCallState) message.obj, message.arg1 == 1);
break;
case INTENT_BATTERY_CHANGED:
processIntentBatteryChanged((Intent) message.obj);
case SEND_CCLC_RESPONSE:
processSendClccResponse((HeadsetClccResponse) message.obj);
break;
- case CLCC_RSP_TIMEOUT:
- {
+ case CLCC_RSP_TIMEOUT: {
BluetoothDevice device = (BluetoothDevice) message.obj;
clccResponseNative(0, 0, 0, 0, false, "", 0, getByteAddress(device));
- }
- break;
+ } break;
case SEND_VENDOR_SPECIFIC_RESULT_CODE:
processSendVendorSpecificResultCode(
(HeadsetVendorSpecificResultCode) message.obj);
break;
- case DIALING_OUT_TIMEOUT:
- {
+ case DIALING_OUT_TIMEOUT: {
BluetoothDevice device = (BluetoothDevice) message.obj;
if (mDialingOut) {
- mDialingOut= false;
- atResponseCodeNative(HeadsetHalConstants.AT_RESPONSE_ERROR,
- 0, getByteAddress(device));
+ mDialingOut = false;
+ atResponseCodeNative(
+ HeadsetHalConstants.AT_RESPONSE_ERROR, 0, getByteAddress(device));
}
- }
- break;
+ } break;
case VIRTUAL_CALL_START:
initiateScoUsingVirtualVoiceCall();
break;
case VIRTUAL_CALL_STOP:
terminateScoUsingVirtualVoiceCall();
break;
- case ENABLE_WBS:
- {
+ case ENABLE_WBS: {
BluetoothDevice device = (BluetoothDevice) message.obj;
- configureWBSNative(getByteAddress(device),WBS_CODEC);
- }
+ configureWBSNative(getByteAddress(device), WBS_CODEC);
break;
- case DISABLE_WBS:
- {
- BluetoothDevice device = (BluetoothDevice) message.obj;
- configureWBSNative(getByteAddress(device),NBS_CODEC);
}
- break;
- case BIND_RESPONSE:
- {
+ case DISABLE_WBS: {
BluetoothDevice device = (BluetoothDevice) message.obj;
- bindResponseNative((int)message.arg1, ((message.arg2 == 1) ? true : false),
- getByteAddress(device));
- }
+ configureWBSNative(getByteAddress(device), NBS_CODEC);
break;
- case START_VR_TIMEOUT:
- {
+ }
+ case BIND_RESPONSE: {
+ BluetoothDevice device = (BluetoothDevice) message.obj;
+ bindResponseNative(
+ (int) message.arg1, message.arg2 == 1, getByteAddress(device));
+ } break;
+ case START_VR_TIMEOUT: {
BluetoothDevice device = (BluetoothDevice) message.obj;
if (mWaitingForVoiceRecognition) {
device = (BluetoothDevice) message.obj;
mWaitingForVoiceRecognition = false;
Log.e(TAG, "Timeout waiting for voice recognition to start");
- atResponseCodeNative(HeadsetHalConstants.AT_RESPONSE_ERROR,
- 0, getByteAddress(device));
+ atResponseCodeNative(
+ HeadsetHalConstants.AT_RESPONSE_ERROR, 0, getByteAddress(device));
}
- }
- break;
+ } break;
case STACK_EVENT:
StackEvent event = (StackEvent) message.obj;
if (DBG) {
- log("event type: " + event.type + "event device : "
- + event.device);
+ log("event type: " + event.type + "event device : " + event.device);
}
switch (event.type) {
case EVENT_TYPE_CONNECTION_STATE_CHANGED:
processHangupCall(event.device);
break;
case EVENT_TYPE_VOLUME_CHANGED:
- processVolumeEvent(event.valueInt, event.valueInt2,
- event.device);
+ processVolumeEvent(event.valueInt, event.valueInt2, event.device);
break;
case EVENT_TYPE_DIAL_CALL:
processDialCall(event.valueString, event.device);
processNoiceReductionEvent(event.valueInt, event.device);
break;
case EVENT_TYPE_WBS:
- Log.d(TAG, "EVENT_TYPE_WBS codec is "+event.valueInt);
+ Log.d(TAG, "EVENT_TYPE_WBS codec is " + event.valueInt);
processWBSEvent(event.valueInt, event.device);
break;
case EVENT_TYPE_AT_CHLD:
// in Connected state
private void processConnectionEvent(int state, BluetoothDevice device) {
- Log.d(TAG, "processConnectionEvent state = " + state + ", device = "
- + device);
+ Log.d(TAG, "processConnectionEvent state = " + state + ", device = " + device);
switch (state) {
case HeadsetHalConstants.CONNECTION_STATE_DISCONNECTED:
if (mConnectedDevicesList.contains(device)) {
mConnectedDevicesList.remove(device);
mHeadsetAudioParam.remove(device);
mHeadsetBrsf.remove(device);
- Log.d(TAG, "device " + device.getAddress() +
- " is removed in Connected state");
+ Log.d(TAG, "device " + device.getAddress()
+ + " is removed in Connected state");
if (mConnectedDevicesList.size() == 0) {
mCurrentDevice = null;
transitionTo(mDisconnected);
- }
- else {
+ } else {
processMultiHFConnected(device);
}
}
broadcastConnectionState(device, BluetoothProfile.STATE_DISCONNECTED,
- BluetoothProfile.STATE_CONNECTED);
+ BluetoothProfile.STATE_CONNECTED);
} else {
Log.e(TAG, "Disconnected from unknown device: " + device);
}
break;
}
Log.w(TAG, "HFP to be Connected in Connected state");
- if (okToConnect(device) && (mConnectedDevicesList.size()
- < max_hf_connections)) {
- Log.i(TAG,"Incoming Hf accepted");
+ if (okToConnect(device)
+ && (mConnectedDevicesList.size() < max_hf_connections)) {
+ Log.i(TAG, "Incoming Hf accepted");
broadcastConnectionState(device, BluetoothProfile.STATE_CONNECTED,
- BluetoothProfile.STATE_DISCONNECTED);
+ BluetoothProfile.STATE_DISCONNECTED);
synchronized (HeadsetStateMachine.this) {
- if(!mConnectedDevicesList.contains(device)) {
+ if (!mConnectedDevicesList.contains(device)) {
mCurrentDevice = device;
mConnectedDevicesList.add(device);
- Log.d(TAG, "device " + device.getAddress() +
- " is added in Connected state");
+ Log.d(TAG, "device " + device.getAddress()
+ + " is added in Connected state");
}
transitionTo(mConnected);
}
configAudioParameters(device);
} else {
// reject the connection and stay in Connected state itself
- Log.i(TAG,"Incoming Hf rejected. priority=" +
- mService.getPriority(device) + " bondState=" +
- device.getBondState());
+ Log.i(TAG, "Incoming Hf rejected. priority=" + mService.getPriority(device)
+ + " bondState=" + device.getBondState());
disconnectHfpNative(getByteAddress(device));
}
break;
default:
- Log.e(TAG, "Connection State Device: " + device + " bad state: " + state);
+ Log.e(TAG, "Connection State Device: " + device + " bad state: " + state);
break;
}
}
switch (state) {
case HeadsetHalConstants.AUDIO_STATE_CONNECTED:
if (!isScoAcceptable()) {
- Log.e(TAG,"Audio Connected without any listener");
+ Log.e(TAG, "Audio Connected without any listener");
disconnectAudioNative(getByteAddress(device));
break;
}
setAudioParameters(device); /*Set proper Audio Paramters.*/
mAudioManager.setBluetoothScoOn(true);
broadcastAudioState(device, BluetoothHeadset.STATE_AUDIO_CONNECTED,
- BluetoothHeadset.STATE_AUDIO_CONNECTING);
+ BluetoothHeadset.STATE_AUDIO_CONNECTING);
mActiveScoDevice = device;
transitionTo(mAudioOn);
break;
case HeadsetHalConstants.AUDIO_STATE_CONNECTING:
mAudioState = BluetoothHeadset.STATE_AUDIO_CONNECTING;
broadcastAudioState(device, BluetoothHeadset.STATE_AUDIO_CONNECTING,
- BluetoothHeadset.STATE_AUDIO_DISCONNECTED);
+ BluetoothHeadset.STATE_AUDIO_DISCONNECTED);
break;
- // TODO(BT) process other states
+ // TODO(BT) process other states
default:
Log.e(TAG, "Audio State Device: " + device + " bad state: " + state);
break;
} else {
Log.e(TAG, "Handsfree phone proxy null for query phone state");
}
-
}
private void processMultiHFConnected(BluetoothDevice device) {
log("Connect state: processMultiHFConnected");
if (mActiveScoDevice != null && mActiveScoDevice.equals(device)) {
- log ("mActiveScoDevice is disconnected, setting it to null");
+ log("mActiveScoDevice is disconnected, setting it to null");
mActiveScoDevice = null;
}
/* Assign the current activedevice again if the disconnected
if (mCurrentDevice != null && mCurrentDevice.equals(device)) {
transitionTo(mConnected);
int deviceSize = mConnectedDevicesList.size();
- mCurrentDevice = mConnectedDevicesList.get(deviceSize-1);
+ mCurrentDevice = mConnectedDevicesList.get(deviceSize - 1);
} else {
// The disconnected device is not current active device
transitionTo(mConnected);
}
- log("processMultiHFConnected , the latest mCurrentDevice is:" +
- mCurrentDevice);
- log("Connect state: processMultiHFConnected ," +
- "fake broadcasting for mCurrentDevice");
+ log("processMultiHFConnected , the latest mCurrentDevice is:" + mCurrentDevice);
+ log("Connect state: processMultiHFConnected ,"
+ + "fake broadcasting for mCurrentDevice");
broadcastConnectionState(mCurrentDevice, BluetoothProfile.STATE_CONNECTED,
- BluetoothProfile.STATE_DISCONNECTED);
+ BluetoothProfile.STATE_DISCONNECTED);
}
}
private class AudioOn extends State {
-
@Override
public void enter() {
- log("Enter AudioOn: " + getCurrentMessage().what + ", size: " +
- mConnectedDevicesList.size());
+ log("Enter AudioOn: " + getCurrentMessage().what + ", size: "
+ + mConnectedDevicesList.size());
}
@Override
public boolean processMessage(Message message) {
- log("AudioOn process message: " + message.what + ", size: " +
- mConnectedDevicesList.size());
+ log("AudioOn process message: " + message.what + ", size: "
+ + mConnectedDevicesList.size());
if (DBG) {
if (mConnectedDevicesList.size() == 0) {
log("ERROR: mConnectedDevicesList is empty in AudioOn");
}
boolean retValue = HANDLED;
- switch(message.what) {
- case CONNECT:
- {
+ switch (message.what) {
+ case CONNECT: {
BluetoothDevice device = (BluetoothDevice) message.obj;
if (device == null) {
break;
if (mConnectedDevicesList.size() >= max_hf_connections) {
BluetoothDevice DisconnectConnectedDevice = null;
IState CurrentAudioState = getCurrentState();
- Log.d(TAG, "Reach to max size, disconnect " +
- "one of them first");
+ Log.d(TAG, "Reach to max size, disconnect "
+ + "one of them first");
DisconnectConnectedDevice = mConnectedDevicesList.get(0);
if (mActiveScoDevice.equals(DisconnectConnectedDevice)) {
- DisconnectConnectedDevice = mConnectedDevicesList.get(1);
+ DisconnectConnectedDevice = mConnectedDevicesList.get(1);
}
broadcastConnectionState(device, BluetoothProfile.STATE_CONNECTING,
- BluetoothProfile.STATE_DISCONNECTED);
+ BluetoothProfile.STATE_DISCONNECTED);
if (!disconnectHfpNative(getByteAddress(DisconnectConnectedDevice))) {
broadcastConnectionState(device, BluetoothProfile.STATE_DISCONNECTED,
- BluetoothProfile.STATE_CONNECTING);
+ BluetoothProfile.STATE_CONNECTING);
break;
} else {
broadcastConnectionState(DisconnectConnectedDevice,
- BluetoothProfile.STATE_DISCONNECTING,
- BluetoothProfile.STATE_CONNECTED);
+ BluetoothProfile.STATE_DISCONNECTING,
+ BluetoothProfile.STATE_CONNECTED);
}
synchronized (HeadsetStateMachine.this) {
transitionTo(mMultiHFPending);
DisconnectConnectedDevice = null;
}
- } else if(mConnectedDevicesList.size() < max_hf_connections) {
+ } else if (mConnectedDevicesList.size() < max_hf_connections) {
broadcastConnectionState(device, BluetoothProfile.STATE_CONNECTING,
- BluetoothProfile.STATE_DISCONNECTED);
+ BluetoothProfile.STATE_DISCONNECTED);
if (!connectHfpNative(getByteAddress(device))) {
broadcastConnectionState(device, BluetoothProfile.STATE_DISCONNECTED,
- BluetoothProfile.STATE_CONNECTING);
+ BluetoothProfile.STATE_CONNECTING);
break;
}
synchronized (HeadsetStateMachine.this) {
Message m = obtainMessage(CONNECT_TIMEOUT);
m.obj = device;
sendMessageDelayed(m, 30000);
- }
- break;
+ } break;
case CONNECT_TIMEOUT:
onConnectionStateChanged(HeadsetHalConstants.CONNECTION_STATE_DISCONNECTED,
- getByteAddress(mTargetDevice));
- break;
- case DISCONNECT:
- {
- BluetoothDevice device = (BluetoothDevice)message.obj;
+ getByteAddress(mTargetDevice));
+ break;
+ case DISCONNECT: {
+ BluetoothDevice device = (BluetoothDevice) message.obj;
if (!mConnectedDevicesList.contains(device)) {
break;
}
if (mActiveScoDevice != null && mActiveScoDevice.equals(device)) {
// The disconnected device is active SCO device
- Log.d(TAG, "AudioOn, the disconnected device" +
- "is active SCO device");
+ Log.d(TAG, "AudioOn, the disconnected device"
+ + "is active SCO device");
deferMessage(obtainMessage(DISCONNECT, message.obj));
// Disconnect BT SCO first
if (disconnectAudioNative(getByteAddress(mActiveScoDevice))) {
} else {
/* Do not disconnect BT SCO if the disconnected
device is not active SCO device */
- Log.d(TAG, "AudioOn, the disconnected device" +
- "is not active SCO device");
+ Log.d(TAG, "AudioOn, the disconnected device"
+ + "is not active SCO device");
broadcastConnectionState(device, BluetoothProfile.STATE_DISCONNECTING,
- BluetoothProfile.STATE_CONNECTED);
+ BluetoothProfile.STATE_CONNECTED);
// Should be still in AudioOn state
if (!disconnectHfpNative(getByteAddress(device))) {
Log.w(TAG, "AudioOn, disconnect device failed");
broadcastConnectionState(device, BluetoothProfile.STATE_CONNECTED,
- BluetoothProfile.STATE_DISCONNECTING);
+ BluetoothProfile.STATE_DISCONNECTING);
break;
}
/* Transtion to MultiHFPending state for Multi
transitionTo(mMultiHFPending);
}
}
- }
- break;
+ } break;
case DISCONNECT_AUDIO:
if (mActiveScoDevice != null) {
if (disconnectAudioNative(getByteAddress(mActiveScoDevice))) {
- log("Disconnecting SCO audio for device = " +
- mActiveScoDevice);
+ log("Disconnecting SCO audio for device = " + mActiveScoDevice);
} else {
- Log.e(TAG, "disconnectAudioNative failed" +
- "for device = " + mActiveScoDevice);
+ Log.e(TAG, "disconnectAudioNative failed"
+ + "for device = " + mActiveScoDevice);
}
}
break;
}
break;
case CALL_STATE_CHANGED:
- processCallState((HeadsetCallState) message.obj, ((message.arg1 == 1)?true:false));
+ processCallState((HeadsetCallState) message.obj, message.arg1 == 1);
break;
case INTENT_BATTERY_CHANGED:
processIntentBatteryChanged((Intent) message.obj);
case SEND_CCLC_RESPONSE:
processSendClccResponse((HeadsetClccResponse) message.obj);
break;
- case CLCC_RSP_TIMEOUT:
- {
+ case CLCC_RSP_TIMEOUT: {
BluetoothDevice device = (BluetoothDevice) message.obj;
clccResponseNative(0, 0, 0, 0, false, "", 0, getByteAddress(device));
- }
break;
+ }
case SEND_VENDOR_SPECIFIC_RESULT_CODE:
processSendVendorSpecificResultCode(
(HeadsetVendorSpecificResultCode) message.obj);
terminateScoUsingVirtualVoiceCall();
break;
- case DIALING_OUT_TIMEOUT:
- {
+ case DIALING_OUT_TIMEOUT: {
if (mDialingOut) {
- BluetoothDevice device = (BluetoothDevice)message.obj;
- mDialingOut= false;
- atResponseCodeNative(HeadsetHalConstants.AT_RESPONSE_ERROR,
- 0, getByteAddress(device));
+ BluetoothDevice device = (BluetoothDevice) message.obj;
+ mDialingOut = false;
+ atResponseCodeNative(
+ HeadsetHalConstants.AT_RESPONSE_ERROR, 0, getByteAddress(device));
}
- }
break;
- case START_VR_TIMEOUT:
- {
+ }
+ case START_VR_TIMEOUT: {
if (mWaitingForVoiceRecognition) {
- BluetoothDevice device = (BluetoothDevice)message.obj;
+ BluetoothDevice device = (BluetoothDevice) message.obj;
mWaitingForVoiceRecognition = false;
- Log.e(TAG, "Timeout waiting for voice recognition" +
- "to start");
- atResponseCodeNative(HeadsetHalConstants.AT_RESPONSE_ERROR,
- 0, getByteAddress(device));
+ Log.e(TAG, "Timeout waiting for voice recognition"
+ + "to start");
+ atResponseCodeNative(
+ HeadsetHalConstants.AT_RESPONSE_ERROR, 0, getByteAddress(device));
}
- }
break;
+ }
case STACK_EVENT:
StackEvent event = (StackEvent) message.obj;
if (DBG) {
processHangupCall(event.device);
break;
case EVENT_TYPE_VOLUME_CHANGED:
- processVolumeEvent(event.valueInt, event.valueInt2,
- event.device);
+ processVolumeEvent(event.valueInt, event.valueInt2, event.device);
break;
case EVENT_TYPE_DIAL_CALL:
processDialCall(event.valueString, event.device);
// in AudioOn state. Some headsets disconnect RFCOMM prior to SCO down. Handle this
private void processConnectionEvent(int state, BluetoothDevice device) {
- Log.d(TAG, "processConnectionEvent state = " + state + ", device = " +
- device);
+ Log.d(TAG, "processConnectionEvent state = " + state + ", device = " + device);
switch (state) {
case HeadsetHalConstants.CONNECTION_STATE_DISCONNECTED:
if (mConnectedDevicesList.contains(device)) {
- if (mActiveScoDevice != null
- && mActiveScoDevice.equals(device)&& mAudioState
- != BluetoothHeadset.STATE_AUDIO_DISCONNECTED) {
- processAudioEvent(
- HeadsetHalConstants.AUDIO_STATE_DISCONNECTED, device);
+ if (mActiveScoDevice != null && mActiveScoDevice.equals(device)
+ && mAudioState != BluetoothHeadset.STATE_AUDIO_DISCONNECTED) {
+ processAudioEvent(HeadsetHalConstants.AUDIO_STATE_DISCONNECTED, device);
}
synchronized (HeadsetStateMachine.this) {
mConnectedDevicesList.remove(device);
mHeadsetAudioParam.remove(device);
mHeadsetBrsf.remove(device);
- Log.d(TAG, "device " + device.getAddress() +
- " is removed in AudioOn state");
+ Log.d(TAG, "device " + device.getAddress()
+ + " is removed in AudioOn state");
broadcastConnectionState(device, BluetoothProfile.STATE_DISCONNECTED,
- BluetoothProfile.STATE_CONNECTED);
+ BluetoothProfile.STATE_CONNECTED);
processWBSEvent(0, device); /* disable WBS audio parameters */
if (mConnectedDevicesList.size() == 0) {
transitionTo(mDisconnected);
- }
- else {
+ } else {
processMultiHFConnected(device);
}
}
Log.e(TAG, "Disconnected from unknown device: " + device);
}
break;
- case HeadsetHalConstants.CONNECTION_STATE_SLC_CONNECTED:
+ case HeadsetHalConstants.CONNECTION_STATE_SLC_CONNECTED:
processSlcConnected();
break;
case HeadsetHalConstants.CONNECTION_STATE_CONNECTED:
break;
}
Log.w(TAG, "HFP to be Connected in AudioOn state");
- if (okToConnect(device) && (mConnectedDevicesList.size()
- < max_hf_connections) ) {
- Log.i(TAG,"Incoming Hf accepted");
+ if (okToConnect(device)
+ && (mConnectedDevicesList.size() < max_hf_connections)) {
+ Log.i(TAG, "Incoming Hf accepted");
broadcastConnectionState(device, BluetoothProfile.STATE_CONNECTED,
- BluetoothProfile.STATE_DISCONNECTED);
+ BluetoothProfile.STATE_DISCONNECTED);
synchronized (HeadsetStateMachine.this) {
if (!mConnectedDevicesList.contains(device)) {
mCurrentDevice = device;
mConnectedDevicesList.add(device);
- Log.d(TAG, "device " + device.getAddress() +
- " is added in AudioOn state");
+ Log.d(TAG, "device " + device.getAddress()
+ + " is added in AudioOn state");
}
}
configAudioParameters(device);
- } else {
- // reject the connection and stay in Connected state itself
- Log.i(TAG,"Incoming Hf rejected. priority="
- + mService.getPriority(device) +
- " bondState=" + device.getBondState());
- disconnectHfpNative(getByteAddress(device));
+ } else {
+ // reject the connection and stay in Connected state itself
+ Log.i(TAG, "Incoming Hf rejected. priority=" + mService.getPriority(device)
+ + " bondState=" + device.getBondState());
+ disconnectHfpNative(getByteAddress(device));
}
break;
default:
mAudioState = BluetoothHeadset.STATE_AUDIO_DISCONNECTED;
mAudioManager.setBluetoothScoOn(false);
broadcastAudioState(device, BluetoothHeadset.STATE_AUDIO_DISCONNECTED,
- BluetoothHeadset.STATE_AUDIO_CONNECTED);
+ BluetoothHeadset.STATE_AUDIO_CONNECTED);
}
transitionTo(mConnected);
break;
case HeadsetHalConstants.AUDIO_STATE_DISCONNECTING:
// TODO(BT) adding STATE_AUDIO_DISCONNECTING in BluetoothHeadset?
- //broadcastAudioState(device, BluetoothHeadset.STATE_AUDIO_DISCONNECTING,
+ // broadcastAudioState(device, BluetoothHeadset.STATE_AUDIO_DISCONNECTING,
// BluetoothHeadset.STATE_AUDIO_CONNECTED);
break;
default:
int volumeValue = intent.getIntExtra(AudioManager.EXTRA_VOLUME_STREAM_VALUE, 0);
if (mPhoneState.getSpeakerVolume() != volumeValue) {
mPhoneState.setSpeakerVolume(volumeValue);
- setVolumeNative(HeadsetHalConstants.VOLUME_TYPE_SPK,
- volumeValue, getByteAddress(device));
+ setVolumeNative(
+ HeadsetHalConstants.VOLUME_TYPE_SPK, volumeValue, getByteAddress(device));
}
}
device equals to the current active device */
if (mCurrentDevice != null && mCurrentDevice.equals(device)) {
int deviceSize = mConnectedDevicesList.size();
- mCurrentDevice = mConnectedDevicesList.get(deviceSize-1);
+ mCurrentDevice = mConnectedDevicesList.get(deviceSize - 1);
}
- if (mAudioState != BluetoothHeadset.STATE_AUDIO_CONNECTED)
- transitionTo(mConnected);
+ if (mAudioState != BluetoothHeadset.STATE_AUDIO_CONNECTED) transitionTo(mConnected);
- log("processMultiHFConnected , the latest mCurrentDevice is:"
- + mCurrentDevice);
- log("AudioOn state: processMultiHFConnected ," +
- "fake broadcasting for mCurrentDevice");
+ log("processMultiHFConnected , the latest mCurrentDevice is:" + mCurrentDevice);
+ log("AudioOn state: processMultiHFConnected ,"
+ + "fake broadcasting for mCurrentDevice");
broadcastConnectionState(mCurrentDevice, BluetoothProfile.STATE_CONNECTED,
- BluetoothProfile.STATE_DISCONNECTED);
+ BluetoothProfile.STATE_DISCONNECTED);
}
}
private class MultiHFPending extends State {
@Override
public void enter() {
- log("Enter MultiHFPending: " + getCurrentMessage().what +
- ", size: " + mConnectedDevicesList.size());
+ log("Enter MultiHFPending: " + getCurrentMessage().what + ", size: "
+ + mConnectedDevicesList.size());
}
@Override
public boolean processMessage(Message message) {
- log("MultiHFPending process message: " + message.what +
- ", size: " + mConnectedDevicesList.size());
+ log("MultiHFPending process message: " + message.what + ", size: "
+ + mConnectedDevicesList.size());
boolean retValue = HANDLED;
- switch(message.what) {
+ switch (message.what) {
case CONNECT:
deferMessage(message);
break;
break;
case CONNECT_TIMEOUT:
onConnectionStateChanged(HeadsetHalConstants.CONNECTION_STATE_DISCONNECTED,
- getByteAddress(mTargetDevice));
+ getByteAddress(mTargetDevice));
break;
case DISCONNECT_AUDIO:
if (mActiveScoDevice != null) {
if (disconnectAudioNative(getByteAddress(mActiveScoDevice))) {
- Log.d(TAG, "MultiHFPending, Disconnecting SCO audio for " +
- mActiveScoDevice);
+ Log.d(TAG, "MultiHFPending, Disconnecting SCO audio for "
+ + mActiveScoDevice);
} else {
- Log.e(TAG, "disconnectAudioNative failed" +
- "for device = " + mActiveScoDevice);
+ Log.e(TAG, "disconnectAudioNative failed"
+ + "for device = " + mActiveScoDevice);
}
}
break;
case DISCONNECT:
BluetoothDevice device = (BluetoothDevice) message.obj;
- if (mConnectedDevicesList.contains(device) &&
- mTargetDevice != null && mTargetDevice.equals(device)) {
+ if (mConnectedDevicesList.contains(device) && mTargetDevice != null
+ && mTargetDevice.equals(device)) {
// cancel connection to the mTargetDevice
- broadcastConnectionState(device,
- BluetoothProfile.STATE_DISCONNECTED,
- BluetoothProfile.STATE_CONNECTING);
+ broadcastConnectionState(device, BluetoothProfile.STATE_DISCONNECTED,
+ BluetoothProfile.STATE_CONNECTING);
synchronized (HeadsetStateMachine.this) {
mTargetDevice = null;
}
processIntentBatteryChanged((Intent) message.obj);
break;
case CALL_STATE_CHANGED:
- processCallState((HeadsetCallState) message.obj,
- ((message.arg1 == 1)?true:false));
+ processCallState((HeadsetCallState) message.obj, message.arg1 == 1);
break;
case DEVICE_STATE_CHANGED:
processDeviceStateChanged((HeadsetDeviceState) message.obj);
case SEND_CCLC_RESPONSE:
processSendClccResponse((HeadsetClccResponse) message.obj);
break;
- case CLCC_RSP_TIMEOUT:
- {
+ case CLCC_RSP_TIMEOUT: {
device = (BluetoothDevice) message.obj;
clccResponseNative(0, 0, 0, 0, false, "", 0, getByteAddress(device));
- }
- break;
+ } break;
case DIALING_OUT_TIMEOUT:
if (mDialingOut) {
device = (BluetoothDevice) message.obj;
- mDialingOut= false;
- atResponseCodeNative(HeadsetHalConstants.AT_RESPONSE_ERROR,
- 0, getByteAddress(device));
+ mDialingOut = false;
+ atResponseCodeNative(
+ HeadsetHalConstants.AT_RESPONSE_ERROR, 0, getByteAddress(device));
}
break;
case VIRTUAL_CALL_START:
device = (BluetoothDevice) message.obj;
- if(mConnectedDevicesList.contains(device)) {
+ if (mConnectedDevicesList.contains(device)) {
initiateScoUsingVirtualVoiceCall();
}
break;
if (mWaitingForVoiceRecognition) {
device = (BluetoothDevice) message.obj;
mWaitingForVoiceRecognition = false;
- Log.e(TAG, "Timeout waiting for voice" +
- "recognition to start");
- atResponseCodeNative(HeadsetHalConstants.AT_RESPONSE_ERROR,
- 0, getByteAddress(device));
+ Log.e(TAG, "Timeout waiting for voice"
+ + "recognition to start");
+ atResponseCodeNative(
+ HeadsetHalConstants.AT_RESPONSE_ERROR, 0, getByteAddress(device));
}
break;
case STACK_EVENT:
processAudioEvent(event.valueInt, event.device);
break;
case EVENT_TYPE_VR_STATE_CHANGED:
- processVrEvent(event.valueInt,event.device);
+ processVrEvent(event.valueInt, event.device);
break;
case EVENT_TYPE_ANSWER_CALL:
- //TODO(BT) could answer call happen on Connected state?
+ // TODO(BT) could answer call happen on Connected state?
processAnswerCall(event.device);
break;
case EVENT_TYPE_HANGUP_CALL:
processHangupCall(event.device);
break;
case EVENT_TYPE_VOLUME_CHANGED:
- processVolumeEvent(event.valueInt, event.valueInt2,
- event.device);
+ processVolumeEvent(event.valueInt, event.valueInt2, event.device);
break;
case EVENT_TYPE_DIAL_CALL:
processDialCall(event.valueString, event.device);
processAtClcc(event.device);
break;
case EVENT_TYPE_UNKNOWN_AT:
- processUnknownAt(event.valueString,event.device);
+ processUnknownAt(event.valueString, event.device);
break;
case EVENT_TYPE_KEY_PRESSED:
processKeyPressed(event.device);
// in MultiHFPending state
private void processConnectionEvent(int state, BluetoothDevice device) {
- Log.d(TAG, "processConnectionEvent state = " + state +
- ", device = " + device);
+ Log.d(TAG, "processConnectionEvent state = " + state + ", device = " + device);
switch (state) {
case HeadsetHalConstants.CONNECTION_STATE_DISCONNECTED:
if (mConnectedDevicesList.contains(device)) {
- if (mMultiDisconnectDevice != null &&
- mMultiDisconnectDevice.equals(device)) {
+ if (mMultiDisconnectDevice != null
+ && mMultiDisconnectDevice.equals(device)) {
mMultiDisconnectDevice = null;
- synchronized (HeadsetStateMachine.this) {
- mConnectedDevicesList.remove(device);
- mHeadsetAudioParam.remove(device);
- mHeadsetBrsf.remove(device);
- Log.d(TAG, "device " + device.getAddress() +
- " is removed in MultiHFPending state");
- broadcastConnectionState(device,
+ synchronized (HeadsetStateMachine.this) {
+ mConnectedDevicesList.remove(device);
+ mHeadsetAudioParam.remove(device);
+ mHeadsetBrsf.remove(device);
+ Log.d(TAG, "device " + device.getAddress()
+ + " is removed in MultiHFPending state");
+ broadcastConnectionState(device,
BluetoothProfile.STATE_DISCONNECTED,
BluetoothProfile.STATE_DISCONNECTING);
- }
-
- if (mTargetDevice != null) {
- if (!connectHfpNative(getByteAddress(mTargetDevice))) {
+ }
- broadcastConnectionState(mTargetDevice,
- BluetoothProfile.STATE_DISCONNECTED,
- BluetoothProfile.STATE_CONNECTING);
- synchronized (HeadsetStateMachine.this) {
- mTargetDevice = null;
- if (mConnectedDevicesList.size() == 0) {
- // Should be not in this state since it has at least
- // one HF connected in MultiHFPending state
- Log.d(TAG, "Should be not in this state, error handling");
- transitionTo(mDisconnected);
- }
- else {
- processMultiHFConnected(device);
- }
- }
- }
- } else {
- synchronized (HeadsetStateMachine.this) {
- mIncomingDevice = null;
- if (mConnectedDevicesList.size() == 0) {
- transitionTo(mDisconnected);
- }
- else {
- processMultiHFConnected(device);
- }
- }
- }
+ if (mTargetDevice != null) {
+ if (!connectHfpNative(getByteAddress(mTargetDevice))) {
+ broadcastConnectionState(mTargetDevice,
+ BluetoothProfile.STATE_DISCONNECTED,
+ BluetoothProfile.STATE_CONNECTING);
+ synchronized (HeadsetStateMachine.this) {
+ mTargetDevice = null;
+ if (mConnectedDevicesList.size() == 0) {
+ // Should be not in this state since it has at least
+ // one HF connected in MultiHFPending state
+ Log.d(TAG,
+ "Should be not in this state, error handling");
+ transitionTo(mDisconnected);
+ } else {
+ processMultiHFConnected(device);
+ }
+ }
+ }
+ } else {
+ synchronized (HeadsetStateMachine.this) {
+ mIncomingDevice = null;
+ if (mConnectedDevicesList.size() == 0) {
+ transitionTo(mDisconnected);
+ } else {
+ processMultiHFConnected(device);
+ }
+ }
+ }
} else {
/* Another HF disconnected when one HF is connecting */
synchronized (HeadsetStateMachine.this) {
- mConnectedDevicesList.remove(device);
- mHeadsetAudioParam.remove(device);
- mHeadsetBrsf.remove(device);
- Log.d(TAG, "device " + device.getAddress() +
- " is removed in MultiHFPending state");
+ mConnectedDevicesList.remove(device);
+ mHeadsetAudioParam.remove(device);
+ mHeadsetBrsf.remove(device);
+ Log.d(TAG, "device " + device.getAddress()
+ + " is removed in MultiHFPending state");
}
- broadcastConnectionState(device,
- BluetoothProfile.STATE_DISCONNECTED,
- BluetoothProfile.STATE_CONNECTED);
+ broadcastConnectionState(device, BluetoothProfile.STATE_DISCONNECTED,
+ BluetoothProfile.STATE_CONNECTED);
}
} else if (mTargetDevice != null && mTargetDevice.equals(device)) {
-
broadcastConnectionState(mTargetDevice, BluetoothProfile.STATE_DISCONNECTED,
- BluetoothProfile.STATE_CONNECTING);
+ BluetoothProfile.STATE_CONNECTING);
synchronized (HeadsetStateMachine.this) {
mTargetDevice = null;
if (mConnectedDevicesList.size() == 0) {
transitionTo(mDisconnected);
- }
- else
- {
- if (mAudioState == BluetoothHeadset.STATE_AUDIO_CONNECTED)
- transitionTo(mAudioOn);
- else transitionTo(mConnected);
+ } else {
+ if (mAudioState == BluetoothHeadset.STATE_AUDIO_CONNECTED)
+ transitionTo(mAudioOn);
+ else
+ transitionTo(mConnected);
}
}
} else {
Log.e(TAG, "Unknown device Disconnected: " + device);
}
break;
- case HeadsetHalConstants.CONNECTION_STATE_CONNECTED:
- /* Outgoing disconnection for device failed */
- if (mConnectedDevicesList.contains(device)) {
-
- broadcastConnectionState(device, BluetoothProfile.STATE_CONNECTED,
- BluetoothProfile.STATE_DISCONNECTING);
- if (mTargetDevice != null) {
- broadcastConnectionState(mTargetDevice, BluetoothProfile.STATE_DISCONNECTED,
- BluetoothProfile.STATE_CONNECTING);
- }
- synchronized (HeadsetStateMachine.this) {
- mTargetDevice = null;
- if (mAudioState == BluetoothHeadset.STATE_AUDIO_CONNECTED)
- transitionTo(mAudioOn);
- else transitionTo(mConnected);
- }
- } else if (mTargetDevice != null && mTargetDevice.equals(device)) {
-
- synchronized (HeadsetStateMachine.this) {
+ case HeadsetHalConstants.CONNECTION_STATE_CONNECTED:
+ /* Outgoing disconnection for device failed */
+ if (mConnectedDevicesList.contains(device)) {
+ broadcastConnectionState(device, BluetoothProfile.STATE_CONNECTED,
+ BluetoothProfile.STATE_DISCONNECTING);
+ if (mTargetDevice != null) {
+ broadcastConnectionState(mTargetDevice,
+ BluetoothProfile.STATE_DISCONNECTED,
+ BluetoothProfile.STATE_CONNECTING);
+ }
+ synchronized (HeadsetStateMachine.this) {
+ mTargetDevice = null;
+ if (mAudioState == BluetoothHeadset.STATE_AUDIO_CONNECTED)
+ transitionTo(mAudioOn);
+ else
+ transitionTo(mConnected);
+ }
+ } else if (mTargetDevice != null && mTargetDevice.equals(device)) {
+ synchronized (HeadsetStateMachine.this) {
mCurrentDevice = device;
mConnectedDevicesList.add(device);
- Log.d(TAG, "device " + device.getAddress() +
- " is added in MultiHFPending state");
+ Log.d(TAG, "device " + device.getAddress()
+ + " is added in MultiHFPending state");
mTargetDevice = null;
if (mAudioState == BluetoothHeadset.STATE_AUDIO_CONNECTED)
transitionTo(mAudioOn);
- else transitionTo(mConnected);
- }
+ else
+ transitionTo(mConnected);
+ }
- broadcastConnectionState(device, BluetoothProfile.STATE_CONNECTED,
- BluetoothProfile.STATE_CONNECTING);
- configAudioParameters(device);
- } else {
- Log.w(TAG, "Some other incoming HF connected" +
- "in Multi Pending state");
- if (okToConnect(device) &&
- (mConnectedDevicesList.size() < max_hf_connections)) {
- Log.i(TAG,"Incoming Hf accepted");
broadcastConnectionState(device, BluetoothProfile.STATE_CONNECTED,
- BluetoothProfile.STATE_DISCONNECTED);
- synchronized (HeadsetStateMachine.this) {
- if (!mConnectedDevicesList.contains(device)) {
- mCurrentDevice = device;
- mConnectedDevicesList.add(device);
- Log.d(TAG, "device " + device.getAddress() +
- " is added in MultiHFPending state");
- }
- }
+ BluetoothProfile.STATE_CONNECTING);
configAudioParameters(device);
} else {
- // reject the connection and stay in Pending state itself
- Log.i(TAG,"Incoming Hf rejected. priority=" +
- mService.getPriority(device) +
- " bondState=" + device.getBondState());
- disconnectHfpNative(getByteAddress(device));
+ Log.w(TAG, "Some other incoming HF connected"
+ + "in Multi Pending state");
+ if (okToConnect(device)
+ && (mConnectedDevicesList.size() < max_hf_connections)) {
+ Log.i(TAG, "Incoming Hf accepted");
+ broadcastConnectionState(device, BluetoothProfile.STATE_CONNECTED,
+ BluetoothProfile.STATE_DISCONNECTED);
+ synchronized (HeadsetStateMachine.this) {
+ if (!mConnectedDevicesList.contains(device)) {
+ mCurrentDevice = device;
+ mConnectedDevicesList.add(device);
+ Log.d(TAG, "device " + device.getAddress()
+ + " is added in MultiHFPending state");
+ }
+ }
+ configAudioParameters(device);
+ } else {
+ // reject the connection and stay in Pending state itself
+ Log.i(TAG, "Incoming Hf rejected. priority="
+ + mService.getPriority(device) + " bondState="
+ + device.getBondState());
+ disconnectHfpNative(getByteAddress(device));
+ }
}
- }
- break;
- case HeadsetHalConstants.CONNECTION_STATE_SLC_CONNECTED:
- processSlcConnected();
- break;
- case HeadsetHalConstants.CONNECTION_STATE_CONNECTING:
- if (mConnectedDevicesList.contains(device)) {
- Log.e(TAG, "current device tries to connect back");
- } else if (mTargetDevice != null && mTargetDevice.equals(device)) {
- if (DBG) {
- log("Stack and target device are connecting");
+ break;
+ case HeadsetHalConstants.CONNECTION_STATE_SLC_CONNECTED:
+ processSlcConnected();
+ break;
+ case HeadsetHalConstants.CONNECTION_STATE_CONNECTING:
+ if (mConnectedDevicesList.contains(device)) {
+ Log.e(TAG, "current device tries to connect back");
+ } else if (mTargetDevice != null && mTargetDevice.equals(device)) {
+ if (DBG) {
+ log("Stack and target device are connecting");
+ }
+ } else if (mIncomingDevice != null && mIncomingDevice.equals(device)) {
+ Log.e(TAG, "Another connecting event on"
+ + "the incoming device");
}
- }
- else if (mIncomingDevice != null && mIncomingDevice.equals(device)) {
- Log.e(TAG, "Another connecting event on" +
- "the incoming device");
- }
- break;
- case HeadsetHalConstants.CONNECTION_STATE_DISCONNECTING:
- if (mConnectedDevicesList.contains(device)) {
- if (DBG) {
- log("stack is disconnecting mCurrentDevice");
+ break;
+ case HeadsetHalConstants.CONNECTION_STATE_DISCONNECTING:
+ if (mConnectedDevicesList.contains(device)) {
+ if (DBG) {
+ log("stack is disconnecting mCurrentDevice");
+ }
+ } else if (mTargetDevice != null && mTargetDevice.equals(device)) {
+ Log.e(TAG, "TargetDevice is getting disconnected");
+ } else if (mIncomingDevice != null && mIncomingDevice.equals(device)) {
+ Log.e(TAG, "IncomingDevice is getting disconnected");
+ } else {
+ Log.e(TAG, "Disconnecting unknow device: " + device);
}
- } else if (mTargetDevice != null && mTargetDevice.equals(device)) {
- Log.e(TAG, "TargetDevice is getting disconnected");
- } else if (mIncomingDevice != null && mIncomingDevice.equals(device)) {
- Log.e(TAG, "IncomingDevice is getting disconnected");
- } else {
- Log.e(TAG, "Disconnecting unknow device: " + device);
- }
- break;
- default:
- Log.e(TAG, "Incorrect state: " + state);
- break;
+ break;
+ default:
+ Log.e(TAG, "Incorrect state: " + state);
+ break;
}
}
switch (state) {
case HeadsetHalConstants.AUDIO_STATE_CONNECTED:
if (!isScoAcceptable()) {
- Log.e(TAG,"Audio Connected without any listener");
+ Log.e(TAG, "Audio Connected without any listener");
disconnectAudioNative(getByteAddress(device));
break;
}
case HeadsetHalConstants.AUDIO_STATE_CONNECTING:
mAudioState = BluetoothHeadset.STATE_AUDIO_CONNECTING;
broadcastAudioState(device, BluetoothHeadset.STATE_AUDIO_CONNECTING,
- BluetoothHeadset.STATE_AUDIO_DISCONNECTED);
+ BluetoothHeadset.STATE_AUDIO_DISCONNECTED);
break;
case HeadsetHalConstants.AUDIO_STATE_DISCONNECTED:
if (mAudioState != BluetoothHeadset.STATE_AUDIO_DISCONNECTED) {
mAudioState = BluetoothHeadset.STATE_AUDIO_DISCONNECTED;
mAudioManager.setBluetoothScoOn(false);
broadcastAudioState(device, BluetoothHeadset.STATE_AUDIO_DISCONNECTED,
- BluetoothHeadset.STATE_AUDIO_CONNECTED);
+ BluetoothHeadset.STATE_AUDIO_CONNECTED);
}
/* The state should be still in MultiHFPending state when audio
disconnected since other device is still connecting/
}
}
-
private void processMultiHFConnected(BluetoothDevice device) {
log("MultiHFPending state: processMultiHFConnected");
if (mActiveScoDevice != null && mActiveScoDevice.equals(device)) {
- log ("mActiveScoDevice is disconnected, setting it to null");
+ log("mActiveScoDevice is disconnected, setting it to null");
mActiveScoDevice = null;
}
/* Assign the current activedevice again if the disconnected
device equals to the current active device */
if (mCurrentDevice != null && mCurrentDevice.equals(device)) {
int deviceSize = mConnectedDevicesList.size();
- mCurrentDevice = mConnectedDevicesList.get(deviceSize-1);
+ mCurrentDevice = mConnectedDevicesList.get(deviceSize - 1);
}
// The disconnected device is not current active device
if (mAudioState == BluetoothHeadset.STATE_AUDIO_CONNECTED)
transitionTo(mAudioOn);
- else transitionTo(mConnected);
- log("processMultiHFConnected , the latest mCurrentDevice is:"
- + mCurrentDevice);
- log("MultiHFPending state: processMultiHFConnected ," +
- "fake broadcasting for mCurrentDevice");
+ else
+ transitionTo(mConnected);
+ log("processMultiHFConnected , the latest mCurrentDevice is:" + mCurrentDevice);
+ log("MultiHFPending state: processMultiHFConnected ,"
+ + "fake broadcasting for mCurrentDevice");
broadcastConnectionState(mCurrentDevice, BluetoothProfile.STATE_CONNECTED,
- BluetoothProfile.STATE_DISCONNECTED);
+ BluetoothProfile.STATE_DISCONNECTED);
}
private void processIntentScoVolume(Intent intent, BluetoothDevice device) {
int volumeValue = intent.getIntExtra(AudioManager.EXTRA_VOLUME_STREAM_VALUE, 0);
if (mPhoneState.getSpeakerVolume() != volumeValue) {
mPhoneState.setSpeakerVolume(volumeValue);
- setVolumeNative(HeadsetHalConstants.VOLUME_TYPE_SPK,
- volumeValue, getByteAddress(device));
+ setVolumeNative(
+ HeadsetHalConstants.VOLUME_TYPE_SPK, volumeValue, getByteAddress(device));
}
}
}
-
private ServiceConnection mConnection = new ServiceConnection() {
public void onServiceConnected(ComponentName className, IBinder service) {
if (DBG) Log.d(TAG, "Proxy object connected");
return BluetoothProfile.STATE_CONNECTING; // incoming connection
}
if (mConnectedDevicesList.contains(device)) {
- if ((mMultiDisconnectDevice != null) &&
- (!mMultiDisconnectDevice.equals(device))) {
+ if ((mMultiDisconnectDevice != null)
+ && (!mMultiDisconnectDevice.equals(device))) {
// The device is still connected
return BluetoothProfile.STATE_CONNECTED;
}
List<BluetoothDevice> getConnectedDevices() {
List<BluetoothDevice> devices = new ArrayList<BluetoothDevice>();
- synchronized(this) {
+ synchronized (this) {
for (int i = 0; i < mConnectedDevicesList.size(); i++)
devices.add(mConnectedDevicesList.get(i));
- }
+ }
return devices;
}
}
boolean isAudioConnected(BluetoothDevice device) {
- synchronized(this) {
-
+ synchronized (this) {
/* Additional check for audio state included for the case when PhoneApp queries
Bluetooth Audio state, before we receive the close event from the stack for the
sco disconnect issued in AudioOn state. This was causing a mismatch in the
Incall screen UI. */
if (getCurrentState() == mAudioOn && mCurrentDevice.equals(device)
- && mAudioState != BluetoothHeadset.STATE_AUDIO_DISCONNECTED)
- {
+ && mAudioState != BluetoothHeadset.STATE_AUDIO_DISCONNECTED) {
return true;
}
}
}
int getAudioState(BluetoothDevice device) {
- synchronized(this) {
+ synchronized (this) {
if (mConnectedDevicesList.size() == 0) {
return BluetoothHeadset.STATE_AUDIO_DISCONNECTED;
}
}
private void processVrEvent(int state, BluetoothDevice device) {
-
- if(device == null) {
+ if (device == null) {
Log.w(TAG, "processVrEvent device is null");
return;
}
- Log.d(TAG, "processVrEvent: state=" + state + " mVoiceRecognitionStarted: " +
- mVoiceRecognitionStarted + " mWaitingforVoiceRecognition: " + mWaitingForVoiceRecognition +
- " isInCall: " + isInCall());
+ Log.d(TAG, "processVrEvent: state=" + state + " mVoiceRecognitionStarted: "
+ + mVoiceRecognitionStarted + " mWaitingforVoiceRecognition: "
+ + mWaitingForVoiceRecognition + " isInCall: " + isInCall());
if (state == HeadsetHalConstants.VR_STATE_STARTED) {
if (!isVirtualCallInProgress() && !isInCall()) {
IDeviceIdleController dic = IDeviceIdleController.Stub.asInterface(
try {
mService.startActivity(sVoiceCommandIntent);
} catch (ActivityNotFoundException e) {
- atResponseCodeNative(HeadsetHalConstants.AT_RESPONSE_ERROR,
- 0, getByteAddress(device));
+ atResponseCodeNative(
+ HeadsetHalConstants.AT_RESPONSE_ERROR, 0, getByteAddress(device));
return;
}
expectVoiceRecognition(device);
} else {
// send error response if call is ongoing
- atResponseCodeNative(HeadsetHalConstants.AT_RESPONSE_ERROR,
- 0, getByteAddress(device));
+ atResponseCodeNative(
+ HeadsetHalConstants.AT_RESPONSE_ERROR, 0, getByteAddress(device));
return;
}
} else if (state == HeadsetHalConstants.VR_STATE_STOPPED) {
- if (mVoiceRecognitionStarted || mWaitingForVoiceRecognition)
- {
- atResponseCodeNative(HeadsetHalConstants.AT_RESPONSE_OK,
- 0, getByteAddress(device));
+ if (mVoiceRecognitionStarted || mWaitingForVoiceRecognition) {
+ atResponseCodeNative(HeadsetHalConstants.AT_RESPONSE_OK, 0, getByteAddress(device));
mVoiceRecognitionStarted = false;
mWaitingForVoiceRecognition = false;
if (!isInCall() && (mActiveScoDevice != null)) {
disconnectAudioNative(getByteAddress(mActiveScoDevice));
mAudioManager.setParameters("A2dpSuspended=false");
}
- }
- else
- {
- atResponseCodeNative(HeadsetHalConstants.AT_RESPONSE_ERROR,
- 0, getByteAddress(device));
+ } else {
+ atResponseCodeNative(
+ HeadsetHalConstants.AT_RESPONSE_ERROR, 0, getByteAddress(device));
}
} else {
Log.e(TAG, "Bad Voice Recognition state: " + state);
}
}
- private void processLocalVrEvent(int state)
- {
+ private void processLocalVrEvent(int state) {
BluetoothDevice device = null;
- if (state == HeadsetHalConstants.VR_STATE_STARTED)
- {
+ if (state == HeadsetHalConstants.VR_STATE_STARTED) {
boolean needAudio = true;
- if (mVoiceRecognitionStarted || isInCall())
- {
- Log.e(TAG, "Voice recognition started when call is active. isInCall:" + isInCall() +
- " mVoiceRecognitionStarted: " + mVoiceRecognitionStarted);
+ if (mVoiceRecognitionStarted || isInCall()) {
+ Log.e(TAG, "Voice recognition started when call is active. isInCall:" + isInCall()
+ + " mVoiceRecognitionStarted: " + mVoiceRecognitionStarted);
return;
}
mVoiceRecognitionStarted = true;
- if (mWaitingForVoiceRecognition)
- {
+ if (mWaitingForVoiceRecognition) {
device = getDeviceForMessage(START_VR_TIMEOUT);
- if (device == null)
- return;
+ if (device == null) return;
Log.d(TAG, "Voice recognition started successfully");
mWaitingForVoiceRecognition = false;
- atResponseCodeNative(HeadsetHalConstants.AT_RESPONSE_OK,
- 0, getByteAddress(device));
+ atResponseCodeNative(HeadsetHalConstants.AT_RESPONSE_OK, 0, getByteAddress(device));
removeMessages(START_VR_TIMEOUT);
- }
- else
- {
+ } else {
Log.d(TAG, "Voice recognition started locally");
needAudio = startVoiceRecognitionNative(getByteAddress(mCurrentDevice));
- if (mCurrentDevice != null)
- device = mCurrentDevice;
+ if (mCurrentDevice != null) device = mCurrentDevice;
}
- if (needAudio && !isAudioOn())
- {
+ if (needAudio && !isAudioOn()) {
Log.d(TAG, "Initiating audio connection for Voice Recognition");
// At this stage, we need to be sure that AVDTP is not streaming. This is needed
// to be compliant with the AV+HFP Whitepaper as we cannot have A2DP in
if (mStartVoiceRecognitionWakeLock.isHeld()) {
mStartVoiceRecognitionWakeLock.release();
}
- }
- else
- {
- Log.d(TAG, "Voice Recognition stopped. mVoiceRecognitionStarted: " + mVoiceRecognitionStarted +
- " mWaitingForVoiceRecognition: " + mWaitingForVoiceRecognition);
- if (mVoiceRecognitionStarted || mWaitingForVoiceRecognition)
- {
+ } else {
+ Log.d(TAG, "Voice Recognition stopped. mVoiceRecognitionStarted: "
+ + mVoiceRecognitionStarted + " mWaitingForVoiceRecognition: "
+ + mWaitingForVoiceRecognition);
+ if (mVoiceRecognitionStarted || mWaitingForVoiceRecognition) {
mVoiceRecognitionStarted = false;
mWaitingForVoiceRecognition = false;
- if (stopVoiceRecognitionNative(getByteAddress(mCurrentDevice))
- && !isInCall() && mActiveScoDevice != null) {
+ if (stopVoiceRecognitionNative(getByteAddress(mCurrentDevice)) && !isInCall()
+ && mActiveScoDevice != null) {
disconnectAudioNative(getByteAddress(mActiveScoDevice));
mAudioManager.setParameters("A2dpSuspended=false");
}
continue;
}
connectionState = getConnectionState(device);
- for(int i = 0; i < states.length; i++) {
+ for (int i = 0; i < states.length; i++) {
if (connectionState == states[i]) {
deviceList.add(device);
}
return deviceList;
}
- private BluetoothDevice getDeviceForMessage(int what)
- {
+ private BluetoothDevice getDeviceForMessage(int what) {
if (what == CONNECT_TIMEOUT) {
log("getDeviceForMessage: returning mTargetDevice for what=" + what);
return mTargetDevice;
log("getDeviceForMessage: No connected device. what=" + what);
return null;
}
- for (BluetoothDevice device : mConnectedDevicesList)
- {
- if (getHandler().hasMessages(what, device))
- {
+ for (BluetoothDevice device : mConnectedDevicesList) {
+ if (getHandler().hasMessages(what, device)) {
log("getDeviceForMessage: returning " + device);
return device;
}
return null;
}
- private BluetoothDevice getMatchingDevice(BluetoothDevice device)
- {
- for (BluetoothDevice matchingDevice : mConnectedDevicesList)
- {
- if (matchingDevice.equals(device))
- {
+ private BluetoothDevice getMatchingDevice(BluetoothDevice device) {
+ for (BluetoothDevice matchingDevice : mConnectedDevicesList) {
+ if (matchingDevice.equals(device)) {
return matchingDevice;
}
}
// This method does not check for error conditon (newState == prevState)
private void broadcastConnectionState(BluetoothDevice device, int newState, int prevState) {
log("Connection state " + device + ": " + prevState + "->" + newState);
- if(prevState == BluetoothProfile.STATE_CONNECTED) {
+ if (prevState == BluetoothProfile.STATE_CONNECTED) {
// Headset is disconnecting, stop Virtual call if active.
terminateScoUsingVirtualVoiceCall();
}
intent.putExtra(BluetoothProfile.EXTRA_PREVIOUS_STATE, prevState);
intent.putExtra(BluetoothProfile.EXTRA_STATE, newState);
intent.putExtra(BluetoothDevice.EXTRA_DEVICE, device);
- mService.sendBroadcastAsUser(intent, UserHandle.ALL,
- HeadsetService.BLUETOOTH_PERM);
+ mService.sendBroadcastAsUser(intent, UserHandle.ALL, HeadsetService.BLUETOOTH_PERM);
}
private void broadcastAudioState(BluetoothDevice device, int newState, int prevState) {
- if(prevState == BluetoothHeadset.STATE_AUDIO_CONNECTED) {
+ if (prevState == BluetoothHeadset.STATE_AUDIO_CONNECTED) {
// When SCO gets disconnected during call transfer, Virtual call
- //needs to be cleaned up.So call terminateScoUsingVirtualVoiceCall.
+ // needs to be cleaned up.So call terminateScoUsingVirtualVoiceCall.
terminateScoUsingVirtualVoiceCall();
}
Intent intent = new Intent(BluetoothHeadset.ACTION_AUDIO_STATE_CHANGED);
intent.putExtra(BluetoothProfile.EXTRA_PREVIOUS_STATE, prevState);
intent.putExtra(BluetoothProfile.EXTRA_STATE, newState);
intent.putExtra(BluetoothDevice.EXTRA_DEVICE, device);
- mService.sendBroadcastAsUser(intent, UserHandle.ALL,
- HeadsetService.BLUETOOTH_PERM);
+ mService.sendBroadcastAsUser(intent, UserHandle.ALL, HeadsetService.BLUETOOTH_PERM);
log("Audio state " + device + ": " + prevState + "->" + newState);
}
/*
* Put the AT command, company ID, arguments, and device in an Intent and broadcast it.
*/
- private void broadcastVendorSpecificEventIntent(String command,
- int companyId,
- int commandType,
- Object[] arguments,
- BluetoothDevice device) {
+ private void broadcastVendorSpecificEventIntent(String command, int companyId, int commandType,
+ Object[] arguments, BluetoothDevice device) {
log("broadcastVendorSpecificEventIntent(" + command + ")");
- Intent intent =
- new Intent(BluetoothHeadset.ACTION_VENDOR_SPECIFIC_HEADSET_EVENT);
+ Intent intent = new Intent(BluetoothHeadset.ACTION_VENDOR_SPECIFIC_HEADSET_EVENT);
intent.putExtra(BluetoothHeadset.EXTRA_VENDOR_SPECIFIC_HEADSET_EVENT_CMD, command);
- intent.putExtra(BluetoothHeadset.EXTRA_VENDOR_SPECIFIC_HEADSET_EVENT_CMD_TYPE,
- commandType);
+ intent.putExtra(BluetoothHeadset.EXTRA_VENDOR_SPECIFIC_HEADSET_EVENT_CMD_TYPE, commandType);
// assert: all elements of args are Serializable
intent.putExtra(BluetoothHeadset.EXTRA_VENDOR_SPECIFIC_HEADSET_EVENT_ARGS, arguments);
intent.putExtra(BluetoothDevice.EXTRA_DEVICE, device);
- intent.addCategory(BluetoothHeadset.VENDOR_SPECIFIC_HEADSET_EVENT_COMPANY_ID_CATEGORY
- + "." + Integer.toString(companyId));
+ intent.addCategory(BluetoothHeadset.VENDOR_SPECIFIC_HEADSET_EVENT_COMPANY_ID_CATEGORY + "."
+ + Integer.toString(companyId));
- mService.sendBroadcastAsUser(intent, UserHandle.ALL,
- HeadsetService.BLUETOOTH_PERM);
+ mService.sendBroadcastAsUser(intent, UserHandle.ALL, HeadsetService.BLUETOOTH_PERM);
}
- private void configAudioParameters(BluetoothDevice device)
- {
+ private void configAudioParameters(BluetoothDevice device) {
// Reset NREC on connect event. Headset will override later
HashMap<String, Integer> AudioParamConfig = new HashMap<String, Integer>();
AudioParamConfig.put("NREC", 1);
mHeadsetAudioParam.put(device, AudioParamConfig);
- mAudioManager.setParameters(HEADSET_NAME + "=" + getCurrentDeviceName(device) + ";" +
- HEADSET_NREC + "=on");
- Log.d(TAG, "configAudioParameters for device:" + device + " are: nrec = " +
- AudioParamConfig.get("NREC"));
+ mAudioManager.setParameters(
+ HEADSET_NAME + "=" + getCurrentDeviceName(device) + ";" + HEADSET_NREC + "=on");
+ Log.d(TAG, "configAudioParameters for device:" + device + " are: nrec = "
+ + AudioParamConfig.get("NREC"));
}
- private void setAudioParameters(BluetoothDevice device)
- {
+ private void setAudioParameters(BluetoothDevice device) {
// 1. update nrec value
// 2. update headset name
int mNrec = 0;
if (AudioParam != null && !AudioParam.isEmpty()) {
mNrec = AudioParam.get("NREC");
} else {
- Log.e(TAG,"setAudioParameters: AudioParam not found");
+ Log.e(TAG, "setAudioParameters: AudioParam not found");
}
if (mNrec == 1) {
mAudioManager.setParameters(HEADSET_NAME + "=" + getCurrentDeviceName(device));
}
- private String parseUnknownAt(String atString)
- {
+ private String parseUnknownAt(String atString) {
StringBuilder atCommand = new StringBuilder(atString.length());
String result = null;
for (int i = 0; i < atString.length(); i++) {
char c = atString.charAt(i);
if (c == '"') {
- int j = atString.indexOf('"', i + 1 ); // search for closing "
- if (j == -1) { // unmatched ", insert one.
+ int j = atString.indexOf('"', i + 1); // search for closing "
+ if (j == -1) { // unmatched ", insert one.
atCommand.append(atString.substring(i, atString.length()));
atCommand.append('"');
break;
return result;
}
- private int getAtCommandType(String atCommand)
- {
+ private int getAtCommandType(String atCommand) {
int commandType = mPhonebook.TYPE_UNKNOWN;
String atString = null;
atCommand = atCommand.trim();
- if (atCommand.length() > 5)
- {
+ if (atCommand.length() > 5) {
atString = atCommand.substring(5);
- if (atString.startsWith("?")) // Read
+ if (atString.startsWith("?")) // Read
commandType = mPhonebook.TYPE_READ;
- else if (atString.startsWith("=?")) // Test
+ else if (atString.startsWith("=?")) // Test
commandType = mPhonebook.TYPE_TEST;
- else if (atString.startsWith("=")) // Set
+ else if (atString.startsWith("=")) // Set
commandType = mPhonebook.TYPE_SET;
else
commandType = mPhonebook.TYPE_UNKNOWN;
}
// 2. Send virtual phone state changed to initialize SCO
- processCallState(new HeadsetCallState(0, 0,
- HeadsetHalConstants.CALL_STATE_DIALING, "", 0), true);
- processCallState(new HeadsetCallState(0, 0,
- HeadsetHalConstants.CALL_STATE_ALERTING, "", 0), true);
- processCallState(new HeadsetCallState(1, 0,
- HeadsetHalConstants.CALL_STATE_IDLE, "", 0), true);
+ processCallState(
+ new HeadsetCallState(0, 0, HeadsetHalConstants.CALL_STATE_DIALING, "", 0), true);
+ processCallState(
+ new HeadsetCallState(0, 0, HeadsetHalConstants.CALL_STATE_ALERTING, "", 0), true);
+ processCallState(
+ new HeadsetCallState(1, 0, HeadsetHalConstants.CALL_STATE_IDLE, "", 0), true);
setVirtualCallInProgress(true);
// Done
if (DBG) log("initiateScoUsingVirtualVoiceCall: Done");
if (DBG) log("terminateScoUsingVirtualVoiceCall: Received");
if (!isVirtualCallInProgress()) {
- Log.e(TAG, "terminateScoUsingVirtualVoiceCall:"+
- "No present call to terminate");
+ Log.e(TAG, "terminateScoUsingVirtualVoiceCall:"
+ + "No present call to terminate");
return false;
}
// 2. Send virtual phone state changed to close SCO
- processCallState(new HeadsetCallState(0, 0,
- HeadsetHalConstants.CALL_STATE_IDLE, "", 0), true);
+ processCallState(
+ new HeadsetCallState(0, 0, HeadsetHalConstants.CALL_STATE_IDLE, "", 0), true);
setVirtualCallInProgress(false);
// Done
if (DBG) log("terminateScoUsingVirtualVoiceCall: Done");
}
private void processAnswerCall(BluetoothDevice device) {
- if(device == null) {
+ if (device == null) {
Log.w(TAG, "processAnswerCall device is null");
return;
}
}
private void processHangupCall(BluetoothDevice device) {
- if(device == null) {
+ if (device == null) {
Log.w(TAG, "processHangupCall device is null");
return;
}
}
private void processDialCall(String number, BluetoothDevice device) {
- if(device == null) {
+ if (device == null) {
Log.w(TAG, "processDialCall device is null");
return;
}
String dialNumber;
if (mDialingOut) {
if (DBG) log("processDialCall, already dialling");
- atResponseCodeNative(HeadsetHalConstants.AT_RESPONSE_ERROR, 0,
- getByteAddress(device));
+ atResponseCodeNative(HeadsetHalConstants.AT_RESPONSE_ERROR, 0, getByteAddress(device));
return;
}
if ((number == null) || (number.length() == 0)) {
dialNumber = mPhonebook.getLastDialledNumber();
if (dialNumber == null) {
if (DBG) log("processDialCall, last dial number null");
- atResponseCodeNative(HeadsetHalConstants.AT_RESPONSE_ERROR, 0,
- getByteAddress(device));
+ atResponseCodeNative(
+ HeadsetHalConstants.AT_RESPONSE_ERROR, 0, getByteAddress(device));
return;
}
} else if (number.charAt(0) == '>') {
// Yuck - memory dialling requested.
// Just dial last number for now
- if (number.startsWith(">9999")) { // for PTS test
- atResponseCodeNative(HeadsetHalConstants.AT_RESPONSE_ERROR, 0,
- getByteAddress(device));
+ if (number.startsWith(">9999")) { // for PTS test
+ atResponseCodeNative(
+ HeadsetHalConstants.AT_RESPONSE_ERROR, 0, getByteAddress(device));
return;
}
if (DBG) log("processDialCall, memory dial do last dial for now");
dialNumber = mPhonebook.getLastDialledNumber();
if (dialNumber == null) {
if (DBG) log("processDialCall, last dial number null");
- atResponseCodeNative(HeadsetHalConstants.AT_RESPONSE_ERROR, 0,
- getByteAddress(device));
+ atResponseCodeNative(
+ HeadsetHalConstants.AT_RESPONSE_ERROR, 0, getByteAddress(device));
return;
}
} else {
// Check for virtual call to terminate before sending Call Intent
terminateScoUsingVirtualVoiceCall();
- Intent intent = new Intent(Intent.ACTION_CALL_PRIVILEGED,
- Uri.fromParts(SCHEME_TEL, dialNumber, null));
+ Intent intent = new Intent(
+ Intent.ACTION_CALL_PRIVILEGED, Uri.fromParts(SCHEME_TEL, dialNumber, null));
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mService.startActivity(intent);
// TODO(BT) continue send OK reults code after call starts
}
private void processVolumeEvent(int volumeType, int volume, BluetoothDevice device) {
- if(device != null && !device.equals(mActiveScoDevice) && mPhoneState.isInCall()) {
+ if (device != null && !device.equals(mActiveScoDevice) && mPhoneState.isInCall()) {
Log.w(TAG, "ignore processVolumeEvent");
return;
}
}
private void processSendDtmf(int dtmf, BluetoothDevice device) {
- if(device == null) {
+ if (device == null) {
Log.w(TAG, "processSendDtmf device is null");
return;
}
processCallState(callState, false);
}
- private void processCallState(HeadsetCallState callState,
- boolean isVirtualCall) {
+ private void processCallState(HeadsetCallState callState, boolean isVirtualCall) {
mPhoneState.setNumActiveCall(callState.mNumActive);
mPhoneState.setNumHeldCall(callState.mNumHeld);
mPhoneState.setCallState(callState.mCallState);
if (mDialingOut) {
- if (callState.mCallState ==
- HeadsetHalConstants.CALL_STATE_DIALING) {
+ if (callState.mCallState == HeadsetHalConstants.CALL_STATE_DIALING) {
BluetoothDevice device = getDeviceForMessage(DIALING_OUT_TIMEOUT);
if (device == null) {
return;
}
- atResponseCodeNative(HeadsetHalConstants.AT_RESPONSE_OK,
- 0, getByteAddress(device));
+ atResponseCodeNative(HeadsetHalConstants.AT_RESPONSE_OK, 0, getByteAddress(device));
removeMessages(DIALING_OUT_TIMEOUT);
- } else if (callState.mCallState ==
- HeadsetHalConstants.CALL_STATE_ACTIVE || callState.mCallState
- == HeadsetHalConstants.CALL_STATE_IDLE) {
+ } else if (callState.mCallState == HeadsetHalConstants.CALL_STATE_ACTIVE
+ || callState.mCallState == HeadsetHalConstants.CALL_STATE_IDLE) {
mDialingOut = false;
}
}
/* Set ActiveScoDevice to null when call ends */
- if ((mActiveScoDevice != null) && !isInCall() &&
- callState.mCallState == HeadsetHalConstants.CALL_STATE_IDLE)
+ if ((mActiveScoDevice != null) && !isInCall()
+ && callState.mCallState == HeadsetHalConstants.CALL_STATE_IDLE)
mActiveScoDevice = null;
- log("mNumActive: " + callState.mNumActive + " mNumHeld: " +
- callState.mNumHeld +" mCallState: " + callState.mCallState);
+ log("mNumActive: " + callState.mNumActive + " mNumHeld: " + callState.mNumHeld
+ + " mCallState: " + callState.mCallState);
log("mNumber: " + callState.mNumber + " mType: " + callState.mType);
if (isVirtualCall) {
// virtual call state update
if (getCurrentState() != mDisconnected) {
phoneStateChangeNative(callState.mNumActive, callState.mNumHeld,
- callState.mCallState, callState.mNumber, callState.mType);
+ callState.mCallState, callState.mNumber, callState.mType);
}
} else {
// circuit-switch voice call update
if (!isVirtualCallInProgress()) {
if (getCurrentState() != mDisconnected) {
phoneStateChangeNative(callState.mNumActive, callState.mNumHeld,
- callState.mCallState, callState.mNumber, callState.mType);
+ callState.mCallState, callState.mNumber, callState.mType);
}
}
}
AudioParamNrec.put("NREC", 1);
else
AudioParamNrec.put("NREC", 0);
- log("NREC value for device :" + device + " is: " +
- AudioParamNrec.get("NREC"));
+ log("NREC value for device :" + device + " is: " + AudioParamNrec.get("NREC"));
} else {
- Log.e(TAG,"processNoiceReductionEvent: AudioParamNrec is null ");
+ Log.e(TAG, "processNoiceReductionEvent: AudioParamNrec is null ");
}
if (mActiveScoDevice != null && mActiveScoDevice.equals(device)
// 1 - NBS on
private void processWBSEvent(int enable, BluetoothDevice device) {
if (enable == 2) {
- Log.d(TAG, "AudioManager.setParameters bt_wbs=on for " +
- device.getName() + " - " + device.getAddress());
+ Log.d(TAG, "AudioManager.setParameters bt_wbs=on for " + device.getName() + " - "
+ + device.getAddress());
mAudioManager.setParameters(HEADSET_WBS + "=on");
} else {
- Log.d(TAG, "AudioManager.setParameters bt_wbs=off for " +
- device.getName() + " - " + device.getAddress());
+ Log.d(TAG, "AudioManager.setParameters bt_wbs=off for " + device.getName() + " - "
+ + device.getAddress());
mAudioManager.setParameters(HEADSET_WBS + "=off");
}
}
private void processAtChld(int chld, BluetoothDevice device) {
- if(device == null) {
+ if (device == null) {
Log.w(TAG, "processAtChld device is null");
return;
}
if (mPhoneProxy != null) {
try {
if (mPhoneProxy.processChld(chld)) {
- atResponseCodeNative(HeadsetHalConstants.AT_RESPONSE_OK,
- 0, getByteAddress(device));
+ atResponseCodeNative(
+ HeadsetHalConstants.AT_RESPONSE_OK, 0, getByteAddress(device));
} else {
- atResponseCodeNative(HeadsetHalConstants.AT_RESPONSE_ERROR,
- 0, getByteAddress(device));
+ atResponseCodeNative(
+ HeadsetHalConstants.AT_RESPONSE_ERROR, 0, getByteAddress(device));
}
} catch (RemoteException e) {
Log.e(TAG, Log.getStackTraceString(new Throwable()));
- atResponseCodeNative(HeadsetHalConstants.AT_RESPONSE_ERROR,
- 0, getByteAddress(device));
+ atResponseCodeNative(
+ HeadsetHalConstants.AT_RESPONSE_ERROR, 0, getByteAddress(device));
}
} else {
Log.e(TAG, "Handsfree phone proxy null for At+Chld");
- atResponseCodeNative(HeadsetHalConstants.AT_RESPONSE_ERROR,
- 0, getByteAddress(device));
+ atResponseCodeNative(HeadsetHalConstants.AT_RESPONSE_ERROR, 0, getByteAddress(device));
}
}
private void processSubscriberNumberRequest(BluetoothDevice device) {
- if(device == null) {
+ if (device == null) {
Log.w(TAG, "processSubscriberNumberRequest device is null");
return;
}
try {
String number = mPhoneProxy.getSubscriberNumber();
if (number != null) {
- atResponseStringNative("+CNUM: ,\"" + number + "\"," +
- PhoneNumberUtils.toaFromString(number) +
- ",,4", getByteAddress(device));
- atResponseCodeNative(HeadsetHalConstants.AT_RESPONSE_OK,
- 0, getByteAddress(device));
+ atResponseStringNative("+CNUM: ,\"" + number + "\","
+ + PhoneNumberUtils.toaFromString(number) + ",,4",
+ getByteAddress(device));
+ atResponseCodeNative(
+ HeadsetHalConstants.AT_RESPONSE_OK, 0, getByteAddress(device));
} else {
Log.e(TAG, "getSubscriberNumber returns null");
- atResponseCodeNative(HeadsetHalConstants.AT_RESPONSE_ERROR,
- 0, getByteAddress(device));
+ atResponseCodeNative(
+ HeadsetHalConstants.AT_RESPONSE_ERROR, 0, getByteAddress(device));
}
} catch (RemoteException e) {
Log.e(TAG, Log.getStackTraceString(new Throwable()));
- atResponseCodeNative(HeadsetHalConstants.AT_RESPONSE_ERROR,
- 0, getByteAddress(device));
+ atResponseCodeNative(
+ HeadsetHalConstants.AT_RESPONSE_ERROR, 0, getByteAddress(device));
}
} else {
Log.e(TAG, "Handsfree phone proxy null for At+CNUM");
private void processAtCind(BluetoothDevice device) {
int call, call_setup;
- if(device == null) {
+ if (device == null) {
Log.w(TAG, "processAtCind device is null");
return;
}
call_setup = mPhoneState.getNumHeldCall();
}
- cindResponseNative(mPhoneState.getService(), call,
- call_setup, mPhoneState.getCallState(),
- mPhoneState.getSignal(), mPhoneState.getRoam(),
- mPhoneState.getBatteryCharge(), getByteAddress(device));
+ cindResponseNative(mPhoneState.getService(), call, call_setup, mPhoneState.getCallState(),
+ mPhoneState.getSignal(), mPhoneState.getRoam(), mPhoneState.getBatteryCharge(),
+ getByteAddress(device));
}
private void processAtCops(BluetoothDevice device) {
- if(device == null) {
+ if (device == null) {
Log.w(TAG, "processAtCops device is null");
return;
}
}
private void processAtClcc(BluetoothDevice device) {
- if(device == null) {
+ if (device == null) {
Log.w(TAG, "processAtClcc device is null");
return;
}
if (mPhoneProxy != null) {
try {
- if(isVirtualCallInProgress()) {
+ if (isVirtualCallInProgress()) {
String phoneNumber = "";
int type = PhoneNumberUtils.TOA_Unknown;
try {
phoneNumber = mPhoneProxy.getSubscriberNumber();
type = PhoneNumberUtils.toaFromString(phoneNumber);
} catch (RemoteException ee) {
- Log.e(TAG, "Unable to retrieve phone number"+
- "using IBluetoothHeadsetPhone proxy");
+ Log.e(TAG, "Unable to retrieve phone number"
+ + "using IBluetoothHeadsetPhone proxy");
phoneNumber = "";
}
- clccResponseNative(1, 0, 0, 0, false, phoneNumber, type,
- getByteAddress(device));
+ clccResponseNative(
+ 1, 0, 0, 0, false, phoneNumber, type, getByteAddress(device));
clccResponseNative(0, 0, 0, 0, false, "", 0, getByteAddress(device));
- }
- else if (!mPhoneProxy.listCurrentCalls()) {
- clccResponseNative(0, 0, 0, 0, false, "", 0,
- getByteAddress(device));
- }
- else
- {
- Log.d(TAG, "Starting CLCC response timeout for device: "
- + device);
+ } else if (!mPhoneProxy.listCurrentCalls()) {
+ clccResponseNative(0, 0, 0, 0, false, "", 0, getByteAddress(device));
+ } else {
+ Log.d(TAG, "Starting CLCC response timeout for device: " + device);
Message m = obtainMessage(CLCC_RSP_TIMEOUT);
m.obj = getMatchingDevice(device);
sendMessageDelayed(m, CLCC_RSP_TIMEOUT_VALUE);
}
private void processAtCscs(String atString, int type, BluetoothDevice device) {
- log("processAtCscs - atString = "+ atString);
- if(mPhonebook != null) {
+ log("processAtCscs - atString = " + atString);
+ if (mPhonebook != null) {
mPhonebook.handleCscsCommand(atString, type, device);
- }
- else {
+ } else {
Log.e(TAG, "Phonebook handle null for At+CSCS");
atResponseCodeNative(HeadsetHalConstants.AT_RESPONSE_ERROR, 0, getByteAddress(device));
}
}
private void processAtCpbs(String atString, int type, BluetoothDevice device) {
- log("processAtCpbs - atString = "+ atString);
- if(mPhonebook != null) {
+ log("processAtCpbs - atString = " + atString);
+ if (mPhonebook != null) {
mPhonebook.handleCpbsCommand(atString, type, device);
- }
- else {
+ } else {
Log.e(TAG, "Phonebook handle null for At+CPBS");
atResponseCodeNative(HeadsetHalConstants.AT_RESPONSE_ERROR, 0, getByteAddress(device));
}
}
private void processAtCpbr(String atString, int type, BluetoothDevice device) {
- log("processAtCpbr - atString = "+ atString);
- if(mPhonebook != null) {
+ log("processAtCpbr - atString = " + atString);
+ if (mPhonebook != null) {
mPhonebook.handleCpbrCommand(atString, type, device);
- }
- else {
+ } else {
Log.e(TAG, "Phonebook handle null for At+CPBR");
atResponseCodeNative(HeadsetHalConstants.AT_RESPONSE_ERROR, 0, getByteAddress(device));
}
}
Object[] args = generateArgs(arg);
- broadcastVendorSpecificEventIntent(command,
- companyId,
- BluetoothHeadset.AT_CMD_TYPE_SET,
- args,
- mCurrentDevice);
+ broadcastVendorSpecificEventIntent(
+ command, companyId, BluetoothHeadset.AT_CMD_TYPE_SET, args, mCurrentDevice);
atResponseCodeNative(HeadsetHalConstants.AT_RESPONSE_OK, 0, getByteAddress(mCurrentDevice));
return true;
}
private void processUnknownAt(String atString, BluetoothDevice device) {
- if(device == null) {
+ if (device == null) {
Log.w(TAG, "processUnknownAt device is null");
return;
}
// TODO (BT)
- log("processUnknownAt - atString = "+ atString);
+ log("processUnknownAt - atString = " + atString);
String atCommand = parseUnknownAt(atString);
int commandType = getAtCommandType(atCommand);
if (atCommand.startsWith("+CSCS"))
}
private void processKeyPressed(BluetoothDevice device) {
- if(device == null) {
+ if (device == null) {
Log.w(TAG, "processKeyPressed device is null");
return;
}
Log.e(TAG, "Handsfree phone proxy null for answering call");
}
} else if (mPhoneState.getNumActiveCall() > 0) {
- if (!isAudioOn())
- {
+ if (!isAudioOn()) {
connectAudioNative(getByteAddress(mCurrentDevice));
- }
- else
- {
+ } else {
if (mPhoneProxy != null) {
try {
mPhoneProxy.hangupCall();
if (DBG) log("processKeyPressed, last dial number null");
return;
}
- Intent intent = new Intent(Intent.ACTION_CALL_PRIVILEGED,
- Uri.fromParts(SCHEME_TEL, dialNumber, null));
+ Intent intent = new Intent(
+ Intent.ACTION_CALL_PRIVILEGED, Uri.fromParts(SCHEME_TEL, dialNumber, null));
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mService.startActivity(intent);
}
}
- private void sendIndicatorIntent(BluetoothDevice device, int ind_id, String ind_value)
- {
+ private void sendIndicatorIntent(BluetoothDevice device, int ind_id, String ind_value) {
Intent intent = new Intent(BluetoothHeadset.ACTION_HF_INDICATORS_VALUE_CHANGED);
intent.putExtra(BluetoothDevice.EXTRA_DEVICE, device);
intent.putExtra(BluetoothHeadset.EXTRA_HF_INDICATORS_IND_ID, ind_id);
mService.sendBroadcast(intent, HeadsetService.BLUETOOTH_PERM);
}
- private void processAtBind( String at_string, BluetoothDevice device) {
+ private void processAtBind(String at_string, BluetoothDevice device) {
log("processAtBind processAtBind: " + at_string);
// Parse the AT String to find the Indicator Ids that are supported
}
switch (ind_id) {
- case HeadsetHalConstants.HF_INDICATOR_ENHANCED_DRIVER_SAFETY :
- log("Send Broadcast intent for the" +
- "Enhanced Driver Safety indicator.");
+ case HeadsetHalConstants.HF_INDICATOR_ENHANCED_DRIVER_SAFETY:
+ log("Send Broadcast intent for the"
+ + "Enhanced Driver Safety indicator.");
sendIndicatorIntent(device, ind_id, null);
break;
- case HeadsetHalConstants.HF_INDICATOR_BATTERY_LEVEL_STATUS :
- log("Send Broadcast intent for the" +
- "Battery Level indicator.");
+ case HeadsetHalConstants.HF_INDICATOR_BATTERY_LEVEL_STATUS:
+ log("Send Broadcast intent for the"
+ + "Battery Level indicator.");
sendIndicatorIntent(device, ind_id, null);
break;
default:
}
}
- private void processAtBiev( int ind_id, int ind_value, BluetoothDevice device) {
+ private void processAtBiev(int ind_id, int ind_value, BluetoothDevice device) {
log(" Process AT + BIEV Command : " + ind_id + ", " + ind_value);
String ind_value_str = Integer.toString(ind_value);
sendMessage(STACK_EVENT, event);
}
- private void onNoiceReductionEnable(boolean enable, byte[] address) {
+ private void onNoiceReductionEnable(boolean enable, byte[] address) {
StackEvent event = new StackEvent(EVENT_TYPE_NOICE_REDUCTION);
event.valueInt = enable ? 1 : 0;
event.device = getDevice(address);
private void processDeviceStateChanged(HeadsetDeviceState deviceState) {
notifyDeviceStatusNative(deviceState.mService, deviceState.mRoam, deviceState.mSignal,
- deviceState.mBatteryCharge);
+ deviceState.mBatteryCharge);
}
private void processSendClccResponse(HeadsetClccResponse clcc) {
removeMessages(CLCC_RSP_TIMEOUT);
}
clccResponseNative(clcc.mIndex, clcc.mDirection, clcc.mStatus, clcc.mMode, clcc.mMpty,
- clcc.mNumber, clcc.mType, getByteAddress(device));
+ clcc.mNumber, clcc.mType, getByteAddress(device));
}
private void processSendVendorSpecificResultCode(HeadsetVendorSpecificResultCode resultCode) {
private String getCurrentDeviceName(BluetoothDevice device) {
String defaultName = "<unknown>";
- if(device == null) {
+ if (device == null) {
return defaultName;
}
}
private boolean isInCall() {
- return ((mPhoneState.getNumActiveCall() > 0) || (mPhoneState.getNumHeldCall() > 0) ||
- ((mPhoneState.getCallState() != HeadsetHalConstants.CALL_STATE_IDLE) &&
- (mPhoneState.getCallState() != HeadsetHalConstants.CALL_STATE_INCOMING)));
+ return ((mPhoneState.getNumActiveCall() > 0) || (mPhoneState.getNumHeldCall() > 0)
+ || ((mPhoneState.getCallState() != HeadsetHalConstants.CALL_STATE_IDLE)
+ && (mPhoneState.getCallState()
+ != HeadsetHalConstants.CALL_STATE_INCOMING)));
}
// Accept incoming SCO only when there is active call, VR activated,
AdapterService adapterService = AdapterService.getAdapterService();
int priority = mService.getPriority(device);
boolean ret = false;
- //check if this is an incoming connection in Quiet mode.
- if((adapterService == null) ||
- ((adapterService.isQuietModeEnabled() == true) &&
- (mTargetDevice == null))){
+ // check if this is an incoming connection in Quiet mode.
+ if ((adapterService == null)
+ || ((adapterService.isQuietModeEnabled() == true) && (mTargetDevice == null))) {
ret = false;
}
// check priority and accept or reject the connection. if priority is undefined
// it is likely that our SDP has not completed and peer is initiating the
// connection. Allow this connection, provided the device is bonded
- else if((BluetoothProfile.PRIORITY_OFF < priority) ||
- ((BluetoothProfile.PRIORITY_UNDEFINED == priority) &&
- (device.getBondState() != BluetoothDevice.BOND_NONE))){
- ret= true;
+ else if ((BluetoothProfile.PRIORITY_OFF < priority)
+ || ((BluetoothProfile.PRIORITY_UNDEFINED == priority)
+ && (device.getBondState() != BluetoothDevice.BOND_NONE))) {
+ ret = true;
}
return ret;
}
}
int atCommandResult = 0;
int atCommandErrorCode = 0;
- //HeadsetBase headset = mHandsfree.getHeadset();
+ // HeadsetBase headset = mHandsfree.getHeadset();
// ASSERT: (headset != null) && headSet.isConnected()
// REASON: mCheckingAccessPermission is true, otherwise resetAtState
// has set mCheckingAccessPermission to false
if (intent.getAction().equals(BluetoothDevice.ACTION_CONNECTION_ACCESS_REPLY)) {
if (intent.getIntExtra(BluetoothDevice.EXTRA_CONNECTION_ACCESS_RESULT,
- BluetoothDevice.CONNECTION_ACCESS_NO)
+ BluetoothDevice.CONNECTION_ACCESS_NO)
== BluetoothDevice.CONNECTION_ACCESS_YES) {
if (intent.getBooleanExtra(BluetoothDevice.EXTRA_ALWAYS_ALLOWED, false)) {
mCurrentDevice.setPhonebookAccessPermission(BluetoothDevice.ACCESS_ALLOWED);
} else {
Log.e(TAG, "Phonebook handle null");
if (device != null) {
- atResponseCodeNative(HeadsetHalConstants.AT_RESPONSE_ERROR, 0,
- getByteAddress(device));
+ atResponseCodeNative(
+ HeadsetHalConstants.AT_RESPONSE_ERROR, 0, getByteAddress(device));
}
}
}
}
}
- /*package*/native boolean atResponseCodeNative(int responseCode, int errorCode,
- byte[] address);
+ /*package*/ native boolean atResponseCodeNative(
+ int responseCode, int errorCode, byte[] address);
/*package*/ native boolean atResponseStringNative(String responseString, byte[] address);
private native static void classInitNative();
private native boolean stopVoiceRecognitionNative(byte[] address);
private native boolean setVolumeNative(int volumeType, int volume, byte[] address);
private native boolean cindResponseNative(int service, int numActive, int numHeld,
- int callState, int signal, int roam,
- int batteryCharge, byte[] address);
+ int callState, int signal, int roam, int batteryCharge, byte[] address);
private native boolean bindResponseNative(int ind_id, boolean ind_status, byte[] address);
- private native boolean notifyDeviceStatusNative(int networkState, int serviceType, int signal,
- int batteryCharge);
+ private native boolean notifyDeviceStatusNative(
+ int networkState, int serviceType, int signal, int batteryCharge);
private native boolean clccResponseNative(int index, int dir, int status, int mode,
- boolean mpty, String number, int type,
- byte[] address);
+ boolean mpty, String number, int type, byte[] address);
private native boolean copsResponseNative(String operatorName, byte[] address);
- private native boolean phoneStateChangeNative(int numActive, int numHeld, int callState,
- String number, int type);
- private native boolean configureWBSNative(byte[] address,int condec_config);
+ private native boolean phoneStateChangeNative(
+ int numActive, int numHeld, int callState, String number, int type);
+ private native boolean configureWBSNative(byte[] address, int condec_config);
}