diff options
author | Jaikumar Ganesh <jaikumar@google.com> | 2010-09-27 17:04:14 -0700 |
---|---|---|
committer | Jaikumar Ganesh <jaikumar@google.com> | 2010-09-28 20:02:33 -0700 |
commit | 7440fc2e0e0257043b967a80dceb0b33797d1d12 (patch) | |
tree | ab5d1b25a7185deb19167f63eb6cd3957f9a1913 /wifi | |
parent | 3f03496ad97b5f60ab432bca2d17a3e07b4ade47 (diff) | |
download | frameworks_base-7440fc2e0e0257043b967a80dceb0b33797d1d12.zip frameworks_base-7440fc2e0e0257043b967a80dceb0b33797d1d12.tar.gz frameworks_base-7440fc2e0e0257043b967a80dceb0b33797d1d12.tar.bz2 |
Wifi: Update code for new BT Apis.
Change-Id: I1deb0a9a1533958cdb79179bebd2d3b435b0b07c
Diffstat (limited to 'wifi')
-rw-r--r-- | wifi/java/android/net/wifi/WifiStateMachine.java | 64 |
1 files changed, 49 insertions, 15 deletions
diff --git a/wifi/java/android/net/wifi/WifiStateMachine.java b/wifi/java/android/net/wifi/WifiStateMachine.java index 7e26028..e82c003 100644 --- a/wifi/java/android/net/wifi/WifiStateMachine.java +++ b/wifi/java/android/net/wifi/WifiStateMachine.java @@ -63,9 +63,11 @@ import android.util.EventLog; import android.util.Log; import android.util.Slog; import android.app.backup.IBackupManager; +import android.bluetooth.BluetoothA2dp; +import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothHeadset; -import android.bluetooth.BluetoothA2dp; +import android.bluetooth.BluetoothProfile; import android.content.ContentResolver; import android.content.Intent; import android.content.Context; @@ -444,8 +446,14 @@ public class WifiStateMachine extends HierarchicalStateMachine { mInterfaceName = SystemProperties.get("wifi.interface", "tiwlan0"); mSupplicantStateTracker = new SupplicantStateTracker(context, getHandler()); - mBluetoothHeadset = new BluetoothHeadset(mContext, null); mLinkProperties = new LinkProperties(); + BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); + if (adapter != null) { + adapter.getProfileProxy(mContext, mBluetoothProfileServiceListener, + BluetoothProfile.A2DP); + adapter.getProfileProxy(mContext, mBluetoothProfileServiceListener, + BluetoothProfile.HEADSET); + } mNetworkInfo.setIsAvailable(false); mLinkProperties.clear(); @@ -1278,24 +1286,50 @@ public class WifiStateMachine extends HierarchicalStateMachine { * * @return Whether to disable coexistence mode. */ - private boolean shouldDisableCoexistenceMode() { - int state = mBluetoothHeadset.getState(mBluetoothHeadset.getCurrentHeadset()); - return state == BluetoothHeadset.STATE_DISCONNECTED; + private synchronized boolean shouldDisableCoexistenceMode() { + Set<BluetoothDevice> devices = mBluetoothHeadset.getConnectedDevices(); + + return (devices.size() != 0 ? true : false); } - private void checkIsBluetoothPlaying() { + private synchronized void checkIsBluetoothPlaying() { boolean isBluetoothPlaying = false; - Set<BluetoothDevice> connected = mBluetoothA2dp.getConnectedSinks(); + if (mBluetoothA2dp != null) { + Set<BluetoothDevice> connected = mBluetoothA2dp.getConnectedDevices(); - for (BluetoothDevice device : connected) { - if (mBluetoothA2dp.getSinkState(device) == BluetoothA2dp.STATE_PLAYING) { - isBluetoothPlaying = true; - break; + for (BluetoothDevice device : connected) { + if (mBluetoothA2dp.isA2dpPlaying(device)) { + isBluetoothPlaying = true; + break; + } } } setBluetoothScanMode(isBluetoothPlaying); } + private BluetoothProfile.ServiceListener mBluetoothProfileServiceListener = + new BluetoothProfile.ServiceListener() { + public void onServiceConnected(int profile, BluetoothProfile proxy) { + synchronized (WifiStateMachine.this) { + if (profile == BluetoothProfile.HEADSET) { + mBluetoothHeadset = (BluetoothHeadset) proxy; + } else if (profile == BluetoothProfile.A2DP) { + mBluetoothA2dp = (BluetoothA2dp)proxy; + } + } + } + + public void onServiceDisconnected(int profile) { + synchronized (WifiStateMachine.this) { + if (profile == BluetoothProfile.HEADSET) { + mBluetoothHeadset = null; + } else if (profile == BluetoothProfile.A2DP) { + mBluetoothA2dp = null; + } + } + } + }; + private void sendScanResultsAvailableBroadcast() { if (!ActivityManagerNative.isSystemReady()) return; @@ -1905,9 +1939,6 @@ public class WifiStateMachine extends HierarchicalStateMachine { //TODO: initialize and fix multicast filtering //mWM.initializeMulticastFiltering(); - if (mBluetoothA2dp == null) { - mBluetoothA2dp = new BluetoothA2dp(mContext); - } checkIsBluetoothPlaying(); sendSupplicantConnectionChangedBroadcast(true); @@ -2458,7 +2489,10 @@ public class WifiStateMachine extends HierarchicalStateMachine { mModifiedBluetoothCoexistenceMode = false; mPowerMode = DRIVER_POWER_MODE_AUTO; - if (shouldDisableCoexistenceMode()) { + // TODO(): Incorporate the else part in the state machine + // If mBluetoothHeadset == null, means it not conencted to the + // service yet. + if (mBluetoothHeadset != null && shouldDisableCoexistenceMode()) { /* * There are problems setting the Wi-Fi driver's power * mode to active when bluetooth coexistence mode is |