From 3659dee2b21c7f269a2bef051483093fe07e5682 Mon Sep 17 00:00:00 2001 From: Jack He Date: Thu, 9 Mar 2017 11:57:02 -0800 Subject: [PATCH] Fix formatting issue on Headset State Machine Test: build, no user visible effect Change-Id: I482661d95ac6e30a6f55afa9970627e889907125 (cherry picked from commit 79ea359530515b27f608e52cc53f33d3797f7d4c) --- src/com/android/bluetooth/hfp/HeadsetService.java | 115 +- .../android/bluetooth/hfp/HeadsetStateMachine.java | 1496 +++++++++----------- 2 files changed, 737 insertions(+), 874 deletions(-) mode change 100755 => 100644 src/com/android/bluetooth/hfp/HeadsetService.java diff --git a/src/com/android/bluetooth/hfp/HeadsetService.java b/src/com/android/bluetooth/hfp/HeadsetService.java old mode 100755 new mode 100644 index 15d4cfb4..feb8fd42 --- a/src/com/android/bluetooth/hfp/HeadsetService.java +++ b/src/com/android/bluetooth/hfp/HeadsetService.java @@ -62,7 +62,7 @@ public class HeadsetService extends ProfileService { try { registerReceiver(mHeadsetReceiver, filter); } catch (Exception e) { - Log.w(TAG,"Unable to register headset receiver",e); + Log.w(TAG, "Unable to register headset receiver", e); } setHeadsetService(this); return true; @@ -72,7 +72,7 @@ public class HeadsetService extends ProfileService { try { unregisterReceiver(mHeadsetReceiver); } catch (Exception e) { - Log.w(TAG,"Unable to unregister headset receiver",e); + Log.w(TAG, "Unable to unregister headset receiver", e); } if (mStateMachine != null) { mStateMachine.doQuit(); @@ -97,13 +97,12 @@ public class HeadsetService extends ProfileService { } else if (action.equals(AudioManager.VOLUME_CHANGED_ACTION)) { int streamType = intent.getIntExtra(AudioManager.EXTRA_VOLUME_STREAM_TYPE, -1); if (streamType == AudioManager.STREAM_BLUETOOTH_SCO) { - mStateMachine.sendMessage(HeadsetStateMachine.INTENT_SCO_VOLUME_CHANGED, - intent); + mStateMachine.sendMessage( + HeadsetStateMachine.INTENT_SCO_VOLUME_CHANGED, intent); } - } - else if (action.equals(BluetoothDevice.ACTION_CONNECTION_ACCESS_REPLY)) { + } else if (action.equals(BluetoothDevice.ACTION_CONNECTION_ACCESS_REPLY)) { int requestType = intent.getIntExtra(BluetoothDevice.EXTRA_ACCESS_REQUEST_TYPE, - BluetoothDevice.REQUEST_TYPE_PHONEBOOK_ACCESS); + BluetoothDevice.REQUEST_TYPE_PHONEBOOK_ACCESS); if (requestType == BluetoothDevice.REQUEST_TYPE_PHONEBOOK_ACCESS) { Log.v(TAG, "Received BluetoothDevice.ACTION_CONNECTION_ACCESS_REPLY"); mStateMachine.handleAccessPermissionResult(intent); @@ -115,7 +114,8 @@ public class HeadsetService extends ProfileService { /** * Handlers for incoming service calls */ - private static class BluetoothHeadsetBinder extends IBluetoothHeadset.Stub implements IProfileServiceBinder { + private static class BluetoothHeadsetBinder + extends IBluetoothHeadset.Stub implements IProfileServiceBinder { private HeadsetService mService; public BluetoothHeadsetBinder(HeadsetService svc) { @@ -128,11 +128,11 @@ public class HeadsetService extends ProfileService { private HeadsetService getService() { if (!Utils.checkCallerAllowManagedProfiles(mService)) { - Log.w(TAG,"Headset call not allowed for non-active user"); + Log.w(TAG, "Headset call not allowed for non-active user"); return null; } - if (mService != null && mService.isAvailable()) { + if (mService != null && mService.isAvailable()) { return mService; } return null; @@ -268,23 +268,22 @@ public class HeadsetService extends ProfileService { return service.stopScoUsingVirtualVoiceCall(device); } - public void phoneStateChanged(int numActive, int numHeld, int callState, - String number, int type) { + public void phoneStateChanged( + int numActive, int numHeld, int callState, String number, int type) { HeadsetService service = getService(); if (service == null) return; service.phoneStateChanged(numActive, numHeld, callState, number, type); } public void clccResponse(int index, int direction, int status, int mode, boolean mpty, - String number, int type) { + String number, int type) { HeadsetService service = getService(); if (service == null) return; service.clccResponse(index, direction, status, mode, mpty, number, type); } - public boolean sendVendorSpecificResultCode(BluetoothDevice device, - String command, - String arg) { + public boolean sendVendorSpecificResultCode( + BluetoothDevice device, String command, String arg) { HeadsetService service = getService(); if (service == null) { return false; @@ -311,17 +310,17 @@ public class HeadsetService extends ProfileService { } }; - //API methods - public static synchronized HeadsetService getHeadsetService(){ + // API methods + public static synchronized HeadsetService getHeadsetService() { if (sHeadsetService != null && sHeadsetService.isAvailable()) { if (DBG) Log.d(TAG, "getHeadsetService(): returning " + sHeadsetService); return sHeadsetService; } - if (DBG) { + if (DBG) { if (sHeadsetService == null) { Log.d(TAG, "getHeadsetService(): service is NULL"); } else if (!(sHeadsetService.isAvailable())) { - Log.d(TAG,"getHeadsetService(): service is not available"); + Log.d(TAG, "getHeadsetService(): service is not available"); } } return null; @@ -332,11 +331,11 @@ public class HeadsetService extends ProfileService { if (DBG) Log.d(TAG, "setHeadsetService(): set to: " + sHeadsetService); sHeadsetService = instance; } else { - if (DBG) { + if (DBG) { if (sHeadsetService == null) { Log.d(TAG, "setHeadsetService(): service not available"); } else if (!sHeadsetService.isAvailable()) { - Log.d(TAG,"setHeadsetService(): service is cleaning up"); + Log.d(TAG, "setHeadsetService(): service is cleaning up"); } } } @@ -347,17 +346,16 @@ public class HeadsetService extends ProfileService { } public boolean connect(BluetoothDevice device) { - enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM, - "Need BLUETOOTH ADMIN permission"); + enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM, "Need BLUETOOTH ADMIN permission"); if (getPriority(device) == BluetoothProfile.PRIORITY_OFF) { return false; } int connectionState = mStateMachine.getConnectionState(device); - Log.d(TAG,"connectionState = " + connectionState); - if (connectionState == BluetoothProfile.STATE_CONNECTED || - connectionState == BluetoothProfile.STATE_CONNECTING) { + Log.d(TAG, "connectionState = " + connectionState); + if (connectionState == BluetoothProfile.STATE_CONNECTED + || connectionState == BluetoothProfile.STATE_CONNECTING) { return false; } @@ -366,11 +364,10 @@ public class HeadsetService extends ProfileService { } boolean disconnect(BluetoothDevice device) { - enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM, - "Need BLUETOOTH ADMIN permission"); + enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM, "Need BLUETOOTH ADMIN permission"); int connectionState = mStateMachine.getConnectionState(device); - if (connectionState != BluetoothProfile.STATE_CONNECTED && - connectionState != BluetoothProfile.STATE_CONNECTING) { + if (connectionState != BluetoothProfile.STATE_CONNECTED + && connectionState != BluetoothProfile.STATE_CONNECTING) { return false; } @@ -394,29 +391,26 @@ public class HeadsetService extends ProfileService { } public boolean setPriority(BluetoothDevice device, int priority) { - enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM, - "Need BLUETOOTH_ADMIN permission"); + enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM, "Need BLUETOOTH_ADMIN permission"); Settings.Global.putInt(getContentResolver(), - Settings.Global.getBluetoothHeadsetPriorityKey(device.getAddress()), - priority); + Settings.Global.getBluetoothHeadsetPriorityKey(device.getAddress()), priority); if (DBG) Log.d(TAG, "Saved priority " + device + " = " + priority); return true; } public int getPriority(BluetoothDevice device) { - enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM, - "Need BLUETOOTH_ADMIN permission"); + enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM, "Need BLUETOOTH_ADMIN permission"); int priority = Settings.Global.getInt(getContentResolver(), - Settings.Global.getBluetoothHeadsetPriorityKey(device.getAddress()), - BluetoothProfile.PRIORITY_UNDEFINED); + Settings.Global.getBluetoothHeadsetPriorityKey(device.getAddress()), + BluetoothProfile.PRIORITY_UNDEFINED); return priority; } boolean startVoiceRecognition(BluetoothDevice device) { enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission"); int connectionState = mStateMachine.getConnectionState(device); - if (connectionState != BluetoothProfile.STATE_CONNECTED && - connectionState != BluetoothProfile.STATE_CONNECTING) { + if (connectionState != BluetoothProfile.STATE_CONNECTED + && connectionState != BluetoothProfile.STATE_CONNECTING) { return false; } mStateMachine.sendMessage(HeadsetStateMachine.VOICE_RECOGNITION_START); @@ -429,8 +423,8 @@ public class HeadsetService extends ProfileService { // But since we allow startVoiceRecognition in STATE_CONNECTED and // STATE_CONNECTING state, we do these 2 in this method int connectionState = mStateMachine.getConnectionState(device); - if (connectionState != BluetoothProfile.STATE_CONNECTED && - connectionState != BluetoothProfile.STATE_CONNECTING) { + if (connectionState != BluetoothProfile.STATE_CONNECTED + && connectionState != BluetoothProfile.STATE_CONNECTING) { return false; } mStateMachine.sendMessage(HeadsetStateMachine.VOICE_RECOGNITION_STOP); @@ -507,16 +501,16 @@ public class HeadsetService extends ProfileService { boolean stopScoUsingVirtualVoiceCall(BluetoothDevice device) { int connectionState = mStateMachine.getConnectionState(device); - if (connectionState != BluetoothProfile.STATE_CONNECTED && - connectionState != BluetoothProfile.STATE_CONNECTING) { + if (connectionState != BluetoothProfile.STATE_CONNECTED + && connectionState != BluetoothProfile.STATE_CONNECTING) { return false; } mStateMachine.sendMessage(HeadsetStateMachine.VIRTUAL_CALL_STOP, device); return true; } - private void phoneStateChanged(int numActive, int numHeld, int callState, - String number, int type) { + private void phoneStateChanged( + int numActive, int numHeld, int callState, String number, int type) { enforceCallingOrSelfPermission(MODIFY_PHONE_STATE, null); Message msg = mStateMachine.obtainMessage(HeadsetStateMachine.CALL_STATE_CHANGED); msg.obj = new HeadsetCallState(numActive, numHeld, callState, number, type); @@ -524,16 +518,15 @@ public class HeadsetService extends ProfileService { mStateMachine.sendMessage(msg); } - private void clccResponse(int index, int direction, int status, int mode, boolean mpty, - String number, int type) { + private void clccResponse( + int index, int direction, int status, int mode, boolean mpty, String number, int type) { enforceCallingOrSelfPermission(MODIFY_PHONE_STATE, null); mStateMachine.sendMessage(HeadsetStateMachine.SEND_CCLC_RESPONSE, - new HeadsetClccResponse(index, direction, status, mode, mpty, number, type)); + new HeadsetClccResponse(index, direction, status, mode, mpty, number, type)); } - private boolean sendVendorSpecificResultCode(BluetoothDevice device, - String command, - String arg) { + private boolean sendVendorSpecificResultCode( + BluetoothDevice device, String command, String arg) { enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission"); int connectionState = mStateMachine.getConnectionState(device); if (connectionState != BluetoothProfile.STATE_CONNECTED) { @@ -559,8 +552,8 @@ public class HeadsetService extends ProfileService { return false; } - for (BluetoothDevice device: getConnectedDevices()) { - mStateMachine.sendMessage(HeadsetStateMachine.ENABLE_WBS,device); + for (BluetoothDevice device : getConnectedDevices()) { + mStateMachine.sendMessage(HeadsetStateMachine.ENABLE_WBS, device); } return true; @@ -575,24 +568,24 @@ public class HeadsetService extends ProfileService { if (mStateMachine.isAudioOn()) { return false; } - for (BluetoothDevice device: getConnectedDevices()) { - mStateMachine.sendMessage(HeadsetStateMachine.DISABLE_WBS,device); + for (BluetoothDevice device : getConnectedDevices()) { + mStateMachine.sendMessage(HeadsetStateMachine.DISABLE_WBS, device); } return true; } private boolean bindResponse(int ind_id, boolean ind_status) { - for (BluetoothDevice device: getConnectedDevices()) { + for (BluetoothDevice device : getConnectedDevices()) { int connectionState = mStateMachine.getConnectionState(device); - if (connectionState != BluetoothProfile.STATE_CONNECTED && - connectionState != BluetoothProfile.STATE_CONNECTING) { + if (connectionState != BluetoothProfile.STATE_CONNECTED + && connectionState != BluetoothProfile.STATE_CONNECTING) { continue; } if (DBG) Log.d("Bind Response sent for", device.getAddress()); Message msg = mStateMachine.obtainMessage(HeadsetStateMachine.BIND_RESPONSE); msg.obj = device; msg.arg1 = ind_id; - msg.arg2 = (ind_status == true) ? 1 : 0; + msg.arg2 = ind_status ? 1 : 0; mStateMachine.sendMessage(msg); return true; } diff --git a/src/com/android/bluetooth/hfp/HeadsetStateMachine.java b/src/com/android/bluetooth/hfp/HeadsetStateMachine.java index 30c28b5d..01e62409 100644 --- a/src/com/android/bluetooth/hfp/HeadsetStateMachine.java +++ b/src/com/android/bluetooth/hfp/HeadsetStateMachine.java @@ -73,8 +73,8 @@ import android.os.SystemProperties; 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"; @@ -126,14 +126,13 @@ final class HeadsetStateMachine extends StateMachine { private static final Map VENDOR_SPECIFIC_AT_COMMAND_COMPANY_ID; // Hash for storing the Audio Parameters like NREC for connected headsets private HashMap mHeadsetAudioParam = - new HashMap(); + new HashMap(); // Hash for storing the Remotedevice BRSF private HashMap mHeadsetBrsf = - new HashMap(); + new HashMap(); private static final ParcelUuid[] HEADSET_UUIDS = { - BluetoothUuid.HSP, - BluetoothUuid.Handsfree, + BluetoothUuid.HSP, BluetoothUuid.Handsfree, }; private Disconnected mDisconnected; @@ -148,7 +147,7 @@ final class HeadsetStateMachine extends StateMachine { 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; @@ -194,8 +193,7 @@ final class HeadsetStateMachine extends StateMachine { private BluetoothDevice mMultiDisconnectDevice = null; // Multi HFP: Connected devices list holds all currently connected headsets - private ArrayList mConnectedDevicesList = - new ArrayList(); + private ArrayList mConnectedDevicesList = new ArrayList(); static { classInitNative(); @@ -212,8 +210,8 @@ final class HeadsetStateMachine extends StateMachine { 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; @@ -229,11 +227,12 @@ final class HeadsetStateMachine extends StateMachine { } 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(); @@ -264,20 +263,19 @@ final class HeadsetStateMachine extends StateMachine { 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); } } } @@ -320,8 +318,8 @@ final class HeadsetStateMachine extends StateMachine { 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; @@ -330,25 +328,25 @@ final class HeadsetStateMachine extends StateMachine { @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; } @@ -369,8 +367,7 @@ final class HeadsetStateMachine extends StateMachine { 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; @@ -399,63 +396,62 @@ final class HeadsetStateMachine extends StateMachine { // 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; } } } @@ -469,25 +465,25 @@ final class HeadsetStateMachine extends StateMachine { @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; } @@ -499,8 +495,7 @@ final class HeadsetStateMachine extends StateMachine { 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; @@ -538,23 +533,20 @@ final class HeadsetStateMachine extends StateMachine { // 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; } @@ -564,8 +556,8 @@ final class HeadsetStateMachine extends StateMachine { 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); @@ -576,8 +568,7 @@ final class HeadsetStateMachine extends StateMachine { mIncomingDevice = null; if (mConnectedDevicesList.size() == 0) { transitionTo(mDisconnected); - } - else { + } else { processMultiHFConnected(device); } } @@ -585,27 +576,24 @@ final class HeadsetStateMachine extends StateMachine { } 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); } } @@ -615,62 +603,60 @@ final class HeadsetStateMachine extends StateMachine { 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)); } } @@ -686,8 +672,7 @@ final class HeadsetStateMachine extends StateMachine { 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 @@ -722,19 +707,19 @@ final class HeadsetStateMachine extends StateMachine { 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); } } @@ -747,8 +732,8 @@ final class HeadsetStateMachine extends StateMachine { // 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 @@ -758,8 +743,8 @@ final class HeadsetStateMachine extends StateMachine { @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"); @@ -768,9 +753,8 @@ final class HeadsetStateMachine extends StateMachine { } boolean retValue = HANDLED; - switch(message.what) { - case CONNECT: - { + switch (message.what) { + case CONNECT: { BluetoothDevice device = (BluetoothDevice) message.obj; if (device == null) { break; @@ -781,66 +765,64 @@ final class HeadsetStateMachine extends StateMachine { 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; } @@ -850,10 +832,8 @@ final class HeadsetStateMachine extends StateMachine { } 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"); @@ -867,8 +847,7 @@ final class HeadsetStateMachine extends StateMachine { } log("connectAudioNative in Connected for device = " + device); connectAudioNative(getByteAddress(device)); - } - break; + } break; case VOICE_RECOGNITION_START: processLocalVrEvent(HeadsetHalConstants.VR_STATE_STARTED); break; @@ -876,7 +855,7 @@ final class HeadsetStateMachine extends StateMachine { 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); @@ -887,68 +866,57 @@ final class HeadsetStateMachine extends StateMachine { 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: @@ -969,8 +937,7 @@ final class HeadsetStateMachine extends StateMachine { 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); @@ -982,7 +949,7 @@ final class HeadsetStateMachine extends StateMachine { 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: @@ -1025,8 +992,7 @@ final class HeadsetStateMachine extends StateMachine { // 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)) { @@ -1035,19 +1001,18 @@ final class HeadsetStateMachine extends StateMachine { 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); } @@ -1062,31 +1027,30 @@ final class HeadsetStateMachine extends StateMachine { 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; } } @@ -1101,7 +1065,7 @@ final class HeadsetStateMachine extends StateMachine { 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; } @@ -1111,16 +1075,16 @@ final class HeadsetStateMachine extends StateMachine { 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; @@ -1137,13 +1101,12 @@ final class HeadsetStateMachine extends StateMachine { } 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 @@ -1151,32 +1114,30 @@ final class HeadsetStateMachine extends StateMachine { 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"); @@ -1185,9 +1146,8 @@ final class HeadsetStateMachine extends StateMachine { } boolean retValue = HANDLED; - switch(message.what) { - case CONNECT: - { + switch (message.what) { + case CONNECT: { BluetoothDevice device = (BluetoothDevice) message.obj; if (device == null) { break; @@ -1211,25 +1171,25 @@ final class HeadsetStateMachine extends StateMachine { 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) { @@ -1238,12 +1198,12 @@ final class HeadsetStateMachine extends StateMachine { 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) { @@ -1255,22 +1215,20 @@ final class HeadsetStateMachine extends StateMachine { 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))) { @@ -1282,15 +1240,15 @@ final class HeadsetStateMachine extends StateMachine { } 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 @@ -1300,16 +1258,14 @@ final class HeadsetStateMachine extends StateMachine { 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; @@ -1325,7 +1281,7 @@ final class HeadsetStateMachine extends StateMachine { } 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); @@ -1336,12 +1292,11 @@ final class HeadsetStateMachine extends StateMachine { 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); @@ -1354,28 +1309,26 @@ final class HeadsetStateMachine extends StateMachine { 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) { @@ -1403,8 +1356,7 @@ final class HeadsetStateMachine extends StateMachine { 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); @@ -1455,31 +1407,27 @@ final class HeadsetStateMachine extends StateMachine { // 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); } } @@ -1487,7 +1435,7 @@ final class HeadsetStateMachine extends StateMachine { 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: @@ -1497,26 +1445,25 @@ final class HeadsetStateMachine extends StateMachine { 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: @@ -1538,13 +1485,13 @@ final class HeadsetStateMachine extends StateMachine { 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: @@ -1569,8 +1516,8 @@ final class HeadsetStateMachine extends StateMachine { 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)); } } @@ -1580,17 +1527,15 @@ final class HeadsetStateMachine extends StateMachine { 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); } } @@ -1599,17 +1544,17 @@ final class HeadsetStateMachine extends StateMachine { 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; @@ -1621,28 +1566,27 @@ final class HeadsetStateMachine extends StateMachine { 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; } @@ -1671,8 +1615,7 @@ final class HeadsetStateMachine extends StateMachine { 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); @@ -1680,23 +1623,21 @@ final class HeadsetStateMachine extends StateMachine { 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; @@ -1710,10 +1651,10 @@ final class HeadsetStateMachine extends StateMachine { 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: @@ -1734,10 +1675,10 @@ final class HeadsetStateMachine extends StateMachine { 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: @@ -1745,8 +1686,7 @@ final class HeadsetStateMachine extends StateMachine { 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); @@ -1773,7 +1713,7 @@ final class HeadsetStateMachine extends StateMachine { 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); @@ -1797,179 +1737,173 @@ final class HeadsetStateMachine extends StateMachine { // 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; } } @@ -1982,7 +1916,7 @@ final class HeadsetStateMachine extends StateMachine { 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; } @@ -1999,14 +1933,14 @@ final class HeadsetStateMachine extends StateMachine { 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/ @@ -2031,42 +1965,40 @@ final class HeadsetStateMachine extends StateMachine { } } - 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"); @@ -2111,8 +2043,8 @@ final class HeadsetStateMachine extends StateMachine { 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; } @@ -2135,10 +2067,10 @@ final class HeadsetStateMachine extends StateMachine { List getConnectedDevices() { List devices = new ArrayList(); - synchronized(this) { + synchronized (this) { for (int i = 0; i < mConnectedDevicesList.size(); i++) devices.add(mConnectedDevicesList.get(i)); - } + } return devices; } @@ -2148,16 +2080,14 @@ final class HeadsetStateMachine extends StateMachine { } 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; } } @@ -2173,7 +2103,7 @@ final class HeadsetStateMachine extends StateMachine { } int getAudioState(BluetoothDevice device) { - synchronized(this) { + synchronized (this) { if (mConnectedDevicesList.size() == 0) { return BluetoothHeadset.STATE_AUDIO_DISCONNECTED; } @@ -2182,14 +2112,13 @@ final class HeadsetStateMachine extends StateMachine { } 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( @@ -2203,75 +2132,61 @@ final class HeadsetStateMachine extends StateMachine { 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 @@ -2292,18 +2207,16 @@ final class HeadsetStateMachine extends StateMachine { 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"); } @@ -2333,7 +2246,7 @@ final class HeadsetStateMachine extends StateMachine { 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); } @@ -2343,8 +2256,7 @@ final class HeadsetStateMachine extends StateMachine { 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; @@ -2353,10 +2265,8 @@ final class HeadsetStateMachine extends StateMachine { 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; } @@ -2365,12 +2275,9 @@ final class HeadsetStateMachine extends StateMachine { 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; } } @@ -2380,7 +2287,7 @@ final class HeadsetStateMachine extends StateMachine { // 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(); } @@ -2395,59 +2302,50 @@ final class HeadsetStateMachine extends StateMachine { } 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 AudioParamConfig = new HashMap(); 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; @@ -2455,7 +2353,7 @@ final class HeadsetStateMachine extends StateMachine { 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) { @@ -2468,16 +2366,15 @@ final class HeadsetStateMachine extends StateMachine { 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; @@ -2492,19 +2389,17 @@ final class HeadsetStateMachine extends StateMachine { 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; @@ -2534,12 +2429,12 @@ final class HeadsetStateMachine extends StateMachine { } // 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"); @@ -2550,14 +2445,14 @@ final class HeadsetStateMachine extends StateMachine { 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"); @@ -2565,7 +2460,7 @@ final class HeadsetStateMachine extends StateMachine { } private void processAnswerCall(BluetoothDevice device) { - if(device == null) { + if (device == null) { Log.w(TAG, "processAnswerCall device is null"); return; } @@ -2582,7 +2477,7 @@ final class HeadsetStateMachine extends StateMachine { } private void processHangupCall(BluetoothDevice device) { - if(device == null) { + if (device == null) { Log.w(TAG, "processHangupCall device is null"); return; } @@ -2604,7 +2499,7 @@ final class HeadsetStateMachine extends StateMachine { } private void processDialCall(String number, BluetoothDevice device) { - if(device == null) { + if (device == null) { Log.w(TAG, "processDialCall device is null"); return; } @@ -2612,32 +2507,31 @@ final class HeadsetStateMachine extends StateMachine { 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 { @@ -2651,8 +2545,8 @@ final class HeadsetStateMachine extends StateMachine { // 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 @@ -2665,7 +2559,7 @@ final class HeadsetStateMachine extends StateMachine { } 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; } @@ -2682,7 +2576,7 @@ final class HeadsetStateMachine extends StateMachine { } private void processSendDtmf(int dtmf, BluetoothDevice device) { - if(device == null) { + if (device == null) { Log.w(TAG, "processSendDtmf device is null"); return; } @@ -2702,42 +2596,38 @@ final class HeadsetStateMachine extends StateMachine { 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 @@ -2761,7 +2651,7 @@ final class HeadsetStateMachine extends StateMachine { if (!isVirtualCallInProgress()) { if (getCurrentState() != mDisconnected) { phoneStateChangeNative(callState.mNumActive, callState.mNumHeld, - callState.mCallState, callState.mNumber, callState.mType); + callState.mCallState, callState.mNumber, callState.mType); } } } @@ -2776,10 +2666,9 @@ final class HeadsetStateMachine extends StateMachine { 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) @@ -2792,18 +2681,18 @@ final class HeadsetStateMachine extends StateMachine { // 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; } @@ -2811,26 +2700,25 @@ final class HeadsetStateMachine extends StateMachine { 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; } @@ -2839,20 +2727,20 @@ final class HeadsetStateMachine extends StateMachine { 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"); @@ -2862,7 +2750,7 @@ final class HeadsetStateMachine extends StateMachine { private void processAtCind(BluetoothDevice device) { int call, call_setup; - if(device == null) { + if (device == null) { Log.w(TAG, "processAtCind device is null"); return; } @@ -2879,14 +2767,13 @@ final class HeadsetStateMachine extends StateMachine { 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; } @@ -2909,36 +2796,31 @@ final class HeadsetStateMachine extends StateMachine { } 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); @@ -2954,33 +2836,30 @@ final class HeadsetStateMachine extends StateMachine { } 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)); } @@ -3056,23 +2935,20 @@ final class HeadsetStateMachine extends StateMachine { } 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")) @@ -3086,7 +2962,7 @@ final class HeadsetStateMachine extends StateMachine { } private void processKeyPressed(BluetoothDevice device) { - if(device == null) { + if (device == null) { Log.w(TAG, "processKeyPressed device is null"); return; } @@ -3102,12 +2978,9 @@ final class HeadsetStateMachine extends StateMachine { 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(); @@ -3124,15 +2997,14 @@ final class HeadsetStateMachine extends StateMachine { 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); @@ -3142,7 +3014,7 @@ final class HeadsetStateMachine extends StateMachine { 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 @@ -3161,14 +3033,14 @@ final class HeadsetStateMachine extends StateMachine { } 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: @@ -3180,7 +3052,7 @@ final class HeadsetStateMachine extends StateMachine { } } - 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); @@ -3245,7 +3117,7 @@ final class HeadsetStateMachine extends StateMachine { 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); @@ -3331,7 +3203,7 @@ final class HeadsetStateMachine extends StateMachine { private void processDeviceStateChanged(HeadsetDeviceState deviceState) { notifyDeviceStatusNative(deviceState.mService, deviceState.mRoam, deviceState.mSignal, - deviceState.mBatteryCharge); + deviceState.mBatteryCharge); } private void processSendClccResponse(HeadsetClccResponse clcc) { @@ -3343,7 +3215,7 @@ final class HeadsetStateMachine extends StateMachine { 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) { @@ -3357,7 +3229,7 @@ final class HeadsetStateMachine extends StateMachine { private String getCurrentDeviceName(BluetoothDevice device) { String defaultName = ""; - if(device == null) { + if (device == null) { return defaultName; } @@ -3377,9 +3249,10 @@ final class HeadsetStateMachine extends StateMachine { } 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, @@ -3397,19 +3270,18 @@ final class HeadsetStateMachine extends StateMachine { 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; } @@ -3430,13 +3302,13 @@ final class HeadsetStateMachine extends StateMachine { } 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); @@ -3460,8 +3332,8 @@ final class HeadsetStateMachine extends StateMachine { } 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)); } } } @@ -3502,8 +3374,8 @@ final class HeadsetStateMachine extends StateMachine { } } - /*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(); @@ -3517,18 +3389,16 @@ final class HeadsetStateMachine extends StateMachine { 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); } -- 2.11.0